mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-11 11:51:27 +00:00
remember sort mode after sort repos/dirents
This commit is contained in:
@@ -3,6 +3,7 @@ define([
|
|||||||
'jquery',
|
'jquery',
|
||||||
'backbone',
|
'backbone',
|
||||||
'common',
|
'common',
|
||||||
|
'js.cookie',
|
||||||
'app/views/side-nav',
|
'app/views/side-nav',
|
||||||
'app/views/myhome-repos',
|
'app/views/myhome-repos',
|
||||||
'app/views/myhome-shared-repos',
|
'app/views/myhome-shared-repos',
|
||||||
@@ -20,7 +21,7 @@ define([
|
|||||||
'app/views/share-admin-upload-links',
|
'app/views/share-admin-upload-links',
|
||||||
'app/views/notifications',
|
'app/views/notifications',
|
||||||
'app/views/account'
|
'app/views/account'
|
||||||
], function($, Backbone, Common, SideNavView, MyReposView,
|
], function($, Backbone, Common, Cookies, SideNavView, MyReposView,
|
||||||
SharedReposView, GroupsView, GroupView, OrgView, DirView,
|
SharedReposView, GroupsView, GroupView, OrgView, DirView,
|
||||||
StarredFileView, ActivitiesView, DevicesView, InvitationsView,
|
StarredFileView, ActivitiesView, DevicesView, InvitationsView,
|
||||||
ShareAdminReposView, ShareAdminFoldersView, ShareAdminShareLinksView,
|
ShareAdminReposView, ShareAdminFoldersView, ShareAdminShareLinksView,
|
||||||
@@ -81,6 +82,7 @@ define([
|
|||||||
|
|
||||||
app.ui.notificationsView = this.notificationsView = new NotificationsView();
|
app.ui.notificationsView = this.notificationsView = new NotificationsView();
|
||||||
app.ui.accountView = this.accountView = new AccountView();
|
app.ui.accountView = this.accountView = new AccountView();
|
||||||
|
app.pageOptions.sort_mode = Cookies.get('sort_mode') || 'name_up';
|
||||||
|
|
||||||
this.currentView = this.myReposView;
|
this.currentView = this.myReposView;
|
||||||
|
|
||||||
|
@@ -42,17 +42,6 @@ define([
|
|||||||
this.view_mode = 'list';
|
this.view_mode = 'list';
|
||||||
}
|
}
|
||||||
|
|
||||||
var sort_mode = Cookies.get('sort_mode');
|
|
||||||
if (sort_mode == 'time_up') {
|
|
||||||
this.sort_mode = 'time_up';
|
|
||||||
} else if (sort_mode == 'time_down') {
|
|
||||||
this.sort_mode = 'time_down';
|
|
||||||
} else if (sort_mode == 'name_down') {
|
|
||||||
this.sort_mode = 'name_down';
|
|
||||||
} else {
|
|
||||||
this.sort_mode = 'name_up';
|
|
||||||
}
|
|
||||||
|
|
||||||
this.contextOptions = {};
|
this.contextOptions = {};
|
||||||
|
|
||||||
this.dir = new DirentCollection();
|
this.dir = new DirentCollection();
|
||||||
@@ -201,8 +190,8 @@ define([
|
|||||||
this.renderDirentsHd();
|
this.renderDirentsHd();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateSortIconByMode(this.sort_mode);
|
Common.updateSortIconByMode(this);
|
||||||
this.sortDirents(this.sort_mode);
|
this.dir = Common.sortCollection(this.dir);
|
||||||
|
|
||||||
this.dir.last_start = 0;
|
this.dir.last_start = 0;
|
||||||
this.dir.limit = 100;
|
this.dir.limit = 100;
|
||||||
@@ -690,17 +679,17 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
sortByName: function() {
|
sortByName: function() {
|
||||||
if (this.sort_mode == 'name_up') {
|
if (app.pageOptions.sort_mode == 'name_up') {
|
||||||
// change sort mode
|
// change sort mode
|
||||||
Cookies.set('sort_mode', 'name_down');
|
Cookies.set('sort_mode', 'name_down');
|
||||||
this.sort_mode = 'name_down';
|
app.pageOptions.sort_mode = 'name_down';
|
||||||
} else {
|
} else {
|
||||||
Cookies.set('sort_mode', 'name_up');
|
Cookies.set('sort_mode', 'name_up');
|
||||||
this.sort_mode = 'name_up';
|
app.pageOptions.sort_mode = 'name_up';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateSortIconByMode(this.sort_mode);
|
Common.updateSortIconByMode(this);
|
||||||
this.sortDirents(this.sort_mode);
|
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);
|
||||||
@@ -709,17 +698,17 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
sortByTime: function () {
|
sortByTime: function () {
|
||||||
if (this.sort_mode == 'time_up') {
|
if (app.pageOptions.sort_mode == 'time_down') {
|
||||||
// change sort mode
|
// change sort mode
|
||||||
Cookies.set('sort_mode', 'time_down');
|
|
||||||
this.sort_mode = 'time_down';
|
|
||||||
} else {
|
|
||||||
Cookies.set('sort_mode', 'time_up');
|
Cookies.set('sort_mode', 'time_up');
|
||||||
this.sort_mode = 'time_up';
|
app.pageOptions.sort_mode = 'time_up';
|
||||||
|
} else {
|
||||||
|
Cookies.set('sort_mode', 'time_down');
|
||||||
|
app.pageOptions.sort_mode = 'time_down';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateSortIconByMode(this.sort_mode);
|
Common.updateSortIconByMode(this);
|
||||||
this.sortDirents(this.sort_mode);
|
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);
|
||||||
@@ -727,57 +716,6 @@ define([
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
sortDirents: function(sort_mode) {
|
|
||||||
// set collection comparator
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sort_mode == 'name_up' || sort_mode == 'name_down') {
|
|
||||||
// if sort by name
|
|
||||||
var result = Common.compareTwoWord(a.get('obj_name'), b.get('obj_name'));
|
|
||||||
if (sort_mode == 'name_up') {
|
|
||||||
return -result;
|
|
||||||
} else {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// if sort by time
|
|
||||||
if (sort_mode == 'time_up') {
|
|
||||||
return a.get('last_modified') < b.get('last_modified') ? -1 : 1;
|
|
||||||
} else {
|
|
||||||
return a.get('last_modified') < b.get('last_modified') ? 1 : -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// sort collection
|
|
||||||
this.dir.sort();
|
|
||||||
},
|
|
||||||
|
|
||||||
updateSortIconByMode: function(sort_mode) {
|
|
||||||
// first hide all icon
|
|
||||||
this.$('.by-name .sort-icon, .by-time .sort-icon').hide();
|
|
||||||
|
|
||||||
// show icon according sort mode
|
|
||||||
if (sort_mode == 'name_up') {
|
|
||||||
this.$('.by-name .sort-icon').removeClass('icon-caret-up').addClass('icon-caret-down').show();
|
|
||||||
} else if (sort_mode == 'name_down') {
|
|
||||||
this.$('.by-name .sort-icon').removeClass('icon-caret-down').addClass('icon-caret-up').show();
|
|
||||||
} else if (sort_mode == 'time_up') {
|
|
||||||
this.$('.by-time .sort-icon').removeClass('icon-caret-up').addClass('icon-caret-down').show();
|
|
||||||
} else if (sort_mode == 'time_down') {
|
|
||||||
this.$('.by-time .sort-icon').removeClass('icon-caret-down').addClass('icon-caret-up').show();
|
|
||||||
} else {
|
|
||||||
// if no sort mode, show name up icon
|
|
||||||
this.$('.by-name .sort-icon').removeClass('icon-caret-down').addClass('icon-caret-up').show();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
select: function () {
|
select: function () {
|
||||||
var $el = this.$('th [type=checkbox]');
|
var $el = this.$('th [type=checkbox]');
|
||||||
|
|
||||||
|
@@ -3,13 +3,14 @@ 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, GroupRepos, GroupRepoView,
|
], function($, _, Backbone, Common, Cookies, GroupRepos, GroupRepoView,
|
||||||
AddGroupRepoView, GroupMembersView, GroupDiscussionsView, GroupSettingsView) {
|
AddGroupRepoView, GroupMembersView, GroupDiscussionsView, GroupSettingsView) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@@ -66,12 +67,15 @@ define([
|
|||||||
this.$emptyTip.hide();
|
this.$emptyTip.hide();
|
||||||
this.renderReposHd();
|
this.renderReposHd();
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
|
this.repos = Common.sortCollection(this.repos);
|
||||||
this.repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
this.$table.show();
|
this.$table.show();
|
||||||
} else {
|
} else {
|
||||||
this.$emptyTip.show();
|
this.$emptyTip.show();
|
||||||
this.$table.hide();
|
this.$table.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Common.updateSortIconByMode(this);
|
||||||
},
|
},
|
||||||
|
|
||||||
renderGroupTop: function(options) {
|
renderGroupTop: function(options) {
|
||||||
@@ -168,46 +172,44 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
sortByName: function() {
|
sortByName: function() {
|
||||||
this.$('.by-time .sort-icon').hide();
|
|
||||||
var repos = this.repos;
|
|
||||||
var $el = this.$('.by-name .sort-icon');
|
if (app.pageOptions.sort_mode == 'name_up') {
|
||||||
if ($el.hasClass('icon-caret-up')) {
|
// change sort mode
|
||||||
repos.comparator = function(a, b) { // a, b: model
|
Cookies.set('sort_mode', 'name_down');
|
||||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
app.pageOptions.sort_mode = 'name_down';
|
||||||
return -result;
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
repos.comparator = function(a, b) { // a, b: model
|
Cookies.set('sort_mode', 'name_up');
|
||||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
app.pageOptions.sort_mode = 'name_up';
|
||||||
return result;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
repos.sort();
|
|
||||||
|
Common.updateSortIconByMode(this);
|
||||||
|
this.repos = Common.sortCollection(this.repos);
|
||||||
|
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
this.repos.comparator = null;
|
||||||
repos.comparator = null;
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
sortByTime: function() {
|
sortByTime: function() {
|
||||||
this.$('.by-name .sort-icon').hide();
|
if (app.pageOptions.sort_mode == 'time_down') {
|
||||||
var repos = this.repos;
|
// change sort mode
|
||||||
var $el = this.$('.by-time .sort-icon');
|
Cookies.set('sort_mode', 'time_up');
|
||||||
if ($el.hasClass('icon-caret-down')) {
|
app.pageOptions.sort_mode = 'time_up';
|
||||||
repos.comparator = function(a, b) { // a, b: model
|
|
||||||
return a.get('mtime') < b.get('mtime') ? 1 : -1;
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
repos.comparator = function(a, b) { // a, b: model
|
Cookies.set('sort_mode', 'time_down');
|
||||||
return a.get('mtime') < b.get('mtime') ? -1 : 1;
|
app.pageOptions.sort_mode = 'time_down';
|
||||||
};
|
|
||||||
}
|
}
|
||||||
repos.sort();
|
|
||||||
|
Common.updateSortIconByMode(this);
|
||||||
|
this.repos = Common.sortCollection(this.repos);
|
||||||
|
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
this.repos.comparator = null;
|
||||||
repos.comparator = null;
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -3,10 +3,11 @@ 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, RepoCollection, RepoView, AddRepoView) {
|
], function($, _, Backbone, Common, Cookies, RepoCollection, RepoView, AddRepoView) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var ReposView = Backbone.View.extend({
|
var ReposView = Backbone.View.extend({
|
||||||
@@ -49,6 +50,7 @@ define([
|
|||||||
this.$emptyTip.hide();
|
this.$emptyTip.hide();
|
||||||
this.renderReposHd();
|
this.renderReposHd();
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
|
this.repos = Common.sortCollection(this.repos);
|
||||||
this.repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
this.$table.show();
|
this.$table.show();
|
||||||
} else {
|
} else {
|
||||||
@@ -56,6 +58,8 @@ 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'});
|
||||||
@@ -115,46 +119,42 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
sortByName: function() {
|
sortByName: function() {
|
||||||
$('.by-time .sort-icon').hide();
|
if (app.pageOptions.sort_mode == 'name_up') {
|
||||||
var repos = this.repos;
|
// change sort mode
|
||||||
var $el = $('.by-name .sort-icon', this.$table);
|
Cookies.set('sort_mode', 'name_down');
|
||||||
if ($el.hasClass('icon-caret-up')) {
|
app.pageOptions.sort_mode = 'name_down';
|
||||||
repos.comparator = function(a, b) { // a, b: model
|
|
||||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
|
||||||
return -result;
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
repos.comparator = function(a, b) { // a, b: model
|
Cookies.set('sort_mode', 'name_up');
|
||||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
app.pageOptions.sort_mode = 'name_up';
|
||||||
return result;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
repos.sort();
|
|
||||||
|
Common.updateSortIconByMode(this);
|
||||||
|
this.repos = Common.sortCollection(this.repos);
|
||||||
|
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
this.repos.comparator = null;
|
||||||
repos.comparator = null;
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
sortByTime: function() {
|
sortByTime: function() {
|
||||||
$('.by-name .sort-icon').hide();
|
if (app.pageOptions.sort_mode == 'time_down') {
|
||||||
var repos = this.repos;
|
// change sort mode
|
||||||
var $el = $('.by-time .sort-icon', this.$table);
|
Cookies.set('sort_mode', 'time_up');
|
||||||
if ($el.hasClass('icon-caret-down')) {
|
app.pageOptions.sort_mode = 'time_up';
|
||||||
repos.comparator = function(a, b) { // a, b: model
|
|
||||||
return a.get('mtime') < b.get('mtime') ? 1 : -1;
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
repos.comparator = function(a, b) { // a, b: model
|
Cookies.set('sort_mode', 'time_down');
|
||||||
return a.get('mtime') < b.get('mtime') ? -1 : 1;
|
app.pageOptions.sort_mode = 'time_down';
|
||||||
};
|
|
||||||
}
|
}
|
||||||
repos.sort();
|
|
||||||
|
Common.updateSortIconByMode(this);
|
||||||
|
this.repos = Common.sortCollection(this.repos);
|
||||||
|
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
this.repos.comparator = null;
|
||||||
repos.comparator = null;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,9 +3,10 @@ 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, RepoCollection, SharedRepoView) {
|
], function($, _, Backbone, Common, Cookies, RepoCollection, SharedRepoView) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var SharedReposView = Backbone.View.extend({
|
var SharedReposView = Backbone.View.extend({
|
||||||
@@ -41,12 +42,15 @@ define([
|
|||||||
this.$emptyTip.hide();
|
this.$emptyTip.hide();
|
||||||
this.renderReposHd();
|
this.renderReposHd();
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
|
this.repos = Common.sortCollection(this.repos);
|
||||||
this.repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
this.$table.show();
|
this.$table.show();
|
||||||
} else {
|
} else {
|
||||||
this.$emptyTip.show();
|
this.$emptyTip.show();
|
||||||
this.$table.hide();
|
this.$table.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Common.updateSortIconByMode(this);
|
||||||
},
|
},
|
||||||
|
|
||||||
showSharedRepos: function() {
|
showSharedRepos: function() {
|
||||||
@@ -102,46 +106,41 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
sortByName: function() {
|
sortByName: function() {
|
||||||
$('.by-time .sort-icon', this.$table).hide();
|
if (app.pageOptions.sort_mode == 'name_up') {
|
||||||
var repos = this.repos;
|
// change sort mode
|
||||||
var $el = $('.by-name .sort-icon', this.$table);
|
Cookies.set('sort_mode', 'name_down');
|
||||||
if ($el.hasClass('icon-caret-up')) {
|
app.pageOptions.sort_mode = 'name_down';
|
||||||
repos.comparator = function(a, b) { // a, b: model
|
|
||||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
|
||||||
return -result;
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
repos.comparator = function(a, b) { // a, b: model
|
Cookies.set('sort_mode', 'name_up');
|
||||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
app.pageOptions.sort_mode = 'name_up';
|
||||||
return result;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
repos.sort();
|
|
||||||
|
Common.updateSortIconByMode(this);
|
||||||
|
this.repos = Common.sortCollection(this.repos);
|
||||||
|
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
this.repos.comparator = null;
|
||||||
repos.comparator = null;
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
sortByTime: function() {
|
sortByTime: function() {
|
||||||
$('.by-name .sort-icon', this.$table).hide();
|
if (app.pageOptions.sort_mode == 'time_down') {
|
||||||
var repos = this.repos;
|
// change sort mode
|
||||||
var $el = $('.by-time .sort-icon', this.$table);
|
Cookies.set('sort_mode', 'time_up');
|
||||||
if ($el.hasClass('icon-caret-down')) {
|
app.pageOptions.sort_mode = 'time_up';
|
||||||
repos.comparator = function(a, b) { // a, b: model
|
|
||||||
return a.get('mtime') < b.get('mtime') ? 1 : -1;
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
repos.comparator = function(a, b) { // a, b: model
|
Cookies.set('sort_mode', 'time_down');
|
||||||
return a.get('mtime') < b.get('mtime') ? -1 : 1;
|
app.pageOptions.sort_mode = 'time_down';
|
||||||
};
|
|
||||||
}
|
}
|
||||||
repos.sort();
|
|
||||||
|
Common.updateSortIconByMode(this);
|
||||||
|
this.repos = Common.sortCollection(this.repos);
|
||||||
|
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
this.repos.comparator = null;
|
||||||
repos.comparator = null;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -87,12 +87,14 @@ define([
|
|||||||
this.$emptyTip.hide();
|
this.$emptyTip.hide();
|
||||||
this.renderReposHd();
|
this.renderReposHd();
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
|
this.repos = Common.sortCollection(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() {
|
||||||
@@ -123,46 +125,42 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
sortByName: function() {
|
sortByName: function() {
|
||||||
$('.by-time .sort-icon', this.$table).hide();
|
if (app.pageOptions.sort_mode == 'name_up') {
|
||||||
var repos = this.repos;
|
// change sort mode
|
||||||
var $el = $('.by-name .sort-icon', this.$table);
|
Cookies.set('sort_mode', 'name_down');
|
||||||
if ($el.hasClass('icon-caret-up')) {
|
app.pageOptions.sort_mode = 'name_down';
|
||||||
repos.comparator = function(a, b) { // a, b: model
|
|
||||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
|
||||||
return -result;
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
repos.comparator = function(a, b) { // a, b: model
|
Cookies.set('sort_mode', 'name_up');
|
||||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
app.pageOptions.sort_mode = 'name_up';
|
||||||
return result;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
repos.sort();
|
|
||||||
|
Common.updateSortIconByMode(this);
|
||||||
|
this.repos = Common.sortCollection(this.repos);
|
||||||
|
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
this.repos.comparator = null;
|
||||||
repos.comparator = null;
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
sortByTime: function() {
|
sortByTime: function() {
|
||||||
$('.by-name .sort-icon', this.$table).hide();
|
if (app.pageOptions.sort_mode == 'time_down') {
|
||||||
var repos = this.repos;
|
// change sort mode
|
||||||
var $el = $('.by-time .sort-icon', this.$table);
|
Cookies.set('sort_mode', 'time_up');
|
||||||
if ($el.hasClass('icon-caret-down')) {
|
app.pageOptions.sort_mode = 'time_up';
|
||||||
repos.comparator = function(a, b) { // a, b: model
|
|
||||||
return a.get('mtime') < b.get('mtime') ? 1 : -1;
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
repos.comparator = function(a, b) { // a, b: model
|
Cookies.set('sort_mode', 'time_down');
|
||||||
return a.get('mtime') < b.get('mtime') ? -1 : 1;
|
app.pageOptions.sort_mode = 'time_down';
|
||||||
};
|
|
||||||
}
|
}
|
||||||
repos.sort();
|
|
||||||
|
Common.updateSortIconByMode(this);
|
||||||
|
this.repos = Common.sortCollection(this.repos);
|
||||||
|
|
||||||
this.$tableBody.empty();
|
this.$tableBody.empty();
|
||||||
repos.each(this.addOne, this);
|
this.repos.each(this.addOne, this);
|
||||||
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
this.repos.comparator = null;
|
||||||
repos.comparator = null;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -778,6 +778,69 @@ define([
|
|||||||
return (a >= b) - (a <= b);
|
return (a >= b) - (a <= b);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
updateSortIconByMode: function(current_el) {
|
||||||
|
var sort_mode = app.pageOptions.sort_mode;
|
||||||
|
|
||||||
|
// first hide all icon
|
||||||
|
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 {
|
||||||
|
// if no sort mode, show name up icon
|
||||||
|
current_el.$('.by-name .sort-icon').removeClass('icon-caret-down').addClass('icon-caret-up').show();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
sortCollection: function(current_collection) {
|
||||||
|
var sort_mode = app.pageOptions.sort_mode;
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
|
// set collection comparator
|
||||||
|
current_collection.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 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;
|
||||||
|
}
|
||||||
|
} 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// sort collection
|
||||||
|
current_collection.sort();
|
||||||
|
return current_collection;
|
||||||
|
},
|
||||||
|
|
||||||
fileSizeFormat: function(bytes, precision) {
|
fileSizeFormat: function(bytes, precision) {
|
||||||
var kilobyte = 1024;
|
var kilobyte = 1024;
|
||||||
var megabyte = kilobyte * 1024;
|
var megabyte = kilobyte * 1024;
|
||||||
|
Reference in New Issue
Block a user