]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/info_group.xul
xul_param and modal xulG conversion
[Evergreen.git] / Open-ILS / xul / staff_client / server / patron / info_group.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_group_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('patron.util'); 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_group.xul');
50
51                                 g.patron_id = xul_param('patron_id');
52
53                                 tree_init();
54
55                                 refresh();
56
57                         } catch(E) {
58                                 var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
59                                         "system administrator or software developer the following:\npatron_info_group.xul\n" + E + '\n';
60                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
61                                 alert(err_msg);
62                         }
63                 }
64
65                 function tree_init() {
66                                 JSAN.use('OpenILS.data'); g.OpenILS = {}; 
67                                 g.OpenILS.data = new OpenILS.data(); g.OpenILS.data.init({'via':'stash'});
68
69                                 JSAN.use('util.list'); g.list = new util.list('patron_list');
70                                 function getString(s) { return g.OpenILS.data.entities[s]; }
71
72                                 JSAN.use('patron.util');
73                                 var columns = patron.util.columns(
74                                         {
75                                                 'active' : { 'hidden' : 'false' },
76                                                 'barred' : { 'hidden' : 'false' },
77                                                 'family_name' : { 'hidden' : 'false' },
78                                                 'first_given_name' : { 'hidden' : 'false' },
79                                                 'second_given_name' : { 'hidden' : 'false' },
80                                                 'dob' : { 'hidden' : 'false' },
81                                                 'master_account' : { 'hidden' : 'false' },
82                                         }
83                                 );
84                                 g.list.init(
85                                         {
86                                                 'columns' : columns,
87                                                 'map_row_to_columns' : patron.util.std_map_row_to_columns(),
88                                                 'retrieve_row' : function(params) {
89                                                         var id = params.retrieve_id;
90                                                         var au_obj = patron.util.retrieve_au_via_id( ses(), id );
91
92                                                         var row = params.row;
93                                                         if (typeof row.my == 'undefined') row.my = {};
94                                                         row.my.au = au_obj;
95                                                         if (typeof params.on_retrieve == 'function') {
96                                                                 params.on_retrieve(row);
97                                                         }
98                                                         return row;
99                                                 },
100                                                 'on_select' : function(ev) {
101                                                         JSAN.use('util.functional');
102                                                         var sel = g.list.retrieve_selection();
103                                                         g.sel_list = util.functional.map_list(
104                                                                 sel,
105                                                                 function(o) { return o.getAttribute('retrieve_id'); }
106                                                         );
107                                                         if (g.sel_list.length > 0) {
108                                                                 $('retrieve_p').disabled = false;
109                                                                 $('retrieve_p').setAttribute('disabled','false');
110                                                                 $('clone').disabled = false;
111                                                                 $('clone').setAttribute('disabled','false');
112                                                                 $('remove').disabled = false;
113                                                                 $('remove').setAttribute('disabled','false');
114                                                                 $('move').disabled = false;
115                                                                 $('move').setAttribute('disabled','false');
116                                                         } else {
117                                                                 $('retrieve_p').disabled = true;
118                                                                 $('retrieve_p').setAttribute('disabled','true');
119                                                                 $('clone').disabled = true;
120                                                                 $('clone').setAttribute('disabled','true');
121                                                                 $('remove').disabled = true;
122                                                                 $('remove').setAttribute('disabled','true');
123                                                                 $('move').disabled = true;
124                                                                 $('move').setAttribute('disabled','true');
125                                                         }
126                                                 }
127                                         }
128                                 );
129                                 $('retrieve_p').disabled = true;
130                                 $('retrieve_p').setAttribute('disabled','true');
131                                 $('clone').disabled = true;
132                                 $('clone').setAttribute('disabled','true');
133                                 $('remove').disabled = true;
134                                 $('remove').setAttribute('disabled','true');
135                                 $('move').disabled = true;
136                                 $('move').setAttribute('disabled','true');
137                                 setTimeout( function() { $('patron_list').focus(); }, 0 );
138                 }
139
140                 function refresh() {
141                         retrieve_group_members();
142                 }
143
144                 function retrieve_group_members() {
145                         try {
146                                 JSAN.use('util.functional'); JSAN.use('patron.util');
147                                 g.group_members = [];
148                                 var p = patron.util.retrieve_au_via_id(ses(),g.patron_id);
149                                 if ((p == null) || (typeof p.ilsevent != 'undefined') ) throw(p);
150                                 var robj = g.network.simple_request(
151                                         'FM_AU_LIST_RETRIEVE_VIA_GROUP',
152                                         [ ses(), p.usrgroup() ]
153                                 );
154                                 if ((robj == null) || (typeof robj.ilsevent != 'undefined') ) throw(robj);
155                                 var ids = util.functional.filter_list( robj, function(o) { return o != g.patron_id; });
156
157                                 g.list.clear();
158
159                                 var funcs = [];
160
161                                         function gen_func(r) {
162                                                 return function() {
163                                                         g.list.append( { 'retrieve_id' : r, 'row' : {} } );
164                                                 }
165                                         }
166
167                                 funcs.push( gen_func(g.patron_id) );
168                                 for (var i = 0; i < ids.length; i++) {
169                                         funcs.push( gen_func(ids[i]) );
170                                 }
171                                 JSAN.use('util.exec'); var exec = new util.exec(4);
172                                 exec.chain( funcs );
173
174                         } catch(E) {
175                                 g.error.standard_unexpected_error_alert('Failed to retrieve all the group members.',E);
176                         }
177                 }
178
179                 function retrieve_patron() {
180                         try {
181                                 if (! g.sel_list ) return;
182                                 if (typeof window.xulG == 'object' && typeof window.xulG.new_tab == 'function') {
183                                         for (var i = 0; i < g.sel_list.length; i++) {   
184                                                 try {
185                                                         var url = urls.XUL_PATRON_DISPLAY 
186                                                                 + '?id=' + window.escape( g.sel_list[i] );
187                                                         window.xulG.new_tab(
188                                                                 url, { 'tab_name' : 'Retrieving Patron..' }, {}
189                                                         );
190                                                 } catch(E) {
191                                                         g.error.standard_unexpected_error_alert('Failed to retrieve patron.',E);
192                                                 }
193                                         }
194                                 }
195                         } catch(E) {
196                                 g.error.standard_unexpected_error_alert('Failed to retrieve patrons.',E);
197                         }
198                 }
199
200                 function clone_patron() {
201                         if (! g.sel_list ) return;
202                         try {
203                                 for (var i = 0; i < g.sel_list.length; i++) {   
204                                         var loc = xulG.url_prefix( urls.XUL_REMOTE_BROWSER ); 
205                                                 //+ '?url=' + window.escape( urls.XUL_PATRON_EDIT + '?ses=' 
206                                                 //+ window.escape( ses() ) + '&clone=' + g.sel_list[i] );
207                                         xulG.new_tab(
208                                                 loc, 
209                                                 {}, 
210                                                 { 
211                                                         'url' : urls.XUL_PATRON_EDIT, // + '?ses=' + window.escape(ses()) + '&clone=' + g.sel_list[i],
212                                                         'show_print_button' : true , 
213                                                         'tab_name' : 'Register Patron Clone for Group' ,
214                                                         'passthru_content_params' : {
215                                                                 'ses' : ses(,
216                                                                 'clone' : g.sel_list[i],
217                                                                 'spawn_search' : spawn_search,
218                                                                 'spawn_editor' : spawn_editor,
219                                                                 'on_save' : function() { refresh(); },
220                                                                 'url_prefix' : xulG.url_prefix,
221                                                                 'new_tab' : xulG.new_tab,
222                                                         },
223                                                         'url_prefix' : xulG.url_prefix,
224                                                         'new_tab' : xulG.new_tab,
225                                                 }
226                                         );
227                                 }
228                         } catch(E) {
229                                 g.error.standard_unexpected_error_alert('error spawning user editors',E);
230                         }
231                 }
232
233                 function spawn_editor(p) {
234                         var url = urls.XUL_PATRON_EDIT;
235                         var passthru = {
236                                 'spawn_search' : spawn_search,
237                                 'spawn_editor' : spawn_editor,
238                                 'on_save' : function() { refresh(); },
239                                 'url_prefix' : xulG.url_prefix,
240                                 'new_tab' : xulG.new_tab,
241                         };
242                         for (var i in p) {
243                                 passthru[i] = p[i];
244                         }
245                         var loc = xulG.url_prefix( urls.XUL_REMOTE_BROWSER ); // + '?url=' + window.escape( url );
246                         xulG.new_tab(
247                                 loc, 
248                                 {}, 
249                                 { 
250                                         'url' : url,
251                                         'show_print_button' : true , 
252                                         'tab_name' : 'Editing Related Patron' ,
253                                         'passthru_content_params' : passthru,
254                                         'url_prefix' : xulG.url_prefix,
255                                         'new_tab' : xulG.new_tab,
256                                 }
257                         );
258
259                 }
260
261                 function spawn_search(s) {
262                         try {
263                                 g.error.sdump('D_TRACE', 'Editor would like to search for: ' + js2JSON(s) ); 
264                                 var loc = xulG.url_prefix(urls.XUL_PATRON_DISPLAY);
265                                         //loc += '?doit=1&query=' + window.escape(js2JSON(s));
266                                 xulG.new_tab( loc, {}, {'doit':1,'query':s} );
267                         } catch(E) {
268                                 g.error.standard_unexpected_error_alert('spawn search',E);
269                         }
270                 }
271
272                 function remove_patron() {
273                         if (! g.sel_list ) return;
274                         var msg = ''; for (var i = 0 ; i < g.sel_list.length; i++) if (g.sel_list[i] == g.patron_id) msg =
275                                 'WARNING: If you remove the currently displayed patron, a NEW group will be displayed in this interface.';
276                         var c = window.confirm('Remove selected patrons from this group?  ' + msg);
277                         if (c) {
278                                 for (var i = 0; i < g.sel_list.length; i++) {   
279                                         var robj = g.network.simple_request('FM_AU_NEW_USERGROUP', [ ses(), g.sel_list[i], get_db_true() ]);
280                                         if (typeof robj.ilsevent != 'undefined') {
281                                                 g.error.standard_unexpected_error_alert('error removing patron (id=' + g.sel_list[i] + ') from usergroup',robj);
282                                         }
283                                 }
284                                 alert('Patrons removed from group.'); 
285                                 /* FIXME - xulrunner bug if this alert comes after refresh? */
286                                 /* that's okay, because now that we're on a distributed database, we want human delay to mitigate race conditions */
287                                 refresh();
288                         } else {
289                                 alert('Patron not removed from group.');
290                         }
291                 }
292
293                 function link_patron(direction) {
294                         try {
295                                 if (! g.sel_list ) { g.sel_list = []; g.sel_list[0] = g.patron_id; }
296                                 if (direction == null) throw('null paramater not allowed');
297                                 var first_msg; var second_msg;
298                                 switch(direction) {
299                                         case true: first_msg = "-->"; break;
300                                         case false: first_msg = "<--"; break;
301                                         default: throw('Invalid parameter.  Expected boolean.'); break;
302                                 }
303                                 var barcode = window.prompt('Please scan a patron barcode:','',first_msg);
304                                 if (!barcode) return;
305                                 JSAN.use('patron.util');
306                                 var patron_b = patron.util.retrieve_fleshed_au_via_barcode(ses(),barcode);
307                                 if (typeof patron_b.ilsevent != 'undefined') throw(patron_b);
308
309                                 if (g.sel_list.length == 0) g.sel_list[0] = g.patron_id;
310                                 for (var i = 0; i < g.sel_list.length; i++) {   
311
312                                         var patron_a = patron.util.retrieve_fleshed_au_via_id(ses(),g.sel_list[i]);
313                                         if (typeof patron_a.ilsevent != 'undefined') throw(patron_a);
314                                         switch(direction) {
315                                                 case true: second_msg = "Move patron " + patron_a.card().barcode() + " into patron " + patron_b.card().barcode() + "'s usergroup..."; break;
316                                                 case false: second_msg = "Move patron " + patron_b.card().barcode() + " into patron " + patron_a.card().barcode() + "'s usergroup..."; break;
317                                         }
318
319                                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
320                                         var top_xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto"><description>' + second_msg + '</description><hbox><spacer flex="1"/><button label="Move" accesskey="M" name="fancy_submit"/><button label="Done" accesskey="D" name="fancy_cancel"/></hbox></vbox>';
321                                         var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical"><hbox flex="1">';
322                                         /************/
323                                         xml += '<vbox flex="1">';
324                                         xml += '<hbox><spacer flex="1"/>';
325                                         if (direction) {
326                                                 xml += '<image src="/xul/server/skin/media/images/patron_right_arrow.png"/>';
327                                         } else {
328                                                 xml += '<image src="/xul/server/skin/media/images/patron_left_arrow.png"/>';
329                                         }
330                                         xml += '</hbox>';
331                                         xml += '<iframe style="min-height: 100px" flex="1" src="' + xulG.url_prefix( urls.XUL_PATRON_SUMMARY );
332                                         xml += '?show_name=1&amp;id=' + g.sel_list[i] + '"/>';
333                                         xml += '</vbox>';
334                                         xml += '<vbox flex="1">';
335                                         xml += '<hbox>';
336                                         if (direction) {
337                                                 xml += '<image src="/xul/server/skin/media/images/patron_right_arrow.png"/>';
338                                         } else {
339                                                 xml += '<image src="/xul/server/skin/media/images/patron_left_arrow.png"/>';
340                                         }
341                                         xml += '<spacer flex="1"/></hbox>';
342                                         xml += '<iframe style="min-height: 100px" flex="1" src="' + xulG.url_prefix( urls.XUL_PATRON_SUMMARY );
343                                         xml += '?show_name=1&amp;id=' + patron_b.id() + '"/>';
344                                         xml += '</vbox>';
345                                         /************/
346                                         xml += '</hbox></vbox>';
347                                         
348                                         var bot_xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto"><hbox>';
349                                         bot_xml += '</hbox></vbox>';
350                 
351                                         //g.data.temp_top = top_xml; g.data.stash('temp_top');
352                                         //g.data.temp_mid = xml; g.data.stash('temp_mid');
353                                         //g.data.temp_bot = bot_xml; g.data.stash('temp_bot');
354                                         JSAN.use('util.window'); var win = new util.window();
355                                         var fancy_prompt_data = win.open(
356                                                 urls.XUL_FANCY_PROMPT,
357                                                 //+ '?xml_in_stash=temp_mid'
358                                                 //+ '&top_xml_in_stash=temp_top'
359                                                 //+ '&bottom_xml_in_stash=temp_bot'
360                                                 //+ '&title=' + window.escape('Move Patron into a Usergroup'),
361                                                 'fancy_prompt', 'chrome,resizable,modal,width=700,height=500',
362                                                 { 'xml' : xml, 'top_xml' : top_xml, 'bottom_xml' : bot_xml, 'title' : 'Move Patron into a Usergroup' }
363                                         );
364                                         if (fancy_prompt_data.fancy_status == 'incomplete') { continue; }
365                                         else {
366                                                 var patron_c;
367                                                 switch(direction) {
368                                                         case true:
369                                                                 patron_a.usrgroup( patron_b.usrgroup() );
370                                                                 patron_a.ischanged( '1' );
371                                                                 patron_c = patron_a;
372                                                         break;
373                                                         case false:
374                                                                 patron_b.usrgroup( patron_a.usrgroup() );
375                                                                 patron_b.ischanged( '1' );
376                                                                 patron_c = patron_b;
377                                                         break;
378                                                 }
379                                                 var robj = g.network.simple_request('FM_AU_UPDATE',[ ses(), patron_c ]);
380                                                 if (typeof robj.ilsevent != 'undefined') g.error.standard_unexpected_error_alert('error linking patron (id=' + g.sel_list[i] + ')', robj);
381                                         }
382                                 }
383                                 alert('User groups updated.');
384                                 refresh();
385                         } catch(E) {
386                                 g.error.standard_unexpected_error_alert('error linking patrons',E);
387                                 refresh();
388                         }
389                 }
390
391         ]]>
392         </script>
393
394         <commandset id="info_group_cmds">
395                 <command id="clone" accesskey="N" label="Register a New Group Member by Cloning Selected Patrons" oncommand="try{clone_patron();}catch(E){alert('FIXME:'+E);}"/>
396                 <command id="remove" accesskey="R" label="Remove Selected Patrons from the Group" oncommand="try{remove_patron();}catch(E){alert('FIXME:'+E);}"/>
397                 <command id="move" accesskey="M" label="Move Selected Patrons to ANOTHER patron's group." oncommand="try{link_patron(true);}catch(E){alert('FIXME:'+E);}"/>     
398                 <command id="add" accesskey="A" label="Move ANOTHER patron to this patron group." oncommand="try{link_patron(false);}catch(E){alert('FIXME:'+E);}"/>    
399                 <command id="retrieve_p" label="Retrieve Selected Patrons" accesskey="P" oncommand="try{retrieve_patron();}catch(E){alert(E);}"/>
400         </commandset>
401
402         <popupset id="info_group_popupset">
403                 <popup id="info_group_actions" position="at_pointer"> 
404                         <menuitem command="clone" />
405                         <menuitem command="remove" />
406                         <menuitem command="move" />
407                         <menuitem command="add" />
408                         <menuitem command="retrieve_p" />
409                 </popup>
410         </popupset>
411
412         <vbox flex="1" class="my_overflow" id="group_panel">
413                 <groupbox flex="1">
414                         <caption label="Group Members"/>
415                         <hbox>
416                                 <spacer flex="1"/>
417                                 <menubar id="ml">
418                                         <menu label="Choose an Action..." accesskey="A" value="0">
419                                                 <menupopup>
420                                                         <menuitem command="clone" />
421                                                         <menuitem command="remove" />
422                                                         <menuitem command="move" />
423                                                         <menuitem command="add" />
424                                                         <menuitem command="retrieve_p" />
425                                                 </menupopup>
426                                         </menu>
427                                 </menubar>
428                         </hbox>
429                         <tree id="patron_list" flex="1" enableColumnDrag="true" seltype="multiple" context="info_group_actions"/>
430                 </groupbox>
431         </vbox>
432
433
434 </window>
435