',
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 = $("