fix alphabetical order of annotations with tags, fixes #681
This commit is contained in:
parent
c4de1a3a40
commit
bc3fedb125
4 changed files with 30 additions and 17 deletions
|
@ -11,6 +11,7 @@ Ox.ArrayEditable = function(options, self) {
|
||||||
.defaults({
|
.defaults({
|
||||||
clickLink: null,
|
clickLink: null,
|
||||||
editable: true,
|
editable: true,
|
||||||
|
getSortValue: null,
|
||||||
highlight: '',
|
highlight: '',
|
||||||
itemName: 'item',
|
itemName: 'item',
|
||||||
items: [],
|
items: [],
|
||||||
|
@ -208,7 +209,6 @@ Ox.ArrayEditable = function(options, self) {
|
||||||
self.editing = false;
|
self.editing = false;
|
||||||
that.blurItem();
|
that.blurItem();
|
||||||
}
|
}
|
||||||
Ox.print('SELECT ITEM', self.options.selected, self.selected);
|
|
||||||
that.find('.OxSelected').removeClass('OxSelected');
|
that.find('.OxSelected').removeClass('OxSelected');
|
||||||
self.selected > -1 && self.$items[self.selected].addClass('OxSelected');
|
self.selected > -1 && self.$items[self.selected].addClass('OxSelected');
|
||||||
triggerSelectEvent();
|
triggerSelectEvent();
|
||||||
|
@ -279,7 +279,13 @@ Ox.ArrayEditable = function(options, self) {
|
||||||
|
|
||||||
function sortItems() {
|
function sortItems() {
|
||||||
if (!Ox.isEmpty(self.options.sort)) {
|
if (!Ox.isEmpty(self.options.sort)) {
|
||||||
self.options.items = Ox.sortBy(self.options.items, self.options.sort);
|
self.options.items = Ox.sortBy(
|
||||||
|
self.options.items,
|
||||||
|
self.options.sort,
|
||||||
|
self.options.getSortValue
|
||||||
|
? {value: self.options.getSortValue}
|
||||||
|
: {}
|
||||||
|
);
|
||||||
self.selected = getSelectedPosition();
|
self.selected = getSelectedPosition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -600,7 +600,6 @@ Ox.Menu = function(options, self) {
|
||||||
if (ids.length == 1) {
|
if (ids.length == 1) {
|
||||||
item = that.getItem(id);
|
item = that.getItem(id);
|
||||||
group = item.options('group');
|
group = item.options('group');
|
||||||
Ox.Log('Menu', 'checkItem', id, item, that.submenus)
|
|
||||||
if (group) {
|
if (group) {
|
||||||
offset = self.optionGroupOffset[group];
|
offset = self.optionGroupOffset[group];
|
||||||
position = getItemPositionById(id);
|
position = getItemPositionById(id);
|
||||||
|
|
|
@ -199,6 +199,11 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
self.$annotations = Ox.ArrayEditable({
|
self.$annotations = Ox.ArrayEditable({
|
||||||
clickLink: self.options.clickLink,
|
clickLink: self.options.clickLink,
|
||||||
editable: self.options.editable,
|
editable: self.options.editable,
|
||||||
|
getSortValue: self.options.type == 'text'
|
||||||
|
? function(value) {
|
||||||
|
return Ox.stripTags(value);
|
||||||
|
}
|
||||||
|
: null,
|
||||||
highlight: self.options.highlight,
|
highlight: self.options.highlight,
|
||||||
items: self.annotations,
|
items: self.annotations,
|
||||||
placeholder: 'No ' + self.options.title,
|
placeholder: 'No ' + self.options.title,
|
||||||
|
@ -540,7 +545,6 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
if (value === '') {
|
if (value === '') {
|
||||||
self.editing = false;
|
self.editing = false;
|
||||||
}
|
}
|
||||||
value && Ox.print('----------------- select item in folder', value, self.options.collapsed)
|
|
||||||
if (value && self.options.collapsed) {
|
if (value && self.options.collapsed) {
|
||||||
self.$panel.options({animate: false});
|
self.$panel.options({animate: false});
|
||||||
self.$panel.options({collapsed: false});
|
self.$panel.options({collapsed: false});
|
||||||
|
@ -620,7 +624,6 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
};
|
};
|
||||||
|
|
||||||
that.updateItem = function(id, data) {
|
that.updateItem = function(id, data) {
|
||||||
Ox.print('-- UPDATE ITEM', id, data);
|
|
||||||
var item = Ox.getObjectById(self.options.items, id);
|
var item = Ox.getObjectById(self.options.items, id);
|
||||||
Ox.forEach(data, function(value, key) {
|
Ox.forEach(data, function(value, key) {
|
||||||
item[key] = value;
|
item[key] = value;
|
||||||
|
|
|
@ -85,24 +85,27 @@ Ox.range = function() {
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
function getSortValues(arr) {
|
function getSortValues(arr, fn) {
|
||||||
var len, matches = {}, sort = {};
|
var arr_ = fn ? arr.map(fn) : arr,
|
||||||
|
len, matches = {}, sort = {};
|
||||||
// find leading numbers
|
// find leading numbers
|
||||||
arr.forEach(function(val) {
|
arr.forEach(function(val, i) {
|
||||||
var match = /^\d+/.exec(val);
|
var match = /^\d+/.exec(arr_[i]);
|
||||||
matches[val] = match ? match[0] : '';
|
matches[val] = match ? match[0] : '';
|
||||||
});
|
});
|
||||||
// get length of longest leading number
|
// get length of longest leading number
|
||||||
len = Ox.max(Ox.map(matches, function(val) {
|
len = Ox.max(Ox.map(matches, function(val) {
|
||||||
return val.length;
|
return val.length;
|
||||||
}));
|
}));
|
||||||
// pad leading numbers and make lowercase
|
// pad leading numbers, make lowercase,
|
||||||
arr.forEach(function(val) {
|
// and remove leading non-word characters
|
||||||
|
arr.forEach(function(val, i) {
|
||||||
sort[val] = (
|
sort[val] = (
|
||||||
matches[val]
|
matches[val]
|
||||||
? Ox.pad(matches[val], len)
|
? arr_[i].toString().replace(
|
||||||
+ val.toString().substr(matches[val].length)
|
matches[val], Ox.pad(matches[val], len)
|
||||||
: val
|
)
|
||||||
|
: arr_[i]
|
||||||
).toLowerCase().replace(/^\W+/, '');
|
).toLowerCase().replace(/^\W+/, '');
|
||||||
});
|
});
|
||||||
return sort;
|
return sort;
|
||||||
|
@ -138,13 +141,14 @@ Ox.range = function() {
|
||||||
Ox.sortBy <f> Sorts an array of objects by given properties
|
Ox.sortBy <f> Sorts an array of objects by given properties
|
||||||
(arr, by) -> <a> Sorted array
|
(arr, by) -> <a> Sorted array
|
||||||
arr <[o]> Array of objects
|
arr <[o]> Array of objects
|
||||||
by <[s]> Array of object properties (asc: 'foo' or '+foo', desc: '-foo')
|
by <[s]> Array of object keys (asc: 'foo' or '+foo', desc: '-foo')
|
||||||
|
fn <o> Optional functions, per key, that return the sort value
|
||||||
> Ox.sortBy([{x: 1, y: 1}, {x: 1, y: 2}, {x: 2, y: 2}], ['+x', '-y'])
|
> Ox.sortBy([{x: 1, y: 1}, {x: 1, y: 2}, {x: 2, y: 2}], ['+x', '-y'])
|
||||||
[{x: 1, y: 2}, {x: 1, y: 1}, {x: 2, y: 2}]
|
[{x: 1, y: 2}, {x: 1, y: 1}, {x: 2, y: 2}]
|
||||||
> Ox.sortBy([{id: 0, name: '80 Days'}, {id: 1, name: '8 Women'}], ['name'])
|
> Ox.sortBy([{id: 0, name: '80 Days'}, {id: 1, name: '8 Women'}], ['name'])
|
||||||
[{id: 1, name: '8 Women'}, {id: 0, name: '80 Days'}]
|
[{id: 1, name: '8 Women'}, {id: 0, name: '80 Days'}]
|
||||||
@*/
|
@*/
|
||||||
Ox.sortBy = function(arr, by) {
|
Ox.sortBy = function(arr, by, fn) {
|
||||||
var length = by.length, values = {};
|
var length = by.length, values = {};
|
||||||
by = by.map(function(v) {
|
by = by.map(function(v) {
|
||||||
return {
|
return {
|
||||||
|
@ -152,12 +156,13 @@ Ox.range = function() {
|
||||||
operator: v[0] == '-' ? '-' : '+'
|
operator: v[0] == '-' ? '-' : '+'
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
fn = fn || {};
|
||||||
by.map(function(v) {
|
by.map(function(v) {
|
||||||
return v.key;
|
return v.key;
|
||||||
}).forEach(function(key) {
|
}).forEach(function(key) {
|
||||||
values[key] = getSortValues(arr.map(function(v) {
|
values[key] = getSortValues(arr.map(function(v) {
|
||||||
return v[key];
|
return v[key];
|
||||||
}));
|
}), fn[key]);
|
||||||
});
|
});
|
||||||
return arr.sort(function(a, b) {
|
return arr.sort(function(a, b) {
|
||||||
var aValue, bValue, index = 0, key, ret = 0;
|
var aValue, bValue, index = 0, key, ret = 0;
|
||||||
|
|
Loading…
Reference in a new issue