fixes #50 - summary page progress on saves
This commit is contained in:
parent
76bb21a150
commit
2c7948903d
@ -1,5 +1,5 @@
|
|||||||
function updateResults(elem) {
|
function updateResults(elem) {
|
||||||
if ($(elem).length ===0){return false;};
|
if ($(elem).length ===0){return false;}
|
||||||
|
|
||||||
var resultsContainer = $(elem).find('[data-id="results"]')[0];
|
var resultsContainer = $(elem).find('[data-id="results"]')[0];
|
||||||
var codeHtml = $(elem).find('.code-html')[0].value.trim();
|
var codeHtml = $(elem).find('.code-html')[0].value.trim();
|
||||||
|
@ -32,11 +32,22 @@ function updateLocalValues($form){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateProgress(data) {
|
||||||
|
$(".progress-bar").attr('aria-valuenow', data.progress)
|
||||||
|
.attr('style','width: '+ data.progress +'%;')
|
||||||
|
.find('span').text(data.progress + '%');
|
||||||
|
if(data.can_submit === true){
|
||||||
|
$('#summary-submit').find('.error').remove();
|
||||||
|
$('#summary-submit').find('.submit-button').prop('disabled', false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function prepareAjax($form) {
|
function prepareAjax($form) {
|
||||||
$form.on("ajax:success", function(e, data){
|
$form.on("ajax:success", function(e, data){
|
||||||
$form.prepend('<div class="success">' + data.message + '</div>');
|
$form.prepend('<div class="success">' + data.message + '</div>');
|
||||||
disableForm($form);
|
disableForm($form);
|
||||||
updateLocalValues($form);
|
updateLocalValues($form);
|
||||||
|
updateProgress(data);
|
||||||
}).on("ajax:error", function(e, xhr) {
|
}).on("ajax:error", function(e, xhr) {
|
||||||
if (xhr.status === 400){
|
if (xhr.status === 400){
|
||||||
$form.prepend('<div class="error">' + xhr.responseJSON.join('<br>') + '</div>');
|
$form.prepend('<div class="error">' + xhr.responseJSON.join('<br>') + '</div>');
|
||||||
|
@ -29,6 +29,10 @@ label {
|
|||||||
font-weight: 300;
|
font-weight: 300;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
form.btn-center {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
#{$all-text-inputs} {
|
#{$all-text-inputs} {
|
||||||
display: block;
|
display: block;
|
||||||
font-size: $base-font-size;
|
font-size: $base-font-size;
|
||||||
|
@ -11,9 +11,10 @@ class QuizController < ApplicationController
|
|||||||
|
|
||||||
def update_answer
|
def update_answer
|
||||||
@answer = prep_answer answer_params[:question_id]
|
@answer = prep_answer answer_params[:question_id]
|
||||||
|
prep_status
|
||||||
send "process_#{prep_question(answer_params[:question_id]).input_type}"
|
send "process_#{prep_question(answer_params[:question_id]).input_type}"
|
||||||
route_remote and return if request.xhr?
|
route_answer_xhr and return if request.xhr?
|
||||||
route_answer
|
route_answer_html
|
||||||
end
|
end
|
||||||
|
|
||||||
def summary
|
def summary
|
||||||
@ -21,11 +22,10 @@ class QuizController < ApplicationController
|
|||||||
redirect_to :question and return unless prep_status.current_question_id.nil?
|
redirect_to :question and return unless prep_status.current_question_id.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_summary
|
def submit_summary
|
||||||
prep_status
|
|
||||||
not_completed_error = 'You must complete all questions to submit your test.'
|
not_completed_error = 'You must complete all questions to submit your test.'
|
||||||
record_error = 'There was a problem with your submission. Please try again later.'
|
record_error = 'There was a problem with your submission. Please try again later.'
|
||||||
redirect_to :summary, flash: { error: not_completed_error } and return unless @status.can_submit
|
redirect_to :summary, flash: { error: not_completed_error } and return unless prep_status.can_submit
|
||||||
redirect_to :thankyou and return if current_candidate.complete!
|
redirect_to :thankyou and return if current_candidate.complete!
|
||||||
redirect_to :summary, flash: { error: record_error }
|
redirect_to :summary, flash: { error: record_error }
|
||||||
end
|
end
|
||||||
@ -62,9 +62,8 @@ class QuizController < ApplicationController
|
|||||||
answer
|
answer
|
||||||
end
|
end
|
||||||
|
|
||||||
def route_answer
|
def route_answer_html
|
||||||
if @answer.errors.present?
|
if @answer.errors.present?
|
||||||
prep_status
|
|
||||||
prep_question answer_params[:question_id]
|
prep_question answer_params[:question_id]
|
||||||
flash[:error] = answer_params[:question_id].to_i
|
flash[:error] = answer_params[:question_id].to_i
|
||||||
render :question
|
render :question
|
||||||
@ -75,11 +74,16 @@ class QuizController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def route_remote
|
def route_answer_xhr
|
||||||
if @answer.errors.present?
|
if @answer.errors.present?
|
||||||
render json: @answer.errors["answer"].to_json, status: 400
|
render json: @answer.errors["answer"].to_json, status: 400
|
||||||
else
|
else
|
||||||
render json: { message: "Your answer has been updated successfully!" }.to_json
|
results = {
|
||||||
|
message: "Your answer has been updated successfully!",
|
||||||
|
can_submit: prep_status.can_submit,
|
||||||
|
progress: prep_status.progress
|
||||||
|
}
|
||||||
|
render json: results.to_json
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -43,11 +43,10 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if @status.can_submit %>
|
<%= form_tag post_summary_path, id: 'summary-submit', class: "btn-center" do %>
|
||||||
<%= form_tag post_summary_path, class: "btn-container-right" do %>
|
<% unless @status.can_submit %>
|
||||||
<input type="submit" class="submit-button" value="Submit all answers" name="submit" />
|
|
||||||
<% end %>
|
|
||||||
<% else %>
|
|
||||||
<div class="error">Sorry, you must answer all questions before you can submit.</div>
|
<div class="error">Sorry, you must answer all questions before you can submit.</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<%= submit_tag "Submit all answers", {class: 'submit-button', disabled: !@status.can_submit } %>
|
||||||
|
<% end %>
|
||||||
</main>
|
</main>
|
||||||
|
@ -9,7 +9,7 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
post "/question(/:answer_id)", to: "quiz#update_answer", as: :post_answer
|
post "/question(/:answer_id)", to: "quiz#update_answer", as: :post_answer
|
||||||
get "/question(/:question_id)", to: "quiz#question", as: :question
|
get "/question(/:question_id)", to: "quiz#question", as: :question
|
||||||
post "/summary", to: "quiz#update_summary", as: :post_summary
|
post "/summary", to: "quiz#submit_summary", as: :post_summary
|
||||||
get "/summary", to: "quiz#summary", as: :summary
|
get "/summary", to: "quiz#summary", as: :summary
|
||||||
|
|
||||||
get "/review/logout", to: "review#logout", as: :review_logout
|
get "/review/logout", to: "review#logout", as: :review_logout
|
||||||
|
Loading…
Reference in New Issue
Block a user