PluginProbe
Property Hive / 1.4.5
Property Hive v1.4.5
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / assets / js / frontend / account.js

account.js in Property Hive 1.4.5, at assets/js/frontend/account.js

302 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var is_submitting = false;
2
3 jQuery(document).ready(function($)
4 {
5 toggleApplicantRegistrationDepartmentFields();
6
7 $('form.applicant-registration-form [name=\'department\'], form.account-requirements-form [name=\'department\']').change(function()
8 {
9 toggleApplicantRegistrationDepartmentFields();
10 });
11
12 // Login form being submitted
13 $('body').on('submit', 'form[name=\'ph_login_form\']', function()
14 {
15 if (!is_submitting)
16 {
17 is_submitting = true;
18
19 var data = $(this).serialize() + '&'+$.param({ 'action': 'propertyhive_login', 'security': propertyhive_account_params.login_nonce });
20
21 var form_obj = $(this);
22
23 form_obj.find('#loginError').hide();
24
25 $.post( propertyhive_account_params.ajax_url, data, function(response)
26 {
27 if (response.success == true)
28 {
29 if ( propertyhive_account_params.redirect_url && propertyhive_account_params.redirect_url != '' )
30 {
31 window.location.href = propertyhive_account_params.redirect_url;
32 }
33 else
34 {
35 if ( propertyhive_account_params.my_account_url && propertyhive_account_params.my_account_url != '' )
36 {
37 window.location.href = propertyhive_account_params.my_account_url;
38 }
39 else
40 {
41 alert('Sorry but no account page has been assigned. Therefore we are unable to redirect.');
42 }
43 }
44 }
45 else
46 {
47 form_obj.find('#loginError').fadeIn();
48 }
49
50 is_submitting = false;
51
52 });
53 }
54
55 return false;
56 });
57
58 // Registration form being submitted
59 $('body').on('submit', 'form[name=\'ph_applicant_registration_form\']', function()
60 {
61 if (!is_submitting)
62 {
63 is_submitting = true;
64
65 var data = $(this).serialize() + '&'+$.param({ 'action': 'propertyhive_applicant_registration', 'security': propertyhive_account_params.register_nonce });
66
67 var form_obj = $(this);
68
69 form_obj.find('#registrationSuccess').hide();
70 form_obj.find('#registrationValidation').hide();
71 form_obj.find('#registrationError').hide();
72
73 $.post( propertyhive_account_params.ajax_url, data, function(response)
74 {
75 if (response.success == true)
76 {
77 if ( propertyhive_account_params.redirect_url && propertyhive_account_params.redirect_url != '' )
78 {
79 window.location.href = propertyhive_account_params.redirect_url;
80 }
81 else
82 {
83 if ( propertyhive_account_params.my_account_url && propertyhive_account_params.my_account_url != '' )
84 {
85 window.location.href = propertyhive_account_params.my_account_url;
86 }
87 else
88 {
89 form_obj.find('#registrationSuccess').fadeIn();
90
91 form_obj.trigger("reset");
92 }
93 }
94 }
95 else
96 {
97 form_obj.find('#registrationValidation').html('Please ensure all required fields have been completed');
98 if (response.reason == 'validation')
99 {
100 if ( response.errors.length > 0 )
101 {
102 var error_html = '';
103 for ( var i in response.errors )
104 {
105 error_html += response.errors[i] + '<br>';
106 }
107 if ( error_html != '' )
108 {
109 form_obj.find('#registrationValidation').html(error_html);
110 }
111 }
112 form_obj.find('#registrationValidation').fadeIn();
113 }
114 else
115 {
116 form_obj.find('#registrationError').fadeIn();
117 }
118 }
119
120 is_submitting = false;
121
122 });
123 }
124
125 return false;
126 });
127
128 // Account details form being submitted
129 $('body').on('submit', 'form[name=\'ph_account_details_form\']', function()
130 {
131 if (!is_submitting)
132 {
133 is_submitting = true;
134
135 var data = $(this).serialize() + '&'+$.param({ 'action': 'propertyhive_save_account_details', 'security': propertyhive_account_params.details_nonce });
136
137 var form_obj = $(this);
138
139 form_obj.find('#detailsSuccess').hide();
140 form_obj.find('#detailsValidation').hide();
141 form_obj.find('#detailsError').hide();
142
143 $.post( propertyhive_account_params.ajax_url, data, function(response)
144 {
145 if (response.success == true)
146 {
147 form_obj.find('#detailsSuccess').fadeIn();
148 }
149 else
150 {
151 if (response.reason == 'validation')
152 {
153 form_obj.find('#detailsValidation').fadeIn();
154 }
155 else
156 {
157 form_obj.find('#detailsError').fadeIn();
158 }
159 }
160
161 is_submitting = false;
162
163 });
164 }
165
166 return false;
167 });
168
169 // Account requirements form being submitted
170 $('body').on('submit', 'form[name=\'ph_account_requirements_form\']', function()
171 {
172 if (!is_submitting)
173 {
174 is_submitting = true;
175
176 var data = $(this).serialize() + '&'+$.param({ 'action': 'propertyhive_save_account_requirements', 'security': propertyhive_account_params.requirements_nonce });
177
178 var form_obj = $(this);
179
180 form_obj.find('#requirementsSuccess').hide();
181 form_obj.find('#requirementsValidation').hide();
182 form_obj.find('#requirementsError').hide();
183
184 $.post( propertyhive_account_params.ajax_url, data, function(response)
185 {
186 if (response.success == true)
187 {
188 form_obj.find('#requirementsSuccess').fadeIn();
189 }
190 else
191 {
192 if (response.reason == 'validation')
193 {
194 form_obj.find('#requirementsValidation').fadeIn();
195 }
196 else
197 {
198 form_obj.find('#requirementsError').fadeIn();
199 }
200 }
201
202 is_submitting = false;
203
204 });
205 }
206
207 return false;
208 });
209
210 $('.my-account-navigation a[href^=\'#\']').click(function(e)
211 {
212 e.preventDefault();
213
214 // Hide/show sections
215 $('.my-account-sections > div').hide();
216 $('.my-account-sections ' + $(this).attr('href')).show();
217
218 // Remove/add active class on nav/tabs
219 $('.my-account-navigation a').each(function()
220 {
221 $(this).parent().removeClass('active');
222 });
223 $(this).parent().addClass('active');
224 });
225 });
226
227 jQuery(window).resize(function() {
228 toggleDepartmentFields();
229 });
230
231 function toggleApplicantRegistrationDepartmentFields()
232 {
233 if (jQuery('form.applicant-registration-form').length > 0 || jQuery('form.account-requirements-form').length > 0)
234 {
235 // There may be multiple forms on the page so treat each one individually
236 jQuery('form.applicant-registration-form, form.account-requirements-form').each(function()
237 {
238 var selectedDepartment = "residential-sales"; // TODO: Use default from settings
239
240 var departmentEl = jQuery(this).find('[name=\'department\']')
241 if (departmentEl.length > 0)
242 {
243 switch (departmentEl.prop('tagName').toLowerCase())
244 {
245 case "select":
246 {
247 var selected = departmentEl;
248 break;
249 }
250 default:
251 {
252 if ( departmentEl.attr('type') == 'hidden' )
253 {
254 var selected = departmentEl;
255 }
256 else
257 {
258 var selected = departmentEl.filter(':checked');
259 }
260 }
261 }
262 }
263
264 jQuery(this).find('.sales-only').hide();
265 jQuery(this).find('.lettings-only').hide();
266 jQuery(this).find('.residential-only').hide();
267 jQuery(this).find('.commercial-only').hide();
268
269 if (selected.length > 0)
270 {
271 selectedDepartment = selected.val();
272
273 // controls won't always be display:block so we should get the
274 // first visible component (that isnt sales/lettings-only) and
275 // use that display
276 var display = 'block';
277 jQuery(this).find('.control').each(function()
278 {
279 if (!jQuery(this).hasClass('.sales-only') && !jQuery(this).hasClass('.lettings-only') && !jQuery(this).hasClass('.residential-only') && !jQuery(this).hasClass('.commercial-only') && jQuery(this).css('display') != 'none')
280 {
281 display = jQuery(this).css('display');
282 }
283 });
284
285 if (selectedDepartment == 'residential-sales')
286 {
287 jQuery(this).find('.sales-only').css('display', display);
288 jQuery(this).find('.residential-only').css('display', display);
289 }
290 else if (selectedDepartment == 'residential-lettings')
291 {
292 jQuery(this).find('.lettings-only').css('display', display);
293 jQuery(this).find('.residential-only').css('display', display);
294 }
295 else if (selectedDepartment == 'commercial')
296 {
297 jQuery(this).find('.commercial-only').css('display', display);
298 }
299 }
300 });
301 }
302 }