foodsoft/plugins/polls/app/views/polls/_form.html.haml
Patrick Gansterer d476993321 Add polls plugin
2020-02-24 14:27:22 +01:00

76 lines
2.7 KiB
Text

- content_for :javascript do
:javascript
var choice = $($.parseHTML("#{escape_javascript(render(partial: 'choice', locals: {value: ''}))}"));
$(function() {
function updateSlideState() {
switch($('select[name="poll[voting_method]"]').val()) {
case 'event':
case 'single_select':
$('#multi_select_count').slideUp();
$('#min_max_points').slideUp();
break;
case 'multi_select':
$('#multi_select_count').slideDown();
$('#min_max_points').slideUp();
break;
case 'points':
case 'resistance_points':
$('#multi_select_count').slideUp();
$('#min_max_points').slideDown();
break;
}
}
$('select[name="poll[voting_method]"]').on('change', updateSlideState);
$('a[data-remove-choice]').on('click', function() {
$(this).parent().remove();
return false;
});
$('a[data-add-choice]').on('touchclick', function() {
choice.clone().appendTo('#choices');
return false;
});
updateSlideState();
});
= simple_form_for @poll do |f|
= f.input :name
.fold-line
= f.input :starts, as: :date_picker_time
= f.input :ends, as: :date_picker_time
= f.input :description, input_html: {rows: 2, class: 'input-xxlarge'}
- if @poll.poll_votes.any?
= f.input :voting_method, label: false do
= f.hint t('.already_voted')
- else
= f.input :one_vote_per_ordergroup, inline_label: true, label: false
- if Ordergroup.custom_fields.any?
= f.input :required_ordergroup_custom_fields, as: :check_boxes, label: false,
collection: Ordergroup.custom_fields.map{|f| [t('.required_ordergroup_custom_field', label: f[:label]), f[:name]]}.to_h
- if User.custom_fields.any?
= f.input :required_user_custom_fields, as: :check_boxes, label: false,
collection: User.custom_fields.map{|f| [t('.required_user_custom_field', label: f[:label]), f[:name]]}.to_h
= f.input :voting_method, collection: Poll.voting_methods,include_blank: false,
input_html: {class: 'input-xxlarge'}, value_method: ->(k){ k.first },
label_method: ->(k){ t("activerecord.attributes.poll.voting_methods.#{k.first}") }
#multi_select_count
= f.input :multi_select_count, input_html: { min: 0 }
#min_max_points
.fold-line
= f.input :min_points
= f.input :max_points
= f.input :choices do
#choices
= render partial: 'choice', collection: @poll.choices, as: :value
- if @poll.choices.empty?
= render partial: 'choice', locals: { value: '' }
= link_to t('.new_choice'), '#', 'data-add-choice' => true, class: 'btn'
.form-actions
= f.button :submit
= link_to t('ui.or_cancel'), :back