2023-04-27 08:31:03 -04:00
|
|
|
import {showLoading} from '../services/dom';
|
2023-04-18 17:20:02 -04:00
|
|
|
import {Component} from './component';
|
2020-07-04 11:53:02 -04:00
|
|
|
|
2022-11-14 18:19:02 -05:00
|
|
|
export class Attachments extends Component {
|
2020-06-30 17:12:45 -04:00
|
|
|
|
|
|
|
setup() {
|
|
|
|
this.container = this.$el;
|
|
|
|
this.pageId = this.$opts.pageId;
|
|
|
|
this.editContainer = this.$refs.editContainer;
|
2020-07-04 11:53:02 -04:00
|
|
|
this.listContainer = this.$refs.listContainer;
|
2023-04-26 11:41:34 -04:00
|
|
|
this.linksContainer = this.$refs.linksContainer;
|
|
|
|
this.listPanel = this.$refs.listPanel;
|
|
|
|
this.attachLinkButton = this.$refs.attachLinkButton;
|
2020-06-30 17:12:45 -04:00
|
|
|
|
|
|
|
this.setupListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
setupListeners() {
|
2020-07-04 11:53:02 -04:00
|
|
|
const reloadListBound = this.reloadList.bind(this);
|
2023-04-26 11:41:34 -04:00
|
|
|
this.container.addEventListener('dropzone-upload-success', reloadListBound);
|
2020-07-04 11:53:02 -04:00
|
|
|
this.container.addEventListener('ajax-form-success', reloadListBound);
|
2020-06-30 17:12:45 -04:00
|
|
|
|
|
|
|
this.container.addEventListener('sortable-list-sort', event => {
|
|
|
|
this.updateOrder(event.detail.ids);
|
|
|
|
});
|
|
|
|
|
2020-07-04 11:53:02 -04:00
|
|
|
this.container.addEventListener('event-emit-select-edit', event => {
|
|
|
|
this.startEdit(event.detail.id);
|
|
|
|
});
|
|
|
|
|
2023-04-19 10:20:04 -04:00
|
|
|
this.container.addEventListener('event-emit-select-edit-back', () => {
|
2020-07-04 11:53:02 -04:00
|
|
|
this.stopEdit();
|
|
|
|
});
|
2020-09-13 13:58:05 -04:00
|
|
|
|
|
|
|
this.container.addEventListener('event-emit-select-insert', event => {
|
|
|
|
const insertContent = event.target.closest('[data-drag-content]').getAttribute('data-drag-content');
|
|
|
|
const contentTypes = JSON.parse(insertContent);
|
|
|
|
window.$events.emit('editor::insert', {
|
|
|
|
html: contentTypes['text/html'],
|
|
|
|
markdown: contentTypes['text/plain'],
|
|
|
|
});
|
|
|
|
});
|
2023-04-26 11:41:34 -04:00
|
|
|
|
|
|
|
this.attachLinkButton.addEventListener('click', () => {
|
|
|
|
this.showSection('links');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
showSection(section) {
|
|
|
|
const sectionMap = {
|
|
|
|
links: this.linksContainer,
|
|
|
|
edit: this.editContainer,
|
|
|
|
list: this.listContainer,
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const [name, elem] of Object.entries(sectionMap)) {
|
|
|
|
elem.toggleAttribute('hidden', name !== section);
|
|
|
|
}
|
2020-07-04 11:53:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
reloadList() {
|
|
|
|
this.stopEdit();
|
|
|
|
window.$http.get(`/attachments/get/page/${this.pageId}`).then(resp => {
|
2023-04-26 11:41:34 -04:00
|
|
|
this.listPanel.innerHTML = resp.data;
|
|
|
|
window.$components.init(this.listPanel);
|
2020-07-04 11:53:02 -04:00
|
|
|
});
|
2020-06-30 17:12:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
updateOrder(idOrder) {
|
|
|
|
window.$http.put(`/attachments/sort/page/${this.pageId}`, {order: idOrder}).then(resp => {
|
|
|
|
window.$events.emit('success', resp.data.message);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-04 11:53:02 -04:00
|
|
|
async startEdit(id) {
|
2023-04-26 11:41:34 -04:00
|
|
|
this.showSection('edit');
|
2020-07-04 11:53:02 -04:00
|
|
|
|
|
|
|
showLoading(this.editContainer);
|
|
|
|
const resp = await window.$http.get(`/attachments/edit/${id}`);
|
|
|
|
this.editContainer.innerHTML = resp.data;
|
2022-11-14 18:19:02 -05:00
|
|
|
window.$components.init(this.editContainer);
|
2020-07-04 11:53:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
stopEdit() {
|
2023-04-26 11:41:34 -04:00
|
|
|
this.showSection('list');
|
2020-07-04 11:53:02 -04:00
|
|
|
}
|
|
|
|
|
2023-04-18 17:20:02 -04:00
|
|
|
}
|