Add surveys; custom generated by admins

Available during registration or after conference

Co-authored-by: Shyukri <shshyukriev@suse.com>
Co-authored-by: Henne <hvogel@opensuse.org>
Co-authored-by: Moises <mdeniz@suse.com>
This commit is contained in:
Stella Rouzi 2016-06-28 18:16:06 +03:00
parent 4e742d170f
commit 9f3c0eff5d
43 changed files with 701 additions and 17 deletions

View file

@ -0,0 +1,92 @@
.row
.col-md-12
.page-header
- if @survey_question.new_record?
%h1
New Survey Question
- else
%h1
Edit Survey Question
.text-muted
= @survey_question.title
.col-md-6
= semantic_form_for @survey_question, url: @url do |f|
.row
.col-md-12
= f.input :title
= f.input :mandatory
%div.survey-possible-answers{ class: @survey_question.choice? ? '' : 'hidden'}
= f.input :possible_answers, hint: 'Comma separated', input_html: { rows: 3 }
.row
.col-md-6
= f.input :min_choices
.col-md-6
= f.input :max_choices
%hr
.row
.col-md-6
%label{ required: 'required' }
Type of Question:
.form-group
%select.selectpicker.form-control{ id: 'survey_question_kind', name: 'survey_question[kind]' }
- SurveyQuestion.kinds.each do |kind|
%option{ id: "#{kind.second}", 'data-icon' => "fa fa-#{SurveyQuestion::ICONS[kind.first.to_sym]}", selected: @survey_question.kind == kind.first }
= kind.first
.col-md-6
%label
Preview:
.panel.panel-default
.panel-body{id: 'survey_question_preview'}
%p{id: 'title', style: 'word-wrap: break-word'}
= @survey_question.title.blank? ? 'What is your answer?' : @survey_question.title
%div.kinds.boolean{ class: @survey_question.boolean? ? '' : 'hidden'}
%input{type: 'radio', name: 'radio'} Yes
%br
%input{type: 'radio', name: 'radio'} No
%div.kinds.choice{ id: '', class: @survey_question.choice? ? '' : 'hidden'}
- if @survey_question.possible_answers.blank?
- if @survey_question.single_choice?
%input{ type: 'radio', name: 'radio' } Choice 1
%br
%input{ type: 'radio', name: 'radio' } Choice 2
%br
%input{ type: 'radio', name: 'radio' } Choice 3
- else
%input{ type: 'checkbox', name: 'checkbox' } Choice 1
%br
%input{ type: 'checkbox', name: 'checkbox' } Choice 2
%br
%input{ type: 'checkbox', name: 'checkbox' } Choice 3
- else
- @survey_question.possible_answers.split(',').map(&:strip).each do |option|
- if @survey_question.single_choice?
%input{ type: 'radio', name: 'radio' }
= option
%br
- else
%input{ type: 'checkbox', name: 'checkbox' }
= option
%br
%div.kinds.string{ class: @survey_question.string? ? '' : 'hidden'}
%input.form-control
%div.kinds.text{ class: @survey_question.text? ? '' : 'hidden'}
%textarea.form-control{ rows: 4 }
%div.kinds.datetime{ class: @survey_question.datetime? ? '' : 'hidden'}
.form-group{class: 'datetimepicker'}
.input-group
.input-group-addon
%span.fa.fa-calendar
%input.form-control{readonly: 'readonly'}
%div.kinds.numeric{ class: @survey_question.numeric? ? '' : 'hidden'}
%input.form-control{ type: 'number' }
= f.submit 'Save', class: 'btn btn-primary'

View file

@ -0,0 +1 @@
= render partial: 'form'

View file

@ -0,0 +1,18 @@
.row
.col-md-12
.page-header
- if @survey.new_record?
%h1 New Survey
- else
%h1 Edit Survey: #{ @survey.title }
.col-md-6
= semantic_form_for @survey, url: @url do |f|
= f.hidden_field :surveyable_type
= f.hidden_field :surveyable_id
= f.input :title
= f.input :description, input_html: { rows: 3 }
= f.input :target, as: :select, collection: Survey.targets.keys, label: "When to ask"
= f.input :start_date, as: :string, input_html: { class: 'datetimepicker' }
= f.input :end_date, as: :string, input_html: { class: 'datetimepicker' }
= f.submit 'Save', class: 'btn btn-primary'

View file

@ -0,0 +1,62 @@
.panel.panel-default
.panel-heading
%span.badge
= question_index
= survey_question.title
- if survey_question.multiple_choice?
( Select
- if survey_question.min_choices != survey_question.max_choices
a minimum of
= survey_question.min_choices
- if survey_question.min_choices != survey_question.max_choices
and a maximum of
= survey_question.max_choices
choices )
- if survey_question.mandatory
%span.fa.fa-asterisk.text-danger
- if can? :edit, @survey
%p.pull-right
= link_to edit_admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question) do
%span.fa.fa-edit
= link_to admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question), method: :delete, data: { confirm: 'Are you sure you want to delete this question?' } do
%span.fa.fa-times
.panel-body
- if survey_question.boolean?
%input{ type: 'hidden', name: "survey_submission[#{survey_question.id}][]" }
%label
%input{ type: 'radio', name: "survey_submission[#{survey_question.id}][]", value: 'Yes', checked: survey_reply.text == 'Yes' }
Yes
%br
%label
%input{ type: 'radio', name: "survey_submission[#{survey_question.id}][]", value: 'No', checked: survey_reply.text == 'No' }
No
- elsif survey_question.choice?
%input{ type: 'hidden', name: "survey_submission[#{survey_question.id}][]" }
- possible_answers = survey_question.possible_answers.split(',').map(&:strip)
- possible_answers.each.with_index(1) do |answer, answer_index|
- if survey_question.single_choice?
%label
%input{ type: 'radio', name: "survey_submission[#{survey_question.id}][]", value: answer, checked: (survey_reply.text.include? answer if survey_reply.text) }
= answer
%br
- else
%label
= check_box_tag "survey_submission[#{survey_question.id}][]", answer, (survey_reply.text.include? answer if survey_reply.text), id: dom_id(survey_reply)
= answer
%br
- elsif survey_question.string?
%input.form-control{ name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text }
- elsif survey_question.text?
= text_area_tag "survey_submission[#{survey_question.id}][]", survey_reply.text, rows: 4, class: 'form-control'
- elsif survey_question.datetime?
.form-group{ class: 'datetimepicker' }
.input-group
.input-group-addon
%span.fa.fa-calendar
%input.form-control{ readonly: 'readonly', name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text }
- elsif survey_question.numeric?
%input.form-control{ type: 'number', name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text }

View file

@ -0,0 +1 @@
= render partial: 'form'

View file

@ -0,0 +1,38 @@
.row
.col-md-12
.page-header
%h1
Surveys
= link_to 'New', new_admin_conference_survey_path(@conference.short_title, survey: { surveyable_type: 'Conference', surveyable_id: @conference.id }), class: 'btn btn-success pull-right'
%p.text-muted
Available surveys for this conference
- if @surveys.any?
.row
.col-md-12
%table.table.table-hover.datatable#surveys
%thead
%th Title
%th When
%th Start Date
%th End Date
%th Actions
%tbody
- @surveys.each_with_index do |survey, index|
%tr
%td
= link_to survey.title, admin_conference_survey_path(@conference.short_title, survey)
%td
= survey.target
%td
= survey.start_date
%td
= survey.end_date
%td
.btn-group
= link_to 'Edit', edit_admin_conference_survey_path(@conference.short_title, survey),
class: 'btn btn-primary'
= link_to 'Delete', admin_conference_survey_path(@conference.short_title, survey),
method: :delete, class: 'btn btn-danger',
data: { confirm: "Do you really want to delete #{survey.title}?"}

View file

@ -0,0 +1 @@
= render partial: 'form'

View file

@ -0,0 +1,20 @@
.row
.col-md-12
.page-header
%h1
Survey: #{@survey.title}
= link_to 'Edit Survey', edit_admin_conference_survey_path(@conference.short_title, @survey), class: 'btn btn-primary pull-right'
%p.text-muted
From:
= @survey.start_date
to
= @survey.end_date
.row
.col-md-12
= semantic_form_for 'survey_submission', url: '#' do |f|
- @survey.survey_questions.each.with_index(1) do |survey_question, question_index|
.row
.col-md-12
- survey_reply = survey_question.survey_replies.new(survey_question_id: survey_question.id, user_id: current_user.id)
= render partial: 'survey_question', locals: { survey_question: survey_question, question_index: question_index, survey_reply: survey_reply }
= link_to 'Add Question', new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), class: 'btn btn-success pull-right'