172 lines
5.5 KiB
JavaScript
172 lines
5.5 KiB
JavaScript
/**
|
|
* 2023 Anvanto
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to the Academic Free License (AFL 3.0)
|
|
*
|
|
* @author Anvanto <anvantoco@gmail.com>
|
|
* @copyright 2023 Anvanto
|
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
|
*/
|
|
|
|
(function ($, window, undefined) {
|
|
'use strict';
|
|
|
|
function anproducts(wrapProductsClass) {
|
|
|
|
var classProductLine = $(wrapProductsClass).attr('data-classProductLine');
|
|
var classProductRemove = $(wrapProductsClass).attr('data-classProductRemove');
|
|
var classInputName = $(wrapProductsClass).attr('data-inputName');
|
|
var classSarchInput = $(wrapProductsClass).attr('data-classSarchInput');
|
|
|
|
var loc = location.pathname.split('/');
|
|
loc.pop();
|
|
|
|
var ajax_get_products = function (q) {
|
|
// return $.get(location.origin+loc.join('/')+'/'+'ajax_products_list.php?forceJson=1&disableCombination=1&exclude_packs=0&excludeVirtuals=0&limit=20&token='+token+'&q='+q);
|
|
return $.get($(wrapProductsClass).attr('data-searchProdutsController')+'&q='+q);
|
|
};
|
|
|
|
var promise = $.when();
|
|
var ptreeinput = $('.'+classSarchInput).closest('.form-group');
|
|
ptreeinput.children('div').append($('<ul id="anblog_search_products_ajax-product-list" class="anblog_search_ajax_product_list"></ul>'));
|
|
|
|
$('#anblog_search_products_ajax-product-list').on('click', 'li', function () {
|
|
|
|
var name = $(this).find('.label').html();
|
|
var img = $(this).find('img').attr('src');
|
|
var id = $(this).data('id');
|
|
|
|
$(wrapProductsClass).append('<div class="'+classProductLine+'"><input type="hidden" name="'+classInputName+'" value="'+id+'" /><div class="label">'+name+' <i class="material-icons delete '+classProductRemove+'">delete</i></div></div>');
|
|
|
|
$('.'+classSarchInput).val('');
|
|
$('#anblog_search_products_ajax-product-list').html('');
|
|
});
|
|
$('.'+classSarchInput).on('keyup', function () {
|
|
var q = $(this).val();
|
|
(function (value) {
|
|
promise = promise.then(function () {
|
|
return ajax_get_products(q);
|
|
}).then(function (response) {
|
|
if (!response) {
|
|
return false;
|
|
}
|
|
(function (products) {
|
|
ptreeinput.find('#anblog_search_products_ajax-product-list').html('');
|
|
$.each(products, function (i, product) {
|
|
ptreeinput.find('#anblog_search_products_ajax-product-list').append($('' +
|
|
'<li data-id="'+product.id+'">' +
|
|
// '<img src="'+product.image+'">' +
|
|
'<div class="label">'+product.name+'' + '</div>' +
|
|
'</li>').on('click', function () {
|
|
}));
|
|
});
|
|
})(JSON.parse(response));
|
|
});
|
|
})(q);
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
//////////////////////////
|
|
var wrapProductsClass = '.js-anblog_products'; // It need to edit
|
|
anproducts(wrapProductsClass);
|
|
$(document).on('click', '.js-anblog_search_products-remove', function(){
|
|
$(this).closest('.js-anblog_search-line').remove();
|
|
});
|
|
/////////////////////////
|
|
|
|
showHideFiels();
|
|
togglePriceTaxFields();
|
|
|
|
showHideFieldsRelation();
|
|
|
|
$( "#snow_on" ).change(function() {
|
|
var snowOn = $('#snow_on').val();
|
|
|
|
if (snowOn == 3) {
|
|
$('.js-anblog-relation').fadeIn(1);
|
|
} else {
|
|
$('.js-anblog-relation-group').fadeOut(1);
|
|
}
|
|
});
|
|
|
|
|
|
|
|
$('.an-sz-type-view input').on('click', function(){
|
|
showHideFiels();
|
|
});
|
|
|
|
$('.js-pf-field-type').on('click', function(){
|
|
togglePriceTaxFields();
|
|
});
|
|
|
|
function showHideFieldsRelation(){
|
|
|
|
var snowOn = $('#snow_on').val();
|
|
|
|
if (snowOn != 3) {
|
|
$('.js-anblog-relation-group').fadeOut(1);
|
|
}
|
|
}
|
|
|
|
function togglePriceTaxFields(){
|
|
|
|
$('.js-pf-price-tax').hide();
|
|
$('.js-pf-validation').hide();
|
|
$('.js-pf-placeholder').hide();
|
|
$('.js-pf-descr').hide();
|
|
$('.js-pf-max_length').hide();
|
|
|
|
var type = $('.js-pf-field-type').val();
|
|
|
|
if (type == 'text' || type == 'textarea' || type == 'date'){
|
|
$('.js-pf-price-tax').show();
|
|
}
|
|
|
|
if (type == 'text' || type == 'textarea'){
|
|
$('.js-pf-validation').show();
|
|
$('.js-pf-placeholder').show();
|
|
$('.js-pf-max_length').show();
|
|
}
|
|
|
|
if (type == 'text' || type == 'textarea' || type == 'date'){
|
|
$('.js-pf-descr').show();
|
|
}
|
|
|
|
}
|
|
|
|
function showHideFiels(){
|
|
|
|
$('.form-group .js-anblog-searchProducts-components').each(function(){
|
|
$(this).parents('.form-group').hide();
|
|
});
|
|
|
|
|
|
$('#id_root_category').parents('.form-group').hide();
|
|
|
|
var relation = $('.an-sz-type-view input[name=relation]:checked').val();
|
|
|
|
switch (relation) {
|
|
|
|
case "1":
|
|
$('#id_root_category').parents('.form-group').show();
|
|
break;
|
|
|
|
case "2":
|
|
$('.form-group .js-anblog-searchProducts-components').each(function(){
|
|
$(this).parents('.form-group').show();
|
|
});
|
|
break;
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
})(jQuery, window);
|