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) {
|
function showOrHideSuggestions(tagName) {
|
||||||
var tag = getExportedTag(tagName);
|
var tag = getExportedTag(tagName);
|
||||||
if (tag && _.size(tag.suggestions) > 0) {
|
var suggestions = tag ? tag.suggestions : [];
|
||||||
var suggestions = filterSuggestions(tag.suggestions);
|
updateSuggestions($suggestions, suggestions);
|
||||||
if (suggestions.length > 0) {
|
|
||||||
attachTagsToSuggestionList($suggestions.find('ul'), suggestions);
|
|
||||||
$suggestions.slideDown('fast');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$suggestions.slideUp('fast');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showOrHideSiblings(tagName) {
|
function showOrHideSiblings(tagName) {
|
||||||
|
@ -300,22 +293,18 @@ App.Controls.TagInput = function($underlyingInput) {
|
||||||
promise.wait(getSiblings(tagName), promise.make(function(resolve, reject) {
|
promise.wait(getSiblings(tagName), promise.make(function(resolve, reject) {
|
||||||
$siblings.slideUp('fast', resolve);
|
$siblings.slideUp('fast', resolve);
|
||||||
})).then(function(siblings) {
|
})).then(function(siblings) {
|
||||||
|
siblings = _.pluck(siblings, 'name');
|
||||||
$siblings.data('lastTag', tagName);
|
$siblings.data('lastTag', tagName);
|
||||||
|
updateSuggestions($siblings, siblings);
|
||||||
if (!_.size(siblings)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var suggestions = filterSuggestions(_.pluck(siblings, 'name'));
|
|
||||||
if (suggestions.length > 0) {
|
|
||||||
attachTagsToSuggestionList($siblings.find('ul'), suggestions);
|
|
||||||
$siblings.slideDown('fast');
|
|
||||||
}
|
|
||||||
}).fail(function() {
|
}).fail(function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateSuggestions($target, siblings) {
|
||||||
function filterSuggestions(sourceTagNames) {
|
function filterSuggestions(sourceTagNames) {
|
||||||
|
if (!sourceTagNames) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
var tagNames = _.filter(sourceTagNames.slice(), function(tagName) {
|
var tagNames = _.filter(sourceTagNames.slice(), function(tagName) {
|
||||||
return !isTaggedWith(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) {
|
function getSiblings(tagName) {
|
||||||
return promise.make(function(resolve, reject) {
|
return promise.make(function(resolve, reject) {
|
||||||
promise.wait(api.get('/tags/' + tagName + '/siblings'))
|
promise.wait(api.get('/tags/' + tagName + '/siblings'))
|
||||||
|
|
Loading…
Reference in a new issue