1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-18 16:36:15 +00:00

Merge pull request #720 from haiwen/sort

Sort
This commit is contained in:
llj
2015-07-14 14:49:07 +08:00
6 changed files with 48 additions and 33 deletions

View File

@@ -293,8 +293,8 @@ define([
'click #mv-dirents': 'mv',
'click #cp-dirents': 'cp',
'click #del-dirents': 'del',
'click #by-name': 'sortByName',
'click #by-time': 'sortByTime'
'click .by-name': 'sortByName',
'click .by-time': 'sortByTime'
},
newDir: function() {
@@ -450,13 +450,16 @@ define([
},
sortByName: function() {
this.$('.by-time .sort-icon').hide();
var dirents = this.dir;
var el = $('#by-name');
var el = this.$('.by-name .sort-icon');
dirents.comparator = function(a, b) {
if (a.get('is_dir') && b.get('is_file')) {
return -1;
} else if (a.get('is_file') && b.get('is_dir')) {
}
if (a.get('is_file') && b.get('is_dir')) {
return 1;
}
@@ -467,21 +470,25 @@ define([
return result;
}
};
dirents.sort();
this.$dirent_list.empty();
dirents.each(this.addOne, this);
el.toggleClass('icon-caret-up icon-caret-down');
el.toggleClass('icon-caret-up icon-caret-down').show();
dirents.comparator = null;
},
sortByTime: function () {
this.$('.by-name .sort-icon').hide();
var dirents = this.dir;
var el = $('#by-time');
var el = this.$('.by-time .sort-icon');
dirents.comparator = function(a, b) {
if (a.get('is_dir') && b.get('is_file')) {
return -1;
}
if (a.get('is_file') && b.get('is_dir')) {
return 1;
}
if (el.hasClass('icon-caret-down')) {
return a.get('last_modified') < b.get('last_modified') ? 1 : -1;
} else {
@@ -489,9 +496,10 @@ define([
}
};
dirents.sort();
this.$dirent_list.empty();
dirents.each(this.addOne, this);
el.toggleClass('icon-caret-up icon-caret-down');
el.toggleClass('icon-caret-up icon-caret-down').show();
dirents.comparator = null;
},

View File

@@ -18,8 +18,8 @@ define([
events: {
'click .repo-create': 'createRepo',
'click #grp-repos .by-name': 'sortByName',
'click #grp-repos .by-time': 'sortByTime'
'click .by-name': 'sortByName',
'click .by-time': 'sortByTime'
},
initialize: function(options) {
@@ -131,8 +131,9 @@ define([
},
sortByName: function() {
this.$('.by-time .sort-icon').hide();
var repos = this.repos;
var el = $('.by-name', this.$table);
var el = this.$('.by-name .sort-icon');
repos.comparator = function(a, b) { // a, b: model
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
if (el.hasClass('icon-caret-up')) {
@@ -144,14 +145,14 @@ define([
repos.sort();
this.$tableBody.empty();
repos.each(this.addOne, this);
el.toggleClass('icon-caret-up icon-caret-down');
el.toggleClass('icon-caret-up icon-caret-down').show();
repos.comparator = null;
},
sortByTime: function() {
this.$('.by-name .sort-icon').hide();
var repos = this.repos;
var el = $('.by-time', this.$table);
var el = this.$('.by-time .sort-icon');
repos.comparator = function(a, b) { // a, b: model
if (el.hasClass('icon-caret-down')) {
return a.get('mtime') < b.get('mtime') ? 1 : -1;
@@ -162,7 +163,7 @@ define([
repos.sort();
this.$tableBody.empty();
repos.each(this.addOne, this);
el.toggleClass('icon-caret-up icon-caret-down');
el.toggleClass('icon-caret-up icon-caret-down').show();
repos.comparator = null;
},

View File

@@ -114,8 +114,9 @@ define([
},
sortByName: function() {
$('.by-time .sort-icon').hide();
var repos = this.repos;
var el = $('.by-name', this.$table);
var el = $('.by-name .sort-icon', this.$table);
repos.comparator = function(a, b) { // a, b: model
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
if (el.hasClass('icon-caret-up')) {
@@ -127,13 +128,14 @@ define([
repos.sort();
this.$tableBody.empty();
repos.each(this.addOne, this);
el.toggleClass('icon-caret-up icon-caret-down');
el.toggleClass('icon-caret-up icon-caret-down').show();
repos.comparator = null;
},
sortByTime: function() {
$('.by-name .sort-icon').hide();
var repos = this.repos;
var el = $('.by-time', this.$table);
var el = $('.by-time .sort-icon', this.$table);
repos.comparator = function(a, b) { // a, b: model
if (el.hasClass('icon-caret-down')) {
return a.get('mtime') < b.get('mtime') ? 1 : -1;
@@ -144,7 +146,7 @@ define([
repos.sort();
this.$tableBody.empty();
repos.each(this.addOne, this);
el.toggleClass('icon-caret-up icon-caret-down');
el.toggleClass('icon-caret-up icon-caret-down').show();
repos.comparator = null;
}

View File

@@ -100,8 +100,9 @@ define([
},
sortByName: function() {
$('.by-time .sort-icon', this.$table).hide();
var repos = this.repos;
var el = $('.by-name', this.$table);
var el = $('.by-name .sort-icon', this.$table);
repos.comparator = function(a, b) { // a, b: model
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
if (el.hasClass('icon-caret-up')) {
@@ -113,13 +114,14 @@ define([
repos.sort();
this.$tableBody.empty();
repos.each(this.addOne, this);
el.toggleClass('icon-caret-up icon-caret-down');
el.toggleClass('icon-caret-up icon-caret-down').show();
repos.comparator = null;
},
sortByTime: function() {
$('.by-name .sort-icon', this.$table).hide();
var repos = this.repos;
var el = $('.by-time', this.$table);
var el = $('.by-time .sort-icon', this.$table);
repos.comparator = function(a, b) { // a, b: model
if (el.hasClass('icon-caret-down')) {
return a.get('mtime') < b.get('mtime') ? 1 : -1;
@@ -130,7 +132,7 @@ define([
repos.sort();
this.$tableBody.empty();
repos.each(this.addOne, this);
el.toggleClass('icon-caret-up icon-caret-down');
el.toggleClass('icon-caret-up icon-caret-down').show();
repos.comparator = null;
}

View File

@@ -139,8 +139,9 @@ define([
},
sortByName: function() {
$('.by-time .sort-icon', this.$table).hide();
var repos = this.repos;
var el = $('.by-name', this.$table);
var el = $('.by-name .sort-icon', this.$table);
repos.comparator = function(a, b) { // a, b: model
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
if (el.hasClass('icon-caret-up')) {
@@ -152,13 +153,14 @@ define([
repos.sort();
this.$tableBody.empty();
repos.each(this.addOne, this);
el.toggleClass('icon-caret-up icon-caret-down');
el.toggleClass('icon-caret-up icon-caret-down').show();
repos.comparator = null;
},
sortByTime: function() {
$('.by-name .sort-icon', this.$table).hide();
var repos = this.repos;
var el = $('.by-time', this.$table);
var el = $('.by-time .sort-icon', this.$table);
repos.comparator = function(a, b) { // a, b: model
if (el.hasClass('icon-caret-down')) {
return a.get('mtime') < b.get('mtime') ? 1 : -1;
@@ -169,7 +171,7 @@ define([
repos.sort();
this.$tableBody.empty();
repos.each(this.addOne, this);
el.toggleClass('icon-caret-up icon-caret-down');
el.toggleClass('icon-caret-up icon-caret-down').show();
repos.comparator = null;
},