Questions: fixes, redesign form, fix edit error

This commit is contained in:
Stella Rouzi 2015-09-10 12:39:52 +03:00
parent 38bc2e3c3a
commit e25425bd77
20 changed files with 300 additions and 117 deletions

View file

@ -1,22 +1,45 @@
.row
.col-md-6
%legend Question
= f.input :title, label: 'Your Question'
= f.input :question_type
= f.input :global, label: 'Make Global',
hint: '(Global questions are available for selection to all conferences)'
.col-md-6.hidden{id: 'answers_col'}
= dynamic_association :answers, 'Answers', f,
hint: 'Insert your answers in the order you want them to appear'
.col-md-12
- unless @question.new_record?
.page-header
%h2
Edit Question
.text-muted
= @question.title
.row
= semantic_form_for(@question, url: @question.new_record? ? admin_conference_questions_path(@conference.short_title) : admin_conference_question_path(@conference.short_title, @question.id)) do |f|
.col-md-6
%br
%legend Question
= f.input :title, label: 'Your Question', input_html: { autofocus: true }
= f.input :question_type
= f.input :global, label: 'Make Global',
hint: '(Global questions are available for selection to all conferences)'
= f.submit 'Save', class: 'btn btn-primary'
.col-md-6.hidden{id: 'answers_col'}
= dynamic_association :answers, 'Answers', f,
hint: 'Insert your answers in the order you want them to appear'
:javascript
$(document).ready(function(){
var selected_type_original = $("#question_question_type_id").find('option:selected').text();
if ( selected_type_original == 'Yes/No' ) {
$('#answers_col').addClass('hidden');
}
else {
$('#answers_col').removeClass('hidden');
}
});
$("#question_question_type_id").change(function () {
var selected_type = $(this).find('option:selected').text();
if (selected_type == 'Yes/No')
if ( selected_type == 'Yes/No' ) {
$('#answers_col').addClass('hidden');
else
}
else {
$('#answers_col').removeClass('hidden');
end
}
});

View file

@ -1,27 +0,0 @@
%table.table.table-hover#questions
%th Enabled
%th Question
%th Type
%th Answers
%th Actions
- @questions.each do |q|
%tr
%td
= hidden_field_tag "conference[question_ids][]", nil
= check_box_tag "conference[question_ids][]", q.id,
@conference.question_ids.include?(q.id), id: dom_id(q)
%td
= q.title
%td
= q.question_type.title
%td
= q.answers.map {|a| a.title}.join(', ')
%td
.btn-group
= link_to 'Show', admin_conference_question_path(@conference.short_title, q), class: 'btn btn-success'
= link_to 'Edit', edit_admin_conference_question_path(@conference.short_title, q),
class: 'btn btn-primary', disabled: !(can? :update, q)
= link_to 'Delete', admin_conference_question_path(@conference.short_title, q),
method: :delete, remote: true, class: 'btn btn-danger',
confirm: "Delete question '#{q.title}'?", disabled: !(can? :destroy, q)

View file

@ -1 +0,0 @@
$('#myquestions').html("<%= escape_javascript(render :partial => 'questions') %>");

View file

@ -1,9 +1 @@
%h2
Edit Question
%h3
"#{@question.title}"
= semantic_form_for(@question, url: admin_conference_question_path(@conference.short_title, @question.id)) do |f|
= render partial: 'form', locals: {f: f}
= f.submit 'Save', class: 'btn btn-primary', confirm: 'Are you sure you want to make these changes?'
= render 'form'

View file

@ -11,24 +11,50 @@
.row
.col-md-12
- if @questions.count > 0
= semantic_form_for(@conference, url: update_conference_admin_conference_questions_path(@conference.short_title)) do |f|
.questions{id: 'myquestions'}
= render partial: 'questions'
- if can? :update, Question.new(conference_id: @conference.id)
= f.submit "Save Questions", class: 'btn btn-primary pull-right',
confirm: 'Are you sure you want to make these changes?'
.questions
%table.table.table-hover.datatable#questions
%thead
%th Enabled
%th Title
%th Type
%th Answers
%th Actions
%tbody
- @questions.each do |question|
%tr
%td
= check_box_tag @conference.short_title, question.id, (@conference.questions.include? question),
method: :patch, url: "/admin/conference/#{@conference.short_title}/questions/#{question.id}/toggle_question?enable=",
disabled: question.answers.blank? || !(can? :update, Question.new(conference_id: @conference.id) ), class: 'switch-checkbox', data: { size: 'small',
off_color: 'warning',
on_text: 'Yes',
off_text: 'No' }
%td
= question.title
%td
= question.question_type.title
%td
= question.answers.map {|answer| "#{answer.title} (#{answer.sum_replies question, @conference})"}.join(', ')
%td
.btn-group
= link_to 'Show', admin_conference_question_path(@conference.short_title, question), class: 'btn btn-success', disabled: !(can? :show, question)
= link_to 'Edit', edit_admin_conference_question_path(@conference.short_title, question),
class: 'btn btn-primary', disabled: !(can? :update, question)
= link_to 'Delete', admin_conference_question_path(@conference.short_title, question),
method: :delete, class: 'btn btn-danger',
data: { confirm: "Delete question '#{question.title}'?" }, disabled: !(can? :destroy, question)
.modal.fade{id: 'new-question', 'role' => 'dialog', 'aria-hidden' => 'true'}
.modal-dialog
.modal-content
.modal-header
%h3{id: 'new-question-header'}
Add new question
Create Question
.modal-body
= semantic_form_for(@new_question, url: admin_conference_questions_path(@conference.short_title), method: :post) do |f|
= render partial: 'form', locals: {f: f}
%button{class: 'btn btn-primary'}
Save
.pull-right
%button{class: 'btn btn-danger', 'data-dismiss'=> 'modal', 'aria-hidden'=>'true'}
Cancel
= render partial: 'form'

View file

@ -5,8 +5,7 @@
%h1= @question.title
- @question.answers.each do |answer|
= answer.title
(#{answer.qanswers.find_by(question: @question).registrations.where(conference: @conference).count})
(#{answer.sum_replies @question, @conference})
.row
.col-md-12