Commit 8bca6f4632c585df6b202077b21e2324045e20ca
Committed by
Fabio Teixeira
1 parent
946bc87a
Exists in
master
and in
3 other branches
Highlight fields with errors.
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: Thiago Ribeiro <thiagitosouza@hotmail.com>
Showing
4 changed files
with
40 additions
and
16 deletions
Show diff stats
controllers/gov_user_plugin_controller.rb
... | ... | @@ -23,7 +23,6 @@ class GovUserPluginController < 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 < 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 < 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 < 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 < 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 < 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
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")) %> | ... | ... |