1 dump('entering util.list.js\n');
3 if (typeof main == 'undefined') main = {};
4 util.list = function (id) {
6 this.node = document.getElementById(id);
8 this.row_count = { 'total' : 0, 'fleshed' : 0 };
10 this.unique_row_counter = 0;
12 if (!this.node) throw('Could not find element ' + id);
13 switch(this.node.nodeName) {
17 throw(this.node.nodeName + ' not yet supported'); break;
18 default: throw(this.node.nodeName + ' not supported'); break;
21 JSAN.use('util.error'); this.error = new util.error();
23 JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.stash_retrieve();
28 util.list.prototype = {
30 'init' : function (params) {
33 obj.scratch_data = {};
35 JSAN.use('util.widgets');
37 obj.printer_context = params.printer_context;
39 if (typeof params.map_row_to_column == 'function') obj.map_row_to_column = params.map_row_to_column;
40 if (typeof params.map_row_to_columns == 'function') {
41 obj.map_row_to_columns = params.map_row_to_columns;
43 obj.map_row_to_columns = obj.std_map_row_to_columns();
45 if (typeof params.retrieve_row == 'function') obj.retrieve_row = params.retrieve_row;
48 if (typeof params.prebuilt != 'undefined') obj.prebuilt = params.prebuilt;
50 if (typeof params.columns == 'undefined') throw('util.list.init: No columns');
52 for (var i = 0; i < params.columns.length; i++) {
53 if (typeof params.columns[i] == 'object') {
54 obj.columns.push( params.columns[i] );
56 var cols = obj.fm_columns( params.columns[i] );
57 for (var j = 0; j < cols.length; j++) {
58 obj.columns.push( cols[j] );
63 switch(obj.node.nodeName) {
64 case 'tree' : obj._init_tree(params); break;
65 case 'listbox' : obj._init_listbox(params); break;
66 default: throw('NYI: Need ._init() for ' + obj.node.nodeName); break;
70 '_init_tree' : function (params) {
74 this.treechildren = this.node.lastChild;
77 var treecols = document.createElement('treecols');
78 this.node.appendChild(treecols);
79 this.treecols = treecols;
81 var check_for_id_collisions = {};
82 for (var i = 0; i < this.columns.length; i++) {
83 var treecol = document.createElement('treecol');
84 for (var j in this.columns[i]) {
85 var value = this.columns[i][j];
87 if (typeof check_for_id_collisions[value] == 'undefined') {
88 check_for_id_collisions[value] = true;
90 // Column id's are important for sorting and saving list configuration. Collisions started happening because
91 // we were using field names as id's, and then later combining column definitions for multiple objects that
92 // shared field names. The downside to this sort of automatic collision prevention is that these generated
93 // id's can change as we add and remove columns, possibly breaking saved list configurations.
94 dump('Column collision with id = ' + value + ', renaming to ');
95 value = value + '_collision_' + i;
99 treecol.setAttribute(j,value);
101 treecols.appendChild(treecol);
102 if (this.columns[i].type == 'checkbox') {
103 treecol.addEventListener(
108 var toggle = ev.target.getAttribute('toggleAll') || 'on';
109 if (toggle == 'off') toggle = 'on'; else toggle = 'off';
110 ev.target.setAttribute('toggleAll',toggle);
111 obj._toggle_checkbox_column(ev.target,toggle);
118 treecol.addEventListener(
122 var sortDir = ev.target.getAttribute('sortDir') || 'desc';
123 if (sortDir == 'desc') sortDir = 'asc'; else sortDir = 'desc';
124 ev.target.setAttribute('sortDir',sortDir);
125 obj._sort_tree(ev.target,sortDir);
128 if (obj.row_count.total != obj.row_count.fleshed && (obj.row_count.total - obj.row_count.fleshed) > 50) {
129 var r = window.confirm(document.getElementById('offlineStrings').getFormattedString('list.row_fetch_warning',[obj.row_count.fleshed,obj.row_count.total]));
132 setTimeout( do_it, 0 );
135 setTimeout( do_it, 0 );
141 var splitter = document.createElement('splitter');
142 splitter.setAttribute('class','tree-splitter');
143 treecols.appendChild(splitter);
146 var treechildren = document.createElement('treechildren');
147 this.node.appendChild(treechildren);
148 this.treechildren = treechildren;
150 if (typeof params.on_sort == 'function') {
151 this.on_sort = params.on_sort;
153 if (typeof params.on_checkbox_toggle == 'function') {
154 this.on_checkbox_toggle = params.on_checkbox_toggle;
156 this.node.addEventListener(
159 if (typeof params.on_select == 'function') {
160 params.on_select(ev);
162 var x = document.getElementById(obj.node.id + '_clipfield');
164 var sel = obj.retrieve_selection();
165 x.setAttribute('disabled', sel.length == 0);
170 if (typeof params.on_click == 'function') {
171 this.node.addEventListener(
178 this.node.addEventListener(
180 function(ev) { obj.detect_visible(); },
184 this.node.addEventListener(
186 function(ev) { obj.auto_retrieve(); },
189 this.node.addEventListener(
191 function(ev) { obj.auto_retrieve(); },
194 window.addEventListener(
196 function(ev) { obj.auto_retrieve(); },
199 /* FIXME -- find events on scrollbar to trigger this */
200 obj.detect_visible_polling();
202 var scrollbar = document.getAnonymousNodes( document.getAnonymousNodes(this.node)[1] )[1];
203 var slider = document.getAnonymousNodes( scrollbar )[2];
204 alert('scrollbar = ' + scrollbar.nodeName + ' grippy = ' + slider.nodeName);
205 scrollbar.addEventListener('click',function(){alert('sb click');},false);
206 scrollbar.addEventListener('command',function(){alert('sb command');},false);
207 scrollbar.addEventListener('scroll',function(){alert('sb scroll');},false);
208 slider.addEventListener('click',function(){alert('slider click');},false);
209 slider.addEventListener('command',function(){alert('slider command');},false);
210 slider.addEventListener('scroll',function(){alert('slider scroll');},false);
212 this.node.addEventListener('scroll',function(){ obj.auto_retrieve(); },false);
214 this.restores_columns(params);
217 '_init_listbox' : function (params) {
220 var listhead = document.createElement('listhead');
221 this.node.appendChild(listhead);
223 var listcols = document.createElement('listcols');
224 this.node.appendChild(listcols);
226 for (var i = 0; i < this.columns.length; i++) {
227 var listheader = document.createElement('listheader');
228 listhead.appendChild(listheader);
229 var listcol = document.createElement('listcol');
230 listcols.appendChild(listcol);
231 for (var j in this.columns[i]) {
232 listheader.setAttribute(j,this.columns[i][j]);
233 listcol.setAttribute(j,this.columns[i][j]);
239 'save_columns' : function (params) {
241 if (obj.data.hash.aous['gui.disable_local_save_columns']) {
242 alert(document.getElementById('offlineStrings').getString('list.column_save_disabled'));
244 switch (this.node.nodeName) {
245 case 'tree' : this._save_columns_tree(params); break;
246 default: throw('NYI: Need .save_columns() for ' + this.node.nodeName); break;
251 '_save_columns_tree' : function (params) {
254 var id = obj.node.getAttribute('id'); if (!id) {
255 alert("FIXME: The columns for this list cannot be saved because the list has no id.");
259 var nl = obj.node.getElementsByTagName('treecol');
260 for (var i = 0; i < nl.length; i++) {
262 var col_id = col.getAttribute('id');
264 alert('FIXME: A column in this list does not have an id and cannot be saved');
267 var col_hidden = col.getAttribute('hidden');
268 var col_width = col.getAttribute('width');
269 var col_ordinal = col.getAttribute('ordinal');
270 my_cols[ col_id ] = { 'hidden' : col_hidden, 'width' : col_width, 'ordinal' : col_ordinal };
272 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
273 JSAN.use('util.file'); var file = new util.file('tree_columns_for_'+window.escape(id));
274 file.set_object(my_cols);
276 alert(document.getElementById('offlineStrings').getString('list.columns_saved'));
278 obj.error.standard_unexpected_error_alert('_save_columns_tree',E);
282 'restores_columns' : function (params) {
284 switch (this.node.nodeName) {
285 case 'tree' : this._restores_columns_tree(params); break;
286 default: throw('NYI: Need .restores_columns() for ' + this.node.nodeName); break;
290 '_restores_columns_tree' : function (params) {
293 var id = obj.node.getAttribute('id'); if (!id) {
294 alert("FIXME: The columns for this list cannot be restored because the list has no id.");
299 if (! obj.data.hash.aous) { obj.data.hash.aous = {}; }
300 if (! obj.data.hash.aous['gui.disable_local_save_columns']) {
301 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
302 JSAN.use('util.file'); var file = new util.file('tree_columns_for_'+window.escape(id));
303 if (file._file.exists()) {
304 my_cols = file.get_object(); file.close();
307 /* local file will trump remote file if allowed, so save ourselves an http request if this is the case */
308 if (obj.data.hash.aous['url.remote_column_settings'] && ! my_cols ) {
310 var x = new XMLHttpRequest();
311 var url = obj.data.hash.aous['url.remote_column_settings'] + '/tree_columns_for_' + window.escape(id);
312 x.open("GET", url, false);
314 if (x.status == 200) {
315 my_cols = JSON2js( x.responseText );
318 // This can happen in the offline interface if you logged in previously and url.remote_column_settings is set.
319 // 1) You may be really "offline" now
320 // 2) the URL may just be a path component without a hostname (ie "/xul/column_settings/"), which won't work
321 // when appended to chrome://open_ils_staff_client/
322 dump('Error retrieving column settings from ' + url + ': ' + E + '\n');
327 var nl = obj.node.getElementsByTagName('treecol');
328 for (var i = 0; i < nl.length; i++) {
330 var col_id = col.getAttribute('id');
332 alert('FIXME: A column in this list does not have an id and cannot be saved');
335 if (typeof my_cols[col_id] != 'undefined') {
336 col.setAttribute('hidden',my_cols[col_id].hidden);
337 col.setAttribute('width',my_cols[col_id].width);
338 col.setAttribute('ordinal',my_cols[col_id].ordinal);
340 obj.error.sdump('D_ERROR','WARNING: Column ' + col_id + ' did not have a saved state.');
345 obj.error.standard_unexpected_error_alert('_restore_columns_tree',E);
349 'clear' : function (params) {
351 switch (this.node.nodeName) {
352 case 'tree' : this._clear_tree(params); break;
353 case 'listbox' : this._clear_listbox(params); break;
354 default: throw('NYI: Need .clear() for ' + this.node.nodeName); break;
356 this.error.sdump('D_LIST','Clearing list ' + this.node.getAttribute('id') + '\n');
357 this.row_count.total = 0;
358 this.row_count.fleshed = 0;
359 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
362 '_clear_tree' : function(params) {
364 if (obj.error.sdump_levels.D_LIST_DUMP_ON_CLEAR) {
365 obj.error.sdump('D_LIST_DUMP_ON_CLEAR',obj.dump());
367 if (obj.error.sdump_levels.D_LIST_DUMP_WITH_KEYS_ON_CLEAR) {
368 obj.error.sdump('D_LIST_DUMP_WITH_KEYS_ON_CLEAR',obj.dump_with_keys());
370 while (obj.treechildren.lastChild) obj.treechildren.removeChild( obj.treechildren.lastChild );
373 '_clear_listbox' : function(params) {
376 var nl = this.node.getElementsByTagName('listitem');
377 for (var i = 0; i < nl.length; i++) {
380 for (var i = 0; i < items.length; i++) {
381 this.node.removeChild(items[i]);
385 'append' : function (params) {
388 switch (this.node.nodeName) {
389 case 'tree' : rparams = this._append_to_tree(params); break;
390 case 'listbox' : rparams = this._append_to_listbox(params); break;
391 default: throw('NYI: Need .append() for ' + this.node.nodeName); break;
393 if (rparams && params.attributes) {
394 for (var i in params.attributes) {
395 rparams.my_node.setAttribute(i,params.attributes[i]);
398 this.row_count.total++;
399 if (this.row_count.fleshed == this.row_count.total) {
400 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
402 rparams.my_node.setAttribute('unique_row_counter',obj.unique_row_counter);
403 rparams.unique_row_counter = obj.unique_row_counter++;
404 if (typeof params.on_append == 'function') {
405 params.on_append(rparams);
410 'refresh_row' : function (params) {
413 switch (this.node.nodeName) {
414 case 'tree' : rparams = this._refresh_row_in_tree(params); break;
415 default: throw('NYI: Need .refresh_row() for ' + this.node.nodeName); break;
417 if (rparams && params.attributes) {
418 for (var i in params.attributes) {
419 rparams.my_node.setAttribute(i,params.attributes[i]);
422 this.row_count.fleshed--;
427 '_append_to_tree' : function (params) {
431 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
433 var s = ('util.list.append: params = ' + (params) + '\n');
435 var treechildren_node = this.treechildren;
437 if (params.node && params.node.nodeName == 'treeitem') {
438 params.node.setAttribute('container','true'); /* params.node.setAttribute('open','true'); */
439 if (params.node.lastChild.nodeName == 'treechildren') {
440 treechildren_node = params.node.lastChild;
442 treechildren_node = document.createElement('treechildren');
443 params.node.appendChild(treechildren_node);
447 var treeitem = document.createElement('treeitem');
448 treeitem.setAttribute('retrieve_id',params.retrieve_id);
449 if (typeof params.to_bottom != 'undefined') {
450 treechildren_node.appendChild( treeitem );
451 if (typeof params.no_auto_select == 'undefined') {
452 if (!obj.auto_select_pending) {
453 obj.auto_select_pending = true;
454 setTimeout(function() {
455 dump('auto-selecting\n');
456 var idx = Number(obj.node.view.rowCount)-1;
457 try { obj.node.view.selection.select(idx); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); }
458 try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); }
459 obj.auto_select_pending = false;
460 try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(idx).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); }
465 if (treechildren_node.firstChild) {
466 treechildren_node.insertBefore( treeitem, treechildren_node.firstChild );
468 treechildren_node.appendChild( treeitem );
470 if (typeof params.no_auto_select == 'undefined') {
471 if (!obj.auto_select_pending) {
472 obj.auto_select_pending = true;
473 setTimeout(function() {
474 try { obj.node.view.selection.select(0); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); }
475 try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); }
476 obj.auto_select_pending = false;
477 try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(0).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); }
482 var treerow = document.createElement('treerow');
483 treeitem.appendChild( treerow );
484 treerow.setAttribute('retrieve_id',params.retrieve_id);
485 if (params.row_properties) treerow.setAttribute('properties',params.row_properties);
487 s += ('tree = ' + this.node + ' treechildren = ' + treechildren_node + '\n');
488 s += ('treeitem = ' + treeitem + ' treerow = ' + treerow + '\n');
490 obj.put_retrieving_label(treerow);
492 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
493 treerow.addEventListener(
497 if (treerow.getAttribute('retrieved') == 'true') return; /* already running */
499 treerow.setAttribute('retrieved','true');
501 //dump('fleshing = ' + params.retrieve_id + '\n');
503 function inc_fleshed() {
504 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
505 treerow.setAttribute('fleshed','true');
506 obj.row_count.fleshed++;
507 if (obj.row_count.fleshed >= obj.row_count.total) {
508 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
512 params.row_node = treeitem;
513 params.on_retrieve = function(p) {
516 obj._map_row_to_treecell(p,treerow);
518 var idx = obj.node.contentView.getIndexOfItem( params.row_node );
519 dump('idx = ' + idx + '\n');
520 // if current row is selected, send another select event to re-sync data that the client code fetches on selects
521 if ( obj.node.view.selection.isSelected( idx ) ) {
522 dump('dispatching select event for on_retrieve for idx = ' + idx + '\n');
523 util.widgets.dispatch('select',obj.node);
526 // Let's not alert on this for now. Getting contentView has no properties in record buckets under certain conditions
527 dump('fixme2: ' + E + '\n');
531 if (typeof params.retrieve_row == 'function') {
533 params.retrieve_row( params );
535 } else if (typeof obj.retrieve_row == 'function') {
537 obj.retrieve_row( params );
546 if (typeof params.flesh_immediately != 'undefined') {
547 if (params.flesh_immediately) {
550 util.widgets.dispatch('flesh',treerow);
556 treerow.addEventListener(
559 //dump('fleshing anon\n');
560 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
561 obj._map_row_to_treecell(params,treerow);
562 treerow.setAttribute('retrieved','true');
563 treerow.setAttribute('fleshed','true');
564 obj.row_count.fleshed++;
565 if (obj.row_count.fleshed >= obj.row_count.total) {
566 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
571 if (typeof params.flesh_immediately != 'undefined') {
572 if (params.flesh_immediately) {
575 util.widgets.dispatch('flesh',treerow);
581 this.error.sdump('D_LIST',s);
585 if (obj.trim_list && obj.row_count.total >= obj.trim_list) {
587 //if (typeof params.to_bottom != 'undefined')
588 if (typeof params.to_top == 'undefined') {
589 if (typeof params.on_delete == 'function') { params.on_delete( treechildren_node.firstChild.getAttribute('unique_row_counter') ); }
590 treechildren_node.removeChild( treechildren_node.firstChild );
592 if (typeof params.on_delete == 'function') { params.on_delete( treechildren_node.lastChild.getAttribute('unique_row_counter') ); }
593 treechildren_node.removeChild( treechildren_node.lastChild );
599 setTimeout( function() { obj.auto_retrieve(); }, 0 );
601 params.my_node = treeitem;
605 '_refresh_row_in_tree' : function (params) {
609 if (typeof params.row == 'undefined') throw('util.list.refresh_row: Object must contain a row');
610 if (typeof params.my_node == 'undefined') throw('util.list.refresh_row: Object must contain a my_node');
611 if (params.my_node.nodeName != 'treeitem') throw('util.list.refresh_rwo: my_node must be a treeitem');
613 var s = ('util.list.refresh_row: params = ' + (params) + '\n');
615 var treeitem = params.my_node;
616 treeitem.setAttribute('retrieve_id',params.retrieve_id);
617 if (typeof params.to_bottom != 'undefined') {
618 if (typeof params.no_auto_select == 'undefined') {
619 if (!obj.auto_select_pending) {
620 obj.auto_select_pending = true;
621 setTimeout(function() {
622 dump('auto-selecting\n');
623 var idx = Number(obj.node.view.rowCount)-1;
624 try { obj.node.view.selection.select(idx); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); }
625 try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); }
626 obj.auto_select_pending = false;
627 try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(idx).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); }
632 //var delete_me = [];
633 //for (var i in treeitem.childNodes) if (treeitem.childNodes[i].nodeName == 'treerow') delete_me.push(treeitem.childNodes[i]);
634 //for (var i = 0; i < delete_me.length; i++) treeitem.removeChild(delete_me[i]);
635 var prev_treerow = treeitem.firstChild; /* FIXME: worry about hierarchal lists like copy_browser? */
636 var treerow = document.createElement('treerow');
637 while (prev_treerow.firstChild) {
638 treerow.appendChild( prev_treerow.removeChild( prev_treerow.firstChild ) );
640 treeitem.replaceChild( treerow, prev_treerow );
641 treerow.setAttribute('retrieve_id',params.retrieve_id);
642 if (params.row_properties) treerow.setAttribute('properties',params.row_properties);
644 s += ('tree = ' + this.node.nodeName + '\n');
645 s += ('treeitem = ' + treeitem.nodeName + ' treerow = ' + treerow.nodeName + '\n');
647 obj.put_retrieving_label(treerow);
649 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
651 s += 'found a retrieve_row function\n';
653 treerow.addEventListener(
657 if (treerow.getAttribute('retrieved') == 'true') return; /* already running */
659 treerow.setAttribute('retrieved','true');
661 //dump('fleshing = ' + params.retrieve_id + '\n');
663 function inc_fleshed() {
664 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
665 treerow.setAttribute('fleshed','true');
666 obj.row_count.fleshed++;
667 if (obj.row_count.fleshed >= obj.row_count.total) {
668 setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 );
672 params.row_node = treeitem;
673 params.on_retrieve = function(p) {
676 obj._map_row_to_treecell(p,treerow);
678 var idx = obj.node.contentView.getIndexOfItem( params.row_node );
679 dump('idx = ' + idx + '\n');
680 // if current row is selected, send another select event to re-sync data that the client code fetches on selects
681 if ( obj.node.view.selection.isSelected( idx ) ) {
682 dump('dispatching select event for on_retrieve for idx = ' + idx + '\n');
683 util.widgets.dispatch('select',obj.node);
686 // Let's not alert on this for now. Getting contentView has no properties in record buckets under certain conditions
687 dump('fixme2: ' + E + '\n');
691 if (typeof params.retrieve_row == 'function') {
693 params.retrieve_row( params );
695 } else if (typeof obj.retrieve_row == 'function') {
697 obj.retrieve_row( params );
706 if (typeof params.flesh_immediately != 'undefined') {
707 if (params.flesh_immediately) {
710 util.widgets.dispatch('flesh',treerow);
718 s += 'did not find a retrieve_row function\n';
720 treerow.addEventListener(
723 //dump('fleshing anon\n');
724 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
725 obj._map_row_to_treecell(params,treerow);
726 treerow.setAttribute('retrieved','true');
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 );
735 if (typeof params.flesh_immediately != 'undefined') {
736 if (params.flesh_immediately) {
739 util.widgets.dispatch('flesh',treerow);
749 if (obj.trim_list && obj.row_count.total >= obj.trim_list) {
751 //if (typeof params.to_bottom != 'undefined')
752 if (typeof params.to_top == 'undefined') {
753 treechildren_node.removeChild( treechildren_node.firstChild );
755 treechildren_node.removeChild( treechildren_node.lastChild );
761 setTimeout( function() { obj.auto_retrieve(); }, 0 );
763 JSAN.use('util.widgets'); util.widgets.dispatch('select',obj.node);
765 this.error.sdump('D_LIST',s);
770 'put_retrieving_label' : function(treerow) {
773 for (var i = 0; i < obj.columns.length; i++) {
775 if (typeof treerow.childNodes[i] == 'undefined') {
776 treecell = document.createElement('treecell');
777 treerow.appendChild(treecell);
779 treecell = treerow.childNodes[i];
781 treecell.setAttribute('label',document.getElementById('offlineStrings').getString('list.row_retrieving'));
784 alert('Error in list.js, put_retrieving_label(): ' + E);
788 'detect_visible' : function() {
791 //dump('detect_visible obj.node = ' + obj.node + '\n');
792 /* FIXME - this is a hack.. if the implementation of tree changes, this could break */
794 /*var s = ''; var A = document.getAnonymousNodes(obj.node);
797 s += '\t' + (typeof B.nodeName != 'undefined' ? B.nodeName : B ) + '\n';
798 if (typeof B.childNodes != 'undefined') for (var j = 0; j < B.childNodes.length; j++) {
799 var C = B.childNodes[j];
800 s += '\t\t' + C.nodeName + '\n';
803 obj.error.sdump('D_XULRUNNER','document.getAnonymousNodes(' + obj.node.nodeName + ') = \n' + s + '\n');*/
804 var scrollbar = document.getAnonymousNodes(obj.node)[2].firstChild;
805 var curpos = scrollbar.getAttribute('curpos');
806 var maxpos = scrollbar.getAttribute('maxpos');
807 //alert('curpos = ' + curpos + ' maxpos = ' + maxpos + ' obj.curpos = ' + obj.curpos + ' obj.maxpos = ' + obj.maxpos + '\n');
808 if ((curpos != obj.curpos) || (maxpos != obj.maxpos)) {
809 if ( obj.auto_retrieve() > 0 ) {
810 obj.curpos = curpos; obj.maxpos = maxpos;
814 obj.error.sdump('D_XULRUNNER', 'List implementation changed? ' + E);
816 } catch(E) { obj.error.sdump('D_ERROR',E); }
819 'detect_visible_polling' : function() {
821 //alert('detect_visible_polling');
823 obj.detect_visible();
824 setTimeout(function() { try { obj.detect_visible_polling(); } catch(E) { alert(E); } },2000);
831 'auto_retrieve' : function(params) {
833 switch (this.node.nodeName) {
834 case 'tree' : obj._auto_retrieve_tree(params); break;
835 default: throw('NYI: Need .auto_retrieve() for ' + obj.node.nodeName); break;
839 '_auto_retrieve_tree' : function (params) {
841 if (!obj.auto_retrieve_in_progress) {
842 obj.auto_retrieve_in_progress = true;
846 //alert('auto_retrieve\n');
848 var startpos = obj.node.treeBoxObject.getFirstVisibleRow();
849 var endpos = obj.node.treeBoxObject.getLastVisibleRow();
850 if (startpos > endpos) endpos = obj.node.treeBoxObject.getPageLength();
851 //dump('startpos = ' + startpos + ' endpos = ' + endpos + '\n');
852 for (var i = startpos; i < endpos + 4; i++) {
854 //dump('trying index ' + i + '\n');
855 var item = obj.node.contentView.getItemAtIndex(i).firstChild;
856 if (item && item.getAttribute('retrieved') != 'true' ) {
857 //dump('\tgot an unfleshed item = ' + item + ' = ' + item.nodeName + '\n');
858 util.widgets.dispatch('flesh',item); count++;
861 //dump(i + ' : ' + E + '\n');
864 obj.auto_retrieve_in_progress = false;
866 } catch(E) { alert(E); }
872 'exec_on_all_fleshed' : function() {
875 if (obj.on_all_fleshed) {
876 if (typeof obj.on_all_fleshed == 'function') {
877 dump('exec_on_all_fleshed == function\n');
880 try { obj.on_all_fleshed(); } catch(E) { obj.error.standard_unexpected_error_alert('_full_retrieve_tree callback',obj.on_all_fleshed); }
883 } else if (typeof obj.on_all_fleshed.length != 'undefined') {
884 dump('exec_on_all_fleshed == array\n');
888 dump('exec_on_all_fleshed, processing on_all_fleshed array, length = ' + obj.on_all_fleshed.length + '\n');
889 var f = obj.on_all_fleshed.pop();
890 if (typeof f == 'function') {
891 try { f(); } catch(E) { obj.error.standard_unexpected_error_alert('_full_retrieve_tree callback',f); }
893 if (obj.on_all_fleshed.length > 0) arguments.callee();
895 obj.error.standard_unexpected_error_alert('exec_on_all_fleshed callback error',E);
900 obj.error.standard_unexpected_error_alert('unexpected on_all_fleshed object: ', obj.on_all_fleshed);
904 obj.error.standard_unexpected_error_alert('exec_on_all-fleshed error',E);
908 'full_retrieve' : function(params) {
910 switch (this.node.nodeName) {
911 case 'tree' : obj._full_retrieve_tree(params); break;
912 default: throw('NYI: Need .full_retrieve() for ' + obj.node.nodeName); break;
916 '_full_retrieve_tree' : function(params) {
919 if (obj.row_count.fleshed >= obj.row_count.total) {
920 dump('Full retrieve... tree seems to be in sync\n' + js2JSON(obj.row_count) + '\n');
921 obj.exec_on_all_fleshed();
923 dump('Full retrieve... syncing tree' + js2JSON(obj.row_count) + '\n');
924 JSAN.use('util.widgets');
925 var nodes = obj.treechildren.childNodes;
926 for (var i = 0; i < nodes.length; i++) {
927 util.widgets.dispatch('flesh',nodes[i].firstChild);
931 obj.error.standard_unexpected_error_alert('_full_retrieve_tree',E);
935 '_append_to_listbox' : function (params) {
939 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
941 var s = ('util.list.append: params = ' + (params) + '\n');
943 var listitem = document.createElement('listitem');
945 s += ('listbox = ' + this.node + ' listitem = ' + listitem + '\n');
947 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
951 listitem.setAttribute('retrieve_id',params.retrieve_id);
952 //FIXME//Make async and fire when row is visible in list
955 params.row_node = listitem;
956 params.on_retrieve = function(row) {
958 obj._map_row_to_listcell(params,listitem);
959 obj.node.appendChild( listitem );
960 util.widgets.dispatch('select',obj.node);
963 if (typeof params.retrieve_row == 'function') {
965 row = params.retrieve_row( params );
969 if (typeof obj.retrieve_row == 'function') {
971 row = obj.retrieve_row( params );
978 this._map_row_to_listcell(params,listitem);
979 this.node.appendChild( listitem );
982 this.error.sdump('D_LIST',s);
983 params.my_node = listitem;
988 '_map_row_to_treecell' : function(params,treerow) {
992 if (typeof params.map_row_to_column == 'function' || typeof this.map_row_to_column == 'function') {
994 for (var i = 0; i < this.columns.length; i++) {
996 if (typeof treerow.childNodes[i] == 'undefined') {
997 treecell = document.createElement('treecell');
998 treerow.appendChild( treecell );
1000 treecell = treerow.childNodes[i];
1003 if ( this.columns[i].editable == false ) { treecell.setAttribute('editable','false'); }
1006 // What skip columns is doing is rendering the treecells as blank/empty
1007 if (params.skip_columns && (params.skip_columns.indexOf(i) != -1)) {
1008 treecell.setAttribute('label',label);
1009 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
1012 if (params.skip_all_columns_except && (params.skip_all_columns_except.indexOf(i) == -1)) {
1013 treecell.setAttribute('label',label);
1014 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
1018 if (typeof params.map_row_to_column == 'function') {
1020 label = params.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1022 } else if (typeof this.map_row_to_column == 'function') {
1024 label = this.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1027 if (this.columns[i].type == 'checkbox') { treecell.setAttribute('value',label); } else { treecell.setAttribute('label',label ? label : ''); }
1028 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
1030 } else if (typeof params.map_row_to_columns == 'function' || typeof this.map_row_to_columns == 'function') {
1034 if (typeof params.map_row_to_columns == 'function') {
1036 labels = params.map_row_to_columns(params.row,this.columns,this.scratch_data);
1038 } else if (typeof this.map_row_to_columns == 'function') {
1040 labels = this.map_row_to_columns(params.row,this.columns,this.scratch_data);
1043 for (var i = 0; i < labels.length; i++) {
1045 if (typeof treerow.childNodes[i] == 'undefined') {
1046 treecell = document.createElement('treecell');
1047 treerow.appendChild(treecell);
1049 treecell = treerow.childNodes[i];
1051 if ( this.columns[i].editable == false ) { treecell.setAttribute('editable','false'); }
1052 if ( this.columns[i].type == 'checkbox') {
1053 treecell.setAttribute('value', labels[i]);
1055 treecell.setAttribute('label',typeof labels[i] == 'string' || typeof labels[i] == 'number' ? labels[i] : '');
1057 s += ('treecell = ' + treecell + ' with label = ' + labels[i] + '\n');
1062 throw('No row to column mapping function.');
1064 this.error.sdump('D_LIST',s);
1067 '_map_row_to_listcell' : function(params,listitem) {
1070 for (var i = 0; i < this.columns.length; i++) {
1072 if (typeof params.map_row_to_column == 'function') {
1074 value = params.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1078 if (typeof this.map_row_to_column == 'function') {
1080 value = this.map_row_to_column(params.row,this.columns[i],this.scratch_data);
1083 if (typeof value == 'string' || typeof value == 'number') {
1084 var listcell = document.createElement('listcell');
1085 listcell.setAttribute('label',value);
1086 listitem.appendChild(listcell);
1087 s += ('listcell = ' + listcell + ' with label = ' + value + '\n');
1089 listitem.appendChild(value);
1090 s += ('listcell = ' + value + ' is really a ' + value.nodeName + '\n');
1093 this.error.sdump('D_LIST',s);
1096 'select_all' : function(params) {
1098 switch(this.node.nodeName) {
1099 case 'tree' : return this._select_all_from_tree(params); break;
1100 default: throw('NYI: Need ._select_all_from_() for ' + this.node.nodeName); break;
1104 '_select_all_from_tree' : function(params) {
1106 this.node.view.selection.selectAll();
1109 'retrieve_selection' : function(params) {
1111 switch(this.node.nodeName) {
1112 case 'tree' : return this._retrieve_selection_from_tree(params); break;
1113 default: throw('NYI: Need ._retrieve_selection_from_() for ' + this.node.nodeName); break;
1117 '_retrieve_selection_from_tree' : function(params) {
1120 var start = new Object();
1121 var end = new Object();
1122 var numRanges = this.node.view.selection.getRangeCount();
1123 for (var t=0; t<numRanges; t++){
1124 this.node.view.selection.getRangeAt(t,start,end);
1125 for (var v=start.value; v<=end.value; v++){
1126 var i = this.node.contentView.getItemAtIndex(v);
1133 'dump' : function(params) {
1135 switch(this.node.nodeName) {
1136 case 'tree' : return this._dump_tree(params); break;
1137 default: throw('NYI: Need .dump() for ' + this.node.nodeName); break;
1141 '_dump_tree' : function(params) {
1144 for (var i = 0; i < this.treechildren.childNodes.length; i++) {
1146 var treeitem = this.treechildren.childNodes[i];
1147 var treerow = treeitem.firstChild;
1148 for (var j = 0; j < treerow.childNodes.length; j++) {
1149 row.push( treerow.childNodes[j].getAttribute('label') );
1156 'dump_with_keys' : function(params) {
1158 switch(this.node.nodeName) {
1159 case 'tree' : return this._dump_tree_with_keys(params); break;
1160 default: throw('NYI: Need .dump_with_keys() for ' + this.node.nodeName); break;
1165 '_dump_tree_with_keys' : function(params) {
1169 function process_tree(treechildren) {
1170 for (var i = 0; i < treechildren.childNodes.length; i++) {
1172 var treeitem = treechildren.childNodes[i];
1173 var treerow = treeitem.firstChild;
1174 for (var j = 0; j < treerow.childNodes.length; j++) {
1175 if (typeof obj.columns[j] == 'undefined') {
1176 dump('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n');
1177 dump('_dump_tree_with_keys @ ' + location.href + '\n');
1178 dump('\ttreerow.childNodes.length='+treerow.childNodes.length+' j='+j+' obj.columns.length='+obj.columns.length+'\n');
1181 row[ obj.columns[j].id ] = treerow.childNodes[j].getAttribute('label');
1185 if (treeitem.childNodes.length > 1) {
1186 process_tree(treeitem.lastChild);
1191 process_tree(this.treechildren);
1196 'dump_csv' : function(params) {
1198 switch(this.node.nodeName) {
1199 case 'tree' : return this._dump_tree_csv(params); break;
1200 default: throw('NYI: Need .dump_csv() for ' + this.node.nodeName); break;
1205 '_dump_tree_csv' : function(params) {
1209 for (var j = 0; j < obj.columns.length; j++) {
1210 if (obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('hidden') == 'true') {
1213 ord_cols.push( [ obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('ordinal'), j ] );
1216 ord_cols.sort( function(a,b) {
1217 if ( Number( a[0] ) < Number( b[0] ) ) return -1;
1218 if ( Number( a[0] ) > Number( b[0] ) ) return 1;
1221 for (var j = 0; j < ord_cols.length; j++) {
1222 if (_dump) _dump += ',';
1223 _dump += '"' + obj.columns[ ord_cols[j][1] ].label.replace(/"/g, '""') + '"';
1227 function process_tree(treechildren) {
1228 for (var i = 0; i < treechildren.childNodes.length; i++) {
1230 var treeitem = treechildren.childNodes[i];
1231 var treerow = treeitem.firstChild;
1232 for (var j = 0; j < ord_cols.length; j++) {
1233 if (row) row += ',';
1234 row += '"' + treerow.childNodes[ ord_cols[j][1] ].getAttribute('label').replace(/"/g, '""') + '"';
1236 _dump += row + '\r\n';
1237 if (treeitem.childNodes.length > 1) {
1238 process_tree(treeitem.lastChild);
1243 process_tree(this.treechildren);
1248 'dump_extended_format' : function(params) {
1250 switch(this.node.nodeName) {
1251 case 'tree' : return this._dump_tree_extended_format(params); break;
1252 default: throw('NYI: Need .dump_extended_format() for ' + this.node.nodeName); break;
1257 '_dump_tree_extended_format' : function(params) {
1261 for (var j = 0; j < obj.columns.length; j++) {
1262 if (obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('hidden') == 'true') {
1265 ord_cols.push( [ obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('ordinal'), j ] );
1268 ord_cols.sort( function(a,b) {
1269 if ( Number( a[0] ) < Number( b[0] ) ) return -1;
1270 if ( Number( a[0] ) > Number( b[0] ) ) return 1;
1274 function process_tree(treechildren) {
1275 for (var i = 0; i < treechildren.childNodes.length; i++) {
1276 var row = document.getElementById('offlineStrings').getString('list.dump_extended_format.record_separator') + '\r\n';
1277 var treeitem = treechildren.childNodes[i];
1278 var treerow = treeitem.firstChild;
1279 for (var j = 0; j < ord_cols.length; j++) {
1280 row += obj.columns[ ord_cols[j][1] ].label + ': ' + treerow.childNodes[ ord_cols[j][1] ].getAttribute('label') + '\r\n';
1282 _dump += row + '\r\n';
1283 if (treeitem.childNodes.length > 1) {
1284 process_tree(treeitem.lastChild);
1289 process_tree(this.treechildren);
1294 'dump_csv_to_clipboard' : function(params) {
1296 if (typeof params == 'undefined') params = {};
1297 if (params.no_full_retrieve) {
1298 copy_to_clipboard( obj.dump_csv( params ) );
1300 obj.wrap_in_full_retrieve( function() { copy_to_clipboard( obj.dump_csv( params ) ); } );
1304 'dump_csv_to_printer' : function(params) {
1306 if (typeof params == 'undefined') params = {};
1307 JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context);
1308 if (params.no_full_retrieve) {
1309 print.simple( obj.dump_csv( params ), {'content_type':'text/plain'} );
1311 obj.wrap_in_full_retrieve(
1313 print.simple( obj.dump_csv( params ), {'content_type':'text/plain'} );
1319 'dump_extended_format_to_printer' : function(params) {
1321 if (typeof params == 'undefined') params = {};
1322 JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context);
1323 if (params.no_full_retrieve) {
1324 print.simple( obj.dump_extended_format( params ), {'content_type':'text/plain'} );
1326 obj.wrap_in_full_retrieve(
1328 print.simple( obj.dump_extended_format( params ), {'content_type':'text/plain'} );
1334 'dump_csv_to_file' : function(params) {
1336 JSAN.use('util.file'); var f = new util.file();
1337 if (typeof params == 'undefined') params = {};
1338 if (params.no_full_retrieve) {
1339 params.data = obj.dump_csv( params );
1340 params.not_json = true;
1341 if (!params.title) params.title = document.getElementById('offlineStrings').getString('list.save_csv_as');
1342 f.export_file( params );
1344 obj.wrap_in_full_retrieve(
1346 params.data = obj.dump_csv( params );
1347 params.not_json = true;
1348 if (!params.title) params.title = document.getElementById('offlineStrings').getString('list.save_csv_as');
1349 f.export_file( params );
1355 'print' : function(params) {
1356 if (!params) params = {};
1357 switch(this.node.nodeName) {
1358 case 'tree' : return this._print_tree(params); break;
1359 default: throw('NYI: Need ._print() for ' + this.node.nodeName); break;
1363 '_print_tree' : function(params) {
1366 var data = obj.data; data.stash_retrieve();
1367 if (!params.staff && data.list.au && data.list.au[0]) {
1368 params.staff = data.list.au[0];
1370 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() ]) {
1371 params.lib = data.hash.aou[ data.list.au[0].ws_ou() ];
1372 params.lib.children(null);
1374 if (params.template && data.print_list_templates[ params.template ]) {
1375 var template = data.print_list_templates[ params.template ];
1376 for (var i in template) params[i] = template[i];
1378 obj.wrap_in_full_retrieve(
1381 if (!params.list) params.list = obj.dump_with_keys();
1382 JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context);
1383 print.tree_list( params );
1384 if (typeof params.callback == 'function') params.callback();
1386 obj.error.standard_unexpected_error_alert('inner _print_tree',E);
1392 obj.error.standard_unexpected_error_alert('_print_tree',E);
1396 'dump_selected_with_keys' : function(params) {
1398 switch(this.node.nodeName) {
1399 case 'tree' : return this._dump_tree_selection_with_keys(params); break;
1400 default: throw('NYI: Need .dump_selection_with_keys() for ' + this.node.nodeName); break;
1405 '_dump_tree_selection_with_keys' : function(params) {
1408 var list = obj._retrieve_selection_from_tree();
1409 for (var i = 0; i < list.length; i++) {
1411 var treeitem = list[i];
1412 var treerow = treeitem.firstChild;
1413 for (var j = 0; j < treerow.childNodes.length; j++) {
1414 var value = treerow.childNodes[j].getAttribute('label');
1415 if (params.skip_hidden_columns) if (obj.node.treeBoxObject.columns.getColumnAt(j).element.getAttribute('hidden') == 'true') continue;
1416 if (typeof obj.columns[j] == 'undefined') {
1417 dump('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n');
1418 dump('_dump_tree_selection_with_keys @ ' + location.href + '\n');
1419 dump('\ttreerow.childNodes.length='+treerow.childNodes.length+' j='+j+' obj.columns.length='+obj.columns.length+'\n');
1422 var id = obj.columns[j].id; if (params.labels_instead_of_ids) id = obj.columns[j].label;
1431 'clipboard' : function(params) {
1434 var dump = obj.dump_selected_with_keys({'skip_hidden_columns':true,'labels_instead_of_ids':true});
1435 obj.data.stash_retrieve();
1436 obj.data.list_clipboard = dump; obj.data.stash('list_clipboard');
1437 JSAN.use('util.window'); var win = new util.window();
1438 win.open(urls.XUL_LIST_CLIPBOARD,'list_clipboard','chrome,resizable,modal');
1439 window.focus(); // sometimes the main window will lower after a clipboard action
1441 this.error.standard_unexpected_error_alert('clipboard',E);
1445 'dump_retrieve_ids' : function(params) {
1447 switch(this.node.nodeName) {
1448 case 'tree' : return this._dump_retrieve_ids_tree(params); break;
1449 default: throw('NYI: Need .dump_retrieve_ids() for ' + this.node.nodeName); break;
1453 '_dump_retrieve_ids_tree' : function(params) {
1456 for (var i = 0; i < this.treechildren.childNodes.length; i++) {
1457 var treeitem = this.treechildren.childNodes[i];
1458 dump.push( treeitem.getAttribute('retrieve_id') );
1463 'wrap_in_full_retrieve' : function(f) {
1465 if (typeof obj.on_all_fleshed == 'function') { // legacy
1466 obj.on_all_fleshed = [ obj.on_all_fleshed ];
1468 if (! obj.on_all_fleshed) obj.on_all_fleshed = [];
1469 obj.on_all_fleshed.push(f);
1470 obj.full_retrieve();
1473 '_sort_tree' : function(col,sortDir) {
1476 if (obj.node.getAttribute('no_sort')) {
1480 for (var i = 0; i < obj.columns.length; i++) {
1481 if (obj.columns[i].id == col.id) col_pos = function(a){return a;}(i);
1483 obj.wrap_in_full_retrieve(
1486 JSAN.use('util.money');
1488 var treeitems = obj.treechildren.childNodes;
1489 for (var i = 0; i < treeitems.length; i++) {
1490 var treeitem = treeitems[i];
1491 var treerow = treeitem.firstChild;
1492 var treecell = treerow.childNodes[ col_pos ];
1493 value = ( { 'value' : treecell ? treecell.getAttribute('label') : '', 'node' : treeitem } );
1496 rows = rows.sort( function(a,b) {
1497 a = a.value; b = b.value;
1498 if (col.getAttribute('sort_type')) {
1499 switch(col.getAttribute('sort_type')) {
1501 JSAN.use('util.date'); // to pull in dojo.date.locale
1502 a = dojo.date.locale.parse(a,{});
1503 b = dojo.date.locale.parse(b,{});
1506 a = Number(a); b = Number(b);
1509 a = util.money.dollars_float_to_cents_integer(a);
1510 b = util.money.dollars_float_to_cents_integer(b);
1512 case 'title' : /* special case for "a" and "the". doesn't use marc 245 indicator */
1513 a = String( a ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
1514 b = String( b ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
1517 a = String( a ).toUpperCase();
1518 b = String( b ).toUpperCase();
1522 if (typeof a == 'string' || typeof b == 'string') {
1523 a = String( a ).toUpperCase();
1524 b = String( b ).toUpperCase();
1527 //dump('sorting: type = ' + col.getAttribute('sort_type') + ' a = ' + a + ' b = ' + b + ' a<b= ' + (a<b) + ' a>b= ' + (a>b) + '\n');
1528 if (a < b) return -1;
1529 if (a > b) return 1;
1532 if (sortDir == 'asc') rows = rows.reverse();
1533 while(obj.treechildren.lastChild) obj.treechildren.removeChild( obj.treechildren.lastChild );
1534 for (var i = 0; i < rows.length; i++) {
1535 obj.treechildren.appendChild( rows[i].node );
1537 if (typeof obj.on_sort == 'function') obj.on_sort();
1539 obj.error.standard_unexpected_error_alert('sorting',E);
1544 obj.error.standard_unexpected_error_alert('pre sorting', E);
1548 '_toggle_checkbox_column' : function(col,toggle) {
1551 if (obj.node.getAttribute('no_toggle')) {
1555 for (var i = 0; i < obj.columns.length; i++) {
1556 if (obj.columns[i].id == col.id) col_pos = function(a){return a;}(i);
1558 var treeitems = obj.treechildren.childNodes;
1559 for (var i = 0; i < treeitems.length; i++) {
1560 var treeitem = treeitems[i];
1561 var treerow = treeitem.firstChild;
1562 var treecell = treerow.childNodes[ col_pos ];
1563 treecell.setAttribute('value',(toggle == 'on'));
1565 if (typeof obj.on_checkbox_toggle == 'function') obj.on_checkbox_toggle(toggle);
1567 obj.error.standard_unexpected_error_alert('pre toggle', E);
1571 'render_list_actions' : function(params) {
1573 switch(this.node.nodeName) {
1574 case 'tree' : return this._render_list_actions_for_tree(params); break;
1575 default: throw('NYI: Need ._render_list_actions() for ' + this.node.nodeName); break;
1579 '_render_list_actions_for_tree' : function(params) {
1582 var btn = document.createElement('button');
1583 btn.setAttribute('id',obj.node.id + '_list_actions');
1584 btn.setAttribute('type','menu');
1585 btn.setAttribute('allowevents','true');
1586 //btn.setAttribute('oncommand','this.firstChild.showPopup();');
1587 btn.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.menu.label'));
1588 btn.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.menu.accesskey'));
1589 var mp = document.createElement('menupopup');
1590 btn.appendChild(mp);
1591 var mi = document.createElement('menuitem');
1592 mi.setAttribute('id',obj.node.id + '_clipfield');
1593 mi.setAttribute('disabled','true');
1594 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.field_to_clipboard.label'));
1595 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.field_to_clipboard.accesskey'));
1597 mi = document.createElement('menuitem');
1598 mi.setAttribute('id',obj.node.id + '_csv_to_clipboard');
1599 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_clipboard.label'));
1600 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_clipboard.accesskey'));
1602 mi = document.createElement('menuitem');
1603 mi.setAttribute('id',obj.node.id + '_csv_to_printer');
1604 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_printer.label'));
1605 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_printer.accesskey'));
1607 mi = document.createElement('menuitem');
1608 mi.setAttribute('id',obj.node.id + '_extended_to_printer');
1609 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.extended_to_printer.label'));
1610 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.extended_to_printer.accesskey'));
1612 mi = document.createElement('menuitem');
1613 mi.setAttribute('id',obj.node.id + '_csv_to_file');
1614 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_file.label'));
1615 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_file.accesskey'));
1617 mi = document.createElement('menuitem');
1618 mi.setAttribute('id',obj.node.id + '_save_columns');
1619 mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.save_column_configuration.label'));
1620 mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.save_column_configuration.accesskey'));
1621 if (obj.data.hash.aous['gui.disable_local_save_columns']) {
1622 mi.setAttribute('disabled','true');
1627 obj.error.standard_unexpected_error_alert('rendering list actions',E);
1631 'set_list_actions' : function(params) {
1633 switch(this.node.nodeName) {
1634 case 'tree' : return this._set_list_actions_for_tree(params); break;
1635 default: throw('NYI: Need ._set_list_actions() for ' + this.node.nodeName); break;
1639 '_set_list_actions_for_tree' : function(params) {
1640 // This should be called after the button element from render_list_actions has been appended to the DOM
1643 var x = document.getElementById(obj.node.id + '_clipfield');
1648 obj.clipboard(params);
1649 if (params && typeof params.on_complete == 'function') {
1650 params.on_complete(params);
1656 x = document.getElementById(obj.node.id + '_csv_to_clipboard');
1661 obj.dump_csv_to_clipboard(params);
1662 if (params && typeof params.on_complete == 'function') {
1663 params.on_complete(params);
1669 x = document.getElementById(obj.node.id + '_csv_to_printer');
1674 obj.dump_csv_to_printer(params);
1675 if (params && typeof params.on_complete == 'function') {
1676 params.on_complete(params);
1682 x = document.getElementById(obj.node.id + '_extended_to_printer');
1687 obj.dump_extended_format_to_printer(params);
1688 if (params && typeof params.on_complete == 'function') {
1689 params.on_complete(params);
1696 x = document.getElementById(obj.node.id + '_csv_to_file');
1701 obj.dump_csv_to_file(params);
1702 if (params && typeof params.on_complete == 'function') {
1703 params.on_complete(params);
1709 x = document.getElementById(obj.node.id + '_save_columns');
1714 obj.save_columns(params);
1715 if (params && typeof params.on_complete == 'function') {
1716 params.on_complete(params);
1724 obj.error.standard_unexpected_error_alert('setting list actions',E);
1728 // Takes fieldmapper class name and attempts to spit out column definitions suitable for .init
1729 'fm_columns' : function(hint,column_extras,prefix) {
1732 if (!prefix) { prefix = ''; }
1734 // requires the dojo library fieldmapper.autoIDL
1735 if (typeof fieldmapper == 'undefined') { throw 'fieldmapper undefined'; }
1736 if (typeof fieldmapper.IDL == 'undefined') { throw 'fieldmapper.IDL undefined'; }
1737 if (typeof fieldmapper.IDL.fmclasses == 'undefined') { throw 'fieldmapper.IDL.fmclasses undefined'; }
1738 if (typeof fieldmapper.IDL.fmclasses[hint] == 'undefined') { throw 'fieldmapper.IDL.fmclasses.' + hint + ' undefined'; }
1739 var my_class = fieldmapper.IDL.fmclasses[hint];
1740 var data = obj.data; data.stash_retrieve();
1742 function col_def(my_field) {
1743 var col_id = prefix + hint + '_' + my_field.name;
1745 var datafield = my_field.name;
1746 var fleshed_display_field;
1747 if (column_extras) {
1748 if (column_extras['*']) {
1749 if (column_extras['*']['dataobj']) {
1750 dataobj = column_extras['*']['dataobj'];
1753 if (column_extras[col_id]) {
1754 if (column_extras[col_id]['dataobj']) {
1755 dataobj = column_extras[col_id]['dataobj'];
1757 if (column_extras[col_id]['datafield']) {
1758 datafield = column_extras[col_id]['datafield'];
1760 if (column_extras[col_id]['fleshed_display_field']) {
1761 fleshed_display_field = column_extras[col_id]['fleshed_display_field'];
1767 'label' : my_field.label || my_field.name,
1768 'sort_type' : [ 'int', 'float', 'id', 'number' ].indexOf(my_field.datatype) > -1 ? 'number' :
1769 ( my_field.datatype == 'money' ? 'money' :
1770 ( my_field.datatype == 'timestamp' ? 'date' : 'default')),
1771 'hidden' : my_field.virtual || my_field.datatype == 'link',
1774 // my_field.datatype => bool float id int interval link money number org_unit text timestamp
1775 if (my_field.datatype == 'link') {
1776 def.render = function(my) {
1777 // is the object fleshed?
1778 return my[dataobj][datafield]() && typeof my[dataobj][datafield]() == 'object'
1779 // yes, show the display field
1780 ? my[dataobj][datafield]()[fleshed_display_field||my_field.key]()
1781 // no, do we have its class in data.hash?
1782 : ( typeof data.hash[ my[dataobj].Structure.field_map[datafield].class ] != 'undefined'
1783 // yes, do we have this particular object cached?
1784 ? ( data.hash[ my[dataobj].Structure.field_map[datafield].class ][ my[dataobj][datafield]() ]
1785 // yes, show the display field
1786 ? data.hash[ my[dataobj].Structure.field_map[datafield].class ][ my[dataobj][datafield]() ][
1787 fleshed_display_field||my_field.key
1789 // no, just show the raw value
1790 : my[dataobj][datafield]()
1792 // no, just show the raw value
1793 : my[dataobj][datafield]()
1797 def.render = function(my) { return my[dataobj][datafield](); }
1799 if (my_field.datatype == 'timestamp') {
1800 JSAN.use('util.date');
1801 def.render = function(my) {
1802 return util.date.formatted_date( my[dataobj][datafield](), '%{localized}' );
1805 if (my_field.datatype == 'org_unit') {
1806 def.render = function(my) {
1807 return typeof my[dataobj][datafield]() == 'object' ? my[dataobj][datafield]().shortname() : data.hash.aou[ my[dataobj][datafield]() ].shortname();
1810 if (my_field.datatype == 'money') {
1811 JSAN.use('util.money');
1812 def.render = function(my) {
1813 return util.money.sanitize( my[dataobj][datafield]() );
1816 if (column_extras) {
1817 if (column_extras['*']) {
1818 for (var attr in column_extras['*']) {
1819 def[attr] = column_extras['*'][attr];
1821 if (column_extras['*']['expanded_label']) {
1822 def.label = my_class.label + ': ' + def.label;
1824 if (column_extras['*']['label_prefix']) {
1825 def.label = column_extras['*']['label_prefix'] + def.label;
1827 if (column_extras['*']['remove_virtual']) {
1828 if (my_field.virtual) {
1829 def.remove_me = true;
1833 if (column_extras[col_id]) {
1834 for (var attr in column_extras[col_id]) {
1835 def[attr] = column_extras[col_id][attr];
1837 if (column_extras[col_id]['keep_me']) {
1838 def.remove_me = false;
1840 if (column_extras[col_id]['label_prefix']) {
1841 def.label = column_extras[col_id]['label_prefix'] + def.label;
1845 if (def.remove_me) {
1846 dump('Skipping ' + def.label + '\n');
1849 dump('Defining ' + def.label + '\n');
1854 for (var i = 0; i < my_class.fields.length; i++) {
1855 var my_field = my_class.fields[i];
1856 var def = col_def(my_field);
1858 columns.push( def );
1863 obj.error.standard_unexpected_error_alert('fm_columns()',E);
1867 // Default for the map_row_to_columns function for .init
1868 'std_map_row_to_columns' : function(error_value) {
1869 return function(row,cols,scratch) {
1870 // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
1871 // cols contains all of the objects listed above in columns
1872 // scratch is a temporary space shared by all cells/rows (or just per row if not explicitly passed in)
1873 if (!scratch) { scratch = {}; }
1876 JSAN.use('util.error'); obj.error = new util.error();
1877 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1878 JSAN.use('util.network'); obj.network = new util.network();
1879 JSAN.use('util.money');
1885 for (var i = 0; i < cols.length; i++) {
1886 switch (typeof cols[i].render) {
1887 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;
1888 case 'string' : cmd += 'try { ' + cols[i].render + '; values['+i+'] = v; } catch(E) { values['+i+'] = error_value; }'; break;
1889 default: cmd += 'values['+i+'] = "??? '+(typeof cols[i].render)+'"; ';
1892 if (cmd) eval( cmd );
1894 obj.error.sdump('D_WARN','map_row_to_column: ' + E);
1895 if (error_value) { value = error_value; } else { value = ' ' };
1901 dump('exiting util.list.js\n');