Commit 402aba1adf501cbfd749366d9fbf8bfc6ef16037
Committed by
Luciano Prestes
1 parent
2168bebe
Exists in
master
and in
5 other branches
subdirectory_fix: Put ajax routes to use subdirectory
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
7 changed files
with
84 additions
and
48 deletions
Show diff stats
lib/mpog_software_plugin.rb
... | ... | @@ -213,7 +213,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
213 | 213 | end |
214 | 214 | |
215 | 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 | 217 | end |
218 | 218 | |
219 | 219 | def add_new_organization_buttons | ... | ... |
public/mpog-custom-libraries.js
... | ... | @@ -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 | 0 | \ No newline at end of file |
public/mpog-incomplete-registration.js
1 | 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 | 8 | function hide_incomplete_percentage(evt) { |
3 | 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 | 12 | if( response == true ) |
7 | 13 | jQuery("#complete_registration").fadeOut(); |
8 | 14 | }); | ... | ... |
public/mpog-institution-validations.js
1 | 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 | 14 | function open_create_institution_modal(evt) { |
3 | 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 | 18 | jQuery("#institution_dialog").html(response); |
7 | 19 | |
8 | 20 | set_form_count_custom_data(); |
... | ... | @@ -54,6 +66,7 @@ |
54 | 66 | |
55 | 67 | function success_ajax_response(response) { |
56 | 68 | close_loading(); |
69 | + | |
57 | 70 | if(response.success){ |
58 | 71 | var institution_name = response.institution_data.name; |
59 | 72 | var institution_id = response.institution_data.id; |
... | ... | @@ -79,11 +92,10 @@ |
79 | 92 | |
80 | 93 | function save_institution(evt) { |
81 | 94 | evt.preventDefault(); |
82 | - var form_data = jQuery("#institution_form").serialize(); | |
83 | 95 | |
84 | 96 | open_loading(jQuery("#loading_message").val()); |
85 | 97 | jQuery.ajax({ |
86 | - url: "/plugin/mpog_software/new_institution", | |
98 | + url: AJAX_URL.new_institution, | |
87 | 99 | data : get_post_data(), |
88 | 100 | type: "POST", |
89 | 101 | success: success_ajax_response, |
... | ... | @@ -96,16 +108,16 @@ |
96 | 108 | } |
97 | 109 | |
98 | 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 | 122 | function get_clone_institution_data(value) { |
111 | 123 | var user_institutions = jQuery(".user_institutions").first().clone(); |
... | ... | @@ -119,7 +131,7 @@ |
119 | 131 | source : function(request, response){ |
120 | 132 | jQuery.ajax({ |
121 | 133 | type: "GET", |
122 | - url: "/plugin/mpog_software/get_institutions", | |
134 | + url: AJAX_URL.get_institutions, | |
123 | 135 | data: {query: request.term}, |
124 | 136 | success: function(result){ |
125 | 137 | response(result); |
... | ... | @@ -246,7 +258,6 @@ |
246 | 258 | jQuery(".remove-institution").click(remove_institution); |
247 | 259 | |
248 | 260 | jQuery("#community_country").change(function(){ |
249 | - console.log(this.value) | |
250 | 261 | show_hide_cnpj_city(this.value); |
251 | 262 | }); |
252 | 263 | ... | ... |
public/mpog-software-validations.js
1 | 1 | (function(){ |
2 | + var AJAX_URL = { | |
3 | + get_field_data: | |
4 | + url_with_subdirectory("/plugin/mpog_software/get_field_data") | |
5 | + }; | |
6 | + | |
7 | + | |
2 | 8 | function get_hidden_description_field(autocomplete_field, klass) { |
3 | 9 | var field = jQuery(autocomplete_field); |
4 | 10 | field = field.parent().parent().find(klass); |
... | ... | @@ -35,7 +41,7 @@ |
35 | 41 | source : function(request, response){ |
36 | 42 | jQuery.ajax({ |
37 | 43 | type: "GET", |
38 | - url: "/plugin/mpog_software/get_field_data", | |
44 | + url: AJAX_URL.get_field_data, | |
39 | 45 | data: {query: request.term, field: field_name}, |
40 | 46 | success: function(result){ |
41 | 47 | response(result); | ... | ... |
public/mpog-user-validations.js
1 | 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 | 9 | * "Class" that switch state field between input and select |
4 | 10 | * If the Country if Brazil, set state to select field |
... | ... | @@ -95,7 +101,7 @@ |
95 | 101 | |
96 | 102 | function check_reactivate_account(value, input_object){ |
97 | 103 | jQuery.ajax({ |
98 | - url : "/plugin/mpog_software/check_reactivate_account", | |
104 | + url : AJAX_URL.check_reactivate_account, | |
99 | 105 | type: "GET", |
100 | 106 | data: { "email": value }, |
101 | 107 | success: function(response) { | ... | ... |
... | ... | @@ -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 | 38 | \ No newline at end of file | ... | ... |