Skip to content

Commit

Permalink
Send language_id (of the currently editing page) parameter to Pages A…
Browse files Browse the repository at this point in the history
…PI requests for page select on link overlay
  • Loading branch information
dbwinger committed Mar 20, 2023
1 parent 99b547f commit 4f4f6b7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/assets/javascripts/alchemy/alchemy.link_dialog.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,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

@$page_urlname.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
1 change: 1 addition & 0 deletions app/views/alchemy/ingredients/shared/_link_tools.html.erb
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_page_urlname")
expect { select2(page_in_other_language.name, from: "Page") }.to raise_error(Capybara::ElementNotFound)
expect(find('#page_urlname').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

0 comments on commit 4f4f6b7

Please sign in to comment.