1ACC.csvimport = { 2 TEXT_CSV_CONTENT_TYPE: 'text/csv', 3 APP_EXCEL_CONTENT_TYPE: 'application/vnd.ms-excel', 4 5 _autoload: [ 6 ["changeFileUploadAppearance", $(".js-file-upload").length != 0], 7 ["bindImportCSVActions", $(".js-import-csv").length != 0] 8 ], 9 10 changeFileUploadAppearance: function() { 11 $('.js-file-upload__input').on('change',function () { 12 var files = (this.files); 13 var spanFileNames = document.createElement("span"); 14 spanFileNames.insertAdjacentText("beforeend", files[0].name.toLowerCase()); 15 spanFileNames.insertAdjacentElement("beforeend", document.createElement("br")); 16 17 $('.js-file-upload__file-name').unbind('mouseenter mouseleave'); 18 $('.js-file-upload__file-name').html(spanFileNames); 19 20 if($('.js-file-upload').parents('#cboxLoadedContent').length > 0){ 21 ACC.colorbox.resize(); 22 } 23 }) 24 }, 25 26 bindImportCSVActions: function() { 27 $('#chooseFileButton').on('click', function (event) { 28 ACC.csvimport.clearGlobalAlerts(); 29 }); 30 31 $('#importButton').on('click', function (event) { 32 event.preventDefault(); 33 ACC.csvimport.clearGlobalAlerts(); 34 35 if (!($('.js-file-upload__input').val().trim().length > 0)) { 36 ACC.csvimport.displayGlobalAlert({type: 'error', messageId: 'import-csv-no-file-chosen-error-message'}); 37 return; 38 } 39 40 var selectedFile = document.getElementById('csvFile').files[0]; 41 if (!ACC.csvimport.isSelectedFileValid(selectedFile)) { 42 return; 43 } 44 45 var form = document.getElementById('importCSVSavedCartForm'); 46 var formData = new window.FormData(form); 47 formData.append("csvFile", selectedFile); 48 49 ACC.csvimport.displayGlobalAlert({type: 'warning', messageId: 'import-csv-upload-message'}); 50 ACC.csvimport.enableDisableActionButtons(false); 51 52 $.ajax({ 53 url: form.action, 54 type: 'POST', 55 data: formData, 56 contentType: false, 57 processData: false, 58 success: function() { 59 ACC.csvimport.displayGlobalAlert({type: 'info', message: ''}); 60 $('#import-csv-alerts .alert-info').append($('#import-csv-success-message').html()); 61 62 ACC.csvimport.clearChosenFile(); 63 }, 64 error: function(jqXHR) { 65 if (jqXHR.status == 400) { 66 if (jqXHR.responseJSON) { 67 ACC.csvimport.displayGlobalAlert({type: 'error', message: jqXHR.responseJSON}); 68 return; 69 } 70 } 71 72 ACC.csvimport.displayGlobalAlert({type: 'error', messageId: 'import-csv-generic-error-message'}); 73 }, 74 complete: function() { 75 ACC.csvimport.enableDisableActionButtons(true); 76 } 77 }); 78 }); 79 }, 80 81 isSelectedFileValid: function(selectedFile) { 82 if (window.File && window.Blob) { 83 if (selectedFile) { 84 if (!(selectedFile.type == ACC.csvimport.TEXT_CSV_CONTENT_TYPE || 85 selectedFile.type == ACC.csvimport.APP_EXCEL_CONTENT_TYPE)) { 86 ACC.csvimport.displayGlobalAlert({type: 'error', messageId: 'import-csv-file-csv-required'}); 87 return false; 88 } 89 90 var fileName = selectedFile.name; 91 if (!fileName || !(/\.csv$/i).test(fileName)) { 92 ACC.csvimport.displayGlobalAlert({type: 'error', messageId: 'import-csv-file-csv-required'}); 93 return false; 94 } 95 } 96 97 var fileMaxSize = $('.js-file-upload__input').data('file-max-size'); 98 if ($.isNumeric(fileMaxSize) && selectedFile) { 99 if (selectedFile.size > parseFloat(fileMaxSize)) { 100 ACC.csvimport.displayGlobalAlert({type: 'error', messageId: 'import-csv-file-max-size-exceeded-error-message'}); 101 return false;
102 } 103 } 104 } 105 106 return true; 107 }, 108 109 displayGlobalAlert: function(options) { 110 ACC.csvimport.clearGlobalAlerts(); 111 var alertTemplateSelector; 112 113 switch (options.type) { 114 case 'error': 115 alertTemplateSelector = '#global-alert-danger-template'; 116 break; 117 case 'warning': 118 alertTemplateSelector = '#global-alert-warning-template'; 119 break; 120 default: 121 alertTemplateSelector = '#global-alert-info-template'; 122 } 123 124 if (typeof options.message != 'undefined') { 125 $('#import-csv-alerts').append($(alertTemplateSelector).tmpl({message: options.message})); 126 } 127 128 if (typeof options.messageId != 'undefined') 129 { 130 $('#import-csv-alerts').append($(alertTemplateSelector).tmpl({message: $(document).find('#' + options.messageId).text()})); 131 } 132 133 $(".closeAccAlert").on("click", function () { 134 $(this).parent('.getAccAlert').remove(); 135 }); 136 }, 137 138 clearGlobalAlerts: function() { 139 $('#import-csv-alerts').empty(); 140 }, 141 142 clearChosenFile: function() { 143 document.getElementById('csvFile').value = ''; 144 $('.js-file-upload__file-name').text(''); 145 }, 146 147 enableDisableActionButtons: function(enable) { 148 $('#chooseFileButton').attr('disabled', !enable); 149 $('#importButton').prop('disabled', !enable); 150 } 151}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.