1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-02 07:47:32 +00:00

Merge pull request #720 from haiwen/sort

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

View File

@ -173,10 +173,10 @@
</th>
<th class="star"></th>
<th class="dirent-icon"></th>
<th><span class="dirent-name">{% trans "Name"%} <span id="by-name" class="icon-caret-up cspt"></span></span></th>
<th class="by-name cspt"><span class="dirent-name">{% trans "Name"%} <span class="sort-icon icon-caret-up"></span></span></th>
<th class="dirent-op"></th>
<th class="dirent-size">{% trans "Size"%}</th>
<th class="dirent-update">{% trans "Last Update" %} <span id="by-time" class="icon-caret-down cspt"></span></th>
<th class="dirent-update by-time cspt">{% trans "Last Update" %} <span class="sort-icon icon-caret-down hide"></span></th>
</tr>
</script>
<script type="text/template" id="dirent-tmpl">
@ -702,19 +702,19 @@
<script type="text/template" id="my-repos-hd-tmpl">
<tr>
<th width="4%"><!--icon--></th>
<th width="46%">{% trans "Name" %} <span class="by-name icon-caret-up cspt"></span></th>
<th width="46%" class="by-name cspt">{% trans "Name" %} <span class="sort-icon icon-caret-down hide"></span></th>
<th width="10%"><!--op--></th>
<th width="20%">{% trans "Size" %}</th>
<th width="20%">{% trans "Last Update" %} <span class="by-time icon-caret-down cspt"></span></th>
<th width="20%" class="by-time cspt">{% trans "Last Update" %} <span class="sort-icon icon-caret-up"></span></th>
</tr>
</script>
<script type="text/template" id="shared-repos-hd-tmpl">
<tr>
<th width="4%"><!--icon--></th>
<th width="40%">{% trans "Name" %} <span class="by-name icon-caret-up cspt"></span></th>
<th width="40%" class="by-name cspt">{% trans "Name" %} <span class="sort-icon icon-caret-down hide"></span></th>
<th width="8%"><!--op--></th>
<th width="14%">{% trans "Size" %}</th>
<th width="18%">{% trans "Last Update" %} <span class="by-time icon-caret-down cspt"></span></th>
<th width="18%" class="by-time cspt">{% trans "Last Update" %} <span class="sort-icon icon-caret-up"></span></th>
<th width="16%">{% trans "Shared By" %}</th>
</tr>
</script>

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;
},