]> BookStack Code Mirror - bookstack/blob - resources/js/components/attachments.js
Started migration of attachment manager from vue
[bookstack] / resources / js / components / attachments.js
1
2 /**
3  * Attachments
4  * @extends {Component}
5  */
6 class Attachments {
7
8     setup() {
9         this.container = this.$el;
10         this.pageId = this.$opts.pageId;
11         this.editContainer = this.$refs.editContainer;
12         this.mainTabs = this.$refs.mainTabs;
13         this.list = this.$refs.list;
14
15         this.setupListeners();
16     }
17
18     setupListeners() {
19         this.container.addEventListener('dropzone-success', event => {
20             this.mainTabs.components.tabs.show('items');
21             window.$http.get(`/attachments/get/page/${this.pageId}`).then(resp => {
22                 this.list.innerHTML = resp.data;
23                 window.components.init(this.list);
24             })
25         });
26
27         this.container.addEventListener('sortable-list-sort', event => {
28             this.updateOrder(event.detail.ids);
29         });
30
31         this.editContainer.addEventListener('keypress', event => {
32             if (event.key === 'Enter') {
33                 // TODO - Update editing file
34             }
35         })
36     }
37
38     updateOrder(idOrder) {
39         window.$http.put(`/attachments/sort/page/${this.pageId}`, {order: idOrder}).then(resp => {
40             window.$events.emit('success', resp.data.message);
41         });
42     }
43
44 }
45
46 export default Attachments;