From 10afab4180865d504ae3c41711508c9df6f4d96a Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Tue, 4 Nov 2014 16:30:10 -0200 Subject: [PATCH] fix_institution: Separate institution edition from community edition --- controllers/mpog_software_plugin_myprofile_controller.rb | 29 +++++++++++++++++++++++++++++ lib/mpog_software_plugin.rb | 2 ++ public/mpog-institution-validations.js | 36 ++++++++++++++++++++++++------------ views/institution_editor_extras.html.erb | 52 ---------------------------------------------------- views/mpog_software_plugin/_institution.html.erb | 2 +- views/mpog_software_plugin_myprofile/edit_institution.html.erb | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 175 insertions(+), 65 deletions(-) delete mode 100644 views/institution_editor_extras.html.erb create mode 100644 views/mpog_software_plugin_myprofile/edit_institution.html.erb 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 @@ -

<%= _('Institution Information') %>

- -
- <%= labelled_text_field(_("CNPJ"), 'institution[cnpj]', context.profile.institution.cnpj, :class=>"formlabel intitution_cnpj_field", :placeholder=>"99.999.999/9999-99") %> -
- - -
- <% if context.profile.institution.type == "PublicInstitution" %> - <%= labelled_text_field(_("Acronym"), "institution[acronym]", context.profile.institution.acronym, :class=>"formlabel") %> - <% else %> - <%= labelled_text_field(_("Fantasy name"), "institution[acronym]", context.profile.institution.acronym, :class=>"formlabel") %> - <% end %> -
-
- -<% if context.profile.institution.type == "PublicInstitution" %> - -
- <%= label_tag('governmental_power', _("Governmental Power")) %> - <%= select_tag(:governmental_power, options_for_select(GovernmentalPower.all.map {|g| [g.name, g.id]}, :selected => context.profile.institution.governmental_power_id), :class=>"formlabel") %> -
-
- - -
- <%= label_tag('governmental_sphere', _("Governmental Sphere")) %> - <%= select_tag(:governmental_sphere, options_for_select(GovernmentalSphere.all.map {|s| [s.name, s.id]}, :selected => context.profile.institution.governmental_sphere_id), :class=>"formlabel") %> -
-
- - -
- <%= label_tag('juridical_nature', _("Juridical Nature")) %> - <%= select_tag(:juridical_nature, options_for_select(JuridicalNature.all.map {|j| [j.name, j.id]}, :selected => context.profile.institution.juridical_nature_id), :class=>"formlabel") %> -
-
- - -
- <% if @show_sisp_field %> - <%= _("SISP?") %> - <%= labelled_radio_button(_('Yes'), 'institution[sisp]', 'true', context.profile.institution.sisp)%> - <%= labelled_radio_button(_('No'), 'institution[sisp]', 'false', !context.profile.institution.sisp)%> - <% else %> - <%= _("SISP?") %> - <%= label_tag('SISP', context.profile.institution.sisp ? "YES" : "NO") %> - <% end %> -
-
- -<% end %> diff --git a/views/mpog_software_plugin/_institution.html.erb b/views/mpog_software_plugin/_institution.html.erb index 66010e4..b61527c 100644 --- a/views/mpog_software_plugin/_institution.html.erb +++ b/views/mpog_software_plugin/_institution.html.erb @@ -25,7 +25,7 @@
<%= labelled_form_for :community, :url => {:action=>"new_institution"}, :html => { :multipart => true, :id=>"institution_form" } do |f| %> - + <%= hidden_field_tag "edit_institution_page", false %> <%= fields_for :institutions do |inst| %>
diff --git a/views/mpog_software_plugin_myprofile/edit_institution.html.erb b/views/mpog_software_plugin_myprofile/edit_institution.html.erb new file mode 100644 index 0000000..e338e9f --- /dev/null +++ b/views/mpog_software_plugin_myprofile/edit_institution.html.erb @@ -0,0 +1,119 @@ +

<%= _('Edit Institution') %>

+ +<% if environment.enabled?('admin_must_approve_new_communities') %> +
+ <%= _("Note that the creation of communities in this environment is restricted. Your request to create this new community will be sent to %{environment} administrators and will be approved or rejected according to their methods and criteria.") % { :environment => environment.name }%> +
+<%end %> + +<% unless flash[:errors].nil? %> +
+

<%= _("Can`t create new Institution: #{flash[:errors].length} errors") %>

+
    + <% flash[:errors].each do |error| %> +
  • <%= error %>
  • + <% end %> +
+
+<% end %> + +
+ +
+
+ <%= _("All fields with (*) are mandatory") %> +
+
+ <%= labelled_form_for :community,:html => { :multipart => true, :id=>"institution_form" } do |f| %> + <%= hidden_field_tag "edit_institution_page", true %> + <%= fields_for :institutions do |inst| %> + +
+ + + +
+
+ + <%= required f.text_field(:name, :value => @institution.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 => @institution.corporate_name) %> +
+
+ + <%= required select_country(_('Country'), 'community', 'country', {:class => 'type-select', :id => "community_country"}, :selected => @institution.community.country) %> + + +
+ + <%= f.select(:state, @estate_list.collect {|state| [state.name, state.name]}, :selected => @institution.community.state) %> +
+
+ + <%= required f.text_field(:city, :value => @institution.community.city) %> + + + +
+ <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %> + <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field", :value => @institution.cnpj) %> +
+
+ + +
+ <%= hidden_field_tag "acronym_translate", _("Acronym") %> + <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %> + <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %> + <%= inst.text_field(:acronym, :value => @institution.acronym) %> +
+
+ + +
+ <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %> + <%= inst.select(:governmental_sphere, [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}, {:selected=>@institution.governmental_power_id})%> +
+
+ + +
+ <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %> + <%= inst.select(:governmental_power, [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}, {:selected=> @institution.governmental_sphere_id})%> +
+
+ +
+ <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %> + <%= inst.select(:juridical_nature, [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}, {:selected=> @institution.juridical_nature_id})%> +
+
+ + +
+ <%= _("SISP?") %> + <% if @show_sisp_field %> + <%= inst.label("sisp" ,_("Yes")) %> + <%= inst.radio_button(:sisp, true, :checked=>(@institution.sisp ? true : false)) %> + <%= inst.label("sisp" ,_("No")) %> + <%= inst.radio_button(:sisp, false, :checked=>(@institution.sisp ? false : true)) %> + <% else %> + <%= inst.label("sisp", _("No")) %> + <% end %> +
+
+
+ + <%= submit_button :save, _('Save') %> + <% end %> +<% end %> + -- libgit2 0.21.2