Commit 402aba1adf501cbfd749366d9fbf8bfc6ef16037

Authored by Fabio Teixeira
Committed by Luciano Prestes
1 parent 2168bebe

subdirectory_fix: Put ajax routes to use subdirectory

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
lib/mpog_software_plugin.rb
@@ -213,7 +213,7 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin @@ -213,7 +213,7 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
213 end 213 end
214 214
215 def js_files 215 def js_files
216 - ["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"] 216 + ["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"]
217 end 217 end
218 218
219 def add_new_organization_buttons 219 def add_new_organization_buttons
public/mpog-custom-libraries.js
@@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
1 -/*  
2 -* "Class" for select and option html generation  
3 -*/  
4 -var SelectElement = (function() {  
5 - function SelectElement(name, id) {  
6 - this.select = document.createElement("select");  
7 - }  
8 -  
9 - SelectElement.prototype.setAttr = function(attr, value) {  
10 - return this.select.setAttribute(attr, value);  
11 - };  
12 -  
13 - SelectElement.prototype.addOption = function(option) {  
14 - return this.select.add(option);  
15 - };  
16 -  
17 - SelectElement.prototype.getSelect = function() {  
18 - return this.select;  
19 - };  
20 -  
21 - SelectElement.generateOption = function(value, text) {  
22 - var option;  
23 - option = document.createElement("option");  
24 - option.setAttribute("value", value);  
25 - option.text = text;  
26 - return option;  
27 - };  
28 -  
29 - return SelectElement;  
30 -})();  
31 \ No newline at end of file 0 \ No newline at end of file
public/mpog-incomplete-registration.js
1 (function() { 1 (function() {
  2 + var AJAX_URL = {
  3 + hide_registration_incomplete_percentage:
  4 + url_with_subdirectory("/plugin/mpog_software/hide_registration_incomplete_percentage")
  5 + };
  6 +
  7 +
2 function hide_incomplete_percentage(evt) { 8 function hide_incomplete_percentage(evt) {
3 evt.preventDefault(); 9 evt.preventDefault();
4 10
5 - jQuery.get("/plugin/mpog_software/hide_registration_incomplete_percentage", {hide:true}, function(response){ 11 + jQuery.get(AJAX_URL.hide_registration_incomplete_percentage, {hide:true}, function(response){
6 if( response == true ) 12 if( response == true )
7 jQuery("#complete_registration").fadeOut(); 13 jQuery("#complete_registration").fadeOut();
8 }); 14 });
public/mpog-institution-validations.js
1 (function(){ 1 (function(){
  2 + var AJAX_URL = {
  3 + create_institution_modal:
  4 + url_with_subdirectory("/plugin/mpog_software/create_institution"),
  5 + new_institution:
  6 + url_with_subdirectory("/plugin/mpog_software/new_institution"),
  7 + institution_already_exists:
  8 + url_with_subdirectory("/plugin/mpog_software/institution_already_exists"),
  9 + get_institutions:
  10 + url_with_subdirectory("/plugin/mpog_software/get_institutions")
  11 + };
  12 +
  13 +
2 function open_create_institution_modal(evt) { 14 function open_create_institution_modal(evt) {
3 evt.preventDefault(); 15 evt.preventDefault();
4 16
5 - jQuery.get("/plugin/mpog_software/create_institution", function(response){ 17 + jQuery.get(AJAX_URL.create_institution_modal, function(response){
6 jQuery("#institution_dialog").html(response); 18 jQuery("#institution_dialog").html(response);
7 19
8 set_form_count_custom_data(); 20 set_form_count_custom_data();
@@ -54,6 +66,7 @@ @@ -54,6 +66,7 @@
54 66
55 function success_ajax_response(response) { 67 function success_ajax_response(response) {
56 close_loading(); 68 close_loading();
  69 +
57 if(response.success){ 70 if(response.success){
58 var institution_name = response.institution_data.name; 71 var institution_name = response.institution_data.name;
59 var institution_id = response.institution_data.id; 72 var institution_id = response.institution_data.id;
@@ -79,11 +92,10 @@ @@ -79,11 +92,10 @@
79 92
80 function save_institution(evt) { 93 function save_institution(evt) {
81 evt.preventDefault(); 94 evt.preventDefault();
82 - var form_data = jQuery("#institution_form").serialize();  
83 95
84 open_loading(jQuery("#loading_message").val()); 96 open_loading(jQuery("#loading_message").val());
85 jQuery.ajax({ 97 jQuery.ajax({
86 - url: "/plugin/mpog_software/new_institution", 98 + url: AJAX_URL.new_institution,
87 data : get_post_data(), 99 data : get_post_data(),
88 type: "POST", 100 type: "POST",
89 success: success_ajax_response, 101 success: success_ajax_response,
@@ -96,16 +108,16 @@ @@ -96,16 +108,16 @@
96 } 108 }
97 109
98 function institution_already_exists(){ 110 function institution_already_exists(){
99 - if( this.value.length >= 3 ) {  
100 - jQuery.get("/plugin/mpog_software/institution_already_exists", {name:this.value}, function(response){  
101 - if( response == true ) {  
102 - jQuery("#already_exists_text").switchClass("hide-field", "show-field");  
103 - } else {  
104 - jQuery("#already_exists_text").switchClass("show-field", "hide-field");  
105 - }  
106 - });  
107 - } 111 + if( this.value.length >= 3 ) {
  112 + jQuery.get(AJAX_URL.institution_already_exists, {name:this.value}, function(response){
  113 + if( response == true ) {
  114 + jQuery("#already_exists_text").switchClass("hide-field", "show-field");
  115 + } else {
  116 + jQuery("#already_exists_text").switchClass("show-field", "hide-field");
  117 + }
  118 + });
108 } 119 }
  120 + }
109 121
110 function get_clone_institution_data(value) { 122 function get_clone_institution_data(value) {
111 var user_institutions = jQuery(".user_institutions").first().clone(); 123 var user_institutions = jQuery(".user_institutions").first().clone();
@@ -119,7 +131,7 @@ @@ -119,7 +131,7 @@
119 source : function(request, response){ 131 source : function(request, response){
120 jQuery.ajax({ 132 jQuery.ajax({
121 type: "GET", 133 type: "GET",
122 - url: "/plugin/mpog_software/get_institutions", 134 + url: AJAX_URL.get_institutions,
123 data: {query: request.term}, 135 data: {query: request.term},
124 success: function(result){ 136 success: function(result){
125 response(result); 137 response(result);
@@ -246,7 +258,6 @@ @@ -246,7 +258,6 @@
246 jQuery(".remove-institution").click(remove_institution); 258 jQuery(".remove-institution").click(remove_institution);
247 259
248 jQuery("#community_country").change(function(){ 260 jQuery("#community_country").change(function(){
249 - console.log(this.value)  
250 show_hide_cnpj_city(this.value); 261 show_hide_cnpj_city(this.value);
251 }); 262 });
252 263
public/mpog-software-validations.js
1 (function(){ 1 (function(){
  2 + var AJAX_URL = {
  3 + get_field_data:
  4 + url_with_subdirectory("/plugin/mpog_software/get_field_data")
  5 + };
  6 +
  7 +
2 function get_hidden_description_field(autocomplete_field, klass) { 8 function get_hidden_description_field(autocomplete_field, klass) {
3 var field = jQuery(autocomplete_field); 9 var field = jQuery(autocomplete_field);
4 field = field.parent().parent().find(klass); 10 field = field.parent().parent().find(klass);
@@ -35,7 +41,7 @@ @@ -35,7 +41,7 @@
35 source : function(request, response){ 41 source : function(request, response){
36 jQuery.ajax({ 42 jQuery.ajax({
37 type: "GET", 43 type: "GET",
38 - url: "/plugin/mpog_software/get_field_data", 44 + url: AJAX_URL.get_field_data,
39 data: {query: request.term, field: field_name}, 45 data: {query: request.term, field: field_name},
40 success: function(result){ 46 success: function(result){
41 response(result); 47 response(result);
public/mpog-user-validations.js
1 (function(){ 1 (function(){
  2 + var AJAX_URL = {
  3 + check_reactivate_account:
  4 + url_with_subdirectory("/plugin/mpog_software/check_reactivate_account")
  5 + };
  6 +
  7 +
2 /* 8 /*
3 * "Class" that switch state field between input and select 9 * "Class" that switch state field between input and select
4 * If the Country if Brazil, set state to select field 10 * If the Country if Brazil, set state to select field
@@ -95,7 +101,7 @@ @@ -95,7 +101,7 @@
95 101
96 function check_reactivate_account(value, input_object){ 102 function check_reactivate_account(value, input_object){
97 jQuery.ajax({ 103 jQuery.ajax({
98 - url : "/plugin/mpog_software/check_reactivate_account", 104 + url : AJAX_URL.check_reactivate_account,
99 type: "GET", 105 type: "GET",
100 data: { "email": value }, 106 data: { "email": value },
101 success: function(response) { 107 success: function(response) {
public/spb-utils.js 0 → 100644
@@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
  1 +/*
  2 +* "Class" for select and option html generation
  3 +*/
  4 +var SelectElement = (function() {
  5 + function SelectElement(name, id) {
  6 + this.select = document.createElement("select");
  7 + }
  8 +
  9 + SelectElement.prototype.setAttr = function(attr, value) {
  10 + return this.select.setAttribute(attr, value);
  11 + };
  12 +
  13 + SelectElement.prototype.addOption = function(option) {
  14 + return this.select.add(option);
  15 + };
  16 +
  17 + SelectElement.prototype.getSelect = function() {
  18 + return this.select;
  19 + };
  20 +
  21 + SelectElement.generateOption = function(value, text) {
  22 + var option;
  23 + option = document.createElement("option");
  24 + option.setAttribute("value", value);
  25 + option.text = text;
  26 + return option;
  27 + };
  28 +
  29 + return SelectElement;
  30 +})();
  31 +
  32 +
  33 +function url_with_subdirectory(url) {
  34 + var subdirectory = jQuery("meta[property='noosfero:root']").attr("content");
  35 +
  36 + return subdirectory+url;
  37 +}
0 \ No newline at end of file 38 \ No newline at end of file