No items found in your shopping cart
Continue Shopping
  • * These dates are an indication and only apply if we receive your payment and if document upload time is respected

    Subtotal
    RM 0
  • Grand Total
    RM 0
'); }); feather.replace(); // Initialize artwork organizer & checker var artworkPages = $('#artwork_pages_' + cartItemId).val(); if (jobSet > 1) { // Show organizer controls $('#assign_artwork_prev_btn, #assign_artwork_next_btn').removeClass('d-none'); $('#assign_artwork_next_btn').parent('.page-item').removeClass('disabled'); } // if (artworkPages > 1) { if (hasBackPage) { // Show organizer back page handler $('#assign_artwork_back').removeClass('d-none'); } updateArtworkOrganizer(cartItemId, artworkFiles, currSet); updateArtworkChecker(cartItemId, artworkFiles, artworkPages); /* Reset tab index */ tabIndex = 0; /* Check initial step setting */ var initStep = $btn.attr('data-step'); if (initStep == '1') { /* Show 1st tab */ $('#' + steps[0] + '_tab').tab('show'); /* Hide other tab */ $('#' + steps[1] + '_tab').removeClass('show active'); } if (initStep == '2') { /* Show 2nd tab */ $('#' + steps[1] + '_tab').tab('show'); /* Hide other tabs */ $('#' + steps[0] + '_tab').removeClass('show active'); /* Show only submit button */ $('#artwork_modal_back_btn, #artwork_modal_next_btn').addClass('d-none'); $('#artwork_modal_submit_btn').removeClass('d-none'); } // console.log('tabIndex: '+tabIndex); // console.log('initStep: '+initStep); }); $('#upload_artwork_modal').on('hide.bs.modal', function() { currSet = 1; // Reset current job set // Reset artwork checklist, organizer and checker $('#upload_artwork_checklist, #front_files, #back_files, #selected_artwork_checklist').html(''); // Hide organizer controls $('#assign_artwork_prev_btn, #assign_artwork_next_btn').addClass('d-none'); $('#assign_artwork_prev_btn').parent('.page-item').addClass('disabled'); // Hide organizer back page handler $('#assign_artwork_back').addClass('d-none'); // Reset tab for (var j = 0; j < steps.length; j++) { $('#' + steps[j] + '_tab').removeClass('show active'); } tabIndex = 0; /* Show first tab */ $('#' + steps[0] + '_tab').tab('show'); /* Reset buttons and checkboxes */ $('#artwork_modal_back_btn').prop('disabled', true); $('#artwork_modal_back_btn').removeClass('d-none'); $('#artwork_modal_next_btn').removeClass('d-none'); $('#confirm_artwork_checkbox').prop('checked', false); $('#artwork_modal_submit_btn').addClass('d-none disabled'); }); // ------------------------------------------------------------------- // Artwork Modal Controls // ------------------------------------------------------------------- $('#artwork_modal_next_btn').on('click', function() { // console.log('next tabIndex: '+tabIndex); /* Hide current tab */ $('#' + steps[tabIndex] + '_tab').removeClass('show active'); /* Increment tab index & show next tab */ tabIndex++; $('#' + steps[tabIndex] + '_tab').addClass('show active'); // console.log('next tabIndex: '+tabIndex); /* Activate back button */ $('#artwork_modal_back_btn').prop('disabled', false); /* Check if reach last tab */ if ((tabIndex + 1) >= steps.length) { tabIndex = (steps.length - 1); $('#artwork_modal_next_btn').addClass('d-none'); $('#artwork_modal_submit_btn').removeClass('d-none'); } }); $('#artwork_modal_back_btn').on('click', function() { // console.log('back tabIndex: '+tabIndex); /* Hide current tab */ $('#' + steps[tabIndex] + '_tab').removeClass('show active'); /* Decrement tab index & show previous tab */ tabIndex--; $('#' + steps[tabIndex] + '_tab').addClass('show active'); // console.log('back tabIndex: '+tabIndex); /* Activate next button */ $('#artwork_modal_next_btn').removeClass('d-none'); /* Reset confirm checkbox and hide submit button */ $('#confirm_artwork_checkbox').prop('checked', false); $('#artwork_modal_submit_btn').addClass('d-none disabled'); /* Check if reach first tab */ if (tabIndex <= 0) { tabIndex = 0; $('#artwork_modal_back_btn').prop('disabled', true); } }); // ------------------------------------------------------------------- // Artwork Organizer Functions // ------------------------------------------------------------------- // Artwork show previous button $('#assign_artwork_prev_btn').on('click', function(e) { e.preventDefault(); var cartItemId = $(this).attr('data-id'), jobSet = $('#job_set_' + cartItemId).val(), artworkFiles = JSON.parse($('#artwork_files_' + cartItemId).val()), artworkPages = $('#artwork_pages_' + cartItemId).val(); if (currSet > 1) { currSet--; } // Button control if (currSet == 1) { $('#assign_artwork_prev_btn').parent('.page-item').addClass('disabled'); } $('#assign_artwork_next_btn').parent('.page-item').removeClass('disabled'); // update updateArtworkOrganizer(cartItemId, artworkFiles, currSet); }); // Artwork show next button $('#assign_artwork_next_btn').on('click', function(e) { e.preventDefault(); var cartItemId = $(this).attr('data-id'), jobSet = $('#job_set_' + cartItemId).val(), artworkFiles = JSON.parse($('#artwork_files_' + cartItemId).val()), artworkPages = $('#artwork_pages_' + cartItemId).val(); if (currSet < jobSet) { currSet++; } // Button control if (currSet == jobSet) { $('#assign_artwork_next_btn').parent('.page-item').addClass('disabled'); } $('#assign_artwork_prev_btn').parent('.page-item').removeClass('disabled'); // update updateArtworkOrganizer(cartItemId, artworkFiles, currSet); }); // Artwork assign to all button $('#upload_artwork_modal').on('click', '[name="artwork_assign_all"]', function() { // Make sure the Assign-All checkbox is checked if ($(this).prop('checked') == false) { return; } $(this).prop('disabled', true); var cartItemId = $(this).attr('data-id'), setIndex = $(this).attr('data-set-index'), fileIndex = $(this).attr('data-file-index'); var $fileContainer = $('#artworkSelected_' + cartItemId + '_' + setIndex + '_' + fileIndex), file = JSON.parse($fileContainer.attr('data-file')); // Make sure there's artwork file selected if (typeof file.file_id == 'undefined') { // Reset the Assign-All checkbox $(this).prop('checked', false).prop('disabled', false); sp.modal.warning('Please select your artwork file first.', false); return; } var jobSet = $('#job_set_' + cartItemId).val(), artworkFiles = JSON.parse($('#artwork_files_' + cartItemId).val()), artworkPages = $('#artwork_pages_' + cartItemId).val(), selectedFiles = JSON.parse($('#selected_files_' + cartItemId).val()); // var queueFiles = []; for (var i = 1; i <= jobSet; i++) { if (typeof selectedFiles['set_' + i] == 'undefined') { selectedFiles['set_' + i] = {}; } selectedFiles['set_' + i]['file_' + fileIndex] = file.file_id; /* queueFiles.push({ set_index: i, file_index: fileIndex, file_id: file.file_id }); */ } // Update selected files $('#selected_files_' + cartItemId).val(JSON.stringify(selectedFiles)); updateArtworkChecker(cartItemId, artworkFiles, artworkPages); // ----------------------------------------------------------------- /* DEPRECATED: Save selected artwork files to database var $chkbox = $(this), chkboxText = $chkbox.siblings('label').html(); var action = 'ARTWORK_ADD_FILES', url = $('#data_'+action+'_URL').val() + cartItemId; // artwork/ajaxSelectFiles/ sp.ajax.post(url, action, { files: queueFiles }, { success: function(response) { // sp.modal.success('Successfully assign file ('+file.name+') to all sets.'); if (typeof callback == 'function') { callback(); } }, error: function (response, code, err) { }, beforeSend: function() { $chkbox.prop('disabled', true); $chkbox.siblings('label').html(chkboxText+' '); }, complete: function() { $chkbox.prop('disabled', false); $chkbox.siblings('label').html(chkboxText+' '); window.setTimeout(function() { $chkbox.siblings('label').html(chkboxText); }, 1500); updateArtworkChecker(cartItemId, artworkFiles, artworkPages); } }); */ }); // Update artwork organizer function updateArtworkOrganizer(cartItemId, artworkFiles, currSet) { // Initialize $('#assign_artwork_current').html(currSet); $('#front_files, #back_files').html(''); // Prepare organizer for current set $.each(artworkFiles, function(fileIndex, file) { var content = '' + '
' + ' ' + '
' + '
' + '
' + file.name + '
' + '
' + file.description + '
' + '
' + ' ' + ' ' + '
' + '
' + '
' + ' ' + ' No file selected yet' + '
' + '
' + '
'; $('#' + file.parent + '_files').append(content); // Append to parent (front or back) // Load selected files into organizer updateSelectedFiles(cartItemId, currSet, fileIndex); }); } // Update artwork checker function updateArtworkChecker(cartItemId, artworkFiles, artworkPages) { var $container = $('#selected_artwork_checklist'), jobSet = $('#job_set_' + cartItemId).val(); // Initialize $container.html(''); for (var i = 1; i <= jobSet; i++) { var content = '', setIndex = i, uploadedFiles = JSON.parse($('#data_uploaded_files').val()), selectedFiles = JSON.parse($('#selected_files_' + cartItemId).val()); if (i > 1) { content += '
'; } content += '
Set No. #' + setIndex + '
'; $.each(artworkFiles, function(fileIndex, file) { var hasArtworkFile = false; // If artwork file selected if (typeof selectedFiles['set_' + setIndex] !== 'undefined') { var fileId = 0; // Get artwork file id if (typeof selectedFiles['set_' + setIndex] !== 'undefined' && typeof selectedFiles['set_' + setIndex]['file_' + fileIndex] !== 'undefined' ) { fileId = selectedFiles['set_' + setIndex]['file_' + fileIndex]; } var selectedFile = {}; // Get artwork file info $.each(uploadedFiles, function(i, uploadedFile) { if (uploadedFile.file_id == fileId) { selectedFile = uploadedFile; } }); if (typeof selectedFile.name !== 'undefined') { hasArtworkFile = true; } } // End of If/Else content += '
'; if (hasArtworkFile) { content += ' '; } else { content += ' '; } content += '
'; content += '
'; content += '
' + file.name + '
'; content += '
' + file.description + '
'; content += '
'; content += '
'; if (hasArtworkFile) { content += ' '; content += '
' + selectedFile.name + '
'; content += ' Size: ' + selectedFile.size_text + ''; } else { content += ' '; content += '
No file selected
'; } content += '
'; content += '
'; content += ' '; content += '
'; content += '
'; content += '
'; }); $container.append(content); } } // ------------------------------------------------------------------- // Artwork Select Functions // ------------------------------------------------------------------- var tmpData = { cartItemId: 0, setIndex: 0, fileIndex: 0 }; $('#select_artwork_modal').on('show.bs.modal', function(e) { var $btn = $(e.relatedTarget); tmpData.cartItemId = $btn.attr('data-id'), tmpData.setIndex = $btn.attr('data-set-index'), tmpData.fileIndex = $btn.attr('data-file-index'); }); $('#select_artwork_modal').on('hidden.bs.modal', function() { // Solve the multiple modal scrollbar problem $('body').addClass('modal-open'); }); // Select Artwork Button $('#select_artwork_modal').on('click', '.js__select-artwork', function() { var $btn = $(this), btnText = $(this).text(); // Add loading state $btn.addClass('disabled'); $btn.text('loading...'); var cartItemId = tmpData.cartItemId, setIndex = tmpData.setIndex, fileIndex = tmpData.fileIndex, file = JSON.parse($(this).attr('data-file')); // Update selected file on organizer var $target = $('#artworkSelected_' + cartItemId + '_' + setIndex + '_' + fileIndex); $target.addClass('text-primary font-weight-bold'); $target.attr('data-file', JSON.stringify(file)); $target.text('selected: ' + file.name); // Update selected file on cart item var selectedFiles = JSON.parse($('#selected_files_' + cartItemId).val()); if (typeof selectedFiles['set_' + setIndex] == 'undefined') { selectedFiles['set_' + setIndex] = {}; } selectedFiles['set_' + setIndex]['file_' + fileIndex] = file.file_id; $('#selected_files_' + cartItemId).val(JSON.stringify(selectedFiles)); // Update artwork checker var artworkFiles = JSON.parse($('#artwork_files_' + cartItemId).val()), artworkPages = $('#artwork_pages_' + cartItemId).val(); updateArtworkChecker(cartItemId, artworkFiles, artworkPages); updateArtworkOrganizer(cartItemId, artworkFiles, setIndex); // Remove loading state $btn.removeClass('disabled'); $btn.text(btnText); $('#select_artwork_modal').modal('hide'); // ----------------------------------------------------------------- /* DEPRECATED: Save selected artwork file to database var action = 'ARTWORK_ADD_FILE', url = $('#data_'+action+'_URL').val() + cartItemId; // artwork/ajaxSelectFile/ sp.ajax.post(url, action, { setIndex: setIndex, fileIndex: fileIndex, fileId: file.file_id, buttons: buttons }, { success: function(response) { // Update selected file for appointed organizer $target.addClass('text-primary font-weight-bold'); $target.attr('data-file', JSON.stringify(file)); $target.text('selected: '+file.name); // Update selected file for appointed cart item var selectedFiles = JSON.parse($('#selected_files_'+cartItemId).val()); if (typeof selectedFiles['set_'+setIndex] == 'undefined') { selectedFiles['set_'+setIndex] = {}; } selectedFiles['set_'+setIndex]['file_'+fileIndex] = file.file_id; $('#selected_files_'+cartItemId).val(JSON.stringify(selectedFiles)); }, error: function (response, code, err) { }, beforeSend: function() { $btn.addClass('disabled'); $btn.text('loading...'); }, complete: function() { $btn.removeClass('disabled'); $btn.text(btnText); $('#select_artwork_modal').modal('hide'); updateArtworkChecker(cartItemId, artworkFiles, artworkPages); } }); */ }); // ------------------------------------------------------------------- // Artwork Submit Functions // ------------------------------------------------------------------- // Confirm artwork button $('#confirm_artwork_checkbox').on('change', function() { if ($(this).prop('checked')) { $('#artwork_modal_submit_btn').removeClass('disabled'); return; } $('#artwork_modal_submit_btn').addClass('disabled'); }); // Submit artwork button $('#artwork_modal_submit_btn').on('click', function() { if ($(this).hasClass('disabled')) { sp.modal.warning('Please confirm that all the artwork files selected are correct.', false); return; } var $btn = $(this), btnText = $btn.text(); // Add loading state $btn.addClass('disabled'); $btn.html('Checking...'); var cartItemId = $btn.attr('data-id'), jobSet = $('#job_set_' + cartItemId).val(), artworkFiles = JSON.parse($('#artwork_files_' + cartItemId).val()), artworkPages = $('#artwork_pages_' + cartItemId).val(); var queuedFiles = [], // Files to be submitted error = 0; // Error counter // Fetch selected artwork files for (var i = 1; i <= jobSet; i++) { var setIndex = i; $.each(artworkFiles, function(fileIndex, file) { var selectedFile = JSON.parse($('#selectedFile_' + cartItemId + '_' + setIndex + '_' + fileIndex).val()); // If no file selected if (typeof selectedFile.file_id == 'undefined') { error++; } // Else, add the file into queue else { queuedFiles.push({ set_index: setIndex, file_index: fileIndex, file_id: selectedFile.file_id }); } }); } if (error > 0) { $('#confirm_artwork_checkbox').prop('checked', false); $btn.html(btnText); sp.modal.warning('Please assign artwork file to all printing pages. Check again.', false); return; } // Submit artwork files to database var action = 'ARTWORK_ADD_FILES', url = $('#' + action + '_API').val() + cartItemId; sp.ajax.post(url, action, { files: queuedFiles }, { success: function(response) { // Update artwork handler status $('#upload_artwork_btn_' + cartItemId).text('Edit Artwork'); $('#upload_artwork_btn_' + cartItemId).removeClass('btn-primary').addClass('btn-success'); $('#upload_artwork_btn_' + cartItemId).attr('data-step', 2); sp.modal.success('Artwork files have been submitted successfully.'); }, error: function(response, code, err) { switch (code) { case 406: sp.modal.error('ERR_' + action + ': Fail to submit artwork files of cart item ID: ' + cartItemId + '
' + response.message); break; default: sp.modal.error('Uncaught Error ERR_' + action + ': ' + err); } }, beforeSend: function() { $btn.html('Submitting...'); }, complete: function() { $btn.removeClass('disabled'); $btn.text(btnText); } }); }); // ------------------------------------------------------------------- // Artwork Upload Functions // ------------------------------------------------------------------- var uploaderUrl = $('#ARTWORK_UPLOAD_HANDLER_API').val(), uploader = { 0: { 'target': '#upload_artwork_uploader', 'dropZone': '#upload_artwork_dropzone' }, 1: { 'target': '#upload_artwork_uploader2', 'dropZone': '#upload_artwork_dropzone2' } }; $.each(uploader, function(i, uploader) { $(uploader.target).fileupload({ dropZone: $(uploader.dropZone), singleFileUploads: false, // BUG: Unknown error while trying to upload files // Temporary fix using Labcommerce Upload Handler url: uploaderUrl, //"https://www.senangprint.com/artwork/upload/handler", dataType: 'json', add: function(e, data) { var errFiles = []; // Validate file types $.each(data.files, function(i, file) { var str = file.name, regex = /(\.|\/)(ai|pdf|zip|rar|jpg|jpeg|png)$/i; if (regex.exec(str) == null) { errFiles.push(file.name); } }); if (errFiles.length > 0) { var errText = 'Wrong file format for selected files ('; var lastIndex = errFiles.length - 1; $.each(errFiles, function(i, filename) { errText += filename; if (i < lastIndex) { errText += ', '; } }); errText += '). Supported file format: JPG, PNG, AI, PDF, ZIP, RAR'; sp.modal.error(errText); return; } // Proceed if no file error data.submit(); }, fail: function(e, data) { console.log(data.errorThrown); console.log(data); }, done: function(e, data) { var cartId = $('#data_cart_id').val(), action = 'CART_ADD_FILES', url = $('#' + action + '_API').val() + cartId; console.log('uploaded') sp.ajax.post(url, action, { files: data.result.files }, { success: function(response) { if (typeof response.results.successFiles !== 'undefined') { var uploadedFiles = JSON.parse($('#data_uploaded_files').val()), newUploadedFiles = response.results.successFiles; newUploadedFiles = response.results.successFiles; if (newUploadedFiles.length > 0) { $.merge(uploadedFiles, newUploadedFiles); $('#data_uploaded_files').val(JSON.stringify(uploadedFiles)); updateUploadedFiles(); var fileCount = newUploadedFiles.length; $('#upload_artwork_uploaded, #upload_artwork_uploaded2').removeClass('d-none'); $('#upload_artwork_uploaded_files, #upload_artwork_uploaded_files2').text(fileCount + (fileCount > 1 ? ' files' : ' file')); } } if (typeof response.results.errorFiles !== 'undefined') { var errorFiles = response.results.errorFiles; if (errorFiles.length > 0) { var errorFileText = ''; $.each(errorFiles, function(i, filename) { errorFileText += filename + ', '; }); errorFileText = errorFileText.slice(0, -1); // Remove trailing comma var fileText = (errorFiles.length > 1) ? 'this file' : 'these files'; sp.modal.error('An error encountered when trying to save ' + fileText + ':
' + errorFileText); } } }, error: function(response, code, err) { switch (code) { case 406: sp.modal.error('ERR_' + action + ': Fail to save artwork files to database
' + response.message); break; default: sp.modal.error('Uncaught Error ERR_' + action + ': ' + err); } } }); $('#upload_artwork_uploading, #upload_artwork_uploading2').addClass('d-none'); window.setTimeout(function() { $('#upload_artwork_progress, #upload_artwork_progress2').css('width', '0%').attr('aria-valuenow', '0'); $('#upload_artwork_progress_percent, #upload_artwork_progress_percent2').text('0'); $('#upload_artwork_uploaded, #upload_artwork_uploaded2').addClass('d-none'); $('#upload_artwork_uploaded_files, #upload_artwork_uploaded_files2').text('0 file'); }, 3000); $('#upload_artwork_uploader, #upload_artwork_uploader2').prop('disabled', false); }, progressall: function(e, data) { $('#upload_artwork_uploader, #upload_artwork_uploader2').prop('disabled', true); var progress = parseInt(data.loaded / data.total * 100, 10); $('#upload_artwork_uploading, #upload_artwork_uploading2').removeClass('d-none'); $('#upload_artwork_progress, #upload_artwork_progress2').css('width', progress + '%'); $('#upload_artwork_progress, #upload_artwork_progress2').attr('aria-valuenow', progress); $('#upload_artwork_progress_percent, #upload_artwork_progress_percent2').text(progress); } }); }); // Dropzone animation on Drag event $(document).bind('dragover', function(e) { e.preventDefault(); e.stopPropagation(); var dropZone = $('#upload_artwork_dropzone, #upload_artwork_dropzone2'), timeout = window.dropZoneTimeout; if (timeout) { clearTimeout(timeout); } else { dropZone.addClass('bg-light'); dropZone.find('.js__resting').addClass('d-none'); dropZone.find('.js__dropping').removeClass('d-none'); } window.dropZoneTimeout = setTimeout(function() { window.dropZoneTimeout = null; dropZone.removeClass('bg-light'); dropZone.find('.js__resting').removeClass('d-none'); dropZone.find('.js__dropping').addClass('d-none'); }, 100); }); // Stop the default browser action from opening the file $(document).bind('drop dragover', function(e) { e.preventDefault(); e.stopPropagation(); }); // Update uploaded files function updateUploadedFiles() { var files = JSON.parse($('#data_uploaded_files').val()); if (files.length > 0) { $('#uploaded_files').find('.js__empty-state').remove(); } $('#uploaded_files').html(''); $.each(files, function(i, file) { var html = '' + '
' + ' ' + '
' + '
' + '
' + file.name + '
' + '
Size: ' + file.size_text + '
' + '
' + '
' + ' ' + '
' + '
' + '
'; $('#uploaded_files').prepend(html); }); } updateUploadedFiles(); // Update selected files function updateSelectedFiles(cartItemId, setIndex, fileIndex) { var $target = $('#artworkSelected_' + cartItemId + '_' + setIndex + '_' + fileIndex), $assignAllSelector = $('#artworkAssignAll_' + cartItemId + '_' + setIndex + '_' + fileIndex), uploadedFiles = JSON.parse($('#data_uploaded_files').val()), selectedFiles = JSON.parse($('#selected_files_' + cartItemId).val()); $assignAllSelector.prop('disabled', true); if (typeof selectedFiles['set_' + setIndex] == 'undefined') return; if (typeof selectedFiles['set_' + setIndex]['file_' + fileIndex] == 'undefined') return; var fileId = selectedFiles['set_' + setIndex]['file_' + fileIndex]; $.each(uploadedFiles, function(i, uploadedFile) { if (uploadedFile.file_id == fileId) { $target.addClass('text-primary font-weight-bold'); $target.attr('data-file', JSON.stringify(uploadedFile)); $target.text('selected: ' + uploadedFile.name); return; } }); $assignAllSelector.prop('disabled', false); $('#selected_files_' + cartItemId).val(JSON.stringify(selectedFiles)); $('#artworkPreview_' + cartItemId + '_' + setIndex + '_' + fileIndex).attr('src', 'https://cdn-icons-png.flaticon.com/64/680/680065.png'); } }); // ------------------------------------------------------------------- // Checkout Handler // ------------------------------------------------------------------- $(function() { $('.js__checkout-btn').on('click', function(e) { e.preventDefault(); var redirectUrl = $('#CHECKOUT_URL').val(), items = $('#cart_contents').children(), selectedItems = [], errItemCounter = 0; // Get selected items $.each(items, function(i, item) { var cartItemId = $(item).attr('id').replace('item_', ''), selected = $('#item_checkbox_' + cartItemId).prop('checked'), jobSet = $('#job_set_' + cartItemId).val(), artworkFiles = JSON.parse($('#artwork_files_' + cartItemId).val()), selectedFiles = JSON.parse($('#selected_files_' + cartItemId).val()), submittedFiles = JSON.parse($('#submitted_files_' + cartItemId).val()); if (selected) { // Add item to queue selectedItems.push(cartItemId); } else { // Skip if item not selected return; } submittedFiles = $.extend(submittedFiles, selectedFiles); var submittedFileArray = Object.keys(submittedFiles).map(function(key) { return submittedFiles[key]; }); // Check for empty artwork files if (submittedFileArray.length != jobSet) { errItemCounter++; } else { var errFileCounter = 0; $.each(submittedFiles, function(i, files) { var fileArray = Object.keys(files).map(function(key) { return files[key]; }); if (fileArray.length != artworkFiles.length) { errFileCounter++; } }); if (errFileCounter > 0) { errItemCounter++; } } }); // Proceed to checkout if (errItemCounter == 0) { // All artwork files assigned Cookies.set('checkout_items', JSON.stringify(selectedItems)); window.location.href = redirectUrl; } else { // More than one empty artwork file e.preventDefault(); var verb = (errItemCounter > 1 ? ' are ' : ' is '), subject = (errItemCounter > 1 ? ' cart items selected do not ' : ' cart item selected does not '), phrase = verb + errItemCounter + subject; sp.modal.confirm('There' + phrase + 'have artwork files assigned. Are you sure to proceed to checkout and upload the files later?'); $('.js-modal-confirm-btn').on('click', function() { Cookies.set('checkout_items', JSON.stringify(selectedItems)); window.location.href = redirectUrl; }); } }); }); // -------------------------------------------------------------------- // Quotation Download Handler // -------------------------------------------------------------------- $(function() { $('.js__quote-btn').on('click', function(e) { e.preventDefault(); // Get cart contents var items = $('#cart_contents').children(); // Get selected items var selectedItems = []; $.each(items, function(i, item) { // Get cart item id var cartItemId = $(item).attr('id').replace('item_', ''), // Get item checkbox status selected = $('#item_checkbox_' + cartItemId).prop('checked'); // Add item to queue if selected if (selected) { selectedItems.push(cartItemId); } }); // Show error if no item selected if (selectedItems.length == 0) { sp.modal.warning('Please select at least one item to generate quotation.'); return; } // DEBUG // alert('download quotation'); // console.log(selectedItems); // Create quotation var action = 'DOC_CREATE_QUOTATION', url = $('#' + action + '_API').val(); var btn = $(this), btnText = btn.text(); sp.ajax.post(url, action, { items: selectedItems }, { success: function(response) { // console.log(response); var downloadUrl = response.results.redirect + '/download'; window.location.href = downloadUrl; }, error: function(response, code, err) { switch (code) { case 406: sp.modal.error('ERR_' + action + ': Fail to create quotation
' + response.message); break; default: sp.modal.error('Uncaught Error ERR_' + action + ': ' + err); } }, beforeSend: function() { $(btn).html('Generating.. '); }, complete: function() { $(btn).text(btnText); } }); }); }) -->