expressCart/public/javascripts/admin.min.js

1 line
18 KiB
JavaScript
Raw Normal View History

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="fal fa-search"></i>');let t=!1;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="fas fa-users"></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="fas fa-cube"></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">${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="fas fa-box-open"></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")})}$(document).ready(function(){if($(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(),i=$("#product_optOptions").val(),s={};""!==$("#productOptions").val()&&'"{}"'!==$("#productOptions").val()&&(s=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">'+i+"</div>",n+='<div class="col-sm-2 text-right">',n+='<button class="product_opt_remove btn btn-outline-danger">Remove</button>',n+="</div></div></li>",$("#product_opt_wrapper").append(n),s[t]={optName:t,optLabel:a,optType:o,optOptions:$.grep(i.split(","),function(e){return 0===e||e})},$("#productOptions").val(JSON.stringify(s)),$("#product_optName").val(""),$("#product_optLabel").val(""),$("#product_optOptions").val("")}),$("#settingsForm").validator().on("submit",function(e){e.isDefaultPrevented()||(e.preventDefault(),$("#footerHtml_input").val($(".CodeMirror")[0].CodeMirror.getValue()),$("#googleAnalytics_input").val($(".CodeMirror")[1].CodeMirror.getValue()),$("#customCss_input").val($(".CodeMirror")[2].CodeMirror.getValue()),$.ajax({method:"POST",url:"/admin/settings/update",data:$("#settingsForm").serialize()}).done(function(e){showNotification