Commit 80db92cc2fef121689f6fa2caaed8a61dc3731de

Authored by Fabio Teixeira
Committed by Gabriela Navarro
1 parent 760ea10e

fix_institution: Change state to select field and correct country bug

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
controllers/mpog_software_plugin_controller.rb
@@ -40,6 +40,7 @@ class MpogSoftwarePluginController &lt; ApplicationController @@ -40,6 +40,7 @@ class MpogSoftwarePluginController &lt; ApplicationController
40 40
41 def create_institution 41 def create_institution
42 @show_sisp_field = environment.admins.include?(current_user.person) 42 @show_sisp_field = environment.admins.include?(current_user.person)
  43 + @estate_list = get_state_list()
43 44
44 if request.xhr? 45 if request.xhr?
45 render :layout=>false 46 render :layout=>false
@@ -57,6 +58,7 @@ class MpogSoftwarePluginController &lt; ApplicationController @@ -57,6 +58,7 @@ class MpogSoftwarePluginController &lt; ApplicationController
57 58
58 def create_institution_admin 59 def create_institution_admin
59 @show_sisp_field = environment.admins.include?(current_user.person) 60 @show_sisp_field = environment.admins.include?(current_user.person)
  61 + @estate_list = get_state_list()
60 62
61 @url_token = split_http_referer request.original_url() 63 @url_token = split_http_referer request.original_url()
62 end 64 end
@@ -143,7 +145,7 @@ class MpogSoftwarePluginController &lt; ApplicationController @@ -143,7 +145,7 @@ class MpogSoftwarePluginController &lt; ApplicationController
143 def get_brazil_states 145 def get_brazil_states
144 redirect_to "/" unless request.xhr? 146 redirect_to "/" unless request.xhr?
145 147
146 - state_list = NationalRegion.find(:all, :conditions=>["national_region_type_id = ?", 2], :order=>"name") 148 + state_list = get_state_list()
147 render :json=>state_list.collect {|state| state.name }.to_json 149 render :json=>state_list.collect {|state| state.name }.to_json
148 end 150 end
149 151
@@ -175,6 +177,10 @@ class MpogSoftwarePluginController &lt; ApplicationController @@ -175,6 +177,10 @@ class MpogSoftwarePluginController &lt; ApplicationController
175 177
176 protected 178 protected
177 179
  180 + def get_state_list
  181 + NationalRegion.find(:all, :conditions=>["national_region_type_id = ?", 2], :order=>"name")
  182 + end
  183 +
178 def private_create_institution 184 def private_create_institution
179 community = Community.new(params[:community]) 185 community = Community.new(params[:community])
180 community.environment = environment 186 community.environment = environment
public/mpog-institution-validations.js
@@ -4,6 +4,8 @@ @@ -4,6 +4,8 @@
4 4
5 jQuery.get("/plugin/mpog_software/create_institution", function(response){ 5 jQuery.get("/plugin/mpog_software/create_institution", function(response){
6 jQuery("#institution_dialog").html(response); 6 jQuery("#institution_dialog").html(response);
  7 +
  8 + set_form_count_custom_data();
7 set_events(); 9 set_events();
8 10
9 jQuery("#institution_dialog").dialog({ 11 jQuery("#institution_dialog").dialog({
@@ -212,10 +214,12 @@ @@ -212,10 +214,12 @@
212 var divisor_option = SelectElement.generateOption("-1", "--------------------------------"); 214 var divisor_option = SelectElement.generateOption("-1", "--------------------------------");
213 var default_option = SelectElement.generateOption("BR", "Brazil"); 215 var default_option = SelectElement.generateOption("BR", "Brazil");
214 216
215 - jQuery('#community_country').find("option[value='']").remove();  
216 - jQuery('#community_country').prepend(divisor_option);  
217 - jQuery('#community_country').prepend(default_option);  
218 - jQuery('#community_country').val("BR"); 217 + if( jQuery('#community_country').find("option[value='']").length == 1 ) {
  218 + jQuery('#community_country').find("option[value='']").remove();
  219 + jQuery('#community_country').prepend(divisor_option);
  220 + jQuery('#community_country').prepend(default_option);
  221 + jQuery('#community_country').val("BR");
  222 + }
219 } 223 }
220 224
221 function set_events() { 225 function set_events() {
views/mpog_software_plugin/_institution.html.erb
@@ -51,7 +51,14 @@ @@ -51,7 +51,14 @@
51 </span> 51 </span>
52 52
53 <%= required select_country(_('Country'), 'community', 'country', {:class => 'type-select', :id => "community_country"}) %> 53 <%= required select_country(_('Country'), 'community', 'country', {:class => 'type-select', :id => "community_country"}) %>
54 - <%= required f.text_field(:state) %> 54 +
  55 + <span class='required-field'>
  56 + <div class="formfield">
  57 + <label for="community_state" class="formlabel"><%= _("State") %></label>
  58 + <%= f.select(:state, @estate_list.collect {|state| [state.name, state.name]}) %>
  59 + </div>
  60 + </span>
  61 +
55 <%= required f.text_field(:city) %> 62 <%= required f.text_field(:city) %>
56 63
57 64