1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
document.addEventListener("DOMContentLoaded", function() { var progress_cat = 0; var progress_file = 0; var progress_button = 0; var progress_upload = 0; var progress_converting = 0; var progress_handler = 0; document.getElementById('upload').onclick = function() { select = parseInt(document.getElementById('category_choose').value); name_category = document.getElementById('category_choose').options[document.getElementById('category_choose').options.selectedIndex].text; file_value = document.forms.upload_file.elements.file_excel.value; if (progressRefresh() >= 60) { UIkit.notification({ message: 'Процесс уже запущен!', pos: 'bottom-right', status: 'warning' }); } else { if (!select) { UIkit.notification({ message: 'Укажите категорию!', pos: 'bottom-right', status: 'warning' }); } else { if (file_value) { UIkit.notification({ message: 'Идет загрузка файла...', pos: 'bottom-right', status: 'primary' }); progress_button = 20; progressRefresh(); } document.getElementById('spinner').classList.toggle('uk-hidden'); uploadFile(); } } return false; } document.getElementById('file_excel').onclick = function() { select = parseInt(document.getElementById('category_choose').value); if (!select) { UIkit.notification({ message: 'Укажите категорию!', pos: 'bottom-right', status: 'warning' }); return false; } } function uploadFile() { var form = document.forms.upload_file; var formData = new FormData(form); var req = new XMLHttpRequest(); req.open("POST", 'handler.php'); req.onreadystatechange = function() { if (req.readyState == 4) { request = JSON.parse(req.responseText); if (request.result) { UIkit.notification({ message: request.success, pos: 'bottom-right', status: 'success' }); progress_converting = 10; progressRefresh(); handlerParse(select, request.name); } else { UIkit.notification({ message: request.error, pos: 'bottom-right', status: 'danger' }); progress_converting = 0; progressRefresh(); } } } req.upload.onprogress = function(event) { progressSuccess = event.loaded * 100 / event.total; progressBarUpload(progressSuccess); } req.send(formData); } document.getElementById('category_choose').onchange = function() { if (this.value > 0) { progress_cat = 20; } else { progress_cat = 0; } progressRefresh(); } document.getElementById('file_excel').onchange = function() { file = document.forms.upload_file.elements.file_excel.value; if (file) { progress_file = 20; } else { progress_file = 0; } progressRefresh(); } function progressBarUpload(progress) { UIkit.util.ready(function() { var bar = document.getElementById('js-progressbar-uploadFile'); var divBar = document.getElementById('progress-upload'); if (!divBar.style.display) { divBar.style.display = 'block'; } bar.value = progress; if (bar.value >= 100) { divBar.style.display = ""; UIkit.notification({ message: 'Файл загружен на сервер...', pos: 'bottom-right', status: 'success' }); progress_upload = 20; progressRefresh(); } }); } function progressRefresh() { progress = progress_cat + progress_file + progress_button + progress_upload + progress_converting + progress_handler; document.getElementById('js-progressbar').value = progress; return progress; } function handlerParse(group, path) { var req = new JsHttpRequest(); UIkit.notification({ message: 'Идет обработка файла...', pos: 'bottom-right', status: 'primary' }); req.open(null, 'handler_update.php', true); req.onreadystatechange = function() { if (req.readyState == 4) { request = JSON.parse(req.responseText); if (request.result) { UIkit.notification({ message: request.success, pos: 'bottom-right', status: 'success' }); progress_handler = 10; progressRefresh(); setTimeout(success, 2000); } else { UIkit.notification({ message: "Произошла ошибка!", pos: 'bottom-right', status: 'danger' }); progress_handler = 0; progressRefresh(); } } } req.send({ group: group, path: path }); } function success() { name_category = document.getElementById('category_choose').options[document.getElementById('category_choose').options.selectedIndex].text; UIkit.modal.alert('Файл загружен и обработан: ' + name_category); document.getElementById('category_choose').value = document.getElementById('category_choose').options[0].text; document.getElementById('upload_file').reset(); progress_cat = 0; progress_file = 0; progress_button = 0; progress_upload = 0; progress_converting = 0; progress_handler = 0; document.getElementById('spinner').classList.toggle('uk-hidden'); progressRefresh(); } }); |