From 0a70acfcda43346e78773deb9daae8ab9ce624fa Mon Sep 17 00:00:00 2001 From: Gabriela Navarro Date: Tue, 5 May 2015 12:00:10 -0300 Subject: [PATCH] Make the view come with previous information --- controllers/gov_user_plugin_controller.rb | 15 ++++----------- lib/institution.rb | 2 +- views/gov_user_plugin/_institution.html.erb | 35 +++++++++++------------------------ 3 files changed, 16 insertions(+), 36 deletions(-) diff --git a/controllers/gov_user_plugin_controller.rb b/controllers/gov_user_plugin_controller.rb index d8d5995..311b43b 100644 --- a/controllers/gov_user_plugin_controller.rb +++ b/controllers/gov_user_plugin_controller.rb @@ -18,14 +18,11 @@ class GovUserPluginController < ApplicationController @governmental_sphere = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]} @governmental_power = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]} @juridical_nature = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]} + @state_options = [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]} params[:community] ||= {} params[:institutions] ||= {} - @state_options = [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]} - @governmental_sphere_options = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]} - @governmental_power_options = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]} - @juridical_nature_options = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]} if request.xhr? render :layout=>false else @@ -46,16 +43,13 @@ class GovUserPluginController < ApplicationController @governmental_sphere = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]} @governmental_power = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]} @juridical_nature = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]} + @state_options = [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]} @url_token = split_http_referer request.original_url() params[:community] ||= {} params[:institutions] ||= {} - @state_options = [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]} - @governmental_sphere_options = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]} - @governmental_power_options = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]} - @juridical_nature_options = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]} end def new_institution @@ -216,8 +210,6 @@ class GovUserPluginController < ApplicationController set_errors institution - set_error_css institution - if inst_errors.empty? && com_errors.empty? && institution.valid? && institution.save { :success => true, :message => _("Institution successful created!"), @@ -237,7 +229,7 @@ class GovUserPluginController < ApplicationController else flash[:errors] = response_message[:errors] - redirect_to :controller => "gov_user_plugin", :action => "create_institution_admin" + redirect_to :controller => "gov_user_plugin", :action => "create_institution_admin", :params => params end end @@ -254,6 +246,7 @@ class GovUserPluginController < ApplicationController flash[:error_institution_governmental_sphere] = institution.errors.include?(:governmental_sphere) ? "highlight-error" : "" flash[:error_institution_governmental_power] = institution.errors.include?(:governmental_power) ? "highlight-error" : "" flash[:error_institution_juridical_nature] = institution.errors.include?(:juridical_nature) ? "highlight-error" : "" + flash[:error_institution_sisp] = institution.errors.include?(:sisp) ? "highlight-error" : "" end end diff --git a/lib/institution.rb b/lib/institution.rb index cfcb317..919a0ad 100644 --- a/lib/institution.rb +++ b/lib/institution.rb @@ -67,7 +67,7 @@ class Institution < ActiveRecord::Base def validate_state if(self.community.blank? || self.errors[:state].blank? && - self.community.state.blank?) + (self.community.state.blank? || self.community.state == "-1")) if self.community.country == "BR" self.errors.add(:state, _("can't be blank")) diff --git a/views/gov_user_plugin/_institution.html.erb b/views/gov_user_plugin/_institution.html.erb index bac8bd0..17fb47a 100644 --- a/views/gov_user_plugin/_institution.html.erb +++ b/views/gov_user_plugin/_institution.html.erb @@ -23,10 +23,6 @@
-
- <%= required_fields_message %> -
-
<%= labelled_form_for :community, :url => {:action=>"new_institution"}, :html => { :multipart => true, :id=>"institution_form" } do |f| %>
<%= required_fields_message %> @@ -47,22 +43,13 @@
- <%= required f.text_field(:name, :class => flash[:error_community_name]) %> + <%= required f.text_field(:name, :class => flash[:error_community_name], :value => params[:community][:name]) %> <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %> -
> - -
- <%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %> - <%= required inst.text_field(:corporate_name, :value => params[:institutions][:corporate_name], :size => 55, :class => "#{params[:error_institution_corporate_name]}") %> -
-
-
- - +
<%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %> - <%= required inst.text_field(:corporate_name, :class => flash[:error_institution_corporate_name]) %> + <%= required inst.text_field(:corporate_name, :value => params[:institutions][:corporate_name], :size => 55, :class => flash[:error_institution_corporate_name]) %>
@@ -71,17 +58,17 @@
- <%= f.select(:state, @state_list.collect {|state| [state.name, state.name]}, {}, {:class => flash[:error_community_state]}) %> + <%= f.select(:state, @state_options, {}, {:class => flash[:error_community_state]}) %>
- <%= required f.text_field(:city, :class => flash[:error_community_city]) %> + <%= required f.text_field(:city, :class => flash[:error_community_city], :value => params[:community][:city]) %>
<%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %> - <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field #{flash[:error_institution_cnpj]}") %> + <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field #{flash[:error_institution_cnpj]}", :value => params[:institutions][:cnpj]) %>
@@ -97,20 +84,20 @@
<%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %> - <%= inst.select(:governmental_sphere, @governmental_sphere, {:selected=>0})%> + <%= inst.select(:governmental_sphere, @governmental_sphere, {:selected=>0}, :class => flash[:error_institution_governmental_sphere])%>
<%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %> - <%= inst.select(:governmental_power, @governmental_power, {:selected=>0})%> + <%= inst.select(:governmental_power, @governmental_power, {:selected=>0}, {:class => flash[:error_institution_governmental_power]})%>
<%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %> - <%= inst.select(:juridical_nature, @juridical_nature, {:selected=>0})%> + <%= inst.select(:juridical_nature, @juridical_nature, {:selected=>0}, {:class => flash[:error_institution_juridical_nature]})%>
@@ -118,9 +105,9 @@
<%= _("SISP?") %> <% if @show_sisp_field %> - <%= inst.radio_button(:sisp, true, :class => "#{params[:error_institution_sisp]}" ) %> + <%= inst.radio_button(:sisp, true, :class => "#{flash[:error_institution_sisp]}" ) %> <%= inst.label :sisp ,_("Yes"), :value => true %> - <%= inst.radio_button(:sisp, false, :checked=>"checked", :class => "#{params[:error_institution_sisp]}") %> + <%= inst.radio_button(:sisp, false, :checked=>"checked", :class => "#{flash[:error_institution_sisp]}") %> <%= inst.label :sisp ,_("No"), :value => false %> <% else %> <%= inst.label("sisp", _("No")) %> -- libgit2 0.21.2