expressCart/public/javascripts/admin.min.js

1 line
18 KiB
JavaScript
Raw Normal View History

2020-01-28 16:51:07 +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="fal fa-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="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">${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="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");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")}})}$(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(),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</button>',n+="</div></div></li>",$("#product_opt_wrapper").append(n),i[t]={optName:t,optLabel:a,optType:o,optOptions:$.grep(s.split(","),function(e){return 0===e||e})},$("#productOptions").val(JSON.stringify(i)),$("#product_optName").val(""),$("#product_optLabel").val(""),$("#product_optOptions").val("")}),$("