Commit 03d6fe1baddca82758051066c79d05e92854d399
1 parent
49506b2f
Exists in
master
and in
5 other branches
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 | (function(){ | 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 | * "Class" that switch state field between input and select | 34 | * "Class" that switch state field between input and select |
| 4 | * If the Country if Brazil, set state to select field | 35 | * If the Country if Brazil, set state to select field |
| 5 | * else set it as a input field | 36 | * else set it as a input field |
| @@ -16,14 +47,18 @@ | @@ -16,14 +47,18 @@ | ||
| 16 | } | 47 | } |
| 17 | 48 | ||
| 18 | function generate_select(state_list) { | 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 | state_list.forEach(function(state){ | 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 | function replace_state_with_select() { | 64 | function replace_state_with_select() { |
| @@ -74,8 +109,19 @@ | @@ -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 | jQuery('#profile_data_country').val("BR"); | 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 | jQuery("#password-balloon").html(jQuery("#user_password_menssage").val()); | 125 | jQuery("#password-balloon").html(jQuery("#user_password_menssage").val()); |
| 80 | jQuery("#profile_data_email").parent().append(jQuery("#email_public_message").remove()); | 126 | jQuery("#profile_data_email").parent().append(jQuery("#email_public_message").remove()); |
| 81 | 127 | ||
| @@ -332,10 +378,12 @@ | @@ -332,10 +378,12 @@ | ||
| 332 | 378 | ||
| 333 | // Event that calls the "Class" to siwtch state field types | 379 | // Event that calls the "Class" to siwtch state field types |
| 334 | jQuery("#profile_data_country").change(function(){ | 380 | jQuery("#profile_data_country").change(function(){ |
| 381 | + if( this.value == "-1" ) jQuery(this).val("BR"); | ||
| 382 | + | ||
| 335 | if( this.value == "BR" && selectFieldChoices.actualFieldIsInput() ) { | 383 | if( this.value == "BR" && selectFieldChoices.actualFieldIsInput() ) { |
| 336 | selectFieldChoices.setSelect(); | 384 | selectFieldChoices.setSelect(); |
| 337 | selectFieldChoices.setShowCity(); | 385 | selectFieldChoices.setShowCity(); |
| 338 | - } else { | 386 | + } else if( this.value != "BR" && !selectFieldChoices.actualFieldIsInput() ) { |
| 339 | selectFieldChoices.setInput(); | 387 | selectFieldChoices.setInput(); |
| 340 | selectFieldChoices.setHideCity(); | 388 | selectFieldChoices.setHideCity(); |
| 341 | } | 389 | } |