diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index d399204..8d3f830 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -248,7 +248,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin end def js_files - ["mpog-software.js", "mpog-software-validations.js", "mpog-user-validations.js", "mpog-institution-validations.js", "mpog-incomplete-registration.js", "mpog-search.js", "jquery.maskedinput.min.js"] + ["mpog-custom-libraries.js", "mpog-software.js", "mpog-software-validations.js", "mpog-user-validations.js", "mpog-institution-validations.js", "mpog-incomplete-registration.js", "mpog-search.js", "jquery.maskedinput.min.js"] end def add_new_organization_buttons diff --git a/public/mpog-custom-libraries.js b/public/mpog-custom-libraries.js new file mode 100644 index 0000000..571862a --- /dev/null +++ b/public/mpog-custom-libraries.js @@ -0,0 +1,30 @@ +/* +* "Class" for select and option html generation +*/ +var SelectElement = (function() { + function SelectElement(name, id) { + this.select = document.createElement("select"); + } + + SelectElement.prototype.setAttr = function(attr, value) { + return this.select.setAttribute(attr, value); + }; + + SelectElement.prototype.addOption = function(option) { + return this.select.add(option); + }; + + SelectElement.prototype.getSelect = function() { + return this.select; + }; + + SelectElement.generateOption = function(value, text) { + var option; + option = document.createElement("option"); + option.setAttribute("value", value); + option.text = text; + return option; + }; + + return SelectElement; +})(); \ No newline at end of file diff --git a/public/mpog-institution-validations.js b/public/mpog-institution-validations.js index 228c5f4..2859912 100644 --- a/public/mpog-institution-validations.js +++ b/public/mpog-institution-validations.js @@ -181,11 +181,13 @@ jQuery(".intitution_cnpj_field").mask("99.999.999/9999-99"); } - function show_hide_cnpj_city() { + function show_hide_cnpj_city(e) { var cnpj = jQuery("#institutions_cnpj").parent().parent(); var city = jQuery("#community_city").parent().parent(); var state = jQuery("#community_state").parent().parent(); + if( this.value == "-1" ) jQuery(this).val("BR"); + if( this.value != "BR" ) { cnpj.hide(); city.hide(); @@ -195,21 +197,33 @@ city.show(); state.show(); } + + e.preventDefault(); } - function set_events() { - show_private_institutions_fields(); + function institution_type_actions() { + if( this.value == "PublicInstitution" ) + show_public_institutions_fields(); + else + show_private_institutions_fields(); + } + + function set_form_count_custom_data() { + var divisor_option = SelectElement.generateOption("-1", "--------------------------------"); + var default_option = SelectElement.generateOption("BR", "Brazil"); + jQuery('#community_country').find("option[value='']").remove(); + jQuery('#community_country').prepend(divisor_option); + jQuery('#community_country').prepend(default_option); jQuery('#community_country').val("BR"); + } + + function set_events() { + show_private_institutions_fields(); jQuery("#create_institution_link").click(open_create_institution_modal); - jQuery("input[type='radio']").click(function(){ - if( this.value == "PublicInstitution" ) - show_public_institutions_fields(); - else - show_private_institutions_fields(); - }); + jQuery("input[type='radio']").click(institution_type_actions); jQuery('#save_institution_button').click(save_institution); @@ -226,5 +240,8 @@ institution_autocomplete(); } - jQuery(document).ready(set_events); + jQuery(document).ready(function(){ + set_form_count_custom_data(); + set_events(); + }); })(); diff --git a/public/mpog-user-validations.js b/public/mpog-user-validations.js index 0a9109f..17e4105 100644 --- a/public/mpog-user-validations.js +++ b/public/mpog-user-validations.js @@ -1,36 +1,5 @@ (function(){ /* - * "Class" for select and option html generation - */ - var SelectElement = (function() { - function SelectElement(name, id) { - this.select = document.createElement("select"); - } - - SelectElement.prototype.setAttr = function(attr, value) { - return this.select.setAttribute(attr, value); - }; - - SelectElement.prototype.addOption = function(option) { - return this.select.add(option); - }; - - SelectElement.prototype.getSelect = function() { - return this.select; - }; - - SelectElement.generateOption = function(value, text) { - var option; - option = document.createElement("option"); - option.setAttribute("value", value); - option.text = text; - return option; - }; - - return SelectElement; - })(); - - /* * "Class" that switch state field between input and select * If the Country if Brazil, set state to select field * else set it as a input field -- libgit2 0.21.2