1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
Ext.namespace('Zarafa.plugins.files.ui');
/**
* @class Zarafa.plugins.files.ui.TreeSorter
* @extends Ext.tree.TreeSorter
*
* Special sorting class for the {@link Zarafa.plugins.files.ui.dialogs.AttachFromFilesTreePanel AttachFromFilesTreePanel},
* this enables special sorting of the folders and files in alphabetical order.
*/
Zarafa.plugins.files.ui.TreeSorter = Ext.extend(Ext.tree.TreeSorter, {
/**
* @constructor
* @param {Ext.tree.Tree} tree The tree which this sorter is being applied on
* @param {Object} config Configuration object
*/
constructor : function(tree, config)
{
Zarafa.plugins.files.ui.TreeSorter.superclass.constructor.apply(this, arguments);
this.sortFn = this.hierarchySort.createDelegate(this);
},
/**
* Special sorting function which applies special sorting when the folder and field
* shows in tree.
*
* @param {Ext.tree.Node} nodeOne The first node to be compared
* @param {Ext.tree.Node} nodeTwo The second node to be compared
* @private
*/
hierarchySort : function(nodeOne, nodeTwo)
{
var nodeOneAttributes = nodeOne.attributes;
var nodeTwoAttributes = nodeTwo.attributes;
var isNodeOneFolder = nodeOneAttributes.isFolder;
var isNodeTwoFolder = nodeTwoAttributes.isFolder;
// Both the nodes are folder.
var bothFolders = isNodeOneFolder && isNodeTwoFolder;
// Both the nodes are files.
var bothNotFolders = !isNodeOneFolder && !isNodeTwoFolder;
if(bothFolders || bothNotFolders) {
var nodeOneText = nodeOneAttributes.text,
nodeTwoText = nodeTwoAttributes.text;
return nodeOneText.toUpperCase() < nodeTwoText.toUpperCase() ? -1 : 1;
} else {
// second node is folder but node one is not folder.
var nodeTwoIsFolder = !isNodeOneFolder && isNodeTwoFolder;
return nodeTwoIsFolder ? 1 : -1;
}
}
});
|