diff --git a/app/controllers/dmails_controller.rb b/app/controllers/dmails_controller.rb index 8c01895e3..3a27011af 100644 --- a/app/controllers/dmails_controller.rb +++ b/app/controllers/dmails_controller.rb @@ -27,9 +27,6 @@ class DmailsController < ApplicationController end end - def search - end - def show @dmail = Dmail.find(params[:id]) check_privilege(@dmail) diff --git a/app/models/dmail.rb b/app/models/dmail.rb index 977a63e18..688e50c69 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -102,6 +102,11 @@ class Dmail < ActiveRecord::Base where("is_deleted = ?", true) end + def title_matches(query) + query = "*#{query}*" unless query =~ /\*/ + where("lower(dmails.title) LIKE ?", query.to_escaped_for_sql_like) + end + def search_message(query) if query =~ /\*/ && CurrentUser.user.is_builder? escaped_query = query.to_escaped_for_sql_like @@ -131,6 +136,10 @@ class Dmail < ActiveRecord::Base q = where("true") return q if params.blank? + if params[:title_matches].present? + q = q.title_matches(params[:title_matches]) + end + if params[:message_matches].present? q = q.search_message(params[:message_matches]) end diff --git a/app/views/dmails/_search.html.erb b/app/views/dmails/_search.html.erb new file mode 100644 index 000000000..969745d0a --- /dev/null +++ b/app/views/dmails/_search.html.erb @@ -0,0 +1,8 @@ +<%= simple_form_for(:search, url: dmails_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %> + <%= f.hidden_field :folder, value: params[:folder] %> + <%= f.input :title_matches, label: "Title", hint: "Use * for wildcard", input_html: { value: params[:search][:title_matches] } %> + <%= f.input :message_matches, label: "Message", hint: "Use * for wildcard", input_html: { value: params[:search][:messages_matches] } %> + <%= f.input :to_name, label: "To", input_html: { value: params[:search][:to_name] } %> + <%= f.input :from_name, label: "From", input_html: { value: params[:search][:from_name] } %> + <%= f.submit "Search" %> +<% end %> diff --git a/app/views/dmails/_secondary_links.html.erb b/app/views/dmails/_secondary_links.html.erb index 06a9d39dd..59c205b62 100644 --- a/app/views/dmails/_secondary_links.html.erb +++ b/app/views/dmails/_secondary_links.html.erb @@ -6,7 +6,6 @@