­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ var asl_engine = window['asl_engine'] || {}; (function($, app_engine) { 'use strict'; /* API method to get paging information */ if($.fn.dataTableExt && $.fn.dataTableExt.oApi){ $.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings ){return {"iStart": oSettings._iDisplayStart,"iEnd": oSettings.fnDisplayEnd(),"iLength": oSettings._iDisplayLength,"iTotal": oSettings.fnRecordsTotal(),"iFilteredTotal": oSettings.fnRecordsDisplay(),"iPage": oSettings._iDisplayLength === -1 ?0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),"iTotalPages": oSettings._iDisplayLength === -1 ?0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )};}; /* Bootstrap style pagination control */ $.extend($.fn.dataTableExt.oPagination,{bootstrap:{fnInit:function(i,a,e){var t=i.oLanguage.oPaginate,l=function(a){a.preventDefault(),i.oApi._fnPageChange(i,a.data.action)&&e(i)};$(a).addClass("pagination").append('");var s=$("a",a);$(s[0]).bind("click.DT",{action:"previous"},l),$(s[1]).bind("click.DT",{action:"next"},l)},fnUpdate:function(i,e){var a,t,l,s,n,o=i.oInstance.fnPagingInfo(),g=i.aanFeatures.p,r=Math.floor(2.5);n=o.iTotalPages<5?(s=1,o.iTotalPages):o.iPage<=r?(s=1,5):o.iPage>=o.iTotalPages-r?(s=o.iTotalPages-5+1,o.iTotalPages):(s=o.iPage-r+1)+5-1;var d=g.length;for(a=0;a'+t+"").insertBefore($("li:last",g[a])[0]).bind("click",function(a){a.preventDefault(),i._iDisplayStart=(parseInt($("a",this).text(),10)-1)*o.iLength,e(i)});0===o.iPage?$("li:first",g[a]).addClass("disabled"):$("li:first",g[a]).removeClass("disabled"),o.iPage===o.iTotalPages-1||0===o.iTotalPages?$("li:last",g[a]).addClass("disabled"):$("li:last",g[a]).removeClass("disabled")}}}}); } /** * [toastIt toast it based on the error or message] * @param {[type]} _response [description] * @return {[type]} [description] */ var toastIt = function(_response) { if(_response.success) { atoastr.success(_response.msg || _response.message); } else { atoastr.error(_response.error || _response.message || _response.msg); } }; // Debounce function function ASLDebounce(func, delay) { let timeoutId; return function (...args) { const context = this; // Preserve the `this` context clearTimeout(timeoutId); // Clear the previous timer timeoutId = setTimeout(() => { func.apply(context, args); // Execute the function after the delay }, delay); }; } /** * [codeAddress description] * @param {[type]} _address [description] * @param {[type]} _callback [description] * @return {[type]} [description] */ function codeAddress(_address, _callback) { var geocoder = new google.maps.Geocoder(); geocoder.geocode({ 'address': _address }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); _callback(results[0].geometry); } else { atoastr.error(ASL_REMOTE.LANG.geocode_fail + status); } }); }; /** * [generateUniqueId Unique ID] * @return {[type]} [description] */ function generateUniqueId() { const timestamp = new Date().getTime(); const random = Math.floor(Math.random() * 1000000); // Adjust the range as needed const uniqueId = `${timestamp}-${random}`; return uniqueId; }; /** * [isEmpty description] * @param {[type]} obj [description] * @return {Boolean} [description] */ function isEmpty(obj) { if (obj == null) return true; if (typeof(obj) == 'string' && obj == '') return true; return Object.keys(obj).length === 0; }; // Asynchronous Load var map, map_object = { is_loaded: true, marker: null, changed: false, store_location: null, search_box: null, map_marker: null, /** * [intialize description] * @param {[type]} _callback [description] * @return {[type]} [description] */ intialize: function(_callback) { var API_KEY = ''; if (asl_configs && asl_configs.api_key) { API_KEY = '&key=' + asl_configs.api_key; } var script = document.createElement('script'); script.type = 'text/javascript'; script.src = '//maps.googleapis.com/maps/api/js?libraries=places,drawing&' + 'loading=async&callback=asl_map_intialized' + API_KEY + '&&v=3.55'; document.body.appendChild(script); this.cb = _callback; }, /** * [render_a_map description] * @param {[type]} _lat [description] * @param {[type]} _lng [description] * @return {[type]} [description] */ render_a_map: function(_lat, _lng) { var hdlr = this, map_div = document.getElementById('map_canvas'), _draggable = true; hdlr.store_location = (_lat && _lng) ? [parseFloat(_lat), parseFloat(_lng)] : [-37.815, 144.965]; var latlng = new google.maps.LatLng(hdlr.store_location[0], hdlr.store_location[1]); if (!map_div) return false; var zoom_value = (window['asl_configs'] && asl_configs.zoom)? parseInt(asl_configs.zoom): 5; var mapOptions = { zoom: zoom_value, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP, styles: [{ "stylers": [{ "saturation": -100 }, { "gamma": 1 }] }, { "elementType": "labels.text.stroke", "stylers": [{ "visibility": "off" }] }, { "featureType": "poi.business", "elementType": "labels.text", "stylers": [{ "visibility": "off" }] }, { "featureType": "poi.business", "elementType": "labels.icon", "stylers": [{ "visibility": "off" }] }, { "featureType": "poi.place_of_worship", "elementType": "labels.text", "stylers": [{ "visibility": "off" }] }, { "featureType": "poi.place_of_worship", "elementType": "labels.icon", "stylers": [{ "visibility": "off" }] }, { "featureType": "road", "elementType": "geometry", "stylers": [{ "visibility": "simplified" }] }, { "featureType": "water", "stylers": [{ "visibility": "on" }, { "saturation": 50 }, { "gamma": 0 }, { "hue": "#50a5d1" }] }, { "featureType": "administrative.neighborhood", "elementType": "labels.text.fill", "stylers": [{ "color": "#333333" }] }, { "featureType": "road.local", "elementType": "labels.text", "stylers": [{ "weight": 0.5 }, { "color": "#333333" }] }, { "featureType": "transit.station", "elementType": "labels.icon", "stylers": [{ "gamma": 1 }, { "saturation": 50 }] }] }; hdlr.map_instance = map = new google.maps.Map(map_div, mapOptions); // && navigator.geolocation && _draggable if ((!hdlr.store_location || isEmpty(hdlr.store_location[0]))) { hdlr.add_marker(latlng); } else if (hdlr.store_location) { if (isNaN(hdlr.store_location[0]) || isNaN(hdlr.store_location[1])) return; //var loc = new google.maps.LatLng(hdlr.store_location[0], hdlr.store_location[1]); hdlr.add_marker(latlng); map.panTo(latlng); } // Add the searchbox var search_control = document.getElementById('asl-setting-search-box'); if(search_control) { // Add the alert after the search if(!asl_configs.api_key) { var error_alert = $('
').addClass('alert alert-danger mt-2').text(ASL_REMOTE.LANG.api_key_missing); $(search_control).after(error_alert); } hdlr.search_box = new google.maps.places.SearchBox(document.getElementById('asl-setting-search-box')); hdlr.map_instance.addListener('bounds_changed', function() { hdlr.search_box.setBounds(hdlr.map_instance.getBounds()); }); hdlr.search_box.addListener('places_changed', function() { hdlr.search(); }); } }, /** * [search Add the search] * @return {[type]} [description] */ search: function() { var hdlr = this; var places = hdlr.search_box.getPlaces(); if (!places || places.length == 0) { return; } var bounds = new google.maps.LatLngBounds(); places.forEach(function(place) { if (!place.geometry) { console.log("Returned place contains no geometry"); return; } if (place.geometry.viewport) { bounds.union(place.geometry.viewport); } else { bounds.extend(place.geometry.location); } hdlr.map_marker.setPosition(place.geometry.location); // Update marker position }); hdlr.map_instance.fitBounds(bounds); }, /** * [add_marker description] * @param {[type]} _loc [description] */ add_marker: function(_loc) { var hdlr = this; // Create a marker hdlr.map_marker = new google.maps.Marker({ draggable: true, position: _loc, map: map }); // Marker icon var marker_icon = new google.maps.MarkerImage(ASL_Instance.url + 'icon/default.png'); hdlr.map_marker.setIcon(marker_icon); hdlr.map_instance.panTo(_loc); // Add the map marker event for the dragend google.maps.event.addListener( hdlr.map_marker, 'dragend', function() { hdlr.store_location = [hdlr.map_marker.position.lat(), hdlr.map_marker.position.lng()]; hdlr.changed = true; var loc = new google.maps.LatLng(hdlr.map_marker.position.lat(), hdlr.map_marker.position.lng()); hdlr.map_instance.panTo(loc); app_engine.pages.store_changed(hdlr.store_location); }); } }; //////////////////////////////////// // Add the lang control switcher // //////////////////////////////////// var lang_ctrl = document.querySelector('#asl-lang-ctrl'); if(lang_ctrl) { // set the control lang var lang_value = (window.wpCookies.get('asl-lang') || ASL_REMOTE.sl_lang || ''); lang_ctrl.value = lang_value; // reset in the storage window.wpCookies.set('asl-lang', lang_value); // Reload Event $(lang_ctrl).bind('change', function(e) { // change in the storage window.wpCookies.set('asl-lang', lang_ctrl.value); window.location.reload(); }); } /** * [uploader AJAX Uploader] * @param {[type]} $form [description] * @param {[type]} _URL [description] * @param {[type]} _done [description] * @return {[type]} [description] */ app_engine.uploader = function($form, _URL, _done /*,_submit_callback*/ ) { function formatFileSize(bytes) { if (typeof bytes !== 'number') { return '' } if (bytes >= 1000000000) { return (bytes / 1000000000).toFixed(2) + ' GB' } if (bytes >= 1000000) { return (bytes / 1000000).toFixed(2) + ' MB' } return (bytes / 1000).toFixed(2) + ' KB' }; var ul = $form.find('ul'); $form[0].reset(); $form.fileupload({ url: _URL, dataType: 'json', //multipart: false, done: function(e, _data) { ul.empty(); _done(e, _data); $form.find('.progress-bar').css('width', '0%'); $form.find('.progress').hide(); //reset form if success if (_data.result.success) {} }, add: function(e, _data) { ul.empty(); //Check file Extension var exten = _data.files[0].name.split('.'), exten = exten[exten.length - 1]; if (['jpg', 'png', 'jpeg', 'gif', 'JPG', 'svg', 'zip', 'csv', 'kml'].indexOf(exten) == -1) { atoastr.error((ASL_REMOTE.LANG.invalid_file_error)); return false; } var tpl = $('
  • '); tpl.find('p').text(_data.files[0].name.substr(0, 50)).append('' + formatFileSize(_data.files[0].size) + ''); _data.context = tpl.appendTo(ul); var jqXHR = null; $form.find('.btn-start').unbind().bind('click', function() { /*if(_submit_callback){ if(!_submit_callback())return false; }*/ jqXHR = _data.submit(); $form.find('.progress').show() }); $form.find('.custom-file-label').html(_data.files[0].name); }, progress: function(e, _data) { var progress = parseInt(_data.loaded / _data.total * 100, 10); $form.find('.progress-bar').css('width', progress + '%'); $form.find('.sr-only').html(progress + '%'); if (progress == 100) { _data.context.removeClass('working'); } }, fail: function(e, _data) { _data.context.addClass('error'); $form.find('.upload-status-box').html(ASL_REMOTE.LANG.upload_fail).addClass('bg-warning alert') } /* formData: function(_form) { var formData = [{ name: '_data[action]', value: 'asl_add_store' }] // console.log(formData); return formData; }*/ }) .bind('fileuploadsubmit', function(e, _data) { _data.formData = $form.ASLSerializeObject(); if(lang_ctrl && lang_ctrl.value && _data.formData) _data.formData['asl-lang'] = lang_ctrl.value; }) .prop('disabled', !$.support.fileInput) .parent().addClass($.support.fileInput ? undefined : 'disabled'); }; //http://harvesthq.github.io/chosen/options.html app_engine['pages'] = { _validate_page: function() { if (ASL_REMOTE.Com) return; aswal({ title: '', html:'
    '+ '
    '+ ''+ '
    '+ '

    '+ASL_REMOTE.LANG.pur_title+'

    '+ ASL_REMOTE.LANG.pur_text+ '
    ', input: 'text', type: "question", showCancelButton: false, allowOutsideClick: false, allowEscapeKey: false, customClass: 'asl-validate-modal', confirmButtonColor: "#dc3545", confirmButtonText: "VALIDATE", preConfirm: function(_value) { return new Promise(function(resolve, reject) { if ($.trim(_value) == '') { aswal.showValidationError('Purchase Code is Missing!'); return false; } aswal.showLoading(); ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=validate_me", { value: _value }, function(_response) { aswal.hideLoading(); if (!_response.success) { aswal.showValidationError(_response.message); reject(); return false; } else { aswal({ type: (_response.success) ? 'success' : 'error', title: (_response.success) ? 'Validate Successfully!' : 'Validation Failed!', html: (_response.message) ? _response.message : ('Validation Failed, Please Contact Support') }); reject(); return true; } }, 'json'); }) } /*inputValidator: function(value) { return !value && 'You need to write something!' }*/ }) }, /** * [store_changed Stores Changed] * @param {[type]} _position [description] * @return {[type]} [description] */ store_changed: function(_position) { if($('#asl_txt_lat')[0]) $('#asl_txt_lat').val(_position[0]); if($('#asl_txt_lng')[0]) $('#asl_txt_lng').val(_position[1]); }, /** * [manage_attribute Manage Attribute] * @return {[type]} [description] */ manage_attribute: function() { /** * [asl_attributes_tabs For each dropdown tabs] * @param {[type]} _options [description] * @return {[type]} [description] */ $.fn.asl_attributes_tabs = function(_options) { var options = $.extend({},_options); var panim = null; /** * [attr_main Run all the methods of the attributes] * @return {[type]} [description] */ function attr_main() { // Main This var $this = $(this), $section = $this.find('> .asl-attr-listing'), $table = $section.find('table'), tab_title = $this.data('tab-title'), tab_plural = $this.data('tab-plural'), tab_single = $this.data('tab-single'), tab_name = $this.data('tab-name'); var asInitVals = {}; $table.dataTable({ "bProcessing": true, "sPaginationType": "bootstrap", "bFilter": false, "bServerSide": true, //"scrollX": true, /*"aoColumnDefs": [ { 'bSortable': false, 'aTargets': [ 1 ] } ],*/ "bAutoWidth": true, "columnDefs": [ { 'bSortable': false, "width": "75px", "targets": 0 }, { "width": "75px", "targets": 1 }, {"targets": 2 }, {"targets": 3 }, {"targets": 4 }, {"targets": 5 }, { 'bSortable': false, 'aTargets': [0, 5] } ], "iDisplayLength": 10, "sAjaxSource": ASL_REMOTE.URL + "?action=asl_ajax_handler&asl-nounce=" + ASL_REMOTE.nounce + "&sl-action=get_attributes&type=" + tab_name, "columns": [ { "data": "check" }, { "data": "id" }, { "data": "name" }, { "data": "ordr" }, { "data": "created_on" }, { "data": "action" } ], 'fnServerData': function(sSource, aoData, fnCallback) { $.get(sSource, aoData, function(json) { fnCallback(json); }, 'json'); }, "fnServerParams": function(aoData) { // add lang if(lang_ctrl) aoData.push({"name": 'asl-lang',"value": lang_ctrl.value}); // Add the filters $("thead input").each(function(i) { if (this.value != "") { aoData.push({ "name": 'filter[' + $(this).attr('data-id') + ']', "value": this.value }); } }); }, "order": [ [1, 'desc'] ] }); //New Attribute $section.find('.btn-asl-new-attr').bind('click', function(e) { aswal({ title: "Create " + tab_single, text: "Do you want to add new " + tab_single + "?", html:'', input: 'text', type: "question", inputPlaceholder: "Enter the value", showCancelButton: true, focusCancel: true, confirmButtonColor: "#28a745", confirmButtonText: "Create it!", customClass: 'aswal-attr-modal', onOpen: function() { var $attr_txt_input = $('.aswal2-input:not(.aswal2-ordr)'); $attr_txt_input.insertBefore($('.aswal2-content')[0]); }, preConfirm: function(_value) { return new Promise(function(resolve) { if ($.trim(_value) != '') { resolve(); } else { aswal.showValidationError( tab_single +' value is required.'); return false; } }) } /*inputValidator: function(value) { return !value && 'You need to write something!' }*/ }) .then(function(result) { if (result) { var $attr_ordr_input = $('#aswal2-input-ordr'); ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=add_attribute", { title: tab_title, name: tab_name, value: result, ordr: $attr_ordr_input.val() }, function(_response) { toastIt(_response); if (_response.success) { $table.fnDraw(); return; } }, 'json'); } }); }); //Select all button $section.find('.select-all').bind('click', function(e) { $section.find('.table input').attr('checked', 'checked'); }); //Delete Selected Attributes:: bulk $section.find('.btn-asl-delete-all').bind('click', function(e) { var $tmp_categories = $section.find('.table input:checked'); if ($tmp_categories.length == 0) { displayMessage('No Category selected', $(".dump-message"), 'alert alert-danger static', true); return; } var item_ids = []; $tmp_categories.each(function(i) { item_ids.push($(this).attr('data-id')); }); aswal({ title: "Delete " + tab_title, text: "Are you sure you want to delete selected " + tab_title + " ?", type: "warning", showCancelButton: true, confirmButtonColor: "#dc3545", confirmButtonText: "Delete it!" }).then(function() { ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=delete_attribute", { title: tab_title, name: tab_name, item_ids: item_ids, multiple: true }, function(_response) { toastIt(_response); if (_response.success) { $table.fnDraw(); return; } }, 'json'); }); }); //show edit attribute model $table.find('tbody').on('click', '.edit_attr', function(e) { var _value = $(this).data('value'), _id = $(this).data('id'), _ordr = $(this).data('ordr'); aswal({ title: "Update " + tab_title, text: "Update existing " + tab_title + " to new name", input: 'text', html:'', type: "question", inputValue: _value, showCancelButton: true, confirmButtonColor: "#28a745", confirmButtonText: "Update it!", customClass: 'aswal-attr-modal', onOpen: function() { var $attr_txt_input = $('.aswal2-input:not(.aswal2-ordr)'); $attr_txt_input.insertBefore($attr_txt_input[0].previousElementSibling); }, preConfirm: function(_value) { return new Promise(function(resolve) { if ($.trim(_value) != '') { resolve(); } else { aswal.showValidationError('Field is empty.'); return false; } }) } }) .then(function(result) { if (result) { var $attr_ordr_input = $('#aswal2-input-ordr'); ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=update_attribute", { id: _id, title: tab_title, name: tab_name, value: result, ordr: $attr_ordr_input.val() }, function(_response) { toastIt(_response); if (_response.success) { $table.fnDraw(); return; } }, 'json'); } }); }); // Show delete attribute model $table.find('tbody').on('click', '.delete_attr', function(e) { var _category_id = $(this).attr("data-id"); aswal({ title: "Delete " + tab_title, text: "Are you sure you want to delete " + tab_title + " " + _category_id + " ?", type: "warning", showCancelButton: true, confirmButtonColor: "#dc3545", confirmButtonText: "Delete it!", }).then( function() { ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=delete_attribute", { title: tab_title, name: tab_name, category_id: _category_id }, function(_response) { toastIt(_response); if (_response.success) { $table.fnDraw(); return; } }, 'json'); } ); }); // Search $section.find("thead input").keyup(function(e) { if (e.keyCode == 13) { $table.fnDraw(); } }); }; /*loop for each*/ this.each(attr_main); return this; }; // Main Loop $('.asl-attr-tab').asl_attributes_tabs({}); }, /** * [manage_categories description] * @return {[type]} [description] */ manage_categories: function() { var table = null; var parent_categories; var asInitVals = {}; table = $('#tbl_categories').dataTable({ "sPaginationType": "bootstrap", "bProcessing": true, "bFilter": false, "bServerSide": true, "bAutoWidth": true, "columnDefs": [ { 'bSortable': false, "width": "75px", "targets": 0 }, { "width": "75px","targets": 1}, {"targets": 2, render: function (data, type, full, meta) { return '' + data + ""; } }, { "width": "100px", "targets": 3 }, { "width": "100px", "targets": 4 }, {"targets": 5 }, {"targets": 6 }, { 'bSortable': false, 'aTargets': [0, 6] } ], "iDisplayLength": 10, "sAjaxSource": ASL_REMOTE.URL + "?action=asl_ajax_handler&asl-nounce=" + ASL_REMOTE.nounce + "&sl-action=get_categories", "columns": [ { "data": "check" }, { "data": "id" }, { "data": "category_name" }, { "data": "parent_name" }, { "data": "ordr" }, { "data": "icon" }, { "data": "created_on" }, { "data": "action" } ], 'fnServerData': function(sSource, aoData, fnCallback) { $.get(sSource, aoData, function(json) { parent_categories = json.parent_categories; fnCallback(json); }, 'json'); }, "fnServerParams": function(aoData) { // add lang if(lang_ctrl) aoData.push({"name": 'asl-lang',"value": lang_ctrl.value}); // Add the search $("thead input").each(function(i) { if (this.value != "") { aoData.push({ "name": 'filter[' + $(this).attr('data-id') + ']', "value": this.value }); } }); // Filter out the object with name "sColumns" aoData = aoData.map(function(item) { if (item.name === "sColumns") { item.value = ""; } return item; }); }, "order": [ [1, 'desc'] ] }); //prompt the category box $('#btn-asl-new-c').bind('click', function() { $("#parent_id").html(''); $.each(parent_categories, function(index, value) { $("#parent_id").append(''); }); $('#asl-add-modal').smodal('show'); }); // Select all button $('.table .select-all').bind('click', function(e) { $('.asl-p-cont .table input').attr('checked', 'checked'); }); // Delete Selected Categories:: bulk $('#btn-asl-delete-all').bind('click', function(e) { var $tmp_categories = $('.asl-p-cont .table input:checked'); if ($tmp_categories.length == 0) { atoastr.error('No Category selected'); return; } var item_ids = []; $('.asl-p-cont .table input:checked').each(function(i) { item_ids.push($(this).attr('data-id')); }); aswal({ title: ASL_REMOTE.LANG.delete_categories, text: ASL_REMOTE.LANG.warn_question + ' ' + ASL_REMOTE.LANG.delete_categories + '?', type: "warning", showCancelButton: true, confirmButtonColor: "#dc3545", confirmButtonText: ASL_REMOTE.LANG.delete_it }).then(function() { ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=delete_category", { item_ids: item_ids, multiple: true }, function(_response) { toastIt(_response); if (_response.success) { table.fnDraw(); return; } }, 'json'); }); }); // To Add New Categories var url_to_upload = ASL_REMOTE.URL, $form = $('#frm-addcategory'); app_engine.uploader($form, url_to_upload + '?action=asl_ajax_handler&asl-nounce=' + ASL_REMOTE.nounce + '&sl-action=add_categories', function(e, data) { var data = data.result; toastIt(data); if (data.success) { //reset form $('#asl-add-modal').smodal('hide'); $('#frm-addcategory').find('input:text, input:file').val(''); $('#progress_bar').hide(); //show table value table.fnDraw(); } }); //Validate $('#btn-asl-add-categories').bind('click', function(e) { if ($('#frm-addcategory ul li').length == 0) { atoastr.error('Please Upload Category Icon'); e.preventDefault(); return; } }); //show edit category model $('#tbl_categories tbody').on('click', '.edit_category', function(e) { $('#updatecategory_image').show(); $('#updatecategory_editimage').hide(); $('#asl-update-modal').smodal('show'); $('#update_category_id_input').val($(this).attr("data-id")); ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=get_category_byid", { category_id: $(this).attr("data-id") }, function(_response) { if (_response.success) { $("#update_category_name").val(_response.item['category_name']); $("#update_parent_id").html(''); $.each(parent_categories, function(index, value) { var selected = _response.item['parent_id'] == value.id ? 'selected' : ''; if (value.id != _response.item['id']) { $("#update_parent_id").append(''); } }); $("#update_category_icon").attr("src", ASL_Instance.url + "svg/" + _response.item['icon']); $("#update_category_ordr").val(_response.item['ordr']); } else { atoastr.error(_response.error); return; } }, 'json'); }); //show edit category upload image $('#change_image').click(function() { $("#update_category_icon").attr("data-id", "") $('#updatecategory_image').hide(); $('#updatecategory_editimage').show(); }); // Update category without icon $('#btn-asl-update-categories').click(function() { if ($("#update_category_icon").attr("data-id") == "same") { ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=update_category", { data: { category_id: $("#update_category_id_input").val(), action: "same", category_name: $("#update_category_name").val(), "parent_id": $("#update_parent_id").val(), "ordr": $("#update_category_ordr").val() } }, function(_response) { toastIt(_response); if (_response.success) { $('#asl-update-modal').smodal('hide'); table.fnDraw(); return; } }, 'json'); } }); // Update category with icon var url_to_upload = ASL_REMOTE.URL, $form = $('#frm-updatecategory'); $form.append(' '); app_engine.uploader($form, url_to_upload + '?action=asl_ajax_handler&asl-nounce=' + ASL_REMOTE.nounce + '&sl-action=update_category', function(e, data) { var data = data.result; if (data.success) { atoastr.success(data.msg); $('#asl-update-modal').smodal('hide'); $('#frm-updatecategory').find('input:text, input:file').val(''); $('#progress_bar_').hide(); table.fnDraw(); } else atoastr.error(data.msg); }); //show delete category model $('#tbl_categories tbody').on('click', '.delete_category', function(e) { var _category_id = $(this).attr("data-id"); aswal({ title: ASL_REMOTE.LANG.delete_category, text: ASL_REMOTE.LANG.warn_question + ' ' + ASL_REMOTE.LANG.delete_category + ' ' + _category_id + " ?", type: "warning", showCancelButton: true, confirmButtonColor: "#dc3545", confirmButtonText: ASL_REMOTE.LANG.delete_it, }).then( function() { ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=delete_category", { category_id: _category_id }, function(_response) { toastIt(_response); if (_response.success) { table.fnDraw(); return; } }, 'json'); } ); }); $("thead input").keyup(function(e) { if (e.keyCode == 13) { table.fnDraw(); } }); }, /** * [manage_markers Manage Markers] * @return {[type]} [description] */ manage_markers: function() { var table = null; //prompt the marker box $('#btn-asl-new-c').bind('click', function() { $('#asl-add-modal').smodal('show'); }); var asInitVals = {}; table = $('#tbl_markers').dataTable({ "sPaginationType": "bootstrap", "bProcessing": true, "bFilter": false, "bServerSide": true, //"scrollX": true, /*"aoColumnDefs": [ { 'bSortable': false, 'aTargets': [ 1 ] } ],*/ "bAutoWidth": true, "columnDefs": [ { 'bSortable': false, "width": "75px", "targets": 0 }, { "width": "75px", "targets": 1 }, {"targets": 2 }, { "width": "100px", "targets": 3 }, {"targets": 4 }, { 'bSortable': false, 'aTargets': [4] } ], "iDisplayLength": 10, "sAjaxSource": ASL_REMOTE.URL + "?action=asl_ajax_handler&asl-nounce=" + ASL_REMOTE.nounce + "&sl-action=get_markers", "columns": [ { "data": "check" }, { "data": "id" }, { "data": "marker_name" }, { "data": "icon" }, { "data": "action" } ], "fnServerParams": function(aoData) { $("#tbl_markers_wrapper thead input").each(function(i) { if (this.value != "") { aoData.push({ "name": 'filter[' + $(this).attr('data-id') + ']', "value": this.value }); } }); }, "order": [ [1, 'desc'] ] }); //TO ADD New Marker var url_to_upload = ASL_REMOTE.URL, $form = $('#frm-addmarker'); app_engine.uploader($form, url_to_upload + '?action=asl_ajax_handler&asl-nounce=' + ASL_REMOTE.nounce + '&sl-action=add_markers', function(e, data) { var data = data.result; if (!data.success) { atoastr.error(data.msg); } else { atoastr.success(data.msg); //reset form $('#asl-add-modal').smodal('hide'); $('#frm-addmarker').find('input:text, input:file').val(''); $('#progress_bar').hide(); //show table value table.fnDraw(); } }); // Show edit marker model $('#tbl_markers tbody').on('click', '.edit_marker', function(e) { $('#message_update').empty().removeAttr('class'); $('#updatemarker_image').show(); $('#updatemarker_editimage').hide(); $('#asl-update-modal').smodal('show'); $('#update_marker_id_input').val($(this).attr("data-id")); ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=get_marker_byid", { marker_id: $(this).attr("data-id") }, function(_response) { if (_response.success) { $("#update_marker_name").val(_response.list[0]['marker_name']); $("#update_marker_icon").attr("src", ASL_Instance.url + "icon/" + _response.list[0]['icon']); } else { atoastr.error(_response.error); return; } }, 'json'); }); //show edit marker upload image $('#change_image').click(function() { $("#update_marker_icon").attr("data-id", "") $('#updatemarker_image').hide(); $('#updatemarker_editimage').show(); }); //update marker without icon $('#btn-asl-update-markers').click(function() { if ($("#update_marker_icon").attr("data-id") == "same") { ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=update_marker", { data: { marker_id: $("#update_marker_id_input").val(), action: "same", marker_name: $("#update_marker_name").val() } }, function(_response) { toastIt(_response); if (_response.success) { table.fnDraw(); return; } }, 'json'); } }); // Update marker with icon var url_to_upload = ASL_REMOTE.URL, $form = $('#frm-updatemarker'); $form.append(' '); app_engine.uploader($form, url_to_upload + '?action=asl_ajax_handler&asl-nounce=' + ASL_REMOTE.nounce + '&sl-action=update_marker', function(e, data) { var data = data.result; if (data.success) { atoastr.success(data.msg); $('#asl-update-modal').smodal('hide'); $('#frm-updatemarker').find('input:text, input:file').val(''); $('#progress_bar_').hide(); table.fnDraw(); } else atoastr.error(data.msg); }); // Show delete marker model $('#tbl_markers tbody').on('click', '.delete_marker', function(e) { var _marker_id = $(this).attr("data-id"); aswal({ title: ASL_REMOTE.LANG.delete_marker, text: ASL_REMOTE.LANG.warn_question + " " + ASL_REMOTE.LANG.delete_marker + " " + _marker_id + "?", type: "warning", showCancelButton: true, confirmButtonColor: "#dc3545", confirmButtonText: ASL_REMOTE.LANG.delete_it, }).then( function() { ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=delete_marker", { marker_id: _marker_id }, function(_response) { toastIt(_response); if (_response.success) { table.fnDraw(); return; } }, 'json'); } ); }); //////////////Delete Selected Categories//////////////// // Select all button $('.table .select-all').bind('click', function(e) { $('.asl-p-cont .table input').attr('checked', 'checked'); }); //Bulk $('#btn-asl-delete-all').bind('click', function(e) { var $tmp_markers = $('.asl-p-cont .table input:checked'); if ($tmp_markers.length == 0) { atoastr.error('No Marker selected'); return; } var item_ids = []; $('.asl-p-cont .table input:checked').each(function(i) { item_ids.push($(this).attr('data-id')); }); aswal({ title: ASL_REMOTE.LANG.delete_markers, text: ASL_REMOTE.LANG.warn_question + " " + ASL_REMOTE.LANG.delete_markers + "?", type: "warning", showCancelButton: true, confirmButtonColor: "#dc3545", confirmButtonText: ASL_REMOTE.LANG.delete_it }) .then(function() { ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=delete_marker", { item_ids: item_ids, multiple: true }, function(_response) { toastIt(_response); if (_response.success) { table.fnDraw(); return; } }, 'json'); }); }); $("thead input").keyup(function(e) { if (e.keyCode == 13) { table.fnDraw(); } }); }, /** * [_logo_media_uploader Media uploader for the logo] * @param {[type]} _callback [when upload is completed] * @return {[type]} [description] */ _logo_media_uploader: function(_callback) { /// Upload the logos $('.asl_upload_logo_btn').click(function(e){ e.preventDefault(); var multiple = false, $class = 'gallery', is_upload = $(this).hasClass('asl_upload_logo_btn'); if (is_upload) { multiple = false; $class = 'icon'; } var button = $(this), hiddenfield = button.prev(), hiddenfieldvalue = hiddenfield.val().split(","), /* the array of added image IDs */ custom_uploader = wp.media({ title: ASL_REMOTE.LANG.select_logo || 'Insert images', /* popup title */ library : {type : 'image'}, button: {text: ASL_REMOTE.LANG.use_image || 'Use Image'}, /* "Insert" button text */ multiple: multiple }) .on('select', function() { var attachments = custom_uploader.state().get('selection').map(function(a) { a.toJSON(); return a; }), thesamepicture = false, i; /* loop through all the images */ for (i = 0; i < attachments.length; ++i) { if (is_upload) { $('ul.asl_logo_mtb').html('
  • '); } else{ /* add HTML element with an image */ $('ul.asl_logo_mtb').append('
  • '); } if (is_upload) { /* add an image ID to the array of all images */ hiddenfieldvalue = attachments[i].id ; } else{ /* add an image ID to the array of all images */ hiddenfieldvalue.push( attachments[i].id ); } } if (!is_upload) { /* refresh sortable */ $( "ul.asl_"+$class+"_mtb" ).sortable( "refresh" ); } if (is_upload) { /* add an image ID to the array of all images */ hiddenfield.val( hiddenfieldvalue ); } else{ /* add the IDs to the hidden field value */ hiddenfield.val( hiddenfieldvalue.join() ); } /* you can print a message for users if you want to let you know about the same images */ if( thesamepicture == true ) alert('The same images are not allowed.'); }).open(); }); // Upload New Logo $('.new_upload_logo').on('click',function(){ var img_id = $('#add_img').val(), logo_name = $('#txt_logo-name').val(); if (img_id != '' && logo_name != '') { ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=upload_logo", { data:{img_id:img_id,logo_name:logo_name} }, function(data) { toastIt(data); // run the call back if(_callback) { _callback(data); } }, 'json'); } }); }, /** * [manage_logos description] * @return {[type]} [description] */ manage_logos: function() { /// Remove the logo images $('body').on('click', '.asl_remove_logo', function(){ var id = $(this).parent().attr('data-id'), gallery = $(this).parent().parent(), hiddenfield = gallery.parent().next(), hiddenfieldvalue = hiddenfield.val().split(","), i = hiddenfieldvalue.indexOf(id); $(this).parent().remove(); /* remove certain array element */ if(i != -1) { hiddenfieldvalue.splice(i, 1); } /* add the IDs to the hidden field value */ hiddenfield.val( hiddenfieldvalue.join() ); return false; }); var table = null; //prompt the logo box $('#btn-asl-new-c').bind('click', function() { $('ul.asl_logo_mtb').html(''); $('#asl-add-modal').smodal('show'); }); var asInitVals = {}; table = $('#tbl_logos').dataTable({ "sPaginationType": "bootstrap", "bProcessing": true, "bFilter": false, "bServerSide": true, //"scrollX": true, /*"aoColumnDefs": [ { 'bSortable': false, 'aTargets': [ 1 ] } ],*/ "bAutoWidth": true, "columnDefs": [ { 'bSortable': false, "width": "75px", "targets": 0 }, { "width": "75px", "targets": 1 }, {"targets": 2 }, { "width": "100px", "targets": 3 }, {"targets": 4 }, { 'bSortable': false, 'aTargets': [4] } ], "iDisplayLength": 10, "sAjaxSource": ASL_REMOTE.URL + "?action=asl_ajax_handler&asl-nounce=" + ASL_REMOTE.nounce + "&sl-action=get_logos", "columns": [ { "data": "check" }, { "data": "id" }, { "data": "name" }, { "data": "path" }, { "data": "action" } ], "fnServerParams": function(aoData) { $("#tbl_logos_wrapper thead input").each(function(i) { if (this.value != "") { aoData.push({ "name": 'filter[' + $(this).attr('data-id') + ']', "value": this.value }); } }); }, "order": [ [1, 'desc'] ] }); // Add new logo uploader this._logo_media_uploader(function(_data){ // Upload response if (_data.success) { // Reset form $('#asl-add-modal').smodal('hide'); $('#frm-addlogo').find('input:text, input:file').val(''); } // refresh the table on success table.fnDraw(); }); // Show edit logo model $('#tbl_logos tbody').on('click', '.edit_logo', function(e) { $('ul.asl_logo_mtb').html(''); $('#updatelogo_image').show(); $('#updatelogo_editimage').hide(); $('#asl-update-modal').smodal('show'); $('#update_logo_id_input').val($(this).attr("data-id")); ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=get_logo_byid", { logo_id: $(this).attr("data-id") }, function(_response) { if (_response.success) { $("#update_logo_name").val(_response.list[0]['name']); $("#update_logo_icon").attr("src", ASL_Instance.url + "Logo/" + _response.list[0]['path']); } else { atoastr.error(_response.error); return; } }, 'json'); }); // Show edit logo upload image $('#change_image').click(function() { $("#update_logo_icon").attr("data-id", "") $('#updatelogo_image').hide(); $('#updatelogo_editimage').show(); }); // Update logo without icon $('#btn-asl-update-logos').click(function() { var img_id = $('#replace_logo').val(), logo_id = $("#update_logo_id_input").val(), logo_name = $('#update_logo_name').val(); if (logo_name != '') { ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=update_logo", { data: { logo_id:logo_id , action:((img_id)? "notsame": ''), logo_name: logo_name , img_id:img_id } }, function(_response) { if (_response.success) { atoastr.success(_response.msg); table.fnDraw(); $('#asl-update-modal').smodal('hide'); return; } else { atoastr.error(_response.msg); return; } }, 'json'); } }); //show delete logo model $('#tbl_logos tbody').on('click', '.delete_logo', function(e) { var _logo_id = $(this).attr("data-id"); aswal({ title: ASL_REMOTE.LANG.delete_logo, text: ASL_REMOTE.LANG.warn_question + " " + ASL_REMOTE.LANG.delete_logo + " " + _logo_id + "?", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: ASL_REMOTE.LANG.delete_it, }).then( function() { ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=delete_logo", { logo_id: _logo_id }, function(_response) { if (_response.success) { atoastr.success(_response.msg); table.fnDraw(); return; } else { atoastr.success((_response.error || ASL_REMOTE.LANG.error_try_again)); return; } }, 'json'); } ); }); //////////////Delete Selected Categories//////////////// //Select all button $('.table .select-all').bind('click', function(e) { $('.asl-p-cont .table input').attr('checked', 'checked'); }); //Bulk $('#btn-asl-delete-all').bind('click', function(e) { var $tmp_logos = $('.asl-p-cont .table input:checked'); if ($tmp_logos.length == 0) { atoastr.error('No Logo selected'); return; } var item_ids = []; $('.asl-p-cont .table input:checked').each(function(i) { item_ids.push($(this).attr('data-id')); }); aswal({ title: ASL_REMOTE.LANG.delete_logos, text: ASL_REMOTE.LANG.warn_question + " " + ASL_REMOTE.LANG.delete_logos + "?", type: "warning", showCancelButton: true, confirmButtonColor: "#dc3545", confirmButtonText: ASL_REMOTE.LANG.delete_it, }).then(function() { ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=delete_logo", { item_ids: item_ids, multiple: true }, function(_response) { toastIt(_response); if (_response.success) { table.fnDraw(); return; } }, 'json'); }); }); $("thead input").keyup(function(e) { if (e.keyCode == 13) { table.fnDraw(); } }); }, /** * [manage_cards description] * @return {[type]} [description] */ manage_cards: function() { var parent_row, updated_shortcode_str; function show_hide_table() { $('#tbl_shortcode tbody tr').each(function(i) { if ($(this).text().trim() == '') { $(this).remove(); } }); let shortcode_row = $('#tbl_shortcode tbody tr'); if (shortcode_row.length) { $('#tbl_shortcode').removeClass('d-none'); $('.no-shortcode').addClass('d-none'); } else { $('#tbl_shortcode').addClass('d-none'); $('.no-shortcode').removeClass('d-none'); } } function update_shortcode(data, parent_row = false) { ServerCall(ASL_REMOTE.URL + '?action=asl_ajax_handler&sl-action=cards_shortcode_presets', data, function(_response) { toastIt(_response); if (_response.success) { switch (data.db_action) { case 'add': $('#asl-add-card').smodal('hide'); var table_row = asl_configs.html.table_row.replace('the_shortcode', _response.data.replaceAll('\\', '')); $('#tbl_shortcode tbody').append(table_row); break; case 'delete': parent_row.remove(); break; case 'edit': parent_row.find('td:first-child span').text(_response.data.replaceAll('\\', '')); $('#asl-edit-card').smodal('hide'); break; } show_hide_table(); } }, 'json'); } // Switch template visibility according to template dropdown field function show_card_layout(modal) { const target_card = modal.find('.choose-card').val(); modal.find('.cards .card-preview').addClass('hide'); modal.find('.cards .' + target_card).removeClass('hide'); } // Scan through active modal and return toggled-off function get_hidden_fields(modal) { var hidden_fields = ''; const hidden_fields_obj = modal.find('.field-toggles .switch input:checkbox:not(:checked)'); hidden_fields_obj.each(function() { hidden_fields += $(this).data('target') + ','; }); if (hidden_fields.length) { hidden_fields = ' hide_fields="' + hidden_fields.replace(/,\s*$/, "") + '"'; } return hidden_fields; } // Scan through active modal and find filter fields function get_filters(modal) { var filter_fields = ''; const filter_fields_obj = modal.find('.asl_cardFilterBox .asl_cardFilterCtnBox'); filter_fields_obj.each(function() { if ($(this).find('select').val().length && $(this).find('input').val().length) { filter_fields += $(this).find('select').val() + '="' + $(this).find('input').val() + '" '; } }); if (filter_fields.length) { modal.find('.asl_noFilters').addClass('hide'); filter_fields = ' ' + filter_fields.trim(); } return filter_fields; } // Scan through active modal and find the selected template from the dropdown function get_card(modal) { const card_card = modal.find('.choose-card').val(); return ' card="' + card_card + '"'; } function get_use_slider(modal) { const user_slider_obj = modal.find('.use-slider input[type=checkbox]:checked'); if (user_slider_obj.length) { return ' slider="1"'; } return ''; } function get_heading_tag(modal) { const heading_tag = modal.find('.heading-tag').val(); return ' heading_tag="' + heading_tag + '"'; } function fields_to_shortcode(modal) { const card_layout = get_card(modal); const hidden_fields = get_hidden_fields(modal); const filters = get_filters(modal); const use_slider = get_use_slider(modal); const heading_tag = get_heading_tag(modal); updated_shortcode_str = '[ASL_CARDS' + hidden_fields + filters + card_layout + use_slider + heading_tag + ']'; } function shortcode_to_fields(existing_shortcode) { var filter_fields; var empty_field = asl_configs.html.filter_field; var field = ''; var modal = $('#asl-edit-card'); // Add empty filter field modal.find('.filter-fields-container').html(empty_field); // Show "No Filters are Applied" Text modal.find('.asl_noFilters').removeClass('hide'); // Reset All Filter Fields modal.find('.choose-card option:selected').attr('selected', false); // Reset All Toggles modal.find('.fields-toggle input[data-target]').attr('checked', true); modal.find('.use-slider input[type=checkbox]').attr('checked', false); modal.find('.asl_previewCard *[data-field]').removeClass('hide'); var attributes = existing_shortcode.replaceAll(']', ''); attributes = attributes.replaceAll('[ASL_CARDS ', ''); attributes = attributes.split('" '); var attribute; for (attribute of attributes) { attribute = attribute.split('="'); attribute[1] = attribute[1].replaceAll('"', ''); // Attribute Value if (attribute[0] == 'hide_fields') { var hide_fields_attr = attribute[1].split(','); modal.find('.fields-toggle > div').each(function() { var input_swt = $(this).find('.switch input'); var target = input_swt.attr('data-target'); if (hide_fields_attr.includes(target)) { input_swt.attr('checked', false); modal.find('.asl_previewCard *[data-field="' + target + '"]').addClass('hide'); } }); } else if (attribute[0] == 'heading_tag') { modal.find('.heading-tag option[value=' + attribute[1] + ']').attr('selected', true); } else if (attribute[0] == 'card') { modal.find('.choose-card option[value=' + attribute[1] + ']').attr('selected', true); } else if (attribute[0] == 'slider' && attribute[1]) { modal.find('.use-slider input[type=checkbox]').attr('checked', true); } else { field = empty_field; field = field.replace(''; $('#ddl-asl-logos').empty().ddslick('destroy'); $('#ddl-asl-logos').html(_HTML).ddslick({ //data: ddData, imagePosition: "right", selectText: "Select Logo", truncateDescription: true, defaultSelectedIndex: (_store) ? String(_store.logo_id) : null }); $('#addimagemodel').smodal('hide'); $form_upload.find('input:text, input:file').val(''); }); // UPLOAD MARKER IMAGE FILE var $form_marker = $('#frm-upload-marker'); app_engine.uploader($form_marker, url_to_upload + '?action=asl_ajax_handler&asl-nounce=' + ASL_REMOTE.nounce + '&sl-action=add_markers', function(_e, _data) { var data = _data.result; toastIt(data); if (data.success) { var _HTML = ''; for (var k in data.list) _HTML += ''; $('#ddl-asl-markers').empty().ddslick('destroy'); $('#ddl-asl-markers').html(_HTML).ddslick({ //data: ddData, imagePosition: "right", selectText: "Select marker", truncateDescription: true, defaultSelectedIndex: (_store) ? String(_store.marker_id) : null }); $('#addmarkermodel').smodal('hide'); $form_marker.find('.progress_bar_').hide(); $form_marker.find('input:text, input:file').val(''); } }); }, /** * [user_setting User Settings] * @param {[type]} _configs [description] * @return {[type]} [description] */ user_setting: function(_configs) { var $form = $('#frm-usersetting'); var _keys = Object.keys(_configs); /** * [set_tmpl_image Current Image Template] */ function set_tmpl_image() { var _tmpl = document.getElementById('asl-template').value, _lyout = document.getElementById('asl-layout').value; // Category accordion if(_lyout == '2') _lyout = '1'; var tmpl_name = (_tmpl == 'list' || _tmpl == 'list-2' || _tmpl == '4' || _tmpl == '5')? _tmpl: _tmpl + '-' + _lyout; $(document.getElementById('asl-tmpl-img')).attr('src', ASL_Instance.plugin_url + 'admin/images/asl-tmpl-' + tmpl_name + '.png'); // Hide the Layout control for the List Template if(_tmpl == 'list' || _tmpl == '4') $('.asl-p-cont .layout-section').addClass('hide'); else $('.asl-p-cont .layout-section').removeClass('hide'); } var radio_fields = ['additional_info', 'link_type', 'distance_unit', 'geo_button', 'time_format', 'week_hours', 'distance_control', 'single_cat_select', 'map_layout', 'infobox_layout', 'color_scheme', 'color_scheme_1', 'color_scheme_2', 'color_scheme_3', 'font_color_scheme','gdpr', 'tabs_layout', 'filter_ddl']; for (var i in _keys) { if (!_keys.hasOwnProperty(i)) continue; if (radio_fields.indexOf(_keys[i]) != -1) { var $elem = $form.find('#asl-' + _keys[i] + '-' + _configs[_keys[i]]); if($elem && $elem[0]) $elem[0].checked = true; continue; } var $elem = $form.find('#asl-' + _keys[i]); if($elem[0]) { if ($elem[0].type == 'checkbox') $elem[0].checked = (_configs[_keys[i]] == '0') ? false : true; else $elem.val(_configs[_keys[i]]); } } ///Make layout Active $('.asl-p-cont .layout-box img').eq($('#asl-template')[0].selectedIndex).addClass('active'); $('#asl-template').bind('change', function(e) { $('.asl-p-cont .layout-box img.active').removeClass('active'); $('.asl-p-cont .layout-box img').eq(this.selectedIndex).addClass('active'); }); // Filter_ddl if(_configs.filter_ddl) { $('#asl-filter_ddl').val(_configs.filter_ddl.split(',')); } // Chosen for the fitler_ddl $('#asl-filter_ddl').chosen({ width: "100%", placeholder_text_multiple: 'Select Filters', no_results_text: 'No Filter' }); // --------------------------------------------------------------- // slug_attr_ddl var $ddl_slug = $('#asl-slug_attr_ddl'), ddl_slug_values = []; if(_configs.slug_attr_ddl) { ddl_slug_values = _configs.slug_attr_ddl.split(','); $ddl_slug.val(ddl_slug_values); } // Chosen for the fitler_ddl_store $ddl_slug.chosen({ width: "100%", placeholder_text_multiple: 'Select Slugs', no_results_text: 'No Filter' }); $ddl_slug.on('change', function(evt, params) { // add the value if(params.selected) { ddl_slug_values.push(params.selected); } // remove the value else if(params.deselected) { ddl_slug_values = ddl_slug_values.filter(function(element) {return element !== params.deselected;}); } }); // --------------------------------------------------------------- /////*Validation Engine*///// $form.validationEngine({ binded: true, scroll: false }); // Main save button $('.btn-asl-user_setting').bind('click', function(e) { if (!$form.validationEngine('validate')) return; var $btn = $(this); $btn.bootButton('loading'); var all_data = { data: { show_categories: 0, advance_filter: 0, time_switch: 0, category_marker: 0, distance_slider: 0, analytics: 0, scroll_wheel: 0, target_blank: 0, user_center: 0, smooth_pan: 0, sort_by_bound: 0, full_width: 0, //filter_result:0, radius_circle: 0, remove_maps_script: 0, category_bound: 0, locale: 0, geo_marker: 0, sort_random: 0, and_filter: 0, fit_bound: 0, admin_notify: 0, lead_follow_up: 0, //cluster: 0, display_list: 0, store_schema: 0, hide_hours: 0, slug_link: 0, hide_logo: 0, direction_btn: 0, zoom_btn: 0, additional_info: 0, print_btn: 0, address_ddl: 0, branches: 0, store_schedule: 0, tran_lbl: 0, wpfrm_store_notify: 0, } }; var data = $form.ASLSerializeObject(); all_data = $.extend(all_data, data); // Save the custom Map all_data['map_style'] = document.getElementById('asl-map_layout_custom').value; // filter_ddl var filter_ddl = $('#asl-filter_ddl').val(); all_data['data[filter_ddl]'] = (filter_ddl && filter_ddl.length)? filter_ddl.join(','): ''; // slug_attr_ddl all_data['slug_attr_ddl'] = (ddl_slug_values && ddl_slug_values.length)? ddl_slug_values.join(','): ''; ServerCall(ASL_REMOTE.URL + '?action=asl_ajax_handler&sl-action=save_setting', all_data, function(_response) { $btn.bootButton('reset'); toastIt(_response); }, 'json'); }); // Reset Slug button $('#btn-asl-slug_reset').on('click', function(e) { var $btn = $(this); // Send an AJAX Request $btn.bootButton('loading'); ServerCall(ASL_REMOTE.URL + '?action=asl_ajax_handler&sl-action=reset_all_slugs', {}, function(_response) { $btn.bootButton('reset'); toastIt(_response); }, 'json'); }); ///////////////////////// // Create TMPL Editor // ///////////////////////// wp.codeEditor.initialize($('#sl-custom-template-textarea'), null); var $section_tmpl_select = $('#asl-customize-section'), $template_select = $('#asl-customize-template'); // Template List doesn't have Infobox $template_select.bind('change', function(e) { var customizer_options = ASL_Instance.tmpls[e.target.value]; // Clear old values $section_tmpl_select.empty(); if(customizer_options) { $.each(customizer_options.options, function(index, option) { const $optionElement = $("