Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/core/Prefab.js
Show First 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | statics : { | ||||
}, | }, | ||||
sortHandler: function(config, value, list, cmp) { | sortHandler: function(config, value, list, cmp) { | ||||
// Sort results so that the viewing user always comes up first; after | // Sort results so that the viewing user always comes up first; after | ||||
// that, prefer unixname matches to realname matches. | // that, prefer unixname matches to realname matches. | ||||
var priority_hits = {}; | var priority_hits = {}; | ||||
var self_hits = {}; | var self_hits = {}; | ||||
// We'll put matches where the user's input is a prefix of the name | |||||
// above mathches where that isn't true. | |||||
var prefix_hits = {}; | |||||
var tokens = this.tokenize(value); | var tokens = this.tokenize(value); | ||||
var normal = this.normalize(value); | |||||
for (var ii = 0; ii < list.length; ii++) { | for (var ii = 0; ii < list.length; ii++) { | ||||
var item = list[ii]; | var item = list[ii]; | ||||
if (this.normalize(item.name).indexOf(normal) === 0) { | |||||
prefix_hits[item.id] = true; | |||||
} | |||||
for (var jj = 0; jj < tokens.length; jj++) { | for (var jj = 0; jj < tokens.length; jj++) { | ||||
if (item.name.indexOf(tokens[jj]) === 0) { | if (item.name.indexOf(tokens[jj]) === 0) { | ||||
priority_hits[item.id] = true; | priority_hits[item.id] = true; | ||||
} | } | ||||
} | } | ||||
if (!item.priority) { | if (!item.priority) { | ||||
continue; | continue; | ||||
Show All 32 Lines | sortHandler: function(config, value, list, cmp) { | ||||
return 1; | return 1; | ||||
} | } | ||||
} | } | ||||
if (priority_hits[u.id] != priority_hits[v.id]) { | if (priority_hits[u.id] != priority_hits[v.id]) { | ||||
return priority_hits[v.id] ? 1 : -1; | return priority_hits[v.id] ? 1 : -1; | ||||
} | } | ||||
if (prefix_hits[u.id] != prefix_hits[v.id]) { | |||||
return prefix_hits[v.id] ? 1 : -1; | |||||
} | |||||
// Sort users ahead of other result types. | // Sort users ahead of other result types. | ||||
if (u.priorityType != v.priorityType) { | if (u.priorityType != v.priorityType) { | ||||
if (u.priorityType == 'user') { | if (u.priorityType == 'user') { | ||||
return -1; | return -1; | ||||
} | } | ||||
if (v.priorityType == 'user') { | if (v.priorityType == 'user') { | ||||
return 1; | return 1; | ||||
} | } | ||||
} | } | ||||
// Sort functions after other result types. | |||||
var uf = (u.tokenType == 'function'); | |||||
var vf = (v.tokenType == 'function'); | |||||
if (uf != vf) { | |||||
return uf ? 1 : -1; | |||||
} | |||||
return cmp(u, v); | return cmp(u, v); | ||||
}); | }); | ||||
}, | }, | ||||
/** | /** | ||||
* Filter callback for tokenizers and typeaheads which filters out closed | * Filter callback for tokenizers and typeaheads which filters out closed | ||||
* or disabled objects unless they are the only options. | * or disabled objects unless they are the only options. | ||||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |