--- /dev/null
+var patron_id;
+var main_interface;
+
+function patron_init() {
+ try {
+ if (typeof JSAN == 'undefined') {
+ throw( "The JSAN library object is missing.");
+ }
+ JSAN.errorLevel = "die"; // none, warn, or die
+ JSAN.addRepository('oils://remote/xul/server/');
+ JSAN.use('util.error'); g.error = new util.error();
+ g.error.sdump('D_TRACE','my_init() for patron.xul');
+
+ JSAN.use('OpenILS.data');
+ g.data = new OpenILS.data();
+ g.data.stash_retrieve();
+
+ patron_id = xul_param('id');
+ if (!patron_id && xul_param('barcode')) {
+ // FIXME - not ideal; these come from the Offline XACT Mgr
+ var p_obj = patron.util.retrieve_fleshed_au_via_barcode(
+ ses(),
+ xul_param('barcode')
+ );
+ if (typeof p_obj.ilsevent != 'undefined') { throw(p_obj); }
+ patron_id = p_obj.id();
+ }
+
+ main_interface = xul_param('interface')
+ || xul_param('show') || 'checkout';
+
+ g.data.last_patron = patron_id;
+ g.data.stash('last_patron');
+
+ JSAN.use('util.file');
+ JSAN.use('util.widgets');
+ JSAN.use('util.functional');
+
+ try {
+ xulG.set_tab_name(get_tab_name(main_interface));
+ } catch(E) {}
+
+ patron_ui_setup();
+ patron_ui_populate();
+ patron_default_focus();
+
+ } catch(E) {
+ alert('Error in patron.xul, my_init(): ' + E);
+ }
+}
+
+function spawn_search(s) {
+ try {
+ xulG.new_patron_tab(
+ { 'tab_name' : 'Patron Search' },
+ {
+ 'run_query' : 1,
+ 'query' : s
+ }
+ );
+ } catch(E) {
+ dump('Error in patron.xul, spawn_search('+s+'): ' + E + '\n');
+ }
+}
+
+function spawn_editor(p) {
+ var url = urls.XUL_PATRON_EDIT;
+ var loc = xulG.url_prefix('XUL_REMOTE_BROWSER');
+ xulG.new_tab(
+ loc,
+ {},
+ {
+ 'url' : url,
+ 'show_print_button' : true ,
+ 'tab_name' : $("patronStrings").getString(
+ 'staff.patron.display.spawn_editor.editing_related_patron'
+ ),
+ 'passthru_content_params' : {
+ 'spawn_search' : spawn_search,
+ 'spawn_editor' : spawn_editor,
+ 'url_prefix' : xulG.url_prefix,
+ 'get_new_session' : xulG.get_new_session,
+ 'new_tab' : xulG.new_tab,
+ 'new_patron_tab' : xulG.new_patron_tab,
+ 'params' : p,
+ 'on_save' : function(p_obj) {
+ JSAN.use('patron.util');
+ patron.util.work_log_patron_edit(p_obj);
+ patron_tab('edit','merely_reset');
+ }
+ },
+ 'lock_tab' : xulG.lock_tab,
+ 'unlock_tab' : xulG.unlock_tab
+ }
+ );
+}
+
+function get_tab_name(p_interface) {
+ try {
+ var tab_name = p_interface + ' Patron#' + patron_id;
+ switch(p_interface) {
+ case 'checkout':
+ tab_name = 'Check Out Patron#' + patron_id;
+ break;
+ case 'items_out':
+ tab_name = 'Items Out Patron#' + patron_id;
+ break;
+ case 'holds':
+ tab_name = 'Holds Patron#' + patron_id;
+ break;
+ case 'messages':
+ tab_name = 'Messages Patron#' + patron_id;
+ break;
+ case 'notes':
+ tab_name = 'Notes Patron#' + patron_id;
+ break;
+ case 'group':
+ tab_name = 'Group Patron#' + patron_id;
+ break;
+ case 'bills': case 'bill_history':
+ tab_name = 'Bills Patron#' + patron_id;
+ break;
+ case 'edit':
+ tab_name = 'Edit Patron#' + patron_id;
+ break;
+ case 'perms':
+ tab_name = 'Permissions Patron#' + patron_id;
+ break;
+ case 'events':
+ tab_name = 'Events Patron#' + patron_id;
+ break;
+ case 'requests':
+ tab_name = 'Requests Patron#' + patron_id;
+ break;
+ case 'statcats':
+ tab_name = 'StatCats Patron#' + patron_id;
+ break;
+ case 'surveys':
+ tab_name = 'Surveys Patron#' + patron_id;
+ break;
+ case 'test_password':
+ tab_name = 'Verify Credentials Patron#' + patron_id;
+ break;
+ }
+ return tab_name;
+ } catch(E) {
+ dump('Error in patron.xul, get_tab_name('+p_interface+'): ' + E + '\n');
+ }
+}
+
+function patron_tab(p_interface,replace_tab) {
+ try {
+ if (replace_tab == 'merely_reset') {
+ if ($(main_interface)) {
+ $(main_interface).disabled = false;
+ }
+ main_interface = p_interface;
+ try {
+ xulG.set_tab_name(get_tab_name(main_interface));
+ } catch(E) {}
+ patron_ui_populate();
+ } else {
+ xulG[
+ replace_tab
+ ? 'set_tab'
+ : 'new_tab'
+ ](
+ urls.XUL_PATRON_DISPLAY,{
+ 'tab_name' : get_tab_name(p_interface)
+ },{
+ 'id':patron_id,
+ 'interface' : p_interface
+ }
+ );
+ }
+ } catch(E) {
+ dump('Error in patron.xul, patron_tab('+p_interface+'): ' + E + '\n');
+ }
+}
+
+function reset_summary() {
+ try {
+ $('iframe1').setAttribute(
+ 'src',
+ 'about:blank'
+ );
+ setTimeout(
+ function() {
+ $('iframe1').setAttribute(
+ 'src',
+ urls.EG_PATRON_SUMMARY + '?au_id=' + patron_id
+ );
+ }, 0
+ );
+ } catch(E) {
+ dump('Error in patron.xul, reset_summary(): ' + E + '\n');
+ }
+}
+
+function sort_button_box(box, recurse) {
+ try {
+ var curgroup = new Array();
+ var curstart = 1;
+ var curordinal = 0;
+ for (var itemid = 0; itemid < box.children.length; itemid++) {
+ var item = box.children[itemid];
+ curordinal++;
+ if (item.getAttribute('forceFirst')) {
+ item.setAttribute('ordinal', curstart);
+ curstart++;
+ continue;
+ }
+ if (item.nodeName == 'description'
+ || item.nodeName == 'label'
+ || item.nodeName == 'spacer'
+ ) {
+ sort_button_box_items(curgroup, curstart);
+ item.setAttribute('ordinal', curordinal);
+ curstart = curordinal + 1;
+ curgroup = new Array();
+ continue;
+ }
+ if ((item.nodeName == 'hbox'
+ || item.nodeName == 'vbox'
+ ) && recurse
+ ) {
+ sort_menu_box(item, recurse);
+ }
+ curgroup.push(item);
+ }
+ sort_button_box_items(curgroup, curstart);
+ } catch(E) {
+ dump('Error in patron.xul, sort_button_box(): ' + E + '\n');
+ }
+}
+
+function sort_button_box_items(itemgroup, start) {
+ try {
+ var curpos = start;
+ var sorted = itemgroup.sort(function(a,b) {
+ var labelA = a.getAttribute('label').toUpperCase();
+ var labelB = b.getAttribute('label').toUpperCase();
+ return labelA.localeCompare(labelB);
+ });
+ for(var item = 0; item < sorted.length; item++) {
+ sorted[item].setAttribute('ordinal', curpos++);
+ }
+ } catch(E) {
+ dump('Error in patron.xul, sort_button_box_items(): ' + E + '\n');
+ }
+}
+
+function handle_reservation(ev) {
+ try {
+ JSAN.use('patron.util');
+ dojo.require("openils.User");
+ dojo.require("openils.XUL");
+ openils.XUL.newTabEasy(
+ "BOOKING_RESERVATION",
+ $("offlineStrings").getString(
+ "menu.cmd_booking_reservation.tab"
+ ), {
+ "bresv_interface_opts": {
+ "patron_barcode":
+ xul_param('barcode')
+ || patron.util.retrieve_fleshed_au_via_id(
+ ses(),
+ patron_id
+ ).card().barcode()
+ }
+ },
+ true
+ );
+ } catch(E) {
+ dump('Error in patron.xul, handle_reservation(): ' + E + '\n');
+ }
+}
+
+function handle_reservation_pickup(ev) {
+ try {
+ JSAN.use('patron.util');
+ dojo.require("openils.User");
+ dojo.require("openils.XUL");
+ openils.XUL.newTabEasy(
+ "BOOKING_PICKUP",
+ $("offlineStrings").getString(
+ "menu.cmd_booking_reservation_pickup.tab"
+ ), {
+ "bresv_interface_opts": {
+ "patron_barcode":
+ xul_param('barcode')
+ || patron.util.retrieve_fleshed_au_via_id(
+ ses(),
+ patron_id
+ ).card().barcode()
+ }
+ },
+ true
+ );
+ } catch(E) {
+ dump('Error in patron.xul, handle_reservation_pickup(): ' + E + '\n');
+ }
+}
+
+function handle_reservation_return(ev) {
+ try {
+ JSAN.use('patron.util');
+ dojo.require("openils.User");
+ dojo.require("openils.XUL");
+ openils.XUL.newTabEasy(
+ "BOOKING_RETURN",
+ $("offlineStrings").getString(
+ "menu.cmd_booking_reservation_return.tab"
+ ), {
+ "bresv_interface_opts": {
+ "patron_barcode":
+ xul_param('barcode')
+ || patron.util.retrieve_fleshed_au_via_id(
+ ses(),
+ patron_id
+ ).card().barcode()
+ }
+ },
+ true
+ );
+ } catch(E) {
+ dump('Error in patron.xul, handle_reservation_pickup(): ' + E + '\n');
+ }
+}
+
+function handle_delete(ev) {
+ try {
+ $('delete').disabled;
+ JSAN.use('patron.util');
+ var p_obj = patron.util.retrieve_fleshed_au_via_id(
+ ses(),
+ patron_id
+ );
+ JSAN.use('util.network');
+ var net = new util.network();
+ if (get_bool( p_obj.super_user() )) {
+ alert($("patronStrings").getString(
+ 'staff.patron.display.cmd_patron_delete.deny_deletion_of_super_user'));
+ return;
+ }
+ if (patron_id == g.data.list.au[0].id()) {
+ alert($("patronStrings").getString(
+ 'staff.patron.display.cmd_patron_delete.deny_deletion_of_self'));
+ return;
+ }
+ var rv = g.error.yns_alert_original(
+ $("patronStrings").getString(
+ 'staff.patron.display.cmd_patron_delete.dialog.message'),
+ $("patronStrings").getString(
+ 'staff.patron.display.cmd_patron_delete.dialog.title'),
+ $("patronStrings").getString(
+ 'staff.patron.display.cmd_patron_delete.dialog.okay'),
+ $("patronStrings").getString(
+ 'staff.patron.display.cmd_patron_delete.dialog.cancel'),
+ null,
+ $("patronStrings").getString(
+ 'staff.patron.display.cmd_patron_delete.dialog.confirmation')
+ );
+ if (rv == 0) {
+ var params = [ ses(), patron_id ];
+ var staff_check = net.simple_request(
+ 'PERM_RETRIEVE_WORK_OU',[
+ ses(),
+ 'STAFF_LOGIN',
+ patron_id
+ ]
+ );
+ if (staff_check.length > 0) {
+ var dest_barcode = window.prompt(
+ $("patronStrings").getString(
+ 'staff.patron.display.cmd_patron_delete.dest_user.prompt'),
+ $("patronStrings").getString(
+ 'staff.patron.display.cmd_patron_delete.dest_user.default_value'),
+ $("patronStrings").getString(
+ 'staff.patron.display.cmd_patron_delete.dest_user.title')
+ );
+ if (!dest_barcode) return;
+ var dest_usr = patron.util.retrieve_fleshed_au_via_barcode(
+ ses(), dest_barcode );
+ if (typeof dest_usr.ilsevent != 'undefined') {
+ alert($("patronStrings").getString(
+ 'staff.patron.display.cmd_patron_delete.dest_user.failure'));
+ return;
+ }
+ if (dest_usr.id() == patron_id) {
+ alert($("patronStrings").getString(
+ 'staff.patron.display.cmd_patron_delete.dest_user.self_reference_failure'));
+ return;
+ }
+ params.push( dest_usr.id() );
+ }
+ var robj = net.simple_request(
+ 'FM_AU_DELETE',
+ params,
+ null,
+ {
+ 'title' : $("patronStrings").getString(
+ 'staff.patron.display.cmd_patron_delete.override_prompt'),
+ 'overridable_events' : [
+ 2004 /* ACTOR_USER_DELETE_OPEN_XACTS */
+ ]
+ }
+ );
+ if (typeof robj.ilsevent != 'undefined') {
+ switch(Number(robj.ilsevent)) {
+ /* already informed via override prompt */
+ case 2004 /* ACTOR_USER_DELETE_OPEN_XACTS */ :
+ return;
+ break;
+ }
+ }
+ util.widgets.dispatch('command','cmd_reload');
+ }
+ $('delete').disabled = false;
+ } catch(E) {
+ dump('Error in patron.xul, handle_delete(): ' + E + '\n');
+ }
+}
+
+function patron_ui_setup() {
+ try {
+ dump('entering patron.xul, ui_setup()\n');
+
+ sort_button_box( $('main_button_group'), false );
+
+ $('cmd_reload').addEventListener(
+ 'command',
+ function(ev){ patron_tab(main_interface,'merely_reset'); },
+ false
+ );
+
+ $('cmd_reservation').addEventListener(
+ 'command',
+ handle_reservation,
+ false
+ );
+
+ $('cmd_reservation_pickup').addEventListener(
+ 'command',
+ handle_reservation_pickup,
+ false
+ );
+
+ $('cmd_reservation_return').addEventListener(
+ 'command',
+ handle_reservation_return,
+ false
+ );
+
+ $('cmd_delete').addEventListener(
+ 'command',
+ handle_delete,
+ false
+ );
+
+ [
+ "bills",
+ "bill_history",
+ "checkout",
+ "edit",
+ "events",
+ "group",
+ "holds",
+ "items_out",
+ "messages",
+ "notes",
+ "perms",
+ "requests",
+ "statcats",
+ "surveys",
+ "test_password"
+ ].forEach(
+ function(cmd) {
+ $('cmd_'+cmd).addEventListener(
+ 'command',
+ function(c_interface) {
+ return function(ev) {
+ patron_tab(c_interface,'merely_reset');
+ }
+ }(cmd),
+ false
+ );
+ }
+ );
+
+ } catch(E) {
+ alert('Error in patron.xul, ui_setup(): ' + E + '\n');
+ }
+}
+
+function patron_ui_populate() {
+ try {
+ $('iframe1').setAttribute(
+ 'src',
+ 'data:,Loading...'
+ );
+ setTimeout(
+ function() {
+ $('iframe1').setAttribute(
+ 'src',
+ urls.EG_PATRON_SUMMARY + '?au_id=' + patron_id
+ );
+ }, 0
+ );
+
+ if ($(main_interface)) {
+ $(main_interface).disabled = true;
+ }
+
+ var barcode_for_some_interfaces = xul_param('barcode');
+ var patron_object_for_some_interfaces;
+
+ var bottom_pane = $('bottom_pane');
+ if ($('iframe2')) { bottom_pane.removeChild($('iframe2')); }
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('id','iframe2');
+ iframe.setAttribute('flex','1');
+ var src = 'data:text/plain,Missing interface';
+ switch(main_interface) {
+ case 'checkout':
+ src = urls.XUL_CHECKOUT;
+ break;
+ case 'items_out':
+ src = urls.XUL_PATRON_ITEMS;
+ break;
+ case 'holds':
+ src = urls.XUL_PATRON_HOLDS;
+ // FIXME - not ideal; but OPAC Place Hold needs this
+ if (!barcode_for_some_interfaces) {
+ JSAN.use('patron.util');
+ var p_obj = patron.util.retrieve_fleshed_au_via_id(
+ ses(),
+ patron_id
+ );
+ barcode_for_some_interfaces = p_obj.card().barcode();
+ }
+ break;
+ case 'messages':
+ src = urls.XUL_STANDING_PENALTIES;
+ JSAN.use('patron.util');
+ patron_object_for_some_interfaces = patron.util.retrieve_fleshed_au_via_id(
+ ses(),
+ patron_id
+ );
+ break;
+ case 'group':
+ src = urls.XUL_PATRON_INFO_GROUP;
+ break;
+ case 'bills':
+ src = urls.XUL_PATRON_BILLS;
+ break;
+ case 'bill_history':
+ src = urls.XUL_PATRON_BILL_HISTORY;
+ break;
+ case 'edit':
+ src = urls.XUL_REMOTE_BROWSER; /* XUL_PATRON_EDIT */
+ break;
+ case 'events':
+ src = urls.XUL_REMOTE_BROWSER; /* EG_TRIGGER_EVENTS */
+ break;
+ case 'statcats':
+ src = urls.XUL_PATRON_INFO_STAT_CATS;
+ break;
+ case 'notes':
+ src = urls.XUL_PATRON_INFO_NOTES;
+ break;
+ case 'requests':
+ src = urls.EG_ACQ_USER_REQUESTS + '?usr=' + patron_id;
+ break;
+ case 'surveys':
+ src = urls.XUL_PATRON_INFO_SURVEYS;
+ break;
+ case 'test_password':
+ src = urls.XUL_VERIFY_CREDENTIALS;
+ var p_obj = patron.util.retrieve_fleshed_au_via_id(
+ ses(),
+ patron_id
+ );
+ patron_object_for_some_interfaces = p_obj;
+ barcode_for_some_interfaces = p_obj.card().barcode();
+ break;
+ case 'perms':
+ src = urls.XUL_USER_PERM_EDITOR
+ + '?ses=' + window.escape(ses())
+ + '&usr=' + patron_id;
+ break;
+ }
+ iframe.setAttribute('src',src);
+ bottom_pane.appendChild(iframe);
+ var cw = get_contentWindow(iframe);
+ cw.IAMXUL = true;
+ cw.xulG = {
+ 'set_tab' : function(a,b,c) { return xulG.set_tab(a,b,c); },
+ 'patron_id' : patron_id,
+ 'get_barcode' : xulG.get_barcode,
+ 'get_barcode_and_settings' : xulG.get_barcode_and_settings,
+ 'get_new_session' : xulG.get_new_session,
+ 'new_tab' : xulG.new_tab,
+ 'new_patron_tab' : xulG.new_patron_tab,
+ 'url_prefix' : xulG.url_prefix,
+ 'on_list_change' : function(x) {},
+ 'lock_tab' : xulG.lock_tab,
+ 'unlock_tab' : xulG.unlock_tab
+ }
+ switch(main_interface) {
+ case 'checkout':
+ cw.xulG.check_stop_checkouts = function() { return false; };
+ break;
+ case 'items_out':
+ break;
+ case 'holds':
+ cw.xulG.patron_barcode = barcode_for_some_interfaces;
+ break;
+ case 'messages':
+ cw.xulG.patron = patron_object_for_some_interfaces;
+ cw.xulG.reset_summary = reset_summary;
+ break;
+ case 'group':
+ break;
+ case 'bills':
+ cw.xulG.on_money_change = function(b) {
+ reset_summary();
+ }
+ cw.xulG.alt_bill_history = function() {
+ patron_tab('bill_history','merely_reset');
+ }
+ break;
+ case 'bill_history':
+ break;
+ case 'edit':
+ cw.xulG.url = urls.XUL_PATRON_EDIT;
+ cw.xulG.show_print_button = urls.XUL_PATRON_EDIT;
+ cw.xulG.passthru_content_params = {
+ 'params' : {
+ 'ses' : ses(),
+ 'usr' : patron_id
+ },
+ 'on_save' : function(p) {
+ JSAN.use('patron.util');
+ patron.util.work_log_patron_edit(p);
+ patron_tab('edit','merely_reset');
+ },
+ 'spawn_search' : spawn_search,
+ 'spawn_editor' : spawn_editor,
+ 'url_prefix' : xulG.url_prefix,
+ 'get_new_session' : xulG.get_new_session,
+ 'new_tab' : xulG.new_tab,
+ 'new_patron_tab' : xulG.new_patron_tab
+ }
+ break;
+ case 'events':
+ cw.xulG.url = urls.EG_TRIGGER_EVENTS + '?patron_id=' + patron_id;
+ cw.xulG.show_print_button = false;
+ cw.xulG.show_nav_buttons = false;
+ break;
+ case 'statcats':
+ break;
+ case 'notes':
+ break;
+ case 'requests':
+ break;
+ case 'surveys':
+ break;
+ case 'test_password':
+ cw.xulG.barcode = barcode_for_some_interfaces;
+ cw.xulG.usrname = patron_object_for_some_interfaces.usrname();
+ break;
+ case 'perms':
+ break;
+ }
+
+ } catch(E) {
+ alert('Error in patron.xul, ui_setup_populate(): ' + E + '\n');
+ }
+}
+
+function patron_default_focus() {
+ setTimeout(
+ function() {
+ try {
+ dump('entering patron.xul, default_focus()\n');
+ if ($('iframe2')) {
+ $('iframe2').focus();
+ var cw = get_contentWindow($('iframe2'));
+ if (cw && typeof cw.default_focus == 'function') {
+ cw.default_focus();
+ }
+ }
+ } catch(E) {
+ dump('Error in patron.xul, default_focus(): ' + E + '\n');
+ }
+ }, 0
+ );
+}
+