43 lines
1.5 KiB
JavaScript
43 lines
1.5 KiB
JavaScript
$(function() {
|
|
$(document).on('click', '#add-pricing-variable-form', function() {
|
|
if (typeof property_forms === "undefined") {var property_forms = $('.pricing-variable-form');}
|
|
if (typeof total_forms === "undefined") {var total_form = $('#id_form-TOTAL_FORMS');}
|
|
if (typeof form_num === "undefined") {var form_num = property_forms.length - 1;}
|
|
var new_form = $(property_forms[0]).clone();
|
|
var form_regex = RegExp(`form-(\\d){1}-`,'g');
|
|
form_num++;
|
|
new_form.html(new_form.html().replace(form_regex, `form-${form_num}-`));
|
|
new_form.appendTo('#pricing-variable-forms tbody');
|
|
$('#id_form-' + form_num + '-key').val('');
|
|
$('#id_form-' + form_num + '-value').val('');
|
|
total_form.val(form_num + 1);
|
|
})
|
|
|
|
$('.sortable').sortable({
|
|
handle: '.handle',
|
|
items: '.sortable-item',
|
|
update : function(event, ui) {
|
|
var new_order = '';
|
|
$(this).find('.sortable-item').each(function(i, x) {
|
|
var item_id = $(x).data('item-id');
|
|
if (new_order) {
|
|
new_order += ',';
|
|
}
|
|
new_order += item_id;
|
|
});
|
|
$.ajax({
|
|
url: $(this).data('order-url'),
|
|
data: {'new-order': new_order}
|
|
});
|
|
}
|
|
});
|
|
|
|
/* focus tab from #open:<tab slug> anchor, to point to open panel */
|
|
if (document.location.hash && document.location.hash.indexOf('#open:') == 0) {
|
|
const $tab_button = $('#tab-' + document.location.hash.substring(6) + '[role=tab]');
|
|
if ($tab_button.length) {
|
|
$('.pk-tabs')[0].tabs.selectTab($tab_button[0]);
|
|
}
|
|
}
|
|
});
|