Commit 8bca6f4632c585df6b202077b21e2324045e20ca

Authored by Gabriela Navarro
Committed by Fabio Teixeira
1 parent 946bc87a

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,7 +23,6 @@ class GovUserPluginController &lt; ApplicationController
23 @governmental_sphere_options = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]} 23 @governmental_sphere_options = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}
24 @governmental_power_options = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]} 24 @governmental_power_options = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}
25 @juridical_nature_options = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]} 25 @juridical_nature_options = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}
26 -  
27 if request.xhr? 26 if request.xhr?
28 render :layout=>false 27 render :layout=>false
29 else 28 else
@@ -67,7 +66,6 @@ class GovUserPluginController &lt; ApplicationController @@ -67,7 +66,6 @@ class GovUserPluginController &lt; ApplicationController
67 response_message = save_institution @institutions 66 response_message = save_institution @institutions
68 67
69 if request.xhr? #User create institution 68 if request.xhr? #User create institution
70 - puts "-"*80, response_message  
71 render :json => response_message.to_json 69 render :json => response_message.to_json
72 else #Admin create institution 70 else #Admin create institution
73 session[:notice] = response_message[:message] # consume the notice 71 session[:notice] = response_message[:message] # consume the notice
@@ -187,7 +185,6 @@ class GovUserPluginController &lt; ApplicationController @@ -187,7 +185,6 @@ class GovUserPluginController &lt; ApplicationController
187 185
188 institution.date_modification = DateTime.now 186 institution.date_modification = DateTime.now
189 institution.save 187 institution.save
190 -  
191 institution 188 institution
192 end 189 end
193 190
@@ -208,9 +205,12 @@ class GovUserPluginController &lt; ApplicationController @@ -208,9 +205,12 @@ class GovUserPluginController &lt; ApplicationController
208 end 205 end
209 206
210 def save_institution institution 207 def save_institution institution
  208 +
211 inst_errors = institution.errors.full_messages 209 inst_errors = institution.errors.full_messages
212 com_errors = institution.community.errors.full_messages 210 com_errors = institution.community.errors.full_messages
213 211
  212 + set_error_css institution
  213 +
214 if inst_errors.empty? && com_errors.empty? && institution.valid? && institution.save 214 if inst_errors.empty? && com_errors.empty? && institution.valid? && institution.save
215 { :success => true, 215 { :success => true,
216 :message => _("Institution successful created!"), 216 :message => _("Institution successful created!"),
@@ -233,4 +233,19 @@ class GovUserPluginController &lt; ApplicationController @@ -233,4 +233,19 @@ class GovUserPluginController &lt; ApplicationController
233 end 233 end
234 end 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 end 251 end
lib/gov_user_plugin.rb
@@ -19,6 +19,10 @@ class GovUserPlugin &lt; Noosfero::Plugin @@ -19,6 +19,10 @@ class GovUserPlugin &lt; Noosfero::Plugin
19 _("A plugin that does this and that.") 19 _("A plugin that does this and that.")
20 end 20 end
21 21
  22 + def stylesheet?
  23 + true
  24 + end
  25 +
22 # Hotspot to insert html without an especific hotspot on view. 26 # Hotspot to insert html without an especific hotspot on view.
23 def body_beginning 27 def body_beginning
24 return if context.session[:user].nil? or context.session[:hide_incomplete_percentage] == true 28 return if context.session[:user].nil? or context.session[:hide_incomplete_percentage] == true
public/style.css
@@ -18,3 +18,9 @@ @@ -18,3 +18,9 @@
18 background: #fff; 18 background: #fff;
19 border: solid 1px #000; 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,15 +39,14 @@
39 </label> 39 </label>
40 </div> 40 </div>
41 </span> 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 <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %> 43 <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %>
45 44
46 <div class= <%= @error_corporate_name %> > 45 <div class= <%= @error_corporate_name %> >
47 <span class='required-field'> 46 <span class='required-field'>
48 <div class="formfield type-text"> 47 <div class="formfield type-text">
49 <%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %> 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 </div> 50 </div>
52 </span> 51 </span>
53 </div> 52 </div>
@@ -57,46 +56,46 @@ @@ -57,46 +56,46 @@
57 <%= hidden_field_tag "acronym_translate", _("Acronym") %> 56 <%= hidden_field_tag "acronym_translate", _("Acronym") %>
58 <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %> 57 <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %>
59 <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %> 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 </div> 60 </div>
62 </span> 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 <span class='required-field'> 65 <span class='required-field'>
67 <div class="formfield"> 66 <div class="formfield">
68 <label for="community_state" class="formlabel"><%= _("State") %></label> 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 </div> 69 </div>
71 </span> 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 <span class='required-field'> 75 <span class='required-field'>
77 <div class="formfield type-text"> 76 <div class="formfield type-text">
78 <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %> 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 </div> 79 </div>
81 </span> 80 </span>
82 81
83 <span class='required-field public-institutions-fields'> 82 <span class='required-field public-institutions-fields'>
84 <div class="formfield type-text"> 83 <div class="formfield type-text">
85 <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %> 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 </div> 86 </div>
88 </span> 87 </span>
89 88
90 <span class='required-field public-institutions-fields'> 89 <span class='required-field public-institutions-fields'>
91 <div class="formfield type-text"> 90 <div class="formfield type-text">
92 <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %> 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 </div> 93 </div>
95 </span> 94 </span>
96 <span class='required-field public-institutions-fields'> 95 <span class='required-field public-institutions-fields'>
97 <div class="formfield type-text"> 96 <div class="formfield type-text">
98 <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %> 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 </div> 99 </div>
101 </span> 100 </span>
102 101
@@ -104,9 +103,9 @@ @@ -104,9 +103,9 @@
104 <div class="formfield type-text"> 103 <div class="formfield type-text">
105 <%= _("SISP?") %> 104 <%= _("SISP?") %>
106 <% if @show_sisp_field %> 105 <% if @show_sisp_field %>
107 - <%= inst.radio_button(:sisp, true) %> 106 + <%= inst.radio_button(:sisp, true, :class => "#{params[:error_institution_sisp]}" ) %>
108 <%= inst.label :sisp ,_("Yes"), :value => true %> 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 <%= inst.label :sisp ,_("No"), :value => false %> 109 <%= inst.label :sisp ,_("No"), :value => false %>
111 <% else %> 110 <% else %>
112 <%= inst.label("sisp", _("No")) %> 111 <%= inst.label("sisp", _("No")) %>