var asl_engine = window['asl_engine'] || {}; (function($, app_engine) { 'use strict'; /** * [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); } }; app_engine['pages'] = { /** * [dashboard Main Dashboard page] * @return {[type]} [description] */ dashboard: function() { var current_date = 0, date_ = new Date(); var day_arr = []; var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], month = months[date_.getMonth()], data_arr = []; // Tabs switch $('.asl-p-cont .nav-tabs a').click(function(e) { e.preventDefault() $(this).tab('show'); }); // add dummy data for (var a = 1; a <= date_.getDate(); a++) { day_arr.push(a + ' ' + month); data_arr.push(0); } var lineChartData = { labels: day_arr, datasets: [{ tension: 0.1, lineTension: 0.1, backgroundColor: "rgba(75, 192, 192, 0.4)", borderColor: "rgba(75, 192, 192, 1", borderCapStyle: 'butt', borderDash: [], borderDashOffset: 0.0, borderJoinStyle: 'miter', pointBorderColor: "rgba(75, 192, 192, 1)", pointBackgroundColor: "#fff", pointBorderWidth: 1, pointHoverRadius: 5, pointHoverBackgroundColor: "rgba(75, 192, 192, 1)", pointHoverBorderColor: "rgba(220, 220, 220, 1)", pointHoverBorderWidth: 2, pointRadius: 1, pointHitRadius: 10, label: 'Searches', backgroundColor: "#57C8F2", data: data_arr }] }; asl_initialize_chart(); // Datetime var $datepicker = $('#sl-datetimepicker'); /** * [get_duration_string Return the duration string used for the AJAX] * @return {[type]} [description] */ function get_duration_string() { var dt_data = $datepicker.data('daterangepicker'); return encodeURI('sl-start=' + dt_data.startDate.format('YYYY-MM-DD') + '&sl-end=' + dt_data.endDate.format('YYYY-MM-DD')); }; ///////////////////////////////// // Change the expertise level // ///////////////////////////////// var $sl_level = $('#asl-level-swtch'); /** * [update_level description] * @param {[type]} _status [description] */ function update_level(_status, _callback) { ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=expertise_level", {status: $sl_level[0].checked? '1': '0'}, function(_response) { toastIt(_response); if(_callback) { _callback(_response); } window.setTimeout(function(){ window.location.reload(); }, 1500); }, 'json'); }; // Cache Switch Event $sl_level.bind('change', function(e) { var chk_ctrl = e.target, status = (chk_ctrl.checked)? '1': '0'; update_level(status); }); ////////////////////////// // Backup the Template // ////////////////////////// $('#sl-btn-tmpl-backup').bind('click', function(e) { aswal({ title: ASL_REMOTE.LANG.backup_tmpl, type: 'question', html: '
'+ ASL_REMOTE.LANG.backup_tmpl_msg + '
' + '', showCancelButton: true, confirmButtonColor: "#dc3545", confirmButtonText: ASL_REMOTE.LANG.backup, preConfirm: function(_value) { var _value = $('#sl-tmpl-section-1').val(); return new Promise(function(resolve, reject) { aswal.showLoading(); ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=backup_tmpl", { template: _value }, function(_response) { aswal.close(); toastIt(_response); }, 'json'); }) } }); }); // Export the leads $('#sl-btn-export-stats').bind('click', function() { window.location.href = ASL_REMOTE.URL + "?action=asl_ajax_handler&asl-nounce=" + ASL_REMOTE.nounce + "&sl-action=export_stats&" + get_duration_string(); }); // Remove the Template $('#sl-btn-tmpl-remove').bind('click', function(e) { aswal({ title: ASL_REMOTE.LANG.remove_tmpl, text: ASL_REMOTE.LANG.remove_tmpl_msg, type: 'question', html: '', showCancelButton: true, confirmButtonColor: "#dc3545", confirmButtonText: ASL_REMOTE.LANG.remove, preConfirm: function(_value) { var _value = $('#sl-tmpl-section-2').val(); return new Promise(function(resolve, reject) { aswal.showLoading(); ServerCall(ASL_REMOTE.URL + "?action=asl_ajax_handler&sl-action=remove_tmpl", { template: _value }, function(_response) { aswal.close(); toastIt(_response); }, 'json'); }) } }); }); ///////////bar chart var ctx = document.getElementById("asl_search_canvas").getContext("2d"), charts_option = { type: 'line', data: lineChartData, options: { bezierCurve: true, animation: true, responsive: true, maintainAspectRatio: false, title: { display: true, text: '#Searches' }, scales: { y: { suggestedMin: 0, ticks: { beginAtZero: true } } } } }; var myBar = new Chart(ctx, charts_option); Chart.defaults.scales.linear.min = 0; /** * [updateChart Get the Stats Chart] * @return {[type]} [description] */ function updateChart(_chart_data) { var temp_keys = [], temp_vals = []; for (var k in _chart_data) { temp_keys.push(_chart_data[k]['label']); temp_vals.push(_chart_data[k]['data']); } myBar.config.data.labels = temp_keys; myBar.config.data.datasets[0].data = temp_vals; myBar.update(); }; // //updateChart(m, y); /** * [getViews Get the Stores Views and Search] * @return {[type]} [description] */ function getViews(stores_views, search_views) { // Clear old records jQuery('#asl-stores-views li').remove(); jQuery('#asl-searches-views li').remove(); /////////////////////////////// // Iterate to fill the list // /////////////////////////////// var stores_views_html = ''; if (stores_views && stores_views.length) { for (var s = 0; s < stores_views.length; s++) { var _store_view = stores_views[s]; stores_views_html += `