expressCart/public/javascripts/admin.min.js

1 line
18 KiB
JavaScript
Raw Normal View History

2020-03-07 19:18:06 +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()})}$(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(),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){re