| 1 |
// @var yatra_admin_params |
| 2 |
|
| 3 |
(function ($) { |
| 4 |
var YatraTabs = { |
| 5 |
|
| 6 |
init: function () { |
| 7 |
this.initNewYatraTabs(); |
| 8 |
this.cacheDom(); |
| 9 |
this.setupAria(); |
| 10 |
this.bindEvents(); |
| 11 |
this.removeStyle(); |
| 12 |
}, |
| 13 |
initNewYatraTabs: function () { |
| 14 |
var parent = $('.yatra-admin--tabs'); |
| 15 |
parent.find('li').on('click', function () { |
| 16 |
$(this).closest('ul').find('li').removeClass('active'); |
| 17 |
$(this).addClass('active'); |
| 18 |
var tab_key = $(this).attr('data-tab'); |
| 19 |
var content = parent.next('.yatra-admin--tab-content'); |
| 20 |
content.find('.yatra-admin-tab--content-section').removeClass('active'); |
| 21 |
content.find('#' + tab_key).addClass('active'); |
| 22 |
}); |
| 23 |
}, |
| 24 |
|
| 25 |
|
| 26 |
cacheDom: function () { |
| 27 |
this.$el = $('.yatra-tabs'); |
| 28 |
this.$tabList = this.$el.find('ul.mb-tab-list'); |
| 29 |
this.$tab = this.$tabList.find('li'); |
| 30 |
this.$tabFirst = this.$tabList.find('li:first-child a'); |
| 31 |
this.$tabLink = this.$tabList.find('li>a'); |
| 32 |
|
| 33 |
this.$tabPanel = this.$el.find('section'); |
| 34 |
this.$tabPanelFirstContent = this.$el.find('section > *:first-child'); |
| 35 |
this.$tabPanelFirst = this.$el.find('section:first-child'); |
| 36 |
this.$tabPanelNotFirst = this.$el.find('section:not(:first-of-type)'); |
| 37 |
}, |
| 38 |
|
| 39 |
bindEvents: function () { |
| 40 |
this.$tabLink.on('click', function () { |
| 41 |
|
| 42 |
this.changeTab(); |
| 43 |
}.bind(this)); |
| 44 |
this.$tabLink.on('keydown', function () { |
| 45 |
this.changeTabKey(); |
| 46 |
}.bind(this)); |
| 47 |
}, |
| 48 |
|
| 49 |
changeTab: function () { |
| 50 |
var self = $(event.target); |
| 51 |
event.preventDefault(); |
| 52 |
this.removeTabFocus(); |
| 53 |
this.setSelectedTab(self); |
| 54 |
this.hideAllTabPanels(); |
| 55 |
this.setSelectedTabPanel(self); |
| 56 |
}, |
| 57 |
|
| 58 |
changeTabKey: function () { |
| 59 |
var self = $(event.target), |
| 60 |
$target = this.setKeyboardDirection(self, event.keyCode); |
| 61 |
|
| 62 |
if ($target.length) { |
| 63 |
this.removeTabFocus(self); |
| 64 |
this.setSelectedTab($target); |
| 65 |
} |
| 66 |
this.hideAllTabPanels(); |
| 67 |
this.setSelectedTabPanel($(document.activeElement)); |
| 68 |
}, |
| 69 |
|
| 70 |
hideAllTabPanels: function () { |
| 71 |
this.$tabPanel.attr('aria-hidden', 'true'); |
| 72 |
}, |
| 73 |
|
| 74 |
removeTabFocus: function (self) { |
| 75 |
var $this = self || $('[role="tab"]'); |
| 76 |
|
| 77 |
$this.attr({ |
| 78 |
'tabindex': '-1', |
| 79 |
'aria-selected': null |
| 80 |
}); |
| 81 |
}, |
| 82 |
|
| 83 |
selectFirstTab: function () { |
| 84 |
this.$tabFirst.attr({ |
| 85 |
'aria-selected': 'true', |
| 86 |
'tabindex': '0' |
| 87 |
}); |
| 88 |
}, |
| 89 |
|
| 90 |
setupAria: function () { |
| 91 |
this.$tabList.attr('role', 'tablist'); |
| 92 |
this.$tab.attr('role', 'presentation'); |
| 93 |
this.$tabLink.attr({ |
| 94 |
'role': 'tab', |
| 95 |
'tabindex': '-1' |
| 96 |
}); |
| 97 |
this.$tabLink.each(function () { |
| 98 |
var $this = $(this); |
| 99 |
|
| 100 |
$this.attr('aria-controls', $this.attr('href').substring(1)); |
| 101 |
}); |
| 102 |
this.$tabPanel.attr({ |
| 103 |
'role': 'tabpanel' |
| 104 |
}); |
| 105 |
this.$tabPanelFirstContent.attr({ |
| 106 |
'tabindex': '0' |
| 107 |
}); |
| 108 |
this.$tabPanelNotFirst.attr({ |
| 109 |
'aria-hidden': 'true' |
| 110 |
}); |
| 111 |
this.selectFirstTab(); |
| 112 |
}, |
| 113 |
|
| 114 |
setKeyboardDirection: function (self, keycode) { |
| 115 |
var $prev = self.parents('li').prev().children('[role="tab"]'), |
| 116 |
$next = self.parents('li').next().children('[role="tab"]'); |
| 117 |
|
| 118 |
switch (keycode) { |
| 119 |
case 37: |
| 120 |
return $prev; |
| 121 |
break; |
| 122 |
case 39: |
| 123 |
return $next; |
| 124 |
break; |
| 125 |
default: |
| 126 |
return false; |
| 127 |
break; |
| 128 |
} |
| 129 |
}, |
| 130 |
|
| 131 |
setSelectedTab: function (self) { |
| 132 |
self.attr({ |
| 133 |
'aria-selected': true, |
| 134 |
'tabindex': '0' |
| 135 |
}).focus(); |
| 136 |
}, |
| 137 |
|
| 138 |
setSelectedTabPanel: function (self) { |
| 139 |
this.$el.find('#' + self.attr('aria-controls')).attr('aria-hidden', null); |
| 140 |
}, |
| 141 |
removeStyle: function () { |
| 142 |
this.$el.find('.yatra-tab-section').removeAttr('style'); |
| 143 |
} |
| 144 |
|
| 145 |
}; |
| 146 |
|
| 147 |
|
| 148 |
var YatraAdmin = { |
| 149 |
|
| 150 |
init: function () { |
| 151 |
|
| 152 |
this.initElement(); |
| 153 |
this.initLib(); |
| 154 |
this.initGalleryBuilder(); |
| 155 |
this.groupPricing(); |
| 156 |
this.fixedDeparture(); |
| 157 |
this.initDateTimePicker(); |
| 158 |
}, |
| 159 |
initElement: function () { |
| 160 |
this.gallery_upload_frame = ''; |
| 161 |
|
| 162 |
}, initLib: function () { |
| 163 |
|
| 164 |
if (typeof "select2" !== 'undefined') { |
| 165 |
$('.yatra-select2').select2(); |
| 166 |
} |
| 167 |
}, |
| 168 |
initGalleryBuilder: function () { |
| 169 |
var uploadBtn = $('.mb-gallery-add'); |
| 170 |
var parent = uploadBtn.closest('.mb-admin-gallery'); |
| 171 |
var $this = this; |
| 172 |
uploadBtn.on('click', function (event) { |
| 173 |
event.preventDefault(); |
| 174 |
$this.initMediaUploader(uploadBtn, parent); |
| 175 |
}); |
| 176 |
$('body').on('click', 'ul.mb-selected-gallery-list li a.remove', function (event) { |
| 177 |
event.preventDefault(); |
| 178 |
$this.removeGalleryItem($(this).closest('li'), parent); |
| 179 |
|
| 180 |
}); |
| 181 |
}, |
| 182 |
initMediaUploader: function (uploadBtn, wrapper) { |
| 183 |
|
| 184 |
var $this = this; |
| 185 |
if (this.gallery_upload_frame) this.gallery_upload_frame.close(); |
| 186 |
|
| 187 |
this.gallery_upload_frame = wp.media.frames.file_frame = wp.media({ |
| 188 |
title: uploadBtn.data('uploader-title'), |
| 189 |
button: { |
| 190 |
text: uploadBtn.data('uploader-button-text'), |
| 191 |
}, |
| 192 |
multiple: true |
| 193 |
}); |
| 194 |
|
| 195 |
this.gallery_upload_frame.on('select', function () { |
| 196 |
var previous_selection_value = wrapper.find("input").val(); |
| 197 |
var previous_selection_array = previous_selection_value.split(","); |
| 198 |
if (previous_selection_array.length == 1 && previous_selection_array[0] == "") { |
| 199 |
previous_selection_array = []; |
| 200 |
} |
| 201 |
var selection = $this.gallery_upload_frame.state().get('selection'); |
| 202 |
var selected_list_node = wrapper.find('ul.mb-selected-gallery-list'); |
| 203 |
var selected_list_html = ''; |
| 204 |
selection.map(function (attachment_object, i) { |
| 205 |
var attachment = attachment_object.toJSON(); |
| 206 |
var attachment_id = attachment.id; |
| 207 |
var attachment_url = attachment.sizes.full.url; |
| 208 |
if ($.inArray(attachment_id, previous_selection_array) !== "-1") { |
| 209 |
previous_selection_array.push(attachment_id); |
| 210 |
selected_list_html += ('<li data-id="' + attachment_id + '"><a class="remove dashicons dashicons-trash"></a><img src="' + attachment_url + '"/></li>'); |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
}); |
| 215 |
wrapper.find("input").val(previous_selection_array.join()); |
| 216 |
selected_list_node.append(selected_list_html); |
| 217 |
}); |
| 218 |
|
| 219 |
|
| 220 |
this.gallery_upload_frame.open(); |
| 221 |
}, |
| 222 |
removeGalleryItem: function (gallery_item, wrapper) { |
| 223 |
var gallery_id = gallery_item.attr('data-id'); |
| 224 |
var list_ids = wrapper.find("input").val(); |
| 225 |
|
| 226 |
var list_ids_array = list_ids.split(","); |
| 227 |
if (list_ids_array.length == 1 && list_ids_array[0] == "") { |
| 228 |
list_ids_array = []; |
| 229 |
} |
| 230 |
var index = list_ids_array.indexOf(gallery_id); |
| 231 |
|
| 232 |
if (index > -1) { |
| 233 |
list_ids_array.splice(index, 1); |
| 234 |
} |
| 235 |
gallery_item.remove(); |
| 236 |
wrapper.find("input").val(list_ids_array.join()); |
| 237 |
}, |
| 238 |
groupPricing: function () { |
| 239 |
var _that = this; |
| 240 |
var add_new = $('#yatra_add_new_pricing_option'); |
| 241 |
add_new.on('click', function () { |
| 242 |
var pricing_option_id = _that.uniqid(); |
| 243 |
var tpl = $('#yatra-group-pricing-tmpl').html(); |
| 244 |
tpl = _that._replaceAll(tpl, '{%pricing_option_id%}', pricing_option_id); |
| 245 |
$(this).closest('.yatra-field-wrap').before(tpl); |
| 246 |
|
| 247 |
}); |
| 248 |
$('body').on('click', '.yatra-pricing-group-wrap .pricing-delete', function () { |
| 249 |
|
| 250 |
var sure = confirm('Are you sure want to delete this group pricing? Pricing will be deleted only after publish.'); |
| 251 |
if (sure) { |
| 252 |
$(this).closest('.yatra-pricing-group-wrap-container').remove(); |
| 253 |
} |
| 254 |
}); |
| 255 |
}, |
| 256 |
uniqid: function () { |
| 257 |
return '_' + Math.random().toString(36).substr(2, 9); |
| 258 |
}, |
| 259 |
_replaceAll: function (str, toReplace, replaceWith) { |
| 260 |
return str ? str.split(toReplace).join(replaceWith) : ''; |
| 261 |
}, |
| 262 |
fixedDeparture: function () { |
| 263 |
$('#yatra_tour_meta_tour_fixed_departure').on('click', function () { |
| 264 |
|
| 265 |
if ($(this).prop('checked') == true) { |
| 266 |
$('div[data-wrap-id="yatra_tour_meta_tour_start_date"]').removeClass('yatra-hide'); |
| 267 |
$('div[data-wrap-id="yatra_tour_meta_tour_end_date"]').removeClass('yatra-hide'); |
| 268 |
|
| 269 |
$('div[data-wrap-id="yatra_tour_meta_tour_duration_days"]').addClass('yatra-hide'); |
| 270 |
$('div[data-wrap-id="yatra_tour_meta_tour_duration_nights"]').addClass('yatra-hide'); |
| 271 |
} else { |
| 272 |
$('div[data-wrap-id="yatra_tour_meta_tour_start_date"]').addClass('yatra-hide'); |
| 273 |
$('div[data-wrap-id="yatra_tour_meta_tour_end_date"]').addClass('yatra-hide'); |
| 274 |
|
| 275 |
$('div[data-wrap-id="yatra_tour_meta_tour_duration_days"]').removeClass('yatra-hide'); |
| 276 |
$('div[data-wrap-id="yatra_tour_meta_tour_duration_nights"]').removeClass('yatra-hide'); |
| 277 |
} |
| 278 |
}); |
| 279 |
|
| 280 |
}, |
| 281 |
initDateTimePicker: function () { |
| 282 |
|
| 283 |
if ($.fn.yatra_datepicker) { |
| 284 |
$('#yatra_tour_meta_tour_start_date').yatra_datepicker({ |
| 285 |
language: 'en', |
| 286 |
dateFormat: 'yyyy-mm-dd', |
| 287 |
minDate: new Date(), |
| 288 |
onSelect: function (dateStr) { |
| 289 |
newMinDate = null; |
| 290 |
newMaxDate = new Date(); |
| 291 |
if ('' !== dateStr) { |
| 292 |
// milliseconds = moment( dateStr, wp_travel_drag_drop_uploader.moment_date_format ).format( 'MM/DD/YYYY' ); |
| 293 |
milliseconds = moment(dateStr, 'YYYY-MM-DD'); |
| 294 |
new_date_min = new Date(milliseconds); |
| 295 |
newMinDate = new Date(new_date_min.setDate(new Date(new_date_min.getDate()))); |
| 296 |
|
| 297 |
} |
| 298 |
$('#yatra_tour_meta_tour_end_date').yatra_datepicker({ |
| 299 |
minDate: newMinDate, |
| 300 |
dateFormat: 'yyyy-mm-dd', |
| 301 |
|
| 302 |
}); |
| 303 |
} |
| 304 |
}); |
| 305 |
|
| 306 |
$('#yatra_tour_meta_tour_end_date').yatra_datepicker({ |
| 307 |
language: 'en', |
| 308 |
minDate: new Date(), |
| 309 |
dateFormat: 'yyyy-mm-dd', |
| 310 |
|
| 311 |
}); |
| 312 |
|
| 313 |
$('.yatra-datepicker').yatra_datepicker({ |
| 314 |
language: 'en', |
| 315 |
minDate: new Date(), |
| 316 |
dateFormat: 'yyyy-mm-dd', |
| 317 |
|
| 318 |
}); |
| 319 |
|
| 320 |
$('.yatra-timepicker').yatra_datepicker({ |
| 321 |
language: 'en', |
| 322 |
timepicker: true, |
| 323 |
onlyTimepicker: true, |
| 324 |
|
| 325 |
}); |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
}; |
| 330 |
|
| 331 |
|
| 332 |
var YatraSubTabs = { |
| 333 |
|
| 334 |
init: function () { |
| 335 |
|
| 336 |
this.cacheDom(); |
| 337 |
this.bindEvents(); |
| 338 |
}, |
| 339 |
|
| 340 |
cacheDom: function () { |
| 341 |
this.$tabList = $('.mb-meta-vertical-tab'); |
| 342 |
this.$tab = this.$tabList.find('li'); |
| 343 |
this.$tabFirst = this.$tabList.find('li:first-child'); |
| 344 |
this.$tabLink = this.$tabList.find('li'); |
| 345 |
this.$tabPanel = this.$tabList.closest('section').find('.mb-meta-vertical-tab-content-item'); |
| 346 |
this.tabReordering(); |
| 347 |
|
| 348 |
}, |
| 349 |
|
| 350 |
bindEvents: function () { |
| 351 |
var $this = this; |
| 352 |
this.$tabLink.on('click', function () { |
| 353 |
this.changeTab(); |
| 354 |
}.bind(this)); |
| 355 |
|
| 356 |
$('body').on('click', '.mb-repeator-heading span.toggle', function () { |
| 357 |
|
| 358 |
$(this).closest('.mb-repeator').find('.mb-repeator-fields').slideToggle('slow', function () { |
| 359 |
|
| 360 |
}); |
| 361 |
}); |
| 362 |
|
| 363 |
$('body').on('click', '.mb-repeator-heading span.add', function () { |
| 364 |
|
| 365 |
$(this).closest('.mb-meta-vertical-tab-content-item').find('.mb-repeator:last').after($(this).closest('.mb-repeator').clone()); |
| 366 |
|
| 367 |
var node = $(this).closest('.mb-meta-vertical-tab-content-item').find('.mb-repeator:last').find('.mb-repeator-heading-input'); |
| 368 |
|
| 369 |
var index = $this.getUpdatedRepeatorIndex($(this)); |
| 370 |
|
| 371 |
$this.repeatorHeading(node, index); |
| 372 |
|
| 373 |
$this.editorFix(node); |
| 374 |
|
| 375 |
}); |
| 376 |
|
| 377 |
$('body').on('click', '.mb-repeator-heading span.remove', function () { |
| 378 |
|
| 379 |
if ($(this).closest('.mb-meta-vertical-tab-content-item').find('.mb-repeator').length > 1) { |
| 380 |
$(this).closest('.mb-repeator').remove(); |
| 381 |
} |
| 382 |
$('.mb-repeator-heading-input').trigger('keyup'); |
| 383 |
}); |
| 384 |
$('body').on('keyup', '.mb-repeator-heading-input', function () { |
| 385 |
|
| 386 |
var index = $this.getUpdatedRepeatorIndex($(this)); |
| 387 |
|
| 388 |
$this.repeatorHeading($(this)); |
| 389 |
|
| 390 |
}); |
| 391 |
$.each($('.mb-repeator-heading-input'), function () { |
| 392 |
|
| 393 |
var index = $(this).closest('.mb-meta-vertical-tab-content-item').find('.mb-repeator').index($(this).closest('.mb-repeator')); |
| 394 |
|
| 395 |
$this.repeatorHeading($(this)); |
| 396 |
}); |
| 397 |
|
| 398 |
$('body').on('click', '.yatra-tab-visibility', function () { |
| 399 |
var li = $(this).closest('li'); |
| 400 |
if (!li.hasClass('hide')) { |
| 401 |
li.removeClass('visible'); |
| 402 |
li.addClass('hide'); |
| 403 |
$(this).removeClass('dashicons-visibility'); |
| 404 |
$(this).addClass('dashicons-hidden'); |
| 405 |
|
| 406 |
} else { |
| 407 |
li.removeClass('hide'); |
| 408 |
li.addClass('visible'); |
| 409 |
$(this).removeClass('dashicons-hidden'); |
| 410 |
$(this).addClass('dashicons-visibility'); |
| 411 |
} |
| 412 |
li.click(); |
| 413 |
|
| 414 |
$this.updateTourTabList(); |
| 415 |
|
| 416 |
}); |
| 417 |
}, |
| 418 |
updateTourTabList: function () { |
| 419 |
|
| 420 |
var sortableItemArray = []; |
| 421 |
|
| 422 |
$.each(this.$tabList.find('li'), function () { |
| 423 |
if (!$(this).hasClass('hide')) { |
| 424 |
sortableItemArray.push($(this).attr('data-tab-content')); |
| 425 |
} |
| 426 |
}); |
| 427 |
if (sortableItemArray.length > 0) { |
| 428 |
$('input#yatra_tour_meta_tour_tabs_ordering').val(sortableItemArray.join()); |
| 429 |
} |
| 430 |
}, |
| 431 |
editorFix: function (node) { |
| 432 |
|
| 433 |
var $this = this; |
| 434 |
|
| 435 |
var editorAreas = node.closest('.mb-meta-vertical-tab-content-item').find('.mb-repeator:last').find('.wp-editor-area'); |
| 436 |
|
| 437 |
node.closest('.mb-meta-vertical-tab-content-item').find('.mb-repeator:last').find('.tmce-active').hide(); |
| 438 |
|
| 439 |
$.each(editorAreas, function () { |
| 440 |
|
| 441 |
var this_id = $(this).attr('id'); |
| 442 |
|
| 443 |
var trimed_id = this_id.substr(0, this_id.lastIndexOf("-", this_id.length - 2)); |
| 444 |
|
| 445 |
var latest_id = $this.getUpdatedRepeatorIndex(node); |
| 446 |
|
| 447 |
var updated_id = trimed_id + '-' + latest_id; |
| 448 |
|
| 449 |
$(this).attr('id', updated_id); |
| 450 |
|
| 451 |
$(this).closest('.yatra-field-wrap').append($(this)); |
| 452 |
|
| 453 |
$(this).closest('.yatra-field-wrap').find('#' + updated_id).show(); |
| 454 |
|
| 455 |
node.closest('.mb-meta-vertical-tab-content-item').find('.mb-repeator:last').find('.tmce-active').remove(); |
| 456 |
node.closest('.mb-meta-vertical-tab-content-item').find('.mb-repeator:last').find('.mce-tinymce').remove(); |
| 457 |
|
| 458 |
tinyMCE.execCommand("mceAddEditor", true, updated_id); |
| 459 |
|
| 460 |
/* var editorSettings = { |
| 461 |
mediaButtons: true, // <- must be true |
| 462 |
tinymce: true, // <- must be true |
| 463 |
quicktags: true, // <- must be true |
| 464 |
|
| 465 |
}; |
| 466 |
|
| 467 |
wp.editor.initialize(updated_id, editorSettings);*/ |
| 468 |
|
| 469 |
|
| 470 |
}); |
| 471 |
|
| 472 |
|
| 473 |
}, |
| 474 |
repeatorHeading: function ($node) { |
| 475 |
var $node_val = $node.val(); |
| 476 |
var $node_index = this.getUpdatedRepeatorIndex($node); |
| 477 |
var replaced_value = $node_val.replace("{index}", $node_index); |
| 478 |
$node.closest('.mb-repeator').find('.repeator-title').html(replaced_value); |
| 479 |
}, |
| 480 |
getUpdatedRepeatorIndex: function ($node) { |
| 481 |
var index = $node.closest('.mb-meta-vertical-tab-content-item').find('.mb-repeator').index($node.closest('.mb-repeator')); |
| 482 |
return index + 1; |
| 483 |
}, |
| 484 |
changeTab: function () { |
| 485 |
var self = $(event.target); |
| 486 |
event.preventDefault(); |
| 487 |
this.$tab.removeClass('active'); |
| 488 |
self.addClass('active'); |
| 489 |
var data_tab_content_id = self.attr('data-tab-content'); |
| 490 |
|
| 491 |
this.$tabPanel.removeClass('active'); |
| 492 |
this.$tabList.closest('section').find('.mb-meta-vertical-tab-content-item[data-tab-content="' + data_tab_content_id + '"]').addClass('active'); |
| 493 |
}, |
| 494 |
tabReordering: function () { |
| 495 |
var $this = this; |
| 496 |
this.$tabList.sortable({ |
| 497 |
update: function (event, ui) { |
| 498 |
$this.updateTourTabList(); |
| 499 |
} |
| 500 |
}); |
| 501 |
} |
| 502 |
|
| 503 |
}; |
| 504 |
|
| 505 |
|
| 506 |
var YatraTaxonomy = { |
| 507 |
|
| 508 |
init: function () { |
| 509 |
|
| 510 |
this.cacheDom(); |
| 511 |
this.bindEvents(); |
| 512 |
}, |
| 513 |
|
| 514 |
cacheDom: function () { |
| 515 |
|
| 516 |
this.$attribute_field_type = $('select[name="attribute_field_type"]'); |
| 517 |
this.$taxonomy_form_field = $('<div class="form-field term-group"/>'); |
| 518 |
}, |
| 519 |
|
| 520 |
bindEvents: function () { |
| 521 |
|
| 522 |
var $this = this; |
| 523 |
$this.$attribute_field_type.on('change', function () { |
| 524 |
$this.onChangeAttributeType($(this)); |
| 525 |
}); |
| 526 |
|
| 527 |
}, |
| 528 |
onChangeAttributeType: function ($attribute_node) { |
| 529 |
|
| 530 |
var spinner = $('<div class="spinner is-active" style="float:none;"></div>'); |
| 531 |
|
| 532 |
var attribute_params = yatra_admin_params.attribute_params; |
| 533 |
|
| 534 |
if ($attribute_node.val() == '') { |
| 535 |
$attribute_node.closest('form').find('.yatra-taxonomy-group').remove(); |
| 536 |
return; |
| 537 |
} |
| 538 |
|
| 539 |
var attribute_data = { |
| 540 |
action: attribute_params.attribute_action, |
| 541 |
yatra_nonce: attribute_params.attribute_nonce, |
| 542 |
attribute_type: $attribute_node.val(), |
| 543 |
is_edit: attribute_params.is_edit |
| 544 |
}; |
| 545 |
$attribute_node.after(spinner); |
| 546 |
$.ajax({ |
| 547 |
type: "POST", |
| 548 |
url: yatra_admin_params.ajax_url, |
| 549 |
data: attribute_data, |
| 550 |
beforeSend: function () { |
| 551 |
|
| 552 |
}, |
| 553 |
success: function (response) { |
| 554 |
|
| 555 |
if (response.success === true) { |
| 556 |
|
| 557 |
$attribute_node.closest('form').find('.yatra-taxonomy-group').remove(); |
| 558 |
|
| 559 |
if (attribute_params.is_edit) { |
| 560 |
$attribute_node.closest('tr').after(response.data); |
| 561 |
} else { |
| 562 |
$attribute_node.closest('.form-field').after(response.data); |
| 563 |
} |
| 564 |
|
| 565 |
} |
| 566 |
$attribute_node.closest('.form-field').find('.spinner').remove() |
| 567 |
|
| 568 |
}, |
| 569 |
complete: function () { |
| 570 |
$attribute_node.closest('.form-field').find('.spinner').remove() |
| 571 |
} |
| 572 |
}); |
| 573 |
} |
| 574 |
|
| 575 |
}; |
| 576 |
|
| 577 |
|
| 578 |
var YatraTourAttributes = { |
| 579 |
|
| 580 |
init: function () { |
| 581 |
|
| 582 |
this.cacheDom(); |
| 583 |
|
| 584 |
this.bindEvents(); |
| 585 |
}, |
| 586 |
|
| 587 |
cacheDom: function () { |
| 588 |
|
| 589 |
this.$add_tour_attribute = $('#add_tour_attribute'); |
| 590 |
|
| 591 |
this.$yatra_tab_section = this.$add_tour_attribute.closest('.yatra-admin-tab-content-inner'); |
| 592 |
|
| 593 |
}, |
| 594 |
|
| 595 |
bindEvents: function () { |
| 596 |
|
| 597 |
var $this = this; |
| 598 |
|
| 599 |
this.$add_tour_attribute.on('click', function () { |
| 600 |
|
| 601 |
var term_id = $this.$yatra_tab_section.find('select[name="tour_attributes"]').find('option:selected').val(); |
| 602 |
|
| 603 |
var spinner = $('<div class="spinner is-active" style="float:none; margin-top:-5px;"></div>'); |
| 604 |
|
| 605 |
var attribute_tour_meta_params = yatra_admin_params.attribute_tour_meta_params; |
| 606 |
|
| 607 |
var length = $this.$yatra_tab_section.find('.mb-tour-attributes-fields[data-term-id="' + term_id + '"]').length; |
| 608 |
|
| 609 |
if (term_id < 1 || length > 0) { |
| 610 |
|
| 611 |
return; |
| 612 |
} |
| 613 |
|
| 614 |
var attribute_tour_meta_data = { |
| 615 |
action: attribute_tour_meta_params.attribute_meta_action, |
| 616 |
yatra_nonce: attribute_tour_meta_params.attribute_meta_nonce, |
| 617 |
term_id: term_id, |
| 618 |
post_id: $('body').find('.yatra_tour_cpt_meta_post_id').val() |
| 619 |
}; |
| 620 |
|
| 621 |
$this.$add_tour_attribute.after(spinner); |
| 622 |
$.ajax({ |
| 623 |
type: "POST", |
| 624 |
url: yatra_admin_params.ajax_url, |
| 625 |
data: attribute_tour_meta_data, |
| 626 |
beforeSend: function () { |
| 627 |
|
| 628 |
}, |
| 629 |
success: function (response) { |
| 630 |
|
| 631 |
if (response.success === true) { |
| 632 |
|
| 633 |
$this.$yatra_tab_section.append(response.data); |
| 634 |
|
| 635 |
$this.$yatra_tab_section.find('select[name="tour_attributes"]').find('option[value="' + term_id + '"]').attr('disabled', 'disabled'); |
| 636 |
|
| 637 |
} |
| 638 |
$this.$yatra_tab_section.find('.spinner').remove() |
| 639 |
|
| 640 |
}, |
| 641 |
complete: function () { |
| 642 |
$this.$yatra_tab_section.find('.spinner').remove() |
| 643 |
} |
| 644 |
}); |
| 645 |
|
| 646 |
|
| 647 |
}); |
| 648 |
|
| 649 |
$('body').on('click', '.mb-remove-item', function () { |
| 650 |
|
| 651 |
var confirm = window.confirm('Are you sure want to delete attribute?'); |
| 652 |
|
| 653 |
if (!confirm) { |
| 654 |
|
| 655 |
return; |
| 656 |
} |
| 657 |
|
| 658 |
var term_id = $(this).closest('.mb-tour-attributes-fields').attr('data-term-id'); |
| 659 |
|
| 660 |
$(this).closest('.mb-tour-attributes-fields').remove(); |
| 661 |
|
| 662 |
$this.$yatra_tab_section.find('#tour_attributes').find('option[value="' + term_id + '"]').removeAttr('disabled'); |
| 663 |
}); |
| 664 |
$.each($this.$yatra_tab_section.find('.mb-tour-attributes-fields'), function () { |
| 665 |
|
| 666 |
var term_id = $(this).attr('data-term-id'); |
| 667 |
|
| 668 |
$this.$yatra_tab_section.find('#tour_attributes').find('option[value="' + term_id + '"]').attr('disabled', 'disabled') |
| 669 |
|
| 670 |
}); |
| 671 |
}, |
| 672 |
|
| 673 |
|
| 674 |
}; |
| 675 |
|
| 676 |
|
| 677 |
$(document).ready(function () { |
| 678 |
YatraAdmin.init(); |
| 679 |
YatraTabs.init(); |
| 680 |
YatraSubTabs.init(); |
| 681 |
YatraTaxonomy.init(); |
| 682 |
YatraTourAttributes.init(); |
| 683 |
}); |
| 684 |
}(jQuery)); |
| 685 |
|