Adding surveys

This commit is contained in:
Stella Rouzi 2016-06-28 18:16:06 +03:00
parent 69a0d12793
commit 335608e6c4
28 changed files with 434 additions and 21 deletions

View file

@ -0,0 +1,4 @@
.nested-fields
= f.inputs do
= f.input :title
= remove_association_link :answer, f

View file

@ -0,0 +1,63 @@
.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.hidden
= f.input :possible_answers, hint: 'Comma separated', input_html: { rows: 3 }
%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.types.each do |type|
%option{ id: "#{type.second}", 'data-icon' => "fa fa-#{SurveyQuestion::ICONS[type.first.to_sym]}" }
= type.first
.col-md-6
.panel.panel-default
.panel-body
%p
What is your answer?
%div.kinds.boolean
%input{type: 'radio', name: 'radio'} Yes
%br
%input{type: 'radio', name: 'radio'} No
%div.kinds.choice.hidden
%input{ type: 'checkbox', name: 'checkbox' } Choice 1
%br
%input{ type: 'checkbox', name: 'checkbox' } Choice 2
%br
%input{ type: 'checkbox', name: 'checkbox' } Choice 3
%div.kinds.string.hidden
%input.form-control
%div.kinds.text.hidden
%textarea.form-control{ rows: 4 }
%div.kinds.datetime.hidden
%input.form-control{id: 'registration-arrival-datepicker', readonly: 'readonly'}
%div.kinds.numeric.hidden
%input.form-control{ type: 'number' }
= f.submit 'Save', class: 'btn btn-primary'

View file

@ -0,0 +1,27 @@
%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

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

View file

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

View file

@ -0,0 +1,32 @@
.row
.col-md-12
.page-header
%h1
Survey Questions
= "(#{@survey_questions.length})"
- if @survey_questions.any?
%table.table
%thead
%th
%th Title
%th Kind
%th Possible Answers
%th Mandatory
%th Answers
%th Actions
%tbody
- @survey_questions.each.with_index(1) do |survey_question, index|
%tr
%td= index
%td= survey_question.title
%td= survey_question.kind
%td= survey_question.possible_answers
%td= survey_question.mandatory
%td
%td
.btn-group
= link_to 'Edit', edit_admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question), class: 'btn btn-primary'
= link_to 'Delete', 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?' }, class: 'btn btn-danger'
= link_to 'Add', new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), class: 'btn btn-success pull-right'

View file

@ -0,0 +1,26 @@
.container
.row
.col-md-12
.page-header
%h1= @question.title
- @question.answers.each do |answer|
= answer.title
(#{answer.qanswers.find_by(question: @question).registrations.where(conference: @conference).count})
.row
.col-md-12
%table.table.table-border.table-hover.datatable#question_users
%thead
%th Name
%th Username
%th Email
%th Answer
%tbody
- @registrations.each do |registration|
%tr
%td= registration.name
%td= registration.username
%td= registration.email
%td= registration.qanswers.find_by(question: @question).answer.title

View file

@ -0,0 +1,14 @@
.row
.col-md-12
.page-header
%h1 New Survey
.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 :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 @@
= render partial: 'form'

View file

@ -0,0 +1,34 @@
.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#surveys
%thead
%th Title
%th Start Date
%th End Date
%th Actions
%tbody
- @surveys.each_with_index do |survey, index|
%tr
%td
= survey.title
%td
= survey.start_date
%td
= survey.end_date
%td
= link_to 'Edit', edit_admin_conference_survey_path(@conference.short_title, survey.id),
method: :get, class: 'btn btn-primary'
= link_to 'Delete', admin_conference_survey_path(@conference.short_title, survey.id),
method: :delete, class: 'btn btn-danger',
data: { confirm: "Do you really want to delete #{survey.title}?"}

View file

@ -0,0 +1,14 @@
.row
.col-md-12
.page-header
%h1 New Survey
.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 :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,6 @@
%p#notice= notice
= link_to 'Edit', edit_admin_survey_path(@admin_survey)
\|
= link_to 'Back', admin_surveys_path