mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Fix selectized users on booth/proposal forms
This commit is contained in:
parent
7e5175536e
commit
0ff503bc1b
6 changed files with 57 additions and 71 deletions
|
|
@ -26,7 +26,7 @@ class UsersController < ApplicationController
|
|||
def search
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: { users: User.where('username like ?', "%#{params[:query]}%").select(:username, :id) }
|
||||
render json: { users: User.active.where('username like ?', "%#{params[:query]}%").select(:username, :id) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -111,30 +111,6 @@ module ApplicationHelper
|
|||
safe_join(event.speakers.map{ |speaker| link_to speaker.name, admin_user_path(speaker) }, ',')
|
||||
end
|
||||
|
||||
def speaker_selector_input(form)
|
||||
user_selector_input(:speakers, form, '', true)
|
||||
end
|
||||
|
||||
def user_selector_input(field, form, hint = '', multiple = true)
|
||||
users = User.where(is_disabled: false).pluck(:id, :name, :username, :email).map { |user| [user[0], user[1].blank? ? user[2] : user[1], user[2], user[3]] }.sort_by { |user| user[1].downcase }
|
||||
form.input(
|
||||
field,
|
||||
as: :select,
|
||||
include_blank: true,
|
||||
label: field.to_s.titleize,
|
||||
hint: hint,
|
||||
collection: options_for_select(
|
||||
users.map { |user| ["#{user[1]} (#{user[2]}) #{user[3]}", user[0]] },
|
||||
(form.object.send(field)&.map(&:id) || form.object.send(field)&.id)
|
||||
),
|
||||
input_html: {
|
||||
class: 'select-help-toggle',
|
||||
multiple: multiple,
|
||||
placeholder: (multiple ? 'Select users...' : 'Select a user...')
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
def event_types_sentence(conference)
|
||||
conference.event_types.map { |et| et.title.pluralize }.to_sentence
|
||||
end
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@
|
|||
%abbr{title: 'This field is required'} *
|
||||
= f.text_field :website_url, class: 'form-control', required: true, placeholder: 'URL'
|
||||
.form-group
|
||||
= f.text_field :responsible_ids, multiple: true, class: "form-control", id: "booth_responsibles", placeholder: "Responsibles"
|
||||
= f.label :responsible_ids, 'Responsibles'
|
||||
= f.select :responsible_ids, [], {}, { multiple: true, class: 'form-control', id: 'users_selectize', placeholder: 'Responsibles' }
|
||||
%span.help-block
|
||||
The people responsible for the `t('booth')`. You can only select existing users.
|
||||
.form-group
|
||||
|
|
@ -38,33 +39,5 @@
|
|||
- else
|
||||
Update `(t'booth').capitalize` Request
|
||||
|
||||
:javascript
|
||||
$(document).ready(function() {
|
||||
$('#booth_responsibles').selectize({
|
||||
persist: false,
|
||||
create: false,
|
||||
valueField: 'id',
|
||||
labelField: 'username',
|
||||
searchField: 'username',
|
||||
load: function(query, callback) {
|
||||
if (!query.length) return callback();
|
||||
$.ajax({
|
||||
url: "#{search_users_path}.json",
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
query: query,
|
||||
},
|
||||
error: function(res) {
|
||||
console.log("selectize error");
|
||||
callback();
|
||||
},
|
||||
success: function(res) {
|
||||
console.log("selectize success");
|
||||
// console.log(res);
|
||||
callback(res.users);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
= render partial: 'shared/user_selectize'
|
||||
|
||||
|
|
|
|||
|
|
@ -9,13 +9,24 @@
|
|||
.form-group
|
||||
= f.label :subtitle
|
||||
= f.text_field :subtitle, class: 'form-control'
|
||||
= # speaker_selector_input f
|
||||
.form-group
|
||||
= f.label :speaker_ids, 'Speakers'
|
||||
- if f.object.speakers.any?
|
||||
%p
|
||||
Current:
|
||||
= f.object.speakers.pluck(:username).join(', ')
|
||||
= f.select :speaker_ids, [], {}, { multiple: true, class: "form-control", id: "users_selectize", placeholder: "Speakers" }
|
||||
%span.help-block
|
||||
The people responsible for the event, beside you. You can only select existing users.
|
||||
- if @program.tracks.confirmed.cfp_active.any?
|
||||
.form-group
|
||||
= f.label :track_id, 'Track'
|
||||
= f.select :track_id, @program.tracks.confirmed.cfp_active.pluck(:name, :id), include_blank: '(Please select)'
|
||||
= f.select :track_id, @program.tracks.confirmed.cfp_active.pluck(:name, :id), { include_blank: '(Please select)' }, { class: 'form-control' }
|
||||
.form-group
|
||||
= f.label :event_type_id, 'Type'
|
||||
= f.select :event_type_id, event_type_select_options(@conference.program.event_types), { include_blank: false }, { class: 'select-help-toggle form-control' }
|
||||
- if @program.languages.present?
|
||||
.form-group
|
||||
= f.label :language
|
||||
= f.select :language, @languages, { include_blank: false}, { class: 'select-help-toggle form-control' }
|
||||
- @conference.program.event_types.each do |event_type|
|
||||
|
|
@ -72,10 +83,5 @@
|
|||
%p.text-right
|
||||
= f.submit 'Update Proposal', class: 'btn btn-success'
|
||||
|
||||
:javascript
|
||||
$(document).ready(function() {
|
||||
$('#event_speaker_ids').selectize({
|
||||
plugins: ['remove_button'],
|
||||
maxItems: 5
|
||||
} )
|
||||
});
|
||||
= render partial: 'shared/user_selectize'
|
||||
|
||||
|
|
|
|||
|
|
@ -56,9 +56,10 @@
|
|||
words.
|
||||
= markdown_hint('[Tips to improve your presentations.](http://blog.hubspot.com/blog/tabid/6307/bid/5975/10-Rules-to-Instantly-Improve-Your-Presentations.aspx)')
|
||||
- if @program.cfp.enable_registrations?
|
||||
.form-group
|
||||
= f.label :require_registration, 'Require participants to register to your event'
|
||||
= f.check_box :require_registration, class: 'form-control'
|
||||
.checkbox
|
||||
%label
|
||||
= f.check_box :require_registration
|
||||
Require participants to register to your event?
|
||||
%p.text-right
|
||||
= link_to '#description', 'data-toggle' => 'collapse', id: 'description_link' do
|
||||
Do you require something special for your event?
|
||||
|
|
|
|||
30
app/views/shared/_user_selectize.html.haml
Normal file
30
app/views/shared/_user_selectize.html.haml
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
:javascript
|
||||
$(document).ready(function() {
|
||||
$('#users_selectize').selectize({
|
||||
persist: false,
|
||||
create: false,
|
||||
valueField: 'id',
|
||||
labelField: 'username',
|
||||
searchField: 'username',
|
||||
load: function(query, callback) {
|
||||
if (!query.length) return callback();
|
||||
$.ajax({
|
||||
url: "#{search_users_path}.json",
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
query: query,
|
||||
},
|
||||
error: function(res) {
|
||||
console.log("selectize error");
|
||||
callback();
|
||||
},
|
||||
success: function(res) {
|
||||
console.log("selectize success");
|
||||
// console.log(res);
|
||||
callback(res.users);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue