1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-09 10:50:24 +00:00

enable sort repo/dirent by Chinese word

This commit is contained in:
lian
2015-04-30 11:59:09 +08:00
parent 801abe9026
commit ca8a449d5a
7 changed files with 56 additions and 11 deletions

View File

@@ -432,16 +432,22 @@ define([
sortByName: function() { sortByName: function() {
var dirents = this.dir; var dirents = this.dir;
var el = $('#by-name'); var el = $('#by-name');
dirents.comparator = function(a, b) { dirents.comparator = function(a, b) {
if (a.get('is_dir') && b.get('is_file')) { if (a.get('is_dir') && b.get('is_file')) {
return -1; return -1;
} else if (a.get('is_file') && b.get('is_dir')) {
return 1;
} }
var result = Common.compareTwoWord(a.get('obj_name'), b.get('obj_name'));
if (el.hasClass('icon-caret-up')) { if (el.hasClass('icon-caret-up')) {
return a.get('obj_name').toLowerCase() < b.get('obj_name').toLowerCase() ? 1 : -1; return -result;
} else { } else {
return a.get('obj_name').toLowerCase() < b.get('obj_name').toLowerCase() ? -1 : 1; return result;
} }
}; };
dirents.sort(); dirents.sort();
this.$dirent_list.empty(); this.$dirent_list.empty();
dirents.each(this.addOne, this); dirents.each(this.addOne, this);

View File

@@ -104,10 +104,11 @@ define([
var repos = this.repos; var repos = this.repos;
var el = $('.by-name', this.$table); var el = $('.by-name', this.$table);
repos.comparator = function(a, b) { // a, b: model repos.comparator = function(a, b) { // a, b: model
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
if (el.hasClass('icon-caret-up')) { if (el.hasClass('icon-caret-up')) {
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? 1 : -1; return -result;
} else { } else {
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? -1 : 1; return result;
} }
}; };
repos.sort(); repos.sort();

View File

@@ -88,10 +88,11 @@ define([
var repos = this.repos; var repos = this.repos;
var el = $('.by-name', this.$table); var el = $('.by-name', this.$table);
repos.comparator = function(a, b) { // a, b: model repos.comparator = function(a, b) { // a, b: model
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
if (el.hasClass('icon-caret-up')) { if (el.hasClass('icon-caret-up')) {
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? 1 : -1; return -result;
} else { } else {
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? -1 : 1; return result;
} }
}; };
repos.sort(); repos.sort();

View File

@@ -79,10 +79,11 @@ define([
var repos = this.repos; var repos = this.repos;
var el = $('.by-name', this.$table); var el = $('.by-name', this.$table);
repos.comparator = function(a, b) { // a, b: model repos.comparator = function(a, b) { // a, b: model
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
if (el.hasClass('icon-caret-up')) { if (el.hasClass('icon-caret-up')) {
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? 1 : -1; return -result;
} else { } else {
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? -1 : 1; return result;
} }
}; };
repos.sort(); repos.sort();

View File

@@ -84,10 +84,11 @@ define([
var repos = this.repos; var repos = this.repos;
var el = $('.by-name', this.$table); var el = $('.by-name', this.$table);
repos.comparator = function(a, b) { // a, b: model repos.comparator = function(a, b) { // a, b: model
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
if (el.hasClass('icon-caret-up')) { if (el.hasClass('icon-caret-up')) {
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? 1 : -1; return -result;
} else { } else {
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? -1 : 1; return result;
} }
}; };
repos.sort(); repos.sort();

View File

@@ -50,12 +50,15 @@ define([
'jquery', 'jquery',
'underscore', 'underscore',
'text', // Workaround for r.js, otherwise text.js will not be included 'text', // Workaround for r.js, otherwise text.js will not be included
], function($, _, text) { 'pinyin-by-unicode'
], function($, _, text, PinyinByUnicode) {
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
ERROR_TIMEOUT: 3000, // 3 secs for error msg ERROR_TIMEOUT: 3000, // 3 secs for error msg
strChineseFirstPY: PinyinByUnicode.strChineseFirstPY,
getUrl: function(options) { getUrl: function(options) {
var siteRoot = app.config.siteRoot; var siteRoot = app.config.siteRoot;
switch (options.name) { switch (options.name) {
@@ -501,6 +504,35 @@ define([
} }
}, },
compareTwoWord: function(a_name, b_name) {
// compare a_name and b_name at lower case
// if a_name >= b_name, return 1
// if a_name < b_name, return -1
var a_val, b_val,
a_uni = a_name.charCodeAt(0),
b_uni = b_name.charCodeAt(0),
strChineseFirstPY = this.strChineseFirstPY;
if ((19968 < a_uni && a_uni < 40869) && (19968 < b_uni && b_uni < 40869)) {
// both are chinese words
a_val = strChineseFirstPY.charAt(a_uni - 19968).toLowerCase();
b_val = strChineseFirstPY.charAt(b_uni - 19968).toLowerCase();
} else if ((19968 < a_uni && a_uni < 40869) && !(19968 < b_uni && b_uni < 40869)) {
// a is chinese and b is english
return 1;
} else if (!(19968 < a_uni && a_uni < 40869) && (19968 < b_uni && b_uni < 40869)) {
// a is english and b is chinese
return -1;
} else {
// both are english words
a_val = a_name.toLowerCase();
b_val = b_name.toLowerCase();
}
return a_val >= b_val ? 1 : -1;
},
fileSizeFormat: function(bytes, precision) { fileSizeFormat: function(bytes, precision) {
var kilobyte = 1024; var kilobyte = 1024;
var megabyte = kilobyte * 1024; var megabyte = kilobyte * 1024;

File diff suppressed because one or more lines are too long