X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/2f6ff0734773c4ac009de699a2661971fd585b22..ac519b3009e353448fc0541d21c08422d77dc57d:/resources/js/components/book-sort.js diff --git a/resources/js/components/book-sort.js b/resources/js/components/book-sort.js index b0d64ad17..3ffadf991 100644 --- a/resources/js/components/book-sort.js +++ b/resources/js/components/book-sort.js @@ -1,4 +1,6 @@ -import {Sortable, MultiDrag} from "sortablejs"; +import Sortable from "sortablejs"; +import {Component} from "./component"; +import {htmlToDom} from "../services/dom"; // Auto sort control const sortOperations = { @@ -35,15 +37,14 @@ const sortOperations = { }, }; -class BookSort { +export class BookSort extends Component { - constructor(elem) { - this.elem = elem; - this.sortContainer = elem.querySelector('[book-sort-boxes]'); - this.input = elem.querySelector('[book-sort-input]'); + setup() { + this.container = this.$el; + this.sortContainer = this.$refs.sortContainer; + this.input = this.$refs.input; - const initialSortBox = elem.querySelector('.sort-box'); - Sortable.mount(new MultiDrag()); + const initialSortBox = this.container.querySelector('.sort-box'); this.setupBookSortable(initialSortBox); this.setupSortPresets(); @@ -91,14 +92,12 @@ class BookSort { * @param {Object} entityInfo */ bookSelect(entityInfo) { - const alreadyAdded = this.elem.querySelector(`[data-type="book"][data-id="${entityInfo.id}"]`) !== null; + const alreadyAdded = this.container.querySelector(`[data-type="book"][data-id="${entityInfo.id}"]`) !== null; if (alreadyAdded) return; const entitySortItemUrl = entityInfo.link + '/sort-item'; window.$http.get(entitySortItemUrl).then(resp => { - const wrap = document.createElement('div'); - wrap.innerHTML = resp.data; - const newBookContainer = wrap.children[0]; + const newBookContainer = htmlToDom(resp.data); this.sortContainer.append(newBookContainer); this.setupBookSortable(newBookContainer); }); @@ -156,7 +155,7 @@ class BookSort { */ buildEntityMap() { const entityMap = []; - const lists = this.elem.querySelectorAll('.sort-list'); + const lists = this.container.querySelectorAll('.sort-list'); for (let list of lists) { const bookId = list.closest('[data-type="book"]').getAttribute('data-id'); @@ -203,6 +202,4 @@ class BookSort { } } -} - -export default BookSort; \ No newline at end of file +} \ No newline at end of file