]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/info_group.xul
mo betta
[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(); } 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.cgi = new CGI();
52                                 g.patron_id = g.cgi.param('patron_id');
53
54                                 tree_init();
55
56                                 refresh();
57
58                         } catch(E) {
59                                 var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
60                                         "system administrator or software developer the following:\npatron_info_group.xul\n" + E + '\n';
61                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
62                                 alert(err_msg);
63                         }
64                 }
65
66                 function tree_init() {
67                                 JSAN.use('OpenILS.data'); g.OpenILS = {}; 
68                                 g.OpenILS.data = new OpenILS.data(); g.OpenILS.data.init({'via':'stash'});
69
70                                 JSAN.use('util.list'); g.list = new util.list('patron_list');
71                                 function getString(s) { return g.OpenILS.data.entities[s]; }
72
73                                 JSAN.use('patron.util');
74                                 var columns = patron.util.columns(
75                                         {
76                                                 'active' : { 'hidden' : 'false' },
77                                                 'barred' : { 'hidden' : 'false' },
78                                                 'family_name' : { 'hidden' : 'false' },
79                                                 'first_given_name' : { 'hidden' : 'false' },
80                                                 'second_given_name' : { 'hidden' : 'false' },
81                                                 'dob' : { 'hidden' : 'false' },
82                                         }
83                                 );
84                                 g.list.init(
85                                         {
86                                                 'columns' : columns,
87                                                 'map_row_to_column' : patron.util.std_map_row_to_column(),
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                                                         'show_print_button' : true , 
212                                                         'tab_name' : 'Register Patron Clone for Group' ,
213                                                         'passthru_content_params' : {
214                                                                 'spawn_search' : spawn_search,
215                                                                 'spawn_editor' : spawn_editor,
216                                                                 'on_save' : function() { refresh(); },
217                                                                 'url_prefix' : xulG.url_prefix,
218                                                                 'new_tab' : xulG.new_tab,
219                                                         },
220                                                         'url_prefix' : xulG.url_prefix,
221                                                         'new_tab' : xulG.new_tab,
222                                                 }
223                                         );
224                                 }
225                         } catch(E) {
226                                 g.error.standard_unexpected_error_alert('error spawning user editors',E);
227                         }
228                 }
229
230                 function spawn_editor(p) {
231                         var url = urls.XUL_PATRON_EDIT;
232                         var param_count = 0;
233                         for (var i in p) {
234                                 if (param_count++ == 0) url += '?'; else url += '&';
235                                 url += i + '=' + window.escape(p[i]);
236                         }
237                         var loc = xulG.url_prefix( urls.XUL_REMOTE_BROWSER ) + '?url=' + window.escape( url );
238                         xulG.new_tab(
239                                 loc, 
240                                 {}, 
241                                 { 
242                                         'show_print_button' : true , 
243                                         'tab_name' : 'Editing Related Patron' ,
244                                         'passthru_content_params' : {
245                                                 'spawn_search' : spawn_search,
246                                                 'spawn_editor' : spawn_editor,
247                                                 'on_save' : function() { refresh(); },
248                                                 'url_prefix' : xulG.url_prefix,
249                                                 'new_tab' : xulG.new_tab,
250                                         },
251                                         'url_prefix' : xulG.url_prefix,
252                                         'new_tab' : xulG.new_tab,
253                                 }
254                         );
255
256                 }
257
258                 function spawn_search(s) {
259                         try {
260                                 g.error.sdump('D_TRACE', 'Editor would like to search for: ' + js2JSON(s) ); 
261                                 var loc = xulG.url_prefix(urls.XUL_PATRON_DISPLAY);
262                                         loc += '?doit=1&query=' + window.escape(js2JSON(s));
263                                 xulG.new_tab( loc, {}, {} );
264                         } catch(E) {
265                                 g.error.standard_unexpected_error_alert('spawn search',E);
266                         }
267                 }
268
269                 function remove_patron() {
270                         if (! g.sel_list ) return;
271                         var msg = ''; for (var i = 0 ; i < g.sel_list.length; i++) if (g.sel_list[i] == g.patron_id) msg =
272                                 'WARNING: If you remove the currently displayed patron, a NEW group will be displayed in this interface.';
273                         var c = window.confirm('Remove selected patrons from this group?  ' + msg);
274                         if (c) {
275                                 for (var i = 0; i < g.sel_list.length; i++) {   
276                                         var robj = g.network.simple_request('FM_AU_NEW_USERGROUP', [ ses(), g.sel_list[i], 't' ]);
277                                         if (typeof robj.ilsevent != 'undefined') {
278                                                 g.error.standard_unexpected_error_alert('error removing patron (id=' + g.sel_list[i] + ') from usergroup',robj);
279                                         }
280                                 }
281                                 alert('Patrons removed from group.'); /* FIXME - xulrunner bug if this alert comes after refresh? */
282                                 refresh();
283                         } else {
284                                 alert('Patron not removed from group.');
285                         }
286                 }
287
288                 function link_patron(direction) {
289                         try {
290                                 if (! g.sel_list ) { g.sel_list = []; g.sel_list[0] = g.patron_id; }
291                                 if (direction == null) throw('null paramater not allowed');
292                                 var first_msg; var second_msg;
293                                 switch(direction) {
294                                         case true: first_msg = "-->"; break;
295                                         case false: first_msg = "<--"; break;
296                                         default: throw('Invalid parameter.  Expected boolean.'); break;
297                                 }
298                                 var barcode = window.prompt('Please scan a patron barcode:','',first_msg);
299                                 if (!barcode) return;
300                                 JSAN.use('patron.util');
301                                 var patron_b = patron.util.retrieve_fleshed_au_via_barcode(ses(),barcode);
302                                 if (typeof patron_b.ilsevent != 'undefined') throw(patron_b);
303
304                                 if (g.sel_list.length == 0) g.sel_list[0] = g.patron_id;
305                                 for (var i = 0; i < g.sel_list.length; i++) {   
306
307                                         var patron_a = patron.util.retrieve_fleshed_au_via_id(ses(),g.sel_list[i]);
308                                         if (typeof patron_a.ilsevent != 'undefined') throw(patron_a);
309                                         switch(direction) {
310                                                 case true: second_msg = "Move patron " + patron_a.card().barcode() + " into patron " + patron_b.card().barcode() + "'s usergroup..."; break;
311                                                 case false: second_msg = "Move patron " + patron_b.card().barcode() + " into patron " + patron_a.card().barcode() + "'s usergroup..."; break;
312                                         }
313
314                                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
315                                         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>';
316                                         var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical"><hbox flex="1">';
317                                         /************/
318                                         xml += '<vbox flex="1">';
319                                         xml += '<hbox><spacer flex="1"/>';
320                                         if (direction) {
321                                                 xml += '<image src="/xul/server/skin/media/images/patron_right_arrow.png"/>';
322                                         } else {
323                                                 xml += '<image src="/xul/server/skin/media/images/patron_left_arrow.png"/>';
324                                         }
325                                         xml += '</hbox>';
326                                         xml += '<iframe style="min-height: 100px" flex="1" src="' + xulG.url_prefix( urls.XUL_PATRON_SUMMARY );
327                                         xml += '?show_name=1&amp;id=' + g.sel_list[i] + '"/>';
328                                         xml += '</vbox>';
329                                         xml += '<vbox flex="1">';
330                                         xml += '<hbox>';
331                                         if (direction) {
332                                                 xml += '<image src="/xul/server/skin/media/images/patron_right_arrow.png"/>';
333                                         } else {
334                                                 xml += '<image src="/xul/server/skin/media/images/patron_left_arrow.png"/>';
335                                         }
336                                         xml += '<spacer flex="1"/></hbox>';
337                                         xml += '<iframe style="min-height: 100px" flex="1" src="' + xulG.url_prefix( urls.XUL_PATRON_SUMMARY );
338                                         xml += '?show_name=1&amp;id=' + patron_b.id() + '"/>';
339                                         xml += '</vbox>';
340                                         /************/
341                                         xml += '</hbox></vbox>';
342                                         
343                                         var bot_xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto"><hbox>';
344                                         bot_xml += '</hbox></vbox>';
345                 
346                                         g.data.temp_top = top_xml; g.data.stash('temp_top');
347                                         g.data.temp_mid = xml; g.data.stash('temp_mid');
348                                         g.data.temp_bot = bot_xml; g.data.stash('temp_bot');
349                                         window.open(
350                                                 urls.XUL_FANCY_PROMPT
351                                                 + '?xml_in_stash=temp_mid'
352                                                 + '&top_xml_in_stash=temp_top'
353                                                 + '&bottom_xml_in_stash=temp_bot'
354                                                 + '&title=' + window.escape('Move Patron into a Usergroup'),
355                                                 'fancy_prompt', 'chrome,resizable,modal,width=700,height=500'
356                                         );
357                                         g.data.init({'via':'stash'});
358                                         if (g.data.fancy_prompt_data == '') { continue; }
359                                         else {
360                                                 var patron_c;
361                                                 switch(direction) {
362                                                         case true:
363                                                                 patron_a.usrgroup( patron_b.usrgroup() );
364                                                                 patron_a.ischanged( '1' );
365                                                                 patron_c = patron_a;
366                                                         break;
367                                                         case false:
368                                                                 patron_b.usrgroup( patron_a.usrgroup() );
369                                                                 patron_b.ischanged( '1' );
370                                                                 patron_c = patron_b;
371                                                         break;
372                                                 }
373                                                 var robj = g.network.simple_request('FM_AU_UPDATE',[ ses(), patron_c ]);
374                                                 if (typeof robj.ilsevent != 'undefined') g.error.standard_unexpected_error_alert('error linking patron (id=' + g.sel_list[i] + ')', robj);
375                                         }
376                                 }
377                                 refresh();
378                                 alert('User groups updated.');
379                         } catch(E) {
380                                 g.error.standard_unexpected_error_alert('error linking patrons',E);
381                                 refresh();
382                         }
383                 }
384
385         ]]>
386         </script>
387
388         <commandset id="info_group_cmds">
389                 <command id="clone" accesskey="N" label="Register a New Group Member by Cloning Selected Patrons" oncommand="try{clone_patron();}catch(E){alert('FIXME:'+E);}"/>
390                 <command id="remove" accesskey="R" label="Remove Selected Patrons from the Group" oncommand="try{remove_patron();}catch(E){alert('FIXME:'+E);}"/>
391                 <command id="move" accesskey="M" label="Move Selected Patrons to ANOTHER patron's group." oncommand="try{link_patron(true);}catch(E){alert('FIXME:'+E);}"/>     
392                 <command id="add" accesskey="A" label="Move ANOTHER patron to this patron group." oncommand="try{link_patron(false);}catch(E){alert('FIXME:'+E);}"/>    
393                 <command id="retrieve_p" label="Retrieve Selected Patrons" accesskey="P" oncommand="try{retrieve_patron();}catch(E){alert(E);}"/>
394         </commandset>
395
396         <popupset id="info_group_popupset">
397                 <popup id="info_group_actions" position="at_pointer"> 
398                         <menuitem command="clone" />
399                         <menuitem command="remove" />
400                         <menuitem command="move" />
401                         <menuitem command="add" />
402                         <menuitem command="retrieve_p" />
403                 </popup>
404         </popupset>
405
406         <vbox flex="1" class="my_overflow" id="group_panel">
407                 <groupbox flex="1">
408                         <caption label="Group Members"/>
409                         <hbox>
410                                 <spacer flex="1"/>
411                                 <menubar id="ml">
412                                         <menu label="Choose an Action..." accesskey="A" value="0">
413                                                 <menupopup>
414                                                         <menuitem command="clone" />
415                                                         <menuitem command="remove" />
416                                                         <menuitem command="move" />
417                                                         <menuitem command="add" />
418                                                         <menuitem command="retrieve_p" />
419                                                 </menupopup>
420                                         </menu>
421                                 </menubar>
422                         </hbox>
423                         <tree id="patron_list" flex="1" enableColumnDrag="true" seltype="multiple" context="info_group_actions"/>
424                 </groupbox>
425         </vbox>
426
427
428 </window>
429