select callback, selections, patron display from patron search, and how does a null...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 21 Dec 2005 20:32:31 +0000 (20:32 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 21 Dec 2005 20:32:31 +0000 (20:32 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@2508 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/chrome/content/evergreen/util/list.js
Open-ILS/xul/staff_client/server/main/menu.js
Open-ILS/xul/staff_client/server/patron/display.js
Open-ILS/xul/staff_client/server/patron/display.xul
Open-ILS/xul/staff_client/server/patron/search_result.js
Open-ILS/xul/staff_client/server/patron/search_result_overlay.xul
Open-ILS/xul/staff_client/server/patron/summary.js
Open-ILS/xul/staff_client/server/patron/summary.xul

index 7d649f7..c04c119 100644 (file)
@@ -63,6 +63,13 @@ util.list.prototype = {
                        this.node.appendChild(treechildren);
                        this.treechildren = treechildren;
                }
+               if (typeof params.on_select == 'function') {
+                       this.node.addEventListener(
+                               'select',
+                               params.on_select,
+                               false
+                       );
+               }
        },
 
        '_init_listbox' : function (params) {
@@ -109,6 +116,7 @@ util.list.prototype = {
                var s = ('util.list.append: params = ' + js2JSON(params) + '\n');
 
                var treeitem = document.createElement('treeitem');
+               treeitem.setAttribute('retrieve_id',params.retrieve_id);
                this.treechildren.appendChild( treeitem );
                var treerow = document.createElement('treerow');
                treeitem.appendChild( treerow );
@@ -237,5 +245,26 @@ util.list.prototype = {
                this.error.sdump('D_LIST',s);
        },
 
+       'retrieve_selection' : function(params) {
+               switch(this.node.nodeName) {
+                       case 'tree' : return this._retrieve_selection_from_tree(params); break;
+                       default: throw('NYI: Need ._retrieve_selection_from_() for ' + this.node.nodeName); break;
+               }
+       },
+
+       '_retrieve_selection_from_tree' : function(params) {
+               var list = [];
+               var start = new Object();
+               var end = new Object();
+               var numRanges = this.node.view.selection.getRangeCount();
+               for (var t=0; t<numRanges; t++){
+                       this.node.view.selection.getRangeAt(t,start,end);
+                       for (var v=start.value; v<=end.value; v++){
+                               var i = this.node.contentView.getItemAtIndex(v);
+                               list.push( i );
+                       }
+               }
+               return list;
+       },
 }
 dump('exiting util.list.js\n');
index a72a443..d0561b0 100644 (file)
@@ -38,7 +38,7 @@ main.menu.prototype = {
                        ],
                        'cmd_new_tab' : [
                                ['oncommand'],
-                               function() { obj.new_tab(true); }
+                               function() { obj.new_tab(null,{'focus':true},null); }
                        ],
                        'cmd_close_tab' : [
                                ['oncommand'],
@@ -132,7 +132,7 @@ main.menu.prototype = {
                obj.controller.view.tabs = obj.controller.view.tabbox.firstChild;
                obj.controller.view.panels = obj.controller.view.tabbox.lastChild;
 
-               obj.new_tab(true);
+               obj.new_tab(null,{'focus':true},null);
        },
 
        'close_tab' : function () {
@@ -204,21 +204,29 @@ main.menu.prototype = {
                return -1;
        },
 
-       'new_tab' : function(focus) {
+       'new_tab' : function(url,params,content_params) {
+               if (!url) url = 'data:text/html,<h1>Hello World</h1>'
+               if (!params) params = {};
+               if (!content_params) content_params = {};
                var tc = this.find_free_tab();
                if (tc == -1) { return null; } // 9 tabs max
                var tab = this.controller.view.tabs.childNodes[ tc ];
                //tab.setAttribute('label','Tab ' + (tc + 1) );
                tab.hidden = false;
                try {
-                       if (focus) this.controller.view.tabs.selectedIndex = tc;
-                       this.set_tab('data:text/html,<h1>Hello World</h1>',{ 'index' : tc });
+                       if (params.focus) this.controller.view.tabs.selectedIndex = tc;
+                       params.index = tc;
+                       this.set_tab(url,params,content_params);
                } catch(E) {
                        this.error.sdump('D_ERROR',E);
                }
        },
 
        'set_tab' : function(url,params,content_params) {
+               if (!url) url = 'data:text/html,<h1>Hello World</h1>'
+               if (!params) params = {};
+               if (!content_params) content_params = {};
+               var obj = this;
                var idx = this.controller.view.tabs.selectedIndex;
                if (params && typeof params.index != 'undefined') idx = params.index;
                var tab = this.controller.view.tabs.childNodes[ idx ];
@@ -228,17 +236,13 @@ main.menu.prototype = {
                frame.setAttribute('flex','1');
                frame.setAttribute('src',url);
                panel.appendChild(frame);
-               if (content_params) {
-                       try {
-                               netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-                               //this.error.sdump('D_MENU', 'frame.contentWindow = ' + frame.contentWindow + '\n');
-                               frame.contentWindow.IAMXUL = true;
-                               frame.contentWindow.xulG = content_params;
-                               //this.error.sdump('D_MENU','content_params ' + js2JSON(content_params) +
-                               //'\nframe.contentWindow.xulG = ' + js2JSON(frame.contentWindow.xulG) );
-                       } catch(E) {
-                               this.error.sdump('D_ERROR', 'main.menu: ' + E);
-                       }
+               content_params.new_tab = function(a,b,c) { obj.new_tab(a,b,c); }
+               try {
+                       netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+                       frame.contentWindow.IAMXUL = true;
+                       frame.contentWindow.xulG = content_params;
+               } catch(E) {
+                       this.error.sdump('D_ERROR', 'main.menu: ' + E);
                }
                return frame;
        }
index de9d12c..11eb5d2 100644 (file)
@@ -11,12 +11,15 @@ patron.display = function (params) {
 
 patron.display.prototype = {
 
+       'retrieve_ids' : [],
+
        'init' : function( params ) {
 
                var obj = this;
 
                obj.session = params['session'];
                obj.barcode = params['barcode'];
+               obj.id = params['id'];
 
                JSAN.use('OpenILS.data'); this.OpenILS = {}; 
                obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
@@ -54,6 +57,20 @@ patron.display.prototype = {
                                        'cmd_patron_retrieve' : [
                                                ['command'],
                                                function(ev) {
+                                                       if (typeof window.xulG == 'object' && typeof window.xulG.new_tab == 'function') {
+                                                               for (var i = 0; i < obj.retrieve_ids.length; i++) {     
+                                                                       try {
+                                                                               var url = urls.remote_patron_display 
+                                                                                       + '?session=' + window.escape(obj.session) 
+                                                                                       + '&id=' + window.escape( obj.retrieve_ids[i] );
+                                                                               window.xulG.new_tab(
+                                                                                       url
+                                                                               );
+                                                                       } catch(E) {
+                                                                               alert(E);
+                                                                       }
+                                                               }
+                                                       }
                                                }
                                        ],
                                        'cmd_patron_refresh' : [
@@ -163,7 +180,7 @@ patron.display.prototype = {
                        }
                );
 
-               if (obj.barcode) {
+               if (obj.barcode || obj.id) {
                        obj.controller.view.PatronNavBar.selectedIndex = 1;
                        obj.controller.view.cmd_patron_refresh.setAttribute('disabled','true');
                        obj.controller.view.cmd_patron_checkout.setAttribute('disabled','true');
@@ -176,7 +193,8 @@ patron.display.prototype = {
                        var frame = obj.left_deck.set_iframe(
                                urls.remote_patron_summary
                                +'?session=' + window.escape(obj.session)
-                               +'&barcode=' + window.escape(obj.barcode), 
+                               +'&barcode=' + window.escape(obj.barcode) 
+                               +'&id=' + window.escape(obj.id), 
                                {},
                                {
                                        'on_finished' : function(patron) {
@@ -205,11 +223,16 @@ patron.display.prototype = {
                                {},
                                {
                                        'on_submit' : function(query) {
+                                               obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','true');
                                                var list_frame = obj.right_deck.reset_iframe(
                                                        urls.remote_patron_search_result
                                                        +'?session=' + window.escape(obj.session) + '&' + query,
                                                        {},
                                                        {
+                                                               'on_select' : function(list) {
+                                                                       obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','false');
+                                                                       obj.retrieve_ids = list;
+                                                               }
                                                        }
                                                );
                                                obj.search_result = list_frame.contentWindow;
index c159bac..c617c4a 100644 (file)
                                g.cgi = new CGI();
 
                                JSAN.use('patron.display'); g.patron = new patron.display();
-                               g.patron.init( { 'barcode' : g.cgi.param('barcode') , 'session' : g.cgi.param('session') } );
+                               g.patron.init( { 
+                                       'session' : g.cgi.param('session') , 
+                                       'barcode' : g.cgi.param('barcode') ,
+                                       'id' : g.cgi.param('id') ,
+                               } );
        
                        } catch(E) {
                                var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
index d5271d5..62a7b49 100644 (file)
@@ -47,6 +47,23 @@ patron.search_result.prototype = {
                                        row.my.au = au_obj;
 
                                        return row;
+                               },
+                               'on_select' : function(ev) {
+                                       JSAN.use('util.functional');
+                                       var sel = obj.list.retrieve_selection();
+                                       var list = util.functional.map_list(
+                                               sel,
+                                               function(o) { return o.getAttribute('retrieve_id'); }
+                                       );
+                                       if (typeof obj.on_select == 'function') {
+                                               obj.on_select(list);
+                                       }
+                                       if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
+                                               obj.error.sdump('D_PATRON','patron.search_result: Calling external .on_select()\n');
+                                               window.xulG.on_select(list);
+                                       } else {
+                                               obj.error.sdump('D_PATRON','patron.search_result: No external .on_select()\n');
+                                       }
                                }
                        }
                );
index 1693edf..d6c3ed2 100644 (file)
@@ -8,7 +8,7 @@
 <commandset id="patron_search_result_cmds" />
 
        <box id="patron_search_result_main" flex="1">
-               <tree id="patron_list" flex="1" enableColumnDrag="true"/>
+               <tree id="patron_list" flex="1" enableColumnDrag="true" seltype="multiple"/>
        </box>
 
 </overlay>
index ae2baf1..bf1cc24 100644 (file)
@@ -17,6 +17,7 @@ patron.summary.prototype = {
 
                obj.session = params['session'];
                obj.barcode = params['barcode'];
+               obj.id = params['id'];
 
                JSAN.use('OpenILS.data'); this.OpenILS = {}; 
                obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
@@ -431,11 +432,22 @@ patron.summary.prototype = {
                        chain.push(
                                function() {
                                        try {
-                                               var robj = obj.network.request(
-                                                       api.fm_au_retrieve_via_barcode.app,
-                                                       api.fm_au_retrieve_via_barcode.method,
-                                                       [ obj.session, obj.barcode ]
-                                               );
+                                               var robj;
+                                               if (obj.barcode && obj.barcode != 'null') {
+                                                       robj = obj.network.request(
+                                                               api.fm_au_retrieve_via_barcode.app,
+                                                               api.fm_au_retrieve_via_barcode.method,
+                                                               [ obj.session, obj.barcode ]
+                                                       );
+                                               } else if (obj.id && obj.id != 'null') {
+                                                       robj = obj.network.request(
+                                                               api.fm_au_retrieve_via_id.app,
+                                                               api.fm_au_retrieve_via_id.method,
+                                                               [ obj.session, obj.id ]
+                                                       );
+                                               } else {
+                                                       throw('summary: No barcode or id');
+                                               }
                                                if (robj) {
 
                                                        if (instanceOf(robj,au)) {
index 5d02c5e..ef1f5f1 100644 (file)
                                g.cgi = new CGI();
 
                                JSAN.use('patron.summary'); g.summary = new patron.summary();
-                               g.summary.init( { 'barcode' : g.cgi.param('barcode') , 'session' : g.cgi.param('session') } );
+                               g.summary.init( { 
+                                       'session' : g.cgi.param('session') ,
+                                       'barcode' : g.cgi.param('barcode') , 
+                                       'id' : g.cgi.param('id') , 
+                               } );
 
                                window.refresh = function () { g.summary.retrieve(); }