]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/main/gen_offline_widgets.xul
fix
[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.functional');
55
56                         save_object('offline_ou_list', build_ou_list());
57
58                         save_object('offline_pgt_list', build_pgt_list());
59
60                         save_object('offline_cit_list', build_cit_list());
61
62                         save_object('offline_cnct_list', build_cnct_list());
63
64                         save_object('offline_asv_list', build_asv_list());
65
66                         var server_time = g.network.request('open-ils.actor','opensrf.system.time',[]);
67                         var local_time = parseInt( new Date().getTime() / 1000 );
68
69                         var delta = server_time - local_time;
70
71                         JSAN.use('util.file'); var file = new util.file('pending_xacts');
72                         if (file._file.exists()) {
73                                 file.close();
74                         } else {
75                                 file.close();
76                                 save_object('offline_delta', [ delta ]);
77                         }
78
79                         save_object('print_list_templates',g.data.print_list_templates);
80
81                         $('placeholder').setAttribute('value','Offline interface synchronized with server.');
82
83                 }
84
85                 function $(id) {
86                         return document.getElementById(id);
87                 }
88
89                 function save_object(filename,obj) {
90                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
91                         JSAN.use('util.file'); var file = new util.file(filename);
92                         file.set_object(obj); file.close();
93                 }
94
95                 function build_ou_list() {
96                         return [
97                                 util.functional.map_list( 
98                                         g.data.list.aou,
99                                         function(obj) { 
100                                                 var sname = obj.shortname(); for (i = sname.length; i < 20; i++) sname += ' ';
101                                                 return [ 
102                                                         obj.name() ? sname + ' ' + obj.name() : obj.shortname(),
103                                                         obj.id(), 
104                                                         ( g.data.hash.aout[ obj.ou_type() ].can_have_users() == 0),
105                                                         ( g.data.hash.aout[ obj.ou_type() ].depth() * 2),
106                                                 ]; 
107                                         }
108                                 ),
109                                 g.data.list.au[0].ws_ou()
110                         ];
111                 }
112
113                 function build_pgt_list() {
114                         return [
115                                 util.functional.map_list( 
116                                         g.data.list.pgt,
117                                         function(obj) { return [ 
118                                                 obj.description() ? obj.name() + ' : ' + obj.description() : obj.name(), 
119                                                 obj.id() 
120                                         ]; }
121                                 )
122                         ];
123                 }
124
125                 function build_cit_list() {
126                         return [
127                                 util.functional.map_list( 
128                                         g.data.list.cit,
129                                         function(obj) { return [ 
130                                                 obj.name(), 
131                                                 obj.id() 
132                                         ]; }
133                                 )
134                         ];
135                 }
136
137                 function build_cnct_list() {
138                         return [
139                                 util.functional.map_list( 
140                                         g.data.list.cnct,
141                                         function(obj) { return [ 
142                                                 obj.name(), 
143                                                 js2JSON( [ obj.id(), obj.circ_duration() ] )
144                                         ]; }
145                                 )
146                         ];
147                 }
148
149                 function build_asv_list() {
150                         var obj = {};
151                         /* loop through required surveys */
152                         for (var i = 0; i < g.data.list.my_asv.length; i++) {
153                                 dump('i = ' + i + '\n');
154                                 var survey = g.data.list.my_asv[i];
155                                 obj[ survey.name() ] = {};
156                                 obj[ survey.name() ][ 'description' ] = survey.description();
157                                 obj[ survey.name() ][ 'questions' ] = [];
158
159                                 /* loop through survey questions */
160                                 for (var j = 0; j < survey.questions().length; j++) {
161                                         dump('\tj = ' + j + '\n');
162                                         var question = survey.questions()[j];
163                                         var q = {};
164                                         q[ 'question' ] = question.question();
165                                         q[ 'answers' ] = util.functional.map_list( 
166                                                 question.answers(),
167                                                 function(obj) { return [ 
168                                                         obj.answer(), 
169                                                         '[' + obj.id() + ',' 
170                                                         + obj.question() + ',' 
171                                                         + question.survey() + ']'
172                                                 ]; }
173                                         );
174                                         obj[ survey.name() ][ 'questions' ].push( q );
175                                 }
176                         }
177                         return obj;
178                 }
179
180         ]]>
181         </script>
182
183         <vbox flex="1">
184                 <label id="placeholder"/>
185         </vbox>
186 </window>
187