Commit 7eac9970ae98e1d2a3ef1b1fe1e8722a94a3ab90
Committed by
Gabriela Navarro
1 parent
7da23487
Exists in
master
and in
79 other branches
Execute create institution javascript only when needed
Showing
5 changed files
with
311 additions
and
277 deletions
Show diff stats
lib/software_communities_plugin.rb
@@ -131,9 +131,9 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | @@ -131,9 +131,9 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | ||
131 | views/edit-software.js | 131 | views/edit-software.js |
132 | views/new-software.js | 132 | views/new-software.js |
133 | views/user-edit-profile.js | 133 | views/user-edit-profile.js |
134 | + views/create-institution.js | ||
134 | initializer.js | 135 | initializer.js |
135 | app.js | 136 | app.js |
136 | - mpog-institution-validations.js | ||
137 | mpog-incomplete-registration.js | 137 | mpog-incomplete-registration.js |
138 | mpog-search.js | 138 | mpog-search.js |
139 | software-catalog.js | 139 | software-catalog.js |
public/initializer.js
@@ -2,11 +2,12 @@ var dependencies = [ | @@ -2,11 +2,12 @@ var dependencies = [ | ||
2 | 'ControlPanel', | 2 | 'ControlPanel', |
3 | 'EditSoftware', | 3 | 'EditSoftware', |
4 | 'NewSoftware', | 4 | 'NewSoftware', |
5 | - 'UserEditProfile' | 5 | + 'UserEditProfile', |
6 | + 'CreateInstitution' | ||
6 | ]; | 7 | ]; |
7 | 8 | ||
8 | 9 | ||
9 | -modulejs.define('Initializer', dependencies, function(cp, es, ns, uep) { | 10 | +modulejs.define('Initializer', dependencies, function(cp, es, ns, uep, ci) { |
10 | 'use strict'; | 11 | 'use strict'; |
11 | 12 | ||
12 | 13 | ||
@@ -30,6 +31,11 @@ modulejs.define('Initializer', dependencies, function(cp, es, ns, uep) { | @@ -30,6 +31,11 @@ modulejs.define('Initializer', dependencies, function(cp, es, ns, uep) { | ||
30 | if( uep.isUserEditProfile() ) { | 31 | if( uep.isUserEditProfile() ) { |
31 | uep.init(); | 32 | uep.init(); |
32 | } | 33 | } |
34 | + | ||
35 | + | ||
36 | + if( ci.isCreateInstitution() ) { | ||
37 | + ci.init(); | ||
38 | + } | ||
33 | } | 39 | } |
34 | }; | 40 | }; |
35 | }); | 41 | }); |
public/mpog-institution-validations.js
@@ -1,273 +0,0 @@ | @@ -1,273 +0,0 @@ | ||
1 | -(function(){ | ||
2 | - var AJAX_URL = { | ||
3 | - create_institution_modal: | ||
4 | - url_with_subdirectory("/plugin/software_communities/create_institution"), | ||
5 | - new_institution: | ||
6 | - url_with_subdirectory("/plugin/software_communities/new_institution"), | ||
7 | - institution_already_exists: | ||
8 | - url_with_subdirectory("/plugin/software_communities/institution_already_exists"), | ||
9 | - get_institutions: | ||
10 | - url_with_subdirectory("/plugin/software_communities/get_institutions") | ||
11 | - }; | ||
12 | - | ||
13 | - | ||
14 | - function open_create_institution_modal(evt) { | ||
15 | - evt.preventDefault(); | ||
16 | - | ||
17 | - jQuery.get(AJAX_URL.create_institution_modal, function(response){ | ||
18 | - jQuery("#institution_dialog").html(response); | ||
19 | - | ||
20 | - set_form_count_custom_data(); | ||
21 | - set_events(); | ||
22 | - | ||
23 | - jQuery("#institution_dialog").dialog({ | ||
24 | - modal: true, | ||
25 | - width: 500, | ||
26 | - height: 530, | ||
27 | - position: 'center', | ||
28 | - close: function() { | ||
29 | - jQuery("#institution_dialog").html(""); | ||
30 | - jQuery('#institution_empty_ajax_message').switchClass("show-field", "hide-field"); | ||
31 | - } | ||
32 | - }); | ||
33 | - }); | ||
34 | - } | ||
35 | - | ||
36 | - function show_public_institutions_fields() { | ||
37 | - jQuery(".public-institutions-fields").show(); | ||
38 | - } | ||
39 | - | ||
40 | - function show_private_institutions_fields() { | ||
41 | - jQuery(".public-institutions-fields").hide(); | ||
42 | - | ||
43 | - jQuery("#institutions_governmental_power option").selected(0); | ||
44 | - jQuery("#institutions_governmental_sphere option").selected(0); | ||
45 | - } | ||
46 | - | ||
47 | - function get_post_data() { | ||
48 | - return { | ||
49 | - community : { | ||
50 | - name : jQuery("#community_name").val(), | ||
51 | - country : jQuery("#community_country").val(), | ||
52 | - state : jQuery("#community_state").val(), | ||
53 | - city : jQuery("#community_city").val() | ||
54 | - }, | ||
55 | - institutions : { | ||
56 | - cnpj: jQuery("#institutions_cnpj").val(), | ||
57 | - type: jQuery("input[name='institutions[type]']:checked").val(), | ||
58 | - acronym : jQuery("#institutions_acronym").val(), | ||
59 | - governmental_power: jQuery("#institutions_governmental_power").selected().val(), | ||
60 | - governmental_sphere: jQuery("#institutions_governmental_sphere").selected().val(), | ||
61 | - juridical_nature: jQuery("#institutions_juridical_nature").selected().val(), | ||
62 | - corporate_name: jQuery("#institutions_corporate_name").val() | ||
63 | - }, | ||
64 | - } | ||
65 | - } | ||
66 | - | ||
67 | - function success_ajax_response(response) { | ||
68 | - close_loading(); | ||
69 | - | ||
70 | - if(response.success){ | ||
71 | - var institution_name = response.institution_data.name; | ||
72 | - var institution_id = response.institution_data.id; | ||
73 | - | ||
74 | - jQuery("#institution_dialog").html("<div class='errorExplanation'><h2>"+response.message+"</h2></div>"); | ||
75 | - jQuery("#create_institution_errors").switchClass("show-field", "hide-field"); | ||
76 | - | ||
77 | - jQuery(".institution_container").append(get_clone_institution_data(institution_id)); | ||
78 | - add_selected_institution_to_list(institution_id, institution_name); | ||
79 | - | ||
80 | - jQuery(".remove-institution").click(remove_institution); | ||
81 | - } else { | ||
82 | - var errors = "<ul>"; | ||
83 | - | ||
84 | - for(var i = 0; i < response.errors.length; i++) { | ||
85 | - errors += "<li>"+response.errors[i]+"</li>"; | ||
86 | - } | ||
87 | - errors += "</ul>"; | ||
88 | - | ||
89 | - jQuery("#create_institution_errors").switchClass("hide-field", "show-field").html("<h2>"+response.message+"</h2>"+errors); | ||
90 | - } | ||
91 | - } | ||
92 | - | ||
93 | - function save_institution(evt) { | ||
94 | - evt.preventDefault(); | ||
95 | - | ||
96 | - open_loading(jQuery("#loading_message").val()); | ||
97 | - jQuery.ajax({ | ||
98 | - url: AJAX_URL.new_institution, | ||
99 | - data : get_post_data(), | ||
100 | - type: "POST", | ||
101 | - success: success_ajax_response, | ||
102 | - error: function() { | ||
103 | - close_loading(); | ||
104 | - var error_message = jQuery("#institution_error_message").val(); | ||
105 | - jQuery("#create_institution_errors").switchClass("hide-field", "show-field").html("<h2>"+error_message+"</h2>"); | ||
106 | - } | ||
107 | - }); | ||
108 | - } | ||
109 | - | ||
110 | - function institution_already_exists(){ | ||
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 | - }); | ||
119 | - } | ||
120 | - } | ||
121 | - | ||
122 | - function get_clone_institution_data(value) { | ||
123 | - var user_institutions = jQuery(".user_institutions").first().clone(); | ||
124 | - user_institutions.val(value); | ||
125 | - | ||
126 | - return user_institutions; | ||
127 | - } | ||
128 | - | ||
129 | - function institution_autocomplete() { | ||
130 | - jQuery("#input_institution").autocomplete({ | ||
131 | - source : function(request, response){ | ||
132 | - jQuery.ajax({ | ||
133 | - type: "GET", | ||
134 | - url: AJAX_URL.get_institutions, | ||
135 | - data: {query: request.term}, | ||
136 | - success: function(result){ | ||
137 | - response(result); | ||
138 | - | ||
139 | - if( result.length == 0 ) { | ||
140 | - jQuery('#institution_empty_ajax_message').switchClass("hide-field", "show-field"); | ||
141 | - } else { | ||
142 | - jQuery('#institution_empty_ajax_message').switchClass("show-field", "hide-field"); | ||
143 | - } | ||
144 | - }, | ||
145 | - error: function(ajax, stat, errorThrown) { | ||
146 | - console.log('Link not found : ' + errorThrown); | ||
147 | - } | ||
148 | - }); | ||
149 | - }, | ||
150 | - | ||
151 | - minLength: 2, | ||
152 | - | ||
153 | - select : function (event, selected) { | ||
154 | - jQuery("#institution_selected").val(selected.item.id).attr("data-name", selected.item.label); | ||
155 | - } | ||
156 | - }); | ||
157 | - } | ||
158 | - | ||
159 | - function add_selected_institution_to_list(id, name) { | ||
160 | - var selected_institution = "<li data-institution='"+id+"'>"+name; | ||
161 | - selected_institution += "<a href='#' class='button without-text icon-remove remove-institution'></a></li>"; | ||
162 | - | ||
163 | - jQuery(".institutions_added").append(selected_institution); | ||
164 | - } | ||
165 | - | ||
166 | - function add_new_institution(evt) { | ||
167 | - evt.preventDefault(); | ||
168 | - var selected = jQuery("#institution_selected"); | ||
169 | - var institution_already_added = jQuery(".institutions_added li[data-institution='"+selected.val()+"']").length; | ||
170 | - | ||
171 | - if(selected.val().length > 0 && institution_already_added == 0) { | ||
172 | - //field that send the institutions to the server | ||
173 | - jQuery(".institution_container").append(get_clone_institution_data(selected.val())); | ||
174 | - | ||
175 | - // Visualy add the selected institution to the list | ||
176 | - add_selected_institution_to_list(selected.val(), selected.attr("data-name")); | ||
177 | - | ||
178 | - // clean the institution flag | ||
179 | - selected.val("").attr("data-name", ""); | ||
180 | - jQuery("#input_institution").val(""); | ||
181 | - | ||
182 | - jQuery(".remove-institution").click(remove_institution); | ||
183 | - } | ||
184 | - } | ||
185 | - | ||
186 | - function remove_institution(evt) { | ||
187 | - evt.preventDefault(); | ||
188 | - var code = jQuery(this).parent().attr("data-institution"); | ||
189 | - | ||
190 | - jQuery(".user_institutions[value="+code+"]").remove(); | ||
191 | - jQuery(this).parent().remove(); | ||
192 | - } | ||
193 | - | ||
194 | - function add_mask_to_form_items() { | ||
195 | - jQuery(".intitution_cnpj_field").mask("99.999.999/9999-99"); | ||
196 | - } | ||
197 | - | ||
198 | - function show_hide_cnpj_city(country) { | ||
199 | - var cnpj = jQuery("#institutions_cnpj").parent().parent(); | ||
200 | - var city = jQuery("#community_city").parent().parent(); | ||
201 | - var state = jQuery("#community_state").parent().parent(); | ||
202 | - | ||
203 | - if( country == "-1" ) jQuery("#community_country").val("BR"); | ||
204 | - | ||
205 | - if( country != "BR" ) { | ||
206 | - cnpj.hide(); | ||
207 | - city.hide(); | ||
208 | - state.hide(); | ||
209 | - } else { | ||
210 | - cnpj.show(); | ||
211 | - city.show(); | ||
212 | - state.show(); | ||
213 | - } | ||
214 | - } | ||
215 | - | ||
216 | - function institution_type_actions(type) { | ||
217 | - if( type == "PublicInstitution" ) | ||
218 | - show_public_institutions_fields(); | ||
219 | - else | ||
220 | - show_private_institutions_fields(); | ||
221 | - } | ||
222 | - | ||
223 | - function set_form_count_custom_data() { | ||
224 | - var divisor_option = SelectElement.generateOption("-1", "--------------------------------"); | ||
225 | - var default_option = SelectElement.generateOption("BR", "Brazil"); | ||
226 | - | ||
227 | - var inst_type = jQuery("input[name='institutions[type]']:checked").val(); | ||
228 | - var country = jQuery("#community_country").val(); | ||
229 | - | ||
230 | - institution_type_actions(inst_type); | ||
231 | - show_hide_cnpj_city(country); | ||
232 | - | ||
233 | - if( jQuery('#community_country').find("option[value='']").length == 1 ) { | ||
234 | - jQuery('#community_country').find("option[value='']").remove(); | ||
235 | - jQuery('#community_country').prepend(divisor_option); | ||
236 | - jQuery('#community_country').prepend(default_option); | ||
237 | - | ||
238 | - if(jQuery("#edit_institution_page").val() == "false"){ | ||
239 | - jQuery('#community_country').val("BR"); | ||
240 | - show_hide_cnpj_city(jQuery('#community_country').val()); | ||
241 | - } | ||
242 | - } | ||
243 | - } | ||
244 | - | ||
245 | - function set_events() { | ||
246 | - jQuery("#create_institution_link").click(open_create_institution_modal); | ||
247 | - | ||
248 | - jQuery("input[name='institutions[type]']").click(function(){ | ||
249 | - institution_type_actions(this.value); | ||
250 | - }); | ||
251 | - | ||
252 | - jQuery('#save_institution_button').click(save_institution); | ||
253 | - | ||
254 | - jQuery("#community_name").keyup(institution_already_exists); | ||
255 | - | ||
256 | - jQuery("#add_new_institution").click(add_new_institution); | ||
257 | - | ||
258 | - jQuery(".remove-institution").click(remove_institution); | ||
259 | - | ||
260 | - jQuery("#community_country").change(function(){ | ||
261 | - show_hide_cnpj_city(this.value); | ||
262 | - }); | ||
263 | - | ||
264 | - add_mask_to_form_items(); | ||
265 | - | ||
266 | - institution_autocomplete(); | ||
267 | - } | ||
268 | - | ||
269 | - jQuery(document).ready(function(){ | ||
270 | - set_form_count_custom_data(); | ||
271 | - set_events(); | ||
272 | - }); | ||
273 | -})(); |
@@ -0,0 +1,299 @@ | @@ -0,0 +1,299 @@ | ||
1 | +modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'], function($, NoosferoRoot, SelectElement) { | ||
2 | + 'use strict'; | ||
3 | + | ||
4 | + var AJAX_URL = { | ||
5 | + create_institution_modal: | ||
6 | + NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/create_institution"), | ||
7 | + new_institution: | ||
8 | + NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/new_institution"), | ||
9 | + institution_already_exists: | ||
10 | + NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/institution_already_exists"), | ||
11 | + get_institutions: | ||
12 | + NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/get_institutions") | ||
13 | + }; | ||
14 | + | ||
15 | + | ||
16 | + function open_create_institution_modal(evt) { | ||
17 | + evt.preventDefault(); | ||
18 | + | ||
19 | + $.get(AJAX_URL.create_institution_modal, function(response){ | ||
20 | + $("#institution_dialog").html(response); | ||
21 | + | ||
22 | + set_form_count_custom_data(); | ||
23 | + set_events(); | ||
24 | + | ||
25 | + $("#institution_dialog").dialog({ | ||
26 | + modal: true, | ||
27 | + width: 500, | ||
28 | + height: 530, | ||
29 | + position: 'center', | ||
30 | + close: function() { | ||
31 | + $("#institution_dialog").html(""); | ||
32 | + $('#institution_empty_ajax_message').switchClass("show-field", "hide-field"); | ||
33 | + } | ||
34 | + }); | ||
35 | + }); | ||
36 | + } | ||
37 | + | ||
38 | + | ||
39 | + function show_public_institutions_fields() { | ||
40 | + $(".public-institutions-fields").show(); | ||
41 | + } | ||
42 | + | ||
43 | + | ||
44 | + function show_private_institutions_fields() { | ||
45 | + $(".public-institutions-fields").hide(); | ||
46 | + | ||
47 | + $("#institutions_governmental_power option").selected(0); | ||
48 | + $("#institutions_governmental_sphere option").selected(0); | ||
49 | + } | ||
50 | + | ||
51 | + | ||
52 | + function get_post_data() { | ||
53 | + return { | ||
54 | + community : { | ||
55 | + name : $("#community_name").val(), | ||
56 | + country : $("#community_country").val(), | ||
57 | + state : $("#community_state").val(), | ||
58 | + city : $("#community_city").val() | ||
59 | + }, | ||
60 | + institutions : { | ||
61 | + cnpj: $("#institutions_cnpj").val(), | ||
62 | + type: $("input[name='institutions[type]']:checked").val(), | ||
63 | + acronym : $("#institutions_acronym").val(), | ||
64 | + governmental_power: $("#institutions_governmental_power").selected().val(), | ||
65 | + governmental_sphere: $("#institutions_governmental_sphere").selected().val(), | ||
66 | + juridical_nature: $("#institutions_juridical_nature").selected().val(), | ||
67 | + corporate_name: $("#institutions_corporate_name").val() | ||
68 | + }, | ||
69 | + } | ||
70 | + } | ||
71 | + | ||
72 | + | ||
73 | + function success_ajax_response(response) { | ||
74 | + close_loading(); | ||
75 | + | ||
76 | + if(response.success){ | ||
77 | + var institution_name = response.institution_data.name; | ||
78 | + var institution_id = response.institution_data.id; | ||
79 | + | ||
80 | + $("#institution_dialog").html("<div class='errorExplanation'><h2>"+response.message+"</h2></div>"); | ||
81 | + $("#create_institution_errors").switchClass("show-field", "hide-field"); | ||
82 | + | ||
83 | + $(".institution_container").append(get_clone_institution_data(institution_id)); | ||
84 | + add_selected_institution_to_list(institution_id, institution_name); | ||
85 | + | ||
86 | + $(".remove-institution").click(remove_institution); | ||
87 | + } else { | ||
88 | + var errors = "<ul>"; | ||
89 | + | ||
90 | + for(var i = 0; i < response.errors.length; i++) { | ||
91 | + errors += "<li>"+response.errors[i]+"</li>"; | ||
92 | + } | ||
93 | + errors += "</ul>"; | ||
94 | + | ||
95 | + $("#create_institution_errors").switchClass("hide-field", "show-field").html("<h2>"+response.message+"</h2>"+errors); | ||
96 | + } | ||
97 | + } | ||
98 | + | ||
99 | + | ||
100 | + function save_institution(evt) { | ||
101 | + evt.preventDefault(); | ||
102 | + | ||
103 | + open_loading($("#loading_message").val()); | ||
104 | + $.ajax({ | ||
105 | + url: AJAX_URL.new_institution, | ||
106 | + data : get_post_data(), | ||
107 | + type: "POST", | ||
108 | + success: success_ajax_response, | ||
109 | + error: function() { | ||
110 | + close_loading(); | ||
111 | + var error_message = $("#institution_error_message").val(); | ||
112 | + $("#create_institution_errors").switchClass("hide-field", "show-field").html("<h2>"+error_message+"</h2>"); | ||
113 | + } | ||
114 | + }); | ||
115 | + } | ||
116 | + | ||
117 | + | ||
118 | + function institution_already_exists(){ | ||
119 | + if( this.value.length >= 3 ) { | ||
120 | + $.get(AJAX_URL.institution_already_exists, {name:this.value}, function(response){ | ||
121 | + if( response == true ) { | ||
122 | + $("#already_exists_text").switchClass("hide-field", "show-field"); | ||
123 | + } else { | ||
124 | + $("#already_exists_text").switchClass("show-field", "hide-field"); | ||
125 | + } | ||
126 | + }); | ||
127 | + } | ||
128 | + } | ||
129 | + | ||
130 | + | ||
131 | + function get_clone_institution_data(value) { | ||
132 | + var user_institutions = $(".user_institutions").first().clone(); | ||
133 | + user_institutions.val(value); | ||
134 | + | ||
135 | + return user_institutions; | ||
136 | + } | ||
137 | + | ||
138 | + | ||
139 | + function institution_autocomplete() { | ||
140 | + $("#input_institution").autocomplete({ | ||
141 | + source : function(request, response){ | ||
142 | + $.ajax({ | ||
143 | + type: "GET", | ||
144 | + url: AJAX_URL.get_institutions, | ||
145 | + data: {query: request.term}, | ||
146 | + success: function(result){ | ||
147 | + response(result); | ||
148 | + | ||
149 | + if( result.length == 0 ) { | ||
150 | + $('#institution_empty_ajax_message').switchClass("hide-field", "show-field"); | ||
151 | + } else { | ||
152 | + $('#institution_empty_ajax_message').switchClass("show-field", "hide-field"); | ||
153 | + } | ||
154 | + }, | ||
155 | + error: function(ajax, stat, errorThrown) { | ||
156 | + console.log('Link not found : ' + errorThrown); | ||
157 | + } | ||
158 | + }); | ||
159 | + }, | ||
160 | + | ||
161 | + minLength: 2, | ||
162 | + | ||
163 | + select : function (event, selected) { | ||
164 | + $("#institution_selected").val(selected.item.id).attr("data-name", selected.item.label); | ||
165 | + } | ||
166 | + }); | ||
167 | + } | ||
168 | + | ||
169 | + | ||
170 | + function add_selected_institution_to_list(id, name) { | ||
171 | + var selected_institution = "<li data-institution='"+id+"'>"+name; | ||
172 | + selected_institution += "<a href='#' class='button without-text icon-remove remove-institution'></a></li>"; | ||
173 | + | ||
174 | + $(".institutions_added").append(selected_institution); | ||
175 | + } | ||
176 | + | ||
177 | + | ||
178 | + function add_new_institution(evt) { | ||
179 | + evt.preventDefault(); | ||
180 | + var selected = $("#institution_selected"); | ||
181 | + var institution_already_added = $(".institutions_added li[data-institution='"+selected.val()+"']").length; | ||
182 | + | ||
183 | + if(selected.val().length > 0 && institution_already_added == 0) { | ||
184 | + //field that send the institutions to the server | ||
185 | + $(".institution_container").append(get_clone_institution_data(selected.val())); | ||
186 | + | ||
187 | + // Visualy add the selected institution to the list | ||
188 | + add_selected_institution_to_list(selected.val(), selected.attr("data-name")); | ||
189 | + | ||
190 | + // clean the institution flag | ||
191 | + selected.val("").attr("data-name", ""); | ||
192 | + $("#input_institution").val(""); | ||
193 | + | ||
194 | + $(".remove-institution").click(remove_institution); | ||
195 | + } | ||
196 | + } | ||
197 | + | ||
198 | + | ||
199 | + function remove_institution(evt) { | ||
200 | + evt.preventDefault(); | ||
201 | + var code = $(this).parent().attr("data-institution"); | ||
202 | + | ||
203 | + $(".user_institutions[value="+code+"]").remove(); | ||
204 | + $(this).parent().remove(); | ||
205 | + } | ||
206 | + | ||
207 | + | ||
208 | + function add_mask_to_form_items() { | ||
209 | + $(".intitution_cnpj_field").mask("99.999.999/9999-99"); | ||
210 | + } | ||
211 | + | ||
212 | + | ||
213 | + function show_hide_cnpj_city(country) { | ||
214 | + var cnpj = $("#institutions_cnpj").parent().parent(); | ||
215 | + var city = $("#community_city").parent().parent(); | ||
216 | + var state = $("#community_state").parent().parent(); | ||
217 | + | ||
218 | + if( country == "-1" ) $("#community_country").val("BR"); | ||
219 | + | ||
220 | + if( country != "BR" ) { | ||
221 | + cnpj.hide(); | ||
222 | + city.hide(); | ||
223 | + state.hide(); | ||
224 | + } else { | ||
225 | + cnpj.show(); | ||
226 | + city.show(); | ||
227 | + state.show(); | ||
228 | + } | ||
229 | + } | ||
230 | + | ||
231 | + | ||
232 | + function institution_type_actions(type) { | ||
233 | + if( type == "PublicInstitution" ) | ||
234 | + show_public_institutions_fields(); | ||
235 | + else | ||
236 | + show_private_institutions_fields(); | ||
237 | + } | ||
238 | + | ||
239 | + | ||
240 | + function set_form_count_custom_data() { | ||
241 | + var divisor_option = SelectElement.generateOption("-1", "--------------------------------"); | ||
242 | + var default_option = SelectElement.generateOption("BR", "Brazil"); | ||
243 | + | ||
244 | + var inst_type = $("input[name='institutions[type]']:checked").val(); | ||
245 | + var country = $("#community_country").val(); | ||
246 | + | ||
247 | + institution_type_actions(inst_type); | ||
248 | + show_hide_cnpj_city(country); | ||
249 | + | ||
250 | + if( $('#community_country').find("option[value='']").length == 1 ) { | ||
251 | + $('#community_country').find("option[value='']").remove(); | ||
252 | + $('#community_country').prepend(divisor_option); | ||
253 | + $('#community_country').prepend(default_option); | ||
254 | + | ||
255 | + if($("#edit_institution_page").val() == "false"){ | ||
256 | + $('#community_country').val("BR"); | ||
257 | + show_hide_cnpj_city($('#community_country').val()); | ||
258 | + } | ||
259 | + } | ||
260 | + } | ||
261 | + | ||
262 | + | ||
263 | + function set_events() { | ||
264 | + $("#create_institution_link").click(open_create_institution_modal); | ||
265 | + | ||
266 | + $("input[name='institutions[type]']").click(function(){ | ||
267 | + institution_type_actions(this.value); | ||
268 | + }); | ||
269 | + | ||
270 | + $('#save_institution_button').click(save_institution); | ||
271 | + | ||
272 | + $("#community_name").keyup(institution_already_exists); | ||
273 | + | ||
274 | + $("#add_new_institution").click(add_new_institution); | ||
275 | + | ||
276 | + $(".remove-institution").click(remove_institution); | ||
277 | + | ||
278 | + $("#community_country").change(function(){ | ||
279 | + show_hide_cnpj_city(this.value); | ||
280 | + }); | ||
281 | + | ||
282 | + add_mask_to_form_items(); | ||
283 | + | ||
284 | + institution_autocomplete(); | ||
285 | + } | ||
286 | + | ||
287 | + | ||
288 | + return { | ||
289 | + isCreateInstitution: function() { | ||
290 | + return $("#institution_form").length === 1; | ||
291 | + }, | ||
292 | + | ||
293 | + | ||
294 | + init: function() { | ||
295 | + set_form_count_custom_data(); | ||
296 | + set_events(); | ||
297 | + } | ||
298 | + } | ||
299 | +}); |
public/views/user-edit-profile.js
1 | -modulejs.define('UserEditProfile', ['jquery', 'SelectElement', 'SelectFieldChoices'], function($, SelectElement, SelectFieldChoices) { | 1 | +modulejs.define('UserEditProfile', ['jquery', 'SelectElement', 'SelectFieldChoices', 'CreateInstitution'], function($, SelectElement, SelectFieldChoices, CreateInstitution) { |
2 | 'use strict'; | 2 | 'use strict'; |
3 | 3 | ||
4 | function set_form_count_custom_data() { | 4 | function set_form_count_custom_data() { |
@@ -209,6 +209,8 @@ modulejs.define('UserEditProfile', ['jquery', 'SelectElement', 'SelectFieldChoic | @@ -209,6 +209,8 @@ modulejs.define('UserEditProfile', ['jquery', 'SelectElement', 'SelectFieldChoic | ||
209 | show_or_hide_phone_mask(); | 209 | show_or_hide_phone_mask(); |
210 | 210 | ||
211 | set_fields_validations(); | 211 | set_fields_validations(); |
212 | + | ||
213 | + CreateInstitution.init(); | ||
212 | } | 214 | } |
213 | } | 215 | } |
214 | }); | 216 | }); |