From 8f2bf86367ee365114d484c186008f67b05c04a5 Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Tue, 26 Aug 2014 16:34:32 -0300 Subject: [PATCH] software_search: Replacing plugin's custom searches for one more generic --- lib/mpog_software_plugin.rb | 36 +++++++++++++++++++++--------------- public/mpog-search.js | 14 +++++++++++++- views/search/search_community_filter.html.erb | 8 ++++---- views/search/search_forms/_community_fields.html.erb | 5 ++--- 4 files changed, 40 insertions(+), 23 deletions(-) diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index 9bc57bd..6d648be 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -329,28 +329,34 @@ class MpogSoftwarePlugin < Noosfero::Plugin if context.params[:action] == "people" expanded_template('search/search_user_filter.html.erb') else context.params[:action] == "communities" + @active_type = if context.params[:type] == "Software" + "software" + elsif context.params[:type] == "Institution" + "institution" + else + "community" + end + expanded_template('search/search_community_filter.html.erb') end end - def custom_people_search params - Person.search(params[:name], - params[:state], - params[:city], - params[:email] - ) - end + def custom_search params + #:params => {"type"=>"Software", "query"=>"", "name"=>"", "database_description"=>"1", "programming_language"=>"1", "operating_system"=>"1", "controlled_vocabulary"=>"Administration", "license_info"=>{"id"=>""}, "e_ping"=>"any", "e_mag"=>"any", "icp_brasil"=>"any", "e_arq"=>"any", "internacionalizable"=>"any", "commit"=>"Search", "controller"=>"search", "action"=>"communities"} - def custom_community_search params - if params[:type] == "Community" - Community.search(params[:name]) - elsif params[:type] == "Software" - - elsif params[:type] == "Institution" + if params[:action] == "people" + Person.search(params[:name], + params[:state], + params[:city], + params[:email] + ) + elsif params[:action] == "communities" and params[:type] == "Institution" - else + elsif params[:action] == "communities" and params[:type] == "Software" - end + else + [] # An empty list will trigger noosfero's default communities search + end end def controlled_vocabulary_transaction diff --git a/public/mpog-search.js b/public/mpog-search.js index d234763..28e6b60 100644 --- a/public/mpog-search.js +++ b/public/mpog-search.js @@ -18,8 +18,20 @@ jQuery(".community_fields").show(); } + function display_search_fields_on_page_load() { + var active_search = jQuery(".search_type input[checked='checked'").val(); + + switch(active_search) { + case "Community": show_community_fields(); break; + case "Software": show_software_fields(); break; + case "Institution": show_institutions_fields(); break; + + default: show_community_fields(); + } + } + function set_events() { - show_community_fields(); + display_search_fields_on_page_load(); jQuery("#type_Community").click(show_community_fields); diff --git a/views/search/search_community_filter.html.erb b/views/search/search_community_filter.html.erb index 1d15a85..f618fa3 100644 --- a/views/search/search_community_filter.html.erb +++ b/views/search/search_community_filter.html.erb @@ -2,15 +2,15 @@
- +
<%= label_tag("type_Community", _("Community")) %> - <%= radio_button_tag(:type, "Community", true) %> + <%= radio_button_tag(:type, "Community", (true if @active_type == "community")) %> <%= label_tag("type_Software", _("Software")) %> - <%= radio_button_tag(:type, "Software") %> + <%= radio_button_tag(:type, "Software", (true if @active_type == "software")) %> <%= label_tag("type_Institution", _("Institution")) %> - <%= radio_button_tag(:type, "Institution") %> + <%= radio_button_tag(:type, "Institution", (true if @active_type == "institution")) %>
diff --git a/views/search/search_forms/_community_fields.html.erb b/views/search/search_forms/_community_fields.html.erb index e32860d..0425e2e 100644 --- a/views/search/search_forms/_community_fields.html.erb +++ b/views/search/search_forms/_community_fields.html.erb @@ -1,8 +1,7 @@ -
- <%= label_tag("name", _("Name"))%> - <%= text_field_tag(:name) %> +
\ No newline at end of file + -- libgit2 0.21.2