+ /**
+ * @param {Upload} upload
+ */
+ startXhrForUpload(upload) {
+ const formData = new FormData();
+ formData.append('file', upload.file, upload.file.name);
+ if (this.method !== 'POST') {
+ formData.append('_method', this.method);
+ }
+ const component = this;
+
+ const req = window.$http.createXMLHttpRequest('POST', this.url, {
+ error() {
+ upload.markError(component.errorMessage);
+ },
+ readystatechange() {
+ if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
+ upload.markSuccess(component.successMessage);
+ } else if (this.readyState === XMLHttpRequest.DONE && this.status >= 400) {
+ upload.markError(window.$http.formatErrorResponseText(this.responseText));
+ }
+ },
+ });
+
+ req.upload.addEventListener('progress', evt => {
+ const percent = Math.min(Math.ceil((evt.loaded / evt.total) * 100), 100);
+ upload.updateProgress(percent);
+ });
+
+ req.setRequestHeader('Accept', 'application/json');
+ req.send(formData);
+ }
+
+ /**
+ * @param {File} file
+ * @return {{image: Element, dom: Element, progress: Element, status: Element, dismiss: function}}
+ */
+ createDomForFile(file) {
+ const image = elem('img', {src: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9.224 7.373a.924.924 0 0 0-.92.925l-.006 7.404c0 .509.412.925.921.925h5.557a.928.928 0 0 0 .926-.925v-5.553l-2.777-2.776Zm3.239 3.239V8.067l2.545 2.545z' style='fill:%23000;fill-opacity:.75'/%3E%3C/svg%3E"});
+ const status = elem('div', {class: 'dropzone-file-item-status'}, []);
+ const progress = elem('div', {class: 'dropzone-file-item-progress'});
+ const imageWrap = elem('div', {class: 'dropzone-file-item-image-wrap'}, [image]);
+
+ const dom = elem('div', {class: 'dropzone-file-item'}, [
+ imageWrap,
+ elem('div', {class: 'dropzone-file-item-text-wrap'}, [
+ elem('div', {class: 'dropzone-file-item-label'}, [file.name]),
+ getLoading(),
+ status,
+ ]),
+ progress,
+ ]);
+
+ if (file.type.startsWith('image/')) {
+ image.src = URL.createObjectURL(file);
+ }
+
+ const dismiss = () => {
+ dom.classList.add('dismiss');
+ dom.addEventListener('animationend', () => {
+ dom.remove();
+ });
+ };
+
+ dom.addEventListener('click', dismiss);
+
+ return {
+ dom, progress, status, dismiss,
+ };