Sorting on a colum: Much, much, much, better. (hope)fully implemented!
This commit is contained in:
parent
56b1e37c13
commit
5411d4b67f
4 changed files with 75 additions and 21 deletions
|
@ -31,6 +31,7 @@ Scholar.ItemTreeView.prototype.setTree = function(treebox)
|
||||||
if(this._treebox)
|
if(this._treebox)
|
||||||
return;
|
return;
|
||||||
this._treebox = treebox;
|
this._treebox = treebox;
|
||||||
|
this.sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
Scholar.ItemTreeView.prototype.getCellText = function(row, column)
|
Scholar.ItemTreeView.prototype.getCellText = function(row, column)
|
||||||
|
@ -57,7 +58,14 @@ Scholar.ItemTreeView.prototype._hideItem = function(row) { this._dataItems
|
||||||
|
|
||||||
Scholar.ItemTreeView.prototype._getItemAtRow = function(row) { return this._dataItems[row]; }
|
Scholar.ItemTreeView.prototype._getItemAtRow = function(row) { return this._dataItems[row]; }
|
||||||
|
|
||||||
Scholar.ItemTreeView.prototype.isSorted = function() { return false; }
|
Scholar.ItemTreeView.prototype.isSorted = function()
|
||||||
|
{
|
||||||
|
for(var i=0, len=this._treebox.columns.count; i<len; i++)
|
||||||
|
if(this._treebox.columns.getColumnAt(i).element.getAttribute('sortActive'))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Scholar.ItemTreeView.prototype.isSeparator = function(row) { return false; }
|
Scholar.ItemTreeView.prototype.isSeparator = function(row) { return false; }
|
||||||
Scholar.ItemTreeView.prototype.isContainer = function(row) { return false; }
|
Scholar.ItemTreeView.prototype.isContainer = function(row) { return false; }
|
||||||
Scholar.ItemTreeView.prototype.getLevel = function(row) { return 0; }
|
Scholar.ItemTreeView.prototype.getLevel = function(row) { return 0; }
|
||||||
|
@ -68,8 +76,41 @@ Scholar.ItemTreeView.prototype.getImageSrc = function(row, col) { }
|
||||||
|
|
||||||
Scholar.ItemTreeView.prototype.cycleHeader = function(column)
|
Scholar.ItemTreeView.prototype.cycleHeader = function(column)
|
||||||
{
|
{
|
||||||
var order = 0;
|
for(var i=0, len=this._treebox.columns.count; i<len; i++)
|
||||||
if(order==0)
|
{
|
||||||
|
col = this._treebox.columns.getColumnAt(i);
|
||||||
|
if(column != col)
|
||||||
|
{
|
||||||
|
col.element.removeAttribute('sortActive');
|
||||||
|
col.element.removeAttribute('sortDirection');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
col.element.setAttribute('sortActive',true);
|
||||||
|
col.element.setAttribute('sortDirection',col.element.getAttribute('sortDirection') == 'descending' ? 'ascending' : 'descending');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sort();
|
||||||
|
}
|
||||||
|
|
||||||
|
Scholar.ItemTreeView.prototype.sort = function()
|
||||||
|
{
|
||||||
|
this.selection.selectEventsSuppressed = true;
|
||||||
|
|
||||||
|
var selectedIDs = new Array();
|
||||||
|
var start = new Object();
|
||||||
|
var end = new Object();
|
||||||
|
for (var i=0, len=this.selection.getRangeCount(); i<len; i++)
|
||||||
|
{
|
||||||
|
this.selection.getRangeAt(i,start,end);
|
||||||
|
for (var j=start.value; j<=end.value; j++)
|
||||||
|
selectedIDs.push(this._getItemAtRow(j).getID());
|
||||||
|
}
|
||||||
|
|
||||||
|
var column = this._treebox.columns.getSortedColumn()
|
||||||
|
var order = column.element.getAttribute('sortDirection') == 'descending';
|
||||||
|
if(order)
|
||||||
{
|
{
|
||||||
function columnSort(a,b)
|
function columnSort(a,b)
|
||||||
{
|
{
|
||||||
|
@ -86,6 +127,13 @@ Scholar.ItemTreeView.prototype.cycleHeader = function(column)
|
||||||
|
|
||||||
this._dataItems.sort(columnSort);
|
this._dataItems.sort(columnSort);
|
||||||
this._refreshHashMap();
|
this._refreshHashMap();
|
||||||
|
|
||||||
|
this.selection.clearSelection();
|
||||||
|
for(var i=0; i < selectedIDs.length; i++)
|
||||||
|
{
|
||||||
|
this.selection.toggleSelect(this._itemRowMap[selectedIDs[i]]);
|
||||||
|
}
|
||||||
|
this.selection.selectEventsSuppressed = false;
|
||||||
this._treebox.invalidate();
|
this._treebox.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +235,10 @@ Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
|
||||||
var row = this._itemRowMap[ids[i]];
|
var row = this._itemRowMap[ids[i]];
|
||||||
if(action == 'modify' && row != null) //must check for null because it could legitimately be 0
|
if(action == 'modify' && row != null) //must check for null because it could legitimately be 0
|
||||||
{
|
{
|
||||||
this._treebox.invalidateRow(row)
|
var item = Scholar.Items.get(ids[i]);
|
||||||
|
|
||||||
|
this._treebox.invalidateRow(row);
|
||||||
|
madeChanges = true;
|
||||||
}
|
}
|
||||||
else if(action == 'add' && row == null)
|
else if(action == 'add' && row == null)
|
||||||
{
|
{
|
||||||
|
@ -200,19 +251,22 @@ Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
madeChanges = true;
|
madeChanges = true;
|
||||||
|
|
||||||
//TODO: sorted? figure it out later
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(madeChanges)
|
if(madeChanges)
|
||||||
|
{
|
||||||
|
if(action == 'add')
|
||||||
|
this.selection.select(this._itemRowMap[item.getID()]);
|
||||||
|
|
||||||
|
if(this.isSorted())
|
||||||
|
this.sort(); //this also refreshes the hash map
|
||||||
|
else if(action != 'modify') //no need to update this if we just modified
|
||||||
this._refreshHashMap();
|
this._refreshHashMap();
|
||||||
|
|
||||||
//Select last add
|
}
|
||||||
if(action == 'add' && item)
|
|
||||||
this.selection.select(this._itemRowMap[item.getID()]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Scholar.ItemTreeView.prototype.canDrop = function(index, orient)
|
Scholar.ItemTreeView.prototype.canDrop = function(index, orient)
|
||||||
|
|
|
@ -89,15 +89,15 @@ MetadataPane = new function()
|
||||||
|
|
||||||
function toggleEdit(save)
|
function toggleEdit(save)
|
||||||
{
|
{
|
||||||
if(_editButton.hidden && save)
|
|
||||||
saveItem();
|
|
||||||
|
|
||||||
_cancelButton.hidden = _editButton.hidden;
|
_cancelButton.hidden = _editButton.hidden;
|
||||||
_saveButton.hidden = _editButton.hidden;
|
_saveButton.hidden = _editButton.hidden;
|
||||||
_creatorsToolbar.hidden = _editButton.hidden;
|
_creatorsToolbar.hidden = _editButton.hidden;
|
||||||
|
|
||||||
_editButton.hidden = !_editButton.hidden;
|
_editButton.hidden = !_editButton.hidden;
|
||||||
|
|
||||||
|
if(!_editButton.hidden && save)
|
||||||
|
saveItem();
|
||||||
|
|
||||||
reloadFields();
|
reloadFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,32 +86,32 @@
|
||||||
<treecol
|
<treecol
|
||||||
id="title"
|
id="title"
|
||||||
label="&items.title_column;"
|
label="&items.title_column;"
|
||||||
flex="4" persist="width ordinal hidden"/>
|
flex="4" persist="width ordinal hidden sortActive sortDirection"/>
|
||||||
<splitter class="tree-splitter"/>
|
<splitter class="tree-splitter"/>
|
||||||
<treecol
|
<treecol
|
||||||
id="firstCreator"
|
id="firstCreator"
|
||||||
label="&items.creator_column;"
|
label="&items.creator_column;"
|
||||||
flex="1" persist="width ordinal hidden"/>
|
flex="1" persist="width ordinal hidden sortActive sortDirection"/>
|
||||||
<splitter class="tree-splitter"/>
|
<splitter class="tree-splitter"/>
|
||||||
<treecol
|
<treecol
|
||||||
id="source"
|
id="source"
|
||||||
label="&items.source_column;"
|
label="&items.source_column;"
|
||||||
flex="1" persist="width ordinal hidden"/>
|
flex="1" persist="width ordinal hidden sortActive sortDirection"/>
|
||||||
<splitter class="tree-splitter"/>
|
<splitter class="tree-splitter"/>
|
||||||
<treecol
|
<treecol
|
||||||
id="rights" hidden="true"
|
id="rights" hidden="true"
|
||||||
label="&items.rights_column;"
|
label="&items.rights_column;"
|
||||||
flex="1" persist="width ordinal hidden"/>
|
flex="1" persist="width ordinal hidden sortActive sortDirection"/>
|
||||||
<splitter class="tree-splitter"/>
|
<splitter class="tree-splitter"/>
|
||||||
<treecol
|
<treecol
|
||||||
id="dateAdded" hidden="true"
|
id="dateAdded" hidden="true"
|
||||||
label="&items.dateAdded_column;"
|
label="&items.dateAdded_column;"
|
||||||
flex="1" persist="width ordinal hidden"/>
|
flex="1" persist="width ordinal hidden sortActive sortDirection"/>
|
||||||
<splitter class="tree-splitter"/>
|
<splitter class="tree-splitter"/>
|
||||||
<treecol
|
<treecol
|
||||||
id="dateModified" hidden="true"
|
id="dateModified" hidden="true"
|
||||||
label="&items.dateModified_column;"
|
label="&items.dateModified_column;"
|
||||||
flex="1" persist="width ordinal hidden"/>
|
flex="1" persist="width ordinal hidden sortActive sortDirection"/>
|
||||||
</treecols>
|
</treecols>
|
||||||
|
|
||||||
<treechildren/>
|
<treechildren/>
|
||||||
|
|
|
@ -12,5 +12,5 @@
|
||||||
<script src="../include.js"/>
|
<script src="../include.js"/>
|
||||||
<script src="test.js"/>
|
<script src="test.js"/>
|
||||||
|
|
||||||
<label></label>
|
<hbox><label>hello asf saf saf saf saf sa sf faj sj ak jgaslg jasg asglj</label></hbox>
|
||||||
</window>
|
</window>
|
||||||
|
|
Loading…
Reference in a new issue