diff --git a/app/models/plan.rb b/app/models/plan.rb index e28b8d3..4c5f974 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -289,7 +289,7 @@ answers.id as answerid, answers.plan_id as plan_id, answers.text as answertext, - answers.created_at as created, + answers.updated_at as updated, users.email as username') .where("questions.id in (?) and answers.plan_id = ?",question_ids, self.id) .to_a @@ -305,7 +305,7 @@ plan: rec.plan_id, id: rec.answerid, text: rec.answertext, - created: rec.created, + updated: rec.updated, user: rec.username } end @@ -326,7 +326,7 @@ aid = answer.nil? ? nil : answer[:id] atext = answer.nil? ? nil : answer[:text] - created = answer.nil? ? nil : answer[:created] + updated = answer.nil? ? nil : answer[:updated] uname = answer.nil? ? nil : answer[:user] space_used += height_of_text(stitle, 1, 1) @@ -356,7 +356,7 @@ status["questions"][qid] = { "format" => format, "answer_id" => aid, - "answer_created_at" => created.to_i, + "answer_updated_at" => updated.to_i, "answer_text" => atext, "answered_by" => uname } diff --git a/lib/assets/javascripts/plans.js b/lib/assets/javascripts/plans.js index aa1323a..89ac3d6 100644 --- a/lib/assets/javascripts/plans.js +++ b/lib/assets/javascripts/plans.js @@ -91,35 +91,21 @@ // Handle section actions on accordion expansion/collapse $('.section-collapse').on('show', function() { var section = $(this); - section.find(".loaded").show(); - section.find(".loading").show(); - // Only lock if there are forms on the page (not read-only) - //if ($('.question-form').length > 0) { - // section.check_section_lock(); - section.find(".question-form").show(); - // check for updated answers - // I (Ray) think we no longer want this but this needs - // replaced by the optimistic locking but I'm leaving it - // till the locking is re-imp0lemented -// $.getJSON("status.json", function(data) { -// $.fn.update_plan_progress(data); -// $(".section-status").each(function(){ -// $(this).update_section_progress(data); -// }); -// //For each question in section, check answer timestamp against currently displayed -// var section_id = section.attr("id").split('-')[1]; -// var num_questions = data.sections[section_id]["questions"].length; -// for (var i = 0; i < num_questions; i++) { -// question_id = data.sections[section_id]["questions"][i]; -// //If timestamp newer than displayed, update answers -// if ($.fn.update_timestamp(question_id, data)) { -// $.fn.update_answer(question_id); -// } -// } -// section.find(".loading").hide(); -// section.find(".loaded").show(); -// }); + $.getJSON("status.json", function(data) { + $.fn.update_plan_progress(data); + $(".section-status").each(function(){ + $(this).update_section_progress(data); + }); + + //For each question in section, check answer timestamp against currently displayed + var section_id = section.attr("id").split('-')[1]; + var num_questions = data.sections[section_id]["questions"].length; + for (var i = 0; i < num_questions; i++) { + question_id = data.sections[section_id]["questions"][i]; + $.fn.update_timestamp(question_id, data) + } + }); }).on('hide', function(){ var section = $(this); // Only attempt unlock if there are forms on the page (not read-only) @@ -355,70 +341,6 @@ return false; }; -$.fn.update_answer = function(question_id) { - $.ajax({ - type: 'GET', - url: "answer.json?q_id="+question_id, - dataType: 'json', - async: false, //Needs to be synchronous, otherwise end up mixing up answers - success: function(data) { - if (data != null) { - //Get divs containing the form and readonly versions - var form_div = $("#question-form-"+question_id); - var readonly_div = $("#question-readonly-"+question_id); - //Look for textfields - if ($("input#answer-text-"+question_id).length == 1) { - $("input#answer-text-"+question_id).val(data.text); - readonly_div.find('.answer-text-readonly').html("
"+data.text+"
"); - } - else { - //Update answer text - both in textarea and readonly - $('#answer-text-'+question_id).val(data.text); - tinymce.get('answer-text-'+question_id).setContent(data.text); - readonly_div.find('.answer-text-readonly').html(data.text); - } - //Update answer options - both in form and readonly - num_options = data.options.length; - form_div.find('option').each(function(){ - var selected = false; - for (var j =0; j < num_options; j++) { - if ($(this).val() == data.options[j].id) { - selected = true; - } - } - if (selected) { - $(this).attr('selected', 'selected'); - } - else { - $(this).removeAttr('selected'); - } - }); - form_div.find(':checkbox,:radio').each(function(){ - var selected = false; - for (var j =0; j < num_options; j++) { - if ($(this).val() == data.options[j].id) { - selected = true; - } - } - if (selected) { - $(this).attr('checked', 'checked'); - } - else { - $(this).removeAttr('checked'); - } - }); - - var list_string = ""; - for (var j =0; j < num_options; j++) { - list_string += "