Commit 2e14336df69ca88062e9df504743d59b068dab34

Authored by Fabio Teixeira
Committed by Gabriela Navarro
1 parent 7eac9970
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

Refactory create-institution.js

Showing 1 changed file with 38 additions and 25 deletions   Show diff stats
public/views/create-institution.js
@@ -49,27 +49,39 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] @@ -49,27 +49,39 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement']
49 } 49 }
50 50
51 51
52 - function get_post_data() { 52 + function get_comunity_post_data() {
53 return { 53 return {
54 - community : {  
55 - name : $("#community_name").val(),  
56 - country : $("#community_country").val(),  
57 - state : $("#community_state").val(),  
58 - city : $("#community_city").val()  
59 - },  
60 - institutions : {  
61 - cnpj: $("#institutions_cnpj").val(),  
62 - type: $("input[name='institutions[type]']:checked").val(),  
63 - acronym : $("#institutions_acronym").val(),  
64 - governmental_power: $("#institutions_governmental_power").selected().val(),  
65 - governmental_sphere: $("#institutions_governmental_sphere").selected().val(),  
66 - juridical_nature: $("#institutions_juridical_nature").selected().val(),  
67 - corporate_name: $("#institutions_corporate_name").val()  
68 - }, 54 + name : $("#community_name").val(),
  55 + country : $("#community_country").val(),
  56 + state : $("#community_state").val(),
  57 + city : $("#community_city").val()
69 } 58 }
70 } 59 }
71 60
72 61
  62 + function get_institution_post_data() {
  63 + return {
  64 + cnpj: $("#institutions_cnpj").val(),
  65 + type: $("input[name='institutions[type]']:checked").val(),
  66 + acronym : $("#institutions_acronym").val(),
  67 + governmental_power: $("#institutions_governmental_power").selected().val(),
  68 + governmental_sphere: $("#institutions_governmental_sphere").selected().val(),
  69 + juridical_nature: $("#institutions_juridical_nature").selected().val(),
  70 + corporate_name: $("#institutions_corporate_name").val()
  71 + }
  72 + }
  73 +
  74 +
  75 + function get_post_data() {
  76 + var post_data = {};
  77 +
  78 + post_data.community = get_comunity_post_data();
  79 + post_data.institutions = get_institution_post_data();
  80 +
  81 + return post_data;
  82 + }
  83 +
  84 +
73 function success_ajax_response(response) { 85 function success_ajax_response(response) {
74 close_loading(); 86 close_loading();
75 87
@@ -118,7 +130,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] @@ -118,7 +130,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement']
118 function institution_already_exists(){ 130 function institution_already_exists(){
119 if( this.value.length >= 3 ) { 131 if( this.value.length >= 3 ) {
120 $.get(AJAX_URL.institution_already_exists, {name:this.value}, function(response){ 132 $.get(AJAX_URL.institution_already_exists, {name:this.value}, function(response){
121 - if( response == true ) { 133 + if( response === true ) {
122 $("#already_exists_text").switchClass("hide-field", "show-field"); 134 $("#already_exists_text").switchClass("hide-field", "show-field");
123 } else { 135 } else {
124 $("#already_exists_text").switchClass("show-field", "hide-field"); 136 $("#already_exists_text").switchClass("show-field", "hide-field");
@@ -146,7 +158,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] @@ -146,7 +158,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement']
146 success: function(result){ 158 success: function(result){
147 response(result); 159 response(result);
148 160
149 - if( result.length == 0 ) { 161 + if( result.length === 0 ) {
150 $('#institution_empty_ajax_message').switchClass("hide-field", "show-field"); 162 $('#institution_empty_ajax_message').switchClass("hide-field", "show-field");
151 } else { 163 } else {
152 $('#institution_empty_ajax_message').switchClass("show-field", "hide-field"); 164 $('#institution_empty_ajax_message').switchClass("show-field", "hide-field");
@@ -180,7 +192,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] @@ -180,7 +192,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement']
180 var selected = $("#institution_selected"); 192 var selected = $("#institution_selected");
181 var institution_already_added = $(".institutions_added li[data-institution='"+selected.val()+"']").length; 193 var institution_already_added = $(".institutions_added li[data-institution='"+selected.val()+"']").length;
182 194
183 - if(selected.val().length > 0 && institution_already_added == 0) { 195 + if(selected.val().length > 0 && institution_already_added === 0) {
184 //field that send the institutions to the server 196 //field that send the institutions to the server
185 $(".institution_container").append(get_clone_institution_data(selected.val())); 197 $(".institution_container").append(get_clone_institution_data(selected.val()));
186 198
@@ -215,9 +227,9 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] @@ -215,9 +227,9 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement']
215 var city = $("#community_city").parent().parent(); 227 var city = $("#community_city").parent().parent();
216 var state = $("#community_state").parent().parent(); 228 var state = $("#community_state").parent().parent();
217 229
218 - if( country == "-1" ) $("#community_country").val("BR"); 230 + if( country === "-1" ) $("#community_country").val("BR");
219 231
220 - if( country != "BR" ) { 232 + if( country !== "BR" ) {
221 cnpj.hide(); 233 cnpj.hide();
222 city.hide(); 234 city.hide();
223 state.hide(); 235 state.hide();
@@ -230,10 +242,11 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] @@ -230,10 +242,11 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement']
230 242
231 243
232 function institution_type_actions(type) { 244 function institution_type_actions(type) {
233 - if( type == "PublicInstitution" ) 245 + if( type === "PublicInstitution" ) {
234 show_public_institutions_fields(); 246 show_public_institutions_fields();
235 - else 247 + } else {
236 show_private_institutions_fields(); 248 show_private_institutions_fields();
  249 + }
237 } 250 }
238 251
239 252
@@ -247,12 +260,12 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] @@ -247,12 +260,12 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement']
247 institution_type_actions(inst_type); 260 institution_type_actions(inst_type);
248 show_hide_cnpj_city(country); 261 show_hide_cnpj_city(country);
249 262
250 - if( $('#community_country').find("option[value='']").length == 1 ) { 263 + if( $('#community_country').find("option[value='']").length === 1 ) {
251 $('#community_country').find("option[value='']").remove(); 264 $('#community_country').find("option[value='']").remove();
252 $('#community_country').prepend(divisor_option); 265 $('#community_country').prepend(divisor_option);
253 $('#community_country').prepend(default_option); 266 $('#community_country').prepend(default_option);
254 267
255 - if($("#edit_institution_page").val() == "false"){ 268 + if($("#edit_institution_page").val() === "false") {
256 $('#community_country').val("BR"); 269 $('#community_country').val("BR");
257 show_hide_cnpj_city($('#community_country').val()); 270 show_hide_cnpj_city($('#community_country').val());
258 } 271 }