From 402aba1adf501cbfd749366d9fbf8bfc6ef16037 Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Thu, 13 Nov 2014 14:49:33 -0200 Subject: [PATCH] subdirectory_fix: Put ajax routes to use subdirectory --- lib/mpog_software_plugin.rb | 2 +- public/mpog-custom-libraries.js | 30 ------------------------------ public/mpog-incomplete-registration.js | 8 +++++++- public/mpog-institution-validations.js | 39 +++++++++++++++++++++++++-------------- public/mpog-software-validations.js | 8 +++++++- public/mpog-user-validations.js | 8 +++++++- public/spb-utils.js | 37 +++++++++++++++++++++++++++++++++++++ 7 files changed, 84 insertions(+), 48 deletions(-) delete mode 100644 public/mpog-custom-libraries.js create mode 100644 public/spb-utils.js diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index 2cd65f0..469f748 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -213,7 +213,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin end def js_files - ["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"] + ["spb-utils.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 deleted file mode 100644 index 571862a..0000000 --- a/public/mpog-custom-libraries.js +++ /dev/null @@ -1,30 +0,0 @@ -/* -* "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-incomplete-registration.js b/public/mpog-incomplete-registration.js index 79ff15b..eec37af 100644 --- a/public/mpog-incomplete-registration.js +++ b/public/mpog-incomplete-registration.js @@ -1,8 +1,14 @@ (function() { + var AJAX_URL = { + hide_registration_incomplete_percentage: + url_with_subdirectory("/plugin/mpog_software/hide_registration_incomplete_percentage") + }; + + function hide_incomplete_percentage(evt) { evt.preventDefault(); - jQuery.get("/plugin/mpog_software/hide_registration_incomplete_percentage", {hide:true}, function(response){ + jQuery.get(AJAX_URL.hide_registration_incomplete_percentage, {hide:true}, function(response){ if( response == true ) jQuery("#complete_registration").fadeOut(); }); diff --git a/public/mpog-institution-validations.js b/public/mpog-institution-validations.js index 3c7c4ad..ead70ec 100644 --- a/public/mpog-institution-validations.js +++ b/public/mpog-institution-validations.js @@ -1,8 +1,20 @@ (function(){ + var AJAX_URL = { + create_institution_modal: + url_with_subdirectory("/plugin/mpog_software/create_institution"), + new_institution: + url_with_subdirectory("/plugin/mpog_software/new_institution"), + institution_already_exists: + url_with_subdirectory("/plugin/mpog_software/institution_already_exists"), + get_institutions: + url_with_subdirectory("/plugin/mpog_software/get_institutions") + }; + + function open_create_institution_modal(evt) { evt.preventDefault(); - jQuery.get("/plugin/mpog_software/create_institution", function(response){ + jQuery.get(AJAX_URL.create_institution_modal, function(response){ jQuery("#institution_dialog").html(response); set_form_count_custom_data(); @@ -54,6 +66,7 @@ function success_ajax_response(response) { close_loading(); + if(response.success){ var institution_name = response.institution_data.name; var institution_id = response.institution_data.id; @@ -79,11 +92,10 @@ function save_institution(evt) { evt.preventDefault(); - var form_data = jQuery("#institution_form").serialize(); open_loading(jQuery("#loading_message").val()); jQuery.ajax({ - url: "/plugin/mpog_software/new_institution", + url: AJAX_URL.new_institution, data : get_post_data(), type: "POST", success: success_ajax_response, @@ -96,16 +108,16 @@ } function institution_already_exists(){ - if( this.value.length >= 3 ) { - jQuery.get("/plugin/mpog_software/institution_already_exists", {name:this.value}, function(response){ - if( response == true ) { - jQuery("#already_exists_text").switchClass("hide-field", "show-field"); - } else { - jQuery("#already_exists_text").switchClass("show-field", "hide-field"); - } - }); - } + if( this.value.length >= 3 ) { + jQuery.get(AJAX_URL.institution_already_exists, {name:this.value}, function(response){ + if( response == true ) { + jQuery("#already_exists_text").switchClass("hide-field", "show-field"); + } else { + jQuery("#already_exists_text").switchClass("show-field", "hide-field"); + } + }); } + } function get_clone_institution_data(value) { var user_institutions = jQuery(".user_institutions").first().clone(); @@ -119,7 +131,7 @@ source : function(request, response){ jQuery.ajax({ type: "GET", - url: "/plugin/mpog_software/get_institutions", + url: AJAX_URL.get_institutions, data: {query: request.term}, success: function(result){ response(result); @@ -246,7 +258,6 @@ jQuery(".remove-institution").click(remove_institution); jQuery("#community_country").change(function(){ - console.log(this.value) show_hide_cnpj_city(this.value); }); diff --git a/public/mpog-software-validations.js b/public/mpog-software-validations.js index 325794e..a6c2fbe 100644 --- a/public/mpog-software-validations.js +++ b/public/mpog-software-validations.js @@ -1,4 +1,10 @@ (function(){ + var AJAX_URL = { + get_field_data: + url_with_subdirectory("/plugin/mpog_software/get_field_data") + }; + + function get_hidden_description_field(autocomplete_field, klass) { var field = jQuery(autocomplete_field); field = field.parent().parent().find(klass); @@ -35,7 +41,7 @@ source : function(request, response){ jQuery.ajax({ type: "GET", - url: "/plugin/mpog_software/get_field_data", + url: AJAX_URL.get_field_data, data: {query: request.term, field: field_name}, success: function(result){ response(result); diff --git a/public/mpog-user-validations.js b/public/mpog-user-validations.js index 17e4105..3d2bd63 100644 --- a/public/mpog-user-validations.js +++ b/public/mpog-user-validations.js @@ -1,4 +1,10 @@ (function(){ + var AJAX_URL = { + check_reactivate_account: + url_with_subdirectory("/plugin/mpog_software/check_reactivate_account") + }; + + /* * "Class" that switch state field between input and select * If the Country if Brazil, set state to select field @@ -95,7 +101,7 @@ function check_reactivate_account(value, input_object){ jQuery.ajax({ - url : "/plugin/mpog_software/check_reactivate_account", + url : AJAX_URL.check_reactivate_account, type: "GET", data: { "email": value }, success: function(response) { diff --git a/public/spb-utils.js b/public/spb-utils.js new file mode 100644 index 0000000..362a59d --- /dev/null +++ b/public/spb-utils.js @@ -0,0 +1,37 @@ +/* +* "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; +})(); + + +function url_with_subdirectory(url) { + var subdirectory = jQuery("meta[property='noosfero:root']").attr("content"); + + return subdirectory+url; +} \ No newline at end of file -- libgit2 0.21.2