PluginProbe
Property Hive / trunk
Property Hive vtrunk
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 1.4.62 All 260 releases
propertyhive / assets / js / admin / settings.js

settings.js in Property Hive trunk, at assets/js/admin/settings.js

549 lines 19.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var initial_save_changes_value = '';
2
3 jQuery( function($){
4
5 // sortable custom field tables
6
7 $('.ph_customfields.sortable-custom-field').each(function()
8 {
9 var taxonomy = $(this).data('taxonomy');
10
11 if ( taxonomy == '' )
12 {
13 return;
14 }
15
16 $(this).find('tbody').sortable({
17 axis: 'y',
18 update: function (event, ui)
19 {
20 var data = $(this).sortable('serialize') + '&'+ $.param({ 'action': 'propertyhive_save_term_order', 'taxonomy': taxonomy, 'security': propertyhive_admin_settings.ajax_nonce });
21
22 $.ajax({
23 data: data,
24 type: 'POST',
25 url: ajaxurl
26 });
27 }
28 });
29 });
30
31 //
32
33 initial_save_changes_value = (jQuery('p.submit button.button-primary').length > 0) ? jQuery('p.submit button.button-primary').text() : '';
34
35 $('a#add_department').click(function(e)
36 {
37 e.preventDefault();
38
39 var new_department_html = $('#active_department_template').html();
40
41 new_department_html = new_department_html.replace(/template/g, 'phnew-' + $('#propertyhive_new_custom_departments').val());
42
43 $('#active_departments').append(new_department_html);
44
45 var new_custom_departments = $('#propertyhive_custom_departments').val();
46 if ( new_custom_departments != '' )
47 {
48 new_custom_departments += ',';
49 }
50 new_custom_departments += 'phnew-' + $('#propertyhive_new_custom_departments').val();
51 $('#propertyhive_custom_departments').val( new_custom_departments );
52
53 $('#propertyhive_new_custom_departments').val( parseInt($('#propertyhive_new_custom_departments').val()) + 1 );
54 });
55
56 $(document).on('click', 'a.delete-department', function(e)
57 {
58 e.preventDefault();
59
60 var confirmBox = confirm('Are you sure you wish to delete this department?');
61
62 if (confirmBox)
63 {
64 var custom_department_key = $(this).attr('data-department');
65
66 $('#propertyhive_active_department_fieldset_' + custom_department_key).remove();
67
68 var new_custom_departments = '';
69 var existing_new_custom_departments = $('#propertyhive_custom_departments').val().split(",");
70 for ( var i in existing_new_custom_departments )
71 {
72 if ( existing_new_custom_departments[i] != custom_department_key )
73 {
74 if ( new_custom_departments != '' )
75 {
76 new_custom_departments += ',';
77 }
78 new_custom_departments += existing_new_custom_departments[i];
79 }
80 }
81 $('#propertyhive_custom_departments').val( new_custom_departments );
82 }
83 });
84
85 $('input.colorpick').wpColorPicker();
86
87 $('form').submit(function()
88 {
89 // Check for confirm removal checkbox
90 // and make sure it's ticked
91 if ( $('input[type=\'checkbox\'][name=\'confirm_removal\']').length > 0 )
92 {
93 if ( !$('input[type=\'checkbox\'][name=\'confirm_removal\']').is( ":checked" ) )
94 {
95 alert( propertyhive_admin_settings.confirm_not_selected_warning );
96 return false;
97 }
98 }
99
100 // Make sure a department has been ticked
101 if ( $('input[type=\'checkbox\'][name^=\'propertyhive_active_departments_\']').length > 0 )
102 {
103 var department_ticked = false;
104 $('input[type=\'checkbox\'][name^=\'propertyhive_active_departments_\']').each(function()
105 {
106 if ( $(this).is( ":checked" ) )
107 {
108 department_ticked = true;
109 }
110 });
111
112 if ( !department_ticked )
113 {
114 alert( propertyhive_admin_settings.no_departments_selected_warning );
115 return false;
116 }
117
118 // Make sure primary department is in the list of ticked departments
119 var selected_primary_department = $("input[type=\'radio\'][name=\'propertyhive_primary_department\']:checked").val();
120 selected_primary_department = selected_primary_department.replace("residential-", "");
121 if ( !$('input[type=\'checkbox\'][name=\'propertyhive_active_departments_' + selected_primary_department + '\']').is( ":checked" ) )
122 {
123 alert( propertyhive_admin_settings.primary_department_not_active_warning );
124 return false;
125 }
126 }
127
128 // Validate disabled modules
129 if ( $('input[type=\'checkbox\'][name^=\'propertyhive_module_disabled_\']').length > 0 )
130 {
131 if (
132 $('input[type=\'checkbox\'][name=\'propertyhive_module_disabled_contacts\']').is( ":checked" ) &&
133 (
134 !$('input[type=\'checkbox\'][name=\'propertyhive_module_disabled_viewings\']').is( ":checked" ) ||
135 !$('input[type=\'checkbox\'][name=\'propertyhive_module_disabled_offers_sales\']').is( ":checked" )
136 )
137 )
138 {
139 alert( 'The contacts module must be enabled in order to use the viewings, offers and sales modules' );
140 return false;
141 }
142 };
143
144 if ( $('select[name=\'propertyhive_default_country\']').length > 0 )
145 {
146 // Make sure default country is in list of selected countries
147 var selected_countries = $('select[name=\'propertyhive_countries[]\']').val();
148 if ( selected_countries == null )
149 {
150 alert( propertyhive_admin_settings.no_countries_selected );
151 return false;
152 }
153 var default_country = $('select[name=\'propertyhive_default_country\']').val();
154 var default_in_selected = false;
155 for ( var i in selected_countries )
156 {
157 if ( default_country == selected_countries[i] )
158 {
159 default_in_selected = true;
160 }
161 }
162 if ( !default_in_selected )
163 {
164 alert( propertyhive_admin_settings.default_country_not_in_selected );
165 return false;
166 }
167 }
168
169 // Disable submit button when form is being submitted to prevent double submissions
170 $('p.submit input[type=\'submit\']').attr('disabled', 'disabled');
171 });
172
173 $('a.batch-delete').click(function()
174 {
175 var term_ids = new Array;
176
177 $('input[name=\'term_id[]\']:checked').each(function()
178 {
179 term_ids.push( $(this).val() );
180 });
181
182 if ( term_ids.length > 0 )
183 {
184 window.location.href = propertyhive_admin_settings.admin_url + 'admin.php?page=ph-settings&tab=customfields&section=' + propertyhive_admin_settings.taxonomy_section + '-delete&id=' + term_ids.join("-");
185 }
186
187 return false;
188 });
189
190 $('.select_all').change(function()
191 {
192 if ( this.checked )
193 {
194 $('input[name=\'term_id[]\']').attr('checked', 'checked');
195
196 // If at least one has been checked, enable Delete Selected button
197 if ( $('input[name=\'term_id[]\']:checked').length > 0 )
198 {
199 $('a.batch-delete').attr('disabled', false);
200 }
201 }
202 else
203 {
204 $('input[name=\'term_id[]\']').removeAttr('checked');
205
206 // Disable Delete Selected button
207 $('a.batch-delete').attr('disabled', 'disabled');
208 }
209 });
210
211 $('input[name=\'term_id[]\']').change(function()
212 {
213 if ( $('input[name=\'term_id[]\']:checked').length > 0 )
214 {
215 $('a.batch-delete').attr('disabled', false);
216 }
217 else
218 {
219 $('a.batch-delete').attr('disabled', 'disabled');
220 }
221
222 // If we're unchecking a term, uncheck the Select All box
223 if ( !this.checked )
224 {
225 $('.select_all').removeAttr('checked');
226 }
227 });
228
229 jQuery('select[name=\'propertyhive_countries[]\']').change(function()
230 {
231 fill_search_form_currency_options();
232 });
233 fill_search_form_currency_options();
234
235 jQuery('input[name^=\'propertyhive_active_departments\']').change(function()
236 {
237 toggle_department_specific_options();
238 });
239 toggle_department_specific_options();
240
241 jQuery('[name=\'propertyhive_maps_provider\']').change(function()
242 {
243 ph_toggle_maps_provider_options();
244 });
245 ph_toggle_maps_provider_options();
246
247 jQuery('[name=\'propertyhive_geocoding_provider\']').change(function()
248 {
249 ph_toggle_geocoding_provider_options();
250 });
251 ph_toggle_geocoding_provider_options();
252
253 jQuery('[name=\'propertyhive_auto_incremental_reference_numbers\']').change(function()
254 {
255 ph_toggle_auto_incremental_reference_number_options();
256 });
257 ph_toggle_auto_incremental_reference_number_options();
258
259 jQuery('.pro-feature-settings .pro-filters ul li a').click(function(e)
260 {
261 e.preventDefault();
262
263 var data_filter = jQuery(this).data('filter');
264
265 jQuery('.pro-feature-settings .pro-filters ul li').removeClass('active');
266 jQuery(this).parent().addClass('active');
267
268 if ( data_filter == '' )
269 {
270 jQuery('.pro-feature-settings .pro-features ul li').hide();
271 jQuery('.pro-feature-settings .pro-features ul li').fadeIn('fast');
272 }
273 else
274 {
275 jQuery('.pro-feature-settings .pro-features ul li').hide();
276 jQuery('.pro-feature-settings .pro-features ul li.' + data_filter).fadeIn('fast');
277 }
278
279 ph_resize_pro_features_list();
280 });
281
282 if ( jQuery('.pro-feature-settings .pro-filters').length > 0 )
283 {
284 jQuery('.pro-feature-settings .pro-filters ul li.active a').trigger('click');
285 }
286
287 jQuery('.pro-feature-settings input[name=\'active_plugins[]\']').change(function()
288 {
289 var parent_el = jQuery(this);
290 var is_checked = parent_el.is(':checked');
291
292 var slug = parent_el.val();
293
294 jQuery(this).parent().next('.loading').show();
295 jQuery(this).parent().hide();
296
297 if ( is_checked )
298 {
299 // need to install/activate plugin
300 jQuery.ajax({
301 url : ajaxurl,
302 method: 'POST',
303 data : {
304 action: "propertyhive_activate_pro_feature",
305 slug : slug,
306 _ajax_nonce: propertyhive_admin_settings.ajax_nonce
307 },
308 dataType : "json",
309 success: function(response)
310 {
311 if ( response.success === true )
312 {
313 if ( typeof response.data !== 'undefined' && typeof response.data.activateUrl !== 'undefined' )
314 {
315 jQuery.ajax({
316 url : response.data.activateUrl,
317 method: 'GET',
318 data : {},
319 success: function(response)
320 {
321 window.location.href = propertyhive_admin_settings.features_settings_url + '&successmessage=1' + ( (jQuery('.pro-filters li.active a').data('filter') != '') ? '&profilter=' + jQuery('.pro-filters li.active a').data('filter') : '' );
322 }
323 });
324 }
325 else
326 {
327 window.location.href = propertyhive_admin_settings.features_settings_url + '&successmessage=1' + ( (jQuery('.pro-filters li.active a').data('filter') != '') ? '&profilter=' + jQuery('.pro-filters li.active a').data('filter') : '' );
328 }
329 }
330 else
331 {
332 parent_el.prop('checked', false);
333 parent_el.parent().next('.loading').hide();
334 parent_el.parent().show();
335 alert(response.data.errorMessage);
336 }
337 }
338 });
339 }
340 else
341 {
342 // need to deactivate plugin
343 jQuery.ajax({
344 url : ajaxurl,
345 method: 'POST',
346 data : {
347 action: "propertyhive_deactivate_pro_feature",
348 slug : slug,
349 _ajax_nonce: propertyhive_admin_settings.ajax_nonce
350 },
351 dataType : "json",
352 success: function(response)
353 {
354 if ( response.success === true )
355 {
356 window.location.href = propertyhive_admin_settings.features_settings_url + '&successmessage=2' + ( (jQuery('.pro-filters li.active a').data('filter') != '') ? '&profilter=' + jQuery('.pro-filters li.active a').data('filter') : '' );
357 }
358 else
359 {
360 parent_el.prop('checked', 'checked');
361 parent_el.parent().next('.loading').hide();
362 parent_el.parent().show();
363 alert(response.data.errorMessage);
364 }
365 }
366 });
367 }
368 });
369
370 if ( jQuery('[name=\'propertyhive_license_type\']').length > 0 )
371 {
372 ph_toggle_license_key_settings();
373
374 jQuery('[name=\'propertyhive_license_type\']').change(function()
375 {
376 ph_toggle_license_key_settings();
377 });
378 }
379
380 ph_resize_pro_features_list();
381 });
382
383 jQuery(window).on( "resize", function()
384 {
385 ph_resize_pro_features_list();
386 });
387
388 function ph_resize_pro_features_list()
389 {
390 if ( jQuery('.pro-features').length > 0 )
391 {
392 jQuery('.pro-features ul li .inner').css('height', 'auto');
393
394 var max_height = 0;
395 jQuery('.pro-features ul li .inner').each(function()
396 {
397 if ( jQuery(this).parent().css('display') != 'none' && jQuery(this).height() > max_height )
398 {
399 max_height = jQuery(this).height();
400 }
401 });
402
403 jQuery('.pro-features ul li .inner').css('height', max_height + 'px');
404 jQuery('.pro-features ul li').css('visibility', 'visible');
405 }
406 }
407
408 function ph_toggle_license_key_settings()
409 {
410 if ( jQuery('[name=\'propertyhive_license_type\']:checked').val() == 'old' )
411 {
412 jQuery('#row_pro_license_key_info').hide();
413 jQuery('#row_pro_license_key_display').hide();
414 jQuery('#row_propertyhive_pro_license_key').hide();
415 jQuery('#row_license_key_info').show();
416 jQuery('#row_propertyhive_license_key').show();
417 jQuery('p.submit button.button-primary').text(initial_save_changes_value);
418 }
419 else
420 {
421 jQuery('#row_pro_license_key_info').show();
422 jQuery('#row_propertyhive_pro_license_key').show();
423 jQuery('#row_pro_license_key_display').show();
424 jQuery('#row_license_key_info').hide();
425 jQuery('#row_propertyhive_license_key').hide();
426
427 if ( propertyhive_admin_settings.valid_pro_license_key )
428 {
429 jQuery('p.submit button.button-primary').text('Deactivate key');
430 }
431 else
432 {
433 jQuery('p.submit button.button-primary').text('Activate key');
434 }
435 }
436 }
437
438 function ph_toggle_maps_provider_options()
439 {
440 jQuery('#row_propertyhive_google_maps_api_key').hide();
441 jQuery('#row_propertyhive_mapbox_api_key').hide();
442
443 if ( jQuery('[name=\'propertyhive_maps_provider\']:checked').val() == 'mapbox' )
444 {
445 jQuery('#row_propertyhive_mapbox_api_key').show();
446 }
447 if ( jQuery('[name=\'propertyhive_maps_provider\']:checked').val() == '' )
448 {
449 jQuery('#row_propertyhive_google_maps_api_key').show();
450 }
451 }
452
453 function ph_toggle_geocoding_provider_options()
454 {
455 jQuery('#row_propertyhive_google_maps_geocoding_api_key').hide();
456 jQuery('#row_propertyhive_mapbox_geocoding_api_key').hide();
457 jQuery('#row_propertyhive_osm_html').hide();
458
459 if ( jQuery('[name=\'propertyhive_geocoding_provider\']:checked').val() == 'mapbox' )
460 {
461 jQuery('#row_propertyhive_mapbox_geocoding_api_key').show();
462 }
463 if ( jQuery('[name=\'propertyhive_geocoding_provider\']:checked').val() == 'osm' )
464 {
465 jQuery('#row_propertyhive_osm_html').show();
466 }
467 if ( jQuery('[name=\'propertyhive_geocoding_provider\']:checked').val() == '' )
468 {
469 jQuery('#row_propertyhive_google_maps_geocoding_api_key').show();
470 }
471 }
472
473 function ph_toggle_auto_incremental_reference_number_options()
474 {
475 if ( jQuery('[name=\'propertyhive_auto_incremental_reference_numbers\']').is(":checked") )
476 {
477 jQuery('#row_propertyhive_auto_incremental_next').show();
478 }
479 else
480 {
481 jQuery('#row_propertyhive_auto_incremental_next').hide();
482 }
483 }
484
485 function fill_search_form_currency_options()
486 {
487 var selected_countries = jQuery('select[name=\'propertyhive_countries[]\']').val();
488 var selected_currency = jQuery('#propertyhive_search_form_currency').val();
489
490 var new_currency_options = new Array();
491
492 for ( var i in selected_countries)
493 {
494 var country = countries[selected_countries[i]];
495
496 new_currency_options.push( country.currency_code );
497 }
498
499 jQuery('#propertyhive_search_form_currency').find('option').remove();
500 if ( new_currency_options.length > 0 )
501 {
502 new_currency_options = jQuery.unique( new_currency_options );
503
504 /*new_currency_options.sort(function(a, b) {
505 var a1 = a.new_currency_options, b1 = b.new_currency_options;
506 if(a1 == b1) return 0;
507 return a1 > b1 ? 1 : -1;
508 });*/
509
510 for ( var i in new_currency_options)
511 {
512 jQuery('#propertyhive_search_form_currency').append('<option value="' + new_currency_options[i] + '">' + new_currency_options[i] + '</option>');
513 }
514 jQuery('#propertyhive_search_form_currency').val(selected_currency);
515
516 if ( new_currency_options.length > 1 )
517 {
518 jQuery('#propertyhive_search_form_currency').parent().parent().show();
519 }
520 else
521 {
522 jQuery('#propertyhive_search_form_currency').parent().parent().hide();
523 }
524
525 if ( jQuery("#propertyhive_search_form_currency :selected").length == 0 )
526 {
527 jQuery("#propertyhive_search_form_currency").val( jQuery("#propertyhive_search_form_currency option:first").val() );
528
529 }
530 }
531 }
532
533 function toggle_department_specific_options()
534 {
535 jQuery('#row_propertyhive_lettings_fees').hide();
536 jQuery('#row_propertyhive_lettings_fees_commercial').hide();
537 jQuery('#row_propertyhive_lettings_fees_display_search_results').hide();
538
539 if (jQuery('#propertyhive_active_departments_lettings').prop('checked') == true)
540 {
541 jQuery('#row_propertyhive_lettings_fees').show();
542 jQuery('#row_propertyhive_lettings_fees_display_search_results').show();
543 }
544 if (jQuery('#propertyhive_active_departments_commercial').prop('checked') == true)
545 {
546 jQuery('#row_propertyhive_lettings_fees_commercial').show();
547 jQuery('#row_propertyhive_lettings_fees_display_search_results').show();
548 }
549 }