Refactored tag suggestions
This commit is contained in:
parent
c350c47195
commit
303f91e15c
1 changed files with 43 additions and 45 deletions
|
@ -279,15 +279,8 @@ App.Controls.TagInput = function($underlyingInput) {
|
|||
|
||||
function showOrHideSuggestions(tagName) {
|
||||
var tag = getExportedTag(tagName);
|
||||
if (tag && _.size(tag.suggestions) > 0) {
|
||||
var suggestions = filterSuggestions(tag.suggestions);
|
||||
if (suggestions.length > 0) {
|
||||
attachTagsToSuggestionList($suggestions.find('ul'), suggestions);
|
||||
$suggestions.slideDown('fast');
|
||||
return;
|
||||
}
|
||||
}
|
||||
$suggestions.slideUp('fast');
|
||||
var suggestions = tag ? tag.suggestions : [];
|
||||
updateSuggestions($suggestions, suggestions);
|
||||
}
|
||||
|
||||
function showOrHideSiblings(tagName) {
|
||||
|
@ -300,22 +293,18 @@ App.Controls.TagInput = function($underlyingInput) {
|
|||
promise.wait(getSiblings(tagName), promise.make(function(resolve, reject) {
|
||||
$siblings.slideUp('fast', resolve);
|
||||
})).then(function(siblings) {
|
||||
siblings = _.pluck(siblings, 'name');
|
||||
$siblings.data('lastTag', tagName);
|
||||
|
||||
if (!_.size(siblings)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var suggestions = filterSuggestions(_.pluck(siblings, 'name'));
|
||||
if (suggestions.length > 0) {
|
||||
attachTagsToSuggestionList($siblings.find('ul'), suggestions);
|
||||
$siblings.slideDown('fast');
|
||||
}
|
||||
updateSuggestions($siblings, siblings);
|
||||
}).fail(function() {
|
||||
});
|
||||
}
|
||||
|
||||
function updateSuggestions($target, siblings) {
|
||||
function filterSuggestions(sourceTagNames) {
|
||||
if (!sourceTagNames) {
|
||||
return [];
|
||||
}
|
||||
var tagNames = _.filter(sourceTagNames.slice(), function(tagName) {
|
||||
return !isTaggedWith(tagName);
|
||||
});
|
||||
|
@ -344,6 +333,15 @@ App.Controls.TagInput = function($underlyingInput) {
|
|||
});
|
||||
}
|
||||
|
||||
var suggestions = filterSuggestions(siblings);
|
||||
if (suggestions.length > 0) {
|
||||
attachTagsToSuggestionList($target.find('ul'), suggestions);
|
||||
$target.slideDown('fast');
|
||||
} else {
|
||||
$target.slideUp('fast');
|
||||
}
|
||||
}
|
||||
|
||||
function getSiblings(tagName) {
|
||||
return promise.make(function(resolve, reject) {
|
||||
promise.wait(api.get('/tags/' + tagName + '/siblings'))
|
||||
|
|
Loading…
Reference in a new issue