-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace alchemyPageSelect usage with alchemy-page-selct
Use the new web component to create the page selects. It was necessary to encapsulate the node form mechanic into an own component.
- Loading branch information
1 parent
b088ea1
commit 9693bd8
Showing
5 changed files
with
56 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,47 @@ | ||
<%= alchemy_form_for([:admin, node]) do |f| %> | ||
<% if node.new_record? && node.root? %> | ||
<%= f.input :menu_type, | ||
collection: Alchemy::Language.current.available_menu_names.map { |n| [I18n.t(n, scope: [:alchemy, :menu_names]), n] }, | ||
include_blank: false, | ||
input_html: { class: 'alchemy_selectbox' } %> | ||
<% else %> | ||
<% if node.root? %> | ||
<%= f.input :name %> | ||
<%= alchemy_form_for([:admin, node], id: "node_form") do |f| %> | ||
<% if node.new_record? && node.root? %> | ||
<%= f.input :menu_type, | ||
collection: Alchemy::Language.current.available_menu_names.map { |n| [I18n.t(n, scope: [:alchemy, :menu_names]), n] }, | ||
include_blank: false, | ||
input_html: { class: 'alchemy_selectbox' } %> | ||
<% else %> | ||
<%= f.input :name, input_html: { | ||
autofocus: true, | ||
value: node.page && node.read_attribute(:name).blank? ? nil : node.name, | ||
placeholder: node.page ? node.page.name : nil | ||
} %> | ||
<%= f.input :page_id, label: Alchemy::Page.model_name.human, input_html: { class: 'alchemy_selectbox' } %> | ||
<%= f.input :url, input_html: { disabled: node.page }, hint: Alchemy.t(:node_url_hint) %> | ||
<%= f.input :title %> | ||
<%= f.input :nofollow %> | ||
<%= f.input :external %> | ||
<%= f.hidden_field :parent_id %> | ||
<% if node.root? %> | ||
<%= f.input :name %> | ||
<% else %> | ||
<%= f.input :name, input_html: { | ||
autofocus: true, | ||
value: node.page && node.read_attribute(:name).blank? ? nil : node.name, | ||
placeholder: node.page ? node.page.name : nil | ||
} %> | ||
<%= render Alchemy::Admin::PageSelect.new(node.page, allow_clear: true) do %> | ||
<%= f.input :page_id, label: Alchemy::Page.model_name.human %> | ||
<% end %> | ||
<%= f.input :url, input_html: { disabled: node.page }, hint: Alchemy.t(:node_url_hint) %> | ||
<%= f.input :title %> | ||
<%= f.input :nofollow %> | ||
<%= f.input :external %> | ||
<%= f.hidden_field :parent_id %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<%= f.hidden_field :language_id %> | ||
<%= f.submit button_label %> | ||
<%= f.hidden_field :language_id %> | ||
<%= f.submit button_label %> | ||
<% end %> | ||
|
||
<script> | ||
$('#node_page_id').alchemyPageSelect({ | ||
placeholder: "<%= Alchemy.t(:search_page) %>", | ||
url: "<%= alchemy.api_pages_path %>", | ||
<% if node.page %> | ||
initialSelection: { | ||
id: <%= node.page_id %>, | ||
text: "<%= node.page.name %>", | ||
url_path: "<%= node.page.url_path %>" | ||
} | ||
<% end %> | ||
}).on('change', function(e) { | ||
if (e.val === '') { | ||
$('#node_name').removeAttr('placeholder') | ||
$('#node_url').val('').prop('disabled', false) | ||
} else { | ||
$('#node_name').attr('placeholder', e.added.name) | ||
$('#node_url').val(e.added.url_path).prop('disabled', true) | ||
} | ||
const nodeName = document.getElementById("node_name") | ||
const nodeUrl = document.getElementById("node_url") | ||
const form = document.getElementById("node_form") | ||
|
||
form.addEventListener("Alchemy.PageSelect.PageAdded", (event) => { | ||
const page = event.detail | ||
nodeName.setAttribute("placeholder", page.name) | ||
nodeUrl.value = page.url_path | ||
nodeUrl.setAttribute("disabled", "disabled") | ||
}) | ||
|
||
form.addEventListener("Alchemy.PageSelect.PageRemoved", (event) => { | ||
nodeName.removeAttribute("placeholder") | ||
nodeUrl.value = "" | ||
nodeUrl.removeAttribute("disabled") | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters