//////////////////////////////////////////////////////////////////////////////// /// /// CollectionTreeView /// -- handles the link between an individual tree and the data layer /// -- displays only collections, in a hierarchy (no items) /// //////////////////////////////////////////////////////////////////////////////// /* * Constructor the the CollectionTreeView object */ Scholar.CollectionTreeView = function() { this._treebox = null; this.refresh(); this._unregisterID = Scholar.Notifier.registerColumnTree(this); } /* * Called by the tree itself */ Scholar.CollectionTreeView.prototype.setTree = function(treebox) { if(this._treebox) return; this._treebox = treebox; //select Library this.selection.select(0); } /* * Reload the rows from the data access methods * (doesn't call the tree.invalidate methods, etc.) */ Scholar.CollectionTreeView.prototype.refresh = function() { this._dataItems = new Array(); this.rowCount = 0; this._showItem(new Scholar.ItemGroup('library',null),0,1); var newRows = Scholar.getCollections(); for(var i = 0; i < newRows.length; i++) this._showItem(new Scholar.ItemGroup('collection',newRows[i]), 0, this._dataItems.length); //item ref, level, beforeRow this._refreshHashMap(); } /* * Called by Scholar.Notifier on any changes to collections in the data layer */ Scholar.CollectionTreeView.prototype.notify = function(action, type, ids) { var madeChanges = false; if(action == 'remove') { 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= 0; i--) if(this.getLevel(i) < thisLevel) return i; return -1; } Scholar.CollectionTreeView.prototype.hasNextSibling = function(row, afterIndex) { var thisLevel = this.getLevel(row); for(var i = afterIndex + 1; i < this.rowCount; i++) { var nextLevel = this.getLevel(i); if(nextLevel == thisLevel) return true; else if(nextLevel < thisLevel) return false; } } /* * Opens/closes the specified row */ Scholar.CollectionTreeView.prototype.toggleOpenState = function(row) { var count = 0; //used to tell the tree how many rows were added/removed var thisLevel = this.getLevel(row); this._treebox.beginUpdateBatch(); if(this.isContainerOpen(row)) { while((row + 1 < this._dataItems.length) && (this.getLevel(row + 1) > thisLevel)) { this._hideItem(row+1); count--; //count is negative when closing a container because we are removing rows } } else { var newRows = Scholar.getCollections(this._getItemAtRow(row).ref.getID()); //Get children for(var i = 0; i < newRows.length; i++) { count++; this._showItem(new Scholar.ItemGroup('collection',newRows[i]), thisLevel+1, row+i+1); //insert new row } } this._dataItems[row][1] = !this._dataItems[row][1]; //toggle container open value this._treebox.rowCountChanged(row+1, count); //tell treebox to repaint these this._treebox.invalidateRow(row); this._treebox.endUpdateBatch(); this._refreshHashMap(); } //////////////////////////////////////////////////////////////////////////////// /// /// Additional functions for managing data in the tree /// //////////////////////////////////////////////////////////////////////////////// /* * Delete the selection */ Scholar.CollectionTreeView.prototype.deleteSelection = function() { if(this.selection.count == 0) return; //collapse open collections for(var i=0; i