From: phasefx Date: Mon, 15 Mar 2010 09:52:49 +0000 (+0000) Subject: Fix some broken survey handling. The patron editor (legacy, haven't checked newer... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=031046bcddf8cac44c312811fad4531337849ada;p=Evergreen.git Fix some broken survey handling. The patron editor (legacy, haven't checked newer one yet) was only saving the response for the first question in any given survey, and the Info/Other -> Survey display screen was likewise mishandling survey responses and giving an ugly error for multi-question surveys. git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_6_0@15845 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/xul/staff_client/server/patron/info_surveys.xul b/Open-ILS/xul/staff_client/server/patron/info_surveys.xul index 3d38bac7c7..6877bcc27d 100644 --- a/Open-ILS/xul/staff_client/server/patron/info_surveys.xul +++ b/Open-ILS/xul/staff_client/server/patron/info_surveys.xul @@ -72,7 +72,16 @@ 'FM_ASVR_RETRIEVE', [ ses(), surveys[i].id(), g.patron_id ] ); - g.survey_responses[ surveys[i].id() ] = responses; + g.survey_responses[ surveys[i].id() ] = {}; + for (var j = 0; j < responses.length; j++) { + if (! g.survey_responses[ responses[j].survey() ]) { + g.survey_responses[ responses[j].survey() ] = {}; + } + if (! g.survey_responses[ responses[j].survey() ][ responses[j].question() ]) { + g.survey_responses[ responses[j].survey() ][ responses[j].question() ] = []; + } + g.survey_responses[ responses[j].survey() ][ responses[j].question() ].push( responses[j] ); + } } } catch(E) { g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.info_surveys.retrieve_surveys.failed'),E); @@ -96,19 +105,18 @@ function render_surveys() { JSAN.use('util.widgets'); util.widgets.remove_children('surveys_panel'); var sp = $('surveys_panel'); - - for (var i in g.survey_responses) { + for (var survey_id in g.survey_responses) { /* template */ var asv_node = $('asv_template').cloneNode(true); sp.appendChild(asv_node); asv_node.hidden = false; - apply(asv_node,'id',g.data.hash.asv[i].id()); - apply(asv_node,'description',g.data.hash.asv[i].description()); - if (g.data.hash.asv[i].required()) { + apply(asv_node,'id',g.data.hash.asv[survey_id].id()); + apply(asv_node,'description',g.data.hash.asv[survey_id].description()); + if (g.data.hash.asv[survey_id].required()) { apply(asv_node, 'required', $("patronStrings").getString('staff.patron.info_surveys.render_surveys.required')); } else { apply(asv_node, 'required', $("patronStrings").getString('staff.patron.info_surveys.render_surveys.not_required')); } - if (g.data.hash.asv[i].opac()) { + if (g.data.hash.asv[survey_id].opac()) { apply(asv_node, 'opac', $("patronStrings").getString('staff.patron.info_stat_cats.render_stat_cats.opac_visible')); } else { apply(asv_node, 'opac', $("patronStrings").getString('staff.patron.info_stat_cats.render_stat_cats.not_opac_visible')); @@ -119,7 +127,7 @@ if (nl.length>0) question_placeholder = nl[0]; if (question_placeholder) { - var questions = g.data.hash.asv[i].questions(); + var questions = g.data.hash.asv[survey_id].questions(); for (var j = 0; j < questions.length; j++) { /* template */ @@ -133,16 +141,17 @@ var nl2 = asvq_node.getElementsByAttribute('name','answer'); var answer_placeholder; if (nl2.length>0) answer_placeholder = nl2[0]; - if (answer_placeholder && g.survey_responses[i].length > 0) { + if (answer_placeholder && g.survey_responses[survey_id]) { /* template */ var asva_node = $('asva_template').cloneNode(true); answer_placeholder.appendChild(asva_node); asva_node.hidden = false; - var last_response = g.survey_responses[i][ g.survey_responses[i].length - 1 ]; + var question_responses = g.survey_responses[survey_id][ questions[j].id() ]; + if (!question_responses || question_responses.length < 1) { continue; } + var last_response = question_responses[ question_responses.length - 1 ]; var date = last_response.effective_date() ? last_response.effective_date() : last_response.answer_date(); date = util.date.formatted_date( date, '%D' ); var answer = util.functional.find_id_object_in_list( questions[j].answers(), last_response.answer() ); - apply(asva_node,'answer',answer.answer()); apply(asva_node,'date',date); } diff --git a/Open-ILS/xul/staff_client/server/patron/ue_ui.js b/Open-ILS/xul/staff_client/server/patron/ue_ui.js index afa17ca67e..6204256352 100644 --- a/Open-ILS/xul/staff_client/server/patron/ue_ui.js +++ b/Open-ILS/xul/staff_client/server/patron/ue_ui.js @@ -216,6 +216,8 @@ function uEditInsertCat( row, cat, idx ) { /* draw the surveys */ function uEditDrawSurveys(surveys) { + patron.survey_responses([]); /* clear out all surveys up front */ + var div = $('uedit_surveys'); var table = div.removeChild($('ue_survey_table')); if( surveys.length == 0 ) unHideMe($('uedit_no_surveys')); @@ -265,11 +267,11 @@ function uEditInsertSurveyQuestion( row, survey, question ) { selector.onchange = function() { - /* remove any existing responses for this survey */ + /* remove any existing responses for this question */ patron.survey_responses( grep( patron.survey_responses(), function(item) { - return (item.survey() != survey.id()); + return (item.question() != row.getAttribute('question')); } ) );