Commit 10afab4180865d504ae3c41711508c9df6f4d96a

Authored by Fabio Teixeira
Committed by Gabriela Navarro
1 parent 80db92cc
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

fix_institution: Separate institution edition from community edition

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
controllers/mpog_software_plugin_myprofile_controller.rb
@@ -9,6 +9,35 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController @@ -9,6 +9,35 @@ class MpogSoftwarePluginMyprofileController &lt; MyProfileController
9 nil 9 nil
10 end 10 end
11 11
  12 + def edit_institution
  13 + @show_sisp_field = environment.admins.include?(current_user.person)
  14 + @estate_list = NationalRegion.find(:all, :conditions=>["national_region_type_id = ?", 2], :order=>"name")
  15 +
  16 + @institution = @profile.institution
  17 +
  18 + if request.post?
  19 + @institution.community.update_attributes(params[:community])
  20 + @institution.update_attributes(params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature))
  21 +
  22 + if @institution.type == "PublicInstitution"
  23 + begin
  24 + govPower = GovernmentalPower.find params[:institutions][:governmental_power]
  25 + govSphere = GovernmentalSphere.find params[:institutions][:governmental_sphere]
  26 + jur_nature = JuridicalNature.find params[:institutions][:juridical_nature]
  27 +
  28 + @institution.juridical_nature = jur_nature
  29 + @institution.governmental_power = govPower
  30 + @institution.governmental_sphere = govSphere
  31 + @institution.save
  32 + rescue
  33 + @institution.errors.add(:governmental_fields, _("Could not find Governmental Power or Governmental Sphere"))
  34 + end
  35 + end
  36 +
  37 + flash[:errors] = @institution.errors.full_messages unless @institution.valid?
  38 + end
  39 + end
  40 +
12 def new_software 41 def new_software
13 @errors = [] 42 @errors = []
14 43
lib/mpog_software_plugin.rb
@@ -233,6 +233,8 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin @@ -233,6 +233,8 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
233 elsif context.profile.person? 233 elsif context.profile.person?
234 return { :title => _("Create a new software"), :icon => "design-editor", :url => {:controller => "mpog_software_plugin_myprofile", :action => "new_software"} } 234 return { :title => _("Create a new software"), :icon => "design-editor", :url => {:controller => "mpog_software_plugin_myprofile", :action => "new_software"} }
235 return nil 235 return nil
  236 + elsif context.profile.institution?
  237 + return { :title => _("Institution Info"), :icon => "edit-profile-group", :url => {:controller => "mpog_software_plugin_myprofile", :action => "edit_institution"} }
236 end 238 end
237 end 239 end
238 240
public/mpog-institution-validations.js
@@ -183,14 +183,15 @@ @@ -183,14 +183,15 @@
183 jQuery(".intitution_cnpj_field").mask("99.999.999/9999-99"); 183 jQuery(".intitution_cnpj_field").mask("99.999.999/9999-99");
184 } 184 }
185 185
186 - function show_hide_cnpj_city(e) { 186 + function show_hide_cnpj_city(country) {
  187 + console.log(country)
187 var cnpj = jQuery("#institutions_cnpj").parent().parent(); 188 var cnpj = jQuery("#institutions_cnpj").parent().parent();
188 var city = jQuery("#community_city").parent().parent(); 189 var city = jQuery("#community_city").parent().parent();
189 var state = jQuery("#community_state").parent().parent(); 190 var state = jQuery("#community_state").parent().parent();
190 191
191 - if( this.value == "-1" ) jQuery(this).val("BR"); 192 + if( country == "-1" ) jQuery("#community_country").val("BR");
192 193
193 - if( this.value != "BR" ) { 194 + if( country != "BR" ) {
194 cnpj.hide(); 195 cnpj.hide();
195 city.hide(); 196 city.hide();
196 state.hide(); 197 state.hide();
@@ -199,12 +200,10 @@ @@ -199,12 +200,10 @@
199 city.show(); 200 city.show();
200 state.show(); 201 state.show();
201 } 202 }
202 -  
203 - e.preventDefault();  
204 } 203 }
205 204
206 - function institution_type_actions() {  
207 - if( this.value == "PublicInstitution" ) 205 + function institution_type_actions(type) {
  206 + if( type == "PublicInstitution" )
208 show_public_institutions_fields(); 207 show_public_institutions_fields();
209 else 208 else
210 show_private_institutions_fields(); 209 show_private_institutions_fields();
@@ -214,20 +213,30 @@ @@ -214,20 +213,30 @@
214 var divisor_option = SelectElement.generateOption("-1", "--------------------------------"); 213 var divisor_option = SelectElement.generateOption("-1", "--------------------------------");
215 var default_option = SelectElement.generateOption("BR", "Brazil"); 214 var default_option = SelectElement.generateOption("BR", "Brazil");
216 215
  216 + var inst_type = jQuery("input[name='institutions[type]']:checked").val();
  217 + var country = jQuery("#community_country").val();
  218 +
  219 + institution_type_actions(inst_type);
  220 + show_hide_cnpj_city(country);
  221 +
217 if( jQuery('#community_country').find("option[value='']").length == 1 ) { 222 if( jQuery('#community_country').find("option[value='']").length == 1 ) {
218 jQuery('#community_country').find("option[value='']").remove(); 223 jQuery('#community_country').find("option[value='']").remove();
219 jQuery('#community_country').prepend(divisor_option); 224 jQuery('#community_country').prepend(divisor_option);
220 jQuery('#community_country').prepend(default_option); 225 jQuery('#community_country').prepend(default_option);
221 - jQuery('#community_country').val("BR"); 226 +
  227 + if(jQuery("#edit_institution_page").val() == "false"){
  228 + jQuery('#community_country').val("BR");
  229 + show_hide_cnpj_city(jQuery('#community_country').val());
  230 + }
222 } 231 }
223 } 232 }
224 233
225 function set_events() { 234 function set_events() {
226 - show_private_institutions_fields();  
227 -  
228 jQuery("#create_institution_link").click(open_create_institution_modal); 235 jQuery("#create_institution_link").click(open_create_institution_modal);
229 236
230 - jQuery("input[type='radio'][name='institutions[type]']").click(institution_type_actions); 237 + jQuery("input[name='institutions[type]']").click(function(){
  238 + institution_type_actions(this.value);
  239 + });
231 240
232 jQuery('#save_institution_button').click(save_institution); 241 jQuery('#save_institution_button').click(save_institution);
233 242
@@ -237,7 +246,10 @@ @@ -237,7 +246,10 @@
237 246
238 jQuery(".remove-institution").click(remove_institution); 247 jQuery(".remove-institution").click(remove_institution);
239 248
240 - jQuery("#community_country").change(show_hide_cnpj_city); 249 + jQuery("#community_country").change(function(){
  250 + console.log(this.value)
  251 + show_hide_cnpj_city(this.value);
  252 + });
241 253
242 add_mask_to_form_items(); 254 add_mask_to_form_items();
243 255
views/institution_editor_extras.html.erb
@@ -1,52 +0,0 @@ @@ -1,52 +0,0 @@
1 -<h2><%= _('Institution Information') %></h2>  
2 -  
3 -<div class="formfield type-text">  
4 - <%= labelled_text_field(_("CNPJ"), 'institution[cnpj]', context.profile.institution.cnpj, :class=>"formlabel intitution_cnpj_field", :placeholder=>"99.999.999/9999-99") %>  
5 -</div>  
6 -  
7 -<span class='required-field'>  
8 -<div class="formfield type-text">  
9 - <% if context.profile.institution.type == "PublicInstitution" %>  
10 - <%= labelled_text_field(_("Acronym"), "institution[acronym]", context.profile.institution.acronym, :class=>"formlabel") %>  
11 - <% else %>  
12 - <%= labelled_text_field(_("Fantasy name"), "institution[acronym]", context.profile.institution.acronym, :class=>"formlabel") %>  
13 - <% end %>  
14 -</div>  
15 -</span>  
16 -  
17 -<% if context.profile.institution.type == "PublicInstitution" %>  
18 - <span class='public-institutions-fields'>  
19 - <div class="formfield type-select">  
20 - <%= label_tag('governmental_power', _("Governmental Power")) %>  
21 - <%= select_tag(:governmental_power, options_for_select(GovernmentalPower.all.map {|g| [g.name, g.id]}, :selected => context.profile.institution.governmental_power_id), :class=>"formlabel") %>  
22 - </div>  
23 - </span>  
24 -  
25 - <span class= 'public-institutions-fields'>  
26 - <div class="formfield type-select">  
27 - <%= label_tag('governmental_sphere', _("Governmental Sphere")) %>  
28 - <%= select_tag(:governmental_sphere, options_for_select(GovernmentalSphere.all.map {|s| [s.name, s.id]}, :selected => context.profile.institution.governmental_sphere_id), :class=>"formlabel") %>  
29 - </div>  
30 - </span>  
31 -  
32 - <span class= 'public-institutions-fields'>  
33 - <div class="formfield type-select">  
34 - <%= label_tag('juridical_nature', _("Juridical Nature")) %>  
35 - <%= select_tag(:juridical_nature, options_for_select(JuridicalNature.all.map {|j| [j.name, j.id]}, :selected => context.profile.institution.juridical_nature_id), :class=>"formlabel") %>  
36 - </div>  
37 - </span>  
38 -  
39 - <span class= 'public-institutions-fields'>  
40 - <div class="formfieldline">  
41 - <% if @show_sisp_field %>  
42 - <%= _("SISP?") %>  
43 - <%= labelled_radio_button(_('Yes'), 'institution[sisp]', 'true', context.profile.institution.sisp)%>  
44 - <%= labelled_radio_button(_('No'), 'institution[sisp]', 'false', !context.profile.institution.sisp)%>  
45 - <% else %>  
46 - <%= _("SISP?") %>  
47 - <%= label_tag('SISP', context.profile.institution.sisp ? "YES" : "NO") %>  
48 - <% end %>  
49 - </div>  
50 - </span>  
51 -  
52 -<% end %>  
views/mpog_software_plugin/_institution.html.erb
@@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
25 </div> 25 </div>
26 <br/> 26 <br/>
27 <%= labelled_form_for :community, :url => {:action=>"new_institution"}, :html => { :multipart => true, :id=>"institution_form" } do |f| %> 27 <%= labelled_form_for :community, :url => {:action=>"new_institution"}, :html => { :multipart => true, :id=>"institution_form" } do |f| %>
28 - 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=''>
31 <div class='formfield type-radio'> 31 <div class='formfield type-radio'>
views/mpog_software_plugin_myprofile/edit_institution.html.erb 0 → 100644
@@ -0,0 +1,119 @@ @@ -0,0 +1,119 @@
  1 +<h1><%= _('Edit Institution') %></h1>
  2 +
  3 +<% if environment.enabled?('admin_must_approve_new_communities') %>
  4 + <div class='explanation'>
  5 + <%= _("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 }%>
  6 + </div>
  7 +<%end %>
  8 +
  9 +<% unless flash[:errors].nil? %>
  10 +<div class="errorExplanation" id="errorExplanation">
  11 + <h2> <%= _("Can`t create new Institution: #{flash[:errors].length} errors") %> </h2>
  12 + <ul>
  13 + <% flash[:errors].each do |error| %>
  14 + <li> <%= error %> </li>
  15 + <% end %>
  16 + </ul>
  17 +</div>
  18 +<% end %>
  19 +
  20 +<div id = 'create_institution_errors' class='errorExplanation hide-field'></div>
  21 +
  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,:html => { :multipart => true, :id=>"institution_form" } do |f| %>
  28 + <%= hidden_field_tag "edit_institution_page", true %>
  29 + <%= fields_for :institutions do |inst| %>
  30 + <span class=''>
  31 + <div class='formfield type-radio'>
  32 + <label> <%= _("Public Institution") %>
  33 + <%= radio_button_tag("institutions[type]", "PublicInstitution", (@institution.type == "PublicInstitution" ? true : false)) %>
  34 + </label>
  35 +
  36 + <label>
  37 + <%= _("Private Institution") %>
  38 + <%= radio_button_tag("institutions[type]" ,"PrivateInstitution", (@institution.type == "PrivateInstitution" ? true : false))%>
  39 + </label>
  40 + </div>
  41 + </span>
  42 +
  43 + <%= required f.text_field(:name, :value => @institution.community.name) %>
  44 + <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %>
  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, :value => @institution.corporate_name) %>
  50 + </div>
  51 + </span>
  52 +
  53 + <%= required select_country(_('Country'), 'community', 'country', {:class => 'type-select', :id => "community_country"}, :selected => @institution.community.country) %>
  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]}, :selected => @institution.community.state) %>
  59 + </div>
  60 + </span>
  61 +
  62 + <%= required f.text_field(:city, :value => @institution.community.city) %>
  63 +
  64 +
  65 + <span class='required-field'>
  66 + <div class="formfield type-text">
  67 + <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %>
  68 + <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field", :value => @institution.cnpj) %>
  69 + </div>
  70 + </span>
  71 +
  72 + <span class='optional-field'>
  73 + <div class="formfield type-text">
  74 + <%= hidden_field_tag "acronym_translate", _("Acronym") %>
  75 + <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %>
  76 + <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %>
  77 + <%= inst.text_field(:acronym, :value => @institution.acronym) %>
  78 + </div>
  79 + </span>
  80 +
  81 + <span class='required-field public-institutions-fields'>
  82 + <div class="formfield type-text">
  83 + <%= 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=>@institution.governmental_power_id})%>
  85 + </div>
  86 + </span>
  87 +
  88 + <span class='required-field public-institutions-fields'>
  89 + <div class="formfield type-text">
  90 + <%= 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=> @institution.governmental_sphere_id})%>
  92 + </div>
  93 + </span>
  94 + <span class='required-field public-institutions-fields'>
  95 + <div class="formfield type-text">
  96 + <%= 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=> @institution.juridical_nature_id})%>
  98 + </div>
  99 + </span>
  100 +
  101 + <span class='required-field public-institutions-fields'>
  102 + <div class="formfield type-text">
  103 + <%= _("SISP?") %>
  104 + <% if @show_sisp_field %>
  105 + <%= inst.label("sisp" ,_("Yes")) %>
  106 + <%= inst.radio_button(:sisp, true, :checked=>(@institution.sisp ? true : false)) %>
  107 + <%= inst.label("sisp" ,_("No")) %>
  108 + <%= inst.radio_button(:sisp, false, :checked=>(@institution.sisp ? false : true)) %>
  109 + <% else %>
  110 + <%= inst.label("sisp", _("No")) %>
  111 + <% end %>
  112 + </div>
  113 + </span>
  114 + <br />
  115 +
  116 + <%= submit_button :save, _('Save') %>
  117 + <% end %>
  118 +<% end %>
  119 +