diff --git a/controllers/mpog_software_plugin_myprofile_controller.rb b/controllers/mpog_software_plugin_myprofile_controller.rb index ad5bb33..d6b5a97 100644 --- a/controllers/mpog_software_plugin_myprofile_controller.rb +++ b/controllers/mpog_software_plugin_myprofile_controller.rb @@ -9,6 +9,35 @@ class MpogSoftwarePluginMyprofileController < MyProfileController nil end + def edit_institution + @show_sisp_field = environment.admins.include?(current_user.person) + @estate_list = NationalRegion.find(:all, :conditions=>["national_region_type_id = ?", 2], :order=>"name") + + @institution = @profile.institution + + if request.post? + @institution.community.update_attributes(params[:community]) + @institution.update_attributes(params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature)) + + if @institution.type == "PublicInstitution" + begin + 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 + @institution.governmental_sphere = govSphere + @institution.save + rescue + @institution.errors.add(:governmental_fields, _("Could not find Governmental Power or Governmental Sphere")) + end + end + + flash[:errors] = @institution.errors.full_messages unless @institution.valid? + end + end + def new_software @errors = [] diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index 8d3f830..bf80375 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -233,6 +233,8 @@ class MpogSoftwarePlugin < Noosfero::Plugin elsif context.profile.person? return { :title => _("Create a new software"), :icon => "design-editor", :url => {:controller => "mpog_software_plugin_myprofile", :action => "new_software"} } return nil + elsif context.profile.institution? + return { :title => _("Institution Info"), :icon => "edit-profile-group", :url => {:controller => "mpog_software_plugin_myprofile", :action => "edit_institution"} } end end diff --git a/public/mpog-institution-validations.js b/public/mpog-institution-validations.js index 0b33f7e..3306ffb 100644 --- a/public/mpog-institution-validations.js +++ b/public/mpog-institution-validations.js @@ -183,14 +183,15 @@ jQuery(".intitution_cnpj_field").mask("99.999.999/9999-99"); } - function show_hide_cnpj_city(e) { + function show_hide_cnpj_city(country) { + console.log(country) var cnpj = jQuery("#institutions_cnpj").parent().parent(); var city = jQuery("#community_city").parent().parent(); var state = jQuery("#community_state").parent().parent(); - if( this.value == "-1" ) jQuery(this).val("BR"); + if( country == "-1" ) jQuery("#community_country").val("BR"); - if( this.value != "BR" ) { + if( country != "BR" ) { cnpj.hide(); city.hide(); state.hide(); @@ -199,12 +200,10 @@ city.show(); state.show(); } - - e.preventDefault(); } - function institution_type_actions() { - if( this.value == "PublicInstitution" ) + function institution_type_actions(type) { + if( type == "PublicInstitution" ) show_public_institutions_fields(); else show_private_institutions_fields(); @@ -214,20 +213,30 @@ var divisor_option = SelectElement.generateOption("-1", "--------------------------------"); var default_option = SelectElement.generateOption("BR", "Brazil"); + var inst_type = jQuery("input[name='institutions[type]']:checked").val(); + var country = jQuery("#community_country").val(); + + institution_type_actions(inst_type); + show_hide_cnpj_city(country); + if( jQuery('#community_country').find("option[value='']").length == 1 ) { jQuery('#community_country').find("option[value='']").remove(); jQuery('#community_country').prepend(divisor_option); jQuery('#community_country').prepend(default_option); - jQuery('#community_country').val("BR"); + + if(jQuery("#edit_institution_page").val() == "false"){ + jQuery('#community_country').val("BR"); + show_hide_cnpj_city(jQuery('#community_country').val()); + } } } function set_events() { - show_private_institutions_fields(); - jQuery("#create_institution_link").click(open_create_institution_modal); - jQuery("input[type='radio'][name='institutions[type]']").click(institution_type_actions); + jQuery("input[name='institutions[type]']").click(function(){ + institution_type_actions(this.value); + }); jQuery('#save_institution_button').click(save_institution); @@ -237,7 +246,10 @@ jQuery(".remove-institution").click(remove_institution); - jQuery("#community_country").change(show_hide_cnpj_city); + jQuery("#community_country").change(function(){ + console.log(this.value) + show_hide_cnpj_city(this.value); + }); add_mask_to_form_items(); diff --git a/views/institution_editor_extras.html.erb b/views/institution_editor_extras.html.erb deleted file mode 100644 index d08cc15..0000000 --- a/views/institution_editor_extras.html.erb +++ /dev/null @@ -1,52 +0,0 @@ -