]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/info_surveys.xul
some i18n goodness and fixes. And an extra column for patron lists, and including...
[Evergreen.git] / Open-ILS / xul / staff_client / server / patron / info_surveys.xul
1 <?xml version="1.0"?>
2 <!-- Application: Evergreen Staff Client -->
3 <!-- Screen: Patron Display -->
4
5 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
6 <!-- STYLESHEETS -->
7 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
8 <?xml-stylesheet href="chrome://open_ils_staff_client/skin/global.css" type="text/css"?>
9 <?xml-stylesheet href="/xul/server/skin/global.css" type="text/css"?>
10 <?xml-stylesheet href="/xul/server/skin/patron_display.css" type="text/css"?>
11
12 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
13 <!-- LOCALIZATION -->
14 <!DOCTYPE window PUBLIC "" ""[
15         <!--#include virtual="/opac/locale/en-US/lang.dtd"-->
16 ]>
17
18 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
19 <!-- OVERLAYS -->
20 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
21
22 <window id="patron_info_surveys_win" width="700" height="550"
23         onload="try{ my_init(); font_helper(); } catch(E) { alert(E); }"
24         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
25
26         <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
27         <!-- BEHAVIOR -->
28         <script type="text/javascript">var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};</script>
29         <scripts id="openils_util_scripts"/>
30
31         <script type="text/javascript" src="/xul/server/main/JSAN.js"/>
32         <script>
33         <![CDATA[
34
35                 function $(id) { return document.getElementById(id); }
36
37                 function my_init() {
38                         try {
39                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
40                                 if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
41                                 JSAN.errorLevel = "die"; // none, warn, or die
42                                 JSAN.addRepository('/xul/server/');
43
44                                 JSAN.use('util.error'); g.error = new util.error();
45                                 JSAN.use('util.network'); g.network = new util.network();
46                                 JSAN.use('util.date'); JSAN.use('util.money'); JSAN.use('util.functional');
47                                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
48
49                                 g.error.sdump('D_TRACE','my_init() for patron_info_surveys.xul');
50
51                                 g.patron_id = xul_param('patron_id');
52
53                                 refresh();
54
55                         } catch(E) {
56                                 var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
57                                         "system administrator or software developer the following:\npatron_info_surveys.xul\n" + E + '\n';
58                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
59                                 alert(err_msg);
60                         }
61                 }
62
63                 function refresh() {
64                         retrieve_surveys(); render_surveys();
65                 }
66
67                 function retrieve_surveys() {
68                         try {
69                                 var surveys = g.data.list.my_asv;
70                                 g.survey_responses = {};
71                                 for (var i = 0; i < surveys.length; i++) {
72                                         var responses = g.network.simple_request(
73                                                 'FM_ASVR_RETRIEVE',
74                                                 [ ses(), surveys[i].id(), g.patron_id ]
75                                         );
76                                         g.survey_responses[ surveys[i].id() ] = responses;
77                                 }
78                         } catch(E) {
79                                 g.error.standard_unexpected_error_alert('Failed to retrieve all the survey responses.',E);
80                         }
81
82                 }
83
84                 function apply(node,field,value) {
85                         util.widgets.apply(
86                                 node,'name',field,
87                                 function(n) {
88                                         switch(n.nodeName) {
89                                                 case 'description' : n.appendChild( document.createTextNode( value ) ); break;
90                                                 case 'label' : n.value = value; break;
91                                                 default : n.value = value; break;
92                                         }
93                                 }
94                         );
95                 }
96
97                 function render_surveys() {
98                         JSAN.use('util.widgets'); util.widgets.remove_children('surveys_panel');
99                         var sp = $('surveys_panel');
100
101                         for (var i in g.survey_responses) {
102
103                                 /* template */
104                                 var asv_node = $('asv_template').cloneNode(true); sp.appendChild(asv_node); asv_node.hidden = false;
105                                 apply(asv_node,'id',g.data.hash.asv[i].id());
106                                 apply(asv_node,'description',g.data.hash.asv[i].description());
107                                 apply(asv_node,'required',g.data.hash.asv[i].required() ? 'Required' : 'Not Required');
108                                 apply(asv_node,'opac',g.data.hash.asv[i].opac() ? 'OPAC Visible' : 'Not OPAC Visible');
109
110                                 var nl = asv_node.getElementsByAttribute('name','questions');
111                                 var question_placeholder;
112                                 if (nl.length>0) question_placeholder = nl[0];
113                                 if (question_placeholder) {
114
115                                         var questions = g.data.hash.asv[i].questions();
116                                         for (var j = 0; j < questions.length; j++) {
117
118                                                 /* template */
119                                                 var asvq_node = $('asvq_template').cloneNode(true); question_placeholder.appendChild(asvq_node); asvq_node.hidden = false;
120                                                 apply(asvq_node,'ordinal',j+1);
121                                                 apply(asvq_node,'question',questions[j].question());
122
123                                                 var nl2 = asvq_node.getElementsByAttribute('name','answer');
124                                                 var answer_placeholder;
125                                                 if (nl2.length>0) answer_placeholder = nl2[0];
126                                                 if (answer_placeholder && g.survey_responses[i].length > 0) {
127
128                                                         /* template */
129                                                         var asva_node = $('asva_template').cloneNode(true); answer_placeholder.appendChild(asva_node); asva_node.hidden = false;
130
131                                                         var last_response = g.survey_responses[i][ g.survey_responses[i].length - 1 ];
132                                                         var date = last_response.effective_date() ? last_response.effective_date() : last_response.answer_date();
133                                                         date = util.date.formatted_date( date, '%D' );
134                                                         var answer = util.functional.find_id_object_in_list( questions[j].answers(), last_response.answer() );
135
136                                                         apply(asva_node,'answer',answer.answer());
137                                                         apply(asva_node,'date',date);
138                                                 }
139                                         }
140
141                                 }
142
143                         }
144
145                 }
146                 
147         ]]>
148         </script>
149
150         <stack hidden="true" id="asv_template" flex="1">
151                 <groupbox flex="1" style="background-color: black;"/>
152                 <groupbox flex="1" style="background-color: #CC9966; -moz-border-radius-topright: 35px;" >
153                         <hbox>
154                                 <label value="Survey #" style="font-weight: bold"/>
155                                 <label name="id" style="font-weight: bold"/>
156                                 <description name="description" style="font-weight: bold"/>
157                                 <spacer flex="1"/>
158                                 <description name="required" style="font-weight: bold"/>
159                                 <description name="opac" style="font-weight: bold"/>
160                         </hbox>
161                         <vbox name="questions"/>
162                 </groupbox>
163         </stack>
164
165         <grid hidden="true" id="asvq_template" flex="1">
166                 <columns><column/><column flex="1"/></columns>
167                 <rows>
168                         <row><label name="ordinal"/><label name="question"/></row>
169                         <row><spacer /><vbox name="answer"/></row>
170                 </rows>
171         </grid>
172
173         <hbox hidden="true" id="asva_template" flex="1">
174                 <label value="Last Answered on:"/><label name="date"/>
175                 <label value="Answer:"/><description style="font-weight: bold" name="answer"/>
176         </hbox>
177
178         <vbox flex="1" class="my_overflow" id="surveys_panel">
179         </vbox>
180
181
182 </window>
183