Summary edit 3 primary input types
This commit is contained in:
parent
bc003eecd1
commit
115fca9009
@ -93,7 +93,7 @@ var saveClickHandler = function(e) {
|
|||||||
var executeQuery;
|
var executeQuery;
|
||||||
var questionId = thisEd.find('.button-edit').attr('data-questionid');
|
var questionId = thisEd.find('.button-edit').attr('data-questionid');
|
||||||
|
|
||||||
if (thisEd.find('textarea.code-answer')) {
|
if (thisEd.hasClass('live_code-type')) {
|
||||||
var htmlAnswer = $(thisEd.find('textarea.code-html')[0]).val();
|
var htmlAnswer = $(thisEd.find('textarea.code-html')[0]).val();
|
||||||
var cssAnswer = $(thisEd.find('textarea.code-css')[0]).val();
|
var cssAnswer = $(thisEd.find('textarea.code-css')[0]).val();
|
||||||
var jsAnswer = $(thisEd.find('textarea.code-js')[0]).val();
|
var jsAnswer = $(thisEd.find('textarea.code-js')[0]).val();
|
||||||
@ -102,29 +102,38 @@ var saveClickHandler = function(e) {
|
|||||||
'css': cssAnswer,
|
'css': cssAnswer,
|
||||||
'js': jsAnswer
|
'js': jsAnswer
|
||||||
}
|
}
|
||||||
} else if(thisEd.find('input').attr('type')=='radio') {
|
} else if(thisEd.hasClass('radio-type')) {
|
||||||
$(thisEd.find('input')).each(function() {
|
$(thisEd.find('input')).each(function() {
|
||||||
if($(this).prop('checked')==true) {
|
if($(this).prop('checked')==true) {
|
||||||
data = $(this).val();
|
data = ({
|
||||||
|
'radio': $(this).val()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if(thisEd.find('input').attr('type')=='checkbox') {
|
} else if(thisEd.hasClass('checkbox-type')) {
|
||||||
|
data = {'checkbox': []};
|
||||||
|
|
||||||
$(thisEd.find('input')).each(function() {
|
$(thisEd.find('input')).each(function() {
|
||||||
if($(this).prop('checked')==true) {
|
if($(this).prop('checked')==true) {
|
||||||
data.push($(this).val());
|
data.checkbox.push($(this).val());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
data = thisEd.find('textarea').val();
|
data = {'text': thisEd.find('textarea').val()};
|
||||||
}
|
}
|
||||||
if(data == '') {
|
if(data == '') {
|
||||||
$(thisEd).before('<div class="error">Please select or enter a value.</div>');
|
$(thisEd).before('<div class="error">Please select or enter a value.</div>');
|
||||||
} else {
|
} else {
|
||||||
thisEd.find('textarea:not(.code-answer)').replaceWith('<p class="text-answer answer-container">' + $.trim(thisEd.find('textarea').val()) + '</p>');
|
thisEd.find('textarea:not(.code-answer)').replaceWith('<p class="text-answer answer-container">' + $.trim(thisEd.find('textarea').val()) + '</p>');
|
||||||
|
url = thisEd.closest('form').attr('action');
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/summary",
|
url: url,
|
||||||
data:{ id: questionId, answer: data},
|
data: ({
|
||||||
|
'answer': data,
|
||||||
|
'submit': true
|
||||||
|
}),
|
||||||
success: function(data){
|
success: function(data){
|
||||||
executeQuery = true;
|
executeQuery = true;
|
||||||
//console.log(data);
|
//console.log(data);
|
||||||
|
@ -22,7 +22,8 @@ class CandidateController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update_answer
|
def update_answer
|
||||||
qid = prep_status.current_question_id
|
qid = params[:qid] ||= prep_status.current_question_id
|
||||||
|
@answer = prep_answer qid
|
||||||
send "process_#{prep_question(qid).input_type}"
|
send "process_#{prep_question(qid).input_type}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -68,8 +69,8 @@ class CandidateController < ApplicationController
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def prep_answer
|
def prep_answer qid = answer_params[:question_id]
|
||||||
answer_ids = { question_id: answer_params[:question_id], candidate_id: current_candidate.to_i }
|
answer_ids = { question_id: qid, candidate_id: current_candidate.to_i }
|
||||||
answer = Answer.find_or_create_by(answer_ids)
|
answer = Answer.find_or_create_by(answer_ids)
|
||||||
answer
|
answer
|
||||||
end
|
end
|
||||||
@ -89,7 +90,6 @@ class CandidateController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def process_text
|
def process_text
|
||||||
@answer = prep_answer
|
|
||||||
@answer.update(answer: answer_params[:text],
|
@answer.update(answer: answer_params[:text],
|
||||||
saved: params.key?(:save),
|
saved: params.key?(:save),
|
||||||
submitted: params.key?(:submit))
|
submitted: params.key?(:submit))
|
||||||
@ -97,7 +97,6 @@ class CandidateController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def process_radio
|
def process_radio
|
||||||
@answer = prep_answer
|
|
||||||
@answer.update(answer: answer_params[:radio],
|
@answer.update(answer: answer_params[:radio],
|
||||||
saved: params.key?(:save),
|
saved: params.key?(:save),
|
||||||
submitted: params.key?(:submit))
|
submitted: params.key?(:submit))
|
||||||
@ -105,7 +104,6 @@ class CandidateController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def process_checkbox
|
def process_checkbox
|
||||||
@answer = prep_answer
|
|
||||||
@answer.update(answer: answer_params[:checkbox],
|
@answer.update(answer: answer_params[:checkbox],
|
||||||
saved: params.key?(:save),
|
saved: params.key?(:save),
|
||||||
submitted: params.key?(:submit))
|
submitted: params.key?(:submit))
|
||||||
@ -113,7 +111,6 @@ class CandidateController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def process_live_code
|
def process_live_code
|
||||||
@answer = prep_answer
|
|
||||||
@answer.update(answer: answer_params[:live_code].to_h,
|
@answer.update(answer: answer_params[:live_code].to_h,
|
||||||
saved: params.key?(:save),
|
saved: params.key?(:save),
|
||||||
submitted: params.key?(:submit))
|
submitted: params.key?(:submit))
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<% @quiz.each do |question| %>
|
<% @quiz.each do |question| %>
|
||||||
<%= form_for(:answer, url: post_summary_path, html:{id: 'summary-form'}) do |form| %>
|
<%= form_for(:answer, url: post_answer_path(answer_id: question.answer_id, qid: question.question_id), html:{class: 'summary-form'}) do |form| %>
|
||||||
<article class="answer-sec <%= question.input_type %>-type" data-qid="<%= question.question_id %>">
|
<article class="answer-sec <%= question.input_type %>-type" data-qid="<%= question.question_id %>">
|
||||||
<div class="question-heading">
|
<div class="question-heading">
|
||||||
<div class="question-title">
|
<div class="question-title">
|
||||||
|
Loading…
Reference in New Issue
Block a user