diff --git a/public/javascripts/admin.js b/public/javascripts/admin.js new file mode 100644 index 0000000..994d4b8 --- /dev/null +++ b/public/javascripts/admin.js @@ -0,0 +1,326 @@ +/* eslint-disable prefer-arrow-callback, no-var, no-tabs */ +/* globals showNotification, slugify */ +$(document).ready(function (){ + $(document).on('click', '#btnGenerateAPIkey', function(e){ + e.preventDefault(); + $.ajax({ + method: 'POST', + url: '/admin/createApiKey' + }) + .done(function(msg){ + $('#apiKey').val(msg.apiKey); + showNotification(msg.message, 'success', true); + }) + .fail(function(msg){ + showNotification(msg.responseJSON.message, 'danger'); + }); + }); + + $(document).on('click', '.product_opt_remove', function(e){ + e.preventDefault(); + var name = $(this).closest('li').find('.opt-name').html(); + + $.ajax({ + method: 'POST', + url: '/admin/product/removeoption', + data: { productId: $('#productId').val(), optName: name } + }) + .done(function(msg){ + showNotification(msg.message, 'success', true); + }) + .fail(function(msg){ + showNotification(msg.responseJSON.message, 'danger'); + }); + }); + + $(document).on('click', '#product_opt_add', function(e){ + e.preventDefault(); + + var optName = $('#product_optName').val(); + var optLabel = $('#product_optLabel').val(); + var optType = $('#product_optType').val(); + var optOptions = $('#product_optOptions').val(); + + var optJson = {}; + if($('#productOptions').val() !== '' && $('#productOptions').val() !== '"{}"'){ + optJson = JSON.parse($('#productOptions').val()); + } + + var html = '
  • '; + html += '
    '; + html += '
    ' + optName + '
    '; + html += '
    ' + optLabel + '
    '; + html += '
    ' + optType + '
    '; + html += '
    ' + optOptions + '
    '; + html += '
    '; + html += ''; + html += '
  • '; + + // append data + $('#product_opt_wrapper').append(html); + + // add to the stored json string + optJson[optName] = { + optName: optName, + optLabel: optLabel, + optType: optType, + optOptions: $.grep(optOptions.split(','), function(n){ return n === 0 || n; }) + }; + + // write new json back to field + $('#productOptions').val(JSON.stringify(optJson)); + + // clear inputs + $('#product_optName').val(''); + $('#product_optLabel').val(''); + $('#product_optOptions').val(''); + }); + + // call update settings API + $('#settingsForm').validator().on('submit', function(e){ + if(!e.isDefaultPrevented()){ + e.preventDefault(); + // set hidden elements from codemirror editors + $('#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(msg){ + showNotification(msg.message, 'success'); + }) + .fail(function(msg){ + showNotification(msg.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(msg){ + showNotification(msg.message, 'success', true); + }) + .fail(function(msg){ + showNotification(msg.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(msg){ + showNotification(msg.message, 'success', true); + }) + .fail(function(msg){ + showNotification(msg.responseJSON.message, 'danger'); + }); + }); + + $('.btn-delete-image').on('click', function(){ + $.ajax({ + method: 'POST', + url: '/admin/product/deleteimage', + data: { product_id: $('#productId').val(), productImage: $(this).attr('data-id') } + }) + .done(function(msg){ + showNotification(msg.message, 'success', true); + }) + .fail(function(msg){ + showNotification(msg.responseJSON.message, 'danger'); + }); + }); + + // Call to API to check if a permalink is available + $(document).on('click', '#validate_permalink', function(e){ + if($('#productPermalink').val() !== ''){ + $.ajax({ + method: 'POST', + url: '/admin/api/validate_permalink', + data: { permalink: $('#productPermalink').val(), docId: $('#productId').val() } + }) + .done(function(msg){ + showNotification(msg.message, 'success'); + }) + .fail(function(msg){ + showNotification(msg.responseJSON.message, 'danger'); + }); + }else{ + showNotification('Please enter a permalink to validate', 'danger'); + } + }); + + // applies an product filter + $(document).on('click', '#btn_product_filter', function(e){ + if($('#product_filter').val() !== ''){ + window.location.href = '/admin/products/filter/' + $('#product_filter').val(); + }else{ + showNotification('Please enter a keyword to filter', 'danger'); + } + }); + + // applies an order filter + $(document).on('click', '#btn_order_filter', function(e){ + if($('#order_filter').val() !== ''){ + window.location.href = '/admin/orders/filter/' + $('#order_filter').val(); + }else{ + showNotification('Please enter a keyword to filter', 'danger'); + } + }); + + // applies an product filter + $(document).on('click', '#btn_customer_filter', function(e){ + if($('#customer_filter').val() !== ''){ + window.location.href = '/admin/customers/filter/' + $('#customer_filter').val(); + }else{ + showNotification('Please enter a keyword to filter', 'danger'); + } + }); + + $('#sendTestEmail').on('click', function(e){ + e.preventDefault(); + $.ajax({ + method: 'POST', + url: '/admin/testEmail' + }) + .done(function(msg){ + showNotification(msg, 'success'); + }) + .fail(function(msg){ + showNotification(msg.responseJSON.message, 'danger'); + }); + }); + + $(document).on('click', '.orderFilterByStatus', function(e){ + e.preventDefault(); + window.location = '/admin/orders/bystatus/' + $('#orderStatusFilter').val(); + }); + + // create a permalink from the product title if no permalink has already been set + $(document).on('click', '#frm_edit_product_save', function(e){ + if($('#productPermalink').val() === '' && $('#productTitle').val() !== ''){ + $('#productPermalink').val(slugify($('#productTitle').val())); + } + }); + + // Call to API for a change to the published state of a product + $('input[class="published_state"]').change(function(){ + $.ajax({ + method: 'POST', + url: '/admin/product/published_state', + data: { id: this.id, state: this.checked } + }) + .done(function(msg){ + showNotification(msg.message, 'success'); + }) + .fail(function(msg){ + showNotification(msg.responseJSON.message, 'danger'); + }); + }); + + // call update settings API + $('#deleteCustomer').on('click', function(e){ + e.preventDefault(); + $.ajax({ + method: 'DELETE', + url: '/admin/customer', + data: { + customerId: $('#customerId').val() + } + }) + .done(function(msg){ + showNotification(msg.message, 'success', false, '/admin/customers'); + }) + .fail(function(msg){ + showNotification(msg.responseJSON.message, 'danger'); + }); + }); + + if($('#footerHtml').length){ + var footerHTML = window.CodeMirror.fromTextArea(document.getElementById('footerHtml'), { + mode: 'xml', + tabMode: 'indent', + theme: 'flatly', + lineNumbers: true, + htmlMode: true, + fixedGutter: false + }); + + footerHTML.setValue(footerHTML.getValue()); + } + + if($('#googleAnalytics').length){ + window.CodeMirror.fromTextArea(document.getElementById('googleAnalytics'), { + mode: 'xml', + tabMode: 'indent', + theme: 'flatly', + lineNumbers: true, + htmlMode: true, + fixedGutter: false + }); + } + + if($('#customCss').length){ + var customCss = window.CodeMirror.fromTextArea(document.getElementById('customCss'), { + mode: 'text/css', + tabMode: 'indent', + theme: 'flatly', + lineNumbers: true + }); + + var customCssBeautified = window.cssbeautify(customCss.getValue(), { + indent: ' ', + autosemicolon: true + }); + customCss.setValue(customCssBeautified); + } + + // call update settings API + $('#settings-menu-new').on('click', function(e){ + e.preventDefault(); + $.ajax({ + method: 'POST', + url: '/admin/settings/menu/new', + data: { + navMenu: $('#navMenu').val(), + navLink: $('#navLink').val() + } + }) + .done(function(msg){ + showNotification(msg.message, 'success', true); + }) + .fail(function(msg){ + showNotification(msg.message, 'danger', true); + }); + }); + + $(document).on('click', '#btnPageUpdate', function(e){ + e.preventDefault(); + $.ajax({ + method: 'POST', + url: '/admin/settings/pages/update', + data: { + page_id: $('#page_id').val(), + pageName: $('#pageName').val(), + pageSlug: $('#pageSlug').val(), + pageEnabled: $('#pageEnabled').is(':checked'), + pageContent: $('#pageContent').val() + } + }) + .done(function(msg){ + showNotification(msg.message, 'success', true); + }) + .fail(function(msg){ + showNotification(msg.responseJSON.message, 'danger'); + }); + }); +}); diff --git a/public/javascripts/admin.min.js b/public/javascripts/admin.min.js new file mode 100644 index 0000000..b888dd2 --- /dev/null +++ b/public/javascripts/admin.min.js @@ -0,0 +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(),i=$("#product_optOptions").val(),n={};""!==$("#productOptions").val()&&'"{}"'!==$("#productOptions").val()&&(n=JSON.parse($("#productOptions").val()));var s='
  • ';s+='
    ',s+='
    '+t+"
    ",s+='
    '+o+"
    ",s+='
    '+a+"
    ",s+='
    '+i+"
    ",s+='
    ',s+='',s+="
  • ",$("#product_opt_wrapper").append(s),n[t]={optName:t,optLabel:o,optType:a,optOptions:$.grep(i.split(","),function(e){return 0===e||e})},$("#productOptions").val(JSON.stringify(n)),$("#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")})}),$(".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(){$.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")})}),$(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")}),$("#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()}),$(document).on("click","#frm_edit_product_save",function(e){""===$("#productPermalink").val()&&""!==$("#productTitle").val()&&$("#productPermalink").val(slugify($("#productTitle").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")})}),$("#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)}$("#settings-menu-new").on("click",function(e){e.preventDefault(),$.ajax({method:"POST",url:"/admin/settings/menu/new",data:{navMenu:$("#navMenu").val(),navLink:$("#navLink").val()}}).done(function(e){showNotification(e.message,"success",!0)}).fail(function(e){showNotification(e.message,"danger",!0)})}),$(document).on("click","#btnPageUpdate",function(e){e.preventDefault(),$.ajax({method:"POST",url:"/admin/settings/pages/update",data:{page_id:$("#page_id").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")})})}); \ No newline at end of file diff --git a/public/javascripts/common.js b/public/javascripts/common.js new file mode 100644 index 0000000..daa8220 --- /dev/null +++ b/public/javascripts/common.js @@ -0,0 +1,125 @@ +/* eslint-disable no-unused-vars */ +/* eslint-disable prefer-arrow-callback, no-var, no-tabs */ +/* globals AdyenCheckout */ +$(document).ready(function (){ + // validate form and show stripe payment + $('#stripeButton').validator().on('click', function(e){ + e.preventDefault(); + if($('#shipping-form').validator('validate').has('.has-error').length === 0){ + // if no form validation errors + var handler = window.StripeCheckout.configure({ + key: $('#stripeButton').data('key'), + image: $('#stripeButton').data('image'), + locale: 'auto', + token: function(token){ + if($('#stripeButton').data('subscription')){ + $('#shipping-form').append(''); + } + $('#shipping-form').append(''); + $('#shipping-form').submit(); + } + }); + + // open the stripe payment form + handler.open({ + email: $('#stripeButton').data('email'), + name: $('#stripeButton').data('name'), + description: $('#stripeButton').data('description'), + zipCode: $('#stripeButton').data('zipCode'), + amount: $('#stripeButton').data('amount'), + currency: $('#stripeButton').data('currency'), + subscription: $('#stripeButton').data('subscription') + }); + } + }); + + if($('#adyen-dropin').length > 0){ + $.ajax({ + method: 'POST', + url: '/adyen/setup' + }) + .done(function(response){ + const configuration = { + locale: 'en-AU', + environment: response.environment.toLowerCase(), + originKey: response.publicKey, + paymentMethodsResponse: response.paymentsResponse + }; + const checkout = new AdyenCheckout(configuration); + checkout + .create('dropin', { + paymentMethodsConfiguration: { + card: { + hasHolderName: false, + holderNameRequired: false, + enableStoreDetails: false, + groupTypes: ['mc', 'visa'], + name: 'Credit or debit card' + } + }, + onSubmit: (state, dropin) => { + if($('#shipping-form').validator('validate').has('.has-error').length === 0){ + $.ajax({ + type: 'POST', + url: '/adyen/checkout_action', + data: { + shipEmail: $('#shipEmail').val(), + shipFirstname: $('#shipFirstname').val(), + shipLastname: $('#shipLastname').val(), + shipAddr1: $('#shipAddr1').val(), + shipAddr2: $('#shipAddr2').val(), + shipCountry: $('#shipCountry').val(), + shipState: $('#shipState').val(), + shipPostcode: $('#shipPostcode').val(), + shipPhoneNumber: $('#shipPhoneNumber').val(), + payment: JSON.stringify(state.data.paymentMethod) + } + }).done((response) => { + window.location = '/payment/' + response.paymentId; + }).fail((response) => { + console.log('Response', response); + showNotification('Failed to complete transaction', 'danger', true); + }); + } + } + }) + .mount('#adyen-dropin'); + }) + .fail(function(msg){ + showNotification(msg.responseJSON.message, 'danger'); + }); + }; +}); + +// show notification popup +function showNotification(msg, type, reloadPage, redirect){ + // defaults to false + reloadPage = reloadPage || false; + + // defaults to null + redirect = redirect || null; + + $('#notify_message').removeClass(); + $('#notify_message').addClass('alert-' + type); + $('#notify_message').html(msg); + $('#notify_message').slideDown(600).delay(2500).slideUp(600, function(){ + if(redirect){ + window.location = redirect; + } + if(reloadPage === true){ + location.reload(); + } + }); +} + +function slugify(str){ + var $slug = ''; + var trimmed = $.trim(str); + $slug = trimmed.replace(/[^a-z0-9-æøå]/gi, '-') + .replace(/-+/g, '-') + .replace(/^-|-$/g, '') + .replace(/æ/gi, 'ae') + .replace(/ø/gi, 'oe') + .replace(/å/gi, 'a'); + return $slug.toLowerCase(); +} diff --git a/public/javascripts/common.min.js b/public/javascripts/common.min.js new file mode 100644 index 0000000..5dd5c1b --- /dev/null +++ b/public/javascripts/common.min.js @@ -0,0 +1 @@ +function showNotification(e,t,a,i){a=a||!1,i=i||null,$("#notify_message").removeClass(),$("#notify_message").addClass("alert-"+t),$("#notify_message").html(e),$("#notify_message").slideDown(600).delay(2500).slideUp(600,function(){i&&(window.location=i),!0===a&&location.reload()})}function slugify(e){return $.trim(e).replace(/[^a-z0-9-æøå]/gi,"-").replace(/-+/g,"-").replace(/^-|-$/g,"").replace(/æ/gi,"ae").replace(/ø/gi,"oe").replace(/å/gi,"a").toLowerCase()}$(document).ready(function(){$("#stripeButton").validator().on("click",function(e){(e.preventDefault(),0===$("#shipping-form").validator("validate").has(".has-error").length)&&window.StripeCheckout.configure({key:$("#stripeButton").data("key"),image:$("#stripeButton").data("image"),locale:"auto",token:function(e){$("#stripeButton").data("subscription")&&$("#shipping-form").append(''),$("#shipping-form").append(''),$("#shipping-form").submit()}}).open({email:$("#stripeButton").data("email"),name:$("#stripeButton").data("name"),description:$("#stripeButton").data("description"),zipCode:$("#stripeButton").data("zipCode"),amount:$("#stripeButton").data("amount"),currency:$("#stripeButton").data("currency"),subscription:$("#stripeButton").data("subscription")})}),$("#adyen-dropin").length>0&&$.ajax({method:"POST",url:"/adyen/setup"}).done(function(e){const t={locale:"en-AU",environment:e.environment.toLowerCase(),originKey:e.publicKey,paymentMethodsResponse:e.paymentsResponse};new AdyenCheckout(t).create("dropin",{paymentMethodsConfiguration:{card:{hasHolderName:!1,holderNameRequired:!1,enableStoreDetails:!1,groupTypes:["mc","visa"],name:"Credit or debit card"}},onSubmit:(e,t)=>{0===$("#shipping-form").validator("validate").has(".has-error").length&&$.ajax({type:"POST",url:"/adyen/checkout_action",data:{shipEmail:$("#shipEmail").val(),shipFirstname:$("#shipFirstname").val(),shipLastname:$("#shipLastname").val(),shipAddr1:$("#shipAddr1").val(),shipAddr2:$("#shipAddr2").val(),shipCountry:$("#shipCountry").val(),shipState:$("#shipState").val(),shipPostcode:$("#shipPostcode").val(),shipPhoneNumber:$("#shipPhoneNumber").val(),payment:JSON.stringify(e.data.paymentMethod)}}).done(e=>{window.location="/payment/"+e.paymentId}).fail(e=>{console.log("Response",e),showNotification("Failed to complete transaction","danger",!0)})}}).mount("#adyen-dropin")}).fail(function(e){showNotification(e.responseJSON.message,"danger")})}); \ No newline at end of file diff --git a/public/javascripts/expressCart.js b/public/javascripts/expressCart.js index 1ee8215..2a4ceba 100644 --- a/public/javascripts/expressCart.js +++ b/public/javascripts/expressCart.js @@ -1,5 +1,5 @@ /* eslint-disable prefer-arrow-callback, no-var, no-tabs */ -/* globals AdyenCheckout */ +/* globals showNotification */ $(document).ready(function (){ // setup if material theme if($('#cartTheme').val() === 'Material'){ @@ -46,59 +46,6 @@ $(document).ready(function (){ e.preventDefault(); }); - $('#sendTestEmail').on('click', function(e){ - e.preventDefault(); - $.ajax({ - method: 'POST', - url: '/admin/testEmail' - }) - .done(function(msg){ - showNotification(msg, 'success'); - }) - .fail(function(msg){ - showNotification(msg.responseJSON.message, 'danger'); - }); - }); - - if($('#footerHtml').length){ - var footerHTML = window.CodeMirror.fromTextArea(document.getElementById('footerHtml'), { - mode: 'xml', - tabMode: 'indent', - theme: 'flatly', - lineNumbers: true, - htmlMode: true, - fixedGutter: false - }); - - footerHTML.setValue(footerHTML.getValue()); - } - - if($('#googleAnalytics').length){ - window.CodeMirror.fromTextArea(document.getElementById('googleAnalytics'), { - mode: 'xml', - tabMode: 'indent', - theme: 'flatly', - lineNumbers: true, - htmlMode: true, - fixedGutter: false - }); - } - - if($('#customCss').length){ - var customCss = window.CodeMirror.fromTextArea(document.getElementById('customCss'), { - mode: 'text/css', - tabMode: 'indent', - theme: 'flatly', - lineNumbers: true - }); - - var customCssBeautified = window.cssbeautify(customCss.getValue(), { - indent: ' ', - autosemicolon: true - }); - customCss.setValue(customCssBeautified); - } - // add the table class to all tables $('table').each(function(){ $(this).addClass('table table-hover'); @@ -116,21 +63,6 @@ $(document).ready(function (){ ellipsis: '...' }); - // Call to API for a change to the published state of a product - $('input[class="published_state"]').change(function(){ - $.ajax({ - method: 'POST', - url: '/admin/product/published_state', - data: { id: this.id, state: this.checked } - }) - .done(function(msg){ - showNotification(msg.message, 'success'); - }) - .fail(function(msg){ - showNotification(msg.responseJSON.message, 'danger'); - }); - }); - $(document).on('click', '.btn-qty-minus', function(e){ var qtyElement = $(e.target).parent().parent().find('.cart-product-quantity'); $(qtyElement).val(parseInt(qtyElement.val()) - 1); @@ -151,11 +83,6 @@ $(document).ready(function (){ deleteFromCart($(e.target)); }); - $(document).on('click', '.orderFilterByStatus', function(e){ - e.preventDefault(); - window.location = '/admin/orders/bystatus/' + $('#orderStatusFilter').val(); - }); - if($('#pager').length){ var pageNum = $('#pageNum').val(); var pageLen = $('#productsPerPage').val(); @@ -184,212 +111,6 @@ $(document).ready(function (){ } } - $(document).on('click', '#btnPageUpdate', function(e){ - e.preventDefault(); - $.ajax({ - method: 'POST', - url: '/admin/settings/pages/update', - data: { - page_id: $('#page_id').val(), - pageName: $('#pageName').val(), - pageSlug: $('#pageSlug').val(), - pageEnabled: $('#pageEnabled').is(':checked'), - pageContent: $('#pageContent').val() - } - }) - .done(function(msg){ - showNotification(msg.message, 'success', true); - }) - .fail(function(msg){ - showNotification(msg.responseJSON.message, 'danger'); - }); - }); - - $(document).on('click', '#btnGenerateAPIkey', function(e){ - e.preventDefault(); - $.ajax({ - method: 'POST', - url: '/admin/createApiKey' - }) - .done(function(msg){ - $('#apiKey').val(msg.apiKey); - showNotification(msg.message, 'success', true); - }) - .fail(function(msg){ - showNotification(msg.responseJSON.message, 'danger'); - }); - }); - - $(document).on('click', '.product_opt_remove', function(e){ - e.preventDefault(); - var name = $(this).closest('li').find('.opt-name').html(); - - $.ajax({ - method: 'POST', - url: '/admin/product/removeoption', - data: { productId: $('#productId').val(), optName: name } - }) - .done(function(msg){ - showNotification(msg.message, 'success', true); - }) - .fail(function(msg){ - showNotification(msg.responseJSON.message, 'danger'); - }); - }); - - $(document).on('click', '#product_opt_add', function(e){ - e.preventDefault(); - - var optName = $('#product_optName').val(); - var optLabel = $('#product_optLabel').val(); - var optType = $('#product_optType').val(); - var optOptions = $('#product_optOptions').val(); - - var optJson = {}; - if($('#productOptions').val() !== '' && $('#productOptions').val() !== '"{}"'){ - optJson = JSON.parse($('#productOptions').val()); - } - - var html = '
  • '; - html += '
    '; - html += '
    ' + optName + '
    '; - html += '
    ' + optLabel + '
    '; - html += '
    ' + optType + '
    '; - html += '
    ' + optOptions + '
    '; - html += '
    '; - html += ''; - html += '
  • '; - - // append data - $('#product_opt_wrapper').append(html); - - // add to the stored json string - optJson[optName] = { - optName: optName, - optLabel: optLabel, - optType: optType, - optOptions: $.grep(optOptions.split(','), function(n){ return n === 0 || n; }) - }; - - // write new json back to field - $('#productOptions').val(JSON.stringify(optJson)); - - // clear inputs - $('#product_optName').val(''); - $('#product_optLabel').val(''); - $('#product_optOptions').val(''); - }); - - // validate form and show stripe payment - $('#stripeButton').validator().on('click', function(e){ - e.preventDefault(); - if($('#shipping-form').validator('validate').has('.has-error').length === 0){ - // if no form validation errors - var handler = window.StripeCheckout.configure({ - key: $('#stripeButton').data('key'), - image: $('#stripeButton').data('image'), - locale: 'auto', - token: function(token){ - if($('#stripeButton').data('subscription')){ - $('#shipping-form').append(''); - } - $('#shipping-form').append(''); - $('#shipping-form').submit(); - } - }); - - // open the stripe payment form - handler.open({ - email: $('#stripeButton').data('email'), - name: $('#stripeButton').data('name'), - description: $('#stripeButton').data('description'), - zipCode: $('#stripeButton').data('zipCode'), - amount: $('#stripeButton').data('amount'), - currency: $('#stripeButton').data('currency'), - subscription: $('#stripeButton').data('subscription') - }); - } - }); - - if($('#adyen-dropin').length > 0){ - $.ajax({ - method: 'POST', - url: '/adyen/setup' - }) - .done(function(response){ - const configuration = { - locale: 'en-AU', - environment: response.environment.toLowerCase(), - originKey: response.publicKey, - paymentMethodsResponse: response.paymentsResponse - }; - const checkout = new AdyenCheckout(configuration); - checkout - .create('dropin', { - paymentMethodsConfiguration: { - card: { - hasHolderName: false, - holderNameRequired: false, - enableStoreDetails: false, - groupTypes: ['mc', 'visa'], - name: 'Credit or debit card' - } - }, - onSubmit: (state, dropin) => { - if($('#shipping-form').validator('validate').has('.has-error').length === 0){ - $.ajax({ - type: 'POST', - url: '/adyen/checkout_action', - data: { - shipEmail: $('#shipEmail').val(), - shipFirstname: $('#shipFirstname').val(), - shipLastname: $('#shipLastname').val(), - shipAddr1: $('#shipAddr1').val(), - shipAddr2: $('#shipAddr2').val(), - shipCountry: $('#shipCountry').val(), - shipState: $('#shipState').val(), - shipPostcode: $('#shipPostcode').val(), - shipPhoneNumber: $('#shipPhoneNumber').val(), - payment: JSON.stringify(state.data.paymentMethod) - } - }).done((response) => { - window.location = '/payment/' + response.paymentId; - }).fail((response) => { - console.log('Response', response); - showNotification('Failed to complete transaction', 'danger', true); - }); - } - } - }) - .mount('#adyen-dropin'); - }) - .fail(function(msg){ - showNotification(msg.responseJSON.message, 'danger'); - }); - }; - - // call update settings API - $('#settingsForm').validator().on('submit', function(e){ - if(!e.isDefaultPrevented()){ - e.preventDefault(); - // set hidden elements from codemirror editors - $('#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(msg){ - showNotification(msg.message, 'success'); - }) - .fail(function(msg){ - showNotification(msg.responseJSON.message, 'danger'); - }); - } - }); - $('#customerLogout').on('click', function(e){ $.ajax({ method: 'POST', @@ -484,24 +205,6 @@ $(document).ready(function (){ e.preventDefault(); }); - // call update settings API - $('#deleteCustomer').on('click', function(e){ - e.preventDefault(); - $.ajax({ - method: 'DELETE', - url: '/admin/customer', - data: { - customerId: $('#customerId').val() - } - }) - .done(function(msg){ - showNotification(msg.message, 'success', false, '/admin/customers'); - }) - .fail(function(msg){ - showNotification(msg.responseJSON.message, 'danger'); - }); - }); - $(document).on('click', '.image-next', function(e){ var thumbnails = $('.thumbnail-image'); var index = 0; @@ -544,20 +247,6 @@ $(document).ready(function (){ $('#product-title-image').attr('src', $(thumbnails).eq(matchedIndex).attr('src')); }); - $(document).on('click', '#orderStatusUpdate', function(e){ - $.ajax({ - method: 'POST', - url: '/admin/order/statusupdate', - data: { order_id: $('#order_id').val(), status: $('#orderStatus').val() } - }) - .done(function(msg){ - showNotification(msg.message, 'success', true); - }) - .fail(function(msg){ - showNotification(msg.responseJSON.message, 'danger'); - }); - }); - $(document).on('click', '.product-add-to-cart', function(e){ var productOptions = getSelectedOptions(); @@ -644,80 +333,6 @@ $(document).ready(function (){ $('#product-title-image').attr('src', $(this).attr('src')); }); - $('.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(msg){ - showNotification(msg.message, 'success', true); - }) - .fail(function(msg){ - showNotification(msg.responseJSON.message, 'danger'); - }); - }); - - $('.btn-delete-image').on('click', function(){ - $.ajax({ - method: 'POST', - url: '/admin/product/deleteimage', - data: { product_id: $('#productId').val(), productImage: $(this).attr('data-id') } - }) - .done(function(msg){ - showNotification(msg.message, 'success', true); - }) - .fail(function(msg){ - showNotification(msg.responseJSON.message, 'danger'); - }); - }); - - // Call to API to check if a permalink is available - $(document).on('click', '#validate_permalink', function(e){ - if($('#productPermalink').val() !== ''){ - $.ajax({ - method: 'POST', - url: '/admin/api/validate_permalink', - data: { permalink: $('#productPermalink').val(), docId: $('#productId').val() } - }) - .done(function(msg){ - showNotification(msg.message, 'success'); - }) - .fail(function(msg){ - showNotification(msg.responseJSON.message, 'danger'); - }); - }else{ - showNotification('Please enter a permalink to validate', 'danger'); - } - }); - - // applies an product filter - $(document).on('click', '#btn_product_filter', function(e){ - if($('#product_filter').val() !== ''){ - window.location.href = '/admin/products/filter/' + $('#product_filter').val(); - }else{ - showNotification('Please enter a keyword to filter', 'danger'); - } - }); - - // applies an order filter - $(document).on('click', '#btn_order_filter', function(e){ - if($('#order_filter').val() !== ''){ - window.location.href = '/admin/orders/filter/' + $('#order_filter').val(); - }else{ - showNotification('Please enter a keyword to filter', 'danger'); - } - }); - - // applies an product filter - $(document).on('click', '#btn_customer_filter', function(e){ - if($('#customer_filter').val() !== ''){ - window.location.href = '/admin/customers/filter/' + $('#customer_filter').val(); - }else{ - showNotification('Please enter a keyword to filter', 'danger'); - } - }); - // resets the order filter $(document).on('click', '#btn_search_reset', function(e){ window.location.replace('/'); @@ -733,13 +348,6 @@ $(document).ready(function (){ } }); - // create a permalink from the product title if no permalink has already been set - $(document).on('click', '#frm_edit_product_save', function(e){ - if($('#productPermalink').val() === '' && $('#productTitle').val() !== ''){ - $('#productPermalink').val(slugify($('#productTitle').val())); - } - }); - if($('#input_notify_message').val() !== ''){ // save values from inputs var messageVal = $('#input_notify_message').val(); @@ -783,18 +391,6 @@ function deleteFromCart(element){ }); } -function slugify(str){ - var $slug = ''; - var trimmed = $.trim(str); - $slug = trimmed.replace(/[^a-z0-9-æøå]/gi, '-') - .replace(/-+/g, '-') - .replace(/^-|-$/g, '') - .replace(/æ/gi, 'ae') - .replace(/ø/gi, 'oe') - .replace(/å/gi, 'a'); - return $slug.toLowerCase(); -} - function cartUpdate(element){ if($(element).val() > 0){ if($(element).val() !== ''){ @@ -865,24 +461,3 @@ function getSelectedOptions(){ }); return options; } - -// show notification popup -function showNotification(msg, type, reloadPage, redirect){ - // defaults to false - reloadPage = reloadPage || false; - - // defaults to null - redirect = redirect || null; - - $('#notify_message').removeClass(); - $('#notify_message').addClass('alert-' + type); - $('#notify_message').html(msg); - $('#notify_message').slideDown(600).delay(2500).slideUp(600, function(){ - if(redirect){ - window.location = redirect; - } - if(reloadPage === true){ - location.reload(); - } - }); -} diff --git a/public/javascripts/expressCart.min.js b/public/javascripts/expressCart.min.js index 3173c08..e2ae62b 100644 --- a/public/javascripts/expressCart.min.js +++ b/public/javascripts/expressCart.min.js @@ -1 +1 @@ -function deleteFromCart(t){$.ajax({method:"POST",url:"/product/removefromcart",data:{cartId:t.attr("data-id")}}).done(function(e){$("#cart-count").text(e.totalCartItems),0===e.totalCartItems?($(t).closest(".cart-row").hide("slow",function(){$(t).closest(".cart-row").remove()}),$(".cart-contents-shipping").hide("slow",function(){$(".cart-contents-shipping").remove()}),showNotification(e.message,"success"),setTimeout(function(){window.location="/"},3700)):($(t).closest(".cart-row").hide("slow",function(){$(t).closest(".cart-row").remove()}),showNotification(e.message,"success"))}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}function slugify(t){return $.trim(t).replace(/[^a-z0-9-æøå]/gi,"-").replace(/-+/g,"-").replace(/^-|-$/g,"").replace(/æ/gi,"ae").replace(/ø/gi,"oe").replace(/å/gi,"a").toLowerCase()}function cartUpdate(t){$(t).val()>0?""!==$(t).val()&&updateCart():$(t).val(1)}function updateCart(){var t=[];$(".cart-product-quantity").each(function(){var e={cartIndex:$(this).attr("id"),itemQuantity:$(this).val(),productId:$(this).attr("data-id")};t.push(e)}),$.ajax({method:"POST",url:"/product/updatecart",data:{items:JSON.stringify(t)}}).done(function(t){updateCartDiv(),$("#cart-count").text(t.totalCartItems)}).fail(function(t){showNotification(t.responseJSON.message,"danger",!0)})}function updateCartDiv(){var t=window.location.pathname.split("/").length>0?window.location.pathname.split("/")[1]:"";$.ajax({method:"GET",url:"/cartPartial",data:{path:t}}).done(function(t){$("#cart").html(t)}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}function getSelectedOptions(){var t={};return $(".product-opt").each(function(){if("opt-"!==$(this).attr("name")){var e=$(this).val().trim();"radio"===$(this).attr("type")&&(e=$('input[name="'+$(this).attr("name")+'"]:checked').val()),t[$(this).attr("name").substring(4,$(this).attr("name").length)]=e}else t[$(this).val().trim()]=$(this).prop("checked")}),t}function showNotification(t,e,a,o){a=a||!1,o=o||null,$("#notify_message").removeClass(),$("#notify_message").addClass("alert-"+e),$("#notify_message").html(t),$("#notify_message").slideDown(600).delay(2500).slideUp(600,function(){o&&(window.location=o),!0===a&&location.reload()})}$(document).ready(function(){if("Material"===$("#cartTheme").val()&&$(".materialboxed").materialbox(),$(window).width()<768&&($(".menu-side").on("click",function(t){t.preventDefault(),$('.menu-side li:not(".active")').slideToggle()}),$('.menu-side li:not(".active")').hide(),$(".menu-side>.active").html(''),$(".menu-side>.active").addClass("menu-side-mobile"),0===$("#navbar ul li").length&&$("#navbar").hide(),$("#offcanvasClose").hide()),$(".shipping-form input").each(function(t){$(this).wrap("
    ");var e=$(this).attr("placeholder");$(this).after('")}),$(".shipping-form input").on("focus",function(){$(this).next().addClass("floatLabel"),$(this).next().removeClass("hidden")}),$(".shipping-form input").on("blur",function(){""===$(this).val()&&($(this).next().addClass("hidden"),$(this).next().removeClass("floatLabel"))}),$(".menu-btn").on("click",function(t){t.preventDefault()}),$("#sendTestEmail").on("click",function(t){t.preventDefault(),$.ajax({method:"POST",url:"/admin/testEmail"}).done(function(t){showNotification(t,"success")}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$("#footerHtml").length){var t=window.CodeMirror.fromTextArea(document.getElementById("footerHtml"),{mode:"xml",tabMode:"indent",theme:"flatly",lineNumbers:!0,htmlMode:!0,fixedGutter:!1});t.setValue(t.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 e=window.CodeMirror.fromTextArea(document.getElementById("customCss"),{mode:"text/css",tabMode:"indent",theme:"flatly",lineNumbers:!0}),a=window.cssbeautify(e.getValue(),{indent:" ",autosemicolon:!0});e.setValue(a)}if($("table").each(function(){$(this).addClass("table table-hover")}),$("#productTags").tokenfield(),$(document).on("click",".dashboard_list",function(t){window.document.location=$(this).attr("href")}).hover(function(){$(this).toggleClass("hover")}),$(".product-title").dotdotdot({ellipsis:"..."}),$('input[class="published_state"]').change(function(){$.ajax({method:"POST",url:"/admin/product/published_state",data:{id:this.id,state:this.checked}}).done(function(t){showNotification(t.message,"success")}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$(document).on("click",".btn-qty-minus",function(t){var e=$(t.target).parent().parent().find(".cart-product-quantity");$(e).val(parseInt(e.val())-1),cartUpdate(e)}),$(document).on("click",".btn-qty-add",function(t){var e=$(t.target).parent().parent().find(".cart-product-quantity");$(e).val(parseInt(e.val())+1),cartUpdate(e)}),$(document).on("change",".cart-product-quantity",function(t){cartUpdate(t.target)}),$(document).on("click",".btn-delete-from-cart",function(t){deleteFromCart($(t.target))}),$(document).on("click",".orderFilterByStatus",function(t){t.preventDefault(),window.location="/admin/orders/bystatus/"+$("#orderStatusFilter").val()}),$("#pager").length){var o=$("#pageNum").val(),i=$("#productsPerPage").val(),n=$("#totalProductCount").val(),s=$("#paginateUrl").val(),r=$("#searchTerm").val();""!==r&&(r+="/");var c="/"+s+"/"+r+"{{number}}",d=Math.ceil(n/i);parseInt(n)>parseInt(i)&&$("#pager").bootpag({total:d,page:o,maxVisible:5,href:c,wrapClass:"pagination",prevClass:"waves-effect",nextClass:"waves-effect",activeClass:"pag-active waves-effect"})}if($(document).on("click","#btnPageUpdate",function(t){t.preventDefault(),$.ajax({method:"POST",url:"/admin/settings/pages/update",data:{page_id:$("#page_id").val(),pageName:$("#pageName").val(),pageSlug:$("#pageSlug").val(),pageEnabled:$("#pageEnabled").is(":checked"),pageContent:$("#pageContent").val()}}).done(function(t){showNotification(t.message,"success",!0)}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$(document).on("click","#btnGenerateAPIkey",function(t){t.preventDefault(),$.ajax({method:"POST",url:"/admin/createApiKey"}).done(function(t){$("#apiKey").val(t.apiKey),showNotification(t.message,"success",!0)}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$(document).on("click",".product_opt_remove",function(t){t.preventDefault();var e=$(this).closest("li").find(".opt-name").html();$.ajax({method:"POST",url:"/admin/product/removeoption",data:{productId:$("#productId").val(),optName:e}}).done(function(t){showNotification(t.message,"success",!0)}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$(document).on("click","#product_opt_add",function(t){t.preventDefault();var e=$("#product_optName").val(),a=$("#product_optLabel").val(),o=$("#product_optType").val(),i=$("#product_optOptions").val(),n={};""!==$("#productOptions").val()&&'"{}"'!==$("#productOptions").val()&&(n=JSON.parse($("#productOptions").val()));var s='
  • ';s+='
    ',s+='
    '+e+"
    ",s+='
    '+a+"
    ",s+='
    '+o+"
    ",s+='
    '+i+"
    ",s+='
    ',s+='',s+="
  • ",$("#product_opt_wrapper").append(s),n[e]={optName:e,optLabel:a,optType:o,optOptions:$.grep(i.split(","),function(t){return 0===t||t})},$("#productOptions").val(JSON.stringify(n)),$("#product_optName").val(""),$("#product_optLabel").val(""),$("#product_optOptions").val("")}),$("#stripeButton").validator().on("click",function(t){(t.preventDefault(),0===$("#shipping-form").validator("validate").has(".has-error").length)&&window.StripeCheckout.configure({key:$("#stripeButton").data("key"),image:$("#stripeButton").data("image"),locale:"auto",token:function(t){$("#stripeButton").data("subscription")&&$("#shipping-form").append(''),$("#shipping-form").append(''),$("#shipping-form").submit()}}).open({email:$("#stripeButton").data("email"),name:$("#stripeButton").data("name"),description:$("#stripeButton").data("description"),zipCode:$("#stripeButton").data("zipCode"),amount:$("#stripeButton").data("amount"),currency:$("#stripeButton").data("currency"),subscription:$("#stripeButton").data("subscription")})}),$("#adyen-dropin").length>0&&$.ajax({method:"POST",url:"/adyen/setup"}).done(function(t){const e={locale:"en-AU",environment:t.environment.toLowerCase(),originKey:t.publicKey,paymentMethodsResponse:t.paymentsResponse};new AdyenCheckout(e).create("dropin",{paymentMethodsConfiguration:{card:{hasHolderName:!1,holderNameRequired:!1,enableStoreDetails:!1,groupTypes:["mc","visa"],name:"Credit or debit card"}},onSubmit:(t,e)=>{0===$("#shipping-form").validator("validate").has(".has-error").length&&$.ajax({type:"POST",url:"/adyen/checkout_action",data:{shipEmail:$("#shipEmail").val(),shipFirstname:$("#shipFirstname").val(),shipLastname:$("#shipLastname").val(),shipAddr1:$("#shipAddr1").val(),shipAddr2:$("#shipAddr2").val(),shipCountry:$("#shipCountry").val(),shipState:$("#shipState").val(),shipPostcode:$("#shipPostcode").val(),shipPhoneNumber:$("#shipPhoneNumber").val(),payment:JSON.stringify(t.data.paymentMethod)}}).done(t=>{window.location="/payment/"+t.paymentId}).fail(t=>{console.log("Response",t),showNotification("Failed to complete transaction","danger",!0)})}}).mount("#adyen-dropin")}).fail(function(t){showNotification(t.responseJSON.message,"danger")}),$("#settingsForm").validator().on("submit",function(t){t.isDefaultPrevented()||(t.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(t){showNotification(t.message,"success")}).fail(function(t){showNotification(t.responseJSON.message,"danger")}))}),$("#customerLogout").on("click",function(t){$.ajax({method:"POST",url:"/customer/logout",data:{}}).done(function(t){location.reload()})}),$("#createCustomerAccount").validator().on("click",function(t){t.preventDefault(),0===$("#shipping-form").validator("validate").has(".has-error").length&&$.ajax({method:"POST",url:"/customer/create",data:{email:$("#shipEmail").val(),firstName:$("#shipFirstname").val(),lastName:$("#shipLastname").val(),address1:$("#shipAddr1").val(),address2:$("#shipAddr2").val(),country:$("#shipCountry").val(),state:$("#shipState").val(),postcode:$("#shipPostcode").val(),phone:$("#shipPhoneNumber").val(),password:$("#newCustomerPassword").val()}}).done(function(t){location.reload()}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$("#loginForm").on("click",function(t){t.isDefaultPrevented()||(t.preventDefault(),$.ajax({method:"POST",url:"/admin/login_action",data:{email:$("#email").val(),password:$("#password").val()}}).done(function(t){window.location="/admin"}).fail(function(t){showNotification(t.responseJSON.message,"danger")})),t.preventDefault()}),$("#customerLogin").on("click",function(t){t.isDefaultPrevented()||(t.preventDefault(),$.ajax({method:"POST",url:"/customer/login_action",data:{loginEmail:$("#customerLoginEmail").val(),loginPassword:$("#customerLoginPassword").val()}}).done(function(t){var e=t.customer;$("#shipEmail").val(e.email),$("#shipFirstname").val(e.firstName),$("#shipLastname").val(e.lastName),$("#shipAddr1").val(e.address1),$("#shipAddr2").val(e.address2),$("#shipCountry").val(e.country),$("#shipState").val(e.state),$("#shipPostcode").val(e.postcode),$("#shipPhoneNumber").val(e.phone),location.reload()}).fail(function(t){showNotification(t.responseJSON.message,"danger")})),t.preventDefault()}),$("#deleteCustomer").on("click",function(t){t.preventDefault(),$.ajax({method:"DELETE",url:"/admin/customer",data:{customerId:$("#customerId").val()}}).done(function(t){showNotification(t.message,"success",!1,"/admin/customers")}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$(document).on("click",".image-next",function(t){var e=$(".thumbnail-image"),a=0,o=0;$(".thumbnail-image").each(function(){$("#product-title-image").attr("src")===$(this).attr("src")&&(o=a+1===e.length||a+1<0?0:a+1),a++}),$("#product-title-image").attr("src",$(e).eq(o).attr("src"))}),$(document).on("click",".image-prev",function(t){var e=$(".thumbnail-image"),a=0,o=0;$(".thumbnail-image").each(function(){$("#product-title-image").attr("src")===$(this).attr("src")&&(o=a-1===e.length||a-1<0?e.length-1:a-1),a++}),$("#product-title-image").attr("src",$(e).eq(o).attr("src"))}),$(document).on("click","#orderStatusUpdate",function(t){$.ajax({method:"POST",url:"/admin/order/statusupdate",data:{order_id:$("#order_id").val(),status:$("#orderStatus").val()}}).done(function(t){showNotification(t.message,"success",!0)}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$(document).on("click",".product-add-to-cart",function(t){var e=getSelectedOptions();parseInt($("#product_quantity").val())<0&&$("#product_quantity").val(0),$.ajax({method:"POST",url:"/product/addtocart",data:{productId:$("#productId").val(),productQuantity:$("#product_quantity").val(),productOptions:JSON.stringify(e),productComment:$("#product_comment").val()}}).done(function(t){$("#cart-count").text(t.totalCartItems),updateCartDiv(),showNotification(t.message,"success")}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$(".cart-product-quantity").on("input",function(){cartUpdate()}),$(document).on("click",".pushy-link",function(t){$("body").removeClass("pushy-open-right")}),$(document).on("click",".add-to-cart",function(t){var e="/product/"+$(this).attr("data-id");$(this).attr("data-link")&&(e="/product/"+$(this).attr("data-link")),"true"===$(this).attr("data-has-options")?window.location=e:$.ajax({method:"POST",url:"/product/addtocart",data:{productId:$(this).attr("data-id")}}).done(function(t){$("#cart-count").text(t.totalCartItems),updateCartDiv(),showNotification(t.message,"success")}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$(document).on("click","#empty-cart",function(t){$.ajax({method:"POST",url:"/product/emptycart"}).done(function(t){$("#cart-count").text(t.totalCartItems),updateCartDiv(),showNotification(t.message,"success",!0)})}),$(".qty-btn-minus").on("click",function(){var t=parseInt($("#product_quantity").val())-1;$("#product_quantity").val(t>0?t:1)}),$(".qty-btn-plus").on("click",function(){$("#product_quantity").val(parseInt($("#product_quantity").val())+1)}),$(".thumbnail-image").on("click",function(){$("#product-title-image").attr("src",$(this).attr("src"))}),$(".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(t){showNotification(t.message,"success",!0)}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$(".btn-delete-image").on("click",function(){$.ajax({method:"POST",url:"/admin/product/deleteimage",data:{product_id:$("#productId").val(),productImage:$(this).attr("data-id")}}).done(function(t){showNotification(t.message,"success",!0)}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$(document).on("click","#validate_permalink",function(t){""!==$("#productPermalink").val()?$.ajax({method:"POST",url:"/admin/api/validate_permalink",data:{permalink:$("#productPermalink").val(),docId:$("#productId").val()}}).done(function(t){showNotification(t.message,"success")}).fail(function(t){showNotification(t.responseJSON.message,"danger")}):showNotification("Please enter a permalink to validate","danger")}),$(document).on("click","#btn_product_filter",function(t){""!==$("#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(t){""!==$("#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(t){""!==$("#customer_filter").val()?window.location.href="/admin/customers/filter/"+$("#customer_filter").val():showNotification("Please enter a keyword to filter","danger")}),$(document).on("click","#btn_search_reset",function(t){window.location.replace("/")}),$(document).on("click","#btn_search",function(t){t.preventDefault(),""===$("#frm_search").val().trim()?showNotification("Please enter a search value","danger"):window.location.href="/search/"+$("#frm_search").val()}),$(document).on("click","#frm_edit_product_save",function(t){""===$("#productPermalink").val()&&""!==$("#productTitle").val()&&$("#productPermalink").val(slugify($("#productTitle").val()))}),""!==$("#input_notify_message").val()){var l=$("#input_notify_message").val(),u=$("#input_notify_messageType").val();$("#input_notify_message").val(""),$("#input_notify_messageType").val(""),showNotification(l,u,!1)}}); \ No newline at end of file +function deleteFromCart(t){$.ajax({method:"POST",url:"/product/removefromcart",data:{cartId:t.attr("data-id")}}).done(function(a){$("#cart-count").text(a.totalCartItems),0===a.totalCartItems?($(t).closest(".cart-row").hide("slow",function(){$(t).closest(".cart-row").remove()}),$(".cart-contents-shipping").hide("slow",function(){$(".cart-contents-shipping").remove()}),showNotification(a.message,"success"),setTimeout(function(){window.location="/"},3700)):($(t).closest(".cart-row").hide("slow",function(){$(t).closest(".cart-row").remove()}),showNotification(a.message,"success"))}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}function cartUpdate(t){$(t).val()>0?""!==$(t).val()&&updateCart():$(t).val(1)}function updateCart(){var t=[];$(".cart-product-quantity").each(function(){var a={cartIndex:$(this).attr("id"),itemQuantity:$(this).val(),productId:$(this).attr("data-id")};t.push(a)}),$.ajax({method:"POST",url:"/product/updatecart",data:{items:JSON.stringify(t)}}).done(function(t){updateCartDiv(),$("#cart-count").text(t.totalCartItems)}).fail(function(t){showNotification(t.responseJSON.message,"danger",!0)})}function updateCartDiv(){var t=window.location.pathname.split("/").length>0?window.location.pathname.split("/")[1]:"";$.ajax({method:"GET",url:"/cartPartial",data:{path:t}}).done(function(t){$("#cart").html(t)}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}function getSelectedOptions(){var t={};return $(".product-opt").each(function(){if("opt-"!==$(this).attr("name")){var a=$(this).val().trim();"radio"===$(this).attr("type")&&(a=$('input[name="'+$(this).attr("name")+'"]:checked').val()),t[$(this).attr("name").substring(4,$(this).attr("name").length)]=a}else t[$(this).val().trim()]=$(this).prop("checked")}),t}$(document).ready(function(){if("Material"===$("#cartTheme").val()&&$(".materialboxed").materialbox(),$(window).width()<768&&($(".menu-side").on("click",function(t){t.preventDefault(),$('.menu-side li:not(".active")').slideToggle()}),$('.menu-side li:not(".active")').hide(),$(".menu-side>.active").html(''),$(".menu-side>.active").addClass("menu-side-mobile"),0===$("#navbar ul li").length&&$("#navbar").hide(),$("#offcanvasClose").hide()),$(".shipping-form input").each(function(t){$(this).wrap("
    ");var a=$(this).attr("placeholder");$(this).after('")}),$(".shipping-form input").on("focus",function(){$(this).next().addClass("floatLabel"),$(this).next().removeClass("hidden")}),$(".shipping-form input").on("blur",function(){""===$(this).val()&&($(this).next().addClass("hidden"),$(this).next().removeClass("floatLabel"))}),$(".menu-btn").on("click",function(t){t.preventDefault()}),$("table").each(function(){$(this).addClass("table table-hover")}),$("#productTags").tokenfield(),$(document).on("click",".dashboard_list",function(t){window.document.location=$(this).attr("href")}).hover(function(){$(this).toggleClass("hover")}),$(".product-title").dotdotdot({ellipsis:"..."}),$(document).on("click",".btn-qty-minus",function(t){var a=$(t.target).parent().parent().find(".cart-product-quantity");$(a).val(parseInt(a.val())-1),cartUpdate(a)}),$(document).on("click",".btn-qty-add",function(t){var a=$(t.target).parent().parent().find(".cart-product-quantity");$(a).val(parseInt(a.val())+1),cartUpdate(a)}),$(document).on("change",".cart-product-quantity",function(t){cartUpdate(t.target)}),$(document).on("click",".btn-delete-from-cart",function(t){deleteFromCart($(t.target))}),$("#pager").length){var t=$("#pageNum").val(),a=$("#productsPerPage").val(),e=$("#totalProductCount").val(),n=$("#paginateUrl").val(),o=$("#searchTerm").val();""!==o&&(o+="/");var i="/"+n+"/"+o+"{{number}}",r=Math.ceil(e/a);parseInt(e)>parseInt(a)&&$("#pager").bootpag({total:r,page:t,maxVisible:5,href:i,wrapClass:"pagination",prevClass:"waves-effect",nextClass:"waves-effect",activeClass:"pag-active waves-effect"})}if($("#customerLogout").on("click",function(t){$.ajax({method:"POST",url:"/customer/logout",data:{}}).done(function(t){location.reload()})}),$("#createCustomerAccount").validator().on("click",function(t){t.preventDefault(),0===$("#shipping-form").validator("validate").has(".has-error").length&&$.ajax({method:"POST",url:"/customer/create",data:{email:$("#shipEmail").val(),firstName:$("#shipFirstname").val(),lastName:$("#shipLastname").val(),address1:$("#shipAddr1").val(),address2:$("#shipAddr2").val(),country:$("#shipCountry").val(),state:$("#shipState").val(),postcode:$("#shipPostcode").val(),phone:$("#shipPhoneNumber").val(),password:$("#newCustomerPassword").val()}}).done(function(t){location.reload()}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$("#loginForm").on("click",function(t){t.isDefaultPrevented()||(t.preventDefault(),$.ajax({method:"POST",url:"/admin/login_action",data:{email:$("#email").val(),password:$("#password").val()}}).done(function(t){window.location="/admin"}).fail(function(t){showNotification(t.responseJSON.message,"danger")})),t.preventDefault()}),$("#customerLogin").on("click",function(t){t.isDefaultPrevented()||(t.preventDefault(),$.ajax({method:"POST",url:"/customer/login_action",data:{loginEmail:$("#customerLoginEmail").val(),loginPassword:$("#customerLoginPassword").val()}}).done(function(t){var a=t.customer;$("#shipEmail").val(a.email),$("#shipFirstname").val(a.firstName),$("#shipLastname").val(a.lastName),$("#shipAddr1").val(a.address1),$("#shipAddr2").val(a.address2),$("#shipCountry").val(a.country),$("#shipState").val(a.state),$("#shipPostcode").val(a.postcode),$("#shipPhoneNumber").val(a.phone),location.reload()}).fail(function(t){showNotification(t.responseJSON.message,"danger")})),t.preventDefault()}),$(document).on("click",".image-next",function(t){var a=$(".thumbnail-image"),e=0,n=0;$(".thumbnail-image").each(function(){$("#product-title-image").attr("src")===$(this).attr("src")&&(n=e+1===a.length||e+1<0?0:e+1),e++}),$("#product-title-image").attr("src",$(a).eq(n).attr("src"))}),$(document).on("click",".image-prev",function(t){var a=$(".thumbnail-image"),e=0,n=0;$(".thumbnail-image").each(function(){$("#product-title-image").attr("src")===$(this).attr("src")&&(n=e-1===a.length||e-1<0?a.length-1:e-1),e++}),$("#product-title-image").attr("src",$(a).eq(n).attr("src"))}),$(document).on("click",".product-add-to-cart",function(t){var a=getSelectedOptions();parseInt($("#product_quantity").val())<0&&$("#product_quantity").val(0),$.ajax({method:"POST",url:"/product/addtocart",data:{productId:$("#productId").val(),productQuantity:$("#product_quantity").val(),productOptions:JSON.stringify(a),productComment:$("#product_comment").val()}}).done(function(t){$("#cart-count").text(t.totalCartItems),updateCartDiv(),showNotification(t.message,"success")}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$(".cart-product-quantity").on("input",function(){cartUpdate()}),$(document).on("click",".pushy-link",function(t){$("body").removeClass("pushy-open-right")}),$(document).on("click",".add-to-cart",function(t){var a="/product/"+$(this).attr("data-id");$(this).attr("data-link")&&(a="/product/"+$(this).attr("data-link")),"true"===$(this).attr("data-has-options")?window.location=a:$.ajax({method:"POST",url:"/product/addtocart",data:{productId:$(this).attr("data-id")}}).done(function(t){$("#cart-count").text(t.totalCartItems),updateCartDiv(),showNotification(t.message,"success")}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$(document).on("click","#empty-cart",function(t){$.ajax({method:"POST",url:"/product/emptycart"}).done(function(t){$("#cart-count").text(t.totalCartItems),updateCartDiv(),showNotification(t.message,"success",!0)})}),$(".qty-btn-minus").on("click",function(){var t=parseInt($("#product_quantity").val())-1;$("#product_quantity").val(t>0?t:1)}),$(".qty-btn-plus").on("click",function(){$("#product_quantity").val(parseInt($("#product_quantity").val())+1)}),$(".thumbnail-image").on("click",function(){$("#product-title-image").attr("src",$(this).attr("src"))}),$(document).on("click","#btn_search_reset",function(t){window.location.replace("/")}),$(document).on("click","#btn_search",function(t){t.preventDefault(),""===$("#frm_search").val().trim()?showNotification("Please enter a search value","danger"):window.location.href="/search/"+$("#frm_search").val()}),""!==$("#input_notify_message").val()){var c=$("#input_notify_message").val(),s=$("#input_notify_messageType").val();$("#input_notify_message").val(""),$("#input_notify_messageType").val(""),showNotification(c,s,!1)}}); \ No newline at end of file diff --git a/views/layouts/layout.hbs b/views/layouts/layout.hbs index f401cf3..cc65c49 100644 --- a/views/layouts/layout.hbs +++ b/views/layouts/layout.hbs @@ -42,7 +42,11 @@ {{#unless admin}} {{/unless}} + + {{#if admin}} + + {{/if}}