]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/main/gen_offline_widgets.xul
generate data dependent interfaces for offline mode
[Evergreen.git] / Open-ILS / xul / staff_client / server / main / gen_offline_widgets.xul
1 <?xml version="1.0"?>
2 <!-- Application: Evergreen Staff Client -->
3 <!-- Screen: Main, Authentication Window -->
4
5 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
6 <!-- PRESENTATION -->
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="chrome://open_ils_staff_client/skin/auth.css" type="text/css"?>
10
11 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
12 <!-- LOCALIZATION -->
13 <!DOCTYPE window PUBLIC "" ""[
14         <!--#include virtual="/opac/locale/en-US/lang.dtd"-->
15 ]>
16
17 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
18 <!-- OVERLAYS -->
19 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
20
21 <window id="gen_offline_menus_win" 
22         onload="try { gen_offline_menus_init(); } catch(E) { alert(E); }"
23         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
24
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="chrome://open_ils_staff_client/content/main/lang.js"/>
32         <script type="text/javascript" src="/xul/server/main/lang.js"/>
33         <script type="text/javascript" src="chrome://open_ils_staff_client/content/main/JSAN.js"/>
34         <script>
35         <![CDATA[
36
37                 function gen_offline_menus_init() {
38
39                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
40
41                         if (typeof JSAN == 'undefined') {
42                                 throw(
43                                         "The JSAN library object is missing."
44                                 );
45                         }
46                         /////////////////////////////////////////////////////////////////////////////
47
48                         JSAN.errorLevel = "die"; // none, warn, or die
49                         JSAN.addRepository('/xul/server/');
50
51                         JSAN.use('util.error'); g.error = new util.error();
52                         JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
53                         JSAN.use('util.network'); g.network = new util.network();
54                         JSAN.use('util.widgets');
55                         JSAN.use('util.functional');
56
57                         build_ou_menulist();
58                         save_xml('offline_ou_list',$('placeholder'));
59
60                         build_pgt_menulist();
61                         save_xml('offline_pgt_list',$('placeholder'));
62
63                         build_cit_menulist();
64                         save_xml('offline_cit_list',$('placeholder'));
65
66                         build_cnct_menulist();
67                         save_xml('offline_cnct_list',$('placeholder'));
68
69                         util.widgets.remove_children('placeholder');
70
71                         var label = document.createElement('label');
72                         label.setAttribute('value','Offline interface synchronized with server.');
73                         $('placeholder').appendChild( label );
74
75                 }
76
77                 function $(id) {
78                         return document.getElementById(id);
79                 }
80
81                 function save_xml(filename,node) {
82                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
83                         JSAN.use('util.file'); var file = new util.file(filename);
84
85                         var serializer = new XMLSerializer();
86                         var xml = serializer.serializeToString(node);
87
88                         file.write_content('truncate',xml);
89                         file.close();
90                 }
91
92                 function build_ou_menulist() {
93                         var x = document.getElementById('placeholder');
94                         util.widgets.remove_children( x );
95
96                         var ml = util.widgets.make_menulist( 
97                                 util.functional.map_list( 
98                                         g.data.list.aou,
99                                         function(obj) { return [ 
100                                                 obj.name() ? obj.shortname() + ' : ' + obj.name() : obj.shortname(), 
101                                                 obj.id(), 
102                                                 ( g.data.hash.aout[ obj.ou_type() ].can_have_users() == 0),
103                                                 ( g.data.hash.aout[ obj.ou_type() ].depth() ),
104                                         ]; }
105                                 ),
106                                 g.data.list.au[0].ws_ou()
107                         );
108
109                         x.appendChild( ml );
110                 }
111
112                 function build_pgt_menulist() {
113                         var x = document.getElementById('placeholder');
114                         util.widgets.remove_children( x );
115
116                         var ml = util.widgets.make_menulist( 
117                                 util.functional.map_list( 
118                                         g.data.list.pgt,
119                                         function(obj) { return [ 
120                                                 obj.description() ? obj.name() + ' : ' + obj.description() : obj.name(), 
121                                                 obj.id() 
122                                         ]; }
123                                 )
124                         );
125
126                         x.appendChild( ml );
127                 }
128
129                 function build_cit_menulist() {
130                         var x = document.getElementById('placeholder');
131                         util.widgets.remove_children( x );
132
133                         var ml = util.widgets.make_menulist( 
134                                 util.functional.map_list( 
135                                         g.data.list.cit,
136                                         function(obj) { return [ 
137                                                 obj.name(), 
138                                                 obj.id() 
139                                         ]; }
140                                 )
141                         );
142
143                         x.appendChild( ml );
144                 }
145
146                 function build_cnct_menulist() {
147                         var x = document.getElementById('placeholder');
148                         util.widgets.remove_children( x );
149
150                         var ml = util.widgets.make_menulist( 
151                                 util.functional.map_list( 
152                                         g.data.list.cnct,
153                                         function(obj) { return [ 
154                                                 obj.name(), 
155                                                 '[' + obj.id() + ',' + obj.circ_duration() + ']'
156                                         ]; }
157                                 )
158                         );
159
160                         x.appendChild( ml );
161                 }
162
163                 function build_req_survey_interface() {
164                         var x = document.getElementById('placeholder');
165                         util.widgets.remove_children( x );
166                         /* loop through required surveys */
167                         for (var i = 0; i < g.data.list.my_asv; i++) {
168                                 var survey = g.data.list.my_asv[i];
169                                 var x_gb = document.createElementById('groupbox');
170                                 x.appendChild(x_gb);
171                                 var x_caption = document.createElementById('caption');
172                                 x_caption.setAttribute('label',survey.name());
173                                 x_gb.appendChild(x_caption);
174
175                                 if (survey.description()) {
176                                         var x_desc = document.createElement('description');
177                                         x_desc.appendChild(
178                                                 document.createTextNode( survey.description() )
179                                         );
180                                         x_gb.appendChild(x_desc);
181                                 }
182
183                                 /* loop through survey questions */
184                                 for (var j = 0; j < survey.questions(); j++) {
185                                         var question = survey.questions()[j];
186                                         var x_desc = document.createElement('description');
187                                         x_desc.appendChild(
188                                                 document.createTextNode(
189                                                         question.question()
190                                                 )
191                                         );
192                                         x_gb.appendChild(x_desc);
193                                         var x_hbox = document.createElement('hbox'); x_hbox.setAttribute('flex','1');
194                                         x_gb.appendChild(x_hbox);
195                                         var x_spacer = document.createElement('spacer'); x_spacer.setAttribute('flex','1');
196                                         x_hbox.appendChild(x_spacer);
197                                         var x_ml = util.widgets.make_menulist( 
198                                                 [ 'Choose a response...', '' ].concat(
199                                                         util.functional.map_list( 
200                                                                 question.answers(),
201                                                                 function(obj) { return [ 
202                                                                         obj.answer(), 
203                                                                         '[' + obj.id() + ',' 
204                                                                         + obj.question() + ',' 
205                                                                         + question.survey() + ']'
206                                                                 ]; }
207                                                         )
208                                                 )
209                                         );
210                                         x_hbox.appendChild(x_ml);
211                                 }
212                         }
213                 }
214
215         ]]>
216         </script>
217
218         <vbox flex="1">
219                 <hbox id="placeholder"/>
220         </vbox>
221 </window>
222