mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-07 01:41:39 +00:00
[sort] fix, rewrote
This commit is contained in:
@@ -190,8 +190,9 @@ define([
|
|||||||
this.renderDirentsHd();
|
this.renderDirentsHd();
|
||||||
}
|
}
|
||||||
|
|
||||||
Common.updateSortIconByMode(this);
|
// sort
|
||||||
this.dir = Common.sortCollection(this.dir);
|
Common.updateSortIconByMode({'context': this.$el});
|
||||||
|
this.sortDirents();
|
||||||
|
|
||||||
this.dir.last_start = 0;
|
this.dir.last_start = 0;
|
||||||
this.dir.limit = 100;
|
this.dir.limit = 100;
|
||||||
@@ -678,18 +679,64 @@ define([
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
sortByName: function() {
|
sortDirents: function() {
|
||||||
if (app.pageOptions.sort_mode == 'name_up') {
|
var sort_mode = app.pageOptions.sort_mode;
|
||||||
// change sort mode
|
switch(sort_mode) {
|
||||||
Cookies.set('sort_mode', 'name_down');
|
case 'name_up':
|
||||||
app.pageOptions.sort_mode = 'name_down';
|
this.dir.comparator = function(a, b) {
|
||||||
} else {
|
if (a.get('is_dir') && b.get('is_file')) {
|
||||||
Cookies.set('sort_mode', 'name_up');
|
return -1;
|
||||||
app.pageOptions.sort_mode = 'name_up';
|
}
|
||||||
|
if (a.get('is_file') && b.get('is_dir')) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
var result = Common.compareTwoWord(a.get('obj_name'), b.get('obj_name'));
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'name_down':
|
||||||
|
this.dir.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;
|
||||||
|
}
|
||||||
|
var result = Common.compareTwoWord(a.get('obj_name'), b.get('obj_name'));
|
||||||
|
return -result;
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'time_up':
|
||||||
|
this.dir.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;
|
||||||
|
}
|
||||||
|
return a.get('last_modified') < b.get('last_modified') ? -1 : 1;
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'time_down':
|
||||||
|
this.dir.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;
|
||||||
|
}
|
||||||
|
return a.get('last_modified') < b.get('last_modified') ? 1 : -1;
|
||||||
|
};
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Common.updateSortIconByMode(this);
|
this.dir.sort();
|
||||||
this.dir = Common.sortCollection(this.dir);
|
},
|
||||||
|
|
||||||
|
sortByName: function() {
|
||||||
|
Common.toggleSortByNameMode();
|
||||||
|
Common.updateSortIconByMode({'context': this.$el});
|
||||||
|
this.sortDirents();
|
||||||
|
|
||||||
this.$dirent_list_body.empty();
|
this.$dirent_list_body.empty();
|
||||||
this.render_dirents_slice(0, this.dir.limit);
|
this.render_dirents_slice(0, this.dir.limit);
|
||||||
@@ -698,17 +745,9 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
sortByTime: function () {
|
sortByTime: function () {
|
||||||
if (app.pageOptions.sort_mode == 'time_down') {
|
Common.toggleSortByTimeMode();
|
||||||
// change sort mode
|
Common.updateSortIconByMode({'context': this.$el});
|
||||||
Cookies.set('sort_mode', 'time_up');
|
this.sortDirents();
|
||||||
app.pageOptions.sort_mode = 'time_up';
|
|
||||||
} else {
|
|
||||||
Cookies.set('sort_mode', 'time_down');
|
|
||||||
app.pageOptions.sort_mode = 'time_down';
|
|
||||||
}
|
|
||||||
|
|
||||||
Common.updateSortIconByMode(this);
|
|
||||||
this.dir = Common.sortCollection(this.dir);
|
|
||||||
|
|
||||||
this.$dirent_list_body.empty();
|
this.$dirent_list_body.empty();
|
||||||
this.render_dirents_slice(0, this.dir.limit);
|
this.render_dirents_slice(0, this.dir.limit);
|
||||||
|
@@ -3,14 +3,13 @@ define([
|
|||||||
'underscore',
|
'underscore',
|
||||||
'backbone',
|
'backbone',
|
||||||
'common',
|
'common',
|
||||||
'js.cookie',
|
|
||||||
'app/collections/group-repos',
|
'app/collections/group-repos',
|
||||||
'app/views/group-repo',
|
'app/views/group-repo',
|
||||||
'app/views/add-group-repo',
|
'app/views/add-group-repo',
|
||||||
'app/views/group-members',
|
'app/views/group-members',
|
||||||
'app/views/group-discussions',
|
'app/views/group-discussions',
|
||||||
'app/views/group-settings'
|
'app/views/group-settings'
|
||||||
], function($, _, Backbone, Common, Cookies, GroupRepos, GroupRepoView,
|
], function($, _, Backbone, Common, GroupRepos, GroupRepoView,
|
||||||
AddGroupRepoView, GroupMembersView, GroupDiscussionsView, GroupSettingsView) {
|
AddGroupRepoView, GroupMembersView, GroupDiscussionsView, GroupSettingsView) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@@ -67,7 +66,11 @@ define([
|
|||||||
this.$emptyTip.hide();
|
this.$emptyTip.hide();
|
||||||
this.renderReposHd();
|
this.renderReposHd();
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
this.repos = Common.sortCollection(this.repos);
|
|
||||||
|
// sort
|
||||||
|
Common.updateSortIconByMode({'context': this.$el});
|
||||||
|
Common.sortLibs({'libs': this.repos});
|
||||||
|
|
||||||
this.repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
this.$table.show();
|
this.$table.show();
|
||||||
} else {
|
} else {
|
||||||
@@ -75,7 +78,6 @@ define([
|
|||||||
this.$table.hide();
|
this.$table.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
Common.updateSortIconByMode(this);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
renderGroupTop: function(options) {
|
renderGroupTop: function(options) {
|
||||||
@@ -172,19 +174,9 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
sortByName: function() {
|
sortByName: function() {
|
||||||
|
Common.toggleSortByNameMode();
|
||||||
|
Common.updateSortIconByMode({'context': this.$el});
|
||||||
if (app.pageOptions.sort_mode == 'name_up') {
|
Common.sortLibs({'libs': this.repos});
|
||||||
// change sort mode
|
|
||||||
Cookies.set('sort_mode', 'name_down');
|
|
||||||
app.pageOptions.sort_mode = 'name_down';
|
|
||||||
} else {
|
|
||||||
Cookies.set('sort_mode', 'name_up');
|
|
||||||
app.pageOptions.sort_mode = 'name_up';
|
|
||||||
}
|
|
||||||
|
|
||||||
Common.updateSortIconByMode(this);
|
|
||||||
this.repos = Common.sortCollection(this.repos);
|
|
||||||
|
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
this.repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
@@ -194,17 +186,9 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
sortByTime: function() {
|
sortByTime: function() {
|
||||||
if (app.pageOptions.sort_mode == 'time_down') {
|
Common.toggleSortByTimeMode();
|
||||||
// change sort mode
|
Common.updateSortIconByMode({'context': this.$el});
|
||||||
Cookies.set('sort_mode', 'time_up');
|
Common.sortLibs({'libs': this.repos});
|
||||||
app.pageOptions.sort_mode = 'time_up';
|
|
||||||
} else {
|
|
||||||
Cookies.set('sort_mode', 'time_down');
|
|
||||||
app.pageOptions.sort_mode = 'time_down';
|
|
||||||
}
|
|
||||||
|
|
||||||
Common.updateSortIconByMode(this);
|
|
||||||
this.repos = Common.sortCollection(this.repos);
|
|
||||||
|
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
this.repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
|
@@ -3,11 +3,10 @@ define([
|
|||||||
'underscore',
|
'underscore',
|
||||||
'backbone',
|
'backbone',
|
||||||
'common',
|
'common',
|
||||||
'js.cookie',
|
|
||||||
'app/collections/repos',
|
'app/collections/repos',
|
||||||
'app/views/repo',
|
'app/views/repo',
|
||||||
'app/views/add-repo',
|
'app/views/add-repo',
|
||||||
], function($, _, Backbone, Common, Cookies, RepoCollection, RepoView, AddRepoView) {
|
], function($, _, Backbone, Common, RepoCollection, RepoView, AddRepoView) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var ReposView = Backbone.View.extend({
|
var ReposView = Backbone.View.extend({
|
||||||
@@ -50,7 +49,11 @@ define([
|
|||||||
this.$emptyTip.hide();
|
this.$emptyTip.hide();
|
||||||
this.renderReposHd();
|
this.renderReposHd();
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
this.repos = Common.sortCollection(this.repos);
|
|
||||||
|
// sort
|
||||||
|
Common.updateSortIconByMode({'context': this.$el});
|
||||||
|
Common.sortLibs({'libs': this.repos});
|
||||||
|
|
||||||
this.repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
this.$table.show();
|
this.$table.show();
|
||||||
} else {
|
} else {
|
||||||
@@ -58,8 +61,6 @@ define([
|
|||||||
this.$emptyTip.show();
|
this.$emptyTip.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
Common.updateSortIconByMode(this);
|
|
||||||
|
|
||||||
if (app.pageOptions.guide_enabled) {
|
if (app.pageOptions.guide_enabled) {
|
||||||
$('#guide-for-new').modal({appendTo: '#main', focus:false});
|
$('#guide-for-new').modal({appendTo: '#main', focus:false});
|
||||||
$('#simplemodal-container').css({'height':'auto'});
|
$('#simplemodal-container').css({'height':'auto'});
|
||||||
@@ -119,17 +120,9 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
sortByName: function() {
|
sortByName: function() {
|
||||||
if (app.pageOptions.sort_mode == 'name_up') {
|
Common.toggleSortByNameMode();
|
||||||
// change sort mode
|
Common.updateSortIconByMode({'context': this.$el});
|
||||||
Cookies.set('sort_mode', 'name_down');
|
Common.sortLibs({'libs': this.repos});
|
||||||
app.pageOptions.sort_mode = 'name_down';
|
|
||||||
} else {
|
|
||||||
Cookies.set('sort_mode', 'name_up');
|
|
||||||
app.pageOptions.sort_mode = 'name_up';
|
|
||||||
}
|
|
||||||
|
|
||||||
Common.updateSortIconByMode(this);
|
|
||||||
this.repos = Common.sortCollection(this.repos);
|
|
||||||
|
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
this.repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
@@ -139,17 +132,9 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
sortByTime: function() {
|
sortByTime: function() {
|
||||||
if (app.pageOptions.sort_mode == 'time_down') {
|
Common.toggleSortByTimeMode();
|
||||||
// change sort mode
|
Common.updateSortIconByMode({'context': this.$el});
|
||||||
Cookies.set('sort_mode', 'time_up');
|
Common.sortLibs({'libs': this.repos});
|
||||||
app.pageOptions.sort_mode = 'time_up';
|
|
||||||
} else {
|
|
||||||
Cookies.set('sort_mode', 'time_down');
|
|
||||||
app.pageOptions.sort_mode = 'time_down';
|
|
||||||
}
|
|
||||||
|
|
||||||
Common.updateSortIconByMode(this);
|
|
||||||
this.repos = Common.sortCollection(this.repos);
|
|
||||||
|
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
this.repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
|
@@ -3,10 +3,9 @@ define([
|
|||||||
'underscore',
|
'underscore',
|
||||||
'backbone',
|
'backbone',
|
||||||
'common',
|
'common',
|
||||||
'js.cookie',
|
|
||||||
'app/collections/repos',
|
'app/collections/repos',
|
||||||
'app/views/shared-repo',
|
'app/views/shared-repo',
|
||||||
], function($, _, Backbone, Common, Cookies, RepoCollection, SharedRepoView) {
|
], function($, _, Backbone, Common, RepoCollection, SharedRepoView) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var SharedReposView = Backbone.View.extend({
|
var SharedReposView = Backbone.View.extend({
|
||||||
@@ -42,7 +41,11 @@ define([
|
|||||||
this.$emptyTip.hide();
|
this.$emptyTip.hide();
|
||||||
this.renderReposHd();
|
this.renderReposHd();
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
this.repos = Common.sortCollection(this.repos);
|
|
||||||
|
// sort
|
||||||
|
Common.updateSortIconByMode({'context': this.$el});
|
||||||
|
Common.sortLibs({'libs': this.repos});
|
||||||
|
|
||||||
this.repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
this.$table.show();
|
this.$table.show();
|
||||||
} else {
|
} else {
|
||||||
@@ -50,7 +53,6 @@ define([
|
|||||||
this.$table.hide();
|
this.$table.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
Common.updateSortIconByMode(this);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
showSharedRepos: function() {
|
showSharedRepos: function() {
|
||||||
@@ -106,17 +108,9 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
sortByName: function() {
|
sortByName: function() {
|
||||||
if (app.pageOptions.sort_mode == 'name_up') {
|
Common.toggleSortByNameMode();
|
||||||
// change sort mode
|
Common.updateSortIconByMode({'context': this.$el});
|
||||||
Cookies.set('sort_mode', 'name_down');
|
Common.sortLibs({'libs': this.repos});
|
||||||
app.pageOptions.sort_mode = 'name_down';
|
|
||||||
} else {
|
|
||||||
Cookies.set('sort_mode', 'name_up');
|
|
||||||
app.pageOptions.sort_mode = 'name_up';
|
|
||||||
}
|
|
||||||
|
|
||||||
Common.updateSortIconByMode(this);
|
|
||||||
this.repos = Common.sortCollection(this.repos);
|
|
||||||
|
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
this.repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
@@ -125,17 +119,9 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
sortByTime: function() {
|
sortByTime: function() {
|
||||||
if (app.pageOptions.sort_mode == 'time_down') {
|
Common.toggleSortByTimeMode();
|
||||||
// change sort mode
|
Common.updateSortIconByMode({'context': this.$el});
|
||||||
Cookies.set('sort_mode', 'time_up');
|
Common.sortLibs({'libs': this.repos});
|
||||||
app.pageOptions.sort_mode = 'time_up';
|
|
||||||
} else {
|
|
||||||
Cookies.set('sort_mode', 'time_down');
|
|
||||||
app.pageOptions.sort_mode = 'time_down';
|
|
||||||
}
|
|
||||||
|
|
||||||
Common.updateSortIconByMode(this);
|
|
||||||
this.repos = Common.sortCollection(this.repos);
|
|
||||||
|
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
this.repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
|
@@ -87,14 +87,17 @@ define([
|
|||||||
this.$emptyTip.hide();
|
this.$emptyTip.hide();
|
||||||
this.renderReposHd();
|
this.renderReposHd();
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
this.repos = Common.sortCollection(this.repos);
|
|
||||||
|
// sort
|
||||||
|
Common.updateSortIconByMode({'context': this.$el});
|
||||||
|
Common.sortLibs({'libs': this.repos});
|
||||||
|
|
||||||
this.repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
this.$table.show();
|
this.$table.show();
|
||||||
} else {
|
} else {
|
||||||
this.$table.hide();
|
this.$table.hide();
|
||||||
this.$emptyTip.show();
|
this.$emptyTip.show();
|
||||||
}
|
}
|
||||||
Common.updateSortIconByMode(this);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
showRepoList: function() {
|
showRepoList: function() {
|
||||||
@@ -125,17 +128,9 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
sortByName: function() {
|
sortByName: function() {
|
||||||
if (app.pageOptions.sort_mode == 'name_up') {
|
Common.toggleSortByNameMode();
|
||||||
// change sort mode
|
Common.updateSortIconByMode({'context': this.$el});
|
||||||
Cookies.set('sort_mode', 'name_down');
|
Common.sortLibs({'libs': this.repos});
|
||||||
app.pageOptions.sort_mode = 'name_down';
|
|
||||||
} else {
|
|
||||||
Cookies.set('sort_mode', 'name_up');
|
|
||||||
app.pageOptions.sort_mode = 'name_up';
|
|
||||||
}
|
|
||||||
|
|
||||||
Common.updateSortIconByMode(this);
|
|
||||||
this.repos = Common.sortCollection(this.repos);
|
|
||||||
|
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
this.repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
@@ -145,17 +140,9 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
sortByTime: function() {
|
sortByTime: function() {
|
||||||
if (app.pageOptions.sort_mode == 'time_down') {
|
Common.toggleSortByTimeMode();
|
||||||
// change sort mode
|
Common.updateSortIconByMode({'context': this.$el});
|
||||||
Cookies.set('sort_mode', 'time_up');
|
Common.sortLibs({'libs': this.repos});
|
||||||
app.pageOptions.sort_mode = 'time_up';
|
|
||||||
} else {
|
|
||||||
Cookies.set('sort_mode', 'time_down');
|
|
||||||
app.pageOptions.sort_mode = 'time_down';
|
|
||||||
}
|
|
||||||
|
|
||||||
Common.updateSortIconByMode(this);
|
|
||||||
this.repos = Common.sortCollection(this.repos);
|
|
||||||
|
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
this.repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
|
@@ -63,7 +63,8 @@ define([
|
|||||||
'text', // Workaround for r.js, otherwise text.js will not be included
|
'text', // Workaround for r.js, otherwise text.js will not be included
|
||||||
'pinyin-by-unicode',
|
'pinyin-by-unicode',
|
||||||
'moment',
|
'moment',
|
||||||
], function($, _, text, PinyinByUnicode, Moment) {
|
'js.cookie'
|
||||||
|
], function($, _, text, PinyinByUnicode, Moment, Cookies) {
|
||||||
return {
|
return {
|
||||||
INFO_TIMEOUT: 10000, // 10 secs for info msg
|
INFO_TIMEOUT: 10000, // 10 secs for info msg
|
||||||
SUCCESS_TIMEOUT: 3000, // 3 secs for success msg
|
SUCCESS_TIMEOUT: 3000, // 3 secs for success msg
|
||||||
@@ -778,67 +779,87 @@ define([
|
|||||||
return (a >= b) - (a <= b);
|
return (a >= b) - (a <= b);
|
||||||
},
|
},
|
||||||
|
|
||||||
updateSortIconByMode: function(current_el) {
|
toggleSortByNameMode: function() {
|
||||||
var sort_mode = app.pageOptions.sort_mode;
|
if (app.pageOptions.sort_mode == 'name_up') {
|
||||||
|
Cookies.set('sort_mode', 'name_down');
|
||||||
// first hide all icon
|
app.pageOptions.sort_mode = 'name_down';
|
||||||
current_el.$('.by-name .sort-icon, .by-time .sort-icon').hide();
|
|
||||||
|
|
||||||
// show icon according sort mode
|
|
||||||
if (sort_mode == 'name_down') {
|
|
||||||
current_el.$('.by-name .sort-icon').removeClass('icon-caret-up').addClass('icon-caret-down').show();
|
|
||||||
} else if (sort_mode == 'name_up') {
|
|
||||||
current_el.$('.by-name .sort-icon').removeClass('icon-caret-down').addClass('icon-caret-up').show();
|
|
||||||
} else if (sort_mode == 'time_down') {
|
|
||||||
current_el.$('.by-time .sort-icon').removeClass('icon-caret-up').addClass('icon-caret-down').show();
|
|
||||||
} else if (sort_mode == 'time_up') {
|
|
||||||
current_el.$('.by-time .sort-icon').removeClass('icon-caret-down').addClass('icon-caret-up').show();
|
|
||||||
} else {
|
} else {
|
||||||
// if no sort mode, show name up icon
|
Cookies.set('sort_mode', 'name_up');
|
||||||
current_el.$('.by-name .sort-icon').removeClass('icon-caret-down').addClass('icon-caret-up').show();
|
app.pageOptions.sort_mode = 'name_up';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
sortCollection: function(current_collection) {
|
toggleSortByTimeMode: function() {
|
||||||
|
if (app.pageOptions.sort_mode == 'time_down') {
|
||||||
|
Cookies.set('sort_mode', 'time_up');
|
||||||
|
app.pageOptions.sort_mode = 'time_up';
|
||||||
|
} else {
|
||||||
|
Cookies.set('sort_mode', 'time_down');
|
||||||
|
app.pageOptions.sort_mode = 'time_down';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
updateSortIconByMode: function(options) {
|
||||||
var sort_mode = app.pageOptions.sort_mode;
|
var sort_mode = app.pageOptions.sort_mode;
|
||||||
|
|
||||||
|
var context = options.context;
|
||||||
|
var $byNameIcon = $('.by-name .sort-icon', context),
|
||||||
|
$byTimeIcon = $('.by-time .sort-icon', context);
|
||||||
|
|
||||||
|
// hide icons
|
||||||
|
$byNameIcon.hide();
|
||||||
|
$byTimeIcon.hide();
|
||||||
|
|
||||||
|
// show icon according sort mode
|
||||||
|
switch(sort_mode) {
|
||||||
|
case 'name_down':
|
||||||
|
$byNameIcon.removeClass('icon-caret-up').addClass('icon-caret-down').show();
|
||||||
|
break;
|
||||||
|
case 'name_up':
|
||||||
|
$byNameIcon.removeClass('icon-caret-down').addClass('icon-caret-up').show();
|
||||||
|
break;
|
||||||
|
case 'time_down':
|
||||||
|
$byTimeIcon.removeClass('icon-caret-up').addClass('icon-caret-down').show();
|
||||||
|
break;
|
||||||
|
case 'time_up':
|
||||||
|
$byTimeIcon.removeClass('icon-caret-down').addClass('icon-caret-up').show();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$byNameIcon.removeClass('icon-caret-down').addClass('icon-caret-up').show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
sortLibs: function(options) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
var sort_mode = app.pageOptions.sort_mode;
|
||||||
|
var libs = options.libs;
|
||||||
|
|
||||||
// set collection comparator
|
switch(sort_mode) {
|
||||||
current_collection.comparator = function(a, b) {
|
case 'name_up':
|
||||||
if (a.get('is_dir') && b.get('is_file')) {
|
libs.comparator = function(a, b) {
|
||||||
return -1;
|
var result = _this.compareTwoWord(a.get('name'), b.get('name'));
|
||||||
}
|
|
||||||
if (a.get('is_file') && b.get('is_dir')) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
var a_name = a.get('name') || a.get('obj_name');
|
|
||||||
var b_name = b.get('name') || b.get('obj_name');
|
|
||||||
|
|
||||||
var a_time = a.get('mtime') || a.get('last_modified');
|
|
||||||
var b_time = b.get('mtime') || b.get('last_modified');
|
|
||||||
|
|
||||||
if (sort_mode == 'name_down' || sort_mode == 'name_up') {
|
|
||||||
// if sort by name
|
|
||||||
var result = _this.compareTwoWord(a_name, b_name);
|
|
||||||
if (sort_mode == 'name_down') {
|
|
||||||
return -result;
|
|
||||||
} else {
|
|
||||||
return result;
|
return result;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// if sort by time
|
|
||||||
if (sort_mode == 'time_up') {
|
|
||||||
return a_time < b_time ? -1 : 1;
|
|
||||||
} else {
|
|
||||||
return a_time < b_time ? 1 : -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
break;
|
||||||
// sort collection
|
case 'name_down':
|
||||||
current_collection.sort();
|
libs.comparator = function(a, b) {
|
||||||
return current_collection;
|
var result = _this.compareTwoWord(a.get('name'), b.get('name'));
|
||||||
|
return -result;
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'time_up':
|
||||||
|
libs.comparator = function(a, b) {
|
||||||
|
return a.get('mtime') < b.get('mtime') ? -1 : 1;
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'time_down':
|
||||||
|
libs.comparator = function(a, b) {
|
||||||
|
return a.get('mtime') < b.get('mtime') ? 1 : -1;
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
libs.sort();
|
||||||
},
|
},
|
||||||
|
|
||||||
fileSizeFormat: function(bytes, precision) {
|
fileSizeFormat: function(bytes, precision) {
|
||||||
|
Reference in New Issue
Block a user