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
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<%= simple_form_for(SavedSearch.new, remote: true) do |f| %>
|
||||
<%= f.input :query, as: :string, input_html: { value: params[:tags], data: { autocomplete: "tag-query" } } %>
|
||||
<%= f.input :label_string, label: "Labels", hint: "A list of tags to help categorize this search. Space delimited." %>
|
||||
<%= f.input :label_string, label: "Labels", hint: "A list of tags to help categorize this search. Space delimited.", input_html: { "data-autocomplete": "saved-search-label" } %>
|
||||
<%= f.input :disable_labels, label: "Don't show this dialog again", as: :boolean %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<%= simple_form_for(@saved_search) do |f| %>
|
||||
<%= f.input :query, :as => :string %>
|
||||
<%= f.input :label_string, :label => "Labels", :hint => "A list of tags to help categorize this search. Space delimited." %>
|
||||
<%= f.input :label_string, label: "Labels", hint: "A list of tags to help categorize this search. Space delimited.", input_html: { "data-autocomplete": "saved-search-label" } %>
|
||||
<%= f.button :submit, :value => "Submit" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
<%= search_form_for(saved_searches_path) do |f| %>
|
||||
<%= f.input :query_ilike, label: "Query", hint: "Use * for wildcard", input_html: { value: params[:search][:query_ilike] } %>
|
||||
<%= f.input :label, label: "Label", input_html: { value: params[:search][:label] } %>
|
||||
<%= f.input :label, label: "Label", input_html: { value: params[:search][:label] }, input_html: { "data-autocomplete": "saved-search-label" } %>
|
||||
<%= f.input :order, collection: [%w[Newest id], %w[Query query], %w[Label label]], include_blank: false, selected: params[:search][:order] %>
|
||||
<%= f.submit "Search" %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user