2021-01-17 09:19:58 +01:00
|
|
|
(function(){var t,e,i,r,n,a,s,o;(t=class extends this.OS.application.BaseApplication{constructor(t){super("Booklet",t)}main(){return this.tree=this.find("toc-ui"),this.currentToc=void 0,this.dirty=!1,this.emux=!1,this.on("treeselect",t=>{var e;return e=t.data.item.data,this.currentToc===e||void 0===e||0===e.treepath?this.reloadEditor():(e.treepath=e.path,this.load(e).then(()=>this.open(e)).catch(t=>(e.loaded=!0,this.open(e),this.error(__("Error when loading '{0}': {1}",e.text,t.toString()),t))))}),this.tree.ondragndrop=t=>this.dndhandle(t),this.initEditor(),this.resizeContent(),this.tree.contextmenuHandle=(t,e)=>{var i;if(i=this.contextMenu())return e.items=i,e.onmenuselect=t=>this[t.data.item.data.dataid](),e.show(t)},this.editor.codemirror.on("change",()=>{if(!this.emux&&this.currentToc)return this.currentToc.descFile.dirty=!0,this.dirty=!0})}newChapter(){var t;return this.currentToc&&"Book"===this.currentToc.type?(t=new i(this.book),this.displayToc(),t.treepath=t.path):this.error(__("No book selected"))}newSection(){var t;return this.currentToc&&"Chapter"===this.currentToc.type?(t=new s(this.currentToc),this.displayToc(),t.treepath=t.path):this.error(__("No chapter selected"))}newFile(){var t;return this.currentToc&&"Section"===this.currentToc.type?(t=new n(this.currentToc),this.displayToc(),t.treepath=t.path):this.error(__("No section selected"))}delete(){var t;return this.currentToc?(t=()=>(this.currentToc=void 0,this.displayToc(),this.reloadEditor()),this.currentToc.remove().then(()=>(this.notify(__("Entrie deleted")),t())).catch(e=>(this.error(e.toString(),e),t()))):this.error(__("No entrie select"))}goUp(){if(this.currentToc&&"Book"!==this.currentToc.type)return this.currentToc.parent.up(this.currentToc),this.displayToc()}goDown(){if(this.currentToc&&"Book"!==this.currentToc.type)return this.currentToc.parent.down(this.currentToc),this.displayToc()}load(t){return new Promise((e,i)=>t.loaded?e():t.descFile.meta().then(r=>t.descFile.read().then(i=>(t.descFile.cache=i,t.loaded=!0,t.descFile.dirty=!1,e())).catch((function(t){return i(__e(t))}))).catch((function(t){return i(__e(t))})))}dndhandle(t){var e,i;if(t&&t.data&&(e=t.data.from.data,i=t.data.to.data,e&&i&&"Book"!==e.type&&"Chapter"!==e.type&&e.parent!==i.parent&&e.parent!==i))return i.type===e.type&&(i=i.parent),i.type===e.parent.type?e.parent.removeChild(e).then(()=>(i.add(e),this.displayToc())):void 0}upload(){if(this.currentToc&&"File"!==this.currentToc.type)return this.currentToc.path.asFileHandle().upload().then(()=>this.notify(__("File uploaded"))).catch(t=>this.error(__("Unable to upload file {0}",t.toString()),t))}contextMenu(){if(this.currentToc)switch(this.currentToc.type){case"Book":return[{text:__("New chapter"),dataid:"newChapter"},{text:__("Delete book"),dataid:"delete"},{text:__("Upload media"),dataid:"upload"}];case"Chapter":return[{text:__("New section"),dataid:"newSection"},{text:__("Delete chapter"),dataid:"delete"},{text:__("Go up"),dataid:"goUp"},{text:__("Go down"),dataid:"goDown"},{text:__("Upload media"),dataid:"upload"}];case"Section":return[{text:__("New file"),dataid:"newFile"},{text:__("Delete section"),dataid:"delete"},{text:__("Go up"),dataid:"goUp"},{text:__("Go down"),dataid:"goDown"},{text:__("Upload media"),dataid:"upload"}];case"File":return[{text:__("Delete file"),dataid:"delete"},{text:__("Go up"),dataid:"goUp"},{text:__("Go down"),dataid:"goDown"}]}}shareFile(t,e){return this.openDialog("FileDialog",{title:__("Select a file"),mimes:t}).then(t=>t.file.path.asFileHandle().publish().then((function(t){return e(t.result)})).catch(t=>this.error(__("Cannot export file for embedding to text"),t))).catch(t=>this.error(t.toString(),t))}initEditor(){var t;return t=this.find("markarea"),this.container=this.find("mycontainer"),this.previewOn=!1,this.editormux=!1,this.editor=new SimpleMDE({element:t,autoDownloadFontAwesome:!1,autofocus:!0,tabSize:4,indentWithTabs:!0,toolbar:["bold","italic","heading","|","quote","code","unordered-list","ordered-list","|","link","image","table","horizontal-rule",{name:"shared image",className:"fa fa-shar
|