import {onChildEvent, onSelect, removeLoading, showLoading} from "../services/dom";
+import {Component} from "./component";
-/**
- * ImageManager
- * @extends {Component}
- */
-class ImageManager {
+export class ImageManager extends Component {
setup() {
-
// Options
this.uploadedTo = this.$opts.uploadedTo;
this.resetState();
this.setupListeners();
-
- window.ImageManager = this;
}
setupListeners() {
this.listContainer.addEventListener('event-emit-select-image', this.onImageSelectEvent.bind(this));
+ this.listContainer.addEventListener('error', event => {
+ event.target.src = baseUrl('loading_error.png');
+ }, true);
+
onSelect(this.selectButton, () => {
if (this.callback) {
this.callback(this.lastSelected);
this.callback = callback;
this.type = type;
- this.popupEl.components.popup.show();
+ this.getPopup().show();
this.dropzoneContainer.classList.toggle('hidden', type !== 'gallery');
if (!this.hasData) {
}
hide() {
- this.popupEl.components.popup.hide();
+ this.getPopup().hide();
+ }
+
+ /**
+ * @returns {Popup}
+ */
+ getPopup() {
+ return window.$components.firstOnElement(this.popupEl, 'popup');
}
async loadGallery() {
};
const {data: html} = await window.$http.get(`images/${this.type}`, params);
+ if (params.page === 1) {
+ this.listContainer.innerHTML = '';
+ }
this.addReturnedHtmlElementsToList(html);
removeLoading(this.listContainer);
}
addReturnedHtmlElementsToList(html) {
const el = document.createElement('div');
el.innerHTML = html;
- window.components.init(el);
+ window.$components.init(el);
for (const child of [...el.children]) {
this.listContainer.appendChild(child);
}
const params = requestDelete ? {delete: true} : {};
const {data: formHtml} = await window.$http.get(`/images/edit/${imageId}`, params);
this.formContainer.innerHTML = formHtml;
- window.components.init(this.formContainer);
+ window.$components.init(this.formContainer);
}
-}
-
-export default ImageManager;
\ No newline at end of file
+}
\ No newline at end of file