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 JSAN.use('util.file'); var file = new util.file('tree_columns_for_'+window.escape(id));
411 file.set_object(my_cols);
413 alert(document.getElementById('offlineStrings').getString('list.columns_saved'));
415 obj.error.standard_unexpected_error_alert('_save_columns_tree',E);
419 'restores_columns' : function (params) {
421 switch (this.node.nodeName) {
422 case 'tree' : this._restores_columns_tree(params); break;
423 default: throw('NYI: Need .restores_columns() for ' + this.node.nodeName); break;
427 '_restores_columns_tree' : function (params) {
430 var id = obj.node.getAttribute('id');
431 if (obj.columns_saved_under) { id = obj.columns_saved_under; }
433 alert("FIXME: The columns for this list cannot be restored because the list has no id.");
438 if (! obj.data.hash.aous) { obj.data.hash.aous = {}; }
439 if (! obj.data.hash.aous['gui.disable_local_save_columns']) {
440 JSAN.use('util.file'); var file = new util.file('tree_columns_for_'+window.escape(id));
441 if (file._file.exists()) {
442 my_cols = file.get_object(); file.close();
445 /* local file will trump remote file if allowed, so save ourselves an http request if this is the case */
446 if (obj.data.hash.aous['url.remote_column_settings'] && ! my_cols ) {
448 var x = new XMLHttpRequest();
449 var url = obj.data.hash.aous['url.remote_column_settings'] + '/tree_columns_for_' + window.escape(id);
450 x.open("GET", url, false);
452 if (x.status == 200) {
453 my_cols = JSON2js( x.responseText );
456 // This can happen in the offline interface if you logged in previously and url.remote_column_settings is set.
457 // 1) You may be really "offline" now
458 // 2) the URL may just be a path component without a hostname (ie "/xul/column_settings/"), which won't work
459 // when appended to chrome://open_ils_staff_client/
460 dump('Error retrieving column settings from ' + url + ': ' + E + '\n');
465 var nl = obj.node.getElementsByTagName('treecol');
466 for (var i = 0; i < nl.length; i++) {
468 var col_id = col.getAttribute('id');
470 alert('FIXME: A column in this list does not have an id and cannot be saved');
473 if (typeof my_cols[col_id] != 'undefined') {
474 col.setAttribute('hidden',my_cols[col_id].hidden);
475 col.setAttribute('width',my_cols[col_id].width);
476 col.setAttribute('ordinal',my_cols[col_id].ordinal);
478 obj.error.sdump('D_ERROR','WARNING: Column ' + col_id + ' did not have a saved state.');
483 obj.error.standard_unexpected_error_alert('_restore_columns_tree',E);
487 'clear' : function (params) {
489 switch (this.node.nodeName) {
490 case 'tree' : this._clear_tree(params); break;
491 case 'listbox' : this._clear_listbox(params); break;
492 default: throw('NYI: Need .clear() for ' + this.node.nodeName); break;
494 this.error.sdump('D_LIST','Clearing list ' + this.node.getAttribute('id') + '\n');
495 this.row_count.total = 0;
496 this.row_count.fleshed = 0;
497 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
500 '_clear_tree' : function(params) {
502 if (obj.error.sdump_levels.D_LIST_DUMP_ON_CLEAR) {
503 obj.error.sdump('D_LIST_DUMP_ON_CLEAR',obj.dump());
505 if (obj.error.sdump_levels.D_LIST_DUMP_WITH_KEYS_ON_CLEAR) {
506 obj.error.sdump('D_LIST_DUMP_WITH_KEYS_ON_CLEAR',obj.dump_with_keys());
508 while (obj.treechildren.lastChild) obj.treechildren.removeChild( obj.treechildren.lastChild );
511 '_clear_listbox' : function(params) {
514 var nl = this.node.getElementsByTagName('listitem');
515 for (var i = 0; i < nl.length; i++) {
518 for (var i = 0; i < items.length; i++) {
519 this.node.removeChild(items[i]);
523 'append' : function (params) {
526 switch (this.node.nodeName) {
527 case 'tree' : rparams = this._append_to_tree(params); break;
528 case 'listbox' : rparams = this._append_to_listbox(params); break;
529 default: throw('NYI: Need .append() for ' + this.node.nodeName); break;
531 if (rparams && params.attributes) {
532 for (var i in params.attributes) {
533 rparams.treeitem_node.setAttribute(i,params.attributes[i]);
536 this.row_count.total++;
537 if (this.row_count.fleshed == this.row_count.total) {
538 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
540 rparams.treeitem_node.setAttribute('unique_row_counter',obj.unique_row_counter);
541 rparams.unique_row_counter = obj.unique_row_counter++;
542 if (typeof params.on_append == 'function') {
543 params.on_append(rparams);
548 'refresh_row' : function (params) {
551 switch (this.node.nodeName) {
552 case 'tree' : rparams = this._refresh_row_in_tree(params); break;
553 default: throw('NYI: Need .refresh_row() for ' + this.node.nodeName); break;
555 if (rparams && params.attributes) {
556 for (var i in params.attributes) {
557 rparams.treeitem_node.setAttribute(i,params.attributes[i]);
560 this.row_count.fleshed--;
565 '_append_to_tree' : function (params) {
569 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
571 var s = ('util.list.append: params = ' + (params) + '\n');
573 var treechildren_node = this.treechildren;
575 if (params.node && params.node.nodeName == 'treeitem') {
576 params.node.setAttribute('container','true'); /* params.node.setAttribute('open','true'); */
577 if (params.node.lastChild.nodeName == 'treechildren') {
578 treechildren_node = params.node.lastChild;
580 treechildren_node = document.createElement('treechildren');
581 params.node.appendChild(treechildren_node);
585 var treeitem = document.createElement('treeitem');
586 treeitem.setAttribute('retrieve_id',params.retrieve_id);
587 if (typeof params.to_bottom != 'undefined') {
588 treechildren_node.appendChild( treeitem );
589 if (typeof params.no_auto_select == 'undefined') {
590 if (!obj.auto_select_pending) {
591 obj.auto_select_pending = true;
592 setTimeout(function() {
593 dump('auto-selecting\n');
594 var idx = Number(obj.node.view.rowCount)-1;
595 try { obj.node.view.selection.select(idx); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); }
596 try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); }
597 obj.auto_select_pending = false;
598 try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(idx).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); }
603 if (treechildren_node.firstChild) {
604 treechildren_node.insertBefore( treeitem, treechildren_node.firstChild );
606 treechildren_node.appendChild( treeitem );
608 if (typeof params.no_auto_select == 'undefined') {
609 if (!obj.auto_select_pending) {
610 obj.auto_select_pending = true;
611 setTimeout(function() {
612 try { obj.node.view.selection.select(0); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); }
613 try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); }
614 obj.auto_select_pending = false;
615 try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(0).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); }
620 var treerow = document.createElement('treerow');
621 treeitem.appendChild( treerow );
622 treerow.setAttribute('retrieve_id',params.retrieve_id);
623 if (params.row_properties) treerow.setAttribute('properties',params.row_properties);
625 s += ('tree = ' + this.node + ' treechildren = ' + treechildren_node + '\n');
626 s += ('treeitem = ' + treeitem + ' treerow = ' + treerow + '\n');
628 obj.put_retrieving_label(treerow);
630 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
631 treerow.addEventListener(
635 if (treerow.getAttribute('retrieved') == 'true') return; /* already running */
637 treerow.setAttribute('retrieved','true');
639 //dump('fleshing = ' + params.retrieve_id + '\n');
641 function inc_fleshed() {
642 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
643 treerow.setAttribute('fleshed','true');
644 obj.row_count.fleshed++;
645 if (obj.row_count.fleshed >= obj.row_count.total) {
646 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
650 params.treeitem_node = treeitem;
651 params.on_retrieve = function(p) {
654 obj._map_row_to_treecell(p,treerow);
656 var idx = obj.node.contentView.getIndexOfItem( params.treeitem_node );
657 dump('idx = ' + idx + '\n');
658 // if current row is selected, send another select event to re-sync data that the client code fetches on selects
659 if ( obj.node.view.selection.isSelected( idx ) ) {
660 dump('dispatching select event for on_retrieve for idx = ' + idx + '\n');
661 util.widgets.dispatch('select',obj.node);
664 // Let's not alert on this for now. Getting contentView has no properties in record buckets under certain conditions
665 dump('fixme2: ' + E + '\n');
669 if (typeof params.retrieve_row == 'function') {
671 params.retrieve_row( params );
673 } else if (typeof obj.retrieve_row == 'function') {
675 obj.retrieve_row( params );
681 obj.refresh_ordinals();
685 if (typeof params.flesh_immediately != 'undefined') {
686 if (params.flesh_immediately) {
689 util.widgets.dispatch('flesh',treerow);
695 treerow.addEventListener(
698 //dump('fleshing anon\n');
699 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
700 obj._map_row_to_treecell(params,treerow);
701 treerow.setAttribute('retrieved','true');
702 treerow.setAttribute('fleshed','true');
703 obj.row_count.fleshed++;
704 if (obj.row_count.fleshed >= obj.row_count.total) {
705 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
707 obj.refresh_ordinals();
711 if (typeof params.flesh_immediately != 'undefined') {
712 if (params.flesh_immediately) {
715 util.widgets.dispatch('flesh',treerow);
721 this.error.sdump('D_LIST',s);
725 if (obj.trim_list && obj.row_count.total >= obj.trim_list) {
727 //if (typeof params.to_bottom != 'undefined')
728 if (typeof params.to_top == 'undefined') {
729 if (typeof params.on_delete == 'function') { params.on_delete( treechildren_node.firstChild.getAttribute('unique_row_counter') ); }
730 treechildren_node.removeChild( treechildren_node.firstChild );
732 if (typeof params.on_delete == 'function') { params.on_delete( treechildren_node.lastChild.getAttribute('unique_row_counter') ); }
733 treechildren_node.removeChild( treechildren_node.lastChild );
739 setTimeout( function() { obj.auto_retrieve(); obj.refresh_ordinals(); }, 0 );
741 params.treeitem_node = treeitem;
745 '_refresh_row_in_tree' : function (params) {
749 if (typeof params.row == 'undefined') throw('util.list.refresh_row: Object must contain a row');
750 if (typeof params.treeitem_node == 'undefined') throw('util.list.refresh_row: Object must contain a treeitem_node');
751 if (params.treeitem_node.nodeName != 'treeitem') throw('util.list.refresh_rwo: treeitem_node must be a treeitem');
753 var s = ('util.list.refresh_row: params = ' + (params) + '\n');
755 var treeitem = params.treeitem_node;
756 treeitem.setAttribute('retrieve_id',params.retrieve_id);
757 if (typeof params.to_bottom != 'undefined') {
758 if (typeof params.no_auto_select == 'undefined') {
759 if (!obj.auto_select_pending) {
760 obj.auto_select_pending = true;
761 setTimeout(function() {
762 dump('auto-selecting\n');
763 var idx = Number(obj.node.view.rowCount)-1;
764 try { obj.node.view.selection.select(idx); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); }
765 try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); }
766 obj.auto_select_pending = false;
767 try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(idx).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); }
772 //var delete_me = [];
773 //for (var i in treeitem.childNodes) if (treeitem.childNodes[i].nodeName == 'treerow') delete_me.push(treeitem.childNodes[i]);
774 //for (var i = 0; i < delete_me.length; i++) treeitem.removeChild(delete_me[i]);
775 var prev_treerow = treeitem.firstChild; /* FIXME: worry about hierarchal lists like copy_browser? */
776 var treerow = document.createElement('treerow');
777 while (prev_treerow.firstChild) {
778 treerow.appendChild( prev_treerow.removeChild( prev_treerow.firstChild ) );
780 treeitem.replaceChild( treerow, prev_treerow );
781 treerow.setAttribute('retrieve_id',params.retrieve_id);
782 if (params.row_properties) treerow.setAttribute('properties',params.row_properties);
784 s += ('tree = ' + this.node.nodeName + '\n');
785 s += ('treeitem = ' + treeitem.nodeName + ' treerow = ' + treerow.nodeName + '\n');
787 obj.put_retrieving_label(treerow);
789 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
791 s += 'found a retrieve_row function\n';
793 treerow.addEventListener(
797 if (treerow.getAttribute('retrieved') == 'true') return; /* already running */
799 treerow.setAttribute('retrieved','true');
801 //dump('fleshing = ' + params.retrieve_id + '\n');
803 function inc_fleshed() {
804 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
805 treerow.setAttribute('fleshed','true');
806 obj.row_count.fleshed++;
807 if (obj.row_count.fleshed >= obj.row_count.total) {
808 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
812 params.treeitem_node = treeitem;
813 params.on_retrieve = function(p) {
816 obj._map_row_to_treecell(p,treerow);
818 var idx = obj.node.contentView.getIndexOfItem( params.treeitem_node );
819 dump('idx = ' + idx + '\n');
820 // if current row is selected, send another select event to re-sync data that the client code fetches on selects
821 if ( obj.node.view.selection.isSelected( idx ) ) {
822 dump('dispatching select event for on_retrieve for idx = ' + idx + '\n');
823 util.widgets.dispatch('select',obj.node);
826 // Let's not alert on this for now. Getting contentView has no properties in record buckets under certain conditions
827 dump('fixme2: ' + E + '\n');
831 if (typeof params.retrieve_row == 'function') {
833 params.retrieve_row( params );
835 } else if (typeof obj.retrieve_row == 'function') {
837 obj.retrieve_row( params );
843 obj.refresh_ordinals();
847 if (typeof params.flesh_immediately != 'undefined') {
848 if (params.flesh_immediately) {
851 util.widgets.dispatch('flesh',treerow);
859 s += 'did not find a retrieve_row function\n';
861 treerow.addEventListener(
864 //dump('fleshing anon\n');
865 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
866 obj._map_row_to_treecell(params,treerow);
867 treerow.setAttribute('retrieved','true');
868 treerow.setAttribute('fleshed','true');
869 obj.row_count.fleshed++;
870 if (obj.row_count.fleshed >= obj.row_count.total) {
871 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
873 obj.refresh_ordinals();
877 if (typeof params.flesh_immediately != 'undefined') {
878 if (params.flesh_immediately) {
881 util.widgets.dispatch('flesh',treerow);
891 if (obj.trim_list && obj.row_count.total >= obj.trim_list) {
893 //if (typeof params.to_bottom != 'undefined')
894 if (typeof params.to_top == 'undefined') {
895 treechildren_node.removeChild( treechildren_node.firstChild );
897 treechildren_node.removeChild( treechildren_node.lastChild );
903 setTimeout( function() { obj.auto_retrieve(); obj.refresh_ordinals(); }, 0 );
905 JSAN.use('util.widgets'); util.widgets.dispatch('select',obj.node);
907 this.error.sdump('D_LIST',s);
912 'refresh_ordinals' : function() {
915 if (obj.refresh_ordinals_timeout_id) { return; }
917 function _refresh_ordinals(clear) {
918 var nl = obj.node.getElementsByAttribute('label','_');
919 for (var i = 0; i < nl.length; i++) {
924 nl[i].setAttribute( // treecell properties for css styling
929 nl = obj.node.getElementsByAttribute('ord_col','true');
930 for (var i = 0; i < nl.length; i++) {
933 // we could just use 'i' here if we trust the order of elements
934 1 + obj.node.contentView.getIndexOfItem(nl[i].parentNode.parentNode) // treeitem
937 if (clear) { obj.refresh_ordinals_timeout_id = null; }
940 // spamming this to cover race conditions
941 setTimeout(_refresh_ordinals, 500); // for speedy looking UI updates
942 setTimeout(_refresh_ordinals, 2000); // for most uses
943 obj.refresh_ordinals_timeout_id = setTimeout(
945 _refresh_ordinals(true);
947 4000 // just in case, say with a slow rendering list
951 alert('Error in list.js, refresh_ordinals(): ' + E);
955 'put_retrieving_label' : function(treerow) {
958 for (var i = 0; i < obj.columns.length; i++) {
960 if (typeof treerow.childNodes[i] == 'undefined') {
961 treecell = document.createElement('treecell');
962 treerow.appendChild(treecell);
964 treecell = treerow.childNodes[i];
966 treecell.setAttribute('label',document.getElementById('offlineStrings').getString('list.row_retrieving'));
969 alert('Error in list.js, put_retrieving_label(): ' + E);
973 'detect_visible' : function() {
976 //dump('detect_visible obj.node = ' + obj.node + '\n');
977 /* FIXME - this is a hack.. if the implementation of tree changes, this could break */
979 /*var s = ''; var A = document.getAnonymousNodes(obj.node);
982 s += '\t' + (typeof B.nodeName != 'undefined' ? B.nodeName : B ) + '\n';
983 if (typeof B.childNodes != 'undefined') for (var j = 0; j < B.childNodes.length; j++) {
984 var C = B.childNodes[j];
985 s += '\t\t' + C.nodeName + '\n';
988 obj.error.sdump('D_XULRUNNER','document.getAnonymousNodes(' + obj.node.nodeName + ') = \n' + s + '\n');*/
989 var scrollbar = document.getAnonymousNodes(obj.node)[2].firstChild;
990 var curpos = scrollbar.getAttribute('curpos');
991 var maxpos = scrollbar.getAttribute('maxpos');
992 //alert('curpos = ' + curpos + ' maxpos = ' + maxpos + ' obj.curpos = ' + obj.curpos + ' obj.maxpos = ' + obj.maxpos + '\n');
993 if ((curpos != obj.curpos) || (maxpos != obj.maxpos)) {
994 if ( obj.auto_retrieve() > 0 ) {
995 obj.curpos = curpos; obj.maxpos = maxpos;
999 obj.error.sdump('D_XULRUNNER', 'List implementation changed? ' + E);
1001 } catch(E) { obj.error.sdump('D_ERROR',E); }
1004 'detect_visible_polling' : function() {
1006 //alert('detect_visible_polling');
1008 obj.detect_visible();
1009 setTimeout(function() { try { obj.detect_visible_polling(); } catch(E) { alert(E); } },2000);
1016 'auto_retrieve' : function(params) {
1018 switch (this.node.nodeName) {
1019 case 'tree' : obj._auto_retrieve_tree(params); break;
1020 default: throw('NYI: Need .auto_retrieve() for ' + obj.node.nodeName); break;
1024 '_auto_retrieve_tree' : function (params) {
1026 if (!obj.auto_retrieve_in_progress) {
1027 obj.auto_retrieve_in_progress = true;
1031 //alert('auto_retrieve\n');
1033 var startpos = obj.node.treeBoxObject.getFirstVisibleRow();
1034 var endpos = obj.node.treeBoxObject.getLastVisibleRow();
1035 if (startpos > endpos) endpos = obj.node.treeBoxObject.getPageLength();
1036 //dump('startpos = ' + startpos + ' endpos = ' + endpos + '\n');
1037 for (var i = startpos; i < endpos + 4; i++) {
1039 //dump('trying index ' + i + '\n');
1040 var item = obj.node.contentView.getItemAtIndex(i).firstChild;
1041 if (item && item.getAttribute('retrieved') != 'true' ) {
1042 //dump('\tgot an unfleshed item = ' + item + ' = ' + item.nodeName + '\n');
1043 util.widgets.dispatch('flesh',item); count++;
1046 //dump(i + ' : ' + E + '\n');
1049 obj.auto_retrieve_in_progress = false;
1051 } catch(E) { alert(E); }
1057 'exec_on_all_fleshed' : function() {
1060 if (obj.on_all_fleshed) {
1061 if (typeof obj.on_all_fleshed == 'function') {
1062 dump('exec_on_all_fleshed == function\n');
1065 try { obj.on_all_fleshed(); } catch(E) { obj.error.standard_unexpected_error_alert('_full_retrieve_tree callback',obj.on_all_fleshed); }
1068 } else if (typeof obj.on_all_fleshed.length != 'undefined') {
1069 dump('exec_on_all_fleshed == array\n');
1073 dump('exec_on_all_fleshed, processing on_all_fleshed array, length = ' + obj.on_all_fleshed.length + '\n');
1074 var f = obj.on_all_fleshed.pop();
1075 if (typeof f == 'function') {
1076 try { f(); } catch(E) { obj.error.standard_unexpected_error_alert('_full_retrieve_tree callback',E); }
1078 if (obj.on_all_fleshed.length > 0) arguments.callee();
1080 obj.error.standard_unexpected_error_alert('exec_on_all_fleshed callback error',E);
1085 obj.error.standard_unexpected_error_alert('unexpected on_all_fleshed object: ', obj.on_all_fleshed);
1089 obj.error.standard_unexpected_error_alert('exec_on_all-fleshed error',E);
1093 'full_retrieve' : function(params) {
1095 switch (this.node.nodeName) {
1096 case 'tree' : obj._full_retrieve_tree(params); break;
1097 default: throw('NYI: Need .full_retrieve() for ' + obj.node.nodeName); break;
1099 obj.refresh_ordinals();
1102 '_full_retrieve_tree' : function(params) {
1105 if (obj.row_count.fleshed >= obj.row_count.total) {
1106 dump('Full retrieve... tree seems to be in sync\n' + js2JSON(obj.row_count) + '\n');
1107 obj.exec_on_all_fleshed();
1109 dump('Full retrieve... syncing tree' + js2JSON(obj.row_count) + '\n');
1110 JSAN.use('util.widgets');
1111 var nodes = obj.treechildren.childNodes;
1112 for (var i = 0; i < nodes.length; i++) {
1113 util.widgets.dispatch('flesh',nodes[i].firstChild);
1117 obj.error.standard_unexpected_error_alert('_full_retrieve_tree',E);
1121 '_append_to_listbox' : function (params) {
1125 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
1127 var s = ('util.list.append: params = ' + (params) + '\n');
1129 var listitem = document.createElement('listitem');
1131 s += ('listbox = ' + this.node + ' listitem = ' + listitem + '\n');
1133 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
1137 listitem.setAttribute('retrieve_id',params.retrieve_id);
1138 //FIXME//Make async and fire when row is visible in list
1141 params.treeitem_node = listitem;
1142 params.on_retrieve = function(row) {
1144 obj._map_row_to_listcell(params,listitem);
1145 obj.node.appendChild( listitem );
1146 util.widgets.dispatch('select',obj.node);
1149 if (typeof params.retrieve_row == 'function') {
1151 row = params.retrieve_row( params );
1155 if (typeof obj.retrieve_row == 'function') {
1157 row = obj.retrieve_row( params );
1164 this._map_row_to_listcell(params,listitem);
1165 this.node.appendChild( listitem );
1168 this.error.sdump('D_LIST',s);
1169 params.treeitem_node = listitem;
1174 '_map_row_to_treecell' : function(params,treerow) {
1178 if (typeof params.map_row_to_column == 'function' || typeof this.map_row_to_column == 'function') {
1180 for (var i = 0; i < this.columns.length; i++) {
1182 if (typeof treerow.childNodes[i] == 'undefined') {
1183 treecell = document.createElement('treecell');
1184 treerow.appendChild( treecell );
1186 treecell = treerow.childNodes[i];
1189 if ( this.columns[i].editable == false ) { treecell.setAttribute('editable','false'); }
1191 var sort_value = '';
1193 // What skip columns is doing is rendering the treecells as blank/empty
1194 if (params.skip_columns && (params.skip_columns.indexOf(i) != -1)) {
1195 treecell.setAttribute('label',label);
1196 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
1199 if (params.skip_all_columns_except && (params.skip_all_columns_except.indexOf(i) == -1)) {
1200 treecell.setAttribute('label',label);
1201 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
1205 if (typeof params.map_row_to_column == 'function') {
1207 label = params.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1209 } else if (typeof this.map_row_to_column == 'function') {
1211 label = this.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1214 if (this.columns[i].type == 'checkbox') { treecell.setAttribute('value',label); } else { treecell.setAttribute('label',label ? label : ''); }
1215 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
1217 } else if (typeof params.map_row_to_columns == 'function' || typeof this.map_row_to_columns == 'function') {
1220 var sort_values = [];
1222 if (typeof params.map_row_to_columns == 'function') {
1224 var values = params.map_row_to_columns(params.row,this.columns,this.scratch_data);
1225 if (typeof values.values == 'undefined') {
1228 labels = values.values;
1229 sort_values = values.sort_values;
1232 } else if (typeof this.map_row_to_columns == 'function') {
1234 var values = this.map_row_to_columns(params.row,this.columns,this.scratch_data);
1235 if (typeof values.values == 'undefined') {
1238 labels = values.values;
1239 sort_values = values.sort_values;
1242 for (var i = 0; i < labels.length; i++) {
1244 if (typeof treerow.childNodes[i] == 'undefined') {
1245 treecell = document.createElement('treecell');
1246 treerow.appendChild(treecell);
1248 treecell = treerow.childNodes[i];
1250 if ( this.columns[i].editable == false ) { treecell.setAttribute('editable','false'); }
1251 if ( this.columns[i].type == 'checkbox') {
1252 treecell.setAttribute('value', labels[i]);
1254 treecell.setAttribute('label',typeof labels[i] == 'string' || typeof labels[i] == 'number' ? labels[i] : '');
1256 if (sort_values[i]) {
1257 treecell.setAttribute('sort_value',js2JSON(sort_values[i]));
1259 s += ('treecell = ' + treecell + ' with label = ' + labels[i] + '\n');
1264 throw('No row to column mapping function.');
1266 this.error.sdump('D_LIST',s);
1269 '_map_row_to_listcell' : function(params,listitem) {
1272 for (var i = 0; i < this.columns.length; i++) {
1274 if (typeof params.map_row_to_column == 'function') {
1276 value = params.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1280 if (typeof this.map_row_to_column == 'function') {
1282 value = this.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1285 if (typeof value == 'string' || typeof value == 'number') {
1286 var listcell = document.createElement('listcell');
1287 listcell.setAttribute('label',value);
1288 listitem.appendChild(listcell);
1289 s += ('listcell = ' + listcell + ' with label = ' + value + '\n');
1291 listitem.appendChild(value);
1292 s += ('listcell = ' + value + ' is really a ' + value.nodeName + '\n');
1295 this.error.sdump('D_LIST',s);
1298 'select_all' : function(params) {
1300 switch(this.node.nodeName) {
1301 case 'tree' : return this._select_all_from_tree(params); break;
1302 default: throw('NYI: Need ._select_all_from_() for ' + this.node.nodeName); break;
1306 '_select_all_from_tree' : function(params) {
1308 this.node.view.selection.selectAll();
1311 'retrieve_selection' : function(params) {
1313 switch(this.node.nodeName) {
1314 case 'tree' : return this._retrieve_selection_from_tree(params); break;
1315 default: throw('NYI: Need ._retrieve_selection_from_() for ' + this.node.nodeName); break;
1319 '_retrieve_selection_from_tree' : function(params) {
1322 var start = new Object();
1323 var end = new Object();
1324 var numRanges = this.node.view.selection.getRangeCount();
1325 for (var t=0; t<numRanges; t++){
1326 this.node.view.selection.getRangeAt(t,start,end);
1327 for (var v=start.value; v<=end.value; v++){
1328 var i = this.node.contentView.getItemAtIndex(v);
1335 'dump' : function(params) {
1337 switch(this.node.nodeName) {
1338 case 'tree' : return this._dump_tree(params); break;
1339 default: throw('NYI: Need .dump() for ' + this.node.nodeName); break;
1343 '_dump_tree' : function(params) {
1346 for (var i = 0; i < this.treechildren.childNodes.length; i++) {
1348 var treeitem = this.treechildren.childNodes[i];
1349 var treerow = treeitem.firstChild;
1350 for (var j = 0; j < treerow.childNodes.length; j++) {
1351 row.push( treerow.childNodes[j].getAttribute('label') );
1358 'dump_with_keys' : function(params) {
1360 switch(this.node.nodeName) {
1361 case 'tree' : return this._dump_tree_with_keys(params); break;
1362 default: throw('NYI: Need .dump_with_keys() for ' + this.node.nodeName); break;
1367 '_dump_tree_with_keys' : function(params) {
1371 function process_tree(treechildren) {
1372 for (var i = 0; i < treechildren.childNodes.length; i++) {
1374 var treeitem = treechildren.childNodes[i];
1375 var treerow = treeitem.firstChild;
1376 for (var j = 0; j < treerow.childNodes.length; j++) {
1377 if (typeof obj.columns[j] == 'undefined') {
1378 dump('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n');
1379 dump('_dump_tree_with_keys @ ' + location.href + '\n');
1380 dump('\ttreerow.childNodes.length='+treerow.childNodes.length+' j='+j+' obj.columns.length='+obj.columns.length+'\n');
1383 row[ obj.columns[j].id ] = treerow.childNodes[j].getAttribute('label');
1384 var sort = treerow.childNodes[j].getAttribute('sort_value');
1386 row[ obj.columns[j].id + '_sort_value' ] = sort;
1391 if (treeitem.childNodes.length > 1) {
1392 process_tree(treeitem.lastChild);
1397 process_tree(this.treechildren);
1402 'dump_csv' : function(params) {
1404 switch(this.node.nodeName) {
1405 case 'tree' : return this._dump_tree_csv(params); break;
1406 default: throw('NYI: Need .dump_csv() for ' + this.node.nodeName); break;
1411 '_dump_tree_csv' : function(params) {
1415 for (var j = 0; j < obj.columns.length; j++) {
1416 if (obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('hidden') == 'true') {
1419 ord_cols.push( [ obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('ordinal'), j ] );
1422 ord_cols.sort( function(a,b) {
1423 if ( Number( a[0] ) < Number( b[0] ) ) return -1;
1424 if ( Number( a[0] ) > Number( b[0] ) ) return 1;
1427 for (var j = 0; j < ord_cols.length; j++) {
1428 if (_dump) _dump += ',';
1429 _dump += '"' + obj.columns[ ord_cols[j][1] ].label.replace(/"/g, '""') + '"';
1433 function process_tree(treechildren) {
1434 for (var i = 0; i < treechildren.childNodes.length; i++) {
1436 var treeitem = treechildren.childNodes[i];
1437 var treerow = treeitem.firstChild;
1438 for (var j = 0; j < ord_cols.length; j++) {
1439 if (row) row += ',';
1440 row += '"' + treerow.childNodes[ ord_cols[j][1] ].getAttribute('label').replace(/"/g, '""') + '"';
1442 _dump += row + '\r\n';
1443 if (treeitem.childNodes.length > 1) {
1444 process_tree(treeitem.lastChild);
1449 process_tree(this.treechildren);
1454 'dump_extended_format' : function(params) {
1456 switch(this.node.nodeName) {
1457 case 'tree' : return this._dump_tree_extended_format(params); break;
1458 default: throw('NYI: Need .dump_extended_format() for ' + this.node.nodeName); break;
1463 '_dump_tree_extended_format' : function(params) {
1467 for (var j = 0; j < obj.columns.length; j++) {
1468 if (obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('hidden') == 'true') {
1471 ord_cols.push( [ obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('ordinal'), j ] );
1474 ord_cols.sort( function(a,b) {
1475 if ( Number( a[0] ) < Number( b[0] ) ) return -1;
1476 if ( Number( a[0] ) > Number( b[0] ) ) return 1;
1480 function process_tree(treechildren) {
1481 for (var i = 0; i < treechildren.childNodes.length; i++) {
1482 var row = document.getElementById('offlineStrings').getString('list.dump_extended_format.record_separator') + '\r\n';
1483 var treeitem = treechildren.childNodes[i];
1484 var treerow = treeitem.firstChild;
1485 for (var j = 0; j < ord_cols.length; j++) {
1486 row += obj.columns[ ord_cols[j][1] ].label + ': ' + treerow.childNodes[ ord_cols[j][1] ].getAttribute('label') + '\r\n';
1488 _dump += row + '\r\n';
1489 if (treeitem.childNodes.length > 1) {
1490 process_tree(treeitem.lastChild);
1495 process_tree(this.treechildren);
1500 'dump_csv_to_clipboard' : function(params) {
1502 if (typeof params == 'undefined') params = {};
1503 if (params.no_full_retrieve) {
1504 copy_to_clipboard( obj.dump_csv( params ) );
1506 obj.wrap_in_full_retrieve( function() { copy_to_clipboard( obj.dump_csv( params ) ); } );
1510 'dump_csv_to_printer' : function(params) {
1512 if (typeof params == 'undefined') params = {};
1513 JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context);
1514 if (params.no_full_retrieve) {
1515 print.simple( obj.dump_csv( params ), {'content_type':'text/plain'} );
1517 obj.wrap_in_full_retrieve(
1519 print.simple( obj.dump_csv( params ), {'content_type':'text/plain'} );
1525 'dump_extended_format_to_printer' : function(params) {
1527 if (typeof params == 'undefined') params = {};
1528 JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context);
1529 if (params.no_full_retrieve) {
1530 print.simple( obj.dump_extended_format( params ), {'content_type':'text/plain'} );
1532 obj.wrap_in_full_retrieve(
1534 print.simple( obj.dump_extended_format( params ), {'content_type':'text/plain'} );
1540 'dump_csv_to_file' : function(params) {
1542 JSAN.use('util.file'); var f = new util.file();
1543 if (typeof params == 'undefined') params = {};
1544 if (params.no_full_retrieve) {
1545 params.data = obj.dump_csv( params );
1546 params.not_json = true;
1547 if (!params.title) params.title = document.getElementById('offlineStrings').getString('list.save_csv_as');
1548 f.export_file( params );
1550 obj.wrap_in_full_retrieve(
1552 params.data = obj.dump_csv( params );
1553 params.not_json = true;
1554 if (!params.title) params.title = document.getElementById('offlineStrings').getString('list.save_csv_as');
1555 f.export_file( params );
1561 'print' : function(params) {
1562 if (!params) params = {};
1563 switch(this.node.nodeName) {
1564 case 'tree' : return this._print_tree(params); break;
1565 default: throw('NYI: Need ._print() for ' + this.node.nodeName); break;
1569 '_print_tree' : function(params) {
1572 var data = obj.data; data.stash_retrieve();
1573 if (!params.staff && data.list.au && data.list.au[0]) {
1574 params.staff = data.list.au[0];
1576 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() ]) {
1577 params.lib = JSON2js( js2JSON( data.hash.aou[ data.list.au[0].ws_ou() ] ) ); // clone this sucker
1578 params.lib.children(null); // since we're modifying it
1580 if (params.template && data.print_list_templates[ params.template ]) {
1581 var template = data.print_list_templates[ params.template ];
1582 if (template.inherit) {
1583 template = data.print_list_templates[ template.inherit ];
1584 // if someone wants to implement recursion later, feel free
1586 for (var i in template) params[i] = template[i];
1588 obj.wrap_in_full_retrieve(
1591 if (!params.list) params.list = obj.dump_with_keys();
1592 JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context);
1593 print.tree_list( params );
1594 if (typeof params.callback == 'function') params.callback();
1596 obj.error.standard_unexpected_error_alert('inner _print_tree',E);
1602 obj.error.standard_unexpected_error_alert('_print_tree',E);
1606 'dump_selected_with_keys' : function(params) {
1608 switch(this.node.nodeName) {
1609 case 'tree' : return this._dump_tree_selection_with_keys(params); break;
1610 default: throw('NYI: Need .dump_selection_with_keys() for ' + this.node.nodeName); break;
1615 '_dump_tree_selection_with_keys' : function(params) {
1618 var list = obj._retrieve_selection_from_tree();
1619 for (var i = 0; i < list.length; i++) {
1621 var treeitem = list[i];
1622 var treerow = treeitem.firstChild;
1623 for (var j = 0; j < treerow.childNodes.length; j++) {
1624 var value = treerow.childNodes[j].getAttribute('label');
1625 if (params.skip_hidden_columns) if (obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('hidden') == 'true') continue;
1626 if (typeof obj.columns[j] == 'undefined') {
1627 dump('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n');
1628 dump('_dump_tree_selection_with_keys @ ' + location.href + '\n');
1629 dump('\ttreerow.childNodes.length='+treerow.childNodes.length+' j='+j+' obj.columns.length='+obj.columns.length+'\n');
1632 var id = obj.columns[j].id; if (params.labels_instead_of_ids) id = obj.columns[j].label;
1641 'clipboard' : function(params) {
1644 var dump = obj.dump_selected_with_keys({'skip_hidden_columns':true,'labels_instead_of_ids':true});
1645 obj.data.stash_retrieve();
1646 obj.data.list_clipboard = dump; obj.data.stash('list_clipboard');
1647 JSAN.use('util.window'); var win = new util.window();
1648 win.open(urls.XUL_LIST_CLIPBOARD,'list_clipboard','chrome,resizable,modal');
1649 window.focus(); // sometimes the main window will lower after a clipboard action
1651 this.error.standard_unexpected_error_alert('clipboard',E);
1655 'dump_retrieve_ids' : function(params) {
1657 switch(this.node.nodeName) {
1658 case 'tree' : return this._dump_retrieve_ids_tree(params); break;
1659 default: throw('NYI: Need .dump_retrieve_ids() for ' + this.node.nodeName); break;
1663 '_dump_retrieve_ids_tree' : function(params) {
1666 for (var i = 0; i < this.treechildren.childNodes.length; i++) {
1667 var treeitem = this.treechildren.childNodes[i];
1668 dump.push( treeitem.getAttribute('retrieve_id') );
1673 'wrap_in_full_retrieve' : function(f) {
1675 if (typeof obj.on_all_fleshed == 'function') { // legacy
1676 obj.on_all_fleshed = [ obj.on_all_fleshed ];
1678 if (! obj.on_all_fleshed) obj.on_all_fleshed = [];
1679 obj.on_all_fleshed.push(f);
1680 obj.full_retrieve();
1683 '_sort_tree' : function() {
1686 if (obj.node.getAttribute('no_sort')) {
1690 var sorts = [ obj.first_sort ].concat( obj.sub_sorts );
1691 var columns = util.functional.map_list(
1697 var column_positions = [];
1698 for (var i = 0; i < columns.length; i++) {
1699 for (var j = 0; j < obj.columns.length; j++) {
1700 if (obj.columns[j].id == columns[i].id) {
1701 column_positions.push( function(a){return a;}(j) );
1705 obj.wrap_in_full_retrieve(
1708 JSAN.use('util.money');
1710 var treeitems = obj.treechildren.childNodes;
1711 for (var i = 0; i < treeitems.length; i++) {
1712 var treeitem = treeitems[i];
1713 var treerow = treeitem.firstChild;
1715 function get_value(treecell) {
1718 ? treecell.getAttribute('label')
1720 'sort_value' : treecell ? treecell.hasAttribute('sort_value')
1722 treecell.getAttribute('sort_value'))
1729 for (var j = 0; j < column_positions.length; j++) {
1730 var treecell = treerow.childNodes[ column_positions[j] ];
1732 'position' : column_positions[j],
1733 'value' : get_value(treecell)
1742 rows = rows.sort( function(A,B) {
1743 function normalize(a,b,p) {
1750 if (obj.columns[p].sort_type) {
1751 switch(obj.columns[p].sort_type) {
1753 JSAN.use('util.date'); // to pull in dojo.date.locale
1754 a = dojo.date.locale.parse(a,{});
1755 b = dojo.date.locale.parse(b,{});
1758 a = Number(a); b = Number(b);
1761 a = util.money.dollars_float_to_cents_integer(a);
1762 b = util.money.dollars_float_to_cents_integer(b);
1764 case 'title' : /* special case for "a" and "the". doesn't use marc 245 indicator */
1765 a = String( a ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
1766 b = String( b ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
1769 a = String( a ).toUpperCase();
1770 b = String( b ).toUpperCase();
1774 if (typeof a == 'string' || typeof b == 'string') {
1775 a = String( a ).toUpperCase();
1776 b = String( b ).toUpperCase();
1783 for (var i = 0; i < sorts.length; i++) {
1785 if (sorts[i].sortDir == 'asc') {
1787 A['values'][i]['value'],
1788 B['values'][i]['value'],
1789 A['values'][i]['position']
1793 B['values'][i]['value'],
1794 A['values'][i]['value'],
1795 A['values'][i]['position']
1798 if (values[0] < values[1] ) {
1801 if (values[0] > values[1] ) {
1807 while(obj.treechildren.lastChild) obj.treechildren.removeChild( obj.treechildren.lastChild );
1808 for (var i = 0; i < rows.length; i++) {
1809 obj.treechildren.appendChild( rows[i].node );
1811 if (typeof obj.on_sort == 'function') obj.on_sort();
1813 obj.error.standard_unexpected_error_alert('sorting',E);
1815 obj.refresh_ordinals();
1819 obj.error.standard_unexpected_error_alert('pre sorting', E);
1823 '_toggle_checkbox_column' : function(col,toggle) {
1826 if (obj.node.getAttribute('no_toggle')) {
1830 for (var i = 0; i < obj.columns.length; i++) {
1831 if (obj.columns[i].id == col.id) col_pos = function(a){return a;}(i);
1833 var treeitems = obj.treechildren.childNodes;
1834 for (var i = 0; i < treeitems.length; i++) {
1835 var treeitem = treeitems[i];
1836 var treerow = treeitem.firstChild;
1837 var treecell = treerow.childNodes[ col_pos ];
1838 treecell.setAttribute('value',(toggle == 'on'));
1840 if (typeof obj.on_checkbox_toggle == 'function') obj.on_checkbox_toggle(toggle);
1842 obj.error.standard_unexpected_error_alert('pre toggle', E);
1846 'render_list_actions' : function(params) {
1848 switch(this.node.nodeName) {
1849 case 'tree' : return this._render_list_actions_for_tree(params); break;
1850 default: throw('NYI: Need ._render_list_actions() for ' + this.node.nodeName); break;
1854 '_render_list_actions_for_tree' : function(params) {
1857 var btn = document.createElement('button');
1858 btn.setAttribute('id',obj.node.id + '_list_actions');
1859 btn.setAttribute('type','menu');
1860 btn.setAttribute('allowevents','true');
1861 //btn.setAttribute('oncommand','this.firstChild.showPopup();');
1862 btn.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.menu.label'));
1863 btn.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.menu.accesskey'));
1864 var mp = document.createElement('menupopup');
1865 btn.appendChild(mp);
1866 var mi = document.createElement('menuitem');
1867 mi.setAttribute('id',obj.node.id + '_clipfield');
1868 mi.setAttribute('disabled','true');
1869 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.field_to_clipboard.label'));
1870 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.field_to_clipboard.accesskey'));
1872 mi = document.createElement('menuitem');
1873 mi.setAttribute('id',obj.node.id + '_csv_to_clipboard');
1874 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_clipboard.label'));
1875 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_clipboard.accesskey'));
1877 mi = document.createElement('menuitem');
1878 mi.setAttribute('id',obj.node.id + '_csv_to_printer');
1879 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_printer.label'));
1880 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_printer.accesskey'));
1882 mi = document.createElement('menuitem');
1883 mi.setAttribute('id',obj.node.id + '_extended_to_printer');
1884 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.extended_to_printer.label'));
1885 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.extended_to_printer.accesskey'));
1887 mi = document.createElement('menuitem');
1888 mi.setAttribute('id',obj.node.id + '_csv_to_file');
1889 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_file.label'));
1890 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_file.accesskey'));
1892 mi = document.createElement('menuitem');
1893 mi.setAttribute('id',obj.node.id + '_save_columns');
1894 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.save_column_configuration.label'));
1895 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.save_column_configuration.accesskey'));
1896 if (obj.data.hash.aous['gui.disable_local_save_columns']) {
1897 mi.setAttribute('disabled','true');
1902 obj.error.standard_unexpected_error_alert('rendering list actions',E);
1906 'set_list_actions' : function(params) {
1908 switch(this.node.nodeName) {
1909 case 'tree' : return this._set_list_actions_for_tree(params); break;
1910 default: throw('NYI: Need ._set_list_actions() for ' + this.node.nodeName); break;
1914 '_set_list_actions_for_tree' : function(params) {
1915 // This should be called after the button element from render_list_actions has been appended to the DOM
1918 var x = document.getElementById(obj.node.id + '_clipfield');
1923 obj.clipboard(params);
1924 if (params && typeof params.on_complete == 'function') {
1925 params.on_complete(params);
1931 x = document.getElementById(obj.node.id + '_csv_to_clipboard');
1936 obj.dump_csv_to_clipboard(params);
1937 if (params && typeof params.on_complete == 'function') {
1938 params.on_complete(params);
1944 x = document.getElementById(obj.node.id + '_csv_to_printer');
1949 obj.dump_csv_to_printer(params);
1950 if (params && typeof params.on_complete == 'function') {
1951 params.on_complete(params);
1957 x = document.getElementById(obj.node.id + '_extended_to_printer');
1962 obj.dump_extended_format_to_printer(params);
1963 if (params && typeof params.on_complete == 'function') {
1964 params.on_complete(params);
1971 x = document.getElementById(obj.node.id + '_csv_to_file');
1976 obj.dump_csv_to_file(params);
1977 if (params && typeof params.on_complete == 'function') {
1978 params.on_complete(params);
1984 x = document.getElementById(obj.node.id + '_save_columns');
1989 obj.save_columns(params);
1990 if (params && typeof params.on_complete == 'function') {
1991 params.on_complete(params);
1999 obj.error.standard_unexpected_error_alert('setting list actions',E);
2003 // Takes fieldmapper class name and attempts to spit out column definitions suitable for .init
2004 'fm_columns' : function(hint,column_extras,prefix) {
2007 if (!prefix) { prefix = ''; }
2009 // requires the dojo library fieldmapper.autoIDL
2010 if (typeof fieldmapper == 'undefined') { throw 'fieldmapper undefined'; }
2011 if (typeof fieldmapper.IDL == 'undefined') { throw 'fieldmapper.IDL undefined'; }
2012 if (typeof fieldmapper.IDL.fmclasses == 'undefined') { throw 'fieldmapper.IDL.fmclasses undefined'; }
2013 if (typeof fieldmapper.IDL.fmclasses[hint] == 'undefined') { throw 'fieldmapper.IDL.fmclasses.' + hint + ' undefined'; }
2014 var my_class = fieldmapper.IDL.fmclasses[hint];
2015 var data = obj.data; data.stash_retrieve();
2017 function col_def(my_field) {
2018 var col_id = prefix + hint + '_' + my_field.name;
2020 var datafield = my_field.name;
2021 var fleshed_display_field;
2022 if (column_extras) {
2023 if (column_extras['*']) {
2024 if (column_extras['*']['dataobj']) {
2025 dataobj = column_extras['*']['dataobj'];
2028 if (column_extras[col_id]) {
2029 if (column_extras[col_id]['dataobj']) {
2030 dataobj = column_extras[col_id]['dataobj'];
2032 if (column_extras[col_id]['datafield']) {
2033 datafield = column_extras[col_id]['datafield'];
2035 if (column_extras[col_id]['fleshed_display_field']) {
2036 fleshed_display_field = column_extras[col_id]['fleshed_display_field'];
2042 'label' : my_field.label || my_field.name,
2043 'sort_type' : [ 'int', 'float', 'id', 'number' ].indexOf(my_field.datatype) > -1 ? 'number' :
2044 ( my_field.datatype == 'money' ? 'money' :
2045 ( my_field.datatype == 'timestamp' ? 'date' : 'default')),
2046 'hidden' : my_field.virtual || my_field.datatype == 'link',
2049 // my_field.datatype => bool float id int interval link money number org_unit text timestamp
2050 if (my_field.datatype == 'link') {
2051 def.render = function(my) {
2052 // is the object fleshed?
2053 return my[dataobj][datafield]() && typeof my[dataobj][datafield]() == 'object'
2054 // yes, show the display field
2055 ? my[dataobj][datafield]()[fleshed_display_field||my_field.key]()
2056 // no, do we have its class in data.hash?
2057 : ( typeof data.hash[ my[dataobj].Structure.field_map[datafield].class ] != 'undefined'
2058 // yes, do we have this particular object cached?
2059 ? ( data.hash[ my[dataobj].Structure.field_map[datafield].class ][ my[dataobj][datafield]() ]
2060 // yes, show the display field
2061 ? data.hash[ my[dataobj].Structure.field_map[datafield].class ][ my[dataobj][datafield]() ][
2062 fleshed_display_field||my_field.key
2064 // no, just show the raw value
2065 : my[dataobj][datafield]()
2067 // no, just show the raw value
2068 : my[dataobj][datafield]()
2072 def.render = function(my) { return my[dataobj][datafield](); }
2074 if (my_field.datatype == 'timestamp') {
2075 JSAN.use('util.date');
2076 def.render = function(my) {
2077 return util.date.formatted_date( my[dataobj][datafield](), '%{localized}' );
2079 def.sort_value = function(my) {
2080 return util.date.db_date2Date( my[dataobj][datafield]() ).getTime();
2083 if (my_field.datatype == 'org_unit') {
2084 def.render = function(my) {
2085 return typeof my[dataobj][datafield]() == 'object' ? my[dataobj][datafield]().shortname() : data.hash.aou[ my[dataobj][datafield]() ].shortname();
2088 if (my_field.datatype == 'money') {
2089 JSAN.use('util.money');
2090 def.render = function(my) {
2091 return util.money.sanitize( my[dataobj][datafield]() );
2093 def.sort_value = function(my) {
2094 return util.money.dollars_float_to_cents_integer( my[dataobj][datafield]() );
2097 if (column_extras) {
2098 if (column_extras['*']) {
2099 for (var attr in column_extras['*']) {
2100 def[attr] = column_extras['*'][attr];
2102 if (column_extras['*']['expanded_label']) {
2103 def.label = my_class.label + ': ' + def.label;
2105 if (column_extras['*']['label_prefix']) {
2106 def.label = column_extras['*']['label_prefix'] + def.label;
2108 if (column_extras['*']['remove_virtual']) {
2109 if (my_field.virtual) {
2110 def.remove_me = true;
2114 if (column_extras[col_id]) {
2115 for (var attr in column_extras[col_id]) {
2116 def[attr] = column_extras[col_id][attr];
2118 if (column_extras[col_id]['keep_me']) {
2119 def.remove_me = false;
2121 if (column_extras[col_id]['label_prefix']) {
2122 def.label = column_extras[col_id]['label_prefix'] + def.label;
2126 if (def.remove_me) {
2127 dump('Skipping ' + def.label + '\n');
2130 dump('Defining ' + def.label + '\n');
2135 for (var i = 0; i < my_class.fields.length; i++) {
2136 var my_field = my_class.fields[i];
2137 var def = col_def(my_field);
2139 columns.push( def );
2144 obj.error.standard_unexpected_error_alert('fm_columns()',E);
2148 // Default for the map_row_to_columns function for .init
2149 'std_map_row_to_columns' : function(error_value) {
2150 return function(row,cols,scratch) {
2151 // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
2152 // cols contains all of the objects listed above in columns
2153 // scratch is a temporary space shared by all cells/rows (or just per row if not explicitly passed in)
2154 if (!scratch) { scratch = {}; }
2157 JSAN.use('util.error'); obj.error = new util.error();
2158 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
2159 JSAN.use('util.network'); obj.network = new util.network();
2160 JSAN.use('util.money');
2162 // FIXME: backwards compatability with server/patron code and the old patron.util.std_map_row_to_columns.
2163 // Will remove in a separate commit and change all instances of obj.OpenILS.data to obj.data at the same time.
2164 obj.OpenILS = { 'data' : obj.data };
2168 var sort_values = [];
2171 for (var i = 0; i < cols.length; i++) {
2172 switch (typeof cols[i].render) {
2173 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;
2174 case 'string' : cmd += 'try { ' + cols[i].render + '; values['+i+'] = v; } catch(E) { values['+i+'] = error_value; }'; break;
2175 default: cmd += 'values['+i+'] = "??? '+(typeof cols[i].render)+'"; ';
2177 switch (typeof cols[i].sort_value) {
2180 sort_values[i] = cols[i].sort_value(my,scratch);
2182 sort_values[i] = error_value;
2183 obj.error.sdump('D_COLUMN_RENDER_ERROR',E);
2187 sort_values[i] = JSON2js(cols[i].sort_value);
2190 cmd += 'sort_values['+i+'] = values[' + i + '];';
2193 if (cmd) eval( cmd );
2195 obj.error.sdump('D_WARN','map_row_to_column: ' + E);
2196 if (error_value) { value = error_value; } else { value = ' ' };
2198 return { 'values' : values, 'sort_values' : sort_values };
2202 dump('exiting util.list.js\n');