Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send language_id (of the currently editing page) parameter to Pages API requests for page select on link overlay #2439

Merged
merged 1 commit into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,17 @@ class window.Alchemy.LinkDialog extends Alchemy.Dialog
initPageSelect: ->
pageTemplate = HandlebarsTemplates.page
element_anchor_placeholder = @$element_anchor.attr('placeholder')
if @link_object.dataset.languageId
api_url = "#{Alchemy.routes.api_pages_path}?language_id=#{@link_object.dataset.languageId}"
else
api_url = Alchemy.routes.api_pages_path

@$internal_link.select2
placeholder: Alchemy.t('Search page')
allowClear: true
minimumInputLength: 3
ajax:
url: Alchemy.routes.api_pages_path
url: api_url
datatype: 'json'
quietMillis: 300
data: (term, page) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
onclick: 'new Alchemy.LinkDialog(this).open(); return false;',
class: "icon_button#{ingredient_editor.linked? ? ' linked' : ''} link-ingredient",
"data-parent-selector": "[data-ingredient-id='#{ingredient_editor.id}']",
"data-language-id": ingredient_editor.page&.language_id,
title: Alchemy.t(:place_link),
id: "edit_link_#{ingredient_editor.id}"
) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
class: picture_editor.linked? ? "linked" : nil,
title: Alchemy.t(:link_image),
"data-parent-selector": "[data-ingredient-id='#{picture_editor.id}']",
"data-language-id": picture_editor.page&.language_id,
id: "edit_link_#{picture_editor.id}"
} do %>
<span class="disabled" tabindex="-1"><%= render_icon(:link) %></span>
Expand Down
17 changes: 17 additions & 0 deletions spec/features/admin/link_overlay_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@
)
end

it "should only return pages from the language of the page being edited" do
page_in_other_language = create :alchemy_page, :public, language: create(:alchemy_language, language_code: "es", public: true)

visit edit_admin_page_path(page1)

within "#element_#{article.id}" do
fill_in "Intro", with: "Link me"
click_link "Link text"
end

within "#overlay_tab_internal_link" do
expect(page).to have_selector("#s2id_internal_link")
expect { select2(page_in_other_language.name, from: "Page") }.to raise_error(Capybara::ElementNotFound)
expect(find("#internal_link").value).not_to eq page_in_other_language.urlname
end
end

it "should be possible to link a page" do
visit edit_admin_page_path(page1)

Expand Down