Commit 52a816c0f9986088170f99a4b10dda269c9cb6cd
Committed by
Fabio Teixeira
1 parent
85bd4347
Exists in
master
and in
3 other branches
Fix the form problem. When there is a error when creating an institution through…
… the admin panel, it would empty the form. Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
3 changed files
with
46 additions
and
24 deletions
Show diff stats
controllers/gov_user_plugin_controller.rb
@@ -16,6 +16,14 @@ class GovUserPluginController < ApplicationController | @@ -16,6 +16,14 @@ class GovUserPluginController < ApplicationController | ||
16 | @show_sisp_field = environment.admins.include?(current_user.person) | 16 | @show_sisp_field = environment.admins.include?(current_user.person) |
17 | @state_list = get_state_list() | 17 | @state_list = get_state_list() |
18 | 18 | ||
19 | + params[:community] ||= {} | ||
20 | + params[:institutions] ||= {} | ||
21 | + | ||
22 | + @state_options = [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]} | ||
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]} | ||
25 | + @juridical_nature_options = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]} | ||
26 | + | ||
19 | if request.xhr? | 27 | if request.xhr? |
20 | render :layout=>false | 28 | render :layout=>false |
21 | else | 29 | else |
@@ -35,6 +43,14 @@ class GovUserPluginController < ApplicationController | @@ -35,6 +43,14 @@ class GovUserPluginController < ApplicationController | ||
35 | @state_list = get_state_list() | 43 | @state_list = get_state_list() |
36 | 44 | ||
37 | @url_token = split_http_referer request.original_url() | 45 | @url_token = split_http_referer request.original_url() |
46 | + | ||
47 | + params[:community] ||= {} | ||
48 | + params[:institutions] ||= {} | ||
49 | + | ||
50 | + @state_options = [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]} | ||
51 | + @governmental_sphere_options = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]} | ||
52 | + @governmental_power_options = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]} | ||
53 | + @juridical_nature_options = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]} | ||
38 | end | 54 | end |
39 | 55 | ||
40 | def new_institution | 56 | def new_institution |
@@ -45,10 +61,10 @@ class GovUserPluginController < ApplicationController | @@ -45,10 +61,10 @@ class GovUserPluginController < ApplicationController | ||
45 | institution_template = Community["institution"] | 61 | institution_template = Community["institution"] |
46 | add_template_in_params institution_template | 62 | add_template_in_params institution_template |
47 | 63 | ||
48 | - institution = private_create_institution | ||
49 | - add_environment_admins_to_institution institution | 64 | + @institutions = private_create_institution |
65 | + add_environment_admins_to_institution @institutions | ||
50 | 66 | ||
51 | - response_message = save_institution institution | 67 | + response_message = save_institution @institutions |
52 | 68 | ||
53 | if request.xhr? #User create institution | 69 | if request.xhr? #User create institution |
54 | render :json => response_message.to_json | 70 | render :json => response_message.to_json |
@@ -203,7 +219,7 @@ class GovUserPluginController < ApplicationController | @@ -203,7 +219,7 @@ class GovUserPluginController < ApplicationController | ||
203 | redirect_to :controller => "/admin_panel", :action => "index" | 219 | redirect_to :controller => "/admin_panel", :action => "index" |
204 | else | 220 | else |
205 | flash[:errors] = response_message[:errors] | 221 | flash[:errors] = response_message[:errors] |
206 | - render :controller => "gov_user_plugin", :action => "create_institution_admin" | 222 | + redirect_to :controller => "gov_user_plugin", :action => "create_institution_admin", :params => params |
207 | end | 223 | end |
208 | end | 224 | end |
209 | 225 |
public/views/create-institution.js
@@ -102,8 +102,12 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | @@ -102,8 +102,12 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | ||
102 | errors += "<li>"+response.errors[i]+"</li>"; | 102 | errors += "<li>"+response.errors[i]+"</li>"; |
103 | } | 103 | } |
104 | errors += "</ul>"; | 104 | errors += "</ul>"; |
105 | - | ||
106 | - $("#create_institution_errors").switchClass("hide-field", "show-field").html("<h2>"+response.message+"</h2>"+errors); | 105 | + if($('#institution_dialog') != []){ |
106 | + $('#create_institution_errors').switchClass("show-field", "hide-field"); | ||
107 | + $('#errorExplanation').html("<h2>"+response.message+"</h2>"+errors); | ||
108 | + }else{ | ||
109 | + $("#create_institution_errors").switchClass("hide-field", "show-field").html("<h2>"+response.message+"</h2>"+errors); | ||
110 | + } | ||
107 | } | 111 | } |
108 | } | 112 | } |
109 | 113 |
views/gov_user_plugin/_institution.html.erb
@@ -20,11 +20,11 @@ | @@ -20,11 +20,11 @@ | ||
20 | <div id = 'create_institution_errors' class='errorExplanation hide-field'></div> | 20 | <div id = 'create_institution_errors' class='errorExplanation hide-field'></div> |
21 | 21 | ||
22 | <div> | 22 | <div> |
23 | - <div class="fields-required"> | ||
24 | - <span class="errorExplanation"><%= _("All fields with (*) are mandatory") %></span> | ||
25 | - </div> | ||
26 | - <br/> | ||
27 | <%= labelled_form_for :community, :url => {:action=>"new_institution"}, :html => { :multipart => true, :id=>"institution_form" } do |f| %> | 23 | <%= labelled_form_for :community, :url => {:action=>"new_institution"}, :html => { :multipart => true, :id=>"institution_form" } do |f| %> |
24 | + <div class="fields-required"> | ||
25 | + <span class="errorExplanation"><%= required_fields_message %></span> | ||
26 | + </div> | ||
27 | + <br/> | ||
28 | <%= hidden_field_tag "edit_institution_page", false %> | 28 | <%= hidden_field_tag "edit_institution_page", false %> |
29 | <%= fields_for :institutions do |inst| %> | 29 | <%= fields_for :institutions do |inst| %> |
30 | <span class=''> | 30 | <span class=''> |
@@ -40,22 +40,24 @@ | @@ -40,22 +40,24 @@ | ||
40 | </div> | 40 | </div> |
41 | </span> | 41 | </span> |
42 | 42 | ||
43 | - <%= required f.text_field(:name) %> | 43 | + <%= required f.text_field(:name, :value => params[:community][:name]) %> |
44 | <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %> | 44 | <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %> |
45 | 45 | ||
46 | - <span class='required-field'> | ||
47 | - <div class="formfield type-text"> | ||
48 | - <%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %> | ||
49 | - <%= required inst.text_field(:corporate_name) %> | ||
50 | - </div> | ||
51 | - </span> | 46 | + <div class= <%= @error_corporate_name %> > |
47 | + <span class='required-field'> | ||
48 | + <div class="formfield type-text"> | ||
49 | + <%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %> | ||
50 | + <%= required inst.text_field(:corporate_name, :value => params[:institutions][:corporate_name]) %> | ||
51 | + </div> | ||
52 | + </span> | ||
53 | + </div> | ||
52 | 54 | ||
53 | <span class='optional-field'> | 55 | <span class='optional-field'> |
54 | <div class="formfield type-text"> | 56 | <div class="formfield type-text"> |
55 | <%= hidden_field_tag "acronym_translate", _("Acronym") %> | 57 | <%= hidden_field_tag "acronym_translate", _("Acronym") %> |
56 | <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %> | 58 | <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %> |
57 | <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %> | 59 | <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %> |
58 | - <%= inst.text_field(:acronym) %> | 60 | + <%= inst.text_field(:acronym, :value => params[:institutions][:acronym]) %> |
59 | </div> | 61 | </div> |
60 | </span> | 62 | </span> |
61 | 63 | ||
@@ -64,37 +66,37 @@ | @@ -64,37 +66,37 @@ | ||
64 | <span class='required-field'> | 66 | <span class='required-field'> |
65 | <div class="formfield"> | 67 | <div class="formfield"> |
66 | <label for="community_state" class="formlabel"><%= _("State") %></label> | 68 | <label for="community_state" class="formlabel"><%= _("State") %></label> |
67 | - <%= f.select(:state, [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]}) %> | 69 | + <%= f.select(:state, @state_options, :selected => params[:community][:state]) %> |
68 | </div> | 70 | </div> |
69 | </span> | 71 | </span> |
70 | 72 | ||
71 | - <%= required f.text_field(:city, :id => "city_field") %> | 73 | + <%= required f.text_field(:city, :value => params[:community][:city], :id => "city_field") %> |
72 | 74 | ||
73 | 75 | ||
74 | <span class='required-field'> | 76 | <span class='required-field'> |
75 | <div class="formfield type-text"> | 77 | <div class="formfield type-text"> |
76 | <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %> | 78 | <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %> |
77 | - <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field") %> | 79 | + <%= required inst.text_field(:cnpj, :value => params[:institutions][:cnpj], :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field") %> |
78 | </div> | 80 | </div> |
79 | </span> | 81 | </span> |
80 | 82 | ||
81 | <span class='required-field public-institutions-fields'> | 83 | <span class='required-field public-institutions-fields'> |
82 | <div class="formfield type-text"> | 84 | <div class="formfield type-text"> |
83 | <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %> | 85 | <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %> |
84 | - <%= inst.select(:governmental_sphere, [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}, {:selected=>0})%> | 86 | + <%= inst.select(:governmental_sphere, @governmental_sphere_options, :selected => params[:institutions][:governmental_sphere])%> |
85 | </div> | 87 | </div> |
86 | </span> | 88 | </span> |
87 | 89 | ||
88 | <span class='required-field public-institutions-fields'> | 90 | <span class='required-field public-institutions-fields'> |
89 | <div class="formfield type-text"> | 91 | <div class="formfield type-text"> |
90 | <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %> | 92 | <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %> |
91 | - <%= inst.select(:governmental_power, [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}, {:selected=>0})%> | 93 | + <%= inst.select(:governmental_power, @governmental_power_options, :selected => params[:institutions][:governmental_power])%> |
92 | </div> | 94 | </div> |
93 | </span> | 95 | </span> |
94 | <span class='required-field public-institutions-fields'> | 96 | <span class='required-field public-institutions-fields'> |
95 | <div class="formfield type-text"> | 97 | <div class="formfield type-text"> |
96 | <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %> | 98 | <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %> |
97 | - <%= inst.select(:juridical_nature, [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}, {:selected=>0})%> | 99 | + <%= inst.select(:juridical_nature, @juridical_nature_options, :selected => params[:institutions][:juridical_nature])%> |
98 | </div> | 100 | </div> |
99 | </span> | 101 | </span> |
100 | 102 |