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');
32 util.list.prototype = {
34 'init' : function (params) {
37 obj.scratch_data = {};
39 // If set, save and restore columns as if the tree/list id was the value of columns_saved_under
40 obj.columns_saved_under = params.columns_saved_under;
42 JSAN.use('util.widgets');
44 obj.printer_context = params.printer_context;
46 if (typeof params.map_row_to_column == 'function') obj.map_row_to_column = params.map_row_to_column;
47 if (typeof params.map_row_to_columns == 'function') {
48 obj.map_row_to_columns = params.map_row_to_columns;
50 obj.map_row_to_columns = obj.std_map_row_to_columns();
52 if (typeof params.retrieve_row == 'function') obj.retrieve_row = params.retrieve_row;
55 if (typeof params.prebuilt != 'undefined') obj.prebuilt = params.prebuilt;
57 if (typeof params.columns == 'undefined') throw('util.list.init: No columns');
61 'label' : document.getElementById('offlineStrings').getString('list.line_number'),
64 'properties' : 'ordinal', // column properties for css styling
67 'render' : function(my,scratch) {
68 // special code will handle this based on the attribute we set
69 // here. All cells for this column need to be updated whenever
70 // a list adds, removes, or sorts rows
75 for (var i = 0; i < params.columns.length; i++) {
76 if (typeof params.columns[i] == 'object') {
77 obj.columns.push( params.columns[i] );
79 var cols = obj.fm_columns( params.columns[i] );
80 for (var j = 0; j < cols.length; j++) {
81 obj.columns.push( cols[j] );
86 switch(obj.node.nodeName) {
87 case 'tree' : obj._init_tree(params); break;
88 case 'listbox' : obj._init_listbox(params); break;
89 default: throw('NYI: Need ._init() for ' + obj.node.nodeName); break;
93 '_init_tree' : function (params) {
97 this.treechildren = this.node.lastChild;
100 var treecols = document.createElement('treecols');
101 this.node.appendChild(treecols);
102 this.treecols = treecols;
104 var check_for_id_collisions = {};
105 for (var i = 0; i < this.columns.length; i++) {
106 var treecol = document.createElement('treecol');
107 for (var j in this.columns[i]) {
108 var value = this.columns[i][j];
110 if (typeof check_for_id_collisions[value] == 'undefined') {
111 check_for_id_collisions[value] = true;
113 // Column id's are important for sorting and saving list configuration. Collisions started happening because
114 // we were using field names as id's, and then later combining column definitions for multiple objects that
115 // shared field names. The downside to this sort of automatic collision prevention is that these generated
116 // id's can change as we add and remove columns, possibly breaking saved list configurations.
117 dump('Column collision with id = ' + value + ', renaming to ');
118 value = value + '_collision_' + i;
122 treecol.setAttribute(j,value);
124 treecols.appendChild(treecol);
125 if (this.columns[i].type == 'checkbox') {
126 treecol.addEventListener(
131 var toggle = ev.target.getAttribute('toggleAll') || 'on';
132 if (toggle == 'off') toggle = 'on'; else toggle = 'off';
133 ev.target.setAttribute('toggleAll',toggle);
134 obj._toggle_checkbox_column(ev.target,toggle);
141 treecol.addEventListener(
144 if (ev.target.getAttribute('no_sort')) {
149 if (ev.ctrlKey) { // sub sort
155 'target' : ev.target,
158 } else { // first sort
159 var sortDir = ev.target.getAttribute('sortDir') || 'desc';
160 if (sortDir == 'desc') sortDir = 'asc'; else sortDir = 'desc';
164 ev.target.setAttribute('sortDir',sortDir);
166 'target' : ev.target,
171 if (obj.first_sort) {
176 if (obj.row_count.total != obj.row_count.fleshed && (obj.row_count.total - obj.row_count.fleshed) > 50) {
177 var r = window.confirm(document.getElementById('offlineStrings').getFormattedString('list.row_fetch_warning',[obj.row_count.fleshed,obj.row_count.total]));
180 setTimeout( do_it, 0 );
183 setTimeout( do_it, 0 );
189 var splitter = document.createElement('splitter');
190 splitter.setAttribute('class','tree-splitter');
191 treecols.appendChild(splitter);
194 var treechildren = document.createElement('treechildren');
195 this.node.appendChild(treechildren);
196 this.treechildren = treechildren;
198 if (typeof params.on_sort == 'function') {
199 this.on_sort = params.on_sort;
201 if (typeof params.on_checkbox_toggle == 'function') {
202 this.on_checkbox_toggle = params.on_checkbox_toggle;
204 this.node.addEventListener(
207 if (typeof params.on_select == 'function') {
208 params.on_select(ev);
210 var x = document.getElementById(obj.node.id + '_clipfield');
212 var sel = obj.retrieve_selection();
213 x.setAttribute('disabled', sel.length == 0);
218 if (typeof params.on_click == 'function') {
219 this.node.addEventListener(
225 if (typeof params.on_dblclick == 'function') {
226 this.node.addEventListener(
234 this.node.addEventListener(
236 function(ev) { obj.detect_visible(); },
240 this.node.addEventListener(
242 function(ev) { obj.auto_retrieve(); },
245 this.node.addEventListener(
247 function(ev) { obj.auto_retrieve(); },
250 window.addEventListener(
252 function(ev) { obj.auto_retrieve(); },
255 /* FIXME -- find events on scrollbar to trigger this */
256 obj.detect_visible_polling();
258 var scrollbar = document.getAnonymousNodes( document.getAnonymousNodes(this.node)[1] )[1];
259 var slider = document.getAnonymousNodes( scrollbar )[2];
260 alert('scrollbar = ' + scrollbar.nodeName + ' grippy = ' + slider.nodeName);
261 scrollbar.addEventListener('click',function(){alert('sb click');},false);
262 scrollbar.addEventListener('command',function(){alert('sb command');},false);
263 scrollbar.addEventListener('scroll',function(){alert('sb scroll');},false);
264 slider.addEventListener('click',function(){alert('slider click');},false);
265 slider.addEventListener('command',function(){alert('slider command');},false);
266 slider.addEventListener('scroll',function(){alert('slider scroll');},false);
268 this.node.addEventListener('scroll',function(){ obj.auto_retrieve(); },false);
270 this.restores_columns(params);
273 '_init_listbox' : function (params) {
276 var listhead = document.createElement('listhead');
277 this.node.appendChild(listhead);
279 var listcols = document.createElement('listcols');
280 this.node.appendChild(listcols);
282 for (var i = 0; i < this.columns.length; i++) {
283 var listheader = document.createElement('listheader');
284 listhead.appendChild(listheader);
285 var listcol = document.createElement('listcol');
286 listcols.appendChild(listcol);
287 for (var j in this.columns[i]) {
288 listheader.setAttribute(j,this.columns[i][j]);
289 listcol.setAttribute(j,this.columns[i][j]);
295 'save_columns' : function (params) {
297 if (obj.data.hash.aous['gui.disable_local_save_columns']) {
298 alert(document.getElementById('offlineStrings').getString('list.column_save_disabled'));
300 switch (this.node.nodeName) {
301 case 'tree' : this._save_columns_tree(params); break;
302 default: throw('NYI: Need .save_columns() for ' + this.node.nodeName); break;
307 '_save_columns_tree' : function (params) {
310 var id = obj.node.getAttribute('id');
311 if (obj.columns_saved_under) { id = obj.columns_saved_under; }
313 alert("FIXME: The columns for this list cannot be saved because the list has no id.");
317 var nl = obj.node.getElementsByTagName('treecol');
318 for (var i = 0; i < nl.length; i++) {
320 var col_id = col.getAttribute('id');
322 alert('FIXME: A column in this list does not have an id and cannot be saved');
325 var col_hidden = col.getAttribute('hidden');
326 var col_width = col.getAttribute('width');
327 var col_ordinal = col.getAttribute('ordinal');
328 my_cols[ col_id ] = { 'hidden' : col_hidden, 'width' : col_width, 'ordinal' : col_ordinal };
330 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
331 JSAN.use('util.file'); var file = new util.file('tree_columns_for_'+window.escape(id));
332 file.set_object(my_cols);
334 alert(document.getElementById('offlineStrings').getString('list.columns_saved'));
336 obj.error.standard_unexpected_error_alert('_save_columns_tree',E);
340 'restores_columns' : function (params) {
342 switch (this.node.nodeName) {
343 case 'tree' : this._restores_columns_tree(params); break;
344 default: throw('NYI: Need .restores_columns() for ' + this.node.nodeName); break;
348 '_restores_columns_tree' : function (params) {
351 var id = obj.node.getAttribute('id');
352 if (obj.columns_saved_under) { id = obj.columns_saved_under; }
354 alert("FIXME: The columns for this list cannot be restored because the list has no id.");
359 if (! obj.data.hash.aous) { obj.data.hash.aous = {}; }
360 if (! obj.data.hash.aous['gui.disable_local_save_columns']) {
361 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
362 JSAN.use('util.file'); var file = new util.file('tree_columns_for_'+window.escape(id));
363 if (file._file.exists()) {
364 my_cols = file.get_object(); file.close();
367 /* local file will trump remote file if allowed, so save ourselves an http request if this is the case */
368 if (obj.data.hash.aous['url.remote_column_settings'] && ! my_cols ) {
370 var x = new XMLHttpRequest();
371 var url = obj.data.hash.aous['url.remote_column_settings'] + '/tree_columns_for_' + window.escape(id);
372 x.open("GET", url, false);
374 if (x.status == 200) {
375 my_cols = JSON2js( x.responseText );
378 // This can happen in the offline interface if you logged in previously and url.remote_column_settings is set.
379 // 1) You may be really "offline" now
380 // 2) the URL may just be a path component without a hostname (ie "/xul/column_settings/"), which won't work
381 // when appended to chrome://open_ils_staff_client/
382 dump('Error retrieving column settings from ' + url + ': ' + E + '\n');
387 var nl = obj.node.getElementsByTagName('treecol');
388 for (var i = 0; i < nl.length; i++) {
390 var col_id = col.getAttribute('id');
392 alert('FIXME: A column in this list does not have an id and cannot be saved');
395 if (typeof my_cols[col_id] != 'undefined') {
396 col.setAttribute('hidden',my_cols[col_id].hidden);
397 col.setAttribute('width',my_cols[col_id].width);
398 col.setAttribute('ordinal',my_cols[col_id].ordinal);
400 obj.error.sdump('D_ERROR','WARNING: Column ' + col_id + ' did not have a saved state.');
405 obj.error.standard_unexpected_error_alert('_restore_columns_tree',E);
409 'clear' : function (params) {
411 switch (this.node.nodeName) {
412 case 'tree' : this._clear_tree(params); break;
413 case 'listbox' : this._clear_listbox(params); break;
414 default: throw('NYI: Need .clear() for ' + this.node.nodeName); break;
416 this.error.sdump('D_LIST','Clearing list ' + this.node.getAttribute('id') + '\n');
417 this.row_count.total = 0;
418 this.row_count.fleshed = 0;
419 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
422 '_clear_tree' : function(params) {
424 if (obj.error.sdump_levels.D_LIST_DUMP_ON_CLEAR) {
425 obj.error.sdump('D_LIST_DUMP_ON_CLEAR',obj.dump());
427 if (obj.error.sdump_levels.D_LIST_DUMP_WITH_KEYS_ON_CLEAR) {
428 obj.error.sdump('D_LIST_DUMP_WITH_KEYS_ON_CLEAR',obj.dump_with_keys());
430 while (obj.treechildren.lastChild) obj.treechildren.removeChild( obj.treechildren.lastChild );
433 '_clear_listbox' : function(params) {
436 var nl = this.node.getElementsByTagName('listitem');
437 for (var i = 0; i < nl.length; i++) {
440 for (var i = 0; i < items.length; i++) {
441 this.node.removeChild(items[i]);
445 'append' : function (params) {
448 switch (this.node.nodeName) {
449 case 'tree' : rparams = this._append_to_tree(params); break;
450 case 'listbox' : rparams = this._append_to_listbox(params); break;
451 default: throw('NYI: Need .append() for ' + this.node.nodeName); break;
453 if (rparams && params.attributes) {
454 for (var i in params.attributes) {
455 rparams.treeitem_node.setAttribute(i,params.attributes[i]);
458 this.row_count.total++;
459 if (this.row_count.fleshed == this.row_count.total) {
460 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
462 rparams.treeitem_node.setAttribute('unique_row_counter',obj.unique_row_counter);
463 rparams.unique_row_counter = obj.unique_row_counter++;
464 if (typeof params.on_append == 'function') {
465 params.on_append(rparams);
470 'refresh_row' : function (params) {
473 switch (this.node.nodeName) {
474 case 'tree' : rparams = this._refresh_row_in_tree(params); break;
475 default: throw('NYI: Need .refresh_row() for ' + this.node.nodeName); break;
477 if (rparams && params.attributes) {
478 for (var i in params.attributes) {
479 rparams.treeitem_node.setAttribute(i,params.attributes[i]);
482 this.row_count.fleshed--;
487 '_append_to_tree' : function (params) {
491 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
493 var s = ('util.list.append: params = ' + (params) + '\n');
495 var treechildren_node = this.treechildren;
497 if (params.node && params.node.nodeName == 'treeitem') {
498 params.node.setAttribute('container','true'); /* params.node.setAttribute('open','true'); */
499 if (params.node.lastChild.nodeName == 'treechildren') {
500 treechildren_node = params.node.lastChild;
502 treechildren_node = document.createElement('treechildren');
503 params.node.appendChild(treechildren_node);
507 var treeitem = document.createElement('treeitem');
508 treeitem.setAttribute('retrieve_id',params.retrieve_id);
509 if (typeof params.to_bottom != 'undefined') {
510 treechildren_node.appendChild( treeitem );
511 if (typeof params.no_auto_select == 'undefined') {
512 if (!obj.auto_select_pending) {
513 obj.auto_select_pending = true;
514 setTimeout(function() {
515 dump('auto-selecting\n');
516 var idx = Number(obj.node.view.rowCount)-1;
517 try { obj.node.view.selection.select(idx); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); }
518 try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); }
519 obj.auto_select_pending = false;
520 try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(idx).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); }
525 if (treechildren_node.firstChild) {
526 treechildren_node.insertBefore( treeitem, treechildren_node.firstChild );
528 treechildren_node.appendChild( treeitem );
530 if (typeof params.no_auto_select == 'undefined') {
531 if (!obj.auto_select_pending) {
532 obj.auto_select_pending = true;
533 setTimeout(function() {
534 try { obj.node.view.selection.select(0); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); }
535 try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); }
536 obj.auto_select_pending = false;
537 try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(0).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); }
542 var treerow = document.createElement('treerow');
543 treeitem.appendChild( treerow );
544 treerow.setAttribute('retrieve_id',params.retrieve_id);
545 if (params.row_properties) treerow.setAttribute('properties',params.row_properties);
547 s += ('tree = ' + this.node + ' treechildren = ' + treechildren_node + '\n');
548 s += ('treeitem = ' + treeitem + ' treerow = ' + treerow + '\n');
550 obj.put_retrieving_label(treerow);
552 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
553 treerow.addEventListener(
557 if (treerow.getAttribute('retrieved') == 'true') return; /* already running */
559 treerow.setAttribute('retrieved','true');
561 //dump('fleshing = ' + params.retrieve_id + '\n');
563 function inc_fleshed() {
564 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
565 treerow.setAttribute('fleshed','true');
566 obj.row_count.fleshed++;
567 if (obj.row_count.fleshed >= obj.row_count.total) {
568 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
572 params.treeitem_node = treeitem;
573 params.on_retrieve = function(p) {
576 obj._map_row_to_treecell(p,treerow);
578 var idx = obj.node.contentView.getIndexOfItem( params.treeitem_node );
579 dump('idx = ' + idx + '\n');
580 // if current row is selected, send another select event to re-sync data that the client code fetches on selects
581 if ( obj.node.view.selection.isSelected( idx ) ) {
582 dump('dispatching select event for on_retrieve for idx = ' + idx + '\n');
583 util.widgets.dispatch('select',obj.node);
586 // Let's not alert on this for now. Getting contentView has no properties in record buckets under certain conditions
587 dump('fixme2: ' + E + '\n');
591 if (typeof params.retrieve_row == 'function') {
593 params.retrieve_row( params );
595 } else if (typeof obj.retrieve_row == 'function') {
597 obj.retrieve_row( params );
603 obj.refresh_ordinals();
607 if (typeof params.flesh_immediately != 'undefined') {
608 if (params.flesh_immediately) {
611 util.widgets.dispatch('flesh',treerow);
617 treerow.addEventListener(
620 //dump('fleshing anon\n');
621 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
622 obj._map_row_to_treecell(params,treerow);
623 treerow.setAttribute('retrieved','true');
624 treerow.setAttribute('fleshed','true');
625 obj.row_count.fleshed++;
626 if (obj.row_count.fleshed >= obj.row_count.total) {
627 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
629 obj.refresh_ordinals();
633 if (typeof params.flesh_immediately != 'undefined') {
634 if (params.flesh_immediately) {
637 util.widgets.dispatch('flesh',treerow);
643 this.error.sdump('D_LIST',s);
647 if (obj.trim_list && obj.row_count.total >= obj.trim_list) {
649 //if (typeof params.to_bottom != 'undefined')
650 if (typeof params.to_top == 'undefined') {
651 if (typeof params.on_delete == 'function') { params.on_delete( treechildren_node.firstChild.getAttribute('unique_row_counter') ); }
652 treechildren_node.removeChild( treechildren_node.firstChild );
654 if (typeof params.on_delete == 'function') { params.on_delete( treechildren_node.lastChild.getAttribute('unique_row_counter') ); }
655 treechildren_node.removeChild( treechildren_node.lastChild );
661 setTimeout( function() { obj.auto_retrieve(); obj.refresh_ordinals(); }, 0 );
663 params.treeitem_node = treeitem;
667 '_refresh_row_in_tree' : function (params) {
671 if (typeof params.row == 'undefined') throw('util.list.refresh_row: Object must contain a row');
672 if (typeof params.treeitem_node == 'undefined') throw('util.list.refresh_row: Object must contain a treeitem_node');
673 if (params.treeitem_node.nodeName != 'treeitem') throw('util.list.refresh_rwo: treeitem_node must be a treeitem');
675 var s = ('util.list.refresh_row: params = ' + (params) + '\n');
677 var treeitem = params.treeitem_node;
678 treeitem.setAttribute('retrieve_id',params.retrieve_id);
679 if (typeof params.to_bottom != 'undefined') {
680 if (typeof params.no_auto_select == 'undefined') {
681 if (!obj.auto_select_pending) {
682 obj.auto_select_pending = true;
683 setTimeout(function() {
684 dump('auto-selecting\n');
685 var idx = Number(obj.node.view.rowCount)-1;
686 try { obj.node.view.selection.select(idx); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); }
687 try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); }
688 obj.auto_select_pending = false;
689 try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(idx).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); }
694 //var delete_me = [];
695 //for (var i in treeitem.childNodes) if (treeitem.childNodes[i].nodeName == 'treerow') delete_me.push(treeitem.childNodes[i]);
696 //for (var i = 0; i < delete_me.length; i++) treeitem.removeChild(delete_me[i]);
697 var prev_treerow = treeitem.firstChild; /* FIXME: worry about hierarchal lists like copy_browser? */
698 var treerow = document.createElement('treerow');
699 while (prev_treerow.firstChild) {
700 treerow.appendChild( prev_treerow.removeChild( prev_treerow.firstChild ) );
702 treeitem.replaceChild( treerow, prev_treerow );
703 treerow.setAttribute('retrieve_id',params.retrieve_id);
704 if (params.row_properties) treerow.setAttribute('properties',params.row_properties);
706 s += ('tree = ' + this.node.nodeName + '\n');
707 s += ('treeitem = ' + treeitem.nodeName + ' treerow = ' + treerow.nodeName + '\n');
709 obj.put_retrieving_label(treerow);
711 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
713 s += 'found a retrieve_row function\n';
715 treerow.addEventListener(
719 if (treerow.getAttribute('retrieved') == 'true') return; /* already running */
721 treerow.setAttribute('retrieved','true');
723 //dump('fleshing = ' + params.retrieve_id + '\n');
725 function inc_fleshed() {
726 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
727 treerow.setAttribute('fleshed','true');
728 obj.row_count.fleshed++;
729 if (obj.row_count.fleshed >= obj.row_count.total) {
730 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
734 params.treeitem_node = treeitem;
735 params.on_retrieve = function(p) {
738 obj._map_row_to_treecell(p,treerow);
740 var idx = obj.node.contentView.getIndexOfItem( params.treeitem_node );
741 dump('idx = ' + idx + '\n');
742 // if current row is selected, send another select event to re-sync data that the client code fetches on selects
743 if ( obj.node.view.selection.isSelected( idx ) ) {
744 dump('dispatching select event for on_retrieve for idx = ' + idx + '\n');
745 util.widgets.dispatch('select',obj.node);
748 // Let's not alert on this for now. Getting contentView has no properties in record buckets under certain conditions
749 dump('fixme2: ' + E + '\n');
753 if (typeof params.retrieve_row == 'function') {
755 params.retrieve_row( params );
757 } else if (typeof obj.retrieve_row == 'function') {
759 obj.retrieve_row( params );
765 obj.refresh_ordinals();
769 if (typeof params.flesh_immediately != 'undefined') {
770 if (params.flesh_immediately) {
773 util.widgets.dispatch('flesh',treerow);
781 s += 'did not find a retrieve_row function\n';
783 treerow.addEventListener(
786 //dump('fleshing anon\n');
787 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
788 obj._map_row_to_treecell(params,treerow);
789 treerow.setAttribute('retrieved','true');
790 treerow.setAttribute('fleshed','true');
791 obj.row_count.fleshed++;
792 if (obj.row_count.fleshed >= obj.row_count.total) {
793 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
795 obj.refresh_ordinals();
799 if (typeof params.flesh_immediately != 'undefined') {
800 if (params.flesh_immediately) {
803 util.widgets.dispatch('flesh',treerow);
813 if (obj.trim_list && obj.row_count.total >= obj.trim_list) {
815 //if (typeof params.to_bottom != 'undefined')
816 if (typeof params.to_top == 'undefined') {
817 treechildren_node.removeChild( treechildren_node.firstChild );
819 treechildren_node.removeChild( treechildren_node.lastChild );
825 setTimeout( function() { obj.auto_retrieve(); obj.refresh_ordinals(); }, 0 );
827 JSAN.use('util.widgets'); util.widgets.dispatch('select',obj.node);
829 this.error.sdump('D_LIST',s);
834 'refresh_ordinals' : function() {
837 if (obj.refresh_ordinals_timeout_id) { return; }
839 function _refresh_ordinals(clear) {
840 var nl = obj.node.getElementsByAttribute('label','_');
841 for (var i = 0; i < nl.length; i++) {
846 nl[i].setAttribute( // treecell properties for css styling
851 nl = obj.node.getElementsByAttribute('ord_col','true');
852 for (var i = 0; i < nl.length; i++) {
855 // we could just use 'i' here if we trust the order of elements
856 1 + obj.node.contentView.getIndexOfItem(nl[i].parentNode.parentNode) // treeitem
859 if (clear) { obj.refresh_ordinals_timeout_id = null; }
862 // spamming this to cover race conditions
863 setTimeout(_refresh_ordinals, 500); // for speedy looking UI updates
864 setTimeout(_refresh_ordinals, 2000); // for most uses
865 obj.refresh_ordinals_timeout_id = setTimeout(
867 _refresh_ordinals(true);
869 4000 // just in case, say with a slow rendering list
873 alert('Error in list.js, refresh_ordinals(): ' + E);
877 'put_retrieving_label' : function(treerow) {
880 for (var i = 0; i < obj.columns.length; i++) {
882 if (typeof treerow.childNodes[i] == 'undefined') {
883 treecell = document.createElement('treecell');
884 treerow.appendChild(treecell);
886 treecell = treerow.childNodes[i];
888 treecell.setAttribute('label',document.getElementById('offlineStrings').getString('list.row_retrieving'));
891 alert('Error in list.js, put_retrieving_label(): ' + E);
895 'detect_visible' : function() {
898 //dump('detect_visible obj.node = ' + obj.node + '\n');
899 /* FIXME - this is a hack.. if the implementation of tree changes, this could break */
901 /*var s = ''; var A = document.getAnonymousNodes(obj.node);
904 s += '\t' + (typeof B.nodeName != 'undefined' ? B.nodeName : B ) + '\n';
905 if (typeof B.childNodes != 'undefined') for (var j = 0; j < B.childNodes.length; j++) {
906 var C = B.childNodes[j];
907 s += '\t\t' + C.nodeName + '\n';
910 obj.error.sdump('D_XULRUNNER','document.getAnonymousNodes(' + obj.node.nodeName + ') = \n' + s + '\n');*/
911 var scrollbar = document.getAnonymousNodes(obj.node)[2].firstChild;
912 var curpos = scrollbar.getAttribute('curpos');
913 var maxpos = scrollbar.getAttribute('maxpos');
914 //alert('curpos = ' + curpos + ' maxpos = ' + maxpos + ' obj.curpos = ' + obj.curpos + ' obj.maxpos = ' + obj.maxpos + '\n');
915 if ((curpos != obj.curpos) || (maxpos != obj.maxpos)) {
916 if ( obj.auto_retrieve() > 0 ) {
917 obj.curpos = curpos; obj.maxpos = maxpos;
921 obj.error.sdump('D_XULRUNNER', 'List implementation changed? ' + E);
923 } catch(E) { obj.error.sdump('D_ERROR',E); }
926 'detect_visible_polling' : function() {
928 //alert('detect_visible_polling');
930 obj.detect_visible();
931 setTimeout(function() { try { obj.detect_visible_polling(); } catch(E) { alert(E); } },2000);
938 'auto_retrieve' : function(params) {
940 switch (this.node.nodeName) {
941 case 'tree' : obj._auto_retrieve_tree(params); break;
942 default: throw('NYI: Need .auto_retrieve() for ' + obj.node.nodeName); break;
946 '_auto_retrieve_tree' : function (params) {
948 if (!obj.auto_retrieve_in_progress) {
949 obj.auto_retrieve_in_progress = true;
953 //alert('auto_retrieve\n');
955 var startpos = obj.node.treeBoxObject.getFirstVisibleRow();
956 var endpos = obj.node.treeBoxObject.getLastVisibleRow();
957 if (startpos > endpos) endpos = obj.node.treeBoxObject.getPageLength();
958 //dump('startpos = ' + startpos + ' endpos = ' + endpos + '\n');
959 for (var i = startpos; i < endpos + 4; i++) {
961 //dump('trying index ' + i + '\n');
962 var item = obj.node.contentView.getItemAtIndex(i).firstChild;
963 if (item && item.getAttribute('retrieved') != 'true' ) {
964 //dump('\tgot an unfleshed item = ' + item + ' = ' + item.nodeName + '\n');
965 util.widgets.dispatch('flesh',item); count++;
968 //dump(i + ' : ' + E + '\n');
971 obj.auto_retrieve_in_progress = false;
973 } catch(E) { alert(E); }
979 'exec_on_all_fleshed' : function() {
982 if (obj.on_all_fleshed) {
983 if (typeof obj.on_all_fleshed == 'function') {
984 dump('exec_on_all_fleshed == function\n');
987 try { obj.on_all_fleshed(); } catch(E) { obj.error.standard_unexpected_error_alert('_full_retrieve_tree callback',obj.on_all_fleshed); }
990 } else if (typeof obj.on_all_fleshed.length != 'undefined') {
991 dump('exec_on_all_fleshed == array\n');
995 dump('exec_on_all_fleshed, processing on_all_fleshed array, length = ' + obj.on_all_fleshed.length + '\n');
996 var f = obj.on_all_fleshed.pop();
997 if (typeof f == 'function') {
998 try { f(); } catch(E) { obj.error.standard_unexpected_error_alert('_full_retrieve_tree callback',f); }
1000 if (obj.on_all_fleshed.length > 0) arguments.callee();
1002 obj.error.standard_unexpected_error_alert('exec_on_all_fleshed callback error',E);
1007 obj.error.standard_unexpected_error_alert('unexpected on_all_fleshed object: ', obj.on_all_fleshed);
1011 obj.error.standard_unexpected_error_alert('exec_on_all-fleshed error',E);
1015 'full_retrieve' : function(params) {
1017 switch (this.node.nodeName) {
1018 case 'tree' : obj._full_retrieve_tree(params); break;
1019 default: throw('NYI: Need .full_retrieve() for ' + obj.node.nodeName); break;
1021 obj.refresh_ordinals();
1024 '_full_retrieve_tree' : function(params) {
1027 if (obj.row_count.fleshed >= obj.row_count.total) {
1028 dump('Full retrieve... tree seems to be in sync\n' + js2JSON(obj.row_count) + '\n');
1029 obj.exec_on_all_fleshed();
1031 dump('Full retrieve... syncing tree' + js2JSON(obj.row_count) + '\n');
1032 JSAN.use('util.widgets');
1033 var nodes = obj.treechildren.childNodes;
1034 for (var i = 0; i < nodes.length; i++) {
1035 util.widgets.dispatch('flesh',nodes[i].firstChild);
1039 obj.error.standard_unexpected_error_alert('_full_retrieve_tree',E);
1043 '_append_to_listbox' : function (params) {
1047 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
1049 var s = ('util.list.append: params = ' + (params) + '\n');
1051 var listitem = document.createElement('listitem');
1053 s += ('listbox = ' + this.node + ' listitem = ' + listitem + '\n');
1055 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
1059 listitem.setAttribute('retrieve_id',params.retrieve_id);
1060 //FIXME//Make async and fire when row is visible in list
1063 params.treeitem_node = listitem;
1064 params.on_retrieve = function(row) {
1066 obj._map_row_to_listcell(params,listitem);
1067 obj.node.appendChild( listitem );
1068 util.widgets.dispatch('select',obj.node);
1071 if (typeof params.retrieve_row == 'function') {
1073 row = params.retrieve_row( params );
1077 if (typeof obj.retrieve_row == 'function') {
1079 row = obj.retrieve_row( params );
1086 this._map_row_to_listcell(params,listitem);
1087 this.node.appendChild( listitem );
1090 this.error.sdump('D_LIST',s);
1091 params.treeitem_node = listitem;
1096 '_map_row_to_treecell' : function(params,treerow) {
1100 if (typeof params.map_row_to_column == 'function' || typeof this.map_row_to_column == 'function') {
1102 for (var i = 0; i < this.columns.length; i++) {
1104 if (typeof treerow.childNodes[i] == 'undefined') {
1105 treecell = document.createElement('treecell');
1106 treerow.appendChild( treecell );
1108 treecell = treerow.childNodes[i];
1111 if ( this.columns[i].editable == false ) { treecell.setAttribute('editable','false'); }
1113 var sort_value = '';
1115 // What skip columns is doing is rendering the treecells as blank/empty
1116 if (params.skip_columns && (params.skip_columns.indexOf(i) != -1)) {
1117 treecell.setAttribute('label',label);
1118 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
1121 if (params.skip_all_columns_except && (params.skip_all_columns_except.indexOf(i) == -1)) {
1122 treecell.setAttribute('label',label);
1123 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
1127 if (typeof params.map_row_to_column == 'function') {
1129 label = params.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1131 } else if (typeof this.map_row_to_column == 'function') {
1133 label = this.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1136 if (this.columns[i].type == 'checkbox') { treecell.setAttribute('value',label); } else { treecell.setAttribute('label',label ? label : ''); }
1137 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
1139 } else if (typeof params.map_row_to_columns == 'function' || typeof this.map_row_to_columns == 'function') {
1142 var sort_values = [];
1144 if (typeof params.map_row_to_columns == 'function') {
1146 var values = params.map_row_to_columns(params.row,this.columns,this.scratch_data);
1147 if (typeof values.values == 'undefined') {
1150 labels = values.values;
1151 sort_values = values.sort_values;
1154 } else if (typeof this.map_row_to_columns == 'function') {
1156 var values = this.map_row_to_columns(params.row,this.columns,this.scratch_data);
1157 if (typeof values.values == 'undefined') {
1160 labels = values.values;
1161 sort_values = values.sort_values;
1164 for (var i = 0; i < labels.length; i++) {
1166 if (typeof treerow.childNodes[i] == 'undefined') {
1167 treecell = document.createElement('treecell');
1168 treerow.appendChild(treecell);
1170 treecell = treerow.childNodes[i];
1172 if ( this.columns[i].editable == false ) { treecell.setAttribute('editable','false'); }
1173 if ( this.columns[i].type == 'checkbox') {
1174 treecell.setAttribute('value', labels[i]);
1176 treecell.setAttribute('label',typeof labels[i] == 'string' || typeof labels[i] == 'number' ? labels[i] : '');
1178 if (sort_values[i]) {
1179 treecell.setAttribute('sort_value',js2JSON(sort_values[i]));
1181 s += ('treecell = ' + treecell + ' with label = ' + labels[i] + '\n');
1186 throw('No row to column mapping function.');
1188 this.error.sdump('D_LIST',s);
1191 '_map_row_to_listcell' : function(params,listitem) {
1194 for (var i = 0; i < this.columns.length; i++) {
1196 if (typeof params.map_row_to_column == 'function') {
1198 value = params.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1202 if (typeof this.map_row_to_column == 'function') {
1204 value = this.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1207 if (typeof value == 'string' || typeof value == 'number') {
1208 var listcell = document.createElement('listcell');
1209 listcell.setAttribute('label',value);
1210 listitem.appendChild(listcell);
1211 s += ('listcell = ' + listcell + ' with label = ' + value + '\n');
1213 listitem.appendChild(value);
1214 s += ('listcell = ' + value + ' is really a ' + value.nodeName + '\n');
1217 this.error.sdump('D_LIST',s);
1220 'select_all' : function(params) {
1222 switch(this.node.nodeName) {
1223 case 'tree' : return this._select_all_from_tree(params); break;
1224 default: throw('NYI: Need ._select_all_from_() for ' + this.node.nodeName); break;
1228 '_select_all_from_tree' : function(params) {
1230 this.node.view.selection.selectAll();
1233 'retrieve_selection' : function(params) {
1235 switch(this.node.nodeName) {
1236 case 'tree' : return this._retrieve_selection_from_tree(params); break;
1237 default: throw('NYI: Need ._retrieve_selection_from_() for ' + this.node.nodeName); break;
1241 '_retrieve_selection_from_tree' : function(params) {
1244 var start = new Object();
1245 var end = new Object();
1246 var numRanges = this.node.view.selection.getRangeCount();
1247 for (var t=0; t<numRanges; t++){
1248 this.node.view.selection.getRangeAt(t,start,end);
1249 for (var v=start.value; v<=end.value; v++){
1250 var i = this.node.contentView.getItemAtIndex(v);
1257 'dump' : function(params) {
1259 switch(this.node.nodeName) {
1260 case 'tree' : return this._dump_tree(params); break;
1261 default: throw('NYI: Need .dump() for ' + this.node.nodeName); break;
1265 '_dump_tree' : function(params) {
1268 for (var i = 0; i < this.treechildren.childNodes.length; i++) {
1270 var treeitem = this.treechildren.childNodes[i];
1271 var treerow = treeitem.firstChild;
1272 for (var j = 0; j < treerow.childNodes.length; j++) {
1273 row.push( treerow.childNodes[j].getAttribute('label') );
1280 'dump_with_keys' : function(params) {
1282 switch(this.node.nodeName) {
1283 case 'tree' : return this._dump_tree_with_keys(params); break;
1284 default: throw('NYI: Need .dump_with_keys() for ' + this.node.nodeName); break;
1289 '_dump_tree_with_keys' : function(params) {
1293 function process_tree(treechildren) {
1294 for (var i = 0; i < treechildren.childNodes.length; i++) {
1296 var treeitem = treechildren.childNodes[i];
1297 var treerow = treeitem.firstChild;
1298 for (var j = 0; j < treerow.childNodes.length; j++) {
1299 if (typeof obj.columns[j] == 'undefined') {
1300 dump('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n');
1301 dump('_dump_tree_with_keys @ ' + location.href + '\n');
1302 dump('\ttreerow.childNodes.length='+treerow.childNodes.length+' j='+j+' obj.columns.length='+obj.columns.length+'\n');
1305 row[ obj.columns[j].id ] = treerow.childNodes[j].getAttribute('label');
1306 var sort = treerow.childNodes[j].getAttribute('sort_value');
1308 row[ obj.columns[j].id + '_sort_value' ] = sort;
1313 if (treeitem.childNodes.length > 1) {
1314 process_tree(treeitem.lastChild);
1319 process_tree(this.treechildren);
1324 'dump_csv' : function(params) {
1326 switch(this.node.nodeName) {
1327 case 'tree' : return this._dump_tree_csv(params); break;
1328 default: throw('NYI: Need .dump_csv() for ' + this.node.nodeName); break;
1333 '_dump_tree_csv' : function(params) {
1337 for (var j = 0; j < obj.columns.length; j++) {
1338 if (obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('hidden') == 'true') {
1341 ord_cols.push( [ obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('ordinal'), j ] );
1344 ord_cols.sort( function(a,b) {
1345 if ( Number( a[0] ) < Number( b[0] ) ) return -1;
1346 if ( Number( a[0] ) > Number( b[0] ) ) return 1;
1349 for (var j = 0; j < ord_cols.length; j++) {
1350 if (_dump) _dump += ',';
1351 _dump += '"' + obj.columns[ ord_cols[j][1] ].label.replace(/"/g, '""') + '"';
1355 function process_tree(treechildren) {
1356 for (var i = 0; i < treechildren.childNodes.length; i++) {
1358 var treeitem = treechildren.childNodes[i];
1359 var treerow = treeitem.firstChild;
1360 for (var j = 0; j < ord_cols.length; j++) {
1361 if (row) row += ',';
1362 row += '"' + treerow.childNodes[ ord_cols[j][1] ].getAttribute('label').replace(/"/g, '""') + '"';
1364 _dump += row + '\r\n';
1365 if (treeitem.childNodes.length > 1) {
1366 process_tree(treeitem.lastChild);
1371 process_tree(this.treechildren);
1376 'dump_extended_format' : function(params) {
1378 switch(this.node.nodeName) {
1379 case 'tree' : return this._dump_tree_extended_format(params); break;
1380 default: throw('NYI: Need .dump_extended_format() for ' + this.node.nodeName); break;
1385 '_dump_tree_extended_format' : function(params) {
1389 for (var j = 0; j < obj.columns.length; j++) {
1390 if (obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('hidden') == 'true') {
1393 ord_cols.push( [ obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('ordinal'), j ] );
1396 ord_cols.sort( function(a,b) {
1397 if ( Number( a[0] ) < Number( b[0] ) ) return -1;
1398 if ( Number( a[0] ) > Number( b[0] ) ) return 1;
1402 function process_tree(treechildren) {
1403 for (var i = 0; i < treechildren.childNodes.length; i++) {
1404 var row = document.getElementById('offlineStrings').getString('list.dump_extended_format.record_separator') + '\r\n';
1405 var treeitem = treechildren.childNodes[i];
1406 var treerow = treeitem.firstChild;
1407 for (var j = 0; j < ord_cols.length; j++) {
1408 row += obj.columns[ ord_cols[j][1] ].label + ': ' + treerow.childNodes[ ord_cols[j][1] ].getAttribute('label') + '\r\n';
1410 _dump += row + '\r\n';
1411 if (treeitem.childNodes.length > 1) {
1412 process_tree(treeitem.lastChild);
1417 process_tree(this.treechildren);
1422 'dump_csv_to_clipboard' : function(params) {
1424 if (typeof params == 'undefined') params = {};
1425 if (params.no_full_retrieve) {
1426 copy_to_clipboard( obj.dump_csv( params ) );
1428 obj.wrap_in_full_retrieve( function() { copy_to_clipboard( obj.dump_csv( params ) ); } );
1432 'dump_csv_to_printer' : function(params) {
1434 if (typeof params == 'undefined') params = {};
1435 JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context);
1436 if (params.no_full_retrieve) {
1437 print.simple( obj.dump_csv( params ), {'content_type':'text/plain'} );
1439 obj.wrap_in_full_retrieve(
1441 print.simple( obj.dump_csv( params ), {'content_type':'text/plain'} );
1447 'dump_extended_format_to_printer' : function(params) {
1449 if (typeof params == 'undefined') params = {};
1450 JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context);
1451 if (params.no_full_retrieve) {
1452 print.simple( obj.dump_extended_format( params ), {'content_type':'text/plain'} );
1454 obj.wrap_in_full_retrieve(
1456 print.simple( obj.dump_extended_format( params ), {'content_type':'text/plain'} );
1462 'dump_csv_to_file' : function(params) {
1464 JSAN.use('util.file'); var f = new util.file();
1465 if (typeof params == 'undefined') params = {};
1466 if (params.no_full_retrieve) {
1467 params.data = obj.dump_csv( params );
1468 params.not_json = true;
1469 if (!params.title) params.title = document.getElementById('offlineStrings').getString('list.save_csv_as');
1470 f.export_file( params );
1472 obj.wrap_in_full_retrieve(
1474 params.data = obj.dump_csv( params );
1475 params.not_json = true;
1476 if (!params.title) params.title = document.getElementById('offlineStrings').getString('list.save_csv_as');
1477 f.export_file( params );
1483 'print' : function(params) {
1484 if (!params) params = {};
1485 switch(this.node.nodeName) {
1486 case 'tree' : return this._print_tree(params); break;
1487 default: throw('NYI: Need ._print() for ' + this.node.nodeName); break;
1491 '_print_tree' : function(params) {
1494 var data = obj.data; data.stash_retrieve();
1495 if (!params.staff && data.list.au && data.list.au[0]) {
1496 params.staff = data.list.au[0];
1498 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() ]) {
1499 params.lib = data.hash.aou[ data.list.au[0].ws_ou() ];
1500 params.lib.children(null);
1502 if (params.template && data.print_list_templates[ params.template ]) {
1503 var template = data.print_list_templates[ params.template ];
1504 if (template.inherit) {
1505 template = data.print_list_templates[ template.inherit ];
1506 // if someone wants to implement recursion later, feel free
1508 for (var i in template) params[i] = template[i];
1510 obj.wrap_in_full_retrieve(
1513 if (!params.list) params.list = obj.dump_with_keys();
1514 JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context);
1515 print.tree_list( params );
1516 if (typeof params.callback == 'function') params.callback();
1518 obj.error.standard_unexpected_error_alert('inner _print_tree',E);
1524 obj.error.standard_unexpected_error_alert('_print_tree',E);
1528 'dump_selected_with_keys' : function(params) {
1530 switch(this.node.nodeName) {
1531 case 'tree' : return this._dump_tree_selection_with_keys(params); break;
1532 default: throw('NYI: Need .dump_selection_with_keys() for ' + this.node.nodeName); break;
1537 '_dump_tree_selection_with_keys' : function(params) {
1540 var list = obj._retrieve_selection_from_tree();
1541 for (var i = 0; i < list.length; i++) {
1543 var treeitem = list[i];
1544 var treerow = treeitem.firstChild;
1545 for (var j = 0; j < treerow.childNodes.length; j++) {
1546 var value = treerow.childNodes[j].getAttribute('label');
1547 if (params.skip_hidden_columns) if (obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('hidden') == 'true') continue;
1548 if (typeof obj.columns[j] == 'undefined') {
1549 dump('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n');
1550 dump('_dump_tree_selection_with_keys @ ' + location.href + '\n');
1551 dump('\ttreerow.childNodes.length='+treerow.childNodes.length+' j='+j+' obj.columns.length='+obj.columns.length+'\n');
1554 var id = obj.columns[j].id; if (params.labels_instead_of_ids) id = obj.columns[j].label;
1563 'clipboard' : function(params) {
1566 var dump = obj.dump_selected_with_keys({'skip_hidden_columns':true,'labels_instead_of_ids':true});
1567 obj.data.stash_retrieve();
1568 obj.data.list_clipboard = dump; obj.data.stash('list_clipboard');
1569 JSAN.use('util.window'); var win = new util.window();
1570 win.open(urls.XUL_LIST_CLIPBOARD,'list_clipboard','chrome,resizable,modal');
1571 window.focus(); // sometimes the main window will lower after a clipboard action
1573 this.error.standard_unexpected_error_alert('clipboard',E);
1577 'dump_retrieve_ids' : function(params) {
1579 switch(this.node.nodeName) {
1580 case 'tree' : return this._dump_retrieve_ids_tree(params); break;
1581 default: throw('NYI: Need .dump_retrieve_ids() for ' + this.node.nodeName); break;
1585 '_dump_retrieve_ids_tree' : function(params) {
1588 for (var i = 0; i < this.treechildren.childNodes.length; i++) {
1589 var treeitem = this.treechildren.childNodes[i];
1590 dump.push( treeitem.getAttribute('retrieve_id') );
1595 'wrap_in_full_retrieve' : function(f) {
1597 if (typeof obj.on_all_fleshed == 'function') { // legacy
1598 obj.on_all_fleshed = [ obj.on_all_fleshed ];
1600 if (! obj.on_all_fleshed) obj.on_all_fleshed = [];
1601 obj.on_all_fleshed.push(f);
1602 obj.full_retrieve();
1605 '_sort_tree' : function() {
1608 if (obj.node.getAttribute('no_sort')) {
1612 var sorts = [ obj.first_sort ].concat( obj.sub_sorts );
1613 var columns = util.functional.map_list(
1619 var column_positions = [];
1620 for (var i = 0; i < columns.length; i++) {
1621 for (var j = 0; j < obj.columns.length; j++) {
1622 if (obj.columns[j].id == columns[i].id) {
1623 column_positions.push( function(a){return a;}(j) );
1627 obj.wrap_in_full_retrieve(
1630 JSAN.use('util.money');
1632 var treeitems = obj.treechildren.childNodes;
1633 for (var i = 0; i < treeitems.length; i++) {
1634 var treeitem = treeitems[i];
1635 var treerow = treeitem.firstChild;
1637 function get_value(treecell) {
1640 ? treecell.getAttribute('label')
1642 'sort_value' : treecell ? treecell.hasAttribute('sort_value')
1644 treecell.getAttribute('sort_value'))
1651 for (var j = 0; j < column_positions.length; j++) {
1652 var treecell = treerow.childNodes[ column_positions[j] ];
1654 'position' : column_positions[j],
1655 'value' : get_value(treecell)
1664 rows = rows.sort( function(A,B) {
1665 function normalize(a,b,p) {
1672 if (obj.columns[p].getAttribute('sort_type')) {
1673 switch(obj.columns[p].getAttribute('sort_type')) {
1675 JSAN.use('util.date'); // to pull in dojo.date.locale
1676 a = dojo.date.locale.parse(a,{});
1677 b = dojo.date.locale.parse(b,{});
1680 a = Number(a); b = Number(b);
1683 a = util.money.dollars_float_to_cents_integer(a);
1684 b = util.money.dollars_float_to_cents_integer(b);
1686 case 'title' : /* special case for "a" and "the". doesn't use marc 245 indicator */
1687 a = String( a ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
1688 b = String( b ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
1691 a = String( a ).toUpperCase();
1692 b = String( b ).toUpperCase();
1696 if (typeof a == 'string' || typeof b == 'string') {
1697 a = String( a ).toUpperCase();
1698 b = String( b ).toUpperCase();
1705 for (var i = 0; i < sorts.length; i++) {
1707 if (sorts[i].sortDir == 'asc') {
1709 B['values'][i]['value'],
1710 A['values'][i]['value'],
1711 A['values'][i]['position']
1715 A['values'][i]['value'],
1716 B['values'][i]['value'],
1717 A['values'][i]['position']
1720 if (values[0] < values[1] ) {
1723 if (values[0] > values[1] ) {
1729 while(obj.treechildren.lastChild) obj.treechildren.removeChild( obj.treechildren.lastChild );
1730 for (var i = 0; i < rows.length; i++) {
1731 obj.treechildren.appendChild( rows[i].node );
1733 if (typeof obj.on_sort == 'function') obj.on_sort();
1735 obj.error.standard_unexpected_error_alert('sorting',E);
1737 obj.refresh_ordinals();
1741 obj.error.standard_unexpected_error_alert('pre sorting', E);
1745 '_toggle_checkbox_column' : function(col,toggle) {
1748 if (obj.node.getAttribute('no_toggle')) {
1752 for (var i = 0; i < obj.columns.length; i++) {
1753 if (obj.columns[i].id == col.id) col_pos = function(a){return a;}(i);
1755 var treeitems = obj.treechildren.childNodes;
1756 for (var i = 0; i < treeitems.length; i++) {
1757 var treeitem = treeitems[i];
1758 var treerow = treeitem.firstChild;
1759 var treecell = treerow.childNodes[ col_pos ];
1760 treecell.setAttribute('value',(toggle == 'on'));
1762 if (typeof obj.on_checkbox_toggle == 'function') obj.on_checkbox_toggle(toggle);
1764 obj.error.standard_unexpected_error_alert('pre toggle', E);
1768 'render_list_actions' : function(params) {
1770 switch(this.node.nodeName) {
1771 case 'tree' : return this._render_list_actions_for_tree(params); break;
1772 default: throw('NYI: Need ._render_list_actions() for ' + this.node.nodeName); break;
1776 '_render_list_actions_for_tree' : function(params) {
1779 var btn = document.createElement('button');
1780 btn.setAttribute('id',obj.node.id + '_list_actions');
1781 btn.setAttribute('type','menu');
1782 btn.setAttribute('allowevents','true');
1783 //btn.setAttribute('oncommand','this.firstChild.showPopup();');
1784 btn.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.menu.label'));
1785 btn.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.menu.accesskey'));
1786 var mp = document.createElement('menupopup');
1787 btn.appendChild(mp);
1788 var mi = document.createElement('menuitem');
1789 mi.setAttribute('id',obj.node.id + '_clipfield');
1790 mi.setAttribute('disabled','true');
1791 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.field_to_clipboard.label'));
1792 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.field_to_clipboard.accesskey'));
1794 mi = document.createElement('menuitem');
1795 mi.setAttribute('id',obj.node.id + '_csv_to_clipboard');
1796 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_clipboard.label'));
1797 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_clipboard.accesskey'));
1799 mi = document.createElement('menuitem');
1800 mi.setAttribute('id',obj.node.id + '_csv_to_printer');
1801 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_printer.label'));
1802 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_printer.accesskey'));
1804 mi = document.createElement('menuitem');
1805 mi.setAttribute('id',obj.node.id + '_extended_to_printer');
1806 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.extended_to_printer.label'));
1807 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.extended_to_printer.accesskey'));
1809 mi = document.createElement('menuitem');
1810 mi.setAttribute('id',obj.node.id + '_csv_to_file');
1811 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_file.label'));
1812 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_file.accesskey'));
1814 mi = document.createElement('menuitem');
1815 mi.setAttribute('id',obj.node.id + '_save_columns');
1816 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.save_column_configuration.label'));
1817 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.save_column_configuration.accesskey'));
1818 if (obj.data.hash.aous['gui.disable_local_save_columns']) {
1819 mi.setAttribute('disabled','true');
1824 obj.error.standard_unexpected_error_alert('rendering list actions',E);
1828 'set_list_actions' : function(params) {
1830 switch(this.node.nodeName) {
1831 case 'tree' : return this._set_list_actions_for_tree(params); break;
1832 default: throw('NYI: Need ._set_list_actions() for ' + this.node.nodeName); break;
1836 '_set_list_actions_for_tree' : function(params) {
1837 // This should be called after the button element from render_list_actions has been appended to the DOM
1840 var x = document.getElementById(obj.node.id + '_clipfield');
1845 obj.clipboard(params);
1846 if (params && typeof params.on_complete == 'function') {
1847 params.on_complete(params);
1853 x = document.getElementById(obj.node.id + '_csv_to_clipboard');
1858 obj.dump_csv_to_clipboard(params);
1859 if (params && typeof params.on_complete == 'function') {
1860 params.on_complete(params);
1866 x = document.getElementById(obj.node.id + '_csv_to_printer');
1871 obj.dump_csv_to_printer(params);
1872 if (params && typeof params.on_complete == 'function') {
1873 params.on_complete(params);
1879 x = document.getElementById(obj.node.id + '_extended_to_printer');
1884 obj.dump_extended_format_to_printer(params);
1885 if (params && typeof params.on_complete == 'function') {
1886 params.on_complete(params);
1893 x = document.getElementById(obj.node.id + '_csv_to_file');
1898 obj.dump_csv_to_file(params);
1899 if (params && typeof params.on_complete == 'function') {
1900 params.on_complete(params);
1906 x = document.getElementById(obj.node.id + '_save_columns');
1911 obj.save_columns(params);
1912 if (params && typeof params.on_complete == 'function') {
1913 params.on_complete(params);
1921 obj.error.standard_unexpected_error_alert('setting list actions',E);
1925 // Takes fieldmapper class name and attempts to spit out column definitions suitable for .init
1926 'fm_columns' : function(hint,column_extras,prefix) {
1929 if (!prefix) { prefix = ''; }
1931 // requires the dojo library fieldmapper.autoIDL
1932 if (typeof fieldmapper == 'undefined') { throw 'fieldmapper undefined'; }
1933 if (typeof fieldmapper.IDL == 'undefined') { throw 'fieldmapper.IDL undefined'; }
1934 if (typeof fieldmapper.IDL.fmclasses == 'undefined') { throw 'fieldmapper.IDL.fmclasses undefined'; }
1935 if (typeof fieldmapper.IDL.fmclasses[hint] == 'undefined') { throw 'fieldmapper.IDL.fmclasses.' + hint + ' undefined'; }
1936 var my_class = fieldmapper.IDL.fmclasses[hint];
1937 var data = obj.data; data.stash_retrieve();
1939 function col_def(my_field) {
1940 var col_id = prefix + hint + '_' + my_field.name;
1942 var datafield = my_field.name;
1943 var fleshed_display_field;
1944 if (column_extras) {
1945 if (column_extras['*']) {
1946 if (column_extras['*']['dataobj']) {
1947 dataobj = column_extras['*']['dataobj'];
1950 if (column_extras[col_id]) {
1951 if (column_extras[col_id]['dataobj']) {
1952 dataobj = column_extras[col_id]['dataobj'];
1954 if (column_extras[col_id]['datafield']) {
1955 datafield = column_extras[col_id]['datafield'];
1957 if (column_extras[col_id]['fleshed_display_field']) {
1958 fleshed_display_field = column_extras[col_id]['fleshed_display_field'];
1964 'label' : my_field.label || my_field.name,
1965 'sort_type' : [ 'int', 'float', 'id', 'number' ].indexOf(my_field.datatype) > -1 ? 'number' :
1966 ( my_field.datatype == 'money' ? 'money' :
1967 ( my_field.datatype == 'timestamp' ? 'date' : 'default')),
1968 'hidden' : my_field.virtual || my_field.datatype == 'link',
1971 // my_field.datatype => bool float id int interval link money number org_unit text timestamp
1972 if (my_field.datatype == 'link') {
1973 def.render = function(my) {
1974 // is the object fleshed?
1975 return my[dataobj][datafield]() && typeof my[dataobj][datafield]() == 'object'
1976 // yes, show the display field
1977 ? my[dataobj][datafield]()[fleshed_display_field||my_field.key]()
1978 // no, do we have its class in data.hash?
1979 : ( typeof data.hash[ my[dataobj].Structure.field_map[datafield].class ] != 'undefined'
1980 // yes, do we have this particular object cached?
1981 ? ( data.hash[ my[dataobj].Structure.field_map[datafield].class ][ my[dataobj][datafield]() ]
1982 // yes, show the display field
1983 ? data.hash[ my[dataobj].Structure.field_map[datafield].class ][ my[dataobj][datafield]() ][
1984 fleshed_display_field||my_field.key
1986 // no, just show the raw value
1987 : my[dataobj][datafield]()
1989 // no, just show the raw value
1990 : my[dataobj][datafield]()
1994 def.render = function(my) { return my[dataobj][datafield](); }
1996 if (my_field.datatype == 'timestamp') {
1997 JSAN.use('util.date');
1998 def.render = function(my) {
1999 return util.date.formatted_date( my[dataobj][datafield](), '%{localized}' );
2001 def.sort_value = function(my) {
2002 return util.date.db_date2Date( my[dataobj][datafield]() ).getTime();
2005 if (my_field.datatype == 'org_unit') {
2006 def.render = function(my) {
2007 return typeof my[dataobj][datafield]() == 'object' ? my[dataobj][datafield]().shortname() : data.hash.aou[ my[dataobj][datafield]() ].shortname();
2010 if (my_field.datatype == 'money') {
2011 JSAN.use('util.money');
2012 def.render = function(my) {
2013 return util.money.sanitize( my[dataobj][datafield]() );
2015 def.sort_value = function(my) {
2016 return util.money.dollars_float_to_cents_integer( my[dataobj][datafield]() );
2019 if (column_extras) {
2020 if (column_extras['*']) {
2021 for (var attr in column_extras['*']) {
2022 def[attr] = column_extras['*'][attr];
2024 if (column_extras['*']['expanded_label']) {
2025 def.label = my_class.label + ': ' + def.label;
2027 if (column_extras['*']['label_prefix']) {
2028 def.label = column_extras['*']['label_prefix'] + def.label;
2030 if (column_extras['*']['remove_virtual']) {
2031 if (my_field.virtual) {
2032 def.remove_me = true;
2036 if (column_extras[col_id]) {
2037 for (var attr in column_extras[col_id]) {
2038 def[attr] = column_extras[col_id][attr];
2040 if (column_extras[col_id]['keep_me']) {
2041 def.remove_me = false;
2043 if (column_extras[col_id]['label_prefix']) {
2044 def.label = column_extras[col_id]['label_prefix'] + def.label;
2048 if (def.remove_me) {
2049 dump('Skipping ' + def.label + '\n');
2052 dump('Defining ' + def.label + '\n');
2057 for (var i = 0; i < my_class.fields.length; i++) {
2058 var my_field = my_class.fields[i];
2059 var def = col_def(my_field);
2061 columns.push( def );
2066 obj.error.standard_unexpected_error_alert('fm_columns()',E);
2070 // Default for the map_row_to_columns function for .init
2071 'std_map_row_to_columns' : function(error_value) {
2072 return function(row,cols,scratch) {
2073 // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
2074 // cols contains all of the objects listed above in columns
2075 // scratch is a temporary space shared by all cells/rows (or just per row if not explicitly passed in)
2076 if (!scratch) { scratch = {}; }
2079 JSAN.use('util.error'); obj.error = new util.error();
2080 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
2081 JSAN.use('util.network'); obj.network = new util.network();
2082 JSAN.use('util.money');
2086 var sort_values = [];
2089 for (var i = 0; i < cols.length; i++) {
2090 switch (typeof cols[i].render) {
2091 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;
2092 case 'string' : cmd += 'try { ' + cols[i].render + '; values['+i+'] = v; } catch(E) { values['+i+'] = error_value; }'; break;
2093 default: cmd += 'values['+i+'] = "??? '+(typeof cols[i].render)+'"; ';
2095 switch (typeof cols[i].sort_value) {
2098 sort_values[i] = cols[i].sort_value(my,scratch);
2100 sort_values[i] = error_value;
2101 obj.error.sdump('D_COLUMN_RENDER_ERROR',E);
2106 + cols[i].sort_value
2109 +'] = v; } catch(E) { sort_values['
2111 + '] = error_value; }';
2114 cmd += 'sort_values['+i+'] = values[' + i + '];';
2117 if (cmd) eval( cmd );
2119 obj.error.sdump('D_WARN','map_row_to_column: ' + E);
2120 if (error_value) { value = error_value; } else { value = ' ' };
2122 return { 'values' : values, 'sort_values' : sort_values };
2126 dump('exiting util.list.js\n');