//////////////////////////////////////////////////////////////////////////////// /// /// ItemTreeView /// -- handles the link between an individual tree and the data layer /// -- displays only items (no collections, no hierarchy) /// //////////////////////////////////////////////////////////////////////////////// /* * Constructor the the ItemTreeView object */ Scholar.ItemTreeView = function(itemGroup) { this._itemGroup = itemGroup; this._treebox = null; this._savedSelection = null; this.refresh(); this._unregisterID = Scholar.Notifier.registerItemTree(this); } /* * Called by the tree itself */ Scholar.ItemTreeView.prototype.setTree = function(treebox) { if(this._treebox) return; this._treebox = treebox; if(!this.isSorted()) { this.cycleHeader(this._treebox.columns.getNamedColumn('firstCreator')); } else { this.sort(); } } /* * Reload the rows from the data access methods * (doesn't call the tree.invalidate methods, etc.) */ Scholar.ItemTreeView.prototype.refresh = function() { this._dataItems = new Array(); this.rowCount = 0; var newRows = this._itemGroup.getChildItems(); for(var i = 0; i < newRows.length; i++) if(newRows[i]) this._showItem(newRows[i], i+1); //item ref, before row this._refreshHashMap(); } /* * Called by Scholar.Notifier on any changes to items in the data layer */ Scholar.ItemTreeView.prototype.notify = function(action, type, ids) { var madeChanges = false; this.selection.selectEventsSuppressed = true; this.saveSelection(); if((action == 'remove' && !this._itemGroup.isLibrary()) || (action == 'delete' && this._itemGroup.isLibrary())) { ids = Scholar.flattenArguments(ids); //Since a remove involves shifting of rows, we have to do it in order //sort the ids by row var rows = new Array(); for(var i=0, len=ids.length; i 0) { rows.sort(function(a,b) { return a-b }); for(var i=0, len=rows.length; i typeB) ? -1 : (typeA < typeB) ? 1 : 0; } } else if(column.id == 'numNotes') { function columnSort(a,b) { return b.numNotes() - a.numNotes(); } } else { function columnSort(a,b) { var fieldA = a.getField(column.id); var fieldB = b.getField(column.id); if(typeof fieldA == 'string') { fieldA = fieldA.toLowerCase(); fieldB = fieldB.toLowerCase(); } return (fieldA > fieldB) ? -1 : (fieldA < fieldB) ? 1 : 0; } } function doSort(a,b) { var s = columnSort(a,b); if(s) return s; else return secondarySort(a,b); } function oppositeSort(a,b) { return(doSort(a,b) * -1); } function secondarySort(a,b) { return (a.getField('dateModified') > b.getField('dateModified')) ? -1 : (a.getField('dateModified') < b.getField('dateModified')) ? 1 : 0; } if(order) this._dataItems.sort(oppositeSort); else this._dataItems.sort(doSort); this._refreshHashMap(); } //////////////////////////////////////////////////////////////////////////////// /// /// Additional functions for managing data in the tree /// //////////////////////////////////////////////////////////////////////////////// /* * Delete the selection */ Scholar.ItemTreeView.prototype.deleteSelection = function() { if(this.selection.count == 0) return; //create an array of selected items var items = new Array(); var start = new Object(); var end = new Object(); for (var i=0, len=this.selection.getRangeCount(); i