autocomplete: add saved search label autocomplete in more places.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import CurrentUser from './current_user'
|
||||
import SavedSearch from './saved_searches'
|
||||
|
||||
let Autocomplete = {};
|
||||
|
||||
@@ -35,6 +34,7 @@ Autocomplete.initialize_all = function() {
|
||||
this.initialize_pool_autocomplete($('[data-autocomplete="pool"]'));
|
||||
this.initialize_user_autocomplete($('[data-autocomplete="user"]'));
|
||||
this.initialize_wiki_autocomplete($('[data-autocomplete="wiki-page"]'));
|
||||
this.initialize_saved_search_autocomplete($('[data-autocomplete="saved-search-label"]'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ Autocomplete.initialize_tag_autocomplete = function() {
|
||||
Autocomplete.favorite_group_source(term, resp, metatag);
|
||||
break;
|
||||
case "search":
|
||||
Autocomplete.saved_search_source(term, resp);
|
||||
Autocomplete.saved_search_source(term, resp, "search:");
|
||||
break;
|
||||
case "tag":
|
||||
Autocomplete.normal_source(term, resp);
|
||||
@@ -238,6 +238,17 @@ Autocomplete.initialize_wiki_autocomplete = function($fields) {
|
||||
});
|
||||
};
|
||||
|
||||
Autocomplete.initialize_saved_search_autocomplete = function($fields) {
|
||||
$fields.autocomplete({
|
||||
search: function() {
|
||||
$(this).data("ui-autocomplete").menu.bindings = $();
|
||||
},
|
||||
source: function(req, resp) {
|
||||
Autocomplete.saved_search_source(req.term, resp);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Autocomplete.normal_source = function(term, resp) {
|
||||
if (term === "") {
|
||||
resp([]);
|
||||
@@ -474,15 +485,15 @@ Autocomplete.favorite_group_source = function(term, resp, metatag) {
|
||||
});
|
||||
}
|
||||
|
||||
Autocomplete.saved_search_source = function(term, resp) {
|
||||
return SavedSearch.labels(term).then(function(labels) {
|
||||
resp(labels.map(function(label) {
|
||||
return {
|
||||
label: label.replace(/_/g, " "),
|
||||
value: "search:" + label,
|
||||
};
|
||||
}));
|
||||
});
|
||||
Autocomplete.saved_search_source = async function(term, resp, prefix = "") {
|
||||
let labels = await $.getJSON("/saved_searches/labels", { "search[label]": term + "*", "limit": 10 });
|
||||
|
||||
resp(labels.map(function(label) {
|
||||
return {
|
||||
label: label.replace(/_/g, " "),
|
||||
value: prefix + label,
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
@@ -3,7 +3,6 @@ import Utility from './utility'
|
||||
import Hammer from 'hammerjs'
|
||||
import Cookie from './cookie'
|
||||
import Note from './notes'
|
||||
import SavedSearch from './saved_searches'
|
||||
|
||||
let Post = {};
|
||||
|
||||
@@ -549,22 +548,6 @@ Post.approve = function(post_id) {
|
||||
}
|
||||
|
||||
Post.initialize_saved_searches = function() {
|
||||
$("#new_saved_search #saved_search_label_string").autocomplete({
|
||||
search: function() {
|
||||
$(this).data("ui-autocomplete").menu.bindings = $();
|
||||
},
|
||||
source: function(req, resp) {
|
||||
SavedSearch.labels(req.term).then(function(labels) {
|
||||
resp(labels.map(function(label) {
|
||||
return {
|
||||
label: label.replace(/_/g, " "),
|
||||
value: label
|
||||
};
|
||||
}));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$("#save-search-dialog").dialog({
|
||||
width: 700,
|
||||
modal: true,
|
||||
|
||||
@@ -6,13 +6,6 @@ SavedSearch.initialize_all = function() {
|
||||
}
|
||||
}
|
||||
|
||||
SavedSearch.labels = function(term) {
|
||||
return $.getJSON("/saved_searches/labels", {
|
||||
"search[label]": term + "*",
|
||||
"limit": 10
|
||||
});
|
||||
}
|
||||
|
||||
$(SavedSearch.initialize_all);
|
||||
|
||||
export default SavedSearch
|
||||
|
||||
Reference in New Issue
Block a user