diff --git a/controllers/mpog_software_plugin_controller.rb b/controllers/mpog_software_plugin_controller.rb index eac8386..1466ee2 100644 --- a/controllers/mpog_software_plugin_controller.rb +++ b/controllers/mpog_software_plugin_controller.rb @@ -48,19 +48,6 @@ class MpogSoftwarePluginController < ApplicationController def create_institution_admin @url_token = split_http_referer request.original_url() - - if request.post? - governmental = {} - juridical = {} - governmental[:power] = params[:institutions][:governmental_power] - governmental[:sphere] = params[:institutions][:governmental_sphere] - juridical[:nature] = params[:institutions][:juridical_nature] - params[:community][:country] = "BR" - params[:institutions].delete :governmental_power - params[:institutions].delete :governmental_sphere - params[:institutions].delete :juridical_nature - redirect_to :action => "new_institution", :community => params[:community], :institution => params[:institutions], :governmental => governmental, :juridical => juridical - end end def split_http_referer http_referer @@ -70,24 +57,24 @@ class MpogSoftwarePluginController < ApplicationController return @url_token end - def new_institution - if !params[:community].nil? and !params[:institution].nil? + if !params[:community].nil? and !params[:institutions].nil? response_message = {} institution = private_create_institution response_message = if institution.errors.full_messages.empty? and institution.valid? and institution.save - {:success => true, :message => _("Institution successful created!"), :institution_data=>{:name=>institution.name, :id=>institution.id}} - else - {:success => false, :message => _("Institution could not be created!"), :errors => institution.errors.full_messages} - end - if request.xhr? and (split_http_referer(request.referer()) != "create_institution_admin") - render :json => response_message.to_json - else - session[:notice] = response_message[:message] # consume the notice - redirect_to :controller => "/admin_panel", :action => "index" - end + {:success => true, :message => _("Institution successful created!"), :institution_data=>{:name=>institution.name, :id=>institution.id}} + else + {:success => false, :message => _("Institution could not be created!"), :errors => institution.errors.full_messages} + end + + if request.xhr? + render :json => response_message.to_json + else + session[:notice] = response_message[:message] # consume the notice + redirect_to :controller => "/admin_panel", :action => "index" + end else redirect_to "/" end @@ -182,10 +169,10 @@ class MpogSoftwarePluginController < ApplicationController community = Community.new(params[:community]) community.environment = environment - institution = if params[:institution][:type] == "PublicInstitution" - PublicInstitution::new params[:institution] + institution = if params[:institutions][:type] == "PublicInstitution" + PublicInstitution::new params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature) else - PrivateInstitution::new params[:institution] + PrivateInstitution::new params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature) end institution.name = community[:name] @@ -193,9 +180,9 @@ class MpogSoftwarePluginController < ApplicationController if institution.type == "PublicInstitution" begin - govPower = GovernmentalPower.find params[:governmental][:power] - govSphere = GovernmentalSphere.find params[:governmental][:sphere] - jur_nature = JuridicalNature.find params[:juridical][:nature] + govPower = GovernmentalPower.find params[:institutions][:governmental_power] + govSphere = GovernmentalSphere.find params[:institutions][:governmental_sphere] + jur_nature = JuridicalNature.find params[:institutions][:juridical_nature] institution.juridical_nature = jur_nature institution.governmental_power = govPower @@ -211,7 +198,7 @@ class MpogSoftwarePluginController < ApplicationController end InstitutionHelper.register_institution_modification institution - + institution end diff --git a/public/mpog-institution-validations.js b/public/mpog-institution-validations.js index 03b9482..33fe7f6 100644 --- a/public/mpog-institution-validations.js +++ b/public/mpog-institution-validations.js @@ -32,38 +32,21 @@ jQuery("#institutions_governmental_sphere option").selected(0); } - function get_selected_institution_type() { - var radio_buttons = jQuery("input[type='radio'][name='type']"); - var type = ""; - - for( var i = 0; i < radio_buttons.length; i++ ) { - if( radio_buttons[i].checked ) { - type = radio_buttons[i].value; - break; - } - } - - return type; - } - function get_post_data() { return { - community : { name : jQuery("#community_name").val(), + community : { + name : jQuery("#community_name").val(), country : jQuery("#community_country").val(), state : jQuery("#community_state").val(), city : jQuery("#community_city").val() }, - governmental : { - power : jQuery("#institutions_governmental_power").selected().val(), - sphere : jQuery("#institutions_governmental_sphere").selected().val() - }, - juridical : { - nature : jQuery("#institutions_juridical_nature").selected().val() - }, - institution : { + institutions : { cnpj: jQuery("#institutions_cnpj").val(), - type: get_selected_institution_type(), + type: jQuery("input[name='institutions[type]']:checked").val(), acronym : jQuery("#institutions_acronym").val(), + governmental_power: jQuery("#institutions_governmental_power").selected().val(), + governmental_sphere: jQuery("#institutions_governmental_sphere").selected().val(), + juridical_nature: jQuery("#institutions_juridical_nature").selected().val() }, } } @@ -204,9 +187,12 @@ jQuery("#create_institution_link").click(open_create_institution_modal); - jQuery("#type_PrivateInstitution").click(show_private_institutions_fields); - - jQuery("#type_PublicInstitution").click(show_public_institutions_fields); + jQuery("input[type='radio']").click(function(){ + if( this.value == "PublicInstitution" ) + show_public_institutions_fields(); + else + show_private_institutions_fields(); + }); jQuery('#save_institution_button').click(save_institution); diff --git a/views/mpog_software_plugin/_institution.html.erb b/views/mpog_software_plugin/_institution.html.erb index cc542e8..538eab1 100644 --- a/views/mpog_software_plugin/_institution.html.erb +++ b/views/mpog_software_plugin/_institution.html.erb @@ -20,11 +20,11 @@
- <%= labelled_form_for :community, :html => { :multipart => true, :id=>"institution_form" } do |f| %> + <%= labelled_form_for :community, :url => {:action=>"new_institution"}, :html => { :multipart => true, :id=>"institution_form" } do |f| %> <%= required f.text_field(:name) %> <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %> - <%= required select_country(_('Country'), f, 'country', {:class => 'type-select', :id => "community_country"}) %> + <%= required select_country(_('Country'), 'community', 'country', {:class => 'type-select', :id => "community_country"}) %> <%= required f.text_field(:state) %> <%= required f.text_field(:city) %> @@ -39,10 +39,14 @@
- <%= label_tag("type_PublicInstitution", _("Public Institution")) %> - <%= radio_button_tag(:type,"PublicInstitution", true)%> - <%= label_tag("type_PrivateInstitution", _("Private Institution")) %> - <%= radio_button_tag(:type,"PrivateInstitution")%> + + +
-- libgit2 0.21.2