// Image Manager
'image_select' => 'Image Select',
'image_upload' => 'Upload Image',
+ 'image_intro' => 'Here you can select and manage images that have been previously uploaded to the system.',
+ 'image_intro_upload' => 'Upload a new image by dragging an image file into this window, or by using the "Upload Image" button above.',
'image_all' => 'All',
'image_all_title' => 'View all images',
'image_book_title' => 'View images uploaded to this book',
'images_deleted' => 'Images Deleted',
'image_preview' => 'Image Preview',
'image_upload_success' => 'Image uploaded successfully',
+ 'image_upload_failure' => 'Image failed to upload',
'image_update_success' => 'Image details successfully updated',
'image_delete_success' => 'Image successfully deleted',
- 'image_upload_remove' => 'Remove',
// Code Editor
'code_editor' => 'Edit Code',
this.url = this.$opts.url;
this.successMessage = this.$opts.successMessage;
- this.removeMessage = this.$opts.removeMessage;
- this.uploadLimit = Number(this.$opts.uploadLimit); // TODO - Use
- this.uploadLimitMessage = this.$opts.uploadLimitMessage; // TODO - Use
- this.timeoutMessage = this.$opts.timeoutMessage; // TODO - Use
+ this.errorMessage = this.$opts.errorMessage;
+ this.uploadLimitMb = Number(this.$opts.uploadLimit);
+ this.uploadLimitMessage = this.$opts.uploadLimitMessage;
this.zoneText = this.$opts.zoneText;
- // window.uploadTimeout // TODO - Use
+ this.fileAcceptTypes = this.$opts.fileAccept;
this.setupListeners();
}
setupListeners() {
onSelect(this.selectButtons, this.manualSelectHandler.bind(this));
+ this.setupDropTargetHandlers();
+ }
+ setupDropTargetHandlers() {
let depth = 0;
+ const reset = () => {
+ this.hideOverlay();
+ depth = 0;
+ };
+
this.dropTarget.addEventListener('dragenter', event => {
event.preventDefault();
depth += 1;
event.preventDefault();
});
- const reset = () => {
- this.hideOverlay();
- depth = 0;
- };
-
- this.dropTarget.addEventListener('dragend', event => {
- reset();
- });
-
- this.dropTarget.addEventListener('dragleave', event => {
+ this.dropTarget.addEventListener('dragend', reset);
+ this.dropTarget.addEventListener('dragleave', () => {
depth -= 1;
if (depth === 0) {
reset();
}
});
-
this.dropTarget.addEventListener('drop', event => {
event.preventDefault();
reset();
}
manualSelectHandler() {
- const input = elem('input', {type: 'file', style: 'left: -400px; visibility: hidden; position: fixed;'});
+ const input = elem('input', {type: 'file', style: 'left: -400px; visibility: hidden; position: fixed;', accept: this.fileAcceptTypes});
this.container.append(input);
input.click();
- input.addEventListener('change', event => {
+ input.addEventListener('change', () => {
for (const file of input.files) {
this.createUploadFromFile(file);
}
* @return {Upload}
*/
createUploadFromFile(file) {
- const {dom, status, progress, dismiss} = this.createDomForFile(file);
+ const {
+ dom, status, progress, dismiss,
+ } = this.createDomForFile(file);
this.statusArea.append(dom);
const component = this;
status.setAttribute('data-status', 'error');
status.textContent = message;
removeLoading(dom);
+ this.updateProgress(100);
},
markSuccess(message) {
status.setAttribute('data-status', 'success');
},
};
+ // Enforce early upload filesize limit
+ if (file.size > (this.uploadLimitMb * 1000000)) {
+ upload.markError(this.uploadLimitMessage);
+ return upload;
+ }
+
this.startXhrForUpload(upload);
return upload;
startXhrForUpload(upload) {
const formData = new FormData();
formData.append('file', upload.file, upload.file.name);
+ const component = this;
const req = window.$http.createXMLHttpRequest('POST', this.url, {
error() {
- upload.markError('Upload failed'); // TODO - Update text
+ upload.markError(component.errorMessage);
},
readystatechange() {
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
- upload.markSuccess('Finished upload!');
+ upload.markSuccess(component.successMessage);
} else if (this.readyState === XMLHttpRequest.DONE && this.status >= 400) {
const content = this.responseText;
const data = content.startsWith('{') ? JSON.parse(content) : {message: content};
* @return {{image: Element, dom: Element, progress: Element, status: Element, dismiss: function}}
*/
createDomForFile(file) {
- const image = elem('img', {src: ''});
+ 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 dismiss = () => {
dom.classList.add('dismiss');
- dom.addEventListener('animationend', event => {
+ dom.addEventListener('animationend', () => {
dom.remove();
});
};
<div components="image-manager dropzone"
option:dropzone:url="{{ url('/images/gallery?' . http_build_query(['uploaded_to' => $uploaded_to ?? 0])) }}"
option:dropzone:success-message="{{ trans('components.image_upload_success') }}"
- option:dropzone:remove-message="{{ trans('components.image_upload_remove') }}"
+ option:dropzone:error-message="{{ trans('components.image_upload_failure') }}"
option:dropzone:upload-limit="{{ config('app.upload_limit') }}"
option:dropzone:upload-limit-message="{{ trans('errors.server_upload_limit') }}"
- option:dropzone:timeout-message="{{ trans('errors.file_upload_timeout') }}"
option:dropzone:zone-text="{{ trans('components.image_dropzone_drop') }}"
+ option:dropzone:file-accept="image/*"
option:image-manager:uploaded-to="{{ $uploaded_to ?? 0 }}"
class="image-manager">
</div>
<div refs="image-manager@form-container-placeholder" class="p-m text-small text-muted">
- <p>Here you can manage or select images that have been previously uploaded to the system.</p>
- <p>Upload a new image by dragging an image file into this window,
- or by using the "Upload Image" button above.</p>
+ <p>{{ trans('components.image_intro') }}</p>
+ <p>{{ trans('components.image_intro_upload') }}</p>
</div>
<div refs="image-manager@formContainer" class="inner flex">