[open-ils-commits] r15845 - branches/rel_1_6_0/Open-ILS/xul/staff_client/server/patron (phasefx)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Mar 15 05:52:55 EDT 2010


Author: phasefx
Date: 2010-03-15 05:52:49 -0400 (Mon, 15 Mar 2010)
New Revision: 15845

Modified:
   branches/rel_1_6_0/Open-ILS/xul/staff_client/server/patron/info_surveys.xul
   branches/rel_1_6_0/Open-ILS/xul/staff_client/server/patron/ue_ui.js
Log:
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.



Modified: branches/rel_1_6_0/Open-ILS/xul/staff_client/server/patron/info_surveys.xul
===================================================================
--- branches/rel_1_6_0/Open-ILS/xul/staff_client/server/patron/info_surveys.xul	2010-03-15 08:52:29 UTC (rev 15844)
+++ branches/rel_1_6_0/Open-ILS/xul/staff_client/server/patron/info_surveys.xul	2010-03-15 09:52:49 UTC (rev 15845)
@@ -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 survey_id in g.survey_responses) {
 
-			for (var i 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);
 						}

Modified: branches/rel_1_6_0/Open-ILS/xul/staff_client/server/patron/ue_ui.js
===================================================================
--- branches/rel_1_6_0/Open-ILS/xul/staff_client/server/patron/ue_ui.js	2010-03-15 08:52:29 UTC (rev 15844)
+++ branches/rel_1_6_0/Open-ILS/xul/staff_client/server/patron/ue_ui.js	2010-03-15 09:52:49 UTC (rev 15845)
@@ -216,6 +216,8 @@
 /* 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 @@
 
 	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'));
 				}
 			)
 		);



More information about the open-ils-commits mailing list