Commit 2e14336df69ca88062e9df504743d59b068dab34
Committed by
Gabriela Navarro
1 parent
7eac9970
Exists in
master
and in
5 other branches
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 | } |