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 if (!this.node) throw('Could not find element ' + id);
11 switch(this.node.nodeName) {
15 throw(this.node.nodeName + ' not yet supported'); break;
16 default: throw(this.node.nodeName + ' not supported'); break;
19 JSAN.use('util.error'); this.error = new util.error();
24 util.list.prototype = {
26 'init' : function (params) {
30 JSAN.use('util.widgets');
32 if (typeof params.map_row_to_column == 'function') obj.map_row_to_column = params.map_row_to_column;
33 if (typeof params.retrieve_row == 'function') obj.retrieve_row = params.retrieve_row;
36 if (typeof params.prebuilt != 'undefined') obj.prebuilt = params.prebuilt;
38 if (typeof params.columns == 'undefined') throw('util.list.init: No columns');
39 obj.columns = params.columns;
41 switch(obj.node.nodeName) {
42 case 'tree' : obj._init_tree(params); break;
43 case 'listbox' : obj._init_listbox(params); break;
44 default: throw('NYI: Need ._init() for ' + obj.node.nodeName); break;
48 'register_all_fleshed_callback' : function(f) {
49 this.on_all_fleshed = f;
52 '_init_tree' : function (params) {
56 this.treechildren = this.node.lastChild;
59 var treecols = document.createElement('treecols');
60 this.node.appendChild(treecols);
62 for (var i = 0; i < this.columns.length; i++) {
63 var treecol = document.createElement('treecol');
64 for (var j in this.columns[i]) {
65 treecol.setAttribute(j,this.columns[i][j]);
67 treecols.appendChild(treecol);
68 treecol.addEventListener(
72 var sortDir = ev.target.getAttribute('sortDir') || 'desc';
73 if (sortDir == 'desc') sortDir = 'asc'; else sortDir = 'desc';
74 ev.target.setAttribute('sortDir',sortDir);
75 obj._sort_tree(ev.target,sortDir);
78 if (obj.row_count.total != obj.row_count.fleshed && (obj.row_count.total - obj.row_count.fleshed) > 50) {
79 var r = window.confirm('WARNING: Only ' + obj.row_count.fleshed + ' out of ' + obj.row_count.total + ' rows in this list have been retrieved for immediate viewing. Sorting this list requires that all these rows be retrieved, and this may take some time and lag the staff client. Would you like to proceed?');
82 setTimeout( do_it, 0 );
85 setTimeout( do_it, 0 );
90 var splitter = document.createElement('splitter');
91 splitter.setAttribute('class','tree-splitter');
92 treecols.appendChild(splitter);
95 var treechildren = document.createElement('treechildren');
96 this.node.appendChild(treechildren);
97 this.treechildren = treechildren;
99 if (typeof params.on_select == 'function') {
100 this.node.addEventListener(
106 if (typeof params.on_click == 'function') {
107 this.node.addEventListener(
114 this.node.addEventListener(
116 function(ev) { obj.detect_visible(); },
120 this.node.addEventListener(
122 function(ev) { obj.auto_retrieve(); },
125 this.node.addEventListener(
127 function(ev) { obj.auto_retrieve(); },
130 window.addEventListener(
132 function(ev) { obj.auto_retrieve(); },
135 /* FIXME -- find events on scrollbar to trigger this */
136 obj.detect_visible_polling();
138 var scrollbar = document.getAnonymousNodes( document.getAnonymousNodes(this.node)[1] )[1];
139 var slider = document.getAnonymousNodes( scrollbar )[2];
140 alert('scrollbar = ' + scrollbar.nodeName + ' grippy = ' + slider.nodeName);
141 scrollbar.addEventListener('click',function(){alert('sb click');},false);
142 scrollbar.addEventListener('command',function(){alert('sb command');},false);
143 scrollbar.addEventListener('scroll',function(){alert('sb scroll');},false);
144 slider.addEventListener('click',function(){alert('slider click');},false);
145 slider.addEventListener('command',function(){alert('slider command');},false);
146 slider.addEventListener('scroll',function(){alert('slider scroll');},false);
148 this.node.addEventListener('scroll',function(){ obj.auto_retrieve(); },false);
150 this.restores_columns(params);
153 '_init_listbox' : function (params) {
156 var listhead = document.createElement('listhead');
157 this.node.appendChild(listhead);
159 var listcols = document.createElement('listcols');
160 this.node.appendChild(listcols);
162 for (var i = 0; i < this.columns.length; i++) {
163 var listheader = document.createElement('listheader');
164 listhead.appendChild(listheader);
165 var listcol = document.createElement('listcol');
166 listcols.appendChild(listcol);
167 for (var j in this.columns[i]) {
168 listheader.setAttribute(j,this.columns[i][j]);
169 listcol.setAttribute(j,this.columns[i][j]);
175 'save_columns' : function (params) {
177 switch (this.node.nodeName) {
178 case 'tree' : this._save_columns_tree(params); break;
179 default: throw('NYI: Need .save_columns() for ' + this.node.nodeName); break;
183 '_save_columns_tree' : function (params) {
186 var id = obj.node.getAttribute('id'); if (!id) {
187 alert("FIXME: The columns for this list cannot be saved because the list has no id.");
191 var nl = obj.node.getElementsByTagName('treecol');
192 for (var i = 0; i < nl.length; i++) {
194 var col_id = col.getAttribute('id');
196 alert('FIXME: A column in this list does not have an id and cannot be saved');
199 var col_hidden = col.getAttribute('hidden');
200 var col_width = col.getAttribute('width');
201 var col_ordinal = col.getAttribute('ordinal');
202 my_cols[ col_id ] = { 'hidden' : col_hidden, 'width' : col_width, 'ordinal' : col_ordinal };
204 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
205 JSAN.use('util.file'); var file = new util.file('tree_columns_for_'+window.escape(id));
206 file.set_object(my_cols);
208 alert('Columns saved.');
210 obj.error.standard_unexpected_error_alert('_save_columns_tree',E);
214 'restores_columns' : function (params) {
216 switch (this.node.nodeName) {
217 case 'tree' : this._restores_columns_tree(params); break;
218 default: throw('NYI: Need .restores_columns() for ' + this.node.nodeName); break;
222 '_restores_columns_tree' : function (params) {
225 var id = obj.node.getAttribute('id'); if (!id) {
226 alert("FIXME: The columns for this list cannot be restored because the list has no id.");
230 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
231 JSAN.use('util.file'); var file = new util.file('tree_columns_for_'+window.escape(id));
232 if (file._file.exists()) {
233 var my_cols = file.get_object(); file.close();
234 var nl = obj.node.getElementsByTagName('treecol');
235 for (var i = 0; i < nl.length; i++) {
237 var col_id = col.getAttribute('id');
239 alert('FIXME: A column in this list does not have an id and cannot be saved');
242 if (typeof my_cols[col_id] != 'undefined') {
243 col.setAttribute('hidden',my_cols[col_id].hidden);
244 col.setAttribute('width',my_cols[col_id].width);
245 col.setAttribute('ordinal',my_cols[col_id].ordinal);
247 obj.error.sdump('D_ERROR','WARNING: Column ' + col_id + ' did not have a saved state.');
252 obj.error.standard_unexpected_error_alert('_restore_columns_tree',E);
256 'clear' : function (params) {
258 switch (this.node.nodeName) {
259 case 'tree' : this._clear_tree(params); break;
260 case 'listbox' : this._clear_listbox(params); break;
261 default: throw('NYI: Need .clear() for ' + this.node.nodeName); break;
263 this.error.sdump('D_LIST','Clearing list ' + this.node.getAttribute('id') + '\n');
264 this.row_count.total = 0;
265 this.row_count.fleshed = 0;
266 if (typeof obj.on_all_fleshed == 'function') {
267 setTimeout( function() { obj.on_all_fleshed(); }, 0 );
271 '_clear_tree' : function(params) {
273 if (obj.error.sdump_levels.D_LIST_DUMP_ON_CLEAR) {
274 obj.error.sdump('D_LIST_DUMP_ON_CLEAR',obj.dump());
276 if (obj.error.sdump_levels.D_LIST_DUMP_WITH_KEYS_ON_CLEAR) {
277 obj.error.sdump('D_LIST_DUMP_WITH_KEYS_ON_CLEAR',obj.dump_with_keys());
279 while (obj.treechildren.lastChild) obj.treechildren.removeChild( obj.treechildren.lastChild );
282 '_clear_listbox' : function(params) {
285 var nl = this.node.getElementsByTagName('listitem');
286 for (var i = 0; i < nl.length; i++) {
289 for (var i = 0; i < items.length; i++) {
290 this.node.removeChild(items[i]);
294 'append' : function (params) {
297 switch (this.node.nodeName) {
298 case 'tree' : rnode = this._append_to_tree(params); break;
299 case 'listbox' : rnode = this._append_to_listbox(params); break;
300 default: throw('NYI: Need .append() for ' + this.node.nodeName); break;
302 if (rnode && params.attributes) {
303 for (var i in params.attributes) {
304 rnode.setAttribute(i,params.attributes[i]);
307 this.row_count.total++;
308 if (this.row_count.fleshed == this.row_count.total) {
309 if (typeof this.on_all_fleshed == 'function') {
310 setTimeout( function() { obj.on_all_fleshed(); }, 0 );
316 '_append_to_tree' : function (params) {
320 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
322 var s = ('util.list.append: params = ' + (params) + '\n');
324 var treechildren_node = this.treechildren;
326 if (params.node && params.node.nodeName == 'treeitem') {
327 params.node.setAttribute('container','true'); /* params.node.setAttribute('open','true'); */
328 if (params.node.lastChild.nodeName == 'treechildren') {
329 treechildren_node = params.node.lastChild;
331 treechildren_node = document.createElement('treechildren');
332 params.node.appendChild(treechildren_node);
336 var treeitem = document.createElement('treeitem');
337 treeitem.setAttribute('retrieve_id',params.retrieve_id);
338 if (typeof params.to_top == 'undefined') {
339 treechildren_node.appendChild( treeitem );
341 if (treechildren_node.firstChild) {
342 treechildren_node.insertBefore( treeitem, treechildren_node.firstChild );
344 treechildren_node.appendChild( treeitem );
347 var treerow = document.createElement('treerow');
348 treeitem.appendChild( treerow );
349 treerow.setAttribute('retrieve_id',params.retrieve_id);
351 s += ('tree = ' + this.node + ' treechildren = ' + treechildren_node + '\n');
352 s += ('treeitem = ' + treeitem + ' treerow = ' + treerow + '\n');
354 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
356 obj.put_retrieving_label(treerow);
357 treerow.addEventListener(
361 if (treerow.getAttribute('retrieved') == 'true') return; /* already running */
363 treerow.setAttribute('retrieved','true');
365 //dump('fleshing = ' + params.retrieve_id + '\n');
367 function inc_fleshed() {
368 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
369 treerow.setAttribute('fleshed','true');
370 obj.row_count.fleshed++;
371 if (obj.row_count.fleshed == obj.row_count.total) {
372 if (typeof obj.on_all_fleshed == 'function') {
373 setTimeout( function() { obj.on_all_fleshed(); }, 0 );
378 params.row_node = treeitem;
379 params.on_retrieve = function(p) {
382 obj._map_row_to_treecell(p,treerow);
385 alert('fixme2: ' + E);
389 if (typeof params.retrieve_row == 'function') {
391 params.retrieve_row( params );
393 } else if (typeof obj.retrieve_row == 'function') {
395 obj.retrieve_row( params );
407 util.widgets.dispatch('flesh',treerow);
412 obj.put_retrieving_label(treerow);
413 treerow.addEventListener(
416 //dump('fleshing anon\n');
417 if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */
418 obj._map_row_to_treecell(params,treerow);
419 treerow.setAttribute('retrieved','true');
420 treerow.setAttribute('fleshed','true');
421 obj.row_count.fleshed++;
422 if (obj.row_count.fleshed == obj.row_count.total) {
423 if (typeof obj.on_all_fleshed == 'function') {
424 setTimeout( function() { obj.on_all_fleshed(); }, 0 );
433 util.widgets.dispatch('flesh',treerow);
438 this.error.sdump('D_LIST',s);
442 if (obj.trim_list && obj.row_count.total >= obj.trim_list) {
444 if (typeof params.to_top == 'undefined') {
445 treechildren_node.removeChild( treechildren_node.firstChild );
447 treechildren_node.removeChild( treechildren_node.lastChild );
453 setTimeout( function() { obj.auto_retrieve(); }, 0 );
458 'put_retrieving_label' : function(treerow) {
463 dump('put_retrieving_label. columns = ' + js2JSON(obj.columns) + '\n');
464 while( obj.columns[cols_idx] && obj.columns[cols_idx].hidden && obj.columns[cols_idx].hidden == 'true') {
465 dump('\t' + cols_idx);
466 var treecell = document.createElement('treecell');
467 treerow.appendChild(treecell);
471 for (var i = 0; i < obj.columns.length; i++) {
472 var treecell = document.createElement('treecell'); treecell.setAttribute('label','Retrieving...');
473 treerow.appendChild(treecell);
476 dump('\t' + cols_idx + '\n');
483 'detect_visible' : function() {
486 //dump('detect_visible obj.node = ' + obj.node + '\n');
487 /* FIXME - this is a hack.. if the implementation of tree changes, this could break */
489 var scrollbar = document.getAnonymousNodes( document.getAnonymousNodes(obj.node)[1] )[1];
490 var curpos = scrollbar.getAttribute('curpos');
491 var maxpos = scrollbar.getAttribute('maxpos');
492 //alert('curpos = ' + curpos + ' maxpos = ' + maxpos + ' obj.curpos = ' + obj.curpos + ' obj.maxpos = ' + obj.maxpos + '\n');
493 if ((curpos != obj.curpos) || (maxpos != obj.maxpos)) {
494 if ( obj.auto_retrieve() > 0 ) {
495 obj.curpos = curpos; obj.maxpos = maxpos;
499 obj.error.sdump('D_XULRUNNER', 'List implementation changed? ' + E);
501 } catch(E) { obj.error.sdump('D_ERROR',E); }
504 'detect_visible_polling' : function() {
506 //alert('detect_visible_polling');
508 obj.detect_visible();
509 setTimeout(function() { try { obj.detect_visible_polling(); } catch(E) { alert(E); } },2000);
516 'auto_retrieve' : function(params) {
518 switch (this.node.nodeName) {
519 case 'tree' : obj._auto_retrieve_tree(params); break;
520 default: throw('NYI: Need .auto_retrieve() for ' + obj.node.nodeName); break;
524 '_auto_retrieve_tree' : function (params) {
526 if (!obj.auto_retrieve_in_progress) {
527 obj.auto_retrieve_in_progress = true;
531 //alert('auto_retrieve\n');
533 var startpos = obj.node.treeBoxObject.getFirstVisibleRow();
534 var endpos = obj.node.treeBoxObject.getLastVisibleRow();
535 if (startpos > endpos) endpos = obj.node.treeBoxObject.getPageLength();
536 //dump('startpos = ' + startpos + ' endpos = ' + endpos + '\n');
537 for (var i = startpos; i < endpos + 4; i++) {
539 //dump('trying index ' + i + '\n');
540 var item = obj.node.contentView.getItemAtIndex(i).firstChild;
541 if (item && item.getAttribute('retrieved') != 'true' ) {
542 //dump('\tgot an unfleshed item = ' + item + ' = ' + item.nodeName + '\n');
543 util.widgets.dispatch('flesh',item); count++;
546 //dump(i + ' : ' + E + '\n');
549 obj.auto_retrieve_in_progress = false;
551 } catch(E) { alert(E); }
557 'full_retrieve' : function(params) {
559 switch (this.node.nodeName) {
560 case 'tree' : obj._full_retrieve_tree(params); break;
561 default: throw('NYI: Need .full_retrieve() for ' + obj.node.nodeName); break;
565 '_full_retrieve_tree' : function(params) {
568 if (obj.row_count.total == obj.row_count.fleshed) {
569 //alert('Full retrieve... tree seems to be in sync\n' + js2JSON(obj.row_count));
570 if (typeof obj.on_all_fleshed == 'function') {
571 setTimeout( function() { obj.on_all_fleshed(); }, 0 );
573 alert('.full_retrieve called with no callback?');
576 //alert('Full retrieve... syncing tree' + js2JSON(obj.row_count));
577 JSAN.use('util.widgets');
578 var nodes = obj.treechildren.childNodes;
579 for (var i = 0; i < nodes.length; i++) {
580 util.widgets.dispatch('flesh',nodes[i].firstChild);
584 obj.error.standard_unexpected_error_alert('_full_retrieve_tree',E);
588 '_append_to_listbox' : function (params) {
592 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
594 var s = ('util.list.append: params = ' + (params) + '\n');
596 var listitem = document.createElement('listitem');
598 s += ('listbox = ' + this.node + ' listitem = ' + listitem + '\n');
600 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
604 listitem.setAttribute('retrieve_id',params.retrieve_id);
605 //FIXME//Make async and fire when row is visible in list
608 params.row_node = listitem;
609 params.on_retrieve = function(row) {
611 obj._map_row_to_listcell(params,listitem);
612 obj.node.appendChild( listitem );
615 if (typeof params.retrieve_row == 'function') {
617 row = params.retrieve_row( params );
621 if (typeof obj.retrieve_row == 'function') {
623 row = obj.retrieve_row( params );
630 this._map_row_to_listcell(params,listitem);
631 this.node.appendChild( listitem );
634 this.error.sdump('D_LIST',s);
639 '_map_row_to_treecell' : function(params,treerow) {
642 util.widgets.remove_children(treerow);
643 for (var i = 0; i < this.columns.length; i++) {
644 var treecell = document.createElement('treecell');
646 if (params.skip_columns && (params.skip_columns.indexOf(i) != -1)) {
647 treecell.setAttribute('label',label);
648 treerow.appendChild( treecell );
649 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
652 if (params.skip_all_columns_except && (params.skip_all_columns_except.indexOf(i) == -1)) {
653 treecell.setAttribute('label',label);
654 treerow.appendChild( treecell );
655 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
658 if (typeof params.map_row_to_column == 'function') {
660 label = params.map_row_to_column(params.row,this.columns[i]);
664 if (typeof this.map_row_to_column == 'function') {
666 label = this.map_row_to_column(params.row,this.columns[i]);
670 throw('No map_row_to_column function');
674 treecell.setAttribute('label',label);
675 treerow.appendChild( treecell );
676 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
678 this.error.sdump('D_LIST',s);
681 '_map_row_to_listcell' : function(params,listitem) {
684 for (var i = 0; i < this.columns.length; i++) {
686 if (typeof params.map_row_to_column == 'function') {
688 value = params.map_row_to_column(params.row,this.columns[i]);
692 if (typeof this.map_row_to_column == 'function') {
694 value = this.map_row_to_column(params.row,this.columns[i]);
697 if (typeof value == 'string' || typeof value == 'number') {
698 var listcell = document.createElement('listcell');
699 listcell.setAttribute('label',value);
700 listitem.appendChild(listcell);
701 s += ('listcell = ' + listcell + ' with label = ' + value + '\n');
703 listitem.appendChild(value);
704 s += ('listcell = ' + value + ' is really a ' + value.nodeName + '\n');
707 this.error.sdump('D_LIST',s);
710 'select_all' : function(params) {
712 switch(this.node.nodeName) {
713 case 'tree' : return this._select_all_from_tree(params); break;
714 default: throw('NYI: Need ._select_all_from_() for ' + this.node.nodeName); break;
718 '_select_all_from_tree' : function(params) {
720 this.node.view.selection.selectAll();
723 'retrieve_selection' : function(params) {
725 switch(this.node.nodeName) {
726 case 'tree' : return this._retrieve_selection_from_tree(params); break;
727 default: throw('NYI: Need ._retrieve_selection_from_() for ' + this.node.nodeName); break;
731 '_retrieve_selection_from_tree' : function(params) {
734 var start = new Object();
735 var end = new Object();
736 var numRanges = this.node.view.selection.getRangeCount();
737 for (var t=0; t<numRanges; t++){
738 this.node.view.selection.getRangeAt(t,start,end);
739 for (var v=start.value; v<=end.value; v++){
740 var i = this.node.contentView.getItemAtIndex(v);
747 'dump' : function(params) {
749 switch(this.node.nodeName) {
750 case 'tree' : return this._dump_tree(params); break;
751 default: throw('NYI: Need .dump() for ' + this.node.nodeName); break;
755 '_dump_tree' : function(params) {
758 for (var i = 0; i < this.treechildren.childNodes.length; i++) {
760 var treeitem = this.treechildren.childNodes[i];
761 var treerow = treeitem.firstChild;
762 for (var j = 0; j < treerow.childNodes.length; j++) {
763 row.push( treerow.childNodes[j].getAttribute('label') );
770 'dump_with_keys' : function(params) {
772 switch(this.node.nodeName) {
773 case 'tree' : return this._dump_tree_with_keys(params); break;
774 default: throw('NYI: Need .dump_with_keys() for ' + this.node.nodeName); break;
779 '_dump_tree_with_keys' : function(params) {
782 for (var i = 0; i < this.treechildren.childNodes.length; i++) {
784 var treeitem = this.treechildren.childNodes[i];
785 var treerow = treeitem.firstChild;
786 for (var j = 0; j < treerow.childNodes.length; j++) {
787 row[ obj.columns[j].id ] = treerow.childNodes[j].getAttribute('label');
794 'dump_selected_with_keys' : function(params) {
796 switch(this.node.nodeName) {
797 case 'tree' : return this._dump_tree_selection_with_keys(params); break;
798 default: throw('NYI: Need .dump_selection_with_keys() for ' + this.node.nodeName); break;
803 '_dump_tree_selection_with_keys' : function(params) {
806 var list = obj._retrieve_selection_from_tree();
807 for (var i = 0; i < list.length; i++) {
809 var treeitem = list[i];
810 var treerow = treeitem.firstChild;
811 for (var j = 0; j < treerow.childNodes.length; j++) {
812 var value = treerow.childNodes[j].getAttribute('label');
814 //if (params.skip_hidden_columns) if (obj.node.firstChild.childNodes[j].getAttribute('hidden')) continue;
815 var id = obj.columns[j].id; if (params.labels_instead_of_ids) id = obj.columns[j].label;
823 'clipboard' : function() {
826 var dump = obj.dump_selected_with_keys({'skip_hidden_columns':true,'labels_instead_of_ids':true});
827 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
828 data.list_clipboard = dump; data.stash('list_clipboard');
829 JSAN.use('util.window'); var win = new util.window();
830 win.open(urls.XUL_LIST_CLIPBOARD,'list_clipboard','chrome,resizable,modal');
832 this.error.standard_unexpected_error_alert('clipboard',E);
836 'dump_retrieve_ids' : function(params) {
838 switch(this.node.nodeName) {
839 case 'tree' : return this._dump_retrieve_ids_tree(params); break;
840 default: throw('NYI: Need .dump_retrieve_ids() for ' + this.node.nodeName); break;
844 '_dump_retrieve_ids_tree' : function(params) {
847 for (var i = 0; i < this.treechildren.childNodes.length; i++) {
848 var treeitem = this.treechildren.childNodes[i];
849 dump.push( treeitem.getAttribute('retrieve_id') );
854 '_sort_tree' : function(col,sortDir) {
857 if (obj.node.getAttribute('no_sort')) {
860 if (obj.on_all_fleshed) {
861 var r = window.confirm('This list is busy rendering/retrieving data. Abort current action and proceed?');
862 if (r) {} else { return; }
865 for (var i = 0; i < obj.columns.length; i++) {
866 if (obj.columns[i].id == col.id) col_pos = function(a){return a;}(i);
868 obj.on_all_fleshed = function() {
870 JSAN.use('util.money');
872 var treeitems = obj.treechildren.childNodes;
873 for (var i = 0; i < treeitems.length; i++) {
874 var treeitem = treeitems[i];
875 var treerow = treeitem.firstChild;
876 var treecell = treerow.childNodes[ col_pos ];
877 value = ( { 'value' : treecell ? treecell.getAttribute('label') : '', 'node' : treeitem } );
880 rows = rows.sort( function(a,b) {
881 a = a.value; b = b.value;
882 if (col.getAttribute('sort_type')) {
883 switch(col.getAttribute('sort_type')) {
885 a = Number(a); b = Number(b);
888 a = util.money.dollars_float_to_cents_integer(a);
889 b = util.money.dollars_float_to_cents_integer(b);
891 case 'title' : /* special case for "a" and "the". doesn't use marc 245 indicator */
892 a = String( a ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
893 b = String( b ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
896 a = String( a ).toUpperCase();
897 b = String( a ).toUpperCase();
901 if (a < b) return -1;
905 if (sortDir == 'asc') rows = rows.reverse();
906 while(obj.treechildren.lastChild) obj.treechildren.removeChild( obj.treechildren.lastChild );
907 for (var i = 0; i < rows.length; i++) {
908 obj.treechildren.appendChild( rows[i].node );
911 obj.error.standard_unexpected_error_alert('sorting',E);
913 setTimeout(function(){ obj.on_all_fleshed = null; },0);
917 obj.error.standard_unexpected_error_alert('pre sorting', E);
922 dump('exiting util.list.js\n');