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;
14 if (!this.node) throw('Could not find element ' + id);
15 switch(this.node.nodeName) {
19 throw(this.node.nodeName + ' not yet supported'); break;
20 default: throw(this.node.nodeName + ' not supported'); break;
23 JSAN.use('util.error'); this.error = new util.error();
25 JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.stash_retrieve();
27 JSAN.use('util.functional');
28 JSAN.use('util.widgets');
33 util.list.prototype = {
35 'init' : function (params) {
38 obj.scratch_data = {};
40 // If set, save and restore columns as if the tree/list id was the value of columns_saved_under
41 obj.columns_saved_under = params.columns_saved_under;
43 JSAN.use('util.widgets');
45 obj.printer_context = params.printer_context;
47 if (typeof params.map_row_to_column == 'function') obj.map_row_to_column = params.map_row_to_column;
48 if (typeof params.map_row_to_columns == 'function') {
49 obj.map_row_to_columns = params.map_row_to_columns;
51 obj.map_row_to_columns = obj.std_map_row_to_columns();
53 if (typeof params.retrieve_row == 'function') obj.retrieve_row = params.retrieve_row;
56 if (typeof params.prebuilt != 'undefined') obj.prebuilt = params.prebuilt;
58 if (typeof params.columns == 'undefined') throw('util.list.init: No columns');
62 'label' : document.getElementById('offlineStrings').getString('list.line_number'),
65 'properties' : 'ordinal', // column properties for css styling
68 'render' : function(my,scratch) {
69 // special code will handle this based on the attribute we set
70 // here. All cells for this column need to be updated whenever
71 // a list adds, removes, or sorts rows
76 for (var i = 0; i < params.columns.length; i++) {
77 if (typeof params.columns[i] == 'object') {
78 obj.columns.push( params.columns[i] );
80 var cols = obj.fm_columns( params.columns[i] );
81 for (var j = 0; j < cols.length; j++) {
82 obj.columns.push( cols[j] );
87 switch(obj.node.nodeName) {
88 case 'tree' : obj._init_tree(params); break;
89 case 'listbox' : obj._init_listbox(params); break;
90 default: throw('NYI: Need ._init() for ' + obj.node.nodeName); break;
94 '_init_tree' : function (params) {
98 this.treechildren = this.node.lastChild;
101 var treecols = document.createElement('treecols');
102 this.node.appendChild(treecols);
103 this.treecols = treecols;
104 if (document.getElementById('column_sort_menu')) {
105 treecols.setAttribute('context','column_sort_menu');
108 var check_for_id_collisions = {};
109 for (var i = 0; i < this.columns.length; i++) {
110 var treecol = document.createElement('treecol');
111 for (var j in this.columns[i]) {
112 var value = this.columns[i][j];
114 if (typeof check_for_id_collisions[value] == 'undefined') {
115 check_for_id_collisions[value] = true;
117 // Column id's are important for sorting and saving list configuration. Collisions started happening because
118 // we were using field names as id's, and then later combining column definitions for multiple objects that
119 // shared field names. The downside to this sort of automatic collision prevention is that these generated
120 // id's can change as we add and remove columns, possibly breaking saved list configurations.
121 dump('Column collision with id = ' + value + ', renaming to ');
122 value = value + '_collision_' + i;
126 treecol.setAttribute(j,value);
128 treecols.appendChild(treecol);
130 if (this.columns[i].type == 'checkbox') {
131 treecol.addEventListener(
136 var toggle = ev.target.getAttribute('toggleAll') || 'on';
137 if (toggle == 'off') toggle = 'on'; else toggle = 'off';
138 ev.target.setAttribute('toggleAll',toggle);
139 obj._toggle_checkbox_column(ev.target,toggle);
146 treecol.addEventListener(
149 dump('sort_first_asc\n');
150 ev.target.setAttribute('sortDir','asc');
152 'target' : ev.target,
156 util.widgets.dispatch('sort',ev.target);
160 treecol.addEventListener(
163 dump('sort_first_desc\n');
164 ev.target.setAttribute('sortDir','desc');
166 'target' : ev.target,
170 util.widgets.dispatch('sort',ev.target);
174 treecol.addEventListener(
177 dump('sort_next_asc\n');
178 ev.target.setAttribute('sortDir','asc');
180 'target' : ev.target,
183 util.widgets.dispatch('sort',ev.target);
187 treecol.addEventListener(
190 dump('sort_next_desc\n');
191 ev.target.setAttribute('sortDir','desc');
193 'target' : ev.target,
196 util.widgets.dispatch('sort',ev.target);
201 treecol.addEventListener(
204 if (ev.button == 2 /* context menu click */ || ev.target.getAttribute('no_sort')) {
208 if (ev.ctrlKey) { // sub sort
213 ev.target.setAttribute('sortDir',sortDir);
215 'target' : ev.target,
218 } else { // first sort
219 var sortDir = ev.target.getAttribute('sortDir') || 'desc';
220 if (sortDir == 'desc') sortDir = 'asc'; else sortDir = 'desc';
224 ev.target.setAttribute('sortDir',sortDir);
226 'target' : ev.target,
231 util.widgets.dispatch('sort',ev.target);
236 treecol.addEventListener(
239 if (!obj.first_sort) {
247 if (obj.row_count.total != obj.row_count.fleshed
248 && (obj.row_count.total - obj.row_count.fleshed) > 50
250 var r = window.confirm(
251 document.getElementById('offlineStrings').getFormattedString(
252 'list.row_fetch_warning',
253 [obj.row_count.fleshed,obj.row_count.total]
258 setTimeout( do_it, 0 );
262 setTimeout( do_it, 0 );
269 var splitter = document.createElement('splitter');
270 splitter.setAttribute('class','tree-splitter');
271 treecols.appendChild(splitter);
274 var treechildren = document.createElement('treechildren');
275 this.node.appendChild(treechildren);
276 this.treechildren = treechildren;
278 if (typeof params.on_sort == 'function') {
279 this.on_sort = params.on_sort;
281 if (typeof params.on_checkbox_toggle == 'function') {
282 this.on_checkbox_toggle = params.on_checkbox_toggle;
284 this.node.addEventListener(
287 if (typeof params.on_select == 'function') {
288 params.on_select(ev);
290 var x = document.getElementById(obj.node.id + '_clipfield');
292 var sel = obj.retrieve_selection();
293 x.setAttribute('disabled', sel.length == 0);
298 if (typeof params.on_click == 'function') {
299 this.node.addEventListener(
305 if (typeof params.on_dblclick == 'function') {
306 this.node.addEventListener(
314 this.node.addEventListener(
316 function(ev) { obj.detect_visible(); },
320 this.node.addEventListener(
322 function(ev) { obj.auto_retrieve(); },
325 this.node.addEventListener(
327 function(ev) { obj.auto_retrieve(); },
330 window.addEventListener(
332 function(ev) { obj.auto_retrieve(); },
335 /* FIXME -- find events on scrollbar to trigger this */
336 obj.detect_visible_polling();
338 var scrollbar = document.getAnonymousNodes( document.getAnonymousNodes(this.node)[1] )[1];
339 var slider = document.getAnonymousNodes( scrollbar )[2];
340 alert('scrollbar = ' + scrollbar.nodeName + ' grippy = ' + slider.nodeName);
341 scrollbar.addEventListener('click',function(){alert('sb click');},false);
342 scrollbar.addEventListener('command',function(){alert('sb command');},false);
343 scrollbar.addEventListener('scroll',function(){alert('sb scroll');},false);
344 slider.addEventListener('click',function(){alert('slider click');},false);
345 slider.addEventListener('command',function(){alert('slider command');},false);
346 slider.addEventListener('scroll',function(){alert('slider scroll');},false);
348 this.node.addEventListener('scroll',function(){ obj.auto_retrieve(); },false);
350 this.restores_columns(params);
353 '_init_listbox' : function (params) {
356 var listhead = document.createElement('listhead');
357 this.node.appendChild(listhead);
359 var listcols = document.createElement('listcols');
360 this.node.appendChild(listcols);
362 for (var i = 0; i < this.columns.length; i++) {
363 var listheader = document.createElement('listheader');
364 listhead.appendChild(listheader);
365 var listcol = document.createElement('listcol');
366 listcols.appendChild(listcol);
367 for (var j in this.columns[i]) {
368 listheader.setAttribute(j,this.columns[i][j]);
369 listcol.setAttribute(j,this.columns[i][j]);
375 'save_columns' : function (params) {
377 if (obj.data.hash.aous['gui.disable_local_save_columns']) {
378 alert(document.getElementById('offlineStrings').getString('list.column_save_disabled'));
380 switch (this.node.nodeName) {
381 case 'tree' : this._save_columns_tree(params); break;
382 default: throw('NYI: Need .save_columns() for ' + this.node.nodeName); break;
387 '_save_columns_tree' : function (params) {
390 var id = obj.node.getAttribute('id');
391 if (obj.columns_saved_under) { id = obj.columns_saved_under; }
393 alert("FIXME: The columns for this list cannot be saved because the list has no id.");
397 var nl = obj.node.getElementsByTagName('treecol');
398 for (var i = 0; i < nl.length; i++) {
400 var col_id = col.getAttribute('id');
402 alert('FIXME: A column in this list does not have an id and cannot be saved');
405 var col_hidden = col.getAttribute('hidden');
406 var col_width = col.getAttribute('width');
407 var col_ordinal = col.getAttribute('ordinal');
408 my_cols[ col_id ] = { 'hidden' : col_hidden, 'width' : col_width, 'ordinal' : col_ordinal };
410 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
411 JSAN.use('util.file'); var file = new util.file('tree_columns_for_'+window.escape(id));
412 file.set_object(my_cols);
414 alert(document.getElementById('offlineStrings').getString('list.columns_saved'));
416 obj.error.standard_unexpected_error_alert('_save_columns_tree',E);
420 'restores_columns' : function (params) {
422 switch (this.node.nodeName) {
423 case 'tree' : this._restores_columns_tree(params); break;
424 default: throw('NYI: Need .restores_columns() for ' + this.node.nodeName); break;
428 '_restores_columns_tree' : function (params) {
431 var id = obj.node.getAttribute('id');
432 if (obj.columns_saved_under) { id = obj.columns_saved_under; }
434 alert("FIXME: The columns for this list cannot be restored because the list has no id.");
439 if (! obj.data.hash.aous) { obj.data.hash.aous = {}; }
440 if (! obj.data.hash.aous['gui.disable_local_save_columns']) {
441 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
442 JSAN.use('util.file'); var file = new util.file('tree_columns_for_'+window.escape(id));
443 if (file._file.exists()) {
444 my_cols = file.get_object(); file.close();
447 /* local file will trump remote file if allowed, so save ourselves an http request if this is the case */
448 if (obj.data.hash.aous['url.remote_column_settings'] && ! my_cols ) {
450 var x = new XMLHttpRequest();
451 var url = obj.data.hash.aous['url.remote_column_settings'] + '/tree_columns_for_' + window.escape(id);
452 x.open("GET", url, false);
454 if (x.status == 200) {
455 my_cols = JSON2js( x.responseText );
458 // This can happen in the offline interface if you logged in previously and url.remote_column_settings is set.
459 // 1) You may be really "offline" now
460 // 2) the URL may just be a path component without a hostname (ie "/xul/column_settings/"), which won't work
461 // when appended to chrome://open_ils_staff_client/
462 dump('Error retrieving column settings from ' + url + ': ' + E + '\n');
467 var nl = obj.node.getElementsByTagName('treecol');
468 for (var i = 0; i < nl.length; i++) {
470 var col_id = col.getAttribute('id');
472 alert('FIXME: A column in this list does not have an id and cannot be saved');
475 if (typeof my_cols[col_id] != 'undefined') {
476 col.setAttribute('hidden',my_cols[col_id].hidden);
477 col.setAttribute('width',my_cols[col_id].width);
478 col.setAttribute('ordinal',my_cols[col_id].ordinal);
480 obj.error.sdump('D_ERROR','WARNING: Column ' + col_id + ' did not have a saved state.');
485 obj.error.standard_unexpected_error_alert('_restore_columns_tree',E);
489 'clear' : function (params) {
491 switch (this.node.nodeName) {
492 case 'tree' : this._clear_tree(params); break;
493 case 'listbox' : this._clear_listbox(params); break;
494 default: throw('NYI: Need .clear() for ' + this.node.nodeName); break;
496 this.error.sdump('D_LIST','Clearing list ' + this.node.getAttribute('id') + '\n');
497 this.row_count.total = 0;
498 this.row_count.fleshed = 0;
499 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
502 '_clear_tree' : function(params) {
504 if (obj.error.sdump_levels.D_LIST_DUMP_ON_CLEAR) {
505 obj.error.sdump('D_LIST_DUMP_ON_CLEAR',obj.dump());
507 if (obj.error.sdump_levels.D_LIST_DUMP_WITH_KEYS_ON_CLEAR) {
508 obj.error.sdump('D_LIST_DUMP_WITH_KEYS_ON_CLEAR',obj.dump_with_keys());
510 while (obj.treechildren.lastChild) obj.treechildren.removeChild( obj.treechildren.lastChild );
513 '_clear_listbox' : function(params) {
516 var nl = this.node.getElementsByTagName('listitem');
517 for (var i = 0; i < nl.length; i++) {
520 for (var i = 0; i < items.length; i++) {
521 this.node.removeChild(items[i]);
525 'append' : function (params) {
528 switch (this.node.nodeName) {
529 case 'tree' : rparams = this._append_to_tree(params); break;
530 case 'listbox' : rparams = this._append_to_listbox(params); break;
531 default: throw('NYI: Need .append() for ' + this.node.nodeName); break;
533 if (rparams && params.attributes) {
534 for (var i in params.attributes) {
535 rparams.treeitem_node.setAttribute(i,params.attributes[i]);
538 this.row_count.total++;
539 if (this.row_count.fleshed == this.row_count.total) {
540 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
542 rparams.treeitem_node.setAttribute('unique_row_counter',obj.unique_row_counter);
543 rparams.unique_row_counter = obj.unique_row_counter++;
544 if (typeof params.on_append == 'function') {
545 params.on_append(rparams);
550 'refresh_row' : function (params) {
553 switch (this.node.nodeName) {
554 case 'tree' : rparams = this._refresh_row_in_tree(params); break;
555 default: throw('NYI: Need .refresh_row() for ' + this.node.nodeName); break;
557 if (rparams && params.attributes) {
558 for (var i in params.attributes) {
559 rparams.treeitem_node.setAttribute(i,params.attributes[i]);
562 this.row_count.fleshed--;
567 '_append_to_tree' : function (params) {
571 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
573 var s = ('util.list.append: params = ' + (params) + '\n');
575 var treechildren_node = this.treechildren;
577 if (params.node && params.node.nodeName == 'treeitem') {
578 params.node.setAttribute('container','true'); /* params.node.setAttribute('open','true'); */
579 if (params.node.lastChild.nodeName == 'treechildren') {
580 treechildren_node = params.node.lastChild;
582 treechildren_node = document.createElement('treechildren');
583 params.node.appendChild(treechildren_node);
587 var treeitem = document.createElement('treeitem');
588 treeitem.setAttribute('retrieve_id',params.retrieve_id);
589 if (typeof params.to_bottom != 'undefined') {
590 treechildren_node.appendChild( treeitem );
591 if (typeof params.no_auto_select == 'undefined') {
592 if (!obj.auto_select_pending) {
593 obj.auto_select_pending = true;
594 setTimeout(function() {
595 dump('auto-selecting\n');
596 var idx = Number(obj.node.view.rowCount)-1;
597 try { obj.node.view.selection.select(idx); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); }
598 try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); }
599 obj.auto_select_pending = false;
600 try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(idx).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); }
605 if (treechildren_node.firstChild) {
606 treechildren_node.insertBefore( treeitem, treechildren_node.firstChild );
608 treechildren_node.appendChild( treeitem );
610 if (typeof params.no_auto_select == 'undefined') {
611 if (!obj.auto_select_pending) {
612 obj.auto_select_pending = true;
613 setTimeout(function() {
614 try { obj.node.view.selection.select(0); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); }
615 try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); }
616 obj.auto_select_pending = false;
617 try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(0).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); }
622 var treerow = document.createElement('treerow');
623 treeitem.appendChild( treerow );
624 treerow.setAttribute('retrieve_id',params.retrieve_id);
625 if (params.row_properties) treerow.setAttribute('properties',params.row_properties);
627 s += ('tree = ' + this.node + ' treechildren = ' + treechildren_node + '\n');
628 s += ('treeitem = ' + treeitem + ' treerow = ' + treerow + '\n');
630 obj.put_retrieving_label(treerow);
632 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
633 treerow.addEventListener(
637 if (treerow.getAttribute('retrieved') == 'true') return; /* already running */
639 treerow.setAttribute('retrieved','true');
641 //dump('fleshing = ' + params.retrieve_id + '\n');
643 function inc_fleshed() {
644 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
645 treerow.setAttribute('fleshed','true');
646 obj.row_count.fleshed++;
647 if (obj.row_count.fleshed >= obj.row_count.total) {
648 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
652 params.treeitem_node = treeitem;
653 params.on_retrieve = function(p) {
656 obj._map_row_to_treecell(p,treerow);
658 var idx = obj.node.contentView.getIndexOfItem( params.treeitem_node );
659 dump('idx = ' + idx + '\n');
660 // if current row is selected, send another select event to re-sync data that the client code fetches on selects
661 if ( obj.node.view.selection.isSelected( idx ) ) {
662 dump('dispatching select event for on_retrieve for idx = ' + idx + '\n');
663 util.widgets.dispatch('select',obj.node);
666 // Let's not alert on this for now. Getting contentView has no properties in record buckets under certain conditions
667 dump('fixme2: ' + E + '\n');
671 if (typeof params.retrieve_row == 'function') {
673 params.retrieve_row( params );
675 } else if (typeof obj.retrieve_row == 'function') {
677 obj.retrieve_row( params );
683 obj.refresh_ordinals();
687 if (typeof params.flesh_immediately != 'undefined') {
688 if (params.flesh_immediately) {
691 util.widgets.dispatch('flesh',treerow);
697 treerow.addEventListener(
700 //dump('fleshing anon\n');
701 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
702 obj._map_row_to_treecell(params,treerow);
703 treerow.setAttribute('retrieved','true');
704 treerow.setAttribute('fleshed','true');
705 obj.row_count.fleshed++;
706 if (obj.row_count.fleshed >= obj.row_count.total) {
707 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
709 obj.refresh_ordinals();
713 if (typeof params.flesh_immediately != 'undefined') {
714 if (params.flesh_immediately) {
717 util.widgets.dispatch('flesh',treerow);
723 this.error.sdump('D_LIST',s);
727 if (obj.trim_list && obj.row_count.total >= obj.trim_list) {
729 //if (typeof params.to_bottom != 'undefined')
730 if (typeof params.to_top == 'undefined') {
731 if (typeof params.on_delete == 'function') { params.on_delete( treechildren_node.firstChild.getAttribute('unique_row_counter') ); }
732 treechildren_node.removeChild( treechildren_node.firstChild );
734 if (typeof params.on_delete == 'function') { params.on_delete( treechildren_node.lastChild.getAttribute('unique_row_counter') ); }
735 treechildren_node.removeChild( treechildren_node.lastChild );
741 setTimeout( function() { obj.auto_retrieve(); obj.refresh_ordinals(); }, 0 );
743 params.treeitem_node = treeitem;
747 '_refresh_row_in_tree' : function (params) {
751 if (typeof params.row == 'undefined') throw('util.list.refresh_row: Object must contain a row');
752 if (typeof params.treeitem_node == 'undefined') throw('util.list.refresh_row: Object must contain a treeitem_node');
753 if (params.treeitem_node.nodeName != 'treeitem') throw('util.list.refresh_rwo: treeitem_node must be a treeitem');
755 var s = ('util.list.refresh_row: params = ' + (params) + '\n');
757 var treeitem = params.treeitem_node;
758 treeitem.setAttribute('retrieve_id',params.retrieve_id);
759 if (typeof params.to_bottom != 'undefined') {
760 if (typeof params.no_auto_select == 'undefined') {
761 if (!obj.auto_select_pending) {
762 obj.auto_select_pending = true;
763 setTimeout(function() {
764 dump('auto-selecting\n');
765 var idx = Number(obj.node.view.rowCount)-1;
766 try { obj.node.view.selection.select(idx); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); }
767 try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); }
768 obj.auto_select_pending = false;
769 try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(idx).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); }
774 //var delete_me = [];
775 //for (var i in treeitem.childNodes) if (treeitem.childNodes[i].nodeName == 'treerow') delete_me.push(treeitem.childNodes[i]);
776 //for (var i = 0; i < delete_me.length; i++) treeitem.removeChild(delete_me[i]);
777 var prev_treerow = treeitem.firstChild; /* FIXME: worry about hierarchal lists like copy_browser? */
778 var treerow = document.createElement('treerow');
779 while (prev_treerow.firstChild) {
780 treerow.appendChild( prev_treerow.removeChild( prev_treerow.firstChild ) );
782 treeitem.replaceChild( treerow, prev_treerow );
783 treerow.setAttribute('retrieve_id',params.retrieve_id);
784 if (params.row_properties) treerow.setAttribute('properties',params.row_properties);
786 s += ('tree = ' + this.node.nodeName + '\n');
787 s += ('treeitem = ' + treeitem.nodeName + ' treerow = ' + treerow.nodeName + '\n');
789 obj.put_retrieving_label(treerow);
791 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
793 s += 'found a retrieve_row function\n';
795 treerow.addEventListener(
799 if (treerow.getAttribute('retrieved') == 'true') return; /* already running */
801 treerow.setAttribute('retrieved','true');
803 //dump('fleshing = ' + params.retrieve_id + '\n');
805 function inc_fleshed() {
806 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
807 treerow.setAttribute('fleshed','true');
808 obj.row_count.fleshed++;
809 if (obj.row_count.fleshed >= obj.row_count.total) {
810 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
814 params.treeitem_node = treeitem;
815 params.on_retrieve = function(p) {
818 obj._map_row_to_treecell(p,treerow);
820 var idx = obj.node.contentView.getIndexOfItem( params.treeitem_node );
821 dump('idx = ' + idx + '\n');
822 // if current row is selected, send another select event to re-sync data that the client code fetches on selects
823 if ( obj.node.view.selection.isSelected( idx ) ) {
824 dump('dispatching select event for on_retrieve for idx = ' + idx + '\n');
825 util.widgets.dispatch('select',obj.node);
828 // Let's not alert on this for now. Getting contentView has no properties in record buckets under certain conditions
829 dump('fixme2: ' + E + '\n');
833 if (typeof params.retrieve_row == 'function') {
835 params.retrieve_row( params );
837 } else if (typeof obj.retrieve_row == 'function') {
839 obj.retrieve_row( params );
845 obj.refresh_ordinals();
849 if (typeof params.flesh_immediately != 'undefined') {
850 if (params.flesh_immediately) {
853 util.widgets.dispatch('flesh',treerow);
861 s += 'did not find a retrieve_row function\n';
863 treerow.addEventListener(
866 //dump('fleshing anon\n');
867 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
868 obj._map_row_to_treecell(params,treerow);
869 treerow.setAttribute('retrieved','true');
870 treerow.setAttribute('fleshed','true');
871 obj.row_count.fleshed++;
872 if (obj.row_count.fleshed >= obj.row_count.total) {
873 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
875 obj.refresh_ordinals();
879 if (typeof params.flesh_immediately != 'undefined') {
880 if (params.flesh_immediately) {
883 util.widgets.dispatch('flesh',treerow);
893 if (obj.trim_list && obj.row_count.total >= obj.trim_list) {
895 //if (typeof params.to_bottom != 'undefined')
896 if (typeof params.to_top == 'undefined') {
897 treechildren_node.removeChild( treechildren_node.firstChild );
899 treechildren_node.removeChild( treechildren_node.lastChild );
905 setTimeout( function() { obj.auto_retrieve(); obj.refresh_ordinals(); }, 0 );
907 JSAN.use('util.widgets'); util.widgets.dispatch('select',obj.node);
909 this.error.sdump('D_LIST',s);
914 'refresh_ordinals' : function() {
917 if (obj.refresh_ordinals_timeout_id) { return; }
919 function _refresh_ordinals(clear) {
920 var nl = obj.node.getElementsByAttribute('label','_');
921 for (var i = 0; i < nl.length; i++) {
926 nl[i].setAttribute( // treecell properties for css styling
931 nl = obj.node.getElementsByAttribute('ord_col','true');
932 for (var i = 0; i < nl.length; i++) {
935 // we could just use 'i' here if we trust the order of elements
936 1 + obj.node.contentView.getIndexOfItem(nl[i].parentNode.parentNode) // treeitem
939 if (clear) { obj.refresh_ordinals_timeout_id = null; }
942 // spamming this to cover race conditions
943 setTimeout(_refresh_ordinals, 500); // for speedy looking UI updates
944 setTimeout(_refresh_ordinals, 2000); // for most uses
945 obj.refresh_ordinals_timeout_id = setTimeout(
947 _refresh_ordinals(true);
949 4000 // just in case, say with a slow rendering list
953 alert('Error in list.js, refresh_ordinals(): ' + E);
957 'put_retrieving_label' : function(treerow) {
960 for (var i = 0; i < obj.columns.length; i++) {
962 if (typeof treerow.childNodes[i] == 'undefined') {
963 treecell = document.createElement('treecell');
964 treerow.appendChild(treecell);
966 treecell = treerow.childNodes[i];
968 treecell.setAttribute('label',document.getElementById('offlineStrings').getString('list.row_retrieving'));
971 alert('Error in list.js, put_retrieving_label(): ' + E);
975 'detect_visible' : function() {
978 //dump('detect_visible obj.node = ' + obj.node + '\n');
979 /* FIXME - this is a hack.. if the implementation of tree changes, this could break */
981 /*var s = ''; var A = document.getAnonymousNodes(obj.node);
984 s += '\t' + (typeof B.nodeName != 'undefined' ? B.nodeName : B ) + '\n';
985 if (typeof B.childNodes != 'undefined') for (var j = 0; j < B.childNodes.length; j++) {
986 var C = B.childNodes[j];
987 s += '\t\t' + C.nodeName + '\n';
990 obj.error.sdump('D_XULRUNNER','document.getAnonymousNodes(' + obj.node.nodeName + ') = \n' + s + '\n');*/
991 var scrollbar = document.getAnonymousNodes(obj.node)[2].firstChild;
992 var curpos = scrollbar.getAttribute('curpos');
993 var maxpos = scrollbar.getAttribute('maxpos');
994 //alert('curpos = ' + curpos + ' maxpos = ' + maxpos + ' obj.curpos = ' + obj.curpos + ' obj.maxpos = ' + obj.maxpos + '\n');
995 if ((curpos != obj.curpos) || (maxpos != obj.maxpos)) {
996 if ( obj.auto_retrieve() > 0 ) {
997 obj.curpos = curpos; obj.maxpos = maxpos;
1001 obj.error.sdump('D_XULRUNNER', 'List implementation changed? ' + E);
1003 } catch(E) { obj.error.sdump('D_ERROR',E); }
1006 'detect_visible_polling' : function() {
1008 //alert('detect_visible_polling');
1010 obj.detect_visible();
1011 setTimeout(function() { try { obj.detect_visible_polling(); } catch(E) { alert(E); } },2000);
1018 'auto_retrieve' : function(params) {
1020 switch (this.node.nodeName) {
1021 case 'tree' : obj._auto_retrieve_tree(params); break;
1022 default: throw('NYI: Need .auto_retrieve() for ' + obj.node.nodeName); break;
1026 '_auto_retrieve_tree' : function (params) {
1028 if (!obj.auto_retrieve_in_progress) {
1029 obj.auto_retrieve_in_progress = true;
1033 //alert('auto_retrieve\n');
1035 var startpos = obj.node.treeBoxObject.getFirstVisibleRow();
1036 var endpos = obj.node.treeBoxObject.getLastVisibleRow();
1037 if (startpos > endpos) endpos = obj.node.treeBoxObject.getPageLength();
1038 //dump('startpos = ' + startpos + ' endpos = ' + endpos + '\n');
1039 for (var i = startpos; i < endpos + 4; i++) {
1041 //dump('trying index ' + i + '\n');
1042 var item = obj.node.contentView.getItemAtIndex(i).firstChild;
1043 if (item && item.getAttribute('retrieved') != 'true' ) {
1044 //dump('\tgot an unfleshed item = ' + item + ' = ' + item.nodeName + '\n');
1045 util.widgets.dispatch('flesh',item); count++;
1048 //dump(i + ' : ' + E + '\n');
1051 obj.auto_retrieve_in_progress = false;
1053 } catch(E) { alert(E); }
1059 'exec_on_all_fleshed' : function() {
1062 if (obj.on_all_fleshed) {
1063 if (typeof obj.on_all_fleshed == 'function') {
1064 dump('exec_on_all_fleshed == function\n');
1067 try { obj.on_all_fleshed(); } catch(E) { obj.error.standard_unexpected_error_alert('_full_retrieve_tree callback',obj.on_all_fleshed); }
1070 } else if (typeof obj.on_all_fleshed.length != 'undefined') {
1071 dump('exec_on_all_fleshed == array\n');
1075 dump('exec_on_all_fleshed, processing on_all_fleshed array, length = ' + obj.on_all_fleshed.length + '\n');
1076 var f = obj.on_all_fleshed.pop();
1077 if (typeof f == 'function') {
1078 try { f(); } catch(E) { obj.error.standard_unexpected_error_alert('_full_retrieve_tree callback',f); }
1080 if (obj.on_all_fleshed.length > 0) arguments.callee();
1082 obj.error.standard_unexpected_error_alert('exec_on_all_fleshed callback error',E);
1087 obj.error.standard_unexpected_error_alert('unexpected on_all_fleshed object: ', obj.on_all_fleshed);
1091 obj.error.standard_unexpected_error_alert('exec_on_all-fleshed error',E);
1095 'full_retrieve' : function(params) {
1097 switch (this.node.nodeName) {
1098 case 'tree' : obj._full_retrieve_tree(params); break;
1099 default: throw('NYI: Need .full_retrieve() for ' + obj.node.nodeName); break;
1101 obj.refresh_ordinals();
1104 '_full_retrieve_tree' : function(params) {
1107 if (obj.row_count.fleshed >= obj.row_count.total) {
1108 dump('Full retrieve... tree seems to be in sync\n' + js2JSON(obj.row_count) + '\n');
1109 obj.exec_on_all_fleshed();
1111 dump('Full retrieve... syncing tree' + js2JSON(obj.row_count) + '\n');
1112 JSAN.use('util.widgets');
1113 var nodes = obj.treechildren.childNodes;
1114 for (var i = 0; i < nodes.length; i++) {
1115 util.widgets.dispatch('flesh',nodes[i].firstChild);
1119 obj.error.standard_unexpected_error_alert('_full_retrieve_tree',E);
1123 '_append_to_listbox' : function (params) {
1127 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
1129 var s = ('util.list.append: params = ' + (params) + '\n');
1131 var listitem = document.createElement('listitem');
1133 s += ('listbox = ' + this.node + ' listitem = ' + listitem + '\n');
1135 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
1139 listitem.setAttribute('retrieve_id',params.retrieve_id);
1140 //FIXME//Make async and fire when row is visible in list
1143 params.treeitem_node = listitem;
1144 params.on_retrieve = function(row) {
1146 obj._map_row_to_listcell(params,listitem);
1147 obj.node.appendChild( listitem );
1148 util.widgets.dispatch('select',obj.node);
1151 if (typeof params.retrieve_row == 'function') {
1153 row = params.retrieve_row( params );
1157 if (typeof obj.retrieve_row == 'function') {
1159 row = obj.retrieve_row( params );
1166 this._map_row_to_listcell(params,listitem);
1167 this.node.appendChild( listitem );
1170 this.error.sdump('D_LIST',s);
1171 params.treeitem_node = listitem;
1176 '_map_row_to_treecell' : function(params,treerow) {
1180 if (typeof params.map_row_to_column == 'function' || typeof this.map_row_to_column == 'function') {
1182 for (var i = 0; i < this.columns.length; i++) {
1184 if (typeof treerow.childNodes[i] == 'undefined') {
1185 treecell = document.createElement('treecell');
1186 treerow.appendChild( treecell );
1188 treecell = treerow.childNodes[i];
1191 if ( this.columns[i].editable == false ) { treecell.setAttribute('editable','false'); }
1193 var sort_value = '';
1195 // What skip columns is doing is rendering the treecells as blank/empty
1196 if (params.skip_columns && (params.skip_columns.indexOf(i) != -1)) {
1197 treecell.setAttribute('label',label);
1198 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
1201 if (params.skip_all_columns_except && (params.skip_all_columns_except.indexOf(i) == -1)) {
1202 treecell.setAttribute('label',label);
1203 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
1207 if (typeof params.map_row_to_column == 'function') {
1209 label = params.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1211 } else if (typeof this.map_row_to_column == 'function') {
1213 label = this.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1216 if (this.columns[i].type == 'checkbox') { treecell.setAttribute('value',label); } else { treecell.setAttribute('label',label ? label : ''); }
1217 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
1219 } else if (typeof params.map_row_to_columns == 'function' || typeof this.map_row_to_columns == 'function') {
1222 var sort_values = [];
1224 if (typeof params.map_row_to_columns == 'function') {
1226 var values = params.map_row_to_columns(params.row,this.columns,this.scratch_data);
1227 if (typeof values.values == 'undefined') {
1230 labels = values.values;
1231 sort_values = values.sort_values;
1234 } else if (typeof this.map_row_to_columns == 'function') {
1236 var values = this.map_row_to_columns(params.row,this.columns,this.scratch_data);
1237 if (typeof values.values == 'undefined') {
1240 labels = values.values;
1241 sort_values = values.sort_values;
1244 for (var i = 0; i < labels.length; i++) {
1246 if (typeof treerow.childNodes[i] == 'undefined') {
1247 treecell = document.createElement('treecell');
1248 treerow.appendChild(treecell);
1250 treecell = treerow.childNodes[i];
1252 if ( this.columns[i].editable == false ) { treecell.setAttribute('editable','false'); }
1253 if ( this.columns[i].type == 'checkbox') {
1254 treecell.setAttribute('value', labels[i]);
1256 treecell.setAttribute('label',typeof labels[i] == 'string' || typeof labels[i] == 'number' ? labels[i] : '');
1258 if (sort_values[i]) {
1259 treecell.setAttribute('sort_value',js2JSON(sort_values[i]));
1261 s += ('treecell = ' + treecell + ' with label = ' + labels[i] + '\n');
1266 throw('No row to column mapping function.');
1268 this.error.sdump('D_LIST',s);
1271 '_map_row_to_listcell' : function(params,listitem) {
1274 for (var i = 0; i < this.columns.length; i++) {
1276 if (typeof params.map_row_to_column == 'function') {
1278 value = params.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1282 if (typeof this.map_row_to_column == 'function') {
1284 value = this.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1287 if (typeof value == 'string' || typeof value == 'number') {
1288 var listcell = document.createElement('listcell');
1289 listcell.setAttribute('label',value);
1290 listitem.appendChild(listcell);
1291 s += ('listcell = ' + listcell + ' with label = ' + value + '\n');
1293 listitem.appendChild(value);
1294 s += ('listcell = ' + value + ' is really a ' + value.nodeName + '\n');
1297 this.error.sdump('D_LIST',s);
1300 'select_all' : function(params) {
1302 switch(this.node.nodeName) {
1303 case 'tree' : return this._select_all_from_tree(params); break;
1304 default: throw('NYI: Need ._select_all_from_() for ' + this.node.nodeName); break;
1308 '_select_all_from_tree' : function(params) {
1310 this.node.view.selection.selectAll();
1313 'retrieve_selection' : function(params) {
1315 switch(this.node.nodeName) {
1316 case 'tree' : return this._retrieve_selection_from_tree(params); break;
1317 default: throw('NYI: Need ._retrieve_selection_from_() for ' + this.node.nodeName); break;
1321 '_retrieve_selection_from_tree' : function(params) {
1324 var start = new Object();
1325 var end = new Object();
1326 var numRanges = this.node.view.selection.getRangeCount();
1327 for (var t=0; t<numRanges; t++){
1328 this.node.view.selection.getRangeAt(t,start,end);
1329 for (var v=start.value; v<=end.value; v++){
1330 var i = this.node.contentView.getItemAtIndex(v);
1337 'dump' : function(params) {
1339 switch(this.node.nodeName) {
1340 case 'tree' : return this._dump_tree(params); break;
1341 default: throw('NYI: Need .dump() for ' + this.node.nodeName); break;
1345 '_dump_tree' : function(params) {
1348 for (var i = 0; i < this.treechildren.childNodes.length; i++) {
1350 var treeitem = this.treechildren.childNodes[i];
1351 var treerow = treeitem.firstChild;
1352 for (var j = 0; j < treerow.childNodes.length; j++) {
1353 row.push( treerow.childNodes[j].getAttribute('label') );
1360 'dump_with_keys' : function(params) {
1362 switch(this.node.nodeName) {
1363 case 'tree' : return this._dump_tree_with_keys(params); break;
1364 default: throw('NYI: Need .dump_with_keys() for ' + this.node.nodeName); break;
1369 '_dump_tree_with_keys' : function(params) {
1373 function process_tree(treechildren) {
1374 for (var i = 0; i < treechildren.childNodes.length; i++) {
1376 var treeitem = treechildren.childNodes[i];
1377 var treerow = treeitem.firstChild;
1378 for (var j = 0; j < treerow.childNodes.length; j++) {
1379 if (typeof obj.columns[j] == 'undefined') {
1380 dump('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n');
1381 dump('_dump_tree_with_keys @ ' + location.href + '\n');
1382 dump('\ttreerow.childNodes.length='+treerow.childNodes.length+' j='+j+' obj.columns.length='+obj.columns.length+'\n');
1385 row[ obj.columns[j].id ] = treerow.childNodes[j].getAttribute('label');
1386 var sort = treerow.childNodes[j].getAttribute('sort_value');
1388 row[ obj.columns[j].id + '_sort_value' ] = sort;
1393 if (treeitem.childNodes.length > 1) {
1394 process_tree(treeitem.lastChild);
1399 process_tree(this.treechildren);
1404 'dump_csv' : function(params) {
1406 switch(this.node.nodeName) {
1407 case 'tree' : return this._dump_tree_csv(params); break;
1408 default: throw('NYI: Need .dump_csv() for ' + this.node.nodeName); break;
1413 '_dump_tree_csv' : function(params) {
1417 for (var j = 0; j < obj.columns.length; j++) {
1418 if (obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('hidden') == 'true') {
1421 ord_cols.push( [ obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('ordinal'), j ] );
1424 ord_cols.sort( function(a,b) {
1425 if ( Number( a[0] ) < Number( b[0] ) ) return -1;
1426 if ( Number( a[0] ) > Number( b[0] ) ) return 1;
1429 for (var j = 0; j < ord_cols.length; j++) {
1430 if (_dump) _dump += ',';
1431 _dump += '"' + obj.columns[ ord_cols[j][1] ].label.replace(/"/g, '""') + '"';
1435 function process_tree(treechildren) {
1436 for (var i = 0; i < treechildren.childNodes.length; i++) {
1438 var treeitem = treechildren.childNodes[i];
1439 var treerow = treeitem.firstChild;
1440 for (var j = 0; j < ord_cols.length; j++) {
1441 if (row) row += ',';
1442 row += '"' + treerow.childNodes[ ord_cols[j][1] ].getAttribute('label').replace(/"/g, '""') + '"';
1444 _dump += row + '\r\n';
1445 if (treeitem.childNodes.length > 1) {
1446 process_tree(treeitem.lastChild);
1451 process_tree(this.treechildren);
1456 'dump_extended_format' : function(params) {
1458 switch(this.node.nodeName) {
1459 case 'tree' : return this._dump_tree_extended_format(params); break;
1460 default: throw('NYI: Need .dump_extended_format() for ' + this.node.nodeName); break;
1465 '_dump_tree_extended_format' : function(params) {
1469 for (var j = 0; j < obj.columns.length; j++) {
1470 if (obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('hidden') == 'true') {
1473 ord_cols.push( [ obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('ordinal'), j ] );
1476 ord_cols.sort( function(a,b) {
1477 if ( Number( a[0] ) < Number( b[0] ) ) return -1;
1478 if ( Number( a[0] ) > Number( b[0] ) ) return 1;
1482 function process_tree(treechildren) {
1483 for (var i = 0; i < treechildren.childNodes.length; i++) {
1484 var row = document.getElementById('offlineStrings').getString('list.dump_extended_format.record_separator') + '\r\n';
1485 var treeitem = treechildren.childNodes[i];
1486 var treerow = treeitem.firstChild;
1487 for (var j = 0; j < ord_cols.length; j++) {
1488 row += obj.columns[ ord_cols[j][1] ].label + ': ' + treerow.childNodes[ ord_cols[j][1] ].getAttribute('label') + '\r\n';
1490 _dump += row + '\r\n';
1491 if (treeitem.childNodes.length > 1) {
1492 process_tree(treeitem.lastChild);
1497 process_tree(this.treechildren);
1502 'dump_csv_to_clipboard' : function(params) {
1504 if (typeof params == 'undefined') params = {};
1505 if (params.no_full_retrieve) {
1506 copy_to_clipboard( obj.dump_csv( params ) );
1508 obj.wrap_in_full_retrieve( function() { copy_to_clipboard( obj.dump_csv( params ) ); } );
1512 'dump_csv_to_printer' : function(params) {
1514 if (typeof params == 'undefined') params = {};
1515 JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context);
1516 if (params.no_full_retrieve) {
1517 print.simple( obj.dump_csv( params ), {'content_type':'text/plain'} );
1519 obj.wrap_in_full_retrieve(
1521 print.simple( obj.dump_csv( params ), {'content_type':'text/plain'} );
1527 'dump_extended_format_to_printer' : function(params) {
1529 if (typeof params == 'undefined') params = {};
1530 JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context);
1531 if (params.no_full_retrieve) {
1532 print.simple( obj.dump_extended_format( params ), {'content_type':'text/plain'} );
1534 obj.wrap_in_full_retrieve(
1536 print.simple( obj.dump_extended_format( params ), {'content_type':'text/plain'} );
1542 'dump_csv_to_file' : function(params) {
1544 JSAN.use('util.file'); var f = new util.file();
1545 if (typeof params == 'undefined') params = {};
1546 if (params.no_full_retrieve) {
1547 params.data = obj.dump_csv( params );
1548 params.not_json = true;
1549 if (!params.title) params.title = document.getElementById('offlineStrings').getString('list.save_csv_as');
1550 f.export_file( params );
1552 obj.wrap_in_full_retrieve(
1554 params.data = obj.dump_csv( params );
1555 params.not_json = true;
1556 if (!params.title) params.title = document.getElementById('offlineStrings').getString('list.save_csv_as');
1557 f.export_file( params );
1563 'print' : function(params) {
1564 if (!params) params = {};
1565 switch(this.node.nodeName) {
1566 case 'tree' : return this._print_tree(params); break;
1567 default: throw('NYI: Need ._print() for ' + this.node.nodeName); break;
1571 '_print_tree' : function(params) {
1574 var data = obj.data; data.stash_retrieve();
1575 if (!params.staff && data.list.au && data.list.au[0]) {
1576 params.staff = data.list.au[0];
1578 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() ]) {
1579 params.lib = data.hash.aou[ data.list.au[0].ws_ou() ];
1580 params.lib.children(null);
1582 if (params.template && data.print_list_templates[ params.template ]) {
1583 var template = data.print_list_templates[ params.template ];
1584 if (template.inherit) {
1585 template = data.print_list_templates[ template.inherit ];
1586 // if someone wants to implement recursion later, feel free
1588 for (var i in template) params[i] = template[i];
1590 obj.wrap_in_full_retrieve(
1593 if (!params.list) params.list = obj.dump_with_keys();
1594 JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context);
1595 print.tree_list( params );
1596 if (typeof params.callback == 'function') params.callback();
1598 obj.error.standard_unexpected_error_alert('inner _print_tree',E);
1604 obj.error.standard_unexpected_error_alert('_print_tree',E);
1608 'dump_selected_with_keys' : function(params) {
1610 switch(this.node.nodeName) {
1611 case 'tree' : return this._dump_tree_selection_with_keys(params); break;
1612 default: throw('NYI: Need .dump_selection_with_keys() for ' + this.node.nodeName); break;
1617 '_dump_tree_selection_with_keys' : function(params) {
1620 var list = obj._retrieve_selection_from_tree();
1621 for (var i = 0; i < list.length; i++) {
1623 var treeitem = list[i];
1624 var treerow = treeitem.firstChild;
1625 for (var j = 0; j < treerow.childNodes.length; j++) {
1626 var value = treerow.childNodes[j].getAttribute('label');
1627 if (params.skip_hidden_columns) if (obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('hidden') == 'true') continue;
1628 if (typeof obj.columns[j] == 'undefined') {
1629 dump('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n');
1630 dump('_dump_tree_selection_with_keys @ ' + location.href + '\n');
1631 dump('\ttreerow.childNodes.length='+treerow.childNodes.length+' j='+j+' obj.columns.length='+obj.columns.length+'\n');
1634 var id = obj.columns[j].id; if (params.labels_instead_of_ids) id = obj.columns[j].label;
1643 'clipboard' : function(params) {
1646 var dump = obj.dump_selected_with_keys({'skip_hidden_columns':true,'labels_instead_of_ids':true});
1647 obj.data.stash_retrieve();
1648 obj.data.list_clipboard = dump; obj.data.stash('list_clipboard');
1649 JSAN.use('util.window'); var win = new util.window();
1650 win.open(urls.XUL_LIST_CLIPBOARD,'list_clipboard','chrome,resizable,modal');
1651 window.focus(); // sometimes the main window will lower after a clipboard action
1653 this.error.standard_unexpected_error_alert('clipboard',E);
1657 'dump_retrieve_ids' : function(params) {
1659 switch(this.node.nodeName) {
1660 case 'tree' : return this._dump_retrieve_ids_tree(params); break;
1661 default: throw('NYI: Need .dump_retrieve_ids() for ' + this.node.nodeName); break;
1665 '_dump_retrieve_ids_tree' : function(params) {
1668 for (var i = 0; i < this.treechildren.childNodes.length; i++) {
1669 var treeitem = this.treechildren.childNodes[i];
1670 dump.push( treeitem.getAttribute('retrieve_id') );
1675 'wrap_in_full_retrieve' : function(f) {
1677 if (typeof obj.on_all_fleshed == 'function') { // legacy
1678 obj.on_all_fleshed = [ obj.on_all_fleshed ];
1680 if (! obj.on_all_fleshed) obj.on_all_fleshed = [];
1681 obj.on_all_fleshed.push(f);
1682 obj.full_retrieve();
1685 '_sort_tree' : function() {
1688 if (obj.node.getAttribute('no_sort')) {
1692 var sorts = [ obj.first_sort ].concat( obj.sub_sorts );
1693 var columns = util.functional.map_list(
1699 var column_positions = [];
1700 for (var i = 0; i < columns.length; i++) {
1701 for (var j = 0; j < obj.columns.length; j++) {
1702 if (obj.columns[j].id == columns[i].id) {
1703 column_positions.push( function(a){return a;}(j) );
1707 obj.wrap_in_full_retrieve(
1710 JSAN.use('util.money');
1712 var treeitems = obj.treechildren.childNodes;
1713 for (var i = 0; i < treeitems.length; i++) {
1714 var treeitem = treeitems[i];
1715 var treerow = treeitem.firstChild;
1717 function get_value(treecell) {
1720 ? treecell.getAttribute('label')
1722 'sort_value' : treecell ? treecell.hasAttribute('sort_value')
1724 treecell.getAttribute('sort_value'))
1731 for (var j = 0; j < column_positions.length; j++) {
1732 var treecell = treerow.childNodes[ column_positions[j] ];
1734 'position' : column_positions[j],
1735 'value' : get_value(treecell)
1744 rows = rows.sort( function(A,B) {
1745 function normalize(a,b,p) {
1752 if (obj.columns[p].sort_type) {
1753 switch(obj.columns[p].sort_type) {
1755 JSAN.use('util.date'); // to pull in dojo.date.locale
1756 a = dojo.date.locale.parse(a,{});
1757 b = dojo.date.locale.parse(b,{});
1760 a = Number(a); b = Number(b);
1763 a = util.money.dollars_float_to_cents_integer(a);
1764 b = util.money.dollars_float_to_cents_integer(b);
1766 case 'title' : /* special case for "a" and "the". doesn't use marc 245 indicator */
1767 a = String( a ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
1768 b = String( b ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
1771 a = String( a ).toUpperCase();
1772 b = String( b ).toUpperCase();
1776 if (typeof a == 'string' || typeof b == 'string') {
1777 a = String( a ).toUpperCase();
1778 b = String( b ).toUpperCase();
1785 for (var i = 0; i < sorts.length; i++) {
1787 if (sorts[i].sortDir == 'asc') {
1789 A['values'][i]['value'],
1790 B['values'][i]['value'],
1791 A['values'][i]['position']
1795 B['values'][i]['value'],
1796 A['values'][i]['value'],
1797 A['values'][i]['position']
1800 if (values[0] < values[1] ) {
1803 if (values[0] > values[1] ) {
1809 while(obj.treechildren.lastChild) obj.treechildren.removeChild( obj.treechildren.lastChild );
1810 for (var i = 0; i < rows.length; i++) {
1811 obj.treechildren.appendChild( rows[i].node );
1813 if (typeof obj.on_sort == 'function') obj.on_sort();
1815 obj.error.standard_unexpected_error_alert('sorting',E);
1817 obj.refresh_ordinals();
1821 obj.error.standard_unexpected_error_alert('pre sorting', E);
1825 '_toggle_checkbox_column' : function(col,toggle) {
1828 if (obj.node.getAttribute('no_toggle')) {
1832 for (var i = 0; i < obj.columns.length; i++) {
1833 if (obj.columns[i].id == col.id) col_pos = function(a){return a;}(i);
1835 var treeitems = obj.treechildren.childNodes;
1836 for (var i = 0; i < treeitems.length; i++) {
1837 var treeitem = treeitems[i];
1838 var treerow = treeitem.firstChild;
1839 var treecell = treerow.childNodes[ col_pos ];
1840 treecell.setAttribute('value',(toggle == 'on'));
1842 if (typeof obj.on_checkbox_toggle == 'function') obj.on_checkbox_toggle(toggle);
1844 obj.error.standard_unexpected_error_alert('pre toggle', E);
1848 'render_list_actions' : function(params) {
1850 switch(this.node.nodeName) {
1851 case 'tree' : return this._render_list_actions_for_tree(params); break;
1852 default: throw('NYI: Need ._render_list_actions() for ' + this.node.nodeName); break;
1856 '_render_list_actions_for_tree' : function(params) {
1859 var btn = document.createElement('button');
1860 btn.setAttribute('id',obj.node.id + '_list_actions');
1861 btn.setAttribute('type','menu');
1862 btn.setAttribute('allowevents','true');
1863 //btn.setAttribute('oncommand','this.firstChild.showPopup();');
1864 btn.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.menu.label'));
1865 btn.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.menu.accesskey'));
1866 var mp = document.createElement('menupopup');
1867 btn.appendChild(mp);
1868 var mi = document.createElement('menuitem');
1869 mi.setAttribute('id',obj.node.id + '_clipfield');
1870 mi.setAttribute('disabled','true');
1871 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.field_to_clipboard.label'));
1872 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.field_to_clipboard.accesskey'));
1874 mi = document.createElement('menuitem');
1875 mi.setAttribute('id',obj.node.id + '_csv_to_clipboard');
1876 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_clipboard.label'));
1877 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_clipboard.accesskey'));
1879 mi = document.createElement('menuitem');
1880 mi.setAttribute('id',obj.node.id + '_csv_to_printer');
1881 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_printer.label'));
1882 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_printer.accesskey'));
1884 mi = document.createElement('menuitem');
1885 mi.setAttribute('id',obj.node.id + '_extended_to_printer');
1886 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.extended_to_printer.label'));
1887 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.extended_to_printer.accesskey'));
1889 mi = document.createElement('menuitem');
1890 mi.setAttribute('id',obj.node.id + '_csv_to_file');
1891 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_file.label'));
1892 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_file.accesskey'));
1894 mi = document.createElement('menuitem');
1895 mi.setAttribute('id',obj.node.id + '_save_columns');
1896 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.save_column_configuration.label'));
1897 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.save_column_configuration.accesskey'));
1898 if (obj.data.hash.aous['gui.disable_local_save_columns']) {
1899 mi.setAttribute('disabled','true');
1904 obj.error.standard_unexpected_error_alert('rendering list actions',E);
1908 'set_list_actions' : function(params) {
1910 switch(this.node.nodeName) {
1911 case 'tree' : return this._set_list_actions_for_tree(params); break;
1912 default: throw('NYI: Need ._set_list_actions() for ' + this.node.nodeName); break;
1916 '_set_list_actions_for_tree' : function(params) {
1917 // This should be called after the button element from render_list_actions has been appended to the DOM
1920 var x = document.getElementById(obj.node.id + '_clipfield');
1925 obj.clipboard(params);
1926 if (params && typeof params.on_complete == 'function') {
1927 params.on_complete(params);
1933 x = document.getElementById(obj.node.id + '_csv_to_clipboard');
1938 obj.dump_csv_to_clipboard(params);
1939 if (params && typeof params.on_complete == 'function') {
1940 params.on_complete(params);
1946 x = document.getElementById(obj.node.id + '_csv_to_printer');
1951 obj.dump_csv_to_printer(params);
1952 if (params && typeof params.on_complete == 'function') {
1953 params.on_complete(params);
1959 x = document.getElementById(obj.node.id + '_extended_to_printer');
1964 obj.dump_extended_format_to_printer(params);
1965 if (params && typeof params.on_complete == 'function') {
1966 params.on_complete(params);
1973 x = document.getElementById(obj.node.id + '_csv_to_file');
1978 obj.dump_csv_to_file(params);
1979 if (params && typeof params.on_complete == 'function') {
1980 params.on_complete(params);
1986 x = document.getElementById(obj.node.id + '_save_columns');
1991 obj.save_columns(params);
1992 if (params && typeof params.on_complete == 'function') {
1993 params.on_complete(params);
2001 obj.error.standard_unexpected_error_alert('setting list actions',E);
2005 // Takes fieldmapper class name and attempts to spit out column definitions suitable for .init
2006 'fm_columns' : function(hint,column_extras,prefix) {
2009 if (!prefix) { prefix = ''; }
2011 // requires the dojo library fieldmapper.autoIDL
2012 if (typeof fieldmapper == 'undefined') { throw 'fieldmapper undefined'; }
2013 if (typeof fieldmapper.IDL == 'undefined') { throw 'fieldmapper.IDL undefined'; }
2014 if (typeof fieldmapper.IDL.fmclasses == 'undefined') { throw 'fieldmapper.IDL.fmclasses undefined'; }
2015 if (typeof fieldmapper.IDL.fmclasses[hint] == 'undefined') { throw 'fieldmapper.IDL.fmclasses.' + hint + ' undefined'; }
2016 var my_class = fieldmapper.IDL.fmclasses[hint];
2017 var data = obj.data; data.stash_retrieve();
2019 function col_def(my_field) {
2020 var col_id = prefix + hint + '_' + my_field.name;
2022 var datafield = my_field.name;
2023 var fleshed_display_field;
2024 if (column_extras) {
2025 if (column_extras['*']) {
2026 if (column_extras['*']['dataobj']) {
2027 dataobj = column_extras['*']['dataobj'];
2030 if (column_extras[col_id]) {
2031 if (column_extras[col_id]['dataobj']) {
2032 dataobj = column_extras[col_id]['dataobj'];
2034 if (column_extras[col_id]['datafield']) {
2035 datafield = column_extras[col_id]['datafield'];
2037 if (column_extras[col_id]['fleshed_display_field']) {
2038 fleshed_display_field = column_extras[col_id]['fleshed_display_field'];
2044 'label' : my_field.label || my_field.name,
2045 'sort_type' : [ 'int', 'float', 'id', 'number' ].indexOf(my_field.datatype) > -1 ? 'number' :
2046 ( my_field.datatype == 'money' ? 'money' :
2047 ( my_field.datatype == 'timestamp' ? 'date' : 'default')),
2048 'hidden' : my_field.virtual || my_field.datatype == 'link',
2051 // my_field.datatype => bool float id int interval link money number org_unit text timestamp
2052 if (my_field.datatype == 'link') {
2053 def.render = function(my) {
2054 // is the object fleshed?
2055 return my[dataobj][datafield]() && typeof my[dataobj][datafield]() == 'object'
2056 // yes, show the display field
2057 ? my[dataobj][datafield]()[fleshed_display_field||my_field.key]()
2058 // no, do we have its class in data.hash?
2059 : ( typeof data.hash[ my[dataobj].Structure.field_map[datafield].class ] != 'undefined'
2060 // yes, do we have this particular object cached?
2061 ? ( data.hash[ my[dataobj].Structure.field_map[datafield].class ][ my[dataobj][datafield]() ]
2062 // yes, show the display field
2063 ? data.hash[ my[dataobj].Structure.field_map[datafield].class ][ my[dataobj][datafield]() ][
2064 fleshed_display_field||my_field.key
2066 // no, just show the raw value
2067 : my[dataobj][datafield]()
2069 // no, just show the raw value
2070 : my[dataobj][datafield]()
2074 def.render = function(my) { return my[dataobj][datafield](); }
2076 if (my_field.datatype == 'timestamp') {
2077 JSAN.use('util.date');
2078 def.render = function(my) {
2079 return util.date.formatted_date( my[dataobj][datafield](), '%{localized}' );
2081 def.sort_value = function(my) {
2082 return util.date.db_date2Date( my[dataobj][datafield]() ).getTime();
2085 if (my_field.datatype == 'org_unit') {
2086 def.render = function(my) {
2087 return typeof my[dataobj][datafield]() == 'object' ? my[dataobj][datafield]().shortname() : data.hash.aou[ my[dataobj][datafield]() ].shortname();
2090 if (my_field.datatype == 'money') {
2091 JSAN.use('util.money');
2092 def.render = function(my) {
2093 return util.money.sanitize( my[dataobj][datafield]() );
2095 def.sort_value = function(my) {
2096 return util.money.dollars_float_to_cents_integer( my[dataobj][datafield]() );
2099 if (column_extras) {
2100 if (column_extras['*']) {
2101 for (var attr in column_extras['*']) {
2102 def[attr] = column_extras['*'][attr];
2104 if (column_extras['*']['expanded_label']) {
2105 def.label = my_class.label + ': ' + def.label;
2107 if (column_extras['*']['label_prefix']) {
2108 def.label = column_extras['*']['label_prefix'] + def.label;
2110 if (column_extras['*']['remove_virtual']) {
2111 if (my_field.virtual) {
2112 def.remove_me = true;
2116 if (column_extras[col_id]) {
2117 for (var attr in column_extras[col_id]) {
2118 def[attr] = column_extras[col_id][attr];
2120 if (column_extras[col_id]['keep_me']) {
2121 def.remove_me = false;
2123 if (column_extras[col_id]['label_prefix']) {
2124 def.label = column_extras[col_id]['label_prefix'] + def.label;
2128 if (def.remove_me) {
2129 dump('Skipping ' + def.label + '\n');
2132 dump('Defining ' + def.label + '\n');
2137 for (var i = 0; i < my_class.fields.length; i++) {
2138 var my_field = my_class.fields[i];
2139 var def = col_def(my_field);
2141 columns.push( def );
2146 obj.error.standard_unexpected_error_alert('fm_columns()',E);
2150 // Default for the map_row_to_columns function for .init
2151 'std_map_row_to_columns' : function(error_value) {
2152 return function(row,cols,scratch) {
2153 // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
2154 // cols contains all of the objects listed above in columns
2155 // scratch is a temporary space shared by all cells/rows (or just per row if not explicitly passed in)
2156 if (!scratch) { scratch = {}; }
2159 JSAN.use('util.error'); obj.error = new util.error();
2160 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
2161 JSAN.use('util.network'); obj.network = new util.network();
2162 JSAN.use('util.money');
2166 var sort_values = [];
2169 for (var i = 0; i < cols.length; i++) {
2170 switch (typeof cols[i].render) {
2171 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;
2172 case 'string' : cmd += 'try { ' + cols[i].render + '; values['+i+'] = v; } catch(E) { values['+i+'] = error_value; }'; break;
2173 default: cmd += 'values['+i+'] = "??? '+(typeof cols[i].render)+'"; ';
2175 switch (typeof cols[i].sort_value) {
2178 sort_values[i] = cols[i].sort_value(my,scratch);
2180 sort_values[i] = error_value;
2181 obj.error.sdump('D_COLUMN_RENDER_ERROR',E);
2186 + cols[i].sort_value
2189 +'] = v; } catch(E) { sort_values['
2191 + '] = error_value; }';
2194 cmd += 'sort_values['+i+'] = values[' + i + '];';
2197 if (cmd) eval( cmd );
2199 obj.error.sdump('D_WARN','map_row_to_column: ' + E);
2200 if (error_value) { value = error_value; } else { value = ' ' };
2202 return { 'values' : values, 'sort_values' : sort_values };
2206 dump('exiting util.list.js\n');