Skip to content

Commit

Permalink
Outsource to new editors_select helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Nov 9, 2024
1 parent 7d53f83 commit 1ae8f91
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
23 changes: 23 additions & 0 deletions app/helpers/lectures_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,27 @@ def teacher_select(form, is_new_lecture, lecture = nil)

p1 + p2
end

def editors_select(form, lecture)
if current_user.admin?
preselection = options_for_select(lecture.select_editors, lecture.editors.map(&:id))
form.select(:editor_ids, preselection, {}, {
class: "selectize",
multiple: true,
data: {
ajax: true,
filled: false,
model: "user",
placeholder: t("basics.enter_two_letters"),
no_results: t("basics.no_results"),
modal: true
}
})
else
form.select(:editor_ids, editors_preselection(lecture), {},
class: "selectize",
multiple: true,
"data-cy": "lecture-editors-select")
end
end
end
21 changes: 1 addition & 20 deletions app/views/lectures/edit/_people.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,7 @@
class: "form-label" %>
<%= helpdesk(t('admin.lecture.info.lecture_editors'), false) %>
<div id="lecture_editors_select" data-cy="editor-select" %>
<% if current_user.admin? %>
<%= f.select :editor_ids,
options_for_select(lecture.select_editors,
lecture.editors.map(&:id)),
{},
{ multiple: true,
class: 'selectize',
data: { ajax: true,
model: 'user',
filled: false,
placeholder: t('basics.enter_two_letters'),
no_results: t('basics.no_results') } } %>
<% else %>
<%= f.select :editor_ids,
editors_preselection(lecture),
{},
{ multiple: true,
class: 'selectize',
data: { cy: 'lecture-editors-select'} } %>
<% end %>
<%= editors_select(f, lecture) %>
</div>
</div>

Expand Down

0 comments on commit 1ae8f91

Please sign in to comment.