-
Notifications
You must be signed in to change notification settings - Fork 491
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
1,143 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
$(function() { | ||
$('.selectpicker').on('changed.bs.select', function (e, clickedIndex) { | ||
$('.kinds').addClass('hidden'); | ||
var selected = $('.selectpicker').find('option:selected').val(); | ||
$('.' + selected).removeClass('hidden'); | ||
|
||
if (selected == 'choice') { | ||
$('.survey-possible-answers').removeClass('hidden'); | ||
} | ||
else | ||
{ | ||
$('.survey-possible-answers').addClass('hidden'); | ||
} | ||
}); | ||
$('#survey_question_title').on('keyup', function(){ | ||
$('#survey_question_preview #title').text($(this).val()) | ||
}); | ||
|
||
function render_possible_answers_preview() { | ||
var options_html = ''; | ||
var options_array = $('#survey_question_possible_answers').val().split(','); | ||
var input_type = ($('#survey_question_min_choices').val() == 1 && | ||
$('#survey_question_max_choices').val() == 1) ? 'radio' : 'checkbox'; | ||
$.each(options_array, function(index, option) { | ||
options_html += '<input type="' + input_type + '" name="preview_option"/> ' + option.trim() + '<br/>'; | ||
}); | ||
$('#survey_question_preview .choice').html(options_html) | ||
}; | ||
|
||
$('#survey_question_possible_answers').on('keyup', render_possible_answers_preview); | ||
$('#survey_question_min_choices').on('change', render_possible_answers_preview); | ||
$('#survey_question_max_choices').on('change', render_possible_answers_preview); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ | |
*= require selectize | ||
*= require selectize.bootstrap3 | ||
*= require mastodon | ||
*= require bootstrap-select | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module Admin | ||
class SurveyQuestionsController < Admin::BaseController | ||
load_and_authorize_resource :conference, find_by: :short_title | ||
load_and_authorize_resource :survey | ||
load_and_authorize_resource through: :survey | ||
|
||
def new | ||
@survey_question = @survey.survey_questions.new(min_choices: 1, max_choices: 1) | ||
@url = admin_conference_survey_survey_questions_path(@conference.short_title, @survey) | ||
end | ||
|
||
def create | ||
@survey_question = @survey.survey_questions.new(survey_question_params) | ||
if @survey_question.save | ||
redirect_to admin_conference_survey_path(@conference.short_title, @survey), notice: 'Successfully created Survey Question.' | ||
else | ||
@url = admin_conference_survey_survey_questions_path(@conference.short_title, @survey) | ||
render :new | ||
end | ||
end | ||
|
||
# GET questions/1/edit | ||
def edit | ||
@url = admin_conference_survey_survey_question_path(@conference.short_title, @survey, @survey_question) | ||
end | ||
|
||
# PUT questions/1 | ||
def update | ||
if @survey_question.update_attributes(survey_question_params) | ||
redirect_to admin_conference_survey_path(@conference.short_title, @survey), notice: 'Successfully updated Survey Question.' | ||
else | ||
@url = admin_conference_survey_survey_question_path(@conference.short_title, @survey, @survey_question) | ||
render :edit | ||
end | ||
end | ||
|
||
# DELETE questions/1 | ||
def destroy | ||
if @survey_question.destroy | ||
redirect_to admin_conference_survey_path(@conference.short_title, @survey), notice: 'Successfully deleted Survey Question.' | ||
else | ||
redirect_to admin_conference_survey_path(@conference.short_title, @survey), error: "Can't delete this Survey Question" | ||
end | ||
end | ||
|
||
private | ||
|
||
def survey_question_params | ||
params.require(:survey_question).permit(:title, :kind, :possible_answers, :min_choices, :max_choices, :mandatory) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Admin | ||
class SurveysController < Admin::BaseController | ||
load_and_authorize_resource :conference, find_by: :short_title | ||
load_and_authorize_resource | ||
|
||
def index | ||
@surveys = @conference.surveys + Survey.where(surveyable: @conference.program.events) | ||
end | ||
|
||
def new | ||
@survey = Survey.new(survey_params) | ||
@url = admin_conference_surveys_path(@conference.short_title) | ||
end | ||
|
||
def create | ||
@survey = Survey.new(survey_params) | ||
if @survey.save | ||
redirect_to new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), notice: 'Successfully created survey' | ||
else | ||
redirect_to new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), error: 'Could not create survey.' + @survey.errors.full_messates.to_sentence | ||
end | ||
end | ||
|
||
def edit | ||
@url = admin_conference_survey_path(@conference.short_title, @survey) | ||
end | ||
|
||
def update | ||
if @survey.update_attributes(survey_params) | ||
redirect_to admin_conference_surveys_path(@conference.short_title) | ||
else | ||
@url = admin_conference_survey_path(@conference.short_title, @survey) | ||
render action: :edit | ||
end | ||
end | ||
|
||
def destroy | ||
@survey.destroy | ||
redirect_to admin_conference_surveys_path(@conference.short_title) | ||
end | ||
|
||
private | ||
|
||
def survey_params | ||
params.require(:survey).permit(:title, :description, :target, :start_date, :end_date, :surveyable_type, :surveyable_id) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class SurveysController < ApplicationController | ||
load_resource :conference, find_by: :short_title | ||
load_and_authorize_resource except: :reply | ||
load_resource only: :reply | ||
skip_authorization_check only: :reply | ||
|
||
def index | ||
@surveys = @conference.surveys.select(&:active?) | ||
end | ||
|
||
def show | ||
@survey_submission = @survey.survey_submissions.new | ||
end | ||
|
||
def reply | ||
unless can? :reply, @survey | ||
redirect_to conference_survey_path(@conference, @survey), alert: 'This survey is currently closed' | ||
return | ||
end | ||
|
||
survey_submission = params[:survey_submission] | ||
|
||
@survey.survey_questions.each do |survey_question| | ||
reply = survey_question.survey_replies.find_by(user: current_user) | ||
reply_text = survey_submission[survey_question.id.to_s].reject(&:blank?).join(',') | ||
|
||
if reply | ||
reply.update_attributes(text: reply_text) unless reply.text == reply_text | ||
else | ||
survey_question.survey_replies.create!(text: reply_text, user: current_user) | ||
end | ||
|
||
user_survey_submission = @survey.survey_submissions.find_by(user: current_user) | ||
if user_survey_submission | ||
user_survey_submission.update_attributes(updated_at: Time.current) | ||
else | ||
@survey.survey_submissions.create!(user: current_user) | ||
end | ||
end | ||
|
||
redirect_to :back | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.