| 1 |
"use strict"; |
| 2 |
jQuery(function($) { |
| 3 |
|
| 4 |
var loader = new ImageLoader(wpcomment_vars.loader); |
| 5 |
// define your 'onreadystatechange' |
| 6 |
loader.loadEvent = function(url, imageAsDom) { |
| 7 |
|
| 8 |
$("#wpcomment-pre-loading").hide(); |
| 9 |
$(".wpcomment-admin-wrap").show(); |
| 10 |
} |
| 11 |
loader.load(); |
| 12 |
|
| 13 |
/********************************* |
| 14 |
* PPOM Form Design JS * |
| 15 |
**********************************/ |
| 16 |
|
| 17 |
|
| 18 |
/*------------------------------------------------------- |
| 19 |
|
| 20 |
------ Its Include Following Function ----- |
| 21 |
|
| 22 |
1- Submit PPOM Form Fields |
| 23 |
2- Hide And Show Import & Export & Product Meta blocks |
| 24 |
3- Get Last Field Index |
| 25 |
4- Show And Hide Visibility Role Field |
| 26 |
5- Remove Unsaved Fields |
| 27 |
6- Check And Uncheck All Fields |
| 28 |
7- Remove Check Fields |
| 29 |
8- On Fields Options Handle Add Option Last |
| 30 |
9- Edit Existing Fields |
| 31 |
10- Add New Fields |
| 32 |
11- Update Existing Fields |
| 33 |
12- Clone New Fields |
| 34 |
13- Clone Existing Fields |
| 35 |
14- Saving WP Comment Settings |
| 36 |
15- Open Product Modal In Existing Meta File (removed) |
| 37 |
16- Handle Fields Tabs |
| 38 |
17- Handle Media Images Of Following Inputs Types |
| 39 |
18- Add Fields Conditions |
| 40 |
19- Add Fields Options |
| 41 |
20- Auto Generate Option IDs |
| 42 |
21- Create Field data_name By Thier Title |
| 43 |
22- Fields Sortable |
| 44 |
23- Fields Option Sortable |
| 45 |
24- Fields Dataname Must Be Required |
| 46 |
25- Fields Add Option Index Controle Funtion |
| 47 |
26- Fields Add Condition Index Controle Function |
| 48 |
27- Get All Fields Title On Condition Element Value After Click On Condition Tab |
| 49 |
28- validate API WooCommerce Product |
| 50 |
------------------------------------------------------------*/ |
| 51 |
|
| 52 |
|
| 53 |
/** |
| 54 |
PPOM Model |
| 55 |
**/ |
| 56 |
var append_overly_model = ("<div class='wpcomment-modal-overlay wpcomment-js-modal-close'></div>"); |
| 57 |
|
| 58 |
$(document).on('click', '[data-modal-id]', function(e) { |
| 59 |
e.preventDefault(); |
| 60 |
$("body").append(append_overly_model); |
| 61 |
var modalBox = $(this).attr('data-modal-id'); |
| 62 |
$('#' + modalBox).fadeIn(); |
| 63 |
}); |
| 64 |
|
| 65 |
wpcomment_close_popup(); |
| 66 |
|
| 67 |
function wpcomment_close_popup() { |
| 68 |
|
| 69 |
$(".wpcomment-js-modal-close, .wpcomment-modal-overlay").click(function(e) { |
| 70 |
|
| 71 |
var target = $(e.target); |
| 72 |
if (target.hasClass("wpcomment-modal-overlay")) { |
| 73 |
return false; |
| 74 |
} |
| 75 |
$(".wpcomment-modal-box, .wpcomment-modal-overlay").fadeOut('fast', function() { |
| 76 |
$(".wpcomment-modal-overlay").remove(); |
| 77 |
}); |
| 78 |
|
| 79 |
}); |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
$('.wpcomment-color-picker-init').wpColorPicker(); |
| 84 |
|
| 85 |
|
| 86 |
/** |
| 87 |
1- Submit PPOM Form Fields |
| 88 |
**/ |
| 89 |
$(".wpcomment-save-fields-meta").submit(function(e) { |
| 90 |
e.preventDefault(); |
| 91 |
|
| 92 |
jQuery(".wpcomment-meta-save-notice").html('<img src="' + wpcomment_vars.loader + '">').show(); |
| 93 |
|
| 94 |
$('.wpcomment-unsave-data').remove(); |
| 95 |
|
| 96 |
var data = $(this).serialize(); |
| 97 |
|
| 98 |
$.post(ajaxurl, data, function(resp) { |
| 99 |
|
| 100 |
const bg_color = resp.status == 'success' ? '#4e694859' : '#ee8b94'; |
| 101 |
jQuery(".wpcomment-meta-save-notice").html(resp.message).css({ 'background-color': bg_color, 'padding': '8px', 'border-left': '5px solid #008c00' }); |
| 102 |
if (resp.status == 'success') { |
| 103 |
if (resp.redirect_to != '') { |
| 104 |
window.location = resp.redirect_to; |
| 105 |
} |
| 106 |
else { |
| 107 |
window.location.reload(true); |
| 108 |
} |
| 109 |
} |
| 110 |
}, 'json'); |
| 111 |
|
| 112 |
}); |
| 113 |
|
| 114 |
|
| 115 |
/** |
| 116 |
2- Hide And Show Import & Export & Product Meta blocks |
| 117 |
**/ |
| 118 |
$('.wpcomment-import-export-btn').on('click', function(event) { |
| 119 |
event.preventDefault(); |
| 120 |
$('.wpcomment-more-plugins-block').hide(); |
| 121 |
$(".wpcomment-import-export-block").show(); |
| 122 |
$(".wpcomment-product-meta-block").hide(); |
| 123 |
}); |
| 124 |
|
| 125 |
$('.wpcomment-cancle-import-export-btn').on('click', function(event) { |
| 126 |
event.preventDefault(); |
| 127 |
$('.wpcomment-more-plugins-block').show(); |
| 128 |
$(".wpcomment-import-export-block").hide(); |
| 129 |
$(".wpcomment-product-meta-block").show(); |
| 130 |
}); |
| 131 |
|
| 132 |
|
| 133 |
/** |
| 134 |
3- Get Last Field Index |
| 135 |
**/ |
| 136 |
var field_no = $('#field_index').val(); |
| 137 |
|
| 138 |
|
| 139 |
/** |
| 140 |
4- Show And Hide Visibility Role Field |
| 141 |
**/ |
| 142 |
$('.wpcomment-slider').find('[data-meta-id="visibility_role"]').removeClass('wpcomment_handle_fields_tab').hide(); |
| 143 |
$('.wpcomment_save_fields_model .wpcomment-slider').each(function(i, div) { |
| 144 |
var visibility_value = $(div).find('[data-meta-id="visibility"] select').val(); |
| 145 |
if (visibility_value == 'roles') { |
| 146 |
$(div).find('[data-meta-id="visibility_role"]').show(); |
| 147 |
} |
| 148 |
}); |
| 149 |
$(document).on('change', '[data-meta-id="visibility"] select', function(e) { |
| 150 |
e.preventDefault(); |
| 151 |
|
| 152 |
var div = $(this).closest('.wpcomment-slider'); |
| 153 |
var visibility_value = $(this).val(); |
| 154 |
console.log(visibility_value); |
| 155 |
if (visibility_value == 'roles') { |
| 156 |
div.find('[data-meta-id="visibility_role"]').show(); |
| 157 |
} |
| 158 |
else { |
| 159 |
div.find('[data-meta-id="visibility_role"]').hide(); |
| 160 |
} |
| 161 |
}); |
| 162 |
|
| 163 |
|
| 164 |
/** |
| 165 |
5- Remove Unsaved Fields |
| 166 |
**/ |
| 167 |
$(document).on('click', '.wpcomment-close-fields', function(event) { |
| 168 |
event.preventDefault(); |
| 169 |
|
| 170 |
$(this).closest('.wpcomment-slider').addClass('wpcomment-unsave-data'); |
| 171 |
}); |
| 172 |
|
| 173 |
|
| 174 |
/** |
| 175 |
6- Check And Uncheck All Fields |
| 176 |
**/ |
| 177 |
$('.wpcomment-main-field-wrapper').on('change', '.onoffswitch-checkbox', function(event) { |
| 178 |
var div = $(this).closest('div'); |
| 179 |
if ($(this).prop('checked')) { |
| 180 |
div.find('input[type="hidden"]').val('on'); |
| 181 |
} |
| 182 |
else { |
| 183 |
div.find('input[type="hidden"]').val('off'); |
| 184 |
} |
| 185 |
}); |
| 186 |
|
| 187 |
$('.wpcomment-main-field-wrapper').on('click', '.wpcomment-check-all-field input', function(event) { |
| 188 |
if ($(this).prop('checked')) { |
| 189 |
$('.wpcomment_field_table .wpcomment-checkboxe-style input[type="checkbox"]').prop('checked', true); |
| 190 |
} |
| 191 |
else { |
| 192 |
$('.wpcomment_field_table .wpcomment-checkboxe-style input[type="checkbox"]').prop('checked', false); |
| 193 |
} |
| 194 |
}); |
| 195 |
$('.wpcomment-main-field-wrapper').on('change', '.wpcomment_field_table tbody .wpcomment-checkboxe-style input[type="checkbox"]', function(event) { |
| 196 |
if ($('.wpcomment_field_table tbody .wpcomment-checkboxe-style input[type="checkbox"]:checked').length == $('.wpcomment_field_table tbody .wpcomment-checkboxe-style input[type="checkbox"]').length) { |
| 197 |
$('.wpcomment-check-all-field input').prop('checked', true); |
| 198 |
} |
| 199 |
else { |
| 200 |
$('.wpcomment-check-all-field input').prop('checked', false); |
| 201 |
} |
| 202 |
}); |
| 203 |
|
| 204 |
|
| 205 |
/** |
| 206 |
7- Remove Check Fields |
| 207 |
**/ |
| 208 |
$('.wpcomment-main-field-wrapper').on('click', '.wpcomment_remove_field', function(e) { |
| 209 |
e.preventDefault(); |
| 210 |
|
| 211 |
var check_field = $('.wpcomment-check-one-field input[type="checkbox"]:checked'); |
| 212 |
|
| 213 |
if (check_field.length > 0) { |
| 214 |
swal({ |
| 215 |
title: "Are you sure?", |
| 216 |
type: "warning", |
| 217 |
showCancelButton: true, |
| 218 |
confirmButtonColor: "#DD6B55 ", |
| 219 |
cancelButtonColor: "#DD6B55", |
| 220 |
confirmButtonText: "Yes", |
| 221 |
cancelButtonText: "No", |
| 222 |
closeOnConfirm: true |
| 223 |
}, function(isConfirm) { |
| 224 |
if (!isConfirm) return; |
| 225 |
|
| 226 |
$('.wpcomment_field_table').find('.wpcomment-check-one-field input').each(function(i, meta_field) { |
| 227 |
|
| 228 |
if (this.checked) { |
| 229 |
var field_id = $(meta_field).val(); |
| 230 |
console.log(field_id) |
| 231 |
$(meta_field).parent().parent().parent('.row_no_' + field_id + '').remove(); |
| 232 |
} |
| 233 |
$('.wpcomment_save_fields_model').find('#wpcomment_field_model_' + field_id + '').remove(); |
| 234 |
}); |
| 235 |
}); |
| 236 |
} |
| 237 |
else { |
| 238 |
swal("Please at least check one field!", "", "error"); |
| 239 |
} |
| 240 |
}); |
| 241 |
|
| 242 |
|
| 243 |
/** |
| 244 |
8- On Fields Options Handle Add Option Last |
| 245 |
**/ |
| 246 |
$('.webcontact-rules').each(function(i, meta_field) { |
| 247 |
|
| 248 |
var selector_btn = $(this).closest('.wpcomment-slider'); |
| 249 |
selector_btn.find('.wpcomment-add-rule').not(':last').removeClass('wpcomment-add-rule').addClass('wpcomment-remove-rule') |
| 250 |
.removeClass('btn-success').addClass('btn-danger') |
| 251 |
.html('<i class="fa fa-minus" aria-hidden="true"></i>'); |
| 252 |
|
| 253 |
}); |
| 254 |
// $('.data-options').each(function(i, meta_field){ |
| 255 |
|
| 256 |
// var selector_btn = $(this).closest('.wpcomment-slider'); |
| 257 |
// selector_btn.find('.wpcomment-add-option').not(':last').removeClass('wpcomment-add-option').addClass('wpcomment-remove-option') |
| 258 |
// .removeClass('btn-success').addClass('btn-danger') |
| 259 |
// .html('<i class="fa fa-minus" aria-hidden="true"></i>'); |
| 260 |
|
| 261 |
// }); |
| 262 |
|
| 263 |
|
| 264 |
/** |
| 265 |
9- Edit Existing Fields |
| 266 |
**/ |
| 267 |
$(document).on('click', '.wpcomment-edit-field', function(event) { |
| 268 |
event.preventDefault(); |
| 269 |
|
| 270 |
var the_id = $(this).attr('id'); |
| 271 |
$('#wpcomment_field_model_' + the_id + '').find('.wpcomment-close-checker').removeClass('wpcomment-close-fields'); |
| 272 |
}); |
| 273 |
|
| 274 |
|
| 275 |
/** |
| 276 |
10- Add New Fields |
| 277 |
**/ |
| 278 |
$(document).on('click', '.wpcomment-add-field', function(event) { |
| 279 |
event.preventDefault(); |
| 280 |
|
| 281 |
var $this = $(this); |
| 282 |
var ui = wpcomment_required_data_name($this); |
| 283 |
if (ui == false) { |
| 284 |
return; |
| 285 |
} |
| 286 |
|
| 287 |
var copy_model_id = $(this).attr('data-copy-model-id'); |
| 288 |
var id = $(this).attr('data-field-index'); |
| 289 |
id = Number(id); |
| 290 |
console.log(id); |
| 291 |
|
| 292 |
var field_title = $('#wpcomment_field_model_' + id + '').find('.wpcomment-modal-body .wpcomment-fields-actions').attr('data-table-id'); |
| 293 |
var data_name = $('#wpcomment_field_model_' + id + '').find('[data-meta-id="data_name"] input').val(); |
| 294 |
var title = $('#wpcomment_field_model_' + id + '').find('[data-meta-id="title"] input').val(); |
| 295 |
var placeholder = $('#wpcomment_field_model_' + id + '').find('[data-meta-id="placeholder"] input').val(); |
| 296 |
var required = $('#wpcomment_field_model_' + id + '').find('[data-meta-id="required"] input').prop('checked'); |
| 297 |
var type = $(this).attr('data-field-type'); |
| 298 |
|
| 299 |
console.log(field_title); |
| 300 |
|
| 301 |
if (required == true) { |
| 302 |
var _ok = 'Yes'; |
| 303 |
} |
| 304 |
else { |
| 305 |
_ok = 'No'; |
| 306 |
} |
| 307 |
if (placeholder == null) { |
| 308 |
placeholder = '-'; |
| 309 |
} |
| 310 |
|
| 311 |
var html = '<tr class="row_no_' + id + '" id="wpcomment_sort_id_' + id + '">'; |
| 312 |
html += '<td class="wpcomment-sortable-handle"><i class="fa fa-arrows" aria-hidden="true"></i></td>'; |
| 313 |
html += '<td class="wpcomment-check-one-field wpcomment-checkboxe-style">'; |
| 314 |
html += '<label>'; |
| 315 |
html += '<input type="checkbox" value="' + id + '">'; |
| 316 |
html += '<span></span>'; |
| 317 |
html += '</label>'; |
| 318 |
html += '</td>'; |
| 319 |
|
| 320 |
html += '<td>'; |
| 321 |
html += '<div class="onoffswitch">'; |
| 322 |
html += '<input checked type="checkbox" name="wpcomment[' + id + '][status]" class="onoffswitch-checkbox" id="wpcomment-onoffswitch-' + id + '" tabindex="0">'; |
| 323 |
html += '<label class="onoffswitch-label" for="wpcomment-onoffswitch-' + id + '">'; |
| 324 |
html += '<span class="onoffswitch-inner"></span>'; |
| 325 |
html += '<span class="onoffswitch-switch"></span>'; |
| 326 |
html += '</label>'; |
| 327 |
html += '</div>'; |
| 328 |
html += '</td>'; |
| 329 |
|
| 330 |
// html += '<td class="wpcomment-check-one-field"><input type="checkbox" value="'+id+'"></td>'; |
| 331 |
html += '<td class="wpcomment_meta_field_id">' + data_name + '</td>'; |
| 332 |
html += '<td class="wpcomment_meta_field_type">' + type + '</td>'; |
| 333 |
html += '<td class="wpcomment_meta_field_title">' + title + '</td>'; |
| 334 |
html += '<td class="wpcomment_meta_field_plchlder">' + placeholder + '</td>'; |
| 335 |
html += '<td class="wpcomment_meta_field_req">' + _ok + '</td>'; |
| 336 |
html += '<td>'; |
| 337 |
html += '<button class="wpcomment_copy_field btn" id="' + id + '" data-field-type="' + field_title + '" style="margin-right: 4px;"><i class="fa fa-clone" aria-hidden="true"></i></button>'; |
| 338 |
html += '<button class="wpcomment-edit-field btn" id="' + id + '" data-modal-id="wpcomment_field_model_' + id + '"><i class="fa fa-pencil" aria-hidden="true"></i></button>'; |
| 339 |
html += '</td>'; |
| 340 |
html += '</tr>'; |
| 341 |
|
| 342 |
// console.log(copy_model_id); |
| 343 |
if (copy_model_id != '' && copy_model_id != undefined) { |
| 344 |
$(html).find('.wpcomment_field_table tbody').end().insertAfter('#wpcomment_sort_id_' + copy_model_id + ''); |
| 345 |
} |
| 346 |
else { |
| 347 |
$(html).appendTo('.wpcomment_field_table tbody'); |
| 348 |
} |
| 349 |
|
| 350 |
$(".wpcomment-modal-box, .wpcomment-modal-overlay").fadeOut('fast', function() { |
| 351 |
$(".wpcomment-modal-overlay").remove(); |
| 352 |
}); |
| 353 |
|
| 354 |
$(this).removeClass('wpcomment-add-field').addClass('wpcomment-update-field'); |
| 355 |
$(this).html('Update Field'); |
| 356 |
|
| 357 |
}); |
| 358 |
|
| 359 |
|
| 360 |
/** |
| 361 |
11- Update Existing Fields |
| 362 |
**/ |
| 363 |
$(document).on('click', '.wpcomment-update-field', function(event) { |
| 364 |
event.preventDefault(); |
| 365 |
|
| 366 |
var $this = $(this); |
| 367 |
var ui = wpcomment_required_data_name($this); |
| 368 |
|
| 369 |
if (ui == false) { |
| 370 |
return; |
| 371 |
} |
| 372 |
|
| 373 |
var id = $(this).attr('data-field-index'); |
| 374 |
id = Number(id); |
| 375 |
|
| 376 |
var data_name = $('#wpcomment_field_model_' + id + '').find('[data-meta-id="data_name"] input').val(); |
| 377 |
var title = $('#wpcomment_field_model_' + id + '').find('[data-meta-id="title"] input').val(); |
| 378 |
var placeholder = $('#wpcomment_field_model_' + id + '').find('[data-meta-id="placeholder"] input').val(); |
| 379 |
var required = $('#wpcomment_field_model_' + id + '').find('[data-meta-id="required"] input').prop('checked'); |
| 380 |
var type = $(this).attr('data-field-type'); |
| 381 |
|
| 382 |
if (required == true) { |
| 383 |
var _ok = 'Yes'; |
| 384 |
} |
| 385 |
else { |
| 386 |
_ok = 'No'; |
| 387 |
} |
| 388 |
|
| 389 |
var row = $('.wpcomment_field_table tbody').find('.row_no_' + id); |
| 390 |
|
| 391 |
row.find(".wpcomment_meta_field_title").html(title); |
| 392 |
row.find(".wpcomment_meta_field_id").html(data_name); |
| 393 |
row.find(".wpcomment_meta_field_type").html(type); |
| 394 |
row.find(".wpcomment_meta_field_plchlder").html(placeholder); |
| 395 |
row.find(".wpcomment_meta_field_req").html(_ok); |
| 396 |
|
| 397 |
$(".wpcomment-modal-box, .wpcomment-modal-overlay").fadeOut('fast', function() { |
| 398 |
$(".wpcomment-modal-overlay").remove(); |
| 399 |
}); |
| 400 |
}); |
| 401 |
|
| 402 |
|
| 403 |
/** |
| 404 |
12- Clone New Fields |
| 405 |
**/ |
| 406 |
var option_index = 0; |
| 407 |
$(document).on('click', '.wpcomment_select_field', function(event) { |
| 408 |
event.preventDefault(); |
| 409 |
|
| 410 |
$('#wpcomment_fields_model_id').find('.wpcomment-js-modal-close').trigger('click'); |
| 411 |
|
| 412 |
var field_type = $(this).data('field-type'); |
| 413 |
var clone_new_field = $(".wpcomment-field-" + field_type + ":last").clone(); |
| 414 |
|
| 415 |
// field attr name apply on all fields meta with wpcomment-meta-field class |
| 416 |
clone_new_field.find('.wpcomment-meta-field').each(function(i, meta_field) { |
| 417 |
var field_name = 'wpcomment[' + field_no + '][' + $(meta_field).attr('data-metatype') + ']'; |
| 418 |
$(meta_field).attr('name', field_name); |
| 419 |
}); |
| 420 |
|
| 421 |
// fields options sortable |
| 422 |
clone_new_field.find(".wpcomment-options-sortable").sortable(); |
| 423 |
|
| 424 |
// add fields index in data-field-no |
| 425 |
clone_new_field.find(".wpcomment-fields-actions").attr('data-field-no', field_no); |
| 426 |
|
| 427 |
// fields conditions handle name attr |
| 428 |
clone_new_field.find('.wpcomment-condition-visible-bound').each(function(i, meta_field) { |
| 429 |
var field_name = 'wpcomment[' + field_no + '][conditions][' + $(meta_field).attr('data-metatype') + ']'; |
| 430 |
$(meta_field).attr('name', field_name); |
| 431 |
}); |
| 432 |
|
| 433 |
clone_new_field.find('.wpcomment-fields-actions [data-meta-id="visibility_role"]').hide(); |
| 434 |
|
| 435 |
var field_model_id = 'wpcomment_field_model_' + field_no + ''; |
| 436 |
|
| 437 |
clone_new_field.find('.wpcomment_save_fields_model').end().appendTo('.wpcomment_save_fields_model').attr('id', field_model_id); |
| 438 |
clone_new_field.find('.wpcomment-field-checker').attr('data-field-index', field_no); |
| 439 |
clone_new_field.find('.wpcomment-field-checker').addClass('wpcomment-add-fields-js-action'); |
| 440 |
|
| 441 |
// var color_picker_input = clone_new_field.find('.wpcomment-color-picker-init').clone(); |
| 442 |
// clone_new_field.find('.wpcomment-color-picker-cloner').html(color_picker_input); |
| 443 |
// clone_new_field.find('.wpcomment-color-picker-init').wpColorPicker(); |
| 444 |
// $('.wpcomment-color-picker-init').wpColorPicker(); |
| 445 |
// $('.wpcomment-color-picker-init').wpColorPicker(); |
| 446 |
|
| 447 |
// $('.wpcomment-color-picker-init').wpColorPicker('destroy'); |
| 448 |
|
| 449 |
|
| 450 |
clone_new_field.addClass('wpcomment_sort_id_' + field_no + ''); |
| 451 |
var field_index = field_no; |
| 452 |
|
| 453 |
// handle multiple options |
| 454 |
var wpcomment_option_type = ''; |
| 455 |
var option_selector = clone_new_field.find('.wpcomment-option-keys'); |
| 456 |
var option_controller = clone_new_field.find('.wpcomment-fields-option'); |
| 457 |
var add_cond_selector = clone_new_field.find('.wpcomment-conditional-keys'); |
| 458 |
|
| 459 |
// for address addon |
| 460 |
var address_selector = clone_new_field.find('.wpcomment-checkout-field'); |
| 461 |
var address_table_id = clone_new_field.find('.wpcomment_address_table'); |
| 462 |
wpcomment_create_address_index(address_selector, field_index, address_table_id); |
| 463 |
|
| 464 |
var wpcolor_selector = clone_new_field.find('.wpcomment-color-picker-cloner'); |
| 465 |
wpcomment_wp_color_handler(wpcolor_selector, field_index, option_index); |
| 466 |
|
| 467 |
wpcomment_create_option_index(option_selector, field_index, option_index, wpcomment_option_type); |
| 468 |
wpcomment_option_controller(option_controller, field_index, option_index, wpcomment_option_type); |
| 469 |
wpcomment_add_condition_set_index(add_cond_selector, field_index, field_type, option_index); |
| 470 |
|
| 471 |
// popup fields on model |
| 472 |
wpcomment_close_popup(); |
| 473 |
$('#wpcomment_field_model_' + field_no + '').fadeIn(); |
| 474 |
|
| 475 |
field_no++; |
| 476 |
}); |
| 477 |
|
| 478 |
|
| 479 |
/** |
| 480 |
13- Clone Existing Fields |
| 481 |
**/ |
| 482 |
var copy_no = 0; |
| 483 |
$('.wpcomment-main-field-wrapper').on('click', '.wpcomment_copy_field', function(e) { |
| 484 |
e.preventDefault(); |
| 485 |
|
| 486 |
var model_id_no = $(this).attr('id'); |
| 487 |
|
| 488 |
var field_type = $(this).data('field-type'); |
| 489 |
// console.log(model_id_no); |
| 490 |
|
| 491 |
var clone_new_field = $('.wpcomment_save_fields_model #wpcomment_field_model_' + model_id_no + '').clone(true); |
| 492 |
// clone_new_field.find('.wpcomment_save_fields_model').end().appendTo('.wpcomment_save_fields_model').attr('id','wpcomment_field_model_'+field_no+''); |
| 493 |
clone_new_field.find('.wpcomment_save_fields_model').end().insertAfter('#wpcomment_field_model_' + model_id_no + '').attr('id', 'wpcomment_field_model_' + field_no + ''); |
| 494 |
clone_new_field.find('.wpcomment-add-fields-js-action').attr('data-field-index', field_no); |
| 495 |
clone_new_field.find('.wpcomment-close-fields').attr('data-field-index', field_no); |
| 496 |
clone_new_field.find('.wpcomment-js-modal-close').addClass('wpcomment-close-fields'); |
| 497 |
clone_new_field.find('.wpcomment-add-fields-js-action').removeClass('wpcomment-update-field'); |
| 498 |
clone_new_field.find('.wpcomment-add-fields-js-action').attr('data-copy-model-id', model_id_no); |
| 499 |
clone_new_field.find('.wpcomment-add-fields-js-action').addClass('wpcomment-add-field'); |
| 500 |
clone_new_field.find('.wpcomment-add-fields-js-action').addClass('wpcomment-insertafter-field'); |
| 501 |
clone_new_field.find('.wpcomment-add-fields-js-action').html('Add Field'); |
| 502 |
clone_new_field.removeClass('wpcomment_sort_id_' + model_id_no + ''); |
| 503 |
clone_new_field.addClass('wpcomment_sort_id_' + field_no + ''); |
| 504 |
|
| 505 |
// field attr name apply on all fields meta with wpcomment-meta-field class |
| 506 |
clone_new_field.find('.wpcomment-meta-field').each(function(i, meta_field) { |
| 507 |
var field_name = 'wpcomment[' + field_no + '][' + $(meta_field).attr('data-metatype') + ']'; |
| 508 |
$(meta_field).attr('name', field_name); |
| 509 |
}); |
| 510 |
|
| 511 |
// fields options sortable |
| 512 |
clone_new_field.find(".wpcomment-options-sortable").sortable(); |
| 513 |
|
| 514 |
// add fields index in data-field-no |
| 515 |
clone_new_field.find(".wpcomment-fields-actions").attr('data-field-no', field_no); |
| 516 |
|
| 517 |
// fields conditions handle name attr |
| 518 |
clone_new_field.find('.wpcomment-condition-visible-bound').each(function(i, meta_field) { |
| 519 |
var field_name = 'wpcomment[' + field_no + '][conditions][' + $(meta_field).attr('data-metatype') + ']'; |
| 520 |
$(meta_field).attr('name', field_name); |
| 521 |
}); |
| 522 |
|
| 523 |
clone_new_field.find('.wpcomment-fields-actions [data-meta-id="visibility_role"]').hide(); |
| 524 |
|
| 525 |
|
| 526 |
var field_index = field_no; |
| 527 |
|
| 528 |
// handle multiple options |
| 529 |
var wpcomment_option_type = 'wpcomment_copy_option'; |
| 530 |
var option_selector = clone_new_field.find('.wpcomment-option-keys'); |
| 531 |
var add_cond_selector = clone_new_field.find('.wpcomment-conditional-keys'); |
| 532 |
var eventcalendar_selector = clone_new_field.find('.wpcomment-eventcalendar-field'); |
| 533 |
var image_option_selector = clone_new_field.find('[data-table-id="image"] .data-options, [data-table-id="imageselect"] .data-options'); |
| 534 |
|
| 535 |
// reset option to one |
| 536 |
// clone_new_field.find('[data-table-id="image"] .data-options').remove(); |
| 537 |
clone_new_field.find('[data-table-id="audio"] .pre-upload-box li').remove(); |
| 538 |
// clone_new_field.find('[data-table-id="imageselect"] .pre-upload-box li').remove(); |
| 539 |
// clone_new_field.find('.data-options').not(':last').remove(); |
| 540 |
clone_new_field.find('.webcontact-rules').not(':last').remove(); |
| 541 |
|
| 542 |
// set existing conditions meta |
| 543 |
$(clone_new_field).find('select[data-metatype="elements"]').each(function(i, condition_element) { |
| 544 |
|
| 545 |
var existing_value1 = $(condition_element).attr("data-existingvalue"); |
| 546 |
if ($.trim(existing_value1) !== '') { |
| 547 |
jQuery(condition_element).val(existing_value1); |
| 548 |
} |
| 549 |
}); |
| 550 |
$(clone_new_field).find('select[data-metatype="element_values"]').each(function(i, condition_element) { |
| 551 |
|
| 552 |
var div = $(this).closest('.webcontact-rules'); |
| 553 |
var existing_value1 = $(condition_element).attr("data-existingvalue"); |
| 554 |
|
| 555 |
if ($.trim(existing_value1) !== '') { |
| 556 |
jQuery(condition_element).val(existing_value1); |
| 557 |
} |
| 558 |
}); |
| 559 |
|
| 560 |
var wpcolor_selector = clone_new_field.find('.wpcomment-color-picker-cloner'); |
| 561 |
wpcomment_wp_color_handler(wpcolor_selector, field_index, option_index); |
| 562 |
|
| 563 |
wpcomment_create_option_index(option_selector, field_index, option_index, wpcomment_option_type); |
| 564 |
var option_controller = clone_new_field.find('.wpcomment-fields-option'); |
| 565 |
|
| 566 |
wpcomment_option_controller(option_controller, field_index, option_index, wpcomment_option_type); |
| 567 |
wpcomment_add_condition_set_index(add_cond_selector, field_index, field_type, option_index); |
| 568 |
|
| 569 |
// for eventcalendar changing index |
| 570 |
wpcomment_eventcalendar_set_index(eventcalendar_selector, field_index); |
| 571 |
|
| 572 |
// set index for all images fields |
| 573 |
image_option_selector.find('input').each(function(img_index, img_meta) { |
| 574 |
|
| 575 |
var opt_in = $(img_meta).attr('data-opt-index'); |
| 576 |
var field_name = 'wpcomment[' + field_index + '][images][' + opt_in + '][' + $(img_meta).attr('data-metatype') + ']'; |
| 577 |
$(img_meta).attr('name', field_name); |
| 578 |
}); |
| 579 |
|
| 580 |
// popup fields on model |
| 581 |
$("body").append(append_overly_model); |
| 582 |
wpcomment_close_popup(); |
| 583 |
$('#wpcomment_field_model_' + field_no + '').fadeIn(); |
| 584 |
|
| 585 |
field_no++; |
| 586 |
}); |
| 587 |
|
| 588 |
|
| 589 |
/** |
| 590 |
14- Saving WP Comment Settings |
| 591 |
**/ |
| 592 |
$(".wpcomment-settings-form").on('submit', function(ev) { |
| 593 |
|
| 594 |
ev.preventDefault(); |
| 595 |
var data = $(this).serialize(); |
| 596 |
|
| 597 |
// return; |
| 598 |
$.post(ajaxurl, data, function(resp) { |
| 599 |
|
| 600 |
alert(resp.message); |
| 601 |
|
| 602 |
}, 'json'); |
| 603 |
}); |
| 604 |
|
| 605 |
|
| 606 |
/** |
| 607 |
16- Handle Fields Tabs |
| 608 |
**/ |
| 609 |
$('.wpcomment-control-all-fields-tabs').hide(); |
| 610 |
$('.wpcomment_handle_fields_tab').show(); |
| 611 |
$(document).on('click', '.wpcomment-tabs-label', function() { |
| 612 |
|
| 613 |
var id = $(this).attr('id'); |
| 614 |
var selectedTab = $(this).parent(); |
| 615 |
var fields_wrap = selectedTab.parent(); |
| 616 |
selectedTab.find('.wpcomment-tabs-label').removeClass('wpcomment-active-tab'); |
| 617 |
$(this).addClass('wpcomment-active-tab'); |
| 618 |
var content_box = fields_wrap.find('.wpcomment-control-all-fields-tabs'); |
| 619 |
content_box.hide(); |
| 620 |
fields_wrap.find('.wpcomment_handle_' + id).fadeIn(200); |
| 621 |
}); |
| 622 |
|
| 623 |
|
| 624 |
/** |
| 625 |
17- Handle Media Images Of Following Inputs Types |
| 626 |
17.1- Pre-Images Type |
| 627 |
17.2- Audio Type |
| 628 |
17.3- Imageselect Type |
| 629 |
**/ |
| 630 |
var $uploaded_image_container; |
| 631 |
$(document).on('click', '.wpcomment-pre-upload-image-btn', function(e) { |
| 632 |
e.preventDefault(); |
| 633 |
|
| 634 |
var meta_type = $(this).attr('data-metatype'); |
| 635 |
$uploaded_image_container = $(this).closest('div'); |
| 636 |
var image_append = $uploaded_image_container.find('ul'); |
| 637 |
var option_index = parseInt($uploaded_image_container.find('#wpcomment-meta-opt-index').val()); |
| 638 |
var main_wrapper = $(this).closest('.wpcomment-slider'); |
| 639 |
var field_index = main_wrapper.find('.wpcomment-fields-actions').attr('data-field-no'); |
| 640 |
var price_placeholder = 'Price (fix or %)'; |
| 641 |
|
| 642 |
var wp_media_type = 'image'; |
| 643 |
if (meta_type == 'audio') { |
| 644 |
wp_media_type = 'audio,video'; |
| 645 |
} |
| 646 |
|
| 647 |
var button = $(this), |
| 648 |
custom_uploader = wp.media({ |
| 649 |
title: 'Choose File', |
| 650 |
library: { |
| 651 |
type: wp_media_type |
| 652 |
}, |
| 653 |
button: { |
| 654 |
text: 'Upload' |
| 655 |
}, |
| 656 |
multiple: true |
| 657 |
}).on('select', function() { |
| 658 |
|
| 659 |
var attachments = custom_uploader.state().get('selection').toJSON(); |
| 660 |
|
| 661 |
attachments.map((meta, index) => { |
| 662 |
// console.log(meta); |
| 663 |
var fileurl = meta.url; |
| 664 |
var fileid = meta.id; |
| 665 |
var filename = meta.filename; |
| 666 |
var file_title = meta.title; |
| 667 |
|
| 668 |
|
| 669 |
var img_icon = '<img width="60" src="' + fileurl + '" style="width: 34px;">'; |
| 670 |
var url_field = '<input placeholder="url" type="text" name="wpcomment[' + field_index + '][' + meta_type + '][' + option_index + '][url]" class="form-control" data-opt-index="' + option_index + '" data-metatype="url">'; |
| 671 |
|
| 672 |
if (meta.type !== 'image') { |
| 673 |
var img_icon = '<img width="60" src="' + meta.icon + '" style="width: 34px;">'; |
| 674 |
url_field = ''; |
| 675 |
} |
| 676 |
|
| 677 |
var price_metatype = 'price'; |
| 678 |
var stock_metatype = 'stock'; |
| 679 |
var stock_placeholder = 'Stock'; |
| 680 |
|
| 681 |
// Set name key for imageselect addon |
| 682 |
if (meta_type == 'imageselect') { |
| 683 |
var class_name = 'data-options ui-sortable-handle'; |
| 684 |
var condidtion_attr = 'image_options'; |
| 685 |
meta_type = 'images'; |
| 686 |
price_placeholder = 'Price'; |
| 687 |
url_field = '<input placeholder="Description" type="text" name="wpcomment[' + field_index + '][' + meta_type + '][' + option_index + '][description]" class="form-control" data-opt-index="' + option_index + '" data-metatype="description">'; |
| 688 |
} |
| 689 |
else if (meta_type == 'images') { |
| 690 |
var class_name = 'data-options ui-sortable-handle'; |
| 691 |
var condidtion_attr = 'image_options'; |
| 692 |
} |
| 693 |
else if (meta_type == 'conditional_meta') { |
| 694 |
meta_type = 'images'; |
| 695 |
var class_name = 'data-options ui-sortable-handle'; |
| 696 |
var condidtion_attr = 'image_options'; |
| 697 |
price_placeholder = 'Meta IDs'; |
| 698 |
price_metatype = 'meta_id'; |
| 699 |
} |
| 700 |
else { |
| 701 |
var class_name = ''; |
| 702 |
var condidtion_attr = ''; |
| 703 |
} |
| 704 |
|
| 705 |
if (fileurl) { |
| 706 |
var image_box = ''; |
| 707 |
image_box += '<li class="' + class_name + '" data-condition-type="' + condidtion_attr + '">'; |
| 708 |
image_box += '<span class="dashicons dashicons-move" style="margin-bottom: 7px;margin-top: 2px;"></span>'; |
| 709 |
image_box += '<span class="wpcomment-uploader-img-title"></span>'; |
| 710 |
image_box += '<div style="display: flex;">'; |
| 711 |
image_box += '<div class="wpcomment-uploader-img-center">'; |
| 712 |
image_box += img_icon; |
| 713 |
image_box += '</div>'; |
| 714 |
image_box += '<input type="hidden" name="wpcomment[' + field_index + '][' + meta_type + '][' + option_index + '][link]" value="' + fileurl + '" data-opt-index="' + option_index + '" data-metatype="link">'; |
| 715 |
image_box += '<input type="hidden" name="wpcomment[' + field_index + '][' + meta_type + '][' + option_index + '][id]" value="' + fileid + '" data-opt-index="' + option_index + '" data-metatype="id">'; |
| 716 |
image_box += '<input type="text" placeholder="Title" name="wpcomment[' + field_index + '][' + meta_type + '][' + option_index + '][title]" class="form-control wpcomment-image-option-title" data-opt-index="' + option_index + '" data-metatype="title" value="' + file_title + '">'; |
| 717 |
image_box += '<input class="form-control" type="text" placeholder="' + price_placeholder + '" name="wpcomment[' + field_index + '][' + meta_type + '][' + option_index + '][' + price_metatype + ']" class="form-control" data-opt-index="' + option_index + '" data-metatype="' + price_metatype + '">'; |
| 718 |
|
| 719 |
if (meta_type != 'audio') { |
| 720 |
image_box += '<input class="form-control" type="text" placeholder="' + stock_placeholder + '" name="wpcomment[' + field_index + '][' + meta_type + '][' + option_index + '][' + stock_metatype + ']" class="form-control" data-opt-index="' + option_index + '" data-metatype="' + stock_metatype + '">'; |
| 721 |
} |
| 722 |
|
| 723 |
image_box += url_field; |
| 724 |
image_box += '<button class="btn btn-danger wpcomment-pre-upload-delete" style="height: 35px;"><i class="fa fa-times" aria-hidden="true"></i></button>'; |
| 725 |
image_box += '</div>'; |
| 726 |
image_box += '</li>'; |
| 727 |
|
| 728 |
$(image_box).appendTo(image_append); |
| 729 |
|
| 730 |
option_index++; |
| 731 |
} |
| 732 |
|
| 733 |
}); |
| 734 |
|
| 735 |
$uploaded_image_container.find('#wpcomment-meta-opt-index').val(option_index); |
| 736 |
|
| 737 |
}).open(); |
| 738 |
}); |
| 739 |
|
| 740 |
var $uploaded_image_container; |
| 741 |
$(document).on('click', '.wpcomment-pre-upload-image-btnsd', function(e) { |
| 742 |
|
| 743 |
e.preventDefault(); |
| 744 |
var meta_type = $(this).attr('data-metatype'); |
| 745 |
$uploaded_image_container = $(this).closest('div'); |
| 746 |
var image_append = $uploaded_image_container.find('ul'); |
| 747 |
var option_index = parseInt($uploaded_image_container.find('#wpcomment-meta-opt-index').val()); |
| 748 |
$uploaded_image_container.find('#wpcomment-meta-opt-index').val(option_index + 1); |
| 749 |
var main_wrapper = $(this).closest('.wpcomment-slider'); |
| 750 |
var field_index = main_wrapper.find('.wpcomment-fields-actions').attr('data-field-no'); |
| 751 |
var price_placeholder = 'Price (fix or %)'; |
| 752 |
wp.media.editor.send.attachment = function(props, attachment) { |
| 753 |
// console.log(attachment); |
| 754 |
var existing_images; |
| 755 |
var fileurl = attachment.url; |
| 756 |
var fileid = attachment.id; |
| 757 |
var img_icon = '<img width="60" src="' + fileurl + '" style="width: 34px;">'; |
| 758 |
var url_field = '<input placeholder="url" type="text" name="wpcomment[' + field_index + '][' + meta_type + '][' + option_index + '][url]" class="form-control" data-opt-index="' + option_index + '" data-metatype="url">'; |
| 759 |
|
| 760 |
if (attachment.type !== 'image') { |
| 761 |
var img_icon = '<img width="60" src="' + attachment.icon + '" style="width: 34px;">'; |
| 762 |
url_field = ''; |
| 763 |
} |
| 764 |
|
| 765 |
var price_metatype = 'price'; |
| 766 |
var stock_metatype = 'stock'; |
| 767 |
var stock_placeholder = 'Stock'; |
| 768 |
|
| 769 |
// Set name key for imageselect addon |
| 770 |
if (meta_type == 'imageselect') { |
| 771 |
var class_name = 'data-options ui-sortable-handle'; |
| 772 |
var condidtion_attr = 'image_options'; |
| 773 |
meta_type = 'images'; |
| 774 |
price_placeholder = 'Price'; |
| 775 |
url_field = '<input placeholder="Description" type="text" name="wpcomment[' + field_index + '][' + meta_type + '][' + option_index + '][description]" class="form-control" data-opt-index="' + option_index + '" data-metatype="description">'; |
| 776 |
} |
| 777 |
else if (meta_type == 'images') { |
| 778 |
var class_name = 'data-options ui-sortable-handle'; |
| 779 |
var condidtion_attr = 'image_options'; |
| 780 |
} |
| 781 |
else if (meta_type == 'conditional_meta') { |
| 782 |
meta_type = 'images'; |
| 783 |
var class_name = 'data-options ui-sortable-handle'; |
| 784 |
var condidtion_attr = 'image_options'; |
| 785 |
price_placeholder = 'Meta IDs'; |
| 786 |
price_metatype = 'meta_id'; |
| 787 |
} |
| 788 |
else { |
| 789 |
var class_name = ''; |
| 790 |
var condidtion_attr = ''; |
| 791 |
} |
| 792 |
|
| 793 |
if (fileurl) { |
| 794 |
var image_box = ''; |
| 795 |
image_box += '<li class="' + class_name + '" data-condition-type="' + condidtion_attr + '">'; |
| 796 |
image_box += '<span class="dashicons dashicons-move" style="margin-bottom: 7px;margin-top: 2px;"></span>'; |
| 797 |
image_box += '<span class="wpcomment-uploader-img-title"></span>'; |
| 798 |
image_box += '<div style="display: flex;">'; |
| 799 |
image_box += '<div class="wpcomment-uploader-img-center">'; |
| 800 |
image_box += img_icon; |
| 801 |
image_box += '</div>'; |
| 802 |
image_box += '<input type="hidden" name="wpcomment[' + field_index + '][' + meta_type + '][' + option_index + '][link]" value="' + fileurl + '" data-opt-index="' + option_index + '" data-metatype="link">'; |
| 803 |
image_box += '<input type="hidden" name="wpcomment[' + field_index + '][' + meta_type + '][' + option_index + '][id]" value="' + fileid + '" data-opt-index="' + option_index + '" data-metatype="id">'; |
| 804 |
image_box += '<input type="text" placeholder="Title" name="wpcomment[' + field_index + '][' + meta_type + '][' + option_index + '][title]" class="form-control wpcomment-image-option-title" data-opt-index="' + option_index + '" data-metatype="title">'; |
| 805 |
image_box += '<input class="form-control" type="text" placeholder="' + price_placeholder + '" name="wpcomment[' + field_index + '][' + meta_type + '][' + option_index + '][' + price_metatype + ']" class="form-control" data-opt-index="' + option_index + '" data-metatype="' + price_metatype + '">'; |
| 806 |
image_box += '<input class="form-control" type="text" placeholder="' + stock_placeholder + '" name="wpcomment[' + field_index + '][' + meta_type + '][' + option_index + '][' + stock_metatype + ']" class="form-control" data-opt-index="' + option_index + '" data-metatype="' + stock_metatype + '">'; |
| 807 |
image_box += url_field; |
| 808 |
image_box += '<button class="btn btn-danger wpcomment-pre-upload-delete" style="height: 35px;"><i class="fa fa-times" aria-hidden="true"></i></button>'; |
| 809 |
image_box += '</div>'; |
| 810 |
image_box += '</li>'; |
| 811 |
|
| 812 |
$(image_box).appendTo(image_append); |
| 813 |
} |
| 814 |
} |
| 815 |
|
| 816 |
wp.media.editor.open(this); |
| 817 |
|
| 818 |
return false; |
| 819 |
}); |
| 820 |
$(document).on('click', '.wpcomment-pre-upload-delete', function(e) { |
| 821 |
|
| 822 |
e.preventDefault(); |
| 823 |
$(this).closest('li').remove(); |
| 824 |
}); |
| 825 |
|
| 826 |
|
| 827 |
/** |
| 828 |
18- Add Fields Conditions |
| 829 |
**/ |
| 830 |
$(document).on('click', '.wpcomment-add-rule', function(e) { |
| 831 |
|
| 832 |
e.preventDefault(); |
| 833 |
|
| 834 |
var div = $(this).closest('.wpcomment-slider'); |
| 835 |
var option_index = parseInt(div.find('.wpcomment-condition-last-id').val()); |
| 836 |
div.find('.wpcomment-condition-last-id').val(option_index + 1); |
| 837 |
|
| 838 |
var field_index = div.find('.wpcomment-fields-actions').attr('data-field-no'); |
| 839 |
var condition_clone = $('.webcontact-rules:last').clone(); |
| 840 |
|
| 841 |
var append_item = div.find('.wpcomment-condition-clone-js'); |
| 842 |
condition_clone.find(append_item).end().appendTo(append_item); |
| 843 |
|
| 844 |
var field_type = ''; |
| 845 |
var add_cond_selector = condition_clone.find('.wpcomment-conditional-keys'); |
| 846 |
wpcomment_add_condition_set_index(add_cond_selector, field_index, field_type, option_index); |
| 847 |
|
| 848 |
$('.wpcomment-slider').find('.webcontact-rules:not(:last) .wpcomment-add-rule') |
| 849 |
.removeClass('wpcomment-add-rule').addClass('wpcomment-remove-rule') |
| 850 |
.removeClass('btn-success').addClass('btn-danger') |
| 851 |
.html('<i class="fa fa-minus" aria-hidden="true"></i>'); |
| 852 |
}).on('click', '.wpcomment-remove-rule', function(e) { |
| 853 |
|
| 854 |
$(this).parents('.webcontact-rules:first').remove(); |
| 855 |
e.preventDefault(); |
| 856 |
return false; |
| 857 |
}); |
| 858 |
|
| 859 |
|
| 860 |
/** |
| 861 |
19- Add Fields Options |
| 862 |
**/ |
| 863 |
$(document).on('click', '.wpcomment-add-option', function(e) { |
| 864 |
|
| 865 |
e.preventDefault(); |
| 866 |
|
| 867 |
var main_wrapper = $(this).closest('.wpcomment-slider'); |
| 868 |
var wpcomment_option_type = 'wpcomment_new_option'; |
| 869 |
|
| 870 |
var li = $(this).closest('li'); |
| 871 |
var ul = li.closest('ul'); |
| 872 |
var clone_item = li.clone(); |
| 873 |
|
| 874 |
clone_item.find(ul).end().appendTo(ul); |
| 875 |
|
| 876 |
var option_index = parseInt(ul.find('#wpcomment-meta-opt-index').val()); |
| 877 |
ul.find('#wpcomment-meta-opt-index').val(option_index + 1); |
| 878 |
console.log(option_index); |
| 879 |
|
| 880 |
var field_index = main_wrapper.find('.wpcomment-fields-actions').attr('data-field-no'); |
| 881 |
var option_selector = clone_item.find('.wpcomment-option-keys'); |
| 882 |
var option_controller = clone_item.find('.wpcomment-fields-option'); |
| 883 |
|
| 884 |
wpcomment_option_controller(option_controller, field_index, option_index, wpcomment_option_type); |
| 885 |
wpcomment_create_option_index(option_selector, field_index, option_index, wpcomment_option_type); |
| 886 |
|
| 887 |
// $('.wpcomment-slider').find('.data-options:not(:last) .wpcomment-add-option') |
| 888 |
// .removeClass('wpcomment-add-option').addClass('wpcomment-remove-option') |
| 889 |
// .removeClass('btn-success').addClass('btn-danger') |
| 890 |
// .html('<i class="fa fa-minus" aria-hidden="true"></i>'); |
| 891 |
}).on('click', '.wpcomment-remove-option', function(e) { |
| 892 |
|
| 893 |
var selector_btn = $(this).closest('.wpcomment-slider'); |
| 894 |
var option_num = selector_btn.find('.data-options').length; |
| 895 |
|
| 896 |
if (option_num > 1) { |
| 897 |
$(this).parents('.data-options:first').remove(); |
| 898 |
} |
| 899 |
else { |
| 900 |
alert('Cannot Remove More Option'); |
| 901 |
} |
| 902 |
|
| 903 |
e.preventDefault(); |
| 904 |
return false; |
| 905 |
}); |
| 906 |
|
| 907 |
|
| 908 |
/** |
| 909 |
20- Auto Generate Option IDs |
| 910 |
**/ |
| 911 |
$(document).on('keyup', '.option-title', function() { |
| 912 |
|
| 913 |
var closes_id = $(this).closest('li').find('.option-id'); |
| 914 |
var option_id = $(this).val().replace(/[^A-Z0-9]/ig, "_"); |
| 915 |
option_id = option_id.toLowerCase(); |
| 916 |
$(closes_id).val(option_id); |
| 917 |
}); |
| 918 |
|
| 919 |
|
| 920 |
/** |
| 921 |
21- Create Field data_name By Thier Title |
| 922 |
**/ |
| 923 |
$(document).on('keyup', '[data-meta-id="title"] input[type="text"]', function() { |
| 924 |
|
| 925 |
var $this = $(this); |
| 926 |
var field_id = $this.val().toLowerCase().replace(/[^A-Za-z\d]/g, '_'); |
| 927 |
var selector = $this.closest('.wpcomment-slider'); |
| 928 |
|
| 929 |
var wp_field = selector.find('.wpcomment-fields-actions').attr('data-table-id'); |
| 930 |
if (wp_field == 'shipping_fields' || wp_field == 'billing_fields') { |
| 931 |
return; |
| 932 |
} |
| 933 |
selector.find('[data-meta-id="data_name"] input[type="text"]').val(field_id); |
| 934 |
}); |
| 935 |
|
| 936 |
|
| 937 |
/** |
| 938 |
22- Fields Sortable |
| 939 |
**/ |
| 940 |
function insertAt(parent, element, index, dir) { |
| 941 |
var el = parent.children().eq(index); |
| 942 |
|
| 943 |
element[dir == 'top' ? 'insertBefore' : 'insertAfter'](el); |
| 944 |
} |
| 945 |
$(".wpcomment_field_table tbody").sortable({ |
| 946 |
stop: function(evt, ui) { |
| 947 |
|
| 948 |
let parent = $('.wpcomment_save_fields_model'), |
| 949 |
el = parent.find('.' + ui.item.attr('id')), |
| 950 |
dir = 'top'; |
| 951 |
if (ui.offset.top > ui.originalPosition.top) { |
| 952 |
dir = 'bottom'; |
| 953 |
} |
| 954 |
insertAt(parent, el, ui.item.index(), dir); |
| 955 |
} |
| 956 |
}); |
| 957 |
|
| 958 |
|
| 959 |
/** |
| 960 |
23- Fields Option Sortable |
| 961 |
**/ |
| 962 |
$(".wpcomment-options-sortable").sortable(); |
| 963 |
|
| 964 |
$("ul.wpcomment-options-container").sortable({ |
| 965 |
revert: true |
| 966 |
}); |
| 967 |
|
| 968 |
|
| 969 |
/** |
| 970 |
24- Fields Dataname Must Be Required |
| 971 |
**/ |
| 972 |
function wpcomment_required_data_name($this) { |
| 973 |
var selector = $this.closest('.wpcomment-slider'); |
| 974 |
var data_name = selector.find('[data-meta-id="data_name"] input[type="text"]').val(); |
| 975 |
if (data_name == '') { |
| 976 |
var msg = 'Data Name must be required'; |
| 977 |
var is_ok = false; |
| 978 |
} |
| 979 |
else { |
| 980 |
msg = ''; |
| 981 |
is_ok = true; |
| 982 |
} |
| 983 |
selector.find('.wpcomment-req-field-id').html(msg); |
| 984 |
return is_ok; |
| 985 |
} |
| 986 |
|
| 987 |
|
| 988 |
/** |
| 989 |
WP Color Picker Controller |
| 990 |
**/ |
| 991 |
function wpcomment_wp_color_handler(wpcolor_selector, field_index, option_index) { |
| 992 |
|
| 993 |
wpcolor_selector.each(function(i, meta_field) { |
| 994 |
var color_picker_input = $(meta_field).find('.wpcomment-color-picker-init').clone(); |
| 995 |
$(meta_field).html(color_picker_input); |
| 996 |
color_picker_input.wpColorPicker(); |
| 997 |
}); |
| 998 |
} |
| 999 |
|
| 1000 |
|
| 1001 |
/** |
| 1002 |
25- Fields Add Option Index Controle Funtion |
| 1003 |
**/ |
| 1004 |
function wpcomment_create_option_index(option_selector, field_index, option_index, wpcomment_option_type) { |
| 1005 |
|
| 1006 |
option_selector.each(function(i, meta_field) { |
| 1007 |
|
| 1008 |
|
| 1009 |
if (wpcomment_option_type == 'wpcomment_copy_option') { |
| 1010 |
var opt_in = $(meta_field).attr('data-opt-index'); |
| 1011 |
if (opt_in !== undefined) { |
| 1012 |
option_index = opt_in; |
| 1013 |
} |
| 1014 |
} |
| 1015 |
$(meta_field).attr('data-opt-index', option_index); |
| 1016 |
|
| 1017 |
|
| 1018 |
var field_name = 'wpcomment[' + field_index + '][options][' + option_index + '][' + $(meta_field).attr('data-metatype') + ']'; |
| 1019 |
$(meta_field).attr('name', field_name); |
| 1020 |
}); |
| 1021 |
} |
| 1022 |
|
| 1023 |
|
| 1024 |
function wpcomment_option_controller(option_selector, field_index, option_index, wpcomment_option_type) { |
| 1025 |
|
| 1026 |
option_selector.each(function(i, meta_field) { |
| 1027 |
|
| 1028 |
console.log(wpcomment_option_type); |
| 1029 |
if (wpcomment_option_type == 'wpcomment_copy_option') { |
| 1030 |
var opt_in = $(meta_field).attr('data-opt-index'); |
| 1031 |
if (opt_in !== undefined) { |
| 1032 |
option_index = opt_in; |
| 1033 |
} |
| 1034 |
} |
| 1035 |
$(meta_field).attr('data-opt-index', option_index); |
| 1036 |
|
| 1037 |
|
| 1038 |
var field_name = 'wpcomment[' + field_index + '][' + $(meta_field).attr('data-optiontype') + '][' + option_index + '][' + $(meta_field).attr('data-metatype') + ']'; |
| 1039 |
$(meta_field).attr('name', field_name); |
| 1040 |
}); |
| 1041 |
} |
| 1042 |
|
| 1043 |
|
| 1044 |
/** |
| 1045 |
26- Fields Add Condition Index Controle Function |
| 1046 |
**/ |
| 1047 |
function wpcomment_add_condition_set_index(add_c_selector, opt_field_no, field_type, opt_no) { |
| 1048 |
add_c_selector.each(function(i, meta_field) { |
| 1049 |
// var field_name = 'wpcomment['+field_no+']['+$(meta_field).attr('data-metatype')+']'; |
| 1050 |
var field_name = 'wpcomment[' + opt_field_no + '][conditions][rules][' + opt_no + '][' + $(meta_field).attr('data-metatype') + ']'; |
| 1051 |
$(meta_field).attr('name', field_name); |
| 1052 |
}); |
| 1053 |
} |
| 1054 |
|
| 1055 |
// address addon |
| 1056 |
function wpcomment_create_address_index(address_selector, field_index, address_table_id) { |
| 1057 |
address_selector.each(function(i, meta_field) { |
| 1058 |
var field_id = $(meta_field).attr('data-fieldtype'); |
| 1059 |
var core_field_type = $(address_table_id).attr('data-addresstype'); |
| 1060 |
var field_name = 'wpcomment[' + field_index + '][' + core_field_type + '][' + field_id + '][' + $(meta_field).attr('data-metatype') + ']'; |
| 1061 |
$(meta_field).attr('name', field_name); |
| 1062 |
}); |
| 1063 |
} |
| 1064 |
|
| 1065 |
|
| 1066 |
// eventcalendar inputs changing |
| 1067 |
function wpcomment_eventcalendar_set_index(add_c_selector, opt_field_no) { |
| 1068 |
|
| 1069 |
add_c_selector.each(function(i, meta_field) { |
| 1070 |
|
| 1071 |
var date = $(meta_field).attr('data-date'); |
| 1072 |
var field_name = 'wpcomment[' + opt_field_no + '][calendar][' + date + '][' + $(meta_field).attr('data-metatype') + ']'; |
| 1073 |
$(meta_field).attr('name', field_name); |
| 1074 |
}); |
| 1075 |
} |
| 1076 |
|
| 1077 |
|
| 1078 |
/** |
| 1079 |
27- Get All Fields Title On Condition Element Value After Click On Condition Tab |
| 1080 |
**/ |
| 1081 |
// populate_conditional_elements(); |
| 1082 |
|
| 1083 |
$(document).on('change', 'select[data-metatype="elements"]', function(e) { |
| 1084 |
e.preventDefault(); |
| 1085 |
|
| 1086 |
var element_name = $(this).val(); |
| 1087 |
var div = $(this).closest('.wpcomment-slider'); |
| 1088 |
|
| 1089 |
var selected_rule_box = $(this).closest('.webcontact-rules'); |
| 1090 |
var element_value_box = selected_rule_box.find('select[data-metatype="element_values"]'); |
| 1091 |
|
| 1092 |
$(".wpcomment-slider").each(function(i, item) { |
| 1093 |
|
| 1094 |
var data_name = $(item).find('input[data-metatype="data_name"]').val(); |
| 1095 |
|
| 1096 |
if (data_name == element_name) { |
| 1097 |
|
| 1098 |
// resetting |
| 1099 |
jQuery(element_value_box).html(''); |
| 1100 |
|
| 1101 |
$(item).find('.data-options').each(function(i, condition_val) { |
| 1102 |
|
| 1103 |
var condition_type = $(condition_val).attr('data-condition-type'); |
| 1104 |
if (condition_type == 'simple_options') { |
| 1105 |
var con_val = $(condition_val).find('input[data-metatype="option"]').val(); |
| 1106 |
} |
| 1107 |
else if (condition_type == 'image_options') { |
| 1108 |
var con_val = $(condition_val).find('.wpcomment-image-option-title').val(); |
| 1109 |
} |
| 1110 |
|
| 1111 |
if ($.trim(con_val) !== '') { |
| 1112 |
|
| 1113 |
|
| 1114 |
var val_id = $.trim(con_val); |
| 1115 |
|
| 1116 |
var $html = ''; |
| 1117 |
$html += '<option value="' + |
| 1118 |
wpcomment_escape_html(val_id) + '">' + |
| 1119 |
con_val + |
| 1120 |
'</option>'; |
| 1121 |
|
| 1122 |
$($html).appendTo(element_value_box); |
| 1123 |
} |
| 1124 |
}); |
| 1125 |
} |
| 1126 |
}); |
| 1127 |
}); |
| 1128 |
|
| 1129 |
$(document).on('change', '[data-meta-id="conditions"] select[data-metatype="element_values"]', function(e) { |
| 1130 |
e.preventDefault(); |
| 1131 |
|
| 1132 |
var element_values = $(this).val(); |
| 1133 |
$(this).attr('data-existingvalue', element_values); |
| 1134 |
}); |
| 1135 |
|
| 1136 |
$(document).on('click', '.wpcomment-condition-tab-js', function(e) { |
| 1137 |
e.preventDefault(); |
| 1138 |
|
| 1139 |
var div = $(this).closest('.wpcomment-slider'); |
| 1140 |
var elements = div.find('select[data-metatype="elements"]'); |
| 1141 |
|
| 1142 |
elements.each(function(i, item) { |
| 1143 |
|
| 1144 |
var conditional_elements = item.value; |
| 1145 |
var exiting_meta = $(item).attr('data-existingvalue', conditional_elements); |
| 1146 |
}); |
| 1147 |
|
| 1148 |
populate_conditional_elements(elements); |
| 1149 |
|
| 1150 |
}); |
| 1151 |
|
| 1152 |
function populate_conditional_elements(elements) { |
| 1153 |
|
| 1154 |
// resetting |
| 1155 |
jQuery('select[data-metatype="elements"]').html(''); |
| 1156 |
|
| 1157 |
jQuery(".wpcomment-slider").each(function(i, item) { |
| 1158 |
|
| 1159 |
var conditional_elements = jQuery(item).find( |
| 1160 |
'input[data-metatype="title"]').val(); |
| 1161 |
var conditional_elements_value = jQuery(item).find( |
| 1162 |
'input[data-metatype="data_name"]').val(); |
| 1163 |
|
| 1164 |
if ($.trim(conditional_elements_value) !== '') { |
| 1165 |
|
| 1166 |
var $html = ''; |
| 1167 |
$html += '<option value="' + |
| 1168 |
conditional_elements_value + '">' + |
| 1169 |
conditional_elements + |
| 1170 |
'</option>'; |
| 1171 |
|
| 1172 |
$($html).appendTo('select[data-metatype="elements"]'); |
| 1173 |
} |
| 1174 |
|
| 1175 |
}); |
| 1176 |
|
| 1177 |
// setting the existing conditional elements |
| 1178 |
$(".wpcomment-slider").each(function(i, item) { |
| 1179 |
|
| 1180 |
$(item).find('select[data-metatype="elements"]').each(function(i, condition_element) { |
| 1181 |
|
| 1182 |
var existing_value1 = $(condition_element).attr("data-existingvalue"); |
| 1183 |
|
| 1184 |
if ($.trim(existing_value1) !== '') { |
| 1185 |
jQuery(condition_element).val(existing_value1); |
| 1186 |
} |
| 1187 |
|
| 1188 |
}); |
| 1189 |
}); |
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
// setting the existing conditional elements values |
| 1194 |
$(".wpcomment-slider").each(function(i, item) { |
| 1195 |
|
| 1196 |
$(item).find('select[data-metatype="element_values"]').each(function(i, condition_element) { |
| 1197 |
|
| 1198 |
var div = $(this).closest('.webcontact-rules'); |
| 1199 |
var existing_value1 = $(condition_element).attr("data-existingvalue"); |
| 1200 |
|
| 1201 |
div.find('select[data-metatype="elements"]').trigger('change'); |
| 1202 |
if ($.trim(existing_value1) !== '') { |
| 1203 |
jQuery(condition_element).val(existing_value1); |
| 1204 |
} |
| 1205 |
}); |
| 1206 |
}); |
| 1207 |
|
| 1208 |
} |
| 1209 |
|
| 1210 |
|
| 1211 |
/** |
| 1212 |
28- validate API WooCommerce Product |
| 1213 |
**/ |
| 1214 |
function validate_api_WPC(form) { |
| 1215 |
|
| 1216 |
jQuery(form).find("#nm-sending-api").html( |
| 1217 |
'<img src="' + nm_personalizedproduct_vars.doing + '">'); |
| 1218 |
|
| 1219 |
var data = jQuery(form).serialize(); |
| 1220 |
data = data + '&action=nm_personalizedproduct_validate_api'; |
| 1221 |
|
| 1222 |
jQuery.post(ajaxurl, data, function(resp) { |
| 1223 |
|
| 1224 |
//console.log(resp); |
| 1225 |
jQuery(form).find("#nm-sending-api").html(resp.message); |
| 1226 |
if (resp.status == 'success') { |
| 1227 |
window.location.reload(true); |
| 1228 |
} |
| 1229 |
}, 'json'); |
| 1230 |
|
| 1231 |
|
| 1232 |
return false; |
| 1233 |
} |
| 1234 |
|
| 1235 |
function wpcomment_escape_html(unsafe) { |
| 1236 |
return unsafe |
| 1237 |
.replace(/&/g, "&") |
| 1238 |
.replace(/</g, "<") |
| 1239 |
.replace(/>/g, ">") |
| 1240 |
.replace(/"/g, """) |
| 1241 |
.replace(/'/g, "'"); |
| 1242 |
} |
| 1243 |
|
| 1244 |
/** |
| 1245 |
* 29 Toggling settings and fields |
| 1246 |
* */ |
| 1247 |
// by defualt wpcomment-settings-wrapper is hidden |
| 1248 |
$('.wpcomment-settings-wrapper').hide(); |
| 1249 |
$(document).on('click', 'button.wpcomment_settings_toggle', function(e) { |
| 1250 |
e.preventDefault(); |
| 1251 |
$('.wpcomment-main-field-wrapper').toggle(); |
| 1252 |
$('.wpcomment-settings-wrapper').toggle(); |
| 1253 |
|
| 1254 |
}) |
| 1255 |
}); |
| 1256 |
|