1 dump('entering util.list.js\n');
3 if (typeof main == 'undefined') main = {};
4 util.list = function (id) {
6 this.node = document.getElementById(id);
8 this.row_count = { 'total' : 0, 'fleshed' : 0 };
10 this.unique_row_counter = 0;
12 if (!this.node) throw('Could not find element ' + id);
13 switch(this.node.nodeName) {
17 throw(this.node.nodeName + ' not yet supported'); break;
18 default: throw(this.node.nodeName + ' not supported'); break;
21 JSAN.use('util.error'); this.error = new util.error();
23 JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.stash_retrieve();
28 util.list.prototype = {
30 'init' : function (params) {
33 obj.scratch_data = {};
35 // If set, save and restore columns as if the tree/list id was the value of columns_saved_under
36 obj.columns_saved_under = params.columns_saved_under;
38 JSAN.use('util.widgets');
40 obj.printer_context = params.printer_context;
42 if (typeof params.map_row_to_column == 'function') obj.map_row_to_column = params.map_row_to_column;
43 if (typeof params.map_row_to_columns == 'function') {
44 obj.map_row_to_columns = params.map_row_to_columns;
46 obj.map_row_to_columns = obj.std_map_row_to_columns();
48 if (typeof params.retrieve_row == 'function') obj.retrieve_row = params.retrieve_row;
51 if (typeof params.prebuilt != 'undefined') obj.prebuilt = params.prebuilt;
53 if (typeof params.columns == 'undefined') throw('util.list.init: No columns');
55 for (var i = 0; i < params.columns.length; i++) {
56 if (typeof params.columns[i] == 'object') {
57 obj.columns.push( params.columns[i] );
59 var cols = obj.fm_columns( params.columns[i] );
60 for (var j = 0; j < cols.length; j++) {
61 obj.columns.push( cols[j] );
66 switch(obj.node.nodeName) {
67 case 'tree' : obj._init_tree(params); break;
68 case 'listbox' : obj._init_listbox(params); break;
69 default: throw('NYI: Need ._init() for ' + obj.node.nodeName); break;
73 '_init_tree' : function (params) {
77 this.treechildren = this.node.lastChild;
80 var treecols = document.createElement('treecols');
81 this.node.appendChild(treecols);
82 this.treecols = treecols;
84 var check_for_id_collisions = {};
85 for (var i = 0; i < this.columns.length; i++) {
86 var treecol = document.createElement('treecol');
87 for (var j in this.columns[i]) {
88 var value = this.columns[i][j];
90 if (typeof check_for_id_collisions[value] == 'undefined') {
91 check_for_id_collisions[value] = true;
93 // Column id's are important for sorting and saving list configuration. Collisions started happening because
94 // we were using field names as id's, and then later combining column definitions for multiple objects that
95 // shared field names. The downside to this sort of automatic collision prevention is that these generated
96 // id's can change as we add and remove columns, possibly breaking saved list configurations.
97 dump('Column collision with id = ' + value + ', renaming to ');
98 value = value + '_collision_' + i;
102 treecol.setAttribute(j,value);
104 treecols.appendChild(treecol);
105 if (this.columns[i].type == 'checkbox') {
106 treecol.addEventListener(
111 var toggle = ev.target.getAttribute('toggleAll') || 'on';
112 if (toggle == 'off') toggle = 'on'; else toggle = 'off';
113 ev.target.setAttribute('toggleAll',toggle);
114 obj._toggle_checkbox_column(ev.target,toggle);
121 treecol.addEventListener(
125 var sortDir = ev.target.getAttribute('sortDir') || 'desc';
126 if (sortDir == 'desc') sortDir = 'asc'; else sortDir = 'desc';
127 ev.target.setAttribute('sortDir',sortDir);
128 obj._sort_tree(ev.target,sortDir);
131 if (obj.row_count.total != obj.row_count.fleshed && (obj.row_count.total - obj.row_count.fleshed) > 50) {
132 var r = window.confirm(document.getElementById('offlineStrings').getFormattedString('list.row_fetch_warning',[obj.row_count.fleshed,obj.row_count.total]));
135 setTimeout( do_it, 0 );
138 setTimeout( do_it, 0 );
144 var splitter = document.createElement('splitter');
145 splitter.setAttribute('class','tree-splitter');
146 treecols.appendChild(splitter);
149 var treechildren = document.createElement('treechildren');
150 this.node.appendChild(treechildren);
151 this.treechildren = treechildren;
153 if (typeof params.on_sort == 'function') {
154 this.on_sort = params.on_sort;
156 if (typeof params.on_checkbox_toggle == 'function') {
157 this.on_checkbox_toggle = params.on_checkbox_toggle;
159 this.node.addEventListener(
162 if (typeof params.on_select == 'function') {
163 params.on_select(ev);
165 var x = document.getElementById(obj.node.id + '_clipfield');
167 var sel = obj.retrieve_selection();
168 x.setAttribute('disabled', sel.length == 0);
173 if (typeof params.on_click == 'function') {
174 this.node.addEventListener(
180 if (typeof params.on_dblclick == 'function') {
181 this.node.addEventListener(
189 this.node.addEventListener(
191 function(ev) { obj.detect_visible(); },
195 this.node.addEventListener(
197 function(ev) { obj.auto_retrieve(); },
200 this.node.addEventListener(
202 function(ev) { obj.auto_retrieve(); },
205 window.addEventListener(
207 function(ev) { obj.auto_retrieve(); },
210 /* FIXME -- find events on scrollbar to trigger this */
211 obj.detect_visible_polling();
213 var scrollbar = document.getAnonymousNodes( document.getAnonymousNodes(this.node)[1] )[1];
214 var slider = document.getAnonymousNodes( scrollbar )[2];
215 alert('scrollbar = ' + scrollbar.nodeName + ' grippy = ' + slider.nodeName);
216 scrollbar.addEventListener('click',function(){alert('sb click');},false);
217 scrollbar.addEventListener('command',function(){alert('sb command');},false);
218 scrollbar.addEventListener('scroll',function(){alert('sb scroll');},false);
219 slider.addEventListener('click',function(){alert('slider click');},false);
220 slider.addEventListener('command',function(){alert('slider command');},false);
221 slider.addEventListener('scroll',function(){alert('slider scroll');},false);
223 this.node.addEventListener('scroll',function(){ obj.auto_retrieve(); },false);
225 this.restores_columns(params);
228 '_init_listbox' : function (params) {
231 var listhead = document.createElement('listhead');
232 this.node.appendChild(listhead);
234 var listcols = document.createElement('listcols');
235 this.node.appendChild(listcols);
237 for (var i = 0; i < this.columns.length; i++) {
238 var listheader = document.createElement('listheader');
239 listhead.appendChild(listheader);
240 var listcol = document.createElement('listcol');
241 listcols.appendChild(listcol);
242 for (var j in this.columns[i]) {
243 listheader.setAttribute(j,this.columns[i][j]);
244 listcol.setAttribute(j,this.columns[i][j]);
250 'save_columns' : function (params) {
252 if (obj.data.hash.aous['gui.disable_local_save_columns']) {
253 alert(document.getElementById('offlineStrings').getString('list.column_save_disabled'));
255 switch (this.node.nodeName) {
256 case 'tree' : this._save_columns_tree(params); break;
257 default: throw('NYI: Need .save_columns() for ' + this.node.nodeName); break;
262 '_save_columns_tree' : function (params) {
265 var id = obj.node.getAttribute('id');
266 if (obj.columns_saved_under) { id = obj.columns_saved_under; }
268 alert("FIXME: The columns for this list cannot be saved because the list has no id.");
272 var nl = obj.node.getElementsByTagName('treecol');
273 for (var i = 0; i < nl.length; i++) {
275 var col_id = col.getAttribute('id');
277 alert('FIXME: A column in this list does not have an id and cannot be saved');
280 var col_hidden = col.getAttribute('hidden');
281 var col_width = col.getAttribute('width');
282 var col_ordinal = col.getAttribute('ordinal');
283 my_cols[ col_id ] = { 'hidden' : col_hidden, 'width' : col_width, 'ordinal' : col_ordinal };
285 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
286 JSAN.use('util.file'); var file = new util.file('tree_columns_for_'+window.escape(id));
287 file.set_object(my_cols);
289 alert(document.getElementById('offlineStrings').getString('list.columns_saved'));
291 obj.error.standard_unexpected_error_alert('_save_columns_tree',E);
295 'restores_columns' : function (params) {
297 switch (this.node.nodeName) {
298 case 'tree' : this._restores_columns_tree(params); break;
299 default: throw('NYI: Need .restores_columns() for ' + this.node.nodeName); break;
303 '_restores_columns_tree' : function (params) {
306 var id = obj.node.getAttribute('id');
307 if (obj.columns_saved_under) { id = obj.columns_saved_under; }
309 alert("FIXME: The columns for this list cannot be restored because the list has no id.");
314 if (! obj.data.hash.aous) { obj.data.hash.aous = {}; }
315 if (! obj.data.hash.aous['gui.disable_local_save_columns']) {
316 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
317 JSAN.use('util.file'); var file = new util.file('tree_columns_for_'+window.escape(id));
318 if (file._file.exists()) {
319 my_cols = file.get_object(); file.close();
322 /* local file will trump remote file if allowed, so save ourselves an http request if this is the case */
323 if (obj.data.hash.aous['url.remote_column_settings'] && ! my_cols ) {
325 var x = new XMLHttpRequest();
326 var url = obj.data.hash.aous['url.remote_column_settings'] + '/tree_columns_for_' + window.escape(id);
327 x.open("GET", url, false);
329 if (x.status == 200) {
330 my_cols = JSON2js( x.responseText );
333 // This can happen in the offline interface if you logged in previously and url.remote_column_settings is set.
334 // 1) You may be really "offline" now
335 // 2) the URL may just be a path component without a hostname (ie "/xul/column_settings/"), which won't work
336 // when appended to chrome://open_ils_staff_client/
337 dump('Error retrieving column settings from ' + url + ': ' + E + '\n');
342 var nl = obj.node.getElementsByTagName('treecol');
343 for (var i = 0; i < nl.length; i++) {
345 var col_id = col.getAttribute('id');
347 alert('FIXME: A column in this list does not have an id and cannot be saved');
350 if (typeof my_cols[col_id] != 'undefined') {
351 col.setAttribute('hidden',my_cols[col_id].hidden);
352 col.setAttribute('width',my_cols[col_id].width);
353 col.setAttribute('ordinal',my_cols[col_id].ordinal);
355 obj.error.sdump('D_ERROR','WARNING: Column ' + col_id + ' did not have a saved state.');
360 obj.error.standard_unexpected_error_alert('_restore_columns_tree',E);
364 'clear' : function (params) {
366 switch (this.node.nodeName) {
367 case 'tree' : this._clear_tree(params); break;
368 case 'listbox' : this._clear_listbox(params); break;
369 default: throw('NYI: Need .clear() for ' + this.node.nodeName); break;
371 this.error.sdump('D_LIST','Clearing list ' + this.node.getAttribute('id') + '\n');
372 this.row_count.total = 0;
373 this.row_count.fleshed = 0;
374 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
377 '_clear_tree' : function(params) {
379 if (obj.error.sdump_levels.D_LIST_DUMP_ON_CLEAR) {
380 obj.error.sdump('D_LIST_DUMP_ON_CLEAR',obj.dump());
382 if (obj.error.sdump_levels.D_LIST_DUMP_WITH_KEYS_ON_CLEAR) {
383 obj.error.sdump('D_LIST_DUMP_WITH_KEYS_ON_CLEAR',obj.dump_with_keys());
385 while (obj.treechildren.lastChild) obj.treechildren.removeChild( obj.treechildren.lastChild );
388 '_clear_listbox' : function(params) {
391 var nl = this.node.getElementsByTagName('listitem');
392 for (var i = 0; i < nl.length; i++) {
395 for (var i = 0; i < items.length; i++) {
396 this.node.removeChild(items[i]);
400 'append' : function (params) {
403 switch (this.node.nodeName) {
404 case 'tree' : rparams = this._append_to_tree(params); break;
405 case 'listbox' : rparams = this._append_to_listbox(params); break;
406 default: throw('NYI: Need .append() for ' + this.node.nodeName); break;
408 if (rparams && params.attributes) {
409 for (var i in params.attributes) {
410 rparams.my_node.setAttribute(i,params.attributes[i]);
413 this.row_count.total++;
414 if (this.row_count.fleshed == this.row_count.total) {
415 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
417 rparams.my_node.setAttribute('unique_row_counter',obj.unique_row_counter);
418 rparams.unique_row_counter = obj.unique_row_counter++;
419 if (typeof params.on_append == 'function') {
420 params.on_append(rparams);
425 'refresh_row' : function (params) {
428 switch (this.node.nodeName) {
429 case 'tree' : rparams = this._refresh_row_in_tree(params); break;
430 default: throw('NYI: Need .refresh_row() for ' + this.node.nodeName); break;
432 if (rparams && params.attributes) {
433 for (var i in params.attributes) {
434 rparams.my_node.setAttribute(i,params.attributes[i]);
437 this.row_count.fleshed--;
442 '_append_to_tree' : function (params) {
446 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
448 var s = ('util.list.append: params = ' + (params) + '\n');
450 var treechildren_node = this.treechildren;
452 if (params.node && params.node.nodeName == 'treeitem') {
453 params.node.setAttribute('container','true'); /* params.node.setAttribute('open','true'); */
454 if (params.node.lastChild.nodeName == 'treechildren') {
455 treechildren_node = params.node.lastChild;
457 treechildren_node = document.createElement('treechildren');
458 params.node.appendChild(treechildren_node);
462 var treeitem = document.createElement('treeitem');
463 treeitem.setAttribute('retrieve_id',params.retrieve_id);
464 if (typeof params.to_bottom != 'undefined') {
465 treechildren_node.appendChild( treeitem );
466 if (typeof params.no_auto_select == 'undefined') {
467 if (!obj.auto_select_pending) {
468 obj.auto_select_pending = true;
469 setTimeout(function() {
470 dump('auto-selecting\n');
471 var idx = Number(obj.node.view.rowCount)-1;
472 try { obj.node.view.selection.select(idx); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); }
473 try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); }
474 obj.auto_select_pending = false;
475 try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(idx).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); }
480 if (treechildren_node.firstChild) {
481 treechildren_node.insertBefore( treeitem, treechildren_node.firstChild );
483 treechildren_node.appendChild( treeitem );
485 if (typeof params.no_auto_select == 'undefined') {
486 if (!obj.auto_select_pending) {
487 obj.auto_select_pending = true;
488 setTimeout(function() {
489 try { obj.node.view.selection.select(0); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); }
490 try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); }
491 obj.auto_select_pending = false;
492 try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(0).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); }
497 var treerow = document.createElement('treerow');
498 treeitem.appendChild( treerow );
499 treerow.setAttribute('retrieve_id',params.retrieve_id);
500 if (params.row_properties) treerow.setAttribute('properties',params.row_properties);
502 s += ('tree = ' + this.node + ' treechildren = ' + treechildren_node + '\n');
503 s += ('treeitem = ' + treeitem + ' treerow = ' + treerow + '\n');
505 obj.put_retrieving_label(treerow);
507 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
508 treerow.addEventListener(
512 if (treerow.getAttribute('retrieved') == 'true') return; /* already running */
514 treerow.setAttribute('retrieved','true');
516 //dump('fleshing = ' + params.retrieve_id + '\n');
518 function inc_fleshed() {
519 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
520 treerow.setAttribute('fleshed','true');
521 obj.row_count.fleshed++;
522 if (obj.row_count.fleshed >= obj.row_count.total) {
523 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
527 params.row_node = treeitem;
528 params.on_retrieve = function(p) {
531 obj._map_row_to_treecell(p,treerow);
533 var idx = obj.node.contentView.getIndexOfItem( params.row_node );
534 dump('idx = ' + idx + '\n');
535 // if current row is selected, send another select event to re-sync data that the client code fetches on selects
536 if ( obj.node.view.selection.isSelected( idx ) ) {
537 dump('dispatching select event for on_retrieve for idx = ' + idx + '\n');
538 util.widgets.dispatch('select',obj.node);
541 // Let's not alert on this for now. Getting contentView has no properties in record buckets under certain conditions
542 dump('fixme2: ' + E + '\n');
546 if (typeof params.retrieve_row == 'function') {
548 params.retrieve_row( params );
550 } else if (typeof obj.retrieve_row == 'function') {
552 obj.retrieve_row( params );
561 if (typeof params.flesh_immediately != 'undefined') {
562 if (params.flesh_immediately) {
565 util.widgets.dispatch('flesh',treerow);
571 treerow.addEventListener(
574 //dump('fleshing anon\n');
575 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
576 obj._map_row_to_treecell(params,treerow);
577 treerow.setAttribute('retrieved','true');
578 treerow.setAttribute('fleshed','true');
579 obj.row_count.fleshed++;
580 if (obj.row_count.fleshed >= obj.row_count.total) {
581 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
586 if (typeof params.flesh_immediately != 'undefined') {
587 if (params.flesh_immediately) {
590 util.widgets.dispatch('flesh',treerow);
596 this.error.sdump('D_LIST',s);
600 if (obj.trim_list && obj.row_count.total >= obj.trim_list) {
602 //if (typeof params.to_bottom != 'undefined')
603 if (typeof params.to_top == 'undefined') {
604 if (typeof params.on_delete == 'function') { params.on_delete( treechildren_node.firstChild.getAttribute('unique_row_counter') ); }
605 treechildren_node.removeChild( treechildren_node.firstChild );
607 if (typeof params.on_delete == 'function') { params.on_delete( treechildren_node.lastChild.getAttribute('unique_row_counter') ); }
608 treechildren_node.removeChild( treechildren_node.lastChild );
614 setTimeout( function() { obj.auto_retrieve(); }, 0 );
616 params.my_node = treeitem;
620 '_refresh_row_in_tree' : function (params) {
624 if (typeof params.row == 'undefined') throw('util.list.refresh_row: Object must contain a row');
625 if (typeof params.my_node == 'undefined') throw('util.list.refresh_row: Object must contain a my_node');
626 if (params.my_node.nodeName != 'treeitem') throw('util.list.refresh_rwo: my_node must be a treeitem');
628 var s = ('util.list.refresh_row: params = ' + (params) + '\n');
630 var treeitem = params.my_node;
631 treeitem.setAttribute('retrieve_id',params.retrieve_id);
632 if (typeof params.to_bottom != 'undefined') {
633 if (typeof params.no_auto_select == 'undefined') {
634 if (!obj.auto_select_pending) {
635 obj.auto_select_pending = true;
636 setTimeout(function() {
637 dump('auto-selecting\n');
638 var idx = Number(obj.node.view.rowCount)-1;
639 try { obj.node.view.selection.select(idx); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); }
640 try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); }
641 obj.auto_select_pending = false;
642 try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(idx).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); }
647 //var delete_me = [];
648 //for (var i in treeitem.childNodes) if (treeitem.childNodes[i].nodeName == 'treerow') delete_me.push(treeitem.childNodes[i]);
649 //for (var i = 0; i < delete_me.length; i++) treeitem.removeChild(delete_me[i]);
650 var prev_treerow = treeitem.firstChild; /* FIXME: worry about hierarchal lists like copy_browser? */
651 var treerow = document.createElement('treerow');
652 while (prev_treerow.firstChild) {
653 treerow.appendChild( prev_treerow.removeChild( prev_treerow.firstChild ) );
655 treeitem.replaceChild( treerow, prev_treerow );
656 treerow.setAttribute('retrieve_id',params.retrieve_id);
657 if (params.row_properties) treerow.setAttribute('properties',params.row_properties);
659 s += ('tree = ' + this.node.nodeName + '\n');
660 s += ('treeitem = ' + treeitem.nodeName + ' treerow = ' + treerow.nodeName + '\n');
662 obj.put_retrieving_label(treerow);
664 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
666 s += 'found a retrieve_row function\n';
668 treerow.addEventListener(
672 if (treerow.getAttribute('retrieved') == 'true') return; /* already running */
674 treerow.setAttribute('retrieved','true');
676 //dump('fleshing = ' + params.retrieve_id + '\n');
678 function inc_fleshed() {
679 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
680 treerow.setAttribute('fleshed','true');
681 obj.row_count.fleshed++;
682 if (obj.row_count.fleshed >= obj.row_count.total) {
683 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
687 params.row_node = treeitem;
688 params.on_retrieve = function(p) {
691 obj._map_row_to_treecell(p,treerow);
693 var idx = obj.node.contentView.getIndexOfItem( params.row_node );
694 dump('idx = ' + idx + '\n');
695 // if current row is selected, send another select event to re-sync data that the client code fetches on selects
696 if ( obj.node.view.selection.isSelected( idx ) ) {
697 dump('dispatching select event for on_retrieve for idx = ' + idx + '\n');
698 util.widgets.dispatch('select',obj.node);
701 // Let's not alert on this for now. Getting contentView has no properties in record buckets under certain conditions
702 dump('fixme2: ' + E + '\n');
706 if (typeof params.retrieve_row == 'function') {
708 params.retrieve_row( params );
710 } else if (typeof obj.retrieve_row == 'function') {
712 obj.retrieve_row( params );
721 if (typeof params.flesh_immediately != 'undefined') {
722 if (params.flesh_immediately) {
725 util.widgets.dispatch('flesh',treerow);
733 s += 'did not find a retrieve_row function\n';
735 treerow.addEventListener(
738 //dump('fleshing anon\n');
739 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
740 obj._map_row_to_treecell(params,treerow);
741 treerow.setAttribute('retrieved','true');
742 treerow.setAttribute('fleshed','true');
743 obj.row_count.fleshed++;
744 if (obj.row_count.fleshed >= obj.row_count.total) {
745 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
750 if (typeof params.flesh_immediately != 'undefined') {
751 if (params.flesh_immediately) {
754 util.widgets.dispatch('flesh',treerow);
764 if (obj.trim_list && obj.row_count.total >= obj.trim_list) {
766 //if (typeof params.to_bottom != 'undefined')
767 if (typeof params.to_top == 'undefined') {
768 treechildren_node.removeChild( treechildren_node.firstChild );
770 treechildren_node.removeChild( treechildren_node.lastChild );
776 setTimeout( function() { obj.auto_retrieve(); }, 0 );
778 JSAN.use('util.widgets'); util.widgets.dispatch('select',obj.node);
780 this.error.sdump('D_LIST',s);
785 'put_retrieving_label' : function(treerow) {
788 for (var i = 0; i < obj.columns.length; i++) {
790 if (typeof treerow.childNodes[i] == 'undefined') {
791 treecell = document.createElement('treecell');
792 treerow.appendChild(treecell);
794 treecell = treerow.childNodes[i];
796 treecell.setAttribute('label',document.getElementById('offlineStrings').getString('list.row_retrieving'));
799 alert('Error in list.js, put_retrieving_label(): ' + E);
803 'detect_visible' : function() {
806 //dump('detect_visible obj.node = ' + obj.node + '\n');
807 /* FIXME - this is a hack.. if the implementation of tree changes, this could break */
809 /*var s = ''; var A = document.getAnonymousNodes(obj.node);
812 s += '\t' + (typeof B.nodeName != 'undefined' ? B.nodeName : B ) + '\n';
813 if (typeof B.childNodes != 'undefined') for (var j = 0; j < B.childNodes.length; j++) {
814 var C = B.childNodes[j];
815 s += '\t\t' + C.nodeName + '\n';
818 obj.error.sdump('D_XULRUNNER','document.getAnonymousNodes(' + obj.node.nodeName + ') = \n' + s + '\n');*/
819 var scrollbar = document.getAnonymousNodes(obj.node)[2].firstChild;
820 var curpos = scrollbar.getAttribute('curpos');
821 var maxpos = scrollbar.getAttribute('maxpos');
822 //alert('curpos = ' + curpos + ' maxpos = ' + maxpos + ' obj.curpos = ' + obj.curpos + ' obj.maxpos = ' + obj.maxpos + '\n');
823 if ((curpos != obj.curpos) || (maxpos != obj.maxpos)) {
824 if ( obj.auto_retrieve() > 0 ) {
825 obj.curpos = curpos; obj.maxpos = maxpos;
829 obj.error.sdump('D_XULRUNNER', 'List implementation changed? ' + E);
831 } catch(E) { obj.error.sdump('D_ERROR',E); }
834 'detect_visible_polling' : function() {
836 //alert('detect_visible_polling');
838 obj.detect_visible();
839 setTimeout(function() { try { obj.detect_visible_polling(); } catch(E) { alert(E); } },2000);
846 'auto_retrieve' : function(params) {
848 switch (this.node.nodeName) {
849 case 'tree' : obj._auto_retrieve_tree(params); break;
850 default: throw('NYI: Need .auto_retrieve() for ' + obj.node.nodeName); break;
854 '_auto_retrieve_tree' : function (params) {
856 if (!obj.auto_retrieve_in_progress) {
857 obj.auto_retrieve_in_progress = true;
861 //alert('auto_retrieve\n');
863 var startpos = obj.node.treeBoxObject.getFirstVisibleRow();
864 var endpos = obj.node.treeBoxObject.getLastVisibleRow();
865 if (startpos > endpos) endpos = obj.node.treeBoxObject.getPageLength();
866 //dump('startpos = ' + startpos + ' endpos = ' + endpos + '\n');
867 for (var i = startpos; i < endpos + 4; i++) {
869 //dump('trying index ' + i + '\n');
870 var item = obj.node.contentView.getItemAtIndex(i).firstChild;
871 if (item && item.getAttribute('retrieved') != 'true' ) {
872 //dump('\tgot an unfleshed item = ' + item + ' = ' + item.nodeName + '\n');
873 util.widgets.dispatch('flesh',item); count++;
876 //dump(i + ' : ' + E + '\n');
879 obj.auto_retrieve_in_progress = false;
881 } catch(E) { alert(E); }
887 'exec_on_all_fleshed' : function() {
890 if (obj.on_all_fleshed) {
891 if (typeof obj.on_all_fleshed == 'function') {
892 dump('exec_on_all_fleshed == function\n');
895 try { obj.on_all_fleshed(); } catch(E) { obj.error.standard_unexpected_error_alert('_full_retrieve_tree callback',obj.on_all_fleshed); }
898 } else if (typeof obj.on_all_fleshed.length != 'undefined') {
899 dump('exec_on_all_fleshed == array\n');
903 dump('exec_on_all_fleshed, processing on_all_fleshed array, length = ' + obj.on_all_fleshed.length + '\n');
904 var f = obj.on_all_fleshed.pop();
905 if (typeof f == 'function') {
906 try { f(); } catch(E) { obj.error.standard_unexpected_error_alert('_full_retrieve_tree callback',f); }
908 if (obj.on_all_fleshed.length > 0) arguments.callee();
910 obj.error.standard_unexpected_error_alert('exec_on_all_fleshed callback error',E);
915 obj.error.standard_unexpected_error_alert('unexpected on_all_fleshed object: ', obj.on_all_fleshed);
919 obj.error.standard_unexpected_error_alert('exec_on_all-fleshed error',E);
923 'full_retrieve' : function(params) {
925 switch (this.node.nodeName) {
926 case 'tree' : obj._full_retrieve_tree(params); break;
927 default: throw('NYI: Need .full_retrieve() for ' + obj.node.nodeName); break;
931 '_full_retrieve_tree' : function(params) {
934 if (obj.row_count.fleshed >= obj.row_count.total) {
935 dump('Full retrieve... tree seems to be in sync\n' + js2JSON(obj.row_count) + '\n');
936 obj.exec_on_all_fleshed();
938 dump('Full retrieve... syncing tree' + js2JSON(obj.row_count) + '\n');
939 JSAN.use('util.widgets');
940 var nodes = obj.treechildren.childNodes;
941 for (var i = 0; i < nodes.length; i++) {
942 util.widgets.dispatch('flesh',nodes[i].firstChild);
946 obj.error.standard_unexpected_error_alert('_full_retrieve_tree',E);
950 '_append_to_listbox' : function (params) {
954 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
956 var s = ('util.list.append: params = ' + (params) + '\n');
958 var listitem = document.createElement('listitem');
960 s += ('listbox = ' + this.node + ' listitem = ' + listitem + '\n');
962 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
966 listitem.setAttribute('retrieve_id',params.retrieve_id);
967 //FIXME//Make async and fire when row is visible in list
970 params.row_node = listitem;
971 params.on_retrieve = function(row) {
973 obj._map_row_to_listcell(params,listitem);
974 obj.node.appendChild( listitem );
975 util.widgets.dispatch('select',obj.node);
978 if (typeof params.retrieve_row == 'function') {
980 row = params.retrieve_row( params );
984 if (typeof obj.retrieve_row == 'function') {
986 row = obj.retrieve_row( params );
993 this._map_row_to_listcell(params,listitem);
994 this.node.appendChild( listitem );
997 this.error.sdump('D_LIST',s);
998 params.my_node = listitem;
1003 '_map_row_to_treecell' : function(params,treerow) {
1007 if (typeof params.map_row_to_column == 'function' || typeof this.map_row_to_column == 'function') {
1009 for (var i = 0; i < this.columns.length; i++) {
1011 if (typeof treerow.childNodes[i] == 'undefined') {
1012 treecell = document.createElement('treecell');
1013 treerow.appendChild( treecell );
1015 treecell = treerow.childNodes[i];
1018 if ( this.columns[i].editable == false ) { treecell.setAttribute('editable','false'); }
1020 var sort_value = '';
1022 // What skip columns is doing is rendering the treecells as blank/empty
1023 if (params.skip_columns && (params.skip_columns.indexOf(i) != -1)) {
1024 treecell.setAttribute('label',label);
1025 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
1028 if (params.skip_all_columns_except && (params.skip_all_columns_except.indexOf(i) == -1)) {
1029 treecell.setAttribute('label',label);
1030 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
1034 if (typeof params.map_row_to_column == 'function') {
1036 label = params.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1038 } else if (typeof this.map_row_to_column == 'function') {
1040 label = this.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1043 if (this.columns[i].type == 'checkbox') { treecell.setAttribute('value',label); } else { treecell.setAttribute('label',label ? label : ''); }
1044 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
1046 } else if (typeof params.map_row_to_columns == 'function' || typeof this.map_row_to_columns == 'function') {
1049 var sort_values = [];
1051 if (typeof params.map_row_to_columns == 'function') {
1053 var values = params.map_row_to_columns(params.row,this.columns,this.scratch_data);
1054 if (typeof values.values == 'undefined') {
1057 labels = values.values;
1058 sort_values = values.sort_values;
1061 } else if (typeof this.map_row_to_columns == 'function') {
1063 var values = this.map_row_to_columns(params.row,this.columns,this.scratch_data);
1064 if (typeof values.values == 'undefined') {
1067 labels = values.values;
1068 sort_values = values.sort_values;
1071 for (var i = 0; i < labels.length; i++) {
1073 if (typeof treerow.childNodes[i] == 'undefined') {
1074 treecell = document.createElement('treecell');
1075 treerow.appendChild(treecell);
1077 treecell = treerow.childNodes[i];
1079 if ( this.columns[i].editable == false ) { treecell.setAttribute('editable','false'); }
1080 if ( this.columns[i].type == 'checkbox') {
1081 treecell.setAttribute('value', labels[i]);
1083 treecell.setAttribute('label',typeof labels[i] == 'string' || typeof labels[i] == 'number' ? labels[i] : '');
1085 if (sort_values[i]) {
1086 treecell.setAttribute('sort_value',js2JSON(sort_values[i]));
1088 s += ('treecell = ' + treecell + ' with label = ' + labels[i] + '\n');
1093 throw('No row to column mapping function.');
1095 this.error.sdump('D_LIST',s);
1098 '_map_row_to_listcell' : function(params,listitem) {
1101 for (var i = 0; i < this.columns.length; i++) {
1103 if (typeof params.map_row_to_column == 'function') {
1105 value = params.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1109 if (typeof this.map_row_to_column == 'function') {
1111 value = this.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1114 if (typeof value == 'string' || typeof value == 'number') {
1115 var listcell = document.createElement('listcell');
1116 listcell.setAttribute('label',value);
1117 listitem.appendChild(listcell);
1118 s += ('listcell = ' + listcell + ' with label = ' + value + '\n');
1120 listitem.appendChild(value);
1121 s += ('listcell = ' + value + ' is really a ' + value.nodeName + '\n');
1124 this.error.sdump('D_LIST',s);
1127 'select_all' : function(params) {
1129 switch(this.node.nodeName) {
1130 case 'tree' : return this._select_all_from_tree(params); break;
1131 default: throw('NYI: Need ._select_all_from_() for ' + this.node.nodeName); break;
1135 '_select_all_from_tree' : function(params) {
1137 this.node.view.selection.selectAll();
1140 'retrieve_selection' : function(params) {
1142 switch(this.node.nodeName) {
1143 case 'tree' : return this._retrieve_selection_from_tree(params); break;
1144 default: throw('NYI: Need ._retrieve_selection_from_() for ' + this.node.nodeName); break;
1148 '_retrieve_selection_from_tree' : function(params) {
1151 var start = new Object();
1152 var end = new Object();
1153 var numRanges = this.node.view.selection.getRangeCount();
1154 for (var t=0; t<numRanges; t++){
1155 this.node.view.selection.getRangeAt(t,start,end);
1156 for (var v=start.value; v<=end.value; v++){
1157 var i = this.node.contentView.getItemAtIndex(v);
1164 'dump' : function(params) {
1166 switch(this.node.nodeName) {
1167 case 'tree' : return this._dump_tree(params); break;
1168 default: throw('NYI: Need .dump() for ' + this.node.nodeName); break;
1172 '_dump_tree' : function(params) {
1175 for (var i = 0; i < this.treechildren.childNodes.length; i++) {
1177 var treeitem = this.treechildren.childNodes[i];
1178 var treerow = treeitem.firstChild;
1179 for (var j = 0; j < treerow.childNodes.length; j++) {
1180 row.push( treerow.childNodes[j].getAttribute('label') );
1187 'dump_with_keys' : function(params) {
1189 switch(this.node.nodeName) {
1190 case 'tree' : return this._dump_tree_with_keys(params); break;
1191 default: throw('NYI: Need .dump_with_keys() for ' + this.node.nodeName); break;
1196 '_dump_tree_with_keys' : function(params) {
1200 function process_tree(treechildren) {
1201 for (var i = 0; i < treechildren.childNodes.length; i++) {
1203 var treeitem = treechildren.childNodes[i];
1204 var treerow = treeitem.firstChild;
1205 for (var j = 0; j < treerow.childNodes.length; j++) {
1206 if (typeof obj.columns[j] == 'undefined') {
1207 dump('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n');
1208 dump('_dump_tree_with_keys @ ' + location.href + '\n');
1209 dump('\ttreerow.childNodes.length='+treerow.childNodes.length+' j='+j+' obj.columns.length='+obj.columns.length+'\n');
1212 row[ obj.columns[j].id ] = treerow.childNodes[j].getAttribute('label');
1213 var sort = treerow.childNodes[j].getAttribute('sort_value');
1215 row[ obj.columns[j].id + '_sort_value' ] = sort;
1220 if (treeitem.childNodes.length > 1) {
1221 process_tree(treeitem.lastChild);
1226 process_tree(this.treechildren);
1231 'dump_csv' : function(params) {
1233 switch(this.node.nodeName) {
1234 case 'tree' : return this._dump_tree_csv(params); break;
1235 default: throw('NYI: Need .dump_csv() for ' + this.node.nodeName); break;
1240 '_dump_tree_csv' : function(params) {
1244 for (var j = 0; j < obj.columns.length; j++) {
1245 if (obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('hidden') == 'true') {
1248 ord_cols.push( [ obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('ordinal'), j ] );
1251 ord_cols.sort( function(a,b) {
1252 if ( Number( a[0] ) < Number( b[0] ) ) return -1;
1253 if ( Number( a[0] ) > Number( b[0] ) ) return 1;
1256 for (var j = 0; j < ord_cols.length; j++) {
1257 if (_dump) _dump += ',';
1258 _dump += '"' + obj.columns[ ord_cols[j][1] ].label.replace(/"/g, '""') + '"';
1262 function process_tree(treechildren) {
1263 for (var i = 0; i < treechildren.childNodes.length; i++) {
1265 var treeitem = treechildren.childNodes[i];
1266 var treerow = treeitem.firstChild;
1267 for (var j = 0; j < ord_cols.length; j++) {
1268 if (row) row += ',';
1269 row += '"' + treerow.childNodes[ ord_cols[j][1] ].getAttribute('label').replace(/"/g, '""') + '"';
1271 _dump += row + '\r\n';
1272 if (treeitem.childNodes.length > 1) {
1273 process_tree(treeitem.lastChild);
1278 process_tree(this.treechildren);
1283 'dump_extended_format' : function(params) {
1285 switch(this.node.nodeName) {
1286 case 'tree' : return this._dump_tree_extended_format(params); break;
1287 default: throw('NYI: Need .dump_extended_format() for ' + this.node.nodeName); break;
1292 '_dump_tree_extended_format' : function(params) {
1296 for (var j = 0; j < obj.columns.length; j++) {
1297 if (obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('hidden') == 'true') {
1300 ord_cols.push( [ obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('ordinal'), j ] );
1303 ord_cols.sort( function(a,b) {
1304 if ( Number( a[0] ) < Number( b[0] ) ) return -1;
1305 if ( Number( a[0] ) > Number( b[0] ) ) return 1;
1309 function process_tree(treechildren) {
1310 for (var i = 0; i < treechildren.childNodes.length; i++) {
1311 var row = document.getElementById('offlineStrings').getString('list.dump_extended_format.record_separator') + '\r\n';
1312 var treeitem = treechildren.childNodes[i];
1313 var treerow = treeitem.firstChild;
1314 for (var j = 0; j < ord_cols.length; j++) {
1315 row += obj.columns[ ord_cols[j][1] ].label + ': ' + treerow.childNodes[ ord_cols[j][1] ].getAttribute('label') + '\r\n';
1317 _dump += row + '\r\n';
1318 if (treeitem.childNodes.length > 1) {
1319 process_tree(treeitem.lastChild);
1324 process_tree(this.treechildren);
1329 'dump_csv_to_clipboard' : function(params) {
1331 if (typeof params == 'undefined') params = {};
1332 if (params.no_full_retrieve) {
1333 copy_to_clipboard( obj.dump_csv( params ) );
1335 obj.wrap_in_full_retrieve( function() { copy_to_clipboard( obj.dump_csv( params ) ); } );
1339 'dump_csv_to_printer' : function(params) {
1341 if (typeof params == 'undefined') params = {};
1342 JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context);
1343 if (params.no_full_retrieve) {
1344 print.simple( obj.dump_csv( params ), {'content_type':'text/plain'} );
1346 obj.wrap_in_full_retrieve(
1348 print.simple( obj.dump_csv( params ), {'content_type':'text/plain'} );
1354 'dump_extended_format_to_printer' : function(params) {
1356 if (typeof params == 'undefined') params = {};
1357 JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context);
1358 if (params.no_full_retrieve) {
1359 print.simple( obj.dump_extended_format( params ), {'content_type':'text/plain'} );
1361 obj.wrap_in_full_retrieve(
1363 print.simple( obj.dump_extended_format( params ), {'content_type':'text/plain'} );
1369 'dump_csv_to_file' : function(params) {
1371 JSAN.use('util.file'); var f = new util.file();
1372 if (typeof params == 'undefined') params = {};
1373 if (params.no_full_retrieve) {
1374 params.data = obj.dump_csv( params );
1375 params.not_json = true;
1376 if (!params.title) params.title = document.getElementById('offlineStrings').getString('list.save_csv_as');
1377 f.export_file( params );
1379 obj.wrap_in_full_retrieve(
1381 params.data = obj.dump_csv( params );
1382 params.not_json = true;
1383 if (!params.title) params.title = document.getElementById('offlineStrings').getString('list.save_csv_as');
1384 f.export_file( params );
1390 'print' : function(params) {
1391 if (!params) params = {};
1392 switch(this.node.nodeName) {
1393 case 'tree' : return this._print_tree(params); break;
1394 default: throw('NYI: Need ._print() for ' + this.node.nodeName); break;
1398 '_print_tree' : function(params) {
1401 var data = obj.data; data.stash_retrieve();
1402 if (!params.staff && data.list.au && data.list.au[0]) {
1403 params.staff = data.list.au[0];
1405 if (!params.lib && data.list.au && data.list.au[0] && data.list.au[0].ws_ou() && data.hash.aou && data.hash.aou[ data.list.au[0].ws_ou() ]) {
1406 params.lib = data.hash.aou[ data.list.au[0].ws_ou() ];
1407 params.lib.children(null);
1409 if (params.template && data.print_list_templates[ params.template ]) {
1410 var template = data.print_list_templates[ params.template ];
1411 if (template.inherit) {
1412 template = data.print_list_templates[ template.inherit ];
1413 // if someone wants to implement recursion later, feel free
1415 for (var i in template) params[i] = template[i];
1417 obj.wrap_in_full_retrieve(
1420 if (!params.list) params.list = obj.dump_with_keys();
1421 JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context);
1422 print.tree_list( params );
1423 if (typeof params.callback == 'function') params.callback();
1425 obj.error.standard_unexpected_error_alert('inner _print_tree',E);
1431 obj.error.standard_unexpected_error_alert('_print_tree',E);
1435 'dump_selected_with_keys' : function(params) {
1437 switch(this.node.nodeName) {
1438 case 'tree' : return this._dump_tree_selection_with_keys(params); break;
1439 default: throw('NYI: Need .dump_selection_with_keys() for ' + this.node.nodeName); break;
1444 '_dump_tree_selection_with_keys' : function(params) {
1447 var list = obj._retrieve_selection_from_tree();
1448 for (var i = 0; i < list.length; i++) {
1450 var treeitem = list[i];
1451 var treerow = treeitem.firstChild;
1452 for (var j = 0; j < treerow.childNodes.length; j++) {
1453 var value = treerow.childNodes[j].getAttribute('label');
1454 if (params.skip_hidden_columns) if (obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('hidden') == 'true') continue;
1455 if (typeof obj.columns[j] == 'undefined') {
1456 dump('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n');
1457 dump('_dump_tree_selection_with_keys @ ' + location.href + '\n');
1458 dump('\ttreerow.childNodes.length='+treerow.childNodes.length+' j='+j+' obj.columns.length='+obj.columns.length+'\n');
1461 var id = obj.columns[j].id; if (params.labels_instead_of_ids) id = obj.columns[j].label;
1470 'clipboard' : function(params) {
1473 var dump = obj.dump_selected_with_keys({'skip_hidden_columns':true,'labels_instead_of_ids':true});
1474 obj.data.stash_retrieve();
1475 obj.data.list_clipboard = dump; obj.data.stash('list_clipboard');
1476 JSAN.use('util.window'); var win = new util.window();
1477 win.open(urls.XUL_LIST_CLIPBOARD,'list_clipboard','chrome,resizable,modal');
1478 window.focus(); // sometimes the main window will lower after a clipboard action
1480 this.error.standard_unexpected_error_alert('clipboard',E);
1484 'dump_retrieve_ids' : function(params) {
1486 switch(this.node.nodeName) {
1487 case 'tree' : return this._dump_retrieve_ids_tree(params); break;
1488 default: throw('NYI: Need .dump_retrieve_ids() for ' + this.node.nodeName); break;
1492 '_dump_retrieve_ids_tree' : function(params) {
1495 for (var i = 0; i < this.treechildren.childNodes.length; i++) {
1496 var treeitem = this.treechildren.childNodes[i];
1497 dump.push( treeitem.getAttribute('retrieve_id') );
1502 'wrap_in_full_retrieve' : function(f) {
1504 if (typeof obj.on_all_fleshed == 'function') { // legacy
1505 obj.on_all_fleshed = [ obj.on_all_fleshed ];
1507 if (! obj.on_all_fleshed) obj.on_all_fleshed = [];
1508 obj.on_all_fleshed.push(f);
1509 obj.full_retrieve();
1512 '_sort_tree' : function(col,sortDir) {
1515 if (obj.node.getAttribute('no_sort')) {
1519 for (var i = 0; i < obj.columns.length; i++) {
1520 if (obj.columns[i].id == col.id) col_pos = function(a){return a;}(i);
1522 obj.wrap_in_full_retrieve(
1525 JSAN.use('util.money');
1527 var treeitems = obj.treechildren.childNodes;
1528 for (var i = 0; i < treeitems.length; i++) {
1529 var treeitem = treeitems[i];
1530 var treerow = treeitem.firstChild;
1531 var treecell = treerow.childNodes[ col_pos ];
1534 ? treecell.getAttribute('label')
1536 'sort_value' : treecell ? treecell.hasAttribute('sort_value')
1538 treecell.getAttribute('sort_value'))
1544 rows = rows.sort( function(a,b) {
1551 if (col.getAttribute('sort_type')) {
1552 switch(col.getAttribute('sort_type')) {
1554 JSAN.use('util.date'); // to pull in dojo.date.locale
1555 a = dojo.date.locale.parse(a,{});
1556 b = dojo.date.locale.parse(b,{});
1559 a = Number(a); b = Number(b);
1562 a = util.money.dollars_float_to_cents_integer(a);
1563 b = util.money.dollars_float_to_cents_integer(b);
1565 case 'title' : /* special case for "a" and "the". doesn't use marc 245 indicator */
1566 a = String( a ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
1567 b = String( b ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
1570 a = String( a ).toUpperCase();
1571 b = String( b ).toUpperCase();
1575 if (typeof a == 'string' || typeof b == 'string') {
1576 a = String( a ).toUpperCase();
1577 b = String( b ).toUpperCase();
1581 //dump('sorting: type = ' + col.getAttribute('sort_type') + ' a = ' + a + ' b = ' + b + ' a<b= ' + (a<b) + ' a>b= ' + (a>b) + '\n');
1582 if (a < b) return -1;
1583 if (a > b) return 1;
1586 if (sortDir == 'asc') rows = rows.reverse();
1587 while(obj.treechildren.lastChild) obj.treechildren.removeChild( obj.treechildren.lastChild );
1588 for (var i = 0; i < rows.length; i++) {
1589 obj.treechildren.appendChild( rows[i].node );
1591 if (typeof obj.on_sort == 'function') obj.on_sort();
1593 obj.error.standard_unexpected_error_alert('sorting',E);
1598 obj.error.standard_unexpected_error_alert('pre sorting', E);
1602 '_toggle_checkbox_column' : function(col,toggle) {
1605 if (obj.node.getAttribute('no_toggle')) {
1609 for (var i = 0; i < obj.columns.length; i++) {
1610 if (obj.columns[i].id == col.id) col_pos = function(a){return a;}(i);
1612 var treeitems = obj.treechildren.childNodes;
1613 for (var i = 0; i < treeitems.length; i++) {
1614 var treeitem = treeitems[i];
1615 var treerow = treeitem.firstChild;
1616 var treecell = treerow.childNodes[ col_pos ];
1617 treecell.setAttribute('value',(toggle == 'on'));
1619 if (typeof obj.on_checkbox_toggle == 'function') obj.on_checkbox_toggle(toggle);
1621 obj.error.standard_unexpected_error_alert('pre toggle', E);
1625 'render_list_actions' : function(params) {
1627 switch(this.node.nodeName) {
1628 case 'tree' : return this._render_list_actions_for_tree(params); break;
1629 default: throw('NYI: Need ._render_list_actions() for ' + this.node.nodeName); break;
1633 '_render_list_actions_for_tree' : function(params) {
1636 var btn = document.createElement('button');
1637 btn.setAttribute('id',obj.node.id + '_list_actions');
1638 btn.setAttribute('type','menu');
1639 btn.setAttribute('allowevents','true');
1640 //btn.setAttribute('oncommand','this.firstChild.showPopup();');
1641 btn.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.menu.label'));
1642 btn.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.menu.accesskey'));
1643 var mp = document.createElement('menupopup');
1644 btn.appendChild(mp);
1645 var mi = document.createElement('menuitem');
1646 mi.setAttribute('id',obj.node.id + '_clipfield');
1647 mi.setAttribute('disabled','true');
1648 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.field_to_clipboard.label'));
1649 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.field_to_clipboard.accesskey'));
1651 mi = document.createElement('menuitem');
1652 mi.setAttribute('id',obj.node.id + '_csv_to_clipboard');
1653 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_clipboard.label'));
1654 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_clipboard.accesskey'));
1656 mi = document.createElement('menuitem');
1657 mi.setAttribute('id',obj.node.id + '_csv_to_printer');
1658 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_printer.label'));
1659 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_printer.accesskey'));
1661 mi = document.createElement('menuitem');
1662 mi.setAttribute('id',obj.node.id + '_extended_to_printer');
1663 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.extended_to_printer.label'));
1664 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.extended_to_printer.accesskey'));
1666 mi = document.createElement('menuitem');
1667 mi.setAttribute('id',obj.node.id + '_csv_to_file');
1668 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_file.label'));
1669 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_file.accesskey'));
1671 mi = document.createElement('menuitem');
1672 mi.setAttribute('id',obj.node.id + '_save_columns');
1673 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.save_column_configuration.label'));
1674 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.save_column_configuration.accesskey'));
1675 if (obj.data.hash.aous['gui.disable_local_save_columns']) {
1676 mi.setAttribute('disabled','true');
1681 obj.error.standard_unexpected_error_alert('rendering list actions',E);
1685 'set_list_actions' : function(params) {
1687 switch(this.node.nodeName) {
1688 case 'tree' : return this._set_list_actions_for_tree(params); break;
1689 default: throw('NYI: Need ._set_list_actions() for ' + this.node.nodeName); break;
1693 '_set_list_actions_for_tree' : function(params) {
1694 // This should be called after the button element from render_list_actions has been appended to the DOM
1697 var x = document.getElementById(obj.node.id + '_clipfield');
1702 obj.clipboard(params);
1703 if (params && typeof params.on_complete == 'function') {
1704 params.on_complete(params);
1710 x = document.getElementById(obj.node.id + '_csv_to_clipboard');
1715 obj.dump_csv_to_clipboard(params);
1716 if (params && typeof params.on_complete == 'function') {
1717 params.on_complete(params);
1723 x = document.getElementById(obj.node.id + '_csv_to_printer');
1728 obj.dump_csv_to_printer(params);
1729 if (params && typeof params.on_complete == 'function') {
1730 params.on_complete(params);
1736 x = document.getElementById(obj.node.id + '_extended_to_printer');
1741 obj.dump_extended_format_to_printer(params);
1742 if (params && typeof params.on_complete == 'function') {
1743 params.on_complete(params);
1750 x = document.getElementById(obj.node.id + '_csv_to_file');
1755 obj.dump_csv_to_file(params);
1756 if (params && typeof params.on_complete == 'function') {
1757 params.on_complete(params);
1763 x = document.getElementById(obj.node.id + '_save_columns');
1768 obj.save_columns(params);
1769 if (params && typeof params.on_complete == 'function') {
1770 params.on_complete(params);
1778 obj.error.standard_unexpected_error_alert('setting list actions',E);
1782 // Takes fieldmapper class name and attempts to spit out column definitions suitable for .init
1783 'fm_columns' : function(hint,column_extras,prefix) {
1786 if (!prefix) { prefix = ''; }
1788 // requires the dojo library fieldmapper.autoIDL
1789 if (typeof fieldmapper == 'undefined') { throw 'fieldmapper undefined'; }
1790 if (typeof fieldmapper.IDL == 'undefined') { throw 'fieldmapper.IDL undefined'; }
1791 if (typeof fieldmapper.IDL.fmclasses == 'undefined') { throw 'fieldmapper.IDL.fmclasses undefined'; }
1792 if (typeof fieldmapper.IDL.fmclasses[hint] == 'undefined') { throw 'fieldmapper.IDL.fmclasses.' + hint + ' undefined'; }
1793 var my_class = fieldmapper.IDL.fmclasses[hint];
1794 var data = obj.data; data.stash_retrieve();
1796 function col_def(my_field) {
1797 var col_id = prefix + hint + '_' + my_field.name;
1799 var datafield = my_field.name;
1800 var fleshed_display_field;
1801 if (column_extras) {
1802 if (column_extras['*']) {
1803 if (column_extras['*']['dataobj']) {
1804 dataobj = column_extras['*']['dataobj'];
1807 if (column_extras[col_id]) {
1808 if (column_extras[col_id]['dataobj']) {
1809 dataobj = column_extras[col_id]['dataobj'];
1811 if (column_extras[col_id]['datafield']) {
1812 datafield = column_extras[col_id]['datafield'];
1814 if (column_extras[col_id]['fleshed_display_field']) {
1815 fleshed_display_field = column_extras[col_id]['fleshed_display_field'];
1821 'label' : my_field.label || my_field.name,
1822 'sort_type' : [ 'int', 'float', 'id', 'number' ].indexOf(my_field.datatype) > -1 ? 'number' :
1823 ( my_field.datatype == 'money' ? 'money' :
1824 ( my_field.datatype == 'timestamp' ? 'date' : 'default')),
1825 'hidden' : my_field.virtual || my_field.datatype == 'link',
1828 // my_field.datatype => bool float id int interval link money number org_unit text timestamp
1829 if (my_field.datatype == 'link') {
1830 def.render = function(my) {
1831 // is the object fleshed?
1832 return my[dataobj][datafield]() && typeof my[dataobj][datafield]() == 'object'
1833 // yes, show the display field
1834 ? my[dataobj][datafield]()[fleshed_display_field||my_field.key]()
1835 // no, do we have its class in data.hash?
1836 : ( typeof data.hash[ my[dataobj].Structure.field_map[datafield].class ] != 'undefined'
1837 // yes, do we have this particular object cached?
1838 ? ( data.hash[ my[dataobj].Structure.field_map[datafield].class ][ my[dataobj][datafield]() ]
1839 // yes, show the display field
1840 ? data.hash[ my[dataobj].Structure.field_map[datafield].class ][ my[dataobj][datafield]() ][
1841 fleshed_display_field||my_field.key
1843 // no, just show the raw value
1844 : my[dataobj][datafield]()
1846 // no, just show the raw value
1847 : my[dataobj][datafield]()
1851 def.render = function(my) { return my[dataobj][datafield](); }
1853 if (my_field.datatype == 'timestamp') {
1854 JSAN.use('util.date');
1855 def.render = function(my) {
1856 return util.date.formatted_date( my[dataobj][datafield](), '%{localized}' );
1858 def.sort_value = function(my) {
1859 return util.date.db_date2Date( my[dataobj][datafield]() ).getTime();
1862 if (my_field.datatype == 'org_unit') {
1863 def.render = function(my) {
1864 return typeof my[dataobj][datafield]() == 'object' ? my[dataobj][datafield]().shortname() : data.hash.aou[ my[dataobj][datafield]() ].shortname();
1867 if (my_field.datatype == 'money') {
1868 JSAN.use('util.money');
1869 def.render = function(my) {
1870 return util.money.sanitize( my[dataobj][datafield]() );
1872 def.sort_value = function(my) {
1873 return util.money.dollars_float_to_cents_integer( my[dataobj][datafield]() );
1876 if (column_extras) {
1877 if (column_extras['*']) {
1878 for (var attr in column_extras['*']) {
1879 def[attr] = column_extras['*'][attr];
1881 if (column_extras['*']['expanded_label']) {
1882 def.label = my_class.label + ': ' + def.label;
1884 if (column_extras['*']['label_prefix']) {
1885 def.label = column_extras['*']['label_prefix'] + def.label;
1887 if (column_extras['*']['remove_virtual']) {
1888 if (my_field.virtual) {
1889 def.remove_me = true;
1893 if (column_extras[col_id]) {
1894 for (var attr in column_extras[col_id]) {
1895 def[attr] = column_extras[col_id][attr];
1897 if (column_extras[col_id]['keep_me']) {
1898 def.remove_me = false;
1900 if (column_extras[col_id]['label_prefix']) {
1901 def.label = column_extras[col_id]['label_prefix'] + def.label;
1905 if (def.remove_me) {
1906 dump('Skipping ' + def.label + '\n');
1909 dump('Defining ' + def.label + '\n');
1914 for (var i = 0; i < my_class.fields.length; i++) {
1915 var my_field = my_class.fields[i];
1916 var def = col_def(my_field);
1918 columns.push( def );
1923 obj.error.standard_unexpected_error_alert('fm_columns()',E);
1927 // Default for the map_row_to_columns function for .init
1928 'std_map_row_to_columns' : function(error_value) {
1929 return function(row,cols,scratch) {
1930 // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
1931 // cols contains all of the objects listed above in columns
1932 // scratch is a temporary space shared by all cells/rows (or just per row if not explicitly passed in)
1933 if (!scratch) { scratch = {}; }
1936 JSAN.use('util.error'); obj.error = new util.error();
1937 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1938 JSAN.use('util.network'); obj.network = new util.network();
1939 JSAN.use('util.money');
1943 var sort_values = [];
1946 for (var i = 0; i < cols.length; i++) {
1947 switch (typeof cols[i].render) {
1948 case 'function': try { values[i] = cols[i].render(my,scratch); } catch(E) { values[i] = error_value; obj.error.sdump('D_COLUMN_RENDER_ERROR',E); } break;
1949 case 'string' : cmd += 'try { ' + cols[i].render + '; values['+i+'] = v; } catch(E) { values['+i+'] = error_value; }'; break;
1950 default: cmd += 'values['+i+'] = "??? '+(typeof cols[i].render)+'"; ';
1952 switch (typeof cols[i].sort_value) {
1955 sort_values[i] = cols[i].sort_value(my,scratch);
1957 sort_values[i] = error_value;
1958 obj.error.sdump('D_COLUMN_RENDER_ERROR',E);
1963 + cols[i].sort_value
1966 +'] = v; } catch(E) { sort_values['
1968 + '] = error_value; }';
1971 cmd += 'sort_values['+i+'] = values[' + i + '];';
1974 if (cmd) eval( cmd );
1976 obj.error.sdump('D_WARN','map_row_to_column: ' + E);
1977 if (error_value) { value = error_value; } else { value = ' ' };
1979 return { 'values' : values, 'sort_values' : sort_values };
1983 dump('exiting util.list.js\n');