views: refactor quick search forms.

This commit is contained in:
evazion
2019-09-10 21:07:28 -05:00
parent ffccc503f7
commit 896f144eb6
23 changed files with 24 additions and 42 deletions

View File

@@ -5,6 +5,8 @@ class CommentsController < ApplicationController
skip_before_action :api_check
def index
params[:group_by] ||= "comment" if params[:search]
if params[:group_by] == "comment" || request.format == Mime::Type.lookup("application/atom+xml")
index_by_comment
elsif request.format == Mime::Type.lookup("text/javascript")

View File

@@ -158,6 +158,14 @@ module ApplicationHelper
tag.input value: "Preview", type: "button", class: "dtext-preview-button", "data-input-id": input_id, "data-preview-id": preview_id
end
def quick_search_form_for(attribute, url, name, autocomplete: nil, &block)
tag.li do
search_form_for(url, classes: "quick-search-form one-line-form") do |f|
f.input attribute, label: false, placeholder: "Search #{name}", input_html: { id: nil, "data-autocomplete": autocomplete }
end
end
end
def search_form_for(url, classes: "inline-form", &block)
defaults = { required: false }
html_options = { autocomplete: "off", class: "search-form #{classes}" }

View File

@@ -78,6 +78,10 @@ form.inline-form {
}
}
form.quick-search-form {
margin: 0;
}
form.one-line-form {
> input, > div.input {
display: inline;

View File

@@ -1,3 +0,0 @@
<%= form_tag(artist_commentaries_path, :method => :get) do %>
<%= text_field "search", "text_matches", :id => "quick_search_text_matches", :placeholder => "Search commentary" %>
<% end %>

View File

@@ -1,6 +1,6 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= render "artist_commentaries/quick_search" %></li>
<%= quick_search_form_for(:text_matches, artist_commentaries_path, "commentaries") %>
<%= subnav_link_to "Search", search_artist_commentaries_path %>
<%= subnav_link_to "Listing", artist_commentaries_path %>
<%= subnav_link_to "Recent changes", artist_commentary_versions_path %>

View File

@@ -1,3 +0,0 @@
<%= form_tag(artists_path, :method => :get) do %>
<%= text_field "search", "any_name_or_url_matches", id: "quick_search_name", placeholder: "Search artists", "data-autocomplete": "artist" %>
<% end %>

View File

@@ -1,6 +1,6 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= render "artists/quick_search" %></li>
<%= quick_search_form_for(:any_name_or_url_matches, artists_path, "artists", autocomplete: "artist") %>
<%= subnav_link_to "Listing", artists_path %>
<%= subnav_link_to "Banned", banned_artists_path %>
<% if CurrentUser.is_member? %>

View File

@@ -1,4 +0,0 @@
<%= form_tag(comments_path, :method => :get) do %>
<%= hidden_field_tag "group_by", "comment" %>
<%= text_field "search", "body_matches", :id => "quick_search_body_matches", :placeholder => "Search comments" %>
<% end %>

View File

@@ -1,6 +1,6 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= render "comments/quick_search" %></li>
<%= quick_search_form_for(:body_matches, comments_path, "comments") %>
<%= subnav_link_to "Listing", comments_path(:group_by => "post") %>
<%= subnav_link_to "Search", search_comments_path %>
<%= subnav_link_to "Help", wiki_pages_path(:title => "help:comments") %>

View File

@@ -1,3 +0,0 @@
<%= form_tag(dmails_path, :method => :get) do %>
<%= text_field "search", "message_matches", :id => "quick_search_message_matches", :placeholder => "Search messages" %>
<% end %>

View File

@@ -1,6 +1,6 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= render "quick_search" %></li>
<%= quick_search_form_for(:message_matches, dmails_path, "dmails") %>
<%= subnav_link_to "All", all_dmails_path(set_default_folder: true) %>
<%= subnav_link_to "Received", received_dmails_path(set_default_folder: true) %>
<%= subnav_link_to "Sent", sent_dmails_path(set_default_folder: true) %>

View File

@@ -1,3 +0,0 @@
<%= form_tag(forum_posts_path, :method => :get) do %>
<%= text_field "search", "body_matches", :id => "quick_search_body_matches", :placeholder => "Search forum" %>
<% end %>

View File

@@ -1,6 +1,6 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= render "forum_posts/quick_search" %></li>
<%= quick_search_form_for(:body_matches, forum_posts_path, "forum posts") %>
<%= subnav_link_to "Listing", forum_topics_path %>
<% if CurrentUser.is_member? %>

View File

@@ -1,4 +0,0 @@
<%= form_tag(notes_path, :method => :get) do %>
<%= hidden_field_tag "group_by", "note" %>
<%= text_field "search", "body_matches", :id => "quick_search_body_matches", :placeholder => "Search notes" %>
<% end %>

View File

@@ -1,6 +1,6 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= render "notes/quick_search" %></li>
<%= quick_search_form_for(:body_matches, notes_path, "notes") %>
<%= subnav_link_to "Listing", notes_path %>
<%= subnav_link_to "Posts", posts_path(:tags => "order:note") %>
<%= subnav_link_to "Search", search_notes_path %>

View File

@@ -1,3 +0,0 @@
<%= form_tag(pools_path, :method => :get) do %>
<%= text_field "search", "name_matches", id: "quick_search_name_matches", placeholder: "Search pools", data: { autocomplete: "pool" } %>
<% end %>

View File

@@ -1,6 +1,6 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= render "pools/quick_search" %></li>
<%= quick_search_form_for(:name_matches, pools_path, "pools", autocomplete: "pool") %>
<%= subnav_link_to "Gallery", gallery_pools_path %>
<%= subnav_link_to "Listing", pools_path %>
<%= subnav_link_to "New", new_pool_path %>

View File

@@ -1,3 +0,0 @@
<%= form_tag(tags_path, :method => :get) do %>
<%= text_field "search", "name_matches", :id => "quick_search_name_matches", :placeholder => "Search tags", :data => { :autocomplete => "tag" } %>
<% end %>

View File

@@ -1,6 +1,6 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= render "tags/quick_search" %></li>
<%= quick_search_form_for(:name_matches, tags_path, "tags", autocomplete: "tag") %>
<%= subnav_link_to "Listing", tags_path %>
<%= subnav_link_to "MetaSearch", meta_searches_tags_path %>
<%= subnav_link_to "Related tags", related_tag_path %>

View File

@@ -1,3 +0,0 @@
<%= form_tag(users_path, :method => :get) do %>
<%= text_field "search", "name_matches", :id => "quick_search_name_matches", :placeholder => "Search users", :data => { autocomplete: "user" } %>
<% end %>

View File

@@ -1,6 +1,6 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= render "users/quick_search" %></li>
<%= quick_search_form_for(:name_matches, users_path, "users", autocomplete: "user") %>
<%= subnav_link_to "Listing", users_path %>
<%= subnav_link_to "Search", search_users_path %>

View File

@@ -1,3 +0,0 @@
<%= form_tag(wiki_pages_path, :method => :get) do %>
<%= text_field "search", "title", id: "quick_search_title", placeholder: "Search wiki pages", data: { autocomplete: "wiki-page" } %>
<% end %>

View File

@@ -1,6 +1,6 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= render "wiki_pages/quick_search" %></li>
<%= quick_search_form_for(:title, wiki_pages_path, "wiki pages", autocomplete: "wiki-page") %>
<%= subnav_link_to "Listing", wiki_pages_path %>