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

edit about

parent 3304f8a0
No related branches found
No related tags found
No related merge requests found
......@@ -9,27 +9,45 @@ 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.elementsForKindPage = document.querySelectorAll('.kind-page');
this.requiredInputsForKindPage = document.querySelectorAll('.kind-page .form-group.required select, .kind-page .form-group.required input');
this.kindInput.addEventListener('change', this.onKindChange.bind(this));
this.onKindChange();
},
onKindChange: function () {
'use strict';
var kind = this.kindInput.value,
i;
for (i = 0; i < this.elementsForKindUrl.length; i += 1) {
if (kind === 'url') {
this.elementsForKindUrl[i].classList.remove('d-none');
} else {
this.elementsForKindUrl[i].classList.add('d-none');
}
var kind = this.kindInput.value;
if (kind === 'url') {
this.showElements(this.elementsForKindUrl, this.requiredInputsForKindUrl);
this.hideElements(this.elementsForKindPage, this.requiredInputsForKindPage);
} else {
this.showElements(this.elementsForKindPage, this.requiredInputsForKindPage);
this.hideElements(this.elementsForKindUrl, this.requiredInputsForKindUrl);
}
},
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].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 < this.requiredInputsForKindUrl.length; i += 1) {
if (kind === 'url') {
this.requiredInputsForKindUrl[i].setAttribute('required', 'required');
} else {
this.requiredInputsForKindUrl[i].removeAttribute('required');
}
for (i = 0; i < requiredInputs.length; i += 1) {
requiredInputs[i].removeAttribute('required');
}
},
......
......@@ -78,7 +78,7 @@ class Admin::Communication::Website::Menu::ItemsController < Admin::Communicatio
def item_params
params.require(:communication_website_menu_item)
.permit(:title, :kind, :url, :parent_id)
.permit(:title, :kind, :url, :parent_id, :about_type, :about_id)
.merge(university_id: current_university.id)
end
end
......@@ -12,6 +12,10 @@
<div class="kind-url">
<%= f.input :url, as: :string %>
</div>
<div class="kind-page">
<%= f.input :about_type, as: :hidden, input_html: { value: 'Communication::Website::Page' } %>
<%= f.association :about, collection: @website.pages.ordered %>
</div>
</div>
</div>
</div>
......
......@@ -12,6 +12,17 @@
<td width="150"><%= Communication::Website::Menu::Item.human_attribute_name('kind') %></td>
<td><%= @item.kind %></td>
</tr>
<% if @item.kind_url? %>
<tr>
<td width="150"><%= Communication::Website::Menu::Item.human_attribute_name('url') %></td>
<td><%= link_to @item.url, @item.url, target: :blank unless @item.url.blank? %></td>
</tr>
<% else %>
<tr>
<td width="150"><%= Communication::Website::Menu::Item.human_attribute_name('about') %></td>
<td><%= link_to_if can?(:read, @item.about), @item.about, [:admin, @item.about] %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
......
......@@ -77,6 +77,7 @@ fr:
identifier: Identifiant
title: Titre
communication/website/menu/item:
about: Cible
kind: Type
parent: Élément parent
title: Titre
......
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