diff --git a/lib/common.js b/lib/common.js index 4972300..4c9c58f 100755 --- a/lib/common.js +++ b/lib/common.js @@ -643,6 +643,13 @@ const getCountryList = () => { return countryArray; }; +const cleanAmount = (amount) => { + if(amount){ + return parseInt(amount.toString().replace('.', '')); + } + return amount; +}; + module.exports = { allowedMimeType, fileSizeLimit, @@ -676,5 +683,6 @@ module.exports = { newId, getData, hooker, - getCountryList + getCountryList, + cleanAmount }; diff --git a/public/javascripts/admin.js b/public/javascripts/admin.js index 2665625..bc62b3f 100644 --- a/public/javascripts/admin.js +++ b/public/javascripts/admin.js @@ -1,5 +1,5 @@ /* eslint-disable prefer-arrow-callback, no-var, no-tabs */ -/* globals showNotification, slugify */ +/* globals showNotification, slugify, numeral */ $(document).ready(function (){ $(document).on('click', '#btnGenerateAPIkey', function(e){ e.preventDefault(); @@ -646,4 +646,78 @@ $(document).ready(function (){ showNotification(msg.responseJSON.message, 'danger'); }); }); + + $('#global-search-value').on('keyup', (e) => { + if($('#global-search-value').val() === ''){ + $('#global-search-results').empty(); + $('#global-search-results').addClass('invisible'); + } + // Search when 3 or more characters are entered + if($('#global-search-value').val().length > 3){ + $('#global-search').html(''); + globalSearch(); + } + }); + + $('#globalSearchModal').on('shown.bs.modal', function (){ + $('#global-search-value').focus(); + }); + + $('body').on('click', '.gr-click', (e) => { + $('#global-search-value').val(); + const url = $(e.currentTarget).closest('.global-result').attr('data-url'); + if(url){ + window.location = url; + } + }); }); + +function globalSearch(){ + $('#global-search-results').empty(); + $.ajax({ + type: 'POST', + url: '/admin/searchall', + data: { + searchValue: $('#global-search-value').val() + } + }).done((res) => { + $('#global-search').html(''); + let hasResult = false; + res.customers.forEach((value) => { + hasResult = true; + let result = '
  • '; + result += '
    '; + result += '
    Customer
    '; + result += '
    ' + value.firstName + ' ' + value.lastName + '
    '; + result += '
    ' + value.email + '
    '; + result += '
  • '; + $('#global-search-results').append(result); + }); + + res.orders.forEach((value) => { + hasResult = true; + let result = '
  • '; + result += '
    '; + result += '
    Order
    '; + result += '
    ' + value.orderFirstname + ' ' + value.orderLastname + '
    '; + result += '
    ' + value.orderEmail + '
    '; + result += '
  • '; + $('#global-search-results').append(result); + }); + + res.products.forEach((value) => { + hasResult = true; + let result = '
  • '; + result += '
    '; + result += '
    Product
    '; + result += '
    ' + value.productTitle + '
    '; + result += '
    ' + numeral(value.productPrice).format('0.00') + '
    '; + result += '
  • '; + $('#global-search-results').append(result); + }); + + if(hasResult === true){ + $('#global-search-results').removeClass('invisible'); + } + }); +} diff --git a/public/javascripts/admin.min.js b/public/javascripts/admin.min.js index aa6cf3b..40f72a0 100644 --- a/public/javascripts/admin.min.js +++ b/public/javascripts/admin.min.js @@ -1 +1 @@ -$(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(),o=$("#product_optLabel").val(),a=$("#product_optType").val(),n=$("#product_optOptions").val(),i={};""!==$("#productOptions").val()&&'"{}"'!==$("#productOptions").val()&&(i=JSON.parse($("#productOptions").val()));var s='
  • ';s+='
    ',s+='
    '+t+"
    ",s+='
    '+o+"
    ",s+='
    '+a+"
    ",s+='
    '+n+"
    ",s+='
    ',s+='',s+="
  • ",$("#product_opt_wrapper").append(s),i[t]={optName:t,optLabel:o,optType:a,optOptions:$.grep(n.split(","),function(e){return 0===e||e})},$("#productOptions").val(JSON.stringify(i)),$("#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(e.message,"success")}).fail(function(e){showNotification(e.responseJSON.message,"danger")}))}),$(document).on("click","#orderStatusUpdate",function(e){$.ajax({method:"POST",url:"/admin/order/statusupdate",data:{order_id:$("#order_id").val(),status:$("#orderStatus").val()}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$("#userNewForm").validator().on("submit",function(e){e.isDefaultPrevented()||(e.preventDefault(),$.ajax({method:"POST",url:"/admin/user/insert",data:{usersName:$("#usersName").val(),userEmail:$("#userEmail").val(),userPassword:$("#userPassword").val()}}).done(function(e){showNotification(e.message,"success",!1,"/admin/user/edit/"+e.userId)}).fail(function(e){showNotification(e.responseJSON.message,"danger")}))}),$(".userDelete").on("click",function(){confirm("Are you sure you want to delete?")&&$.ajax({method:"POST",url:"/admin/user/delete",data:{userId:$(this).attr("data-id")}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$("#userEditForm").validator().on("submit",function(e){e.isDefaultPrevented()||(e.preventDefault(),$.ajax({method:"POST",url:"/admin/user/update",data:{userId:$("#userId").val(),usersName:$("#usersName").val(),userEmail:$("#userEmail").val(),userPassword:$("#userPassword").val(),userAdmin:$("#userPassword").is(":checked")}}).done(function(e){showNotification(e.message,"success")}).fail(function(e){showNotification(e.responseJSON.message,"danger")}))}),$("#productNewForm").validator().on("submit",function(e){e.isDefaultPrevented()||(e.preventDefault(),""===$("#productPermalink").val()&&""!==$("#productTitle").val()&&$("#productPermalink").val(slugify($("#productTitle").val())),$.ajax({method:"POST",url:"/admin/product/insert",data:{productTitle:$("#productTitle").val(),productPrice:$("#productPrice").val(),productPublished:$("#productPublished").val(),productStock:$("#productStock").val(),productDescription:$("#productDescription").val(),productPermalink:$("#productPermalink").val(),productOptions:$("#productOptions").val(),productSubscription:$("#productSubscription").val(),productComment:$("#productComment").is(":checked"),productTags:$("#productTags").val()}}).done(function(e){showNotification(e.message,"success",!1,"/admin/product/edit/"+e.productId)}).fail(function(e){showNotification(e.responseJSON.message,"danger")}))}),$("#productEditForm").validator().on("submit",function(e){e.isDefaultPrevented()||(e.preventDefault(),""===$("#productPermalink").val()&&""!==$("#productTitle").val()&&$("#productPermalink").val(slugify($("#productTitle").val())),$.ajax({method:"POST",url:"/admin/product/update",data:{productId:$("#productId").val(),productTitle:$("#productTitle").val(),productPrice:$("#productPrice").val(),productPublished:$("#productPublished").val(),productStock:$("#productStock").val(),productDescription:$("#productDescription").val(),productPermalink:$("#productPermalink").val(),productOptions:$("#productOptions").val(),productSubscription:$("#productSubscription").val(),productComment:$("#productComment").is(":checked"),productTags:$("#productTags").val()}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")}))}),$(".set-as-main-image").on("click",function(){$.ajax({method:"POST",url:"/admin/product/setasmainimage",data:{product_id:$("#productId").val(),productImage:$(this).attr("data-id")}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$(".btn-delete-image").on("click",function(){confirm("Are you sure you want to delete this image?")&&$.ajax({method:"POST",url:"/admin/product/deleteimage",data:{product_id:$("#productId").val(),productImage:$(this).attr("data-id")}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$(".btn-delete-product").on("click",function(){confirm("Are you sure you want to delete this product?")&&$.ajax({method:"POST",url:"/admin/product/delete",data:{productId:$(this).attr("data-id")}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$(document).on("click","#validate_permalink",function(e){""!==$("#productPermalink").val()?$.ajax({method:"POST",url:"/admin/api/validate_permalink",data:{permalink:$("#productPermalink").val(),docId:$("#productId").val()}}).done(function(e){showNotification(e.message,"success")}).fail(function(e){showNotification(e.responseJSON.message,"danger")}):showNotification("Please enter a permalink to validate","danger")}),$(document).on("click","#btn_product_filter",function(e){""!==$("#product_filter").val()?window.location.href="/admin/products/filter/"+$("#product_filter").val():showNotification("Please enter a keyword to filter","danger")}),$(document).on("click","#btn_order_filter",function(e){""!==$("#order_filter").val()?window.location.href="/admin/orders/filter/"+$("#order_filter").val():showNotification("Please enter a keyword to filter","danger")}),$(document).on("click","#btn_customer_filter",function(e){""!==$("#customer_filter").val()?window.location.href="/admin/customers/filter/"+$("#customer_filter").val():showNotification("Please enter a keyword to filter","danger")}),$(document).on("click","#lookupCustomer",function(e){e.preventDefault(),$.ajax({method:"POST",url:"/admin/customer/lookup",data:{customerEmail:$("#customerEmail").val()}}).done(function(e){showNotification(e.message,"success"),$("#orderFirstName").val(e.customer.firstName),$("#orderLastName").val(e.customer.lastName),$("#orderAddress1").val(e.customer.address1),$("#orderAddress2").val(e.customer.address2),$("#orderCountry").val(e.customer.country),$("#orderState").val(e.customer.state),$("#orderPostcode").val(e.customer.postcode),$("#orderPhone").val(e.customer.phone)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$(document).on("click","#orderCreate",function(e){e.preventDefault(),0===$("#createOrderForm").validator("validate").has(".has-error").length&&$.ajax({method:"POST",url:"/admin/order/create",data:{orderStatus:$("#orderStatus").val(),email:$("#customerEmail").val(),firstName:$("#orderFirstName").val(),lastName:$("#orderLastName").val(),address1:$("#orderAddress1").val(),address2:$("#orderAddress2").val(),country:$("#orderCountry").val(),state:$("#orderState").val(),postcode:$("#orderPostcode").val(),phone:$("#orderPhone").val(),orderComment:$("#orderComment").val()}}).done(function(e){showNotification(e.message,"success"),window.location=`/admin/order/view/${e.orderId}`}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$("#sendTestEmail").on("click",function(e){e.preventDefault(),$.ajax({method:"POST",url:"/admin/testEmail"}).done(function(e){showNotification(e,"success")}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$(document).on("click",".orderFilterByStatus",function(e){e.preventDefault(),window.location="/admin/orders/bystatus/"+$("#orderStatusFilter").val()}),$('input[class="published_state"]').change(function(){$.ajax({method:"POST",url:"/admin/product/published_state",data:{id:this.id,state:this.checked}}).done(function(e){showNotification(e.message,"success")}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$("#updateCustomer").validator().on("click",function(e){e.preventDefault(),0===$("#customer-form").validator("validate").has(".has-error").length&&$.ajax({method:"POST",url:"/admin/customer/update",data:{customerId:$("#customerId").val(),email:$("#email").val(),firstName:$("#firstName").val(),lastName:$("#lastName").val(),address1:$("#address1").val(),address2:$("#address2").val(),country:$("#country").val(),state:$("#state").val(),postcode:$("#postcode").val(),phone:$("#phone").val()}}).done(function(e){showNotification(e.message,"success")}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$("#deleteCustomer").on("click",function(e){e.preventDefault(),$.ajax({method:"DELETE",url:"/admin/customer",data:{customerId:$("#customerId").val()}}).done(function(e){showNotification(e.message,"success",!1,"/admin/customers")}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$("#footerHtml").length){var e=window.CodeMirror.fromTextArea(document.getElementById("footerHtml"),{mode:"xml",tabMode:"indent",theme:"flatly",lineNumbers:!0,htmlMode:!0,fixedGutter:!1});e.setValue(e.getValue())}if($("#googleAnalytics").length&&window.CodeMirror.fromTextArea(document.getElementById("googleAnalytics"),{mode:"xml",tabMode:"indent",theme:"flatly",lineNumbers:!0,htmlMode:!0,fixedGutter:!1}),$("#customCss").length){var t=window.CodeMirror.fromTextArea(document.getElementById("customCss"),{mode:"text/css",tabMode:"indent",theme:"flatly",lineNumbers:!0}),o=window.cssbeautify(t.getValue(),{indent:" ",autosemicolon:!0});t.setValue(o)}$(document).on("click","#btnPageUpdate",function(e){e.preventDefault(),$.ajax({method:"POST",url:"/admin/settings/page",data:{pageId:$("#pageId").val(),pageName:$("#pageName").val(),pageSlug:$("#pageSlug").val(),pageEnabled:$("#pageEnabled").is(":checked"),pageContent:$("#pageContent").val()}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$(document).on("click","#btnPageDelete",function(e){e.preventDefault(),confirm("Are you sure?")&&$.ajax({method:"POST",url:"/admin/settings/page/delete",data:{pageId:$(this).attr("data-id")}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.message,"danger",!0)})}),$(document).on("click","#settings-menu-new",function(e){e.preventDefault(),$.ajax({method:"POST",url:"/admin/settings/menu/new",data:{navMenu:$("#newNavMenu").val(),navLink:$("#newNavLink").val()}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.message,"danger",!0)})}),$(document).on("click","#settings-menu-update",function(e){e.preventDefault();var t=$(this).attr("data-id"),o=$("#menuId-"+t);$.ajax({method:"POST",url:"/admin/settings/menu/update",data:{navId:o.find(".navId").val(),navMenu:o.find(".navMenu").val(),navLink:o.find(".navLink").val()}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.message,"danger",!0)})}),$(document).on("click",".settings-menu-delete",function(e){e.preventDefault(),confirm("Are you sure?")&&$.ajax({method:"POST",url:"/admin/settings/menu/delete",data:{menuId:$(this).attr("data-id")}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.message,"danger",!0)})}),$("#draggable_list").length&&$("#draggable_list").sortable({update:function(){var e=[];$(".navId").each(function(t){e.push($($(".navId")[t]).val())}),$.ajax({data:{order:e},type:"POST",url:"/admin/settings/menu/save_order"}).done(function(){showNotification("Menu order saved","success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger",!0)})}}),$(document).on("click","#uploadButton",function(e){e.preventDefault();var t=new FormData($("#uploadForm")[0]);t.append("productId",$("#productId").val()),$.ajax({method:"POST",url:"/admin/file/upload",processData:!1,contentType:!1,cache:!1,data:t}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})})}); \ No newline at end of file +function globalSearch(){$("#global-search-results").empty(),$.ajax({type:"POST",url:"/admin/searchall",data:{searchValue:$("#global-search-value").val()}}).done(e=>{$("#global-search").html('');let t=!1;e.customers.forEach(e=>{t=!0;let a='
  • ';a+='
    ',a+='
    Customer
    ',a+='
    '+e.firstName+" "+e.lastName+"
    ",a+='
    '+e.email+"
    ",a+="
  • ",$("#global-search-results").append(a)}),e.orders.forEach(e=>{t=!0;let a='
  • ';a+='
    ',a+='
    Order
    ',a+='
    '+e.orderFirstname+" "+e.orderLastname+"
    ",a+='
    '+e.orderEmail+"
    ",a+="
  • ",$("#global-search-results").append(a)}),e.products.forEach(e=>{t=!0;let a='
  • ';a+='
    ',a+='
    Product
    ',a+='
    '+e.productTitle+"
    ",a+='
    '+numeral(e.productPrice).format("0.00")+"
    ",a+="
  • ",$("#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(),s=$("#product_optOptions").val(),i={};""!==$("#productOptions").val()&&'"{}"'!==$("#productOptions").val()&&(i=JSON.parse($("#productOptions").val()));var n='
  • ';n+='
    ',n+='
    '+t+"
    ",n+='
    '+a+"
    ",n+='
    '+o+"
    ",n+='
    '+s+"
    ",n+='
    ',n+='',n+="
  • ",$("#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("")}),$("#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(e.message,"success")}).fail(function(e){showNotification(e.responseJSON.message,"danger")}))}),$(document).on("click","#orderStatusUpdate",function(e){$.ajax({method:"POST",url:"/admin/order/statusupdate",data:{order_id:$("#order_id").val(),status:$("#orderStatus").val()}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$("#userNewForm").validator().on("submit",function(e){e.isDefaultPrevented()||(e.preventDefault(),$.ajax({method:"POST",url:"/admin/user/insert",data:{usersName:$("#usersName").val(),userEmail:$("#userEmail").val(),userPassword:$("#userPassword").val()}}).done(function(e){showNotification(e.message,"success",!1,"/admin/user/edit/"+e.userId)}).fail(function(e){showNotification(e.responseJSON.message,"danger")}))}),$(".userDelete").on("click",function(){confirm("Are you sure you want to delete?")&&$.ajax({method:"POST",url:"/admin/user/delete",data:{userId:$(this).attr("data-id")}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$("#userEditForm").validator().on("submit",function(e){e.isDefaultPrevented()||(e.preventDefault(),$.ajax({method:"POST",url:"/admin/user/update",data:{userId:$("#userId").val(),usersName:$("#usersName").val(),userEmail:$("#userEmail").val(),userPassword:$("#userPassword").val(),userAdmin:$("#userPassword").is(":checked")}}).done(function(e){showNotification(e.message,"success")}).fail(function(e){showNotification(e.responseJSON.message,"danger")}))}),$("#productNewForm").validator().on("submit",function(e){e.isDefaultPrevented()||(e.preventDefault(),""===$("#productPermalink").val()&&""!==$("#productTitle").val()&&$("#productPermalink").val(slugify($("#productTitle").val())),$.ajax({method:"POST",url:"/admin/product/insert",data:{productTitle:$("#productTitle").val(),productPrice:$("#productPrice").val(),productPublished:$("#productPublished").val(),productStock:$("#productStock").val(),productDescription:$("#productDescription").val(),productPermalink:$("#productPermalink").val(),productOptions:$("#productOptions").val(),productSubscription:$("#productSubscription").val(),productComment:$("#productComment").is(":checked"),productTags:$("#productTags").val()}}).done(function(e){showNotification(e.message,"success",!1,"/admin/product/edit/"+e.productId)}).fail(function(e){showNotification(e.responseJSON.message,"danger")}))}),$("#productEditForm").validator().on("submit",function(e){e.isDefaultPrevented()||(e.preventDefault(),""===$("#productPermalink").val()&&""!==$("#productTitle").val()&&$("#productPermalink").val(slugify($("#productTitle").val())),$.ajax({method:"POST",url:"/admin/product/update",data:{productId:$("#productId").val(),productTitle:$("#productTitle").val(),productPrice:$("#productPrice").val(),productPublished:$("#productPublished").val(),productStock:$("#productStock").val(),productDescription:$("#productDescription").val(),productPermalink:$("#productPermalink").val(),productOptions:$("#productOptions").val(),productSubscription:$("#productSubscription").val(),productComment:$("#productComment").is(":checked"),productTags:$("#productTags").val()}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")}))}),$(".set-as-main-image").on("click",function(){$.ajax({method:"POST",url:"/admin/product/setasmainimage",data:{product_id:$("#productId").val(),productImage:$(this).attr("data-id")}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$(".btn-delete-image").on("click",function(){confirm("Are you sure you want to delete this image?")&&$.ajax({method:"POST",url:"/admin/product/deleteimage",data:{product_id:$("#productId").val(),productImage:$(this).attr("data-id")}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$(".btn-delete-product").on("click",function(){confirm("Are you sure you want to delete this product?")&&$.ajax({method:"POST",url:"/admin/product/delete",data:{productId:$(this).attr("data-id")}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$(document).on("click","#validate_permalink",function(e){""!==$("#productPermalink").val()?$.ajax({method:"POST",url:"/admin/api/validate_permalink",data:{permalink:$("#productPermalink").val(),docId:$("#productId").val()}}).done(function(e){showNotification(e.message,"success")}).fail(function(e){showNotification(e.responseJSON.message,"danger")}):showNotification("Please enter a permalink to validate","danger")}),$(document).on("click","#btn_product_filter",function(e){""!==$("#product_filter").val()?window.location.href="/admin/products/filter/"+$("#product_filter").val():showNotification("Please enter a keyword to filter","danger")}),$(document).on("click","#btn_order_filter",function(e){""!==$("#order_filter").val()?window.location.href="/admin/orders/filter/"+$("#order_filter").val():showNotification("Please enter a keyword to filter","danger")}),$(document).on("click","#btn_customer_filter",function(e){""!==$("#customer_filter").val()?window.location.href="/admin/customers/filter/"+$("#customer_filter").val():showNotification("Please enter a keyword to filter","danger")}),$(document).on("click","#lookupCustomer",function(e){e.preventDefault(),$.ajax({method:"POST",url:"/admin/customer/lookup",data:{customerEmail:$("#customerEmail").val()}}).done(function(e){showNotification(e.message,"success"),$("#orderFirstName").val(e.customer.firstName),$("#orderLastName").val(e.customer.lastName),$("#orderAddress1").val(e.customer.address1),$("#orderAddress2").val(e.customer.address2),$("#orderCountry").val(e.customer.country),$("#orderState").val(e.customer.state),$("#orderPostcode").val(e.customer.postcode),$("#orderPhone").val(e.customer.phone)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$(document).on("click","#orderCreate",function(e){e.preventDefault(),0===$("#createOrderForm").validator("validate").has(".has-error").length&&$.ajax({method:"POST",url:"/admin/order/create",data:{orderStatus:$("#orderStatus").val(),email:$("#customerEmail").val(),firstName:$("#orderFirstName").val(),lastName:$("#orderLastName").val(),address1:$("#orderAddress1").val(),address2:$("#orderAddress2").val(),country:$("#orderCountry").val(),state:$("#orderState").val(),postcode:$("#orderPostcode").val(),phone:$("#orderPhone").val(),orderComment:$("#orderComment").val()}}).done(function(e){showNotification(e.message,"success"),window.location=`/admin/order/view/${e.orderId}`}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$("#sendTestEmail").on("click",function(e){e.preventDefault(),$.ajax({method:"POST",url:"/admin/testEmail"}).done(function(e){showNotification(e,"success")}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$(document).on("click",".orderFilterByStatus",function(e){e.preventDefault(),window.location="/admin/orders/bystatus/"+$("#orderStatusFilter").val()}),$('input[class="published_state"]').change(function(){$.ajax({method:"POST",url:"/admin/product/published_state",data:{id:this.id,state:this.checked}}).done(function(e){showNotification(e.message,"success")}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$("#updateCustomer").validator().on("click",function(e){e.preventDefault(),0===$("#customer-form").validator("validate").has(".has-error").length&&$.ajax({method:"POST",url:"/admin/customer/update",data:{customerId:$("#customerId").val(),email:$("#email").val(),firstName:$("#firstName").val(),lastName:$("#lastName").val(),address1:$("#address1").val(),address2:$("#address2").val(),country:$("#country").val(),state:$("#state").val(),postcode:$("#postcode").val(),phone:$("#phone").val()}}).done(function(e){showNotification(e.message,"success")}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$("#deleteCustomer").on("click",function(e){e.preventDefault(),$.ajax({method:"DELETE",url:"/admin/customer",data:{customerId:$("#customerId").val()}}).done(function(e){showNotification(e.message,"success",!1,"/admin/customers")}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$("#footerHtml").length){var e=window.CodeMirror.fromTextArea(document.getElementById("footerHtml"),{mode:"xml",tabMode:"indent",theme:"flatly",lineNumbers:!0,htmlMode:!0,fixedGutter:!1});e.setValue(e.getValue())}if($("#googleAnalytics").length&&window.CodeMirror.fromTextArea(document.getElementById("googleAnalytics"),{mode:"xml",tabMode:"indent",theme:"flatly",lineNumbers:!0,htmlMode:!0,fixedGutter:!1}),$("#customCss").length){var t=window.CodeMirror.fromTextArea(document.getElementById("customCss"),{mode:"text/css",tabMode:"indent",theme:"flatly",lineNumbers:!0}),a=window.cssbeautify(t.getValue(),{indent:" ",autosemicolon:!0});t.setValue(a)}$(document).on("click","#btnPageUpdate",function(e){e.preventDefault(),$.ajax({method:"POST",url:"/admin/settings/page",data:{pageId:$("#pageId").val(),pageName:$("#pageName").val(),pageSlug:$("#pageSlug").val(),pageEnabled:$("#pageEnabled").is(":checked"),pageContent:$("#pageContent").val()}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$(document).on("click","#btnPageDelete",function(e){e.preventDefault(),confirm("Are you sure?")&&$.ajax({method:"POST",url:"/admin/settings/page/delete",data:{pageId:$(this).attr("data-id")}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.message,"danger",!0)})}),$(document).on("click","#settings-menu-new",function(e){e.preventDefault(),$.ajax({method:"POST",url:"/admin/settings/menu/new",data:{navMenu:$("#newNavMenu").val(),navLink:$("#newNavLink").val()}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.message,"danger",!0)})}),$(document).on("click","#settings-menu-update",function(e){e.preventDefault();var t=$(this).attr("data-id"),a=$("#menuId-"+t);$.ajax({method:"POST",url:"/admin/settings/menu/update",data:{navId:a.find(".navId").val(),navMenu:a.find(".navMenu").val(),navLink:a.find(".navLink").val()}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.message,"danger",!0)})}),$(document).on("click",".settings-menu-delete",function(e){e.preventDefault(),confirm("Are you sure?")&&$.ajax({method:"POST",url:"/admin/settings/menu/delete",data:{menuId:$(this).attr("data-id")}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.message,"danger",!0)})}),$("#draggable_list").length&&$("#draggable_list").sortable({update:function(){var e=[];$(".navId").each(function(t){e.push($($(".navId")[t]).val())}),$.ajax({data:{order:e},type:"POST",url:"/admin/settings/menu/save_order"}).done(function(){showNotification("Menu order saved","success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger",!0)})}}),$(document).on("click","#uploadButton",function(e){e.preventDefault();var t=new FormData($("#uploadForm")[0]);t.append("productId",$("#productId").val()),$.ajax({method:"POST",url:"/admin/file/upload",processData:!1,contentType:!1,cache:!1,data:t}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}),$("#global-search-value").on("keyup",e=>{""===$("#global-search-value").val()&&($("#global-search-results").empty(),$("#global-search-results").addClass("invisible")),$("#global-search-value").val().length>3&&($("#global-search").html(''),globalSearch())}),$("#globalSearchModal").on("shown.bs.modal",function(){$("#global-search-value").focus()}),$("body").on("click",".gr-click",e=>{$("#global-search-value").val();const t=$(e.currentTarget).closest(".global-result").attr("data-url");t&&(window.location=t)})}); \ No newline at end of file diff --git a/public/stylesheets/admin.css b/public/stylesheets/admin.css index d650632..3365450 100644 --- a/public/stylesheets/admin.css +++ b/public/stylesheets/admin.css @@ -109,6 +109,50 @@ body .popover { color: #838b8f; font-size: 20px; } +.global-result-type { + color: #8d8d8d; +} +.global-result:hover { + background-color: #007bff; +} +.global-result:hover .global-result-detail, +.global-result:hover .global-result-type, +.global-result:hover .global-result-type .fal { + color: #fff !important; +} +.global-result a { + text-decoration: none !important; +} +.global-result:hover { + cursor: pointer; +} +.global-result:first-child { + border-top-left-radius: 0; + border-top-right-radius: 0; +} +.global-result { + border-left: 0; + border-right: 0; +} +.global-search-modal-content, +.global-search-modal-header { + background-color: transparent; + border: none; +} +#global-search-results { + padding-right: 0; + border-bottom-left-radius: 0.3rem; + border-bottom-right-radius: 0.3rem; +} +.global-search-form { + margin-bottom: 0; +} +#global-search-value { + border-bottom-right-radius: 0; +} +.search-input-addon { + border-bottom-left-radius: 0; +} @media only screen and (max-width: 768px) { .navbar-default .navbar-brand { padding-top: 10px; diff --git a/public/stylesheets/admin.min.css b/public/stylesheets/admin.min.css index 0d89e6c..5026760 100644 --- a/public/stylesheets/admin.min.css +++ b/public/stylesheets/admin.min.css @@ -1 +1 @@ -.btn-outline-primary,.btn-warning{color:#fff!important;background-color:#000;border-color:#000}.btn-outline-danger{color:#fff!important;background-color:#cc4135;border-color:#cc4135}.has-error div,.has-error input,.has-error textarea{border-color:#cc4135}#frm_search,.search-bar-input,.search-bar-input .btn{padding-top:10px;height:45px}.productsWrapper{padding-right:10px;padding-left:10px}.searchBarWrapper{padding-right:0;padding-left:0}.footer{padding-top:20px}.product-price{padding-bottom:0}.navbarMenuWrapper{background-color:#f5f5f5}.navbarMenu>ul>li>a:hover{color:#cc4135!important}.navbarMenu{padding-right:0;padding-left:0}.product-wrapper>a:hover{color:#cc4135!important}#navbar,#navbar>.navbar-nav,#navbar>.navbar-nav>li>a,.navbar-header,.navbar-static-top{margin-bottom:0;height:100px!important}#navbar>.navbar-nav>li>a{padding-top:35px}.pagination>li>a{background-color:#cc4135!important}body .popover{display:none!important}.navbar-brand{color:#cc4135!important;letter-spacing:4px;padding-left:20px!important;padding-top:0!important;height:80px!important;font-size:55px!important}.navbar-brand,.navbar-brand-image{height:80px;padding-left:10px;padding-top:10px}.navbar-default .badge{background-color:#cc4135}#empty-cart:active,#empty-cart:active:hover,#empty-cart:focus,#empty-cart:hover,.pushy-link:active,.pushy-link:active:hover,.pushy-link:focus,.pushy-link:hover{border-color:#cc4135;background-color:#cc4135}.navActive>a{margin-bottom:0;padding-top:15px;border-bottom:5px solid #cc4135}#navbar,#navbar>.navbar-nav,#navbar>.navbar-nav>li>a,.navbar-header,.navbar-static-top{background-color:#fff}.navbar-default .navbar-nav>li>a{color:#838b8f;font-size:20px}@media only screen and (max-width:768px){.navbar-default .navbar-brand{padding-top:10px}.navbar-default .navbar-nav>li>a{font-size:16px}.searchBarWrapper{padding-top:10px}.navbarMenuWrapper{padding-left:0;padding-right:0}.navbarMenuOuter{padding-left:0;padding-right:0}.navActive>a{color:#fff!important}.navbarMenu{padding-right:7.5px;padding-left:7.5px}.navActive>a{color:#fff!important;background-color:#cc4135;border-bottom:none}.footer{padding-top:10px}} \ No newline at end of file +.btn-outline-primary,.btn-warning{color:#fff!important;background-color:#000;border-color:#000}.btn-outline-danger{color:#fff!important;background-color:#cc4135;border-color:#cc4135}.has-error div,.has-error input,.has-error textarea{border-color:#cc4135}#frm_search,.search-bar-input,.search-bar-input .btn{padding-top:10px;height:45px}.productsWrapper{padding-right:10px;padding-left:10px}.searchBarWrapper{padding-right:0;padding-left:0}.footer{padding-top:20px}.product-price{padding-bottom:0}.navbarMenuWrapper{background-color:#f5f5f5}.navbarMenu>ul>li>a:hover{color:#cc4135!important}.navbarMenu{padding-right:0;padding-left:0}.product-wrapper>a:hover{color:#cc4135!important}#navbar,#navbar>.navbar-nav,#navbar>.navbar-nav>li>a,.navbar-header,.navbar-static-top{margin-bottom:0;height:100px!important}#navbar>.navbar-nav>li>a{padding-top:35px}.pagination>li>a{background-color:#cc4135!important}body .popover{display:none!important}.navbar-brand{color:#cc4135!important;letter-spacing:4px;padding-left:20px!important;padding-top:0!important;height:80px!important;font-size:55px!important}.navbar-brand,.navbar-brand-image{height:80px;padding-left:10px;padding-top:10px}.navbar-default .badge{background-color:#cc4135}#empty-cart:active,#empty-cart:active:hover,#empty-cart:focus,#empty-cart:hover,.pushy-link:active,.pushy-link:active:hover,.pushy-link:focus,.pushy-link:hover{border-color:#cc4135;background-color:#cc4135}.navActive>a{margin-bottom:0;padding-top:15px;border-bottom:5px solid #cc4135}#navbar,#navbar>.navbar-nav,#navbar>.navbar-nav>li>a,.navbar-header,.navbar-static-top{background-color:#fff}.navbar-default .navbar-nav>li>a{color:#838b8f;font-size:20px}.global-result-type{color:#8d8d8d}.global-result:hover{background-color:#007bff}.global-result:hover .global-result-detail,.global-result:hover .global-result-type,.global-result:hover .global-result-type .fal{color:#fff!important}.global-result a{text-decoration:none!important}.global-result:hover{cursor:pointer}.global-result:first-child{border-top-left-radius:0;border-top-right-radius:0}.global-result{border-left:0;border-right:0}.global-search-modal-content,.global-search-modal-header{background-color:transparent;border:none}#global-search-results{padding-right:0;border-bottom-left-radius:.3rem;border-bottom-right-radius:.3rem}.global-search-form{margin-bottom:0}#global-search-value{border-bottom-right-radius:0}.search-input-addon{border-bottom-left-radius:0}@media only screen and (max-width:768px){.navbar-default .navbar-brand{padding-top:10px}.navbar-default .navbar-nav>li>a{font-size:16px}.searchBarWrapper{padding-top:10px}.navbarMenuWrapper{padding-left:0;padding-right:0}.navbarMenuOuter{padding-left:0;padding-right:0}.navActive>a{color:#fff!important}.navbarMenu{padding-right:7.5px;padding-left:7.5px}.navActive>a{color:#fff!important;background-color:#cc4135;border-bottom:none}.footer{padding-top:10px}} \ No newline at end of file diff --git a/public/stylesheets/less/admin.less b/public/stylesheets/less/admin.less index 666276b..b6c275b 100644 --- a/public/stylesheets/less/admin.less +++ b/public/stylesheets/less/admin.less @@ -116,6 +116,61 @@ body .popover{display:none !important; } font-size: 20px; } +.global-result-type { + color: #8d8d8d; +} + +.global-result:hover { + background-color: #007bff; +} + +.global-result:hover .global-result-detail, +.global-result:hover .global-result-type, +.global-result:hover .global-result-type .fal { + color: #fff !important; +} + +.global-result a { + text-decoration: none !important; +} + +.global-result:hover { + cursor: pointer; +} + +.global-result:first-child { + border-top-left-radius: 0; + border-top-right-radius: 0; +} + +.global-result { + border-left: 0; + border-right: 0; +} + +.global-search-modal-content, .global-search-modal-header{ + background-color: transparent; + border: none; +} + +#global-search-results{ + padding-right: 0; + border-bottom-left-radius: .3rem; + border-bottom-right-radius: .3rem; +} + +.global-search-form{ + margin-bottom: 0; +} + +#global-search-value { + border-bottom-right-radius: 0; +} + +.search-input-addon { + border-bottom-left-radius: 0; +} + @media only screen and (max-width: 768px){ .navbar-default .navbar-brand { padding-top: 10px; diff --git a/public/stylesheets/less/style.less b/public/stylesheets/less/style.less index 7e61fd9..29c1d7b 100644 --- a/public/stylesheets/less/style.less +++ b/public/stylesheets/less/style.less @@ -203,6 +203,14 @@ input[type=number]::-webkit-outer-spin-button { margin-top: -7px; } +.pad-right-10{ + padding-right: 10px; +} + +.pad-right-15{ + padding-right: 15px; +} + .no-pad-left{ padding-left: 0px; } diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index 0329df7..3664f3f 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -159,6 +159,12 @@ input[type=number]::-webkit-outer-spin-button { .list-group-input-pad select { margin-top: -7px; } +.pad-right-10 { + padding-right: 10px; +} +.pad-right-15 { + padding-right: 15px; +} .no-pad-left { padding-left: 0px; } diff --git a/public/stylesheets/style.min.css b/public/stylesheets/style.min.css index 6df132e..7d2d921 100644 --- a/public/stylesheets/style.min.css +++ b/public/stylesheets/style.min.css @@ -1 +1 @@ -html{position:relative;min-height:100%}body{margin-bottom:140px}body,html{font-size:16px}.content-body{margin-bottom:40px}.menu-top{margin-top:15px;margin-left:15px;margin-right:15px}.menu-side,.product-layout{padding-top:35px}.menu-side-mobile{background-color:transparent!important;color:inherit!important;text-align:center;border-bottom-right-radius:4px;border-bottom-left-radius:4px}.dragable_item{cursor:move}.page-header{padding-bottom:5px}.cart-contents-title{font-size:18px;font-weight:700}.cart-row{padding-bottom:10px;display:flex;align-items:center}.cart-item-row{margin-top:5px}.cart-link{padding-left:7px}.cart-product{padding:0!important}a.text-danger:focus,a.text-danger:hover{color:#cc3a2c}.cart-update-button{cursor:pointer}.thumbnail-image{cursor:pointer}#product-images{margin-bottom:30px}.product-layout{padding-top:30px}.product-title-image{margin:auto;max-height:400px;width:auto}.thumbnail-image-container .img-fluid{display:block;width:auto;max-height:100%;margin:auto}input[type=number]::-webkit-inner-spin-button,input[type=number]::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.navbar-brand{color:#cc3a2c;letter-spacing:4px;padding-left:20px;padding-top:0;height:80px;font-size:55px}.navbar-brand>img{width:auto;height:100%}.thumbnail{min-height:415px}.vertical-center{display:flex;align-items:center}.title-image-container .img-fluid{display:block;width:auto;max-height:100%;margin:auto}.title-image-container{height:400px}.thumbnail-image-container{height:350px}.product-title{font-size:20px;margin-top:0}.product-title-home{display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;align-items:center;justify-content:center;text-align:center}.product-price{padding-bottom:10px;font-size:20px;color:#aaa}.productOptions{padding-bottom:15px}.product-option{font-size:18px}.body_text,.btnAddToCart{padding-top:15px;padding-bottom:15px}.product-option-text{font-size:16px;color:#aaa;padding-bottom:10px;padding-top:10px}.seporator{padding-top:5px;border-bottom:1px solid #eee;padding-bottom:6px}.list-group-input-pad select{margin-top:-7px}.no-pad-left{padding-left:0}.no-pad-right{padding-right:0}.top-marg-10{margin-top:10px}.top-marg-15{margin-top:15px}.top-marg-20{margin-top:20px}.top-pad-5{padding-top:10px}.top-pad-8{padding-top:8px}.top-pad-10{padding-top:10px}.top-pad-20{padding-top:20px}.top-pad-50{padding-top:50px}.top-pad-100{padding-top:100px}.bottom-pad-10{padding-bottom:10px}.bottom-pad-15{padding-bottom:15px}.bottom-pad-20{padding-bottom:20px}.bottom-pad-30{padding-bottom:30px}.bottom-marg-10{margin-bottom:10px}.bottom-marg-15{margin-bottom:15px}.bottom-marg-20{margin-bottom:20px}.left-pad-10{padding-left:10px}.left-pad-30{padding-left:30px}.right-pad-10{padding-right:10px}.shipping-form input{margin-bottom:15px}#header{height:50px}.search-bar{margin-top:10px}.breadcrumb{background-color:#f8f9fa;margin-top:10px}.breadcrumbProPerRow-3{margin-left:10px;margin-right:10px}.searchProPerRow-3,.searchProPerRow-4{padding-left:0;padding-right:0}.dropup-button{height:34px;padding:0;color:#fff!important}.dropdown-menu>li>a{padding-top:5px!important}.pad-bottom{padding-bottom:25px}.keywords{padding-bottom:30px;padding-top:20px;font-size:19px}.file-form{padding-left:15px;padding-right:15px}.editor_btn_action{border-top-left-radius:4px!important;border-bottom-left-radius:4px!important}.dropup-list{padding-bottom:5px;margin-right:10px;margin-left:10px;margin-top:10px}#notify_message{position:fixed;display:none;z-index:9999;padding-top:10px;height:50px;bottom:0;width:100%;text-align:center;font-size:22px}.input-group .form-control{z-index:1}.btn-file{position:relative;overflow:hidden}.btn-file input[type=file]{position:absolute;top:0;right:0;min-width:100%;min-height:100%;font-size:100px;text-align:right;filter:alpha(opacity=0);opacity:0;outline:0;background:#fff;cursor:inherit;display:block}.offcanvas-element{z-index:100;background-color:#fff}.product-item{padding-left:0;padding-right:0}input:focus{outline:0;background:#fbfbe9}input+label{display:block;cursor:text;transition:.15s ease-out all;position:absolute;top:.9em;left:1.3em}.floatLabel{top:.1em;left:32px;font-size:.7em;color:#999;font-weight:400;transition:.15s ease-out all}input.form-control.customerDetails{padding-bottom:5px}.footer{position:absolute;bottom:0;width:100%;height:100px;padding-top:25px;background-color:#f5f5f5}.admin{margin-bottom:0}.previous a{border-bottom-left-radius:.25rem;border-top-left-radius:.25rem}.next a{border-bottom-right-radius:.25rem;border-top-right-radius:.25rem}.image-next{position:absolute;top:180px;right:0}.image-prev{position:absolute;top:180px;left:0}.image-button{cursor:pointer;opacity:.7}.image-button-show{cursor:pointer;opacity:.7!important}.navbar-default{background-color:#fff}.navbar-default .navbar-nav>li>a{color:#000}.navbar-default .navbar-nav>li>a:focus,.navbar-default .navbar-nav>li>a:hover{color:#000}.btn-outline-primary,.btn-warning{color:#fff;background-color:#000;border-color:#000}.btn-outline-primary:hover,.btn-warning:hover{color:#fff!important;background-color:#000!important;border-color:#000!important;opacity:.65}.btn-outline-danger{color:#fff;background-color:#cc3a2c;border-color:#cc3a2c}.btn-outline-danger:hover{color:#fff!important;background-color:#cc3a2c!important;border-color:#cc3a2c!important;opacity:.65}a:focus,a:hover{color:#000}a{color:#000}.list-group-item.active,.list-group-item.active:focus,.list-group-item.active:hover{background-color:#000;border-color:#000}.navbar-default .navbar-brand{color:#000;font-size:40px;font-weight:700}.navbar-default .navbar-brand:focus,.navbar-default .navbar-brand:hover{color:#000}.navbar-brand-image{padding:0;height:70px}.page-item.disabled .page-link{color:#b7b7b7}.page-link{color:#fff;border:0}.navbar-default .navbar-toggle:focus,.navbar-default .navbar-toggle:hover{background-color:#000}.thumbnail{border:none}.help-block{color:#95a5a6}@media only screen and (min-width:768px){.pushy{width:700px}.pushy-right{-webkit-transform:translate3d(700px,0,0);-ms-transform:translate3d(700px,0,0);transform:translate3d(700px,0,0)}.pushy-open-right #container,.pushy-open-right .push{-webkit-transform:translate3d(-700px,0,0);-ms-transform:translate3d(-700px,0,0);transform:translate3d(-700px,0,0)}}@media only screen and (max-width:768px){.pushy{width:calc(100%)}.pushy-right{-webkit-transform:translate3d(calc(100%),0,0);-ms-transform:translate3d(calc(100%),0,0);transform:translate3d(calc(100%),0,0)}.pushy-open-right #container,.pushy-open-right .push{-webkit-transform:translate3d(-calc(100%),0,0);-ms-transform:translate3d(-calc(100%),0,0);transform:translate3d(-calc(100%),0,0)}.product-item{padding-left:0;padding-right:0}.showFooter{margin-bottom:220px}.title-image-container{height:auto}.product-title{font-size:18px;padding-top:18px;min-height:auto}.search-bar-input{padding-left:0;padding-right:0}.menu-side{padding-top:15px}.product-layout{padding-top:0;padding-bottom:30px;margin-left:5px;margin-right:5px}#btn_search{border-top-right-radius:4px;border-bottom-right-radius:4px}.cart-row{padding-top:10px;border-bottom:1px solid #ecf0f1;display:block}.cart-body{padding-top:0}.cart-contents-shipping{padding-top:10px}#cart{padding-bottom:15px}.footer{height:100px}body{margin-bottom:100px}.navbar-brand{padding-left:0;height:auto}.thumbnail{min-height:0}} \ No newline at end of file +html{position:relative;min-height:100%}body{margin-bottom:140px}body,html{font-size:16px}.content-body{margin-bottom:40px}.menu-top{margin-top:15px;margin-left:15px;margin-right:15px}.menu-side,.product-layout{padding-top:35px}.menu-side-mobile{background-color:transparent!important;color:inherit!important;text-align:center;border-bottom-right-radius:4px;border-bottom-left-radius:4px}.dragable_item{cursor:move}.page-header{padding-bottom:5px}.cart-contents-title{font-size:18px;font-weight:700}.cart-row{padding-bottom:10px;display:flex;align-items:center}.cart-item-row{margin-top:5px}.cart-link{padding-left:7px}.cart-product{padding:0!important}a.text-danger:focus,a.text-danger:hover{color:#cc3a2c}.cart-update-button{cursor:pointer}.thumbnail-image{cursor:pointer}#product-images{margin-bottom:30px}.product-layout{padding-top:30px}.product-title-image{margin:auto;max-height:400px;width:auto}.thumbnail-image-container .img-fluid{display:block;width:auto;max-height:100%;margin:auto}input[type=number]::-webkit-inner-spin-button,input[type=number]::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.navbar-brand{color:#cc3a2c;letter-spacing:4px;padding-left:20px;padding-top:0;height:80px;font-size:55px}.navbar-brand>img{width:auto;height:100%}.thumbnail{min-height:415px}.vertical-center{display:flex;align-items:center}.title-image-container .img-fluid{display:block;width:auto;max-height:100%;margin:auto}.title-image-container{height:400px}.thumbnail-image-container{height:350px}.product-title{font-size:20px;margin-top:0}.product-title-home{display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;align-items:center;justify-content:center;text-align:center}.product-price{padding-bottom:10px;font-size:20px;color:#aaa}.productOptions{padding-bottom:15px}.product-option{font-size:18px}.body_text,.btnAddToCart{padding-top:15px;padding-bottom:15px}.product-option-text{font-size:16px;color:#aaa;padding-bottom:10px;padding-top:10px}.seporator{padding-top:5px;border-bottom:1px solid #eee;padding-bottom:6px}.list-group-input-pad select{margin-top:-7px}.pad-right-10{padding-right:10px}.pad-right-15{padding-right:15px}.no-pad-left{padding-left:0}.no-pad-right{padding-right:0}.top-marg-10{margin-top:10px}.top-marg-15{margin-top:15px}.top-marg-20{margin-top:20px}.top-pad-5{padding-top:10px}.top-pad-8{padding-top:8px}.top-pad-10{padding-top:10px}.top-pad-20{padding-top:20px}.top-pad-50{padding-top:50px}.top-pad-100{padding-top:100px}.bottom-pad-10{padding-bottom:10px}.bottom-pad-15{padding-bottom:15px}.bottom-pad-20{padding-bottom:20px}.bottom-pad-30{padding-bottom:30px}.bottom-marg-10{margin-bottom:10px}.bottom-marg-15{margin-bottom:15px}.bottom-marg-20{margin-bottom:20px}.left-pad-10{padding-left:10px}.left-pad-30{padding-left:30px}.right-pad-10{padding-right:10px}.shipping-form input{margin-bottom:15px}#header{height:50px}.search-bar{margin-top:10px}.breadcrumb{background-color:#f8f9fa;margin-top:10px}.breadcrumbProPerRow-3{margin-left:10px;margin-right:10px}.searchProPerRow-3,.searchProPerRow-4{padding-left:0;padding-right:0}.dropup-button{height:34px;padding:0;color:#fff!important}.dropdown-menu>li>a{padding-top:5px!important}.pad-bottom{padding-bottom:25px}.keywords{padding-bottom:30px;padding-top:20px;font-size:19px}.file-form{padding-left:15px;padding-right:15px}.editor_btn_action{border-top-left-radius:4px!important;border-bottom-left-radius:4px!important}.dropup-list{padding-bottom:5px;margin-right:10px;margin-left:10px;margin-top:10px}#notify_message{position:fixed;display:none;z-index:9999;padding-top:10px;height:50px;bottom:0;width:100%;text-align:center;font-size:22px}.input-group .form-control{z-index:1}.btn-file{position:relative;overflow:hidden}.btn-file input[type=file]{position:absolute;top:0;right:0;min-width:100%;min-height:100%;font-size:100px;text-align:right;filter:alpha(opacity=0);opacity:0;outline:0;background:#fff;cursor:inherit;display:block}.offcanvas-element{z-index:100;background-color:#fff}.product-item{padding-left:0;padding-right:0}input:focus{outline:0;background:#fbfbe9}input+label{display:block;cursor:text;transition:.15s ease-out all;position:absolute;top:.9em;left:1.3em}.floatLabel{top:.1em;left:32px;font-size:.7em;color:#999;font-weight:400;transition:.15s ease-out all}input.form-control.customerDetails{padding-bottom:5px}.footer{position:absolute;bottom:0;width:100%;height:100px;padding-top:25px;background-color:#f5f5f5}.admin{margin-bottom:0}.previous a{border-bottom-left-radius:.25rem;border-top-left-radius:.25rem}.next a{border-bottom-right-radius:.25rem;border-top-right-radius:.25rem}.image-next{position:absolute;top:180px;right:0}.image-prev{position:absolute;top:180px;left:0}.image-button{cursor:pointer;opacity:.7}.image-button-show{cursor:pointer;opacity:.7!important}.navbar-default{background-color:#fff}.navbar-default .navbar-nav>li>a{color:#000}.navbar-default .navbar-nav>li>a:focus,.navbar-default .navbar-nav>li>a:hover{color:#000}.btn-outline-primary,.btn-warning{color:#fff;background-color:#000;border-color:#000}.btn-outline-primary:hover,.btn-warning:hover{color:#fff!important;background-color:#000!important;border-color:#000!important;opacity:.65}.btn-outline-danger{color:#fff;background-color:#cc3a2c;border-color:#cc3a2c}.btn-outline-danger:hover{color:#fff!important;background-color:#cc3a2c!important;border-color:#cc3a2c!important;opacity:.65}a:focus,a:hover{color:#000}a{color:#000}.list-group-item.active,.list-group-item.active:focus,.list-group-item.active:hover{background-color:#000;border-color:#000}.navbar-default .navbar-brand{color:#000;font-size:40px;font-weight:700}.navbar-default .navbar-brand:focus,.navbar-default .navbar-brand:hover{color:#000}.navbar-brand-image{padding:0;height:70px}.page-item.disabled .page-link{color:#b7b7b7}.page-link{color:#fff;border:0}.navbar-default .navbar-toggle:focus,.navbar-default .navbar-toggle:hover{background-color:#000}.thumbnail{border:none}.help-block{color:#95a5a6}@media only screen and (min-width:768px){.pushy{width:700px}.pushy-right{-webkit-transform:translate3d(700px,0,0);-ms-transform:translate3d(700px,0,0);transform:translate3d(700px,0,0)}.pushy-open-right #container,.pushy-open-right .push{-webkit-transform:translate3d(-700px,0,0);-ms-transform:translate3d(-700px,0,0);transform:translate3d(-700px,0,0)}}@media only screen and (max-width:768px){.pushy{width:calc(100%)}.pushy-right{-webkit-transform:translate3d(calc(100%),0,0);-ms-transform:translate3d(calc(100%),0,0);transform:translate3d(calc(100%),0,0)}.pushy-open-right #container,.pushy-open-right .push{-webkit-transform:translate3d(-calc(100%),0,0);-ms-transform:translate3d(-calc(100%),0,0);transform:translate3d(-calc(100%),0,0)}.product-item{padding-left:0;padding-right:0}.showFooter{margin-bottom:220px}.title-image-container{height:auto}.product-title{font-size:18px;padding-top:18px;min-height:auto}.search-bar-input{padding-left:0;padding-right:0}.menu-side{padding-top:15px}.product-layout{padding-top:0;padding-bottom:30px;margin-left:5px;margin-right:5px}#btn_search{border-top-right-radius:4px;border-bottom-right-radius:4px}.cart-row{padding-top:10px;border-bottom:1px solid #ecf0f1;display:block}.cart-body{padding-top:0}.cart-contents-shipping{padding-top:10px}#cart{padding-bottom:15px}.footer{height:100px}body{margin-bottom:100px}.navbar-brand{padding-left:0;height:auto}.thumbnail{min-height:0}} \ No newline at end of file diff --git a/routes/admin.js b/routes/admin.js index 3a00f33..88ebfd5 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -11,6 +11,10 @@ const mime = require('mime-type/with-db'); const ObjectId = require('mongodb').ObjectID; const router = express.Router(); +// Regex +const emailRegex = /\S+@\S+\.\S+/; +const numericRegex = /^\d*\.?\d*$/; + // Admin section router.get('/admin', restrict, (req, res, next) => { res.redirect('/admin/dashboard'); @@ -497,4 +501,107 @@ router.post('/admin/testEmail', restrict, (req, res) => { res.status(200).json({ message: 'Test email sent' }); }); +router.post('/admin/searchall', restrict, async (req, res, next) => { + const db = req.app.db; + const searchValue = req.body.searchValue; + const limitReturned = 5; + + // Empty arrays + let customers = []; + let orders = []; + let products = []; + + // Default queries + const customerQuery = {}; + const orderQuery = {}; + const productQuery = {}; + + // If an ObjectId is detected use that + if(ObjectId.isValid(req.body.searchValue)){ + // Get customers + customers = await db.customers.find({ + _id: ObjectId(searchValue) + }) + .limit(limitReturned) + .sort({ created: 1 }) + .toArray(); + + // Get orders + orders = await db.orders.find({ + _id: ObjectId(searchValue) + }) + .limit(limitReturned) + .sort({ orderDate: 1 }) + .toArray(); + + // Get products + products = await db.products.find({ + _id: ObjectId(searchValue) + }) + .limit(limitReturned) + .sort({ productAddedDate: 1 }) + .toArray(); + + return res.status(200).json({ + customers, + orders, + products + }); + } + + // If email address is detected + if(emailRegex.test(req.body.searchValue)){ + customerQuery.email = searchValue; + orderQuery.orderEmail = searchValue; + }else if(numericRegex.test(req.body.searchValue)){ + // If a numeric value is detected + orderQuery.amount = common.cleanAmount(req.body.searchValue); + productQuery.productPrice = common.cleanAmount(req.body.searchValue); + }else{ + // String searches + customerQuery.$or = [ + { firstName: { $regex: new RegExp(searchValue, 'img') } }, + { lastName: { $regex: new RegExp(searchValue, 'img') } } + ]; + orderQuery.$or = [ + { orderFirstname: { $regex: new RegExp(searchValue, 'img') } }, + { orderLastname: { $regex: new RegExp(searchValue, 'img') } } + ]; + productQuery.$or = [ + { productTitle: { $regex: new RegExp(searchValue, 'img') } }, + { productDescription: { $regex: new RegExp(searchValue, 'img') } } + ]; + } + + // Get customers + if(Object.keys(customerQuery).length > 0){ + customers = await db.customers.find(customerQuery) + .limit(limitReturned) + .sort({ created: 1 }) + .toArray(); + } + + // Get orders + if(Object.keys(orderQuery).length > 0){ + orders = await db.orders.find(orderQuery) + .limit(limitReturned) + .sort({ orderDate: 1 }) + .toArray(); + } + + // Get products + if(Object.keys(productQuery).length > 0){ + products = await db.products.find(productQuery) + .limit(limitReturned) + .sort({ productAddedDate: 1 }) + .toArray(); + } + + return res.status(200).json({ + customers, + orders, + products + }); +}); + module.exports = router; diff --git a/views/layouts/layout.hbs b/views/layouts/layout.hbs index ee0da30..37bf70f 100644 --- a/views/layouts/layout.hbs +++ b/views/layouts/layout.hbs @@ -119,6 +119,7 @@ {{/unless}} {{#if admin}} {{#if @root.session.user}} + {{/if}} {{/if}} @@ -176,5 +177,28 @@ {{/if}} + {{#if admin}} + + {{/if}}