Commit 03d6fe1baddca82758051066c79d05e92854d399

Authored by Fabio Teixeira
1 parent 49506b2f
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

correcoes_aderencia: Set Brazil as the first country option

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing 1 changed file with 54 additions and 6 deletions   Show diff stats
public/mpog-user-validations.js
1 1 (function(){
2 2 /*
  3 + * "Class" for select and option html generation
  4 + */
  5 + var SelectElement = (function() {
  6 + function SelectElement(name, id) {
  7 + this.select = document.createElement("select");
  8 + }
  9 +
  10 + SelectElement.prototype.setAttr = function(attr, value) {
  11 + return this.select.setAttribute(attr, value);
  12 + };
  13 +
  14 + SelectElement.prototype.addOption = function(option) {
  15 + return this.select.add(option);
  16 + };
  17 +
  18 + SelectElement.prototype.getSelect = function() {
  19 + return this.select;
  20 + };
  21 +
  22 + SelectElement.generateOption = function(value, text) {
  23 + var option;
  24 + option = document.createElement("option");
  25 + option.setAttribute("value", value);
  26 + option.text = text;
  27 + return option;
  28 + };
  29 +
  30 + return SelectElement;
  31 + })();
  32 +
  33 + /*
3 34 * "Class" that switch state field between input and select
4 35 * If the Country if Brazil, set state to select field
5 36 * else set it as a input field
... ... @@ -16,14 +47,18 @@
16 47 }
17 48  
18 49 function generate_select(state_list) {
19   - var html = "<select class='type-select valid' id='state_field' name='profile_data[state]'>";
  50 + var select_element = new SelectElement();
  51 +
  52 + select_element.setAttr("name", "profile_data[state]");
  53 + select_element.setAttr("id", "state_field");
  54 + select_element.setAttr("class", "type-select valid");
20 55  
21 56 state_list.forEach(function(state){
22   - html += "<option value='"+state+"'>"+state+"</option>";
  57 + var option = SelectElement.generateOption(state, state);
  58 + select_element.addOption(option);
23 59 });
24 60  
25   - html += "</select>";
26   - return html;
  61 + return select_element.getSelect();
27 62 }
28 63  
29 64 function replace_state_with_select() {
... ... @@ -74,8 +109,19 @@
74 109 }
75 110 }
76 111  
77   - function set_initial_form_custom_data(selectFieldChoices) {
  112 + function set_form_count_custom_data() {
  113 + var divisor_option = SelectElement.generateOption("-1", "--------------------------------");
  114 + var default_option = SelectElement.generateOption("BR", "Brazil");
  115 +
  116 + jQuery('#profile_data_country').find("option[value='']").remove();
  117 + jQuery('#profile_data_country').prepend(divisor_option);
  118 + jQuery('#profile_data_country').prepend(default_option);
78 119 jQuery('#profile_data_country').val("BR");
  120 + }
  121 +
  122 + function set_initial_form_custom_data(selectFieldChoices) {
  123 + set_form_count_custom_data();
  124 +
79 125 jQuery("#password-balloon").html(jQuery("#user_password_menssage").val());
80 126 jQuery("#profile_data_email").parent().append(jQuery("#email_public_message").remove());
81 127  
... ... @@ -332,10 +378,12 @@
332 378  
333 379 // Event that calls the "Class" to siwtch state field types
334 380 jQuery("#profile_data_country").change(function(){
  381 + if( this.value == "-1" ) jQuery(this).val("BR");
  382 +
335 383 if( this.value == "BR" && selectFieldChoices.actualFieldIsInput() ) {
336 384 selectFieldChoices.setSelect();
337 385 selectFieldChoices.setShowCity();
338   - } else {
  386 + } else if( this.value != "BR" && !selectFieldChoices.actualFieldIsInput() ) {
339 387 selectFieldChoices.setInput();
340 388 selectFieldChoices.setHideCity();
341 389 }
... ...