Skip to content
Snippets Groups Projects
Unverified Commit 2ba53a9f authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

websites edit

parent 101f9763
No related branches found
No related tags found
No related merge requests found
//= require_self
//= require ./menu_items
//= require ./websites
window.osuny.communication = {};
......@@ -7,10 +7,10 @@ window.osuny.communication.menuItems = {
}
this.elementsForKindUrl = document.querySelectorAll('.kind-url');
this.requiredInputsForKindUrl = document.querySelectorAll('.kind-url .form-group.required select, .kind-url .form-group.required input');
this.requiredInputsForKindUrl = document.querySelectorAll('.kind-url .required select, .kind-url .required input');
this.elementsForKindPage = document.querySelectorAll('.kind-page');
this.requiredInputsForKindPage = document.querySelectorAll('.kind-page .form-group.required select, .kind-page .form-group.required input');
this.requiredInputsForKindPage = document.querySelectorAll('.kind-page .required select, .kind-page .required input');
this.kindInput.addEventListener('change', this.onKindChange.bind(this));
this.onKindChange();
......
window.osuny.communication.websites = {
init: function () {
'use strict';
this.aboutTypeInput = document.querySelector('form #communication_website_about_type');
if (this.aboutTypeInput === null) {
return;
}
this.elementsForTypeSchool = document.querySelectorAll('.type-school');
this.requiredInputsForTypeSchool = document.querySelectorAll('.type-school .required select, .type-school .required input');
this.elementsForTypeJournal = document.querySelectorAll('.type-journal');
this.requiredInputsForTypeJournal = document.querySelectorAll('.type-journal .required select, .type-journal .required input');
this.aboutTypeInput.addEventListener('change', this.onTypeChange.bind(this));
this.onTypeChange();
},
onTypeChange: function () {
'use strict';
var aboutType = this.aboutTypeInput.value;
if (aboutType === 'Education::School') {
this.showElements(this.elementsForTypeSchool, this.requiredInputsForTypeSchool);
this.hideElements(this.elementsForTypeJournal, this.requiredInputsForTypeJournal);
} else if (aboutType === 'Research::Journal') {
this.showElements(this.elementsForTypeJournal, this.requiredInputsForTypeJournal);
this.hideElements(this.elementsForTypeSchool, this.requiredInputsForTypeSchool);
} else {
this.hideElements(this.elementsForTypeJournal, this.requiredInputsForTypeJournal);
this.hideElements(this.elementsForTypeSchool, this.requiredInputsForTypeSchool);
}
},
showElements: function (elements, requiredInputs) {
'use strict';
var i;
for (i = 0; i < elements.length; i += 1) {
elements[i].classList.remove('d-none');
}
for (i = 0; i < requiredInputs.length; i += 1) {
requiredInputs[i].removeAttribute('disabled');
requiredInputs[i].setAttribute('required', 'required');
}
},
hideElements: function (elements, requiredInputs) {
'use strict';
var i;
for (i = 0; i < elements.length; i += 1) {
elements[i].classList.add('d-none');
}
for (i = 0; i < requiredInputs.length; i += 1) {
requiredInputs[i].removeAttribute('required');
requiredInputs[i].setAttribute('disabled', 'disabled');
}
},
invoke: function () {
'use strict';
return {
init: this.init.bind(this)
};
}
}.invoke();
window.addEventListener('DOMContentLoaded', function () {
'use strict';
if (document.body.classList.contains('websites-new') || document.body.classList.contains('websites-edit')) {
window.osuny.communication.websites.init();
}
});
......@@ -8,18 +8,18 @@
I18n.t("activerecord.attributes.communication/website.about_#{object}")
},
include_blank: false %>
<%
unless website.about_type.blank?
case website.about_type
when Research::Journal.name
collection = current_university.research_journals
when Education::School.name
collection = current_university.education_schools
end
%>
<div class="type-school">
<%= f.input :about_id,
collection: collection %>
<% end %>
collection: current_university.education_schools,
label: Education::School.model_name.human,
required: true %>
</div>
<div class="type-journal">
<%= f.input :about_id,
collection: current_university.research_journals,
label: Research::Journal.model_name.human,
required: true %>
</div>
</div>
<div class="col-md-4">
<%= f.input :domain %>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment