Commit 0a70acfcda43346e78773deb9daae8ab9ce624fa

Authored by Gabriela Navarro
Committed by Fabio Teixeira
1 parent e357d9c7

Make the view come with previous information

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
controllers/gov_user_plugin_controller.rb
@@ -18,14 +18,11 @@ class GovUserPluginController &lt; ApplicationController @@ -18,14 +18,11 @@ class GovUserPluginController &lt; ApplicationController
18 @governmental_sphere = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]} 18 @governmental_sphere = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}
19 @governmental_power = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]} 19 @governmental_power = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}
20 @juridical_nature = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]} 20 @juridical_nature = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}
  21 + @state_options = [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]}
21 22
22 params[:community] ||= {} 23 params[:community] ||= {}
23 params[:institutions] ||= {} 24 params[:institutions] ||= {}
24 25
25 - @state_options = [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]}  
26 - @governmental_sphere_options = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}  
27 - @governmental_power_options = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}  
28 - @juridical_nature_options = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}  
29 if request.xhr? 26 if request.xhr?
30 render :layout=>false 27 render :layout=>false
31 else 28 else
@@ -46,16 +43,13 @@ class GovUserPluginController &lt; ApplicationController @@ -46,16 +43,13 @@ class GovUserPluginController &lt; ApplicationController
46 @governmental_sphere = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]} 43 @governmental_sphere = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}
47 @governmental_power = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]} 44 @governmental_power = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}
48 @juridical_nature = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]} 45 @juridical_nature = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}
  46 + @state_options = [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]}
49 47
50 @url_token = split_http_referer request.original_url() 48 @url_token = split_http_referer request.original_url()
51 49
52 params[:community] ||= {} 50 params[:community] ||= {}
53 params[:institutions] ||= {} 51 params[:institutions] ||= {}
54 52
55 - @state_options = [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]}  
56 - @governmental_sphere_options = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}  
57 - @governmental_power_options = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}  
58 - @juridical_nature_options = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}  
59 end 53 end
60 54
61 def new_institution 55 def new_institution
@@ -216,8 +210,6 @@ class GovUserPluginController &lt; ApplicationController @@ -216,8 +210,6 @@ class GovUserPluginController &lt; ApplicationController
216 210
217 set_errors institution 211 set_errors institution
218 212
219 - set_error_css institution  
220 -  
221 if inst_errors.empty? && com_errors.empty? && institution.valid? && institution.save 213 if inst_errors.empty? && com_errors.empty? && institution.valid? && institution.save
222 { :success => true, 214 { :success => true,
223 :message => _("Institution successful created!"), 215 :message => _("Institution successful created!"),
@@ -237,7 +229,7 @@ class GovUserPluginController &lt; ApplicationController @@ -237,7 +229,7 @@ class GovUserPluginController &lt; ApplicationController
237 else 229 else
238 flash[:errors] = response_message[:errors] 230 flash[:errors] = response_message[:errors]
239 231
240 - redirect_to :controller => "gov_user_plugin", :action => "create_institution_admin" 232 + redirect_to :controller => "gov_user_plugin", :action => "create_institution_admin", :params => params
241 end 233 end
242 end 234 end
243 235
@@ -254,6 +246,7 @@ class GovUserPluginController &lt; ApplicationController @@ -254,6 +246,7 @@ class GovUserPluginController &lt; ApplicationController
254 flash[:error_institution_governmental_sphere] = institution.errors.include?(:governmental_sphere) ? "highlight-error" : "" 246 flash[:error_institution_governmental_sphere] = institution.errors.include?(:governmental_sphere) ? "highlight-error" : ""
255 flash[:error_institution_governmental_power] = institution.errors.include?(:governmental_power) ? "highlight-error" : "" 247 flash[:error_institution_governmental_power] = institution.errors.include?(:governmental_power) ? "highlight-error" : ""
256 flash[:error_institution_juridical_nature] = institution.errors.include?(:juridical_nature) ? "highlight-error" : "" 248 flash[:error_institution_juridical_nature] = institution.errors.include?(:juridical_nature) ? "highlight-error" : ""
  249 + flash[:error_institution_sisp] = institution.errors.include?(:sisp) ? "highlight-error" : ""
257 end 250 end
258 251
259 end 252 end
lib/institution.rb
@@ -67,7 +67,7 @@ class Institution &lt; ActiveRecord::Base @@ -67,7 +67,7 @@ class Institution &lt; ActiveRecord::Base
67 def validate_state 67 def validate_state
68 if(self.community.blank? || 68 if(self.community.blank? ||
69 self.errors[:state].blank? && 69 self.errors[:state].blank? &&
70 - self.community.state.blank?) 70 + (self.community.state.blank? || self.community.state == "-1"))
71 71
72 if self.community.country == "BR" 72 if self.community.country == "BR"
73 self.errors.add(:state, _("can't be blank")) 73 self.errors.add(:state, _("can't be blank"))
views/gov_user_plugin/_institution.html.erb
@@ -23,10 +23,6 @@ @@ -23,10 +23,6 @@
23 <div id = 'create_institution_errors' class='errorExplanation hide-field'></div> 23 <div id = 'create_institution_errors' class='errorExplanation hide-field'></div>
24 24
25 <div> 25 <div>
26 - <div class="fields-required">  
27 - <span class="errorExplanation"><%= required_fields_message %></span>  
28 - </div>  
29 - <br/>  
30 <%= labelled_form_for :community, :url => {:action=>"new_institution"}, :html => { :multipart => true, :id=>"institution_form" } do |f| %> 26 <%= labelled_form_for :community, :url => {:action=>"new_institution"}, :html => { :multipart => true, :id=>"institution_form" } do |f| %>
31 <div class="fields-required"> 27 <div class="fields-required">
32 <span class="errorExplanation"><%= required_fields_message %></span> 28 <span class="errorExplanation"><%= required_fields_message %></span>
@@ -47,22 +43,13 @@ @@ -47,22 +43,13 @@
47 </div> 43 </div>
48 </span> 44 </span>
49 45
50 - <%= required f.text_field(:name, :class => flash[:error_community_name]) %> 46 + <%= required f.text_field(:name, :class => flash[:error_community_name], :value => params[:community][:name]) %>
51 <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %> 47 <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %>
52 48
53 - <div class= <%= @error_corporate_name %> >  
54 - <span class='required-field'>  
55 - <div class="formfield type-text">  
56 - <%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %>  
57 - <%= required inst.text_field(:corporate_name, :value => params[:institutions][:corporate_name], :size => 55, :class => "#{params[:error_institution_corporate_name]}") %>  
58 - </div>  
59 - </span>  
60 - </div>  
61 -  
62 - <span class='optional-field'> 49 + <span class='required-field'>
63 <div class="formfield type-text"> 50 <div class="formfield type-text">
64 <%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %> 51 <%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %>
65 - <%= required inst.text_field(:corporate_name, :class => flash[:error_institution_corporate_name]) %> 52 + <%= required inst.text_field(:corporate_name, :value => params[:institutions][:corporate_name], :size => 55, :class => flash[:error_institution_corporate_name]) %>
66 </div> 53 </div>
67 </span> 54 </span>
68 55
@@ -71,17 +58,17 @@ @@ -71,17 +58,17 @@
71 <span class='required-field'> 58 <span class='required-field'>
72 <div class="formfield"> 59 <div class="formfield">
73 <label for="community_state" class="formlabel"><%= _("State") %></label> 60 <label for="community_state" class="formlabel"><%= _("State") %></label>
74 - <%= f.select(:state, @state_list.collect {|state| [state.name, state.name]}, {}, {:class => flash[:error_community_state]}) %> 61 + <%= f.select(:state, @state_options, {}, {:class => flash[:error_community_state]}) %>
75 </div> 62 </div>
76 </span> 63 </span>
77 64
78 - <%= required f.text_field(:city, :class => flash[:error_community_city]) %> 65 + <%= required f.text_field(:city, :class => flash[:error_community_city], :value => params[:community][:city]) %>
79 66
80 67
81 <span class='required-field'> 68 <span class='required-field'>
82 <div class="formfield type-text"> 69 <div class="formfield type-text">
83 <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %> 70 <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %>
84 - <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field #{flash[:error_institution_cnpj]}") %> 71 + <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field #{flash[:error_institution_cnpj]}", :value => params[:institutions][:cnpj]) %>
85 </div> 72 </div>
86 </span> 73 </span>
87 74
@@ -97,20 +84,20 @@ @@ -97,20 +84,20 @@
97 <span class='required-field public-institutions-fields'> 84 <span class='required-field public-institutions-fields'>
98 <div class="formfield type-text"> 85 <div class="formfield type-text">
99 <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %> 86 <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %>
100 - <%= inst.select(:governmental_sphere, @governmental_sphere, {:selected=>0})%> 87 + <%= inst.select(:governmental_sphere, @governmental_sphere, {:selected=>0}, :class => flash[:error_institution_governmental_sphere])%>
101 </div> 88 </div>
102 </span> 89 </span>
103 90
104 <span class='required-field public-institutions-fields'> 91 <span class='required-field public-institutions-fields'>
105 <div class="formfield type-text"> 92 <div class="formfield type-text">
106 <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %> 93 <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %>
107 - <%= inst.select(:governmental_power, @governmental_power, {:selected=>0})%> 94 + <%= inst.select(:governmental_power, @governmental_power, {:selected=>0}, {:class => flash[:error_institution_governmental_power]})%>
108 </div> 95 </div>
109 </span> 96 </span>
110 <span class='required-field public-institutions-fields'> 97 <span class='required-field public-institutions-fields'>
111 <div class="formfield type-text"> 98 <div class="formfield type-text">
112 <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %> 99 <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %>
113 - <%= inst.select(:juridical_nature, @juridical_nature, {:selected=>0})%> 100 + <%= inst.select(:juridical_nature, @juridical_nature, {:selected=>0}, {:class => flash[:error_institution_juridical_nature]})%>
114 </div> 101 </div>
115 </span> 102 </span>
116 103
@@ -118,9 +105,9 @@ @@ -118,9 +105,9 @@
118 <div class="formfield type-text"> 105 <div class="formfield type-text">
119 <%= _("SISP?") %> 106 <%= _("SISP?") %>
120 <% if @show_sisp_field %> 107 <% if @show_sisp_field %>
121 - <%= inst.radio_button(:sisp, true, :class => "#{params[:error_institution_sisp]}" ) %> 108 + <%= inst.radio_button(:sisp, true, :class => "#{flash[:error_institution_sisp]}" ) %>
122 <%= inst.label :sisp ,_("Yes"), :value => true %> 109 <%= inst.label :sisp ,_("Yes"), :value => true %>
123 - <%= inst.radio_button(:sisp, false, :checked=>"checked", :class => "#{params[:error_institution_sisp]}") %> 110 + <%= inst.radio_button(:sisp, false, :checked=>"checked", :class => "#{flash[:error_institution_sisp]}") %>
124 <%= inst.label :sisp ,_("No"), :value => false %> 111 <%= inst.label :sisp ,_("No"), :value => false %>
125 <% else %> 112 <% else %>
126 <%= inst.label("sisp", _("No")) %> 113 <%= inst.label("sisp", _("No")) %>