2020-03-17 18:38:46 +10:00
|
|
|
function globalSearch(){$("#global-search-results").empty(),$.ajax({type:"POST",url:"/admin/searchall",data:{searchValue:$("#global-search-value").val()}}).done(e=>{$("#global-search").html('<i class="feather" data-feather="search"></i>');let t=!1;if(e.customers.forEach(e=>{t=!0;const a=`\n <li class="list-group-item global-result text-center" data-url="/admin/customer/view/${e._id}">\n <div class="row">\n <div class="col global-result-type gr-click"><i class="feather" data-feather="user"></i> Customer</div>\n <div class="col global-result-detail gr-click">${e.firstName} ${e.lastName}</div>\n <div class="col global-result-detail gr-click">${e.email}</div>\n </div>\n </li>`;$("#global-search-results").append(a)}),e.orders.forEach(e=>{t=!0;const a=`\n <li class="list-group-item global-result text-center" data-url="/admin/order/view/${e._id}">\n <div class="row">\n <div class="col global-result-type gr-click"><i class="feather" data-feather="package"></i> Order</div>\n <div class="col global-result-detail gr-click">${e.orderFirstname} ${e.orderLastname}</div>\n <div class="col global-result-detail gr-click">${moment(e.orderDate).format("YYYY/MM/DD")}</div>\n <div class="col global-result-detail gr-click">${e.orderEmail}</div>\n </div>\n </li>`;$("#global-search-results").append(a)}),e.products.forEach(e=>{t=!0;const a=`<li class="list-group-item global-result text-center" data-url="/admin/product/edit/${e._id}">\n <div class="row">\n <div class="col global-result-type gr-click"><i class="feather" data-feather="tag"></i> Product</div>\n <div class="col global-result-detail gr-click">${e.productTitle}</div>\n <div class="col global-result-detail gr-click">${$("#currencySymbol").val()}${numeral(e.productPrice).format("0.00")}</div>\n </div>\n </li>`;$("#global-search-results").append(a)}),!0===t)$("#global-search-results").removeClass("invisible");else{const e='<li class="list-group-item text-center">\n <div class="row">\n <div class="col global-result-type gr-click">Nothing found</div>\n </div>\n </li>';$("#global-search-results").append(e),$("#global-search-results").removeClass("invisible")}feather.replace()})}function validationErrors(e){var t="";return e.forEach(e=>{t+=`<p>${e.dataPath.replace("/","")} - <span class="text-danger">${e.message}<span></p>`}),t}$(document).ready(function(){if($.ajaxSetup({headers:{"csrf-token":$('meta[name="csrfToken"]').attr("content")}}),$(document).on("click","#btnGenerateAPIkey",function(e){e.preventDefault(),$.ajax({method:"POST",url:"/admin/createApiKey"}).done(function(e){$("#apiKey").val(e.apiKey),showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$(document).on("click",".product_opt_remove",function(e){e.preventDefault();var t=$(this).closest("li").find(".opt-name").html();$.ajax({method:"POST",url:"/admin/product/removeoption",data:{productId:$("#productId").val(),optName:t}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$(document).on("click","#product_opt_add",function(e){e.preventDefault();var t=$("#product_optName").val(),a=$("#product_optLabel").val(),o=$("#product_optType").val(),s=$("#product_optOptions").val(),i={};""!==$("#productOptions").val()&&'"{}"'!==$("#productOptions").val()&&(i=JSON.parse($("#productOptions").val()));var n='<li class="list-group-item">';n+='<div class="row">',n+='<div class="col-sm-2 opt-name">'+t+"</div>",n+='<div class="col-sm-2">'+a+"</div>",n+='<div class="col-sm-2">'+o+"</div>",n+='<div class="col-sm-4">'+s+"</div>",n+='<div class="col-sm-2 text-right">',n+='<button class="product_opt_remove btn btn-outline-danger">Remove
|