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 18 @governmental_sphere = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}
19 19 @governmental_power = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}
20 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 23 params[:community] ||= {}
23 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 26 if request.xhr?
30 27 render :layout=>false
31 28 else
... ... @@ -46,16 +43,13 @@ class GovUserPluginController &lt; ApplicationController
46 43 @governmental_sphere = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}
47 44 @governmental_power = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}
48 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 48 @url_token = split_http_referer request.original_url()
51 49  
52 50 params[:community] ||= {}
53 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 53 end
60 54  
61 55 def new_institution
... ... @@ -216,8 +210,6 @@ class GovUserPluginController &lt; ApplicationController
216 210  
217 211 set_errors institution
218 212  
219   - set_error_css institution
220   -
221 213 if inst_errors.empty? && com_errors.empty? && institution.valid? && institution.save
222 214 { :success => true,
223 215 :message => _("Institution successful created!"),
... ... @@ -237,7 +229,7 @@ class GovUserPluginController &lt; ApplicationController
237 229 else
238 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 233 end
242 234 end
243 235  
... ... @@ -254,6 +246,7 @@ class GovUserPluginController &lt; ApplicationController
254 246 flash[:error_institution_governmental_sphere] = institution.errors.include?(:governmental_sphere) ? "highlight-error" : ""
255 247 flash[:error_institution_governmental_power] = institution.errors.include?(:governmental_power) ? "highlight-error" : ""
256 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 250 end
258 251  
259 252 end
... ...
lib/institution.rb
... ... @@ -67,7 +67,7 @@ class Institution &lt; ActiveRecord::Base
67 67 def validate_state
68 68 if(self.community.blank? ||
69 69 self.errors[:state].blank? &&
70   - self.community.state.blank?)
  70 + (self.community.state.blank? || self.community.state == "-1"))
71 71  
72 72 if self.community.country == "BR"
73 73 self.errors.add(:state, _("can't be blank"))
... ...
views/gov_user_plugin/_institution.html.erb
... ... @@ -23,10 +23,6 @@
23 23 <div id = 'create_institution_errors' class='errorExplanation hide-field'></div>
24 24  
25 25 <div>
26   - <div class="fields-required">
27   - <span class="errorExplanation"><%= required_fields_message %></span>
28   - </div>
29   - <br/>
30 26 <%= labelled_form_for :community, :url => {:action=>"new_institution"}, :html => { :multipart => true, :id=>"institution_form" } do |f| %>
31 27 <div class="fields-required">
32 28 <span class="errorExplanation"><%= required_fields_message %></span>
... ... @@ -47,22 +43,13 @@
47 43 </div>
48 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 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 50 <div class="formfield type-text">
64 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 53 </div>
67 54 </span>
68 55  
... ... @@ -71,17 +58,17 @@
71 58 <span class='required-field'>
72 59 <div class="formfield">
73 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 62 </div>
76 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 68 <span class='required-field'>
82 69 <div class="formfield type-text">
83 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 72 </div>
86 73 </span>
87 74  
... ... @@ -97,20 +84,20 @@
97 84 <span class='required-field public-institutions-fields'>
98 85 <div class="formfield type-text">
99 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 88 </div>
102 89 </span>
103 90  
104 91 <span class='required-field public-institutions-fields'>
105 92 <div class="formfield type-text">
106 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 95 </div>
109 96 </span>
110 97 <span class='required-field public-institutions-fields'>
111 98 <div class="formfield type-text">
112 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 101 </div>
115 102 </span>
116 103  
... ... @@ -118,9 +105,9 @@
118 105 <div class="formfield type-text">
119 106 <%= _("SISP?") %>
120 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 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 111 <%= inst.label :sisp ,_("No"), :value => false %>
125 112 <% else %>
126 113 <%= inst.label("sisp", _("No")) %>
... ...