Commit 8bca6f4632c585df6b202077b21e2324045e20ca

Authored by Gabriela Navarro
Committed by Fabio Teixeira
1 parent 946bc87a
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Highlight fields with errors.

Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Signed-off-by: Thiago Ribeiro <thiagitosouza@hotmail.com>
controllers/gov_user_plugin_controller.rb
... ... @@ -23,7 +23,6 @@ class GovUserPluginController &lt; ApplicationController
23 23 @governmental_sphere_options = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}
24 24 @governmental_power_options = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}
25 25 @juridical_nature_options = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}
26   -
27 26 if request.xhr?
28 27 render :layout=>false
29 28 else
... ... @@ -67,7 +66,6 @@ class GovUserPluginController &lt; ApplicationController
67 66 response_message = save_institution @institutions
68 67  
69 68 if request.xhr? #User create institution
70   - puts "-"*80, response_message
71 69 render :json => response_message.to_json
72 70 else #Admin create institution
73 71 session[:notice] = response_message[:message] # consume the notice
... ... @@ -187,7 +185,6 @@ class GovUserPluginController &lt; ApplicationController
187 185  
188 186 institution.date_modification = DateTime.now
189 187 institution.save
190   -
191 188 institution
192 189 end
193 190  
... ... @@ -208,9 +205,12 @@ class GovUserPluginController &lt; ApplicationController
208 205 end
209 206  
210 207 def save_institution institution
  208 +
211 209 inst_errors = institution.errors.full_messages
212 210 com_errors = institution.community.errors.full_messages
213 211  
  212 + set_error_css institution
  213 +
214 214 if inst_errors.empty? && com_errors.empty? && institution.valid? && institution.save
215 215 { :success => true,
216 216 :message => _("Institution successful created!"),
... ... @@ -233,4 +233,19 @@ class GovUserPluginController &lt; ApplicationController
233 233 end
234 234 end
235 235  
  236 + def set_error_css institution
  237 + institution.valid?
  238 + institution.community.valid?
  239 + params[:error_community_name] = institution.community.errors.include?(:name) ? "highlight-error" : ""
  240 + params[:error_community_country] = institution.community.errors.include?(:country) ? "highlight-error" : ""
  241 + params[:error_community_city] = institution.errors.include?(:city) ? "highlight-error" : ""
  242 + params[:error_community_state] = institution.errors.include?(:state) ? "highlight-error" : ""
  243 + params[:error_institution_corporate_name] = institution.errors.include?(:corporate_name) ? "highlight-error" : ""
  244 + params[:error_institution_acronym] = institution.errors.include?(:acronym) ? "highlight-error" : ""
  245 + params[:error_institution_cnpj] = institution.errors.include?(:cnpj) ? "highlight-error" : ""
  246 + params[:error_institution_governmental_sphere] = institution.errors.include?(:governmental_sphere) ? "highlight-error" : ""
  247 + params[:error_institution_governmental_power] = institution.errors.include?(:governmental_power) ? "highlight-error" : ""
  248 + params[:error_institution_juridical_nature] = institution.errors.include?(:juridical_nature) ? "highlight-error" : ""
  249 + params[:error_institution_sisp] = institution.errors.include?(:sisp) ? "highlight-error" : ""
  250 + end
236 251 end
... ...
lib/gov_user_plugin.rb
... ... @@ -19,6 +19,10 @@ class GovUserPlugin &lt; Noosfero::Plugin
19 19 _("A plugin that does this and that.")
20 20 end
21 21  
  22 + def stylesheet?
  23 + true
  24 + end
  25 +
22 26 # Hotspot to insert html without an especific hotspot on view.
23 27 def body_beginning
24 28 return if context.session[:user].nil? or context.session[:hide_incomplete_percentage] == true
... ...
public/style.css
... ... @@ -18,3 +18,9 @@
18 18 background: #fff;
19 19 border: solid 1px #000;
20 20 }
  21 +
  22 +.highlight-error {
  23 + outline: none;
  24 + border-color: #FF0000;
  25 + box-shadow: 0 0 10px #FF0000;
  26 +}
... ...
views/gov_user_plugin/_institution.html.erb
... ... @@ -39,15 +39,14 @@
39 39 </label>
40 40 </div>
41 41 </span>
42   -
43   - <%= required f.text_field(:name, :value => params[:community][:name], :size => 55) %>
  42 + <%= required f.text_field(:name, :value => params[:community][:name], :size => 55, :class => "#{params[:error_community_name]}" ) %>
44 43 <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %>
45 44  
46 45 <div class= <%= @error_corporate_name %> >
47 46 <span class='required-field'>
48 47 <div class="formfield type-text">
49 48 <%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %>
50   - <%= required inst.text_field(:corporate_name, :value => params[:institutions][:corporate_name], :size => 55) %>
  49 + <%= required inst.text_field(:corporate_name, :value => params[:institutions][:corporate_name], :size => 55, :class => "#{params[:error_institution_corporate_name]}") %>
51 50 </div>
52 51 </span>
53 52 </div>
... ... @@ -57,46 +56,46 @@
57 56 <%= hidden_field_tag "acronym_translate", _("Acronym") %>
58 57 <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %>
59 58 <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %>
60   - <%= inst.text_field(:acronym, :value => params[:institutions][:acronym]) %>
  59 + <%= inst.text_field(:acronym, :value => params[:institutions][:acronym], :class => "#{params[:error_institution_acronym]}") %>
61 60 </div>
62 61 </span>
63 62  
64   - <%= required select_country(_('Country'), 'community', 'country', {:class => 'type-select', :id => "community_country"}) %>
  63 + <%= required select_country(_('Country'), 'community', 'country', {:class => "type-select #{params[:error_community_country]}", :id => "community_country"}) %>
65 64  
66 65 <span class='required-field'>
67 66 <div class="formfield">
68 67 <label for="community_state" class="formlabel"><%= _("State") %></label>
69   - <%= f.select(:state, @state_options, :selected => params[:community][:state]) %>
  68 + <%= f.select(:state, @state_options, :selected => params[:community][:state], :class => "#{params[:error_community_state]}") %>
70 69 </div>
71 70 </span>
72 71  
73   - <%= required f.text_field(:city, :value => params[:community][:city], :id => "city_field") %>
  72 + <%= required f.text_field(:city, :value => params[:community][:city], :id => "city_field", :class => "#{params[:error_community_city]}") %>
74 73  
75 74  
76 75 <span class='required-field'>
77 76 <div class="formfield type-text">
78 77 <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %>
79   - <%= required inst.text_field(:cnpj, :value => params[:institutions][:cnpj], :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field") %>
  78 + <%= required inst.text_field(:cnpj, :value => params[:institutions][:cnpj], :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field #{params[:error_institution_cnpj]}") %>
80 79 </div>
81 80 </span>
82 81  
83 82 <span class='required-field public-institutions-fields'>
84 83 <div class="formfield type-text">
85 84 <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %>
86   - <%= inst.select(:governmental_sphere, @governmental_sphere_options, :selected => params[:institutions][:governmental_sphere])%>
  85 + <%= inst.select(:governmental_sphere, @governmental_sphere_options, :selected => params[:institutions][:governmental_sphere], :class => "#{params[:error_institution_governmental_sphere]}" )%>
87 86 </div>
88 87 </span>
89 88  
90 89 <span class='required-field public-institutions-fields'>
91 90 <div class="formfield type-text">
92 91 <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %>
93   - <%= inst.select(:governmental_power, @governmental_power_options, :selected => params[:institutions][:governmental_power])%>
  92 + <%= inst.select(:governmental_power, @governmental_power_options, :selected => params[:institutions][:governmental_power], :class => "#{params[:error_institution_governmental_power]}")%>
94 93 </div>
95 94 </span>
96 95 <span class='required-field public-institutions-fields'>
97 96 <div class="formfield type-text">
98 97 <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %>
99   - <%= inst.select(:juridical_nature, @juridical_nature_options, :selected => params[:institutions][:juridical_nature])%>
  98 + <%= inst.select(:juridical_nature, @juridical_nature_options, :selected => params[:institutions][:juridical_nature], :class => "#{params[:error_institution_juridical_nature]}")%>
100 99 </div>
101 100 </span>
102 101  
... ... @@ -104,9 +103,9 @@
104 103 <div class="formfield type-text">
105 104 <%= _("SISP?") %>
106 105 <% if @show_sisp_field %>
107   - <%= inst.radio_button(:sisp, true) %>
  106 + <%= inst.radio_button(:sisp, true, :class => "#{params[:error_institution_sisp]}" ) %>
108 107 <%= inst.label :sisp ,_("Yes"), :value => true %>
109   - <%= inst.radio_button(:sisp, false, :checked=>"checked") %>
  108 + <%= inst.radio_button(:sisp, false, :checked=>"checked", :class => "#{params[:error_institution_sisp]}") %>
110 109 <%= inst.label :sisp ,_("No"), :value => false %>
111 110 <% else %>
112 111 <%= inst.label("sisp", _("No")) %>
... ...