2 lines
44 KiB
JavaScript
2 lines
44 KiB
JavaScript
"use strict";function _classCallCheck(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")}function setInputSelection(e,o,t){if(e.focus(),void 0!==e.selectionStart)e.selectionStart=o,e.selectionEnd=t;else if(document.selection&&document.selection.createRange){e.select();var n=document.selection.createRange();n.collapse(!0),n.moveEnd("character",t),n.moveStart("character",o),n.select()}}function makeSafePath(e){var o=_.split(_.trim(e),"/");return o=_.map(o,function(e){return _.kebabCase(_.deburr(_.trim(e)))}),_.join(_.filter(o,function(e){return!_.isEmpty(e)}),"/")}var _createClass=function(){function e(e,o){for(var t=0;t<o.length;t++){var n=o[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(o,t,n){return t&&e(o.prototype,t),n&&e(o,n),o}}();jQuery(document).ready(function(e){var o=this;e("a").smoothScroll({speed:400,offset:-70});new Sticky(".stickyscroll");e(window).bind("beforeunload",function(){e("#notifload").addClass("active")}),e(document).ajaxSend(function(){e("#notifload").addClass("active")}).ajaxComplete(function(){e("#notifload").removeClass("active")});var t=new Alerts;alertsData&&_.forEach(alertsData,function(e){t.push(e)});var n=io(window.location.origin);if(e("#search-input").length){e("#search-input").focus(),e(".searchresults").css("display","block");var i=new Vue({el:"#header-container",data:{searchq:"",searchres:[],searchsuggest:[],searchload:0,searchactive:!1,searchmoveidx:0,searchmovekey:"",searchmovearr:[]},watch:{searchq:function(e,o){i.searchmoveidx=0,e.length>=3?(i.searchactive=!0,i.searchload++,n.emit("search",{terms:e},function(e){i.searchres=e.match,i.searchsuggest=e.suggest,i.searchmovearr=_.concat([],i.searchres,i.searchsuggest),i.searchload>0&&i.searchload--})):(i.searchactive=!1,i.searchres=[],i.searchsuggest=[],i.searchmovearr=[],i.searchload=0)},searchmoveidx:function(e,o){i.searchmovekey=e>0?i.searchmovearr[e-1]?"res."+i.searchmovearr[e-1].entryPath:"sug."+i.searchmovearr[e-1]:""}},methods:{useSuggestion:function(e){i.searchq=e},closeSearch:function(){i.searchq=""},moveSelectSearch:function(){if(!(i.searchmoveidx<1)){var e=i.searchmoveidx-1;i.searchmovearr[e]?window.location.assign("/"+i.searchmovearr[e].entryPath):i.searchq=i.searchmovearr[e]}},moveDownSearch:function(){i.searchmoveidx<i.searchmovearr.length&&i.searchmoveidx++},moveUpSearch:function(){i.searchmoveidx>0&&i.searchmoveidx--}}});e("main").on("click",i.closeSearch)}if(e("#page-type-view").length){var a="home"!==e("#page-type-view").data("entrypath")?e("#page-type-view").data("entrypath"):"",r=a+"/new-page";e(".btn-create-prompt").on("click",function(o){e("#txt-create-prompt").val(r),e("#modal-create-prompt").toggleClass("is-active"),setInputSelection(e("#txt-create-prompt").get(0),a.length+1,r.length),e("#txt-create-prompt").removeClass("is-danger").next().addClass("is-hidden")}),e("#txt-create-prompt").on("keypress",function(o){13===o.which&&e(".btn-create-go").trigger("click")}),e(".btn-create-go").on("click",function(o){var t=makeSafePath(e("#txt-create-prompt").val());_.isEmpty(t)?e("#txt-create-prompt").addClass("is-danger").next().removeClass("is-hidden"):(e("#txt-create-prompt").parent().addClass("is-loading"),window.location.assign("/create/"+t))}),""!==a&&e(".btn-move-prompt").removeClass("is-hidden");var l=_.lastIndexOf(a,"/")+1;e(".btn-move-prompt").on("click",function(o){e("#txt-move-prompt").val(a),e("#modal-move-prompt").toggleClass("is-active"),setInputSelection(e("#txt-move-prompt").get(0),l,a.length),e("#txt-move-prompt").removeClass("is-danger").next().addClass("is-hidden")}),e("#txt-move-prompt").on("keypress",function(o){13===o.which&&e(".btn-move-go").trigger("click")}),e(".btn-move-go").on("click",function(o){var n=makeSafePath(e("#txt-move-prompt").val());_.isEmpty(n)||n===a||"home"===n?e("#txt-move-prompt").addClass("is-danger").next().removeClass("is-hidden"):(e("#txt-move-prompt").parent().addClass("is-loading"),e.ajax(window.location.href,{data:{move:n},dataType:"json",method:"PUT"}).then(function(e,o,i){e.ok?window.location.assign("/"+n):t.pushError("Something went wrong",e.error)},function(e,o,n){t.pushError("Something went wrong","Save operation failed.")}))})}if(e("#page-type-create").length){var d=e("#page-type-create").data("entrypath");if(e(".btn-create-discard").on("click",function(o){e("#modal-create-discard").toggleClass("is-active")}),1===e("#mk-editor").length){var s=!1;Vue.filter("filesize",function(e){return _.toUpper(filesize(e))});var c=new Vue({el:"#modal-editor-image",data:{isLoading:!1,isLoadingText:"",newFolderName:"",newFolderShow:!1,newFolderError:!1,fetchFromUrlURL:"",fetchFromUrlShow:!1,folders:[],currentFolder:"",currentImage:"",currentAlign:"left",images:[],uploadSucceeded:!1,postUploadChecks:0,renameImageShow:!1,renameImageId:"",renameImageFilename:"",deleteImageShow:!1,deleteImageId:"",deleteImageFilename:""},methods:{open:function(){s=!0,e("#modal-editor-image").addClass("is-active"),c.refreshFolders()},cancel:function(o){s=!1,e("#modal-editor-image").removeClass("is-active")},selectImage:function(e){c.currentImage=e},insertImage:function(e){F.codemirror.doc.somethingSelected()&&F.codemirror.execCommand("singleSelection");var o=_.find(c.images,["_id",c.currentImage]);o.normalizedPath="f:"===o.folder?o.filename:o.folder.slice(2)+"/"+o.filename,o.titleGuess=_.startCase(o.basename);var t="!["+o.titleGuess+"](/uploads/"+o.normalizedPath+' "'+o.titleGuess+'")';switch(c.currentAlign){case"center":t+="{.align-center}";break;case"right":t+="{.align-right}";break;case"logo":t+="{.pagelogo}"}F.codemirror.doc.replaceSelection(t),c.cancel()},newFolder:function(o){c.newFolderName="",c.newFolderError=!1,c.newFolderShow=!0,_.delay(function(){e("#txt-editor-image-newfoldername").focus()},400)},newFolderDiscard:function(e){c.newFolderShow=!1},newFolderCreate:function(e){var o=new RegExp("^[a-z0-9][a-z0-9-]*[a-z0-9]$");if(c.newFolderName=_.kebabCase(_.trim(c.newFolderName)),_.isEmpty(c.newFolderName)||!o.test(c.newFolderName))return void(c.newFolderError=!0);c.newFolderDiscard(),c.isLoadingText="Creating new folder...",c.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsCreateFolder",{foldername:c.newFolderName},function(e){c.folders=e,c.currentFolder=c.newFolderName,c.images=[],c.isLoading=!1})})},fetchFromUrl:function(o){c.fetchFromUrlURL="",c.fetchFromUrlShow=!0,_.delay(function(){e("#txt-editor-image-fetchurl").focus()},400)},fetchFromUrlDiscard:function(e){c.fetchFromUrlShow=!1},fetchFromUrlGo:function(e){c.fetchFromUrlDiscard(),c.isLoadingText="Fetching image...",c.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsFetchFileFromURL",{folder:c.currentFolder,fetchUrl:c.fetchFromUrlURL},function(e){e.ok?c.waitChangeComplete(c.images.length,!0):(c.isLoading=!1,t.pushError("Upload error",e.msg))})})},renameImage:function(){var o=_.find(c.images,["_id",c.renameImageId]);c.renameImageFilename=o.basename||"",c.renameImageShow=!0,_.delay(function(){e("#txt-editor-image-rename").focus(),_.defer(function(){e("#txt-editor-image-rename").select()})},400)},renameImageDiscard:function(){c.renameImageShow=!1},renameImageGo:function(){c.renameImageDiscard(),c.isLoadingText="Renaming image...",c.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsRenameFile",{uid:c.renameImageId,folder:c.currentFolder,filename:c.renameImageFilename},function(e){e.ok?c.waitChangeComplete(c.images.length,!1):(c.isLoading=!1,t.pushError("Rename error",e.msg))})})},moveImage:function(e,o){c.isLoadingText="Moving image...",c.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsMoveFile",{uid:e,folder:o},function(e){e.ok?c.loadImages():(c.isLoading=!1,t.pushError("Rename error",e.msg))})})},deleteImageWarn:function(e){if(e){var o=_.find(c.images,["_id",c.deleteImageId]);c.deleteImageFilename=o.filename||"this image"}c.deleteImageShow=e},deleteImageGo:function(){c.deleteImageWarn(!1),c.isLoadingText="Deleting image...",c.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsDeleteFile",{uid:c.deleteImageId},function(e){c.loadImages()})})},selectFolder:function(e){c.currentFolder=e,c.loadImages()},refreshFolders:function(){c.isLoadingText="Fetching folders list...",c.isLoading=!0,c.currentFolder="",c.currentImage="",Vue.nextTick(function(){n.emit("uploadsGetFolders",{},function(e){c.folders=e,c.loadImages()})})},loadImages:function(e){return e||(c.isLoadingText="Fetching images...",c.isLoading=!0),new Promise(function(o,t){Vue.nextTick(function(){n.emit("uploadsGetImages",{folder:c.currentFolder},function(t){c.images=t,e||(c.isLoading=!1),c.attachContextMenus(),o(!0)})})})},waitChangeComplete:function(e,o){o=!_.isBoolean(o)||o,c.postUploadChecks++,c.isLoadingText="Processing...",Vue.nextTick(function(){c.loadImages(!0).then(function(){c.images.length!==e===o?(c.postUploadChecks=0,c.isLoading=!1):c.postUploadChecks>5?(c.postUploadChecks=0,c.isLoading=!1,t.pushError("Unable to fetch updated listing","Try again later")):_.delay(function(){c.waitChangeComplete(e,o)},1500)})})},attachContextMenus:function(){var o=_.map(c.folders,function(o){return{name:""!==o?o:"/ (root)",icon:"fa-folder",callback:function(o,t){var n=_.toString(e(t.$trigger).data("uid")),i=_.nth(c.folders,o);c.moveImage(n,i)}}});e.contextMenu("destroy",".editor-modal-image-choices > figure"),e.contextMenu({selector:".editor-modal-image-choices > figure",appendTo:".editor-modal-image-choices",position:function(o,t,n){e(o.$trigger).addClass("is-contextopen");var i=e(o.$trigger).position(),a={w:e(o.$trigger).width()/2,h:e(o.$trigger).height()/2};o.$menu.css({top:i.top+a.h,left:i.left+a.w})},events:{hide:function(o){e(o.$trigger).removeClass("is-contextopen")}},items:{rename:{name:"Rename",icon:"fa-edit",callback:function(e,o){c.renameImageId=_.toString(o.$trigger[0].dataset.uid),c.renameImage()}},move:{name:"Move to...",icon:"fa-folder-open-o",items:o},delete:{name:"Delete",icon:"fa-trash",callback:function(e,o){c.deleteImageId=_.toString(o.$trigger[0].dataset.uid),c.deleteImageWarn(!0)}}}})}}});e("#btn-editor-image-upload input").on("change",function(n){var i=c.images.length;e(n.currentTarget).simpleUpload("/uploads/img",{name:"imgfile",data:{folder:c.currentFolder},limit:20,expect:"json",allowedExts:["jpg","jpeg","gif","png","webp"],allowedTypes:["image/png","image/jpeg","image/gif","image/webp"],maxFileSize:3145728,init:function(e){c.uploadSucceeded=!1,c.isLoadingText="Preparing to upload...",c.isLoading=!0},progress:function(e){c.isLoadingText="Uploading..."+Math.round(e)+"%"},success:function(e){if(e.ok){var o=_.filter(e.results,["ok",!1]);o.length?(_.forEach(o,function(e){t.pushError("Upload error",e.msg)}),o.length<e.results.length&&(t.push({title:"Some uploads succeeded",message:"Files that are not mentionned in the errors above were uploaded successfully."}),c.uploadSucceeded=!0)):c.uploadSucceeded=!0}else t.pushError("Upload error",e.msg)},error:function(e){t.pushError(e.message,o.upload.file.name)},finish:function(){c.uploadSucceeded?c.waitChangeComplete(i,!0):c.isLoading=!1}})});var m=new Vue({el:"#modal-editor-file",data:{isLoading:!1,isLoadingText:"",newFolderName:"",newFolderShow:!1,newFolderError:!1,folders:[],currentFolder:"",currentFile:"",files:[],uploadSucceeded:!1,postUploadChecks:0,renameFileShow:!1,renameFileId:"",renameFileFilename:"",deleteFileShow:!1,deleteFileId:"",deleteFileFilename:""},methods:{open:function(){s=!0,e("#modal-editor-file").addClass("is-active"),m.refreshFolders()},cancel:function(o){s=!1,e("#modal-editor-file").removeClass("is-active")},selectFile:function(e){m.currentFile=e},insertFileLink:function(e){F.codemirror.doc.somethingSelected()&&F.codemirror.execCommand("singleSelection");var o=_.find(m.files,["_id",m.currentFile]);o.normalizedPath="f:"===o.folder?o.filename:o.folder.slice(2)+"/"+o.filename,o.titleGuess=_.startCase(o.basename);var t="["+o.titleGuess+"](/uploads/"+o.normalizedPath+' "'+o.titleGuess+'")';F.codemirror.doc.replaceSelection(t),m.cancel()},newFolder:function(o){m.newFolderName="",m.newFolderError=!1,m.newFolderShow=!0,_.delay(function(){e("#txt-editor-file-newfoldername").focus()},400)},newFolderDiscard:function(e){m.newFolderShow=!1},newFolderCreate:function(e){var o=new RegExp("^[a-z0-9][a-z0-9-]*[a-z0-9]$");if(m.newFolderName=_.kebabCase(_.trim(m.newFolderName)),_.isEmpty(m.newFolderName)||!o.test(m.newFolderName))return void(m.newFolderError=!0);m.newFolderDiscard(),m.isLoadingText="Creating new folder...",m.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsCreateFolder",{foldername:m.newFolderName},function(e){m.folders=e,m.currentFolder=m.newFolderName,m.files=[],m.isLoading=!1})})},renameFile:function(){var o=_.find(m.files,["_id",m.renameFileId]);m.renameFileFilename=o.basename||"",m.renameFileShow=!0,_.delay(function(){e("#txt-editor-renamefile").focus(),_.defer(function(){e("#txt-editor-file-rename").select()})},400)},renameFileDiscard:function(){m.renameFileShow=!1},renameFileGo:function(){m.renameFileDiscard(),m.isLoadingText="Renaming file...",m.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsRenameFile",{uid:m.renameFileId,folder:m.currentFolder,filename:m.renameFileFilename},function(e){e.ok?m.waitChangeComplete(m.files.length,!1):(m.isLoading=!1,t.pushError("Rename error",e.msg))})})},moveFile:function(e,o){m.isLoadingText="Moving file...",m.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsMoveFile",{uid:e,folder:o},function(e){e.ok?m.loadFiles():(m.isLoading=!1,t.pushError("Rename error",e.msg))})})},deleteFileWarn:function(e){if(e){var o=_.find(m.files,["_id",m.deleteFileId]);m.deleteFileFilename=o.filename||"this file"}m.deleteFileShow=e},deleteFileGo:function(){m.deleteFileWarn(!1),m.isLoadingText="Deleting file...",m.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsDeleteFile",{uid:m.deleteFileId},function(e){m.loadFiles()})})},selectFolder:function(e){m.currentFolder=e,m.loadFiles()},refreshFolders:function(){m.isLoadingText="Fetching folders list...",m.isLoading=!0,m.currentFolder="",m.currentImage="",Vue.nextTick(function(){n.emit("uploadsGetFolders",{},function(e){m.folders=e,m.loadFiles()})})},loadFiles:function(e){return e||(m.isLoadingText="Fetching files...",m.isLoading=!0),new Promise(function(o,t){Vue.nextTick(function(){n.emit("uploadsGetFiles",{folder:m.currentFolder},function(t){m.files=t,e||(m.isLoading=!1),m.attachContextMenus(),o(!0)})})})},waitChangeComplete:function(e,o){o=!_.isBoolean(o)||o,m.postUploadChecks++,m.isLoadingText="Processing...",Vue.nextTick(function(){m.loadFiles(!0).then(function(){m.files.length!==e===o?(m.postUploadChecks=0,m.isLoading=!1):m.postUploadChecks>5?(m.postUploadChecks=0,m.isLoading=!1,t.pushError("Unable to fetch updated listing","Try again later")):_.delay(function(){m.waitChangeComplete(e,o)},1500)})})},attachContextMenus:function(){var o=_.map(m.folders,function(o){return{name:""!==o?o:"/ (root)",icon:"fa-folder",callback:function(o,t){var n=_.toString(e(t.$trigger).data("uid")),i=_.nth(m.folders,o);m.moveFile(n,i)}}});e.contextMenu("destroy",".editor-modal-file-choices > figure"),e.contextMenu({selector:".editor-modal-file-choices > figure",appendTo:".editor-modal-file-choices",position:function(o,t,n){e(o.$trigger).addClass("is-contextopen");var i=e(o.$trigger).position(),a={w:e(o.$trigger).width()/5,h:e(o.$trigger).height()/2};o.$menu.css({top:i.top+a.h,left:i.left+a.w})},events:{hide:function(o){e(o.$trigger).removeClass("is-contextopen")}},items:{rename:{name:"Rename",icon:"fa-edit",callback:function(e,o){m.renameFileId=_.toString(o.$trigger[0].dataset.uid),m.renameFile()}},move:{name:"Move to...",icon:"fa-folder-open-o",items:o},delete:{name:"Delete",icon:"fa-trash",callback:function(e,o){m.deleteFileId=_.toString(o.$trigger[0].dataset.uid),m.deleteFileWarn(!0)}}}})}}});e("#btn-editor-file-upload input").on("change",function(o){var n=m.files.length;e(o.currentTarget).simpleUpload("/uploads/file",{name:"binfile",data:{folder:m.currentFolder},limit:20,expect:"json",maxFileSize:0,init:function(e){m.uploadSucceeded=!1,m.isLoadingText="Preparing to upload...",m.isLoading=!0},progress:function(e){m.isLoadingText="Uploading..."+Math.round(e)+"%"},success:function(e){if(e.ok){var o=_.filter(e.results,["ok",!1]);o.length?(_.forEach(o,function(e){t.pushError("Upload error",e.msg)}),o.length<e.results.length&&(t.push({title:"Some uploads succeeded",message:"Files that are not mentionned in the errors above were uploaded successfully."}),m.uploadSucceeded=!0)):m.uploadSucceeded=!0}else t.pushError("Upload error",e.msg)},error:function(e){t.pushError("Upload error",e.message)},finish:function(){m.uploadSucceeded?m.waitChangeComplete(n,!0):m.isLoading=!1}})});var u={youtube:new RegExp(/(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|&v(?:i)?=))([^#&?]*).*/,"i"),vimeo:new RegExp(/vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^\/]*)\/videos\/|album\/(?:\d+)\/video\/|)(\d+)(?:$|\/|\?)/,"i"),dailymotion:new RegExp(/(?:dailymotion\.com(?:\/embed)?(?:\/video|\/hub)|dai\.ly)\/([0-9a-z]+)(?:[-_0-9a-zA-Z]+(?:#video=)?([a-z0-9]+)?)?/,"i")},g=new Vue({el:"#modal-editor-video",data:{link:""},methods:{open:function(o){e("#modal-editor-video").addClass("is-active"),e("#modal-editor-video input").focus()},cancel:function(o){s=!1,e("#modal-editor-video").removeClass("is-active"),g.link=""},insertVideo:function(e){F.codemirror.doc.somethingSelected()&&F.codemirror.execCommand("singleSelection");var o=_.findKey(u,function(e){return e.test(g.link)});_.isNil(o)&&(o="video");var t="[video]("+g.link+"){."+o+"}\n";F.codemirror.doc.replaceSelection(t),g.cancel()}}}),f=ace.require("ace/ext/modelist"),p=null,h=[],w=function(o){return e.ajax({url:"/js/ace/mode-"+o+".js",dataType:"script",cache:!0,beforeSend:function(){if(_.includes(h,o))return!1},success:function(){h.push(o)}})},v=new Vue({el:"#modal-editor-codeblock",data:{modes:f.modesByName,modeSelected:"text",initContent:""},watch:{modeSelected:function(e,o){w(e).done(function(){ace.require("ace/mode/"+e),p.getSession().setMode("ace/mode/"+e)})}},methods:{open:function(o){e("#modal-editor-codeblock").addClass("is-active"),_.delay(function(){p=ace.edit("codeblock-editor"),p.setTheme("ace/theme/tomorrow_night"),p.getSession().setMode("ace/mode/"+v.modeSelected),p.setOption("fontSize","14px"),p.setOption("hScrollBarAlwaysVisible",!1),p.setOption("wrap",!0),p.setValue(v.initContent),p.focus(),p.renderer.updateFull()},300)},cancel:function(o){s=!1,e("#modal-editor-codeblock").removeClass("is-active"),v.initContent=""},insertCode:function(e){F.codemirror.doc.somethingSelected()&&F.codemirror.execCommand("singleSelection");var o="\n```"+v.modeSelected+"\n"+p.getValue()+"\n```\n";F.codemirror.doc.replaceSelection(o),v.cancel()}}}),F=new SimpleMDE({autofocus:!0,autoDownloadFontAwesome:!1,element:e("#mk-editor").get(0),placeholder:"Enter Markdown formatted content here...",spellChecker:!1,status:!1,toolbar:[{name:"bold",action:SimpleMDE.toggleBold,className:"icon-bold",title:"Bold"},{name:"italic",action:SimpleMDE.toggleItalic,className:"icon-italic",title:"Italic"},{name:"strikethrough",action:SimpleMDE.toggleStrikethrough,className:"icon-strikethrough",title:"Strikethrough"},"|",{name:"heading-1",action:SimpleMDE.toggleHeading1,className:"icon-header fa-header-x fa-header-1",title:"Big Heading"},{name:"heading-2",action:SimpleMDE.toggleHeading2,className:"icon-header fa-header-x fa-header-2",title:"Medium Heading"},{name:"heading-3",action:SimpleMDE.toggleHeading3,className:"icon-header fa-header-x fa-header-3",title:"Small Heading"},{name:"quote",action:SimpleMDE.toggleBlockquote,className:"icon-quote-left",title:"Quote"},"|",{name:"unordered-list",action:SimpleMDE.toggleUnorderedList,className:"icon-th-list",title:"Bullet List"},{name:"ordered-list",action:SimpleMDE.toggleOrderedList,className:"icon-list-ol",title:"Numbered List"},"|",{name:"link",action:function(e){},className:"icon-link2",title:"Insert Link"},{name:"image",action:function(e){s||c.open()},className:"icon-image",title:"Insert Image"},{name:"file",action:function(e){s||m.open()},className:"icon-paper",title:"Insert File"},{name:"video",action:function(e){s||g.open()},className:"icon-video-camera2",title:"Insert Video Player"},"|",{name:"inline-code",action:function(e){if(!e.codemirror.doc.somethingSelected())return t.pushError("Invalid selection","You must select at least 1 character first.");var o=e.codemirror.doc.getSelections();o=_.map(o,function(e){return"`"+e+"`"}),e.codemirror.doc.replaceSelections(o)},className:"icon-terminal",title:"Inline Code"},{name:"code-block",action:function(e){s||(s=!0,F.codemirror.doc.somethingSelected()&&(v.initContent=F.codemirror.doc.getSelection()),v.open())},className:"icon-code",title:"Code Block"},"|",{name:"table",action:function(e){},className:"icon-table",title:"Insert Table"},{name:"horizontal-rule",action:SimpleMDE.drawHorizontalRule,className:"icon-minus2",title:"Horizontal Rule"}],shortcuts:{toggleBlockquote:null,toggleFullScreen:null}}),x=function(o){e.ajax(window.location.href,{data:{markdown:F.value()},dataType:"json",method:"PUT"}).then(function(e,o,n){e.ok?window.location.assign("/"+d):t.pushError("Something went wrong",e.error)},function(e,o,n){t.pushError("Something went wrong","Save operation failed.")})};e(".btn-edit-save, .btn-create-save").on("click",function(e){x(e)}),e(window).bind("keydown",function(e){if(e.ctrlKey||e.metaKey)switch(String.fromCharCode(e.which).toLowerCase()){case"s":e.preventDefault(),x(e)}})}}if(e("#page-type-edit").length){var S=e("#page-type-edit").data("entrypath");if(e(".btn-edit-discard").on("click",function(o){e("#modal-edit-discard").toggleClass("is-active")}),1===e("#mk-editor").length){var k=!1;Vue.filter("filesize",function(e){return _.toUpper(filesize(e))});var C=new Vue({el:"#modal-editor-image",data:{isLoading:!1,isLoadingText:"",newFolderName:"",newFolderShow:!1,newFolderError:!1,fetchFromUrlURL:"",fetchFromUrlShow:!1,folders:[],currentFolder:"",currentImage:"",currentAlign:"left",images:[],uploadSucceeded:!1,postUploadChecks:0,renameImageShow:!1,renameImageId:"",renameImageFilename:"",deleteImageShow:!1,deleteImageId:"",deleteImageFilename:""},methods:{open:function(){k=!0,e("#modal-editor-image").addClass("is-active"),C.refreshFolders()},cancel:function(o){k=!1,e("#modal-editor-image").removeClass("is-active")},selectImage:function(e){C.currentImage=e},insertImage:function(e){F.codemirror.doc.somethingSelected()&&F.codemirror.execCommand("singleSelection");var o=_.find(C.images,["_id",C.currentImage]);o.normalizedPath="f:"===o.folder?o.filename:o.folder.slice(2)+"/"+o.filename,o.titleGuess=_.startCase(o.basename);var t="!["+o.titleGuess+"](/uploads/"+o.normalizedPath+' "'+o.titleGuess+'")';switch(C.currentAlign){case"center":t+="{.align-center}";break;case"right":t+="{.align-right}";break;case"logo":t+="{.pagelogo}"}F.codemirror.doc.replaceSelection(t),C.cancel()},newFolder:function(o){C.newFolderName="",C.newFolderError=!1,C.newFolderShow=!0,_.delay(function(){e("#txt-editor-image-newfoldername").focus()},400)},newFolderDiscard:function(e){C.newFolderShow=!1},newFolderCreate:function(e){var o=new RegExp("^[a-z0-9][a-z0-9-]*[a-z0-9]$");if(C.newFolderName=_.kebabCase(_.trim(C.newFolderName)),_.isEmpty(C.newFolderName)||!o.test(C.newFolderName))return void(C.newFolderError=!0);C.newFolderDiscard(),C.isLoadingText="Creating new folder...",C.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsCreateFolder",{foldername:C.newFolderName},function(e){C.folders=e,C.currentFolder=C.newFolderName,C.images=[],C.isLoading=!1})})},fetchFromUrl:function(o){C.fetchFromUrlURL="",C.fetchFromUrlShow=!0,_.delay(function(){e("#txt-editor-image-fetchurl").focus()},400)},fetchFromUrlDiscard:function(e){C.fetchFromUrlShow=!1},fetchFromUrlGo:function(e){C.fetchFromUrlDiscard(),C.isLoadingText="Fetching image...",C.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsFetchFileFromURL",{folder:C.currentFolder,fetchUrl:C.fetchFromUrlURL},function(e){e.ok?C.waitChangeComplete(C.images.length,!0):(C.isLoading=!1,t.pushError("Upload error",e.msg))})})},renameImage:function(){var o=_.find(C.images,["_id",C.renameImageId]);C.renameImageFilename=o.basename||"",C.renameImageShow=!0,_.delay(function(){e("#txt-editor-image-rename").focus(),_.defer(function(){e("#txt-editor-image-rename").select()})},400)},renameImageDiscard:function(){C.renameImageShow=!1},renameImageGo:function(){C.renameImageDiscard(),C.isLoadingText="Renaming image...",C.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsRenameFile",{uid:C.renameImageId,folder:C.currentFolder,filename:C.renameImageFilename},function(e){e.ok?C.waitChangeComplete(C.images.length,!1):(C.isLoading=!1,t.pushError("Rename error",e.msg))})})},moveImage:function(e,o){C.isLoadingText="Moving image...",C.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsMoveFile",{uid:e,folder:o},function(e){e.ok?C.loadImages():(C.isLoading=!1,t.pushError("Rename error",e.msg))})})},deleteImageWarn:function(e){if(e){var o=_.find(C.images,["_id",C.deleteImageId]);C.deleteImageFilename=o.filename||"this image"}C.deleteImageShow=e},deleteImageGo:function(){C.deleteImageWarn(!1),C.isLoadingText="Deleting image...",C.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsDeleteFile",{uid:C.deleteImageId},function(e){C.loadImages()})})},selectFolder:function(e){C.currentFolder=e,C.loadImages()},refreshFolders:function(){C.isLoadingText="Fetching folders list...",C.isLoading=!0,C.currentFolder="",C.currentImage="",Vue.nextTick(function(){n.emit("uploadsGetFolders",{},function(e){C.folders=e,C.loadImages()})})},loadImages:function(e){return e||(C.isLoadingText="Fetching images...",C.isLoading=!0),new Promise(function(o,t){Vue.nextTick(function(){n.emit("uploadsGetImages",{folder:C.currentFolder},function(t){C.images=t,e||(C.isLoading=!1),C.attachContextMenus(),o(!0)})})})},waitChangeComplete:function(e,o){o=!_.isBoolean(o)||o,C.postUploadChecks++,C.isLoadingText="Processing...",Vue.nextTick(function(){C.loadImages(!0).then(function(){C.images.length!==e===o?(C.postUploadChecks=0,C.isLoading=!1):C.postUploadChecks>5?(C.postUploadChecks=0,C.isLoading=!1,t.pushError("Unable to fetch updated listing","Try again later")):_.delay(function(){C.waitChangeComplete(e,o)},1500)})})},attachContextMenus:function(){var o=_.map(C.folders,function(o){return{name:""!==o?o:"/ (root)",icon:"fa-folder",callback:function(o,t){var n=_.toString(e(t.$trigger).data("uid")),i=_.nth(C.folders,o);C.moveImage(n,i)}}});e.contextMenu("destroy",".editor-modal-image-choices > figure"),e.contextMenu({selector:".editor-modal-image-choices > figure",appendTo:".editor-modal-image-choices",position:function(o,t,n){e(o.$trigger).addClass("is-contextopen");var i=e(o.$trigger).position(),a={w:e(o.$trigger).width()/2,h:e(o.$trigger).height()/2};o.$menu.css({top:i.top+a.h,left:i.left+a.w})},events:{hide:function(o){e(o.$trigger).removeClass("is-contextopen")}},items:{rename:{name:"Rename",icon:"fa-edit",callback:function(e,o){C.renameImageId=_.toString(o.$trigger[0].dataset.uid),C.renameImage()}},move:{name:"Move to...",icon:"fa-folder-open-o",items:o},delete:{name:"Delete",icon:"fa-trash",callback:function(e,o){C.deleteImageId=_.toString(o.$trigger[0].dataset.uid),C.deleteImageWarn(!0)}}}})}}});e("#btn-editor-image-upload input").on("change",function(n){var i=C.images.length;e(n.currentTarget).simpleUpload("/uploads/img",{name:"imgfile",data:{folder:C.currentFolder},limit:20,expect:"json",allowedExts:["jpg","jpeg","gif","png","webp"],allowedTypes:["image/png","image/jpeg","image/gif","image/webp"],maxFileSize:3145728,init:function(e){C.uploadSucceeded=!1,C.isLoadingText="Preparing to upload...",C.isLoading=!0},progress:function(e){C.isLoadingText="Uploading..."+Math.round(e)+"%"},success:function(e){if(e.ok){var o=_.filter(e.results,["ok",!1]);o.length?(_.forEach(o,function(e){t.pushError("Upload error",e.msg)}),o.length<e.results.length&&(t.push({title:"Some uploads succeeded",message:"Files that are not mentionned in the errors above were uploaded successfully."}),C.uploadSucceeded=!0)):C.uploadSucceeded=!0}else t.pushError("Upload error",e.msg)},error:function(e){t.pushError(e.message,o.upload.file.name)},finish:function(){C.uploadSucceeded?C.waitChangeComplete(i,!0):C.isLoading=!1}})});var I=new Vue({el:"#modal-editor-file",data:{isLoading:!1,isLoadingText:"",newFolderName:"",newFolderShow:!1,newFolderError:!1,folders:[],currentFolder:"",currentFile:"",files:[],uploadSucceeded:!1,postUploadChecks:0,renameFileShow:!1,renameFileId:"",renameFileFilename:"",deleteFileShow:!1,deleteFileId:"",deleteFileFilename:""},methods:{open:function(){k=!0,e("#modal-editor-file").addClass("is-active"),I.refreshFolders()},cancel:function(o){k=!1,e("#modal-editor-file").removeClass("is-active")},selectFile:function(e){I.currentFile=e},insertFileLink:function(e){F.codemirror.doc.somethingSelected()&&F.codemirror.execCommand("singleSelection");var o=_.find(I.files,["_id",I.currentFile]);o.normalizedPath="f:"===o.folder?o.filename:o.folder.slice(2)+"/"+o.filename,o.titleGuess=_.startCase(o.basename);var t="["+o.titleGuess+"](/uploads/"+o.normalizedPath+' "'+o.titleGuess+'")';F.codemirror.doc.replaceSelection(t),I.cancel()},newFolder:function(o){I.newFolderName="",I.newFolderError=!1,I.newFolderShow=!0,_.delay(function(){e("#txt-editor-file-newfoldername").focus()},400)},newFolderDiscard:function(e){I.newFolderShow=!1},newFolderCreate:function(e){var o=new RegExp("^[a-z0-9][a-z0-9-]*[a-z0-9]$");if(I.newFolderName=_.kebabCase(_.trim(I.newFolderName)),_.isEmpty(I.newFolderName)||!o.test(I.newFolderName))return void(I.newFolderError=!0);I.newFolderDiscard(),I.isLoadingText="Creating new folder...",I.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsCreateFolder",{foldername:I.newFolderName},function(e){I.folders=e,I.currentFolder=I.newFolderName,I.files=[],I.isLoading=!1})})},renameFile:function(){var o=_.find(I.files,["_id",I.renameFileId]);I.renameFileFilename=o.basename||"",I.renameFileShow=!0,_.delay(function(){e("#txt-editor-renamefile").focus(),_.defer(function(){e("#txt-editor-file-rename").select()})},400)},renameFileDiscard:function(){I.renameFileShow=!1},renameFileGo:function(){I.renameFileDiscard(),I.isLoadingText="Renaming file...",I.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsRenameFile",{uid:I.renameFileId,folder:I.currentFolder,filename:I.renameFileFilename},function(e){e.ok?I.waitChangeComplete(I.files.length,!1):(I.isLoading=!1,t.pushError("Rename error",e.msg))})})},moveFile:function(e,o){I.isLoadingText="Moving file...",I.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsMoveFile",{uid:e,folder:o},function(e){e.ok?I.loadFiles():(I.isLoading=!1,t.pushError("Rename error",e.msg))})})},deleteFileWarn:function(e){if(e){var o=_.find(I.files,["_id",I.deleteFileId]);I.deleteFileFilename=o.filename||"this file"}I.deleteFileShow=e},deleteFileGo:function(){I.deleteFileWarn(!1),I.isLoadingText="Deleting file...",I.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsDeleteFile",{uid:I.deleteFileId},function(e){I.loadFiles()})})},selectFolder:function(e){I.currentFolder=e,I.loadFiles()},refreshFolders:function(){I.isLoadingText="Fetching folders list...",I.isLoading=!0,I.currentFolder="",I.currentImage="",Vue.nextTick(function(){n.emit("uploadsGetFolders",{},function(e){I.folders=e,I.loadFiles()})})},loadFiles:function(e){return e||(I.isLoadingText="Fetching files...",I.isLoading=!0),new Promise(function(o,t){Vue.nextTick(function(){n.emit("uploadsGetFiles",{folder:I.currentFolder},function(t){I.files=t,e||(I.isLoading=!1),I.attachContextMenus(),o(!0)})})})},waitChangeComplete:function(e,o){o=!_.isBoolean(o)||o,I.postUploadChecks++,I.isLoadingText="Processing...",Vue.nextTick(function(){I.loadFiles(!0).then(function(){I.files.length!==e===o?(I.postUploadChecks=0,I.isLoading=!1):I.postUploadChecks>5?(I.postUploadChecks=0,I.isLoading=!1,t.pushError("Unable to fetch updated listing","Try again later")):_.delay(function(){
|
|
I.waitChangeComplete(e,o)},1500)})})},attachContextMenus:function(){var o=_.map(I.folders,function(o){return{name:""!==o?o:"/ (root)",icon:"fa-folder",callback:function(o,t){var n=_.toString(e(t.$trigger).data("uid")),i=_.nth(I.folders,o);I.moveFile(n,i)}}});e.contextMenu("destroy",".editor-modal-file-choices > figure"),e.contextMenu({selector:".editor-modal-file-choices > figure",appendTo:".editor-modal-file-choices",position:function(o,t,n){e(o.$trigger).addClass("is-contextopen");var i=e(o.$trigger).position(),a={w:e(o.$trigger).width()/5,h:e(o.$trigger).height()/2};o.$menu.css({top:i.top+a.h,left:i.left+a.w})},events:{hide:function(o){e(o.$trigger).removeClass("is-contextopen")}},items:{rename:{name:"Rename",icon:"fa-edit",callback:function(e,o){I.renameFileId=_.toString(o.$trigger[0].dataset.uid),I.renameFile()}},move:{name:"Move to...",icon:"fa-folder-open-o",items:o},delete:{name:"Delete",icon:"fa-trash",callback:function(e,o){I.deleteFileId=_.toString(o.$trigger[0].dataset.uid),I.deleteFileWarn(!0)}}}})}}});e("#btn-editor-file-upload input").on("change",function(o){var n=I.files.length;e(o.currentTarget).simpleUpload("/uploads/file",{name:"binfile",data:{folder:I.currentFolder},limit:20,expect:"json",maxFileSize:0,init:function(e){I.uploadSucceeded=!1,I.isLoadingText="Preparing to upload...",I.isLoading=!0},progress:function(e){I.isLoadingText="Uploading..."+Math.round(e)+"%"},success:function(e){if(e.ok){var o=_.filter(e.results,["ok",!1]);o.length?(_.forEach(o,function(e){t.pushError("Upload error",e.msg)}),o.length<e.results.length&&(t.push({title:"Some uploads succeeded",message:"Files that are not mentionned in the errors above were uploaded successfully."}),I.uploadSucceeded=!0)):I.uploadSucceeded=!0}else t.pushError("Upload error",e.msg)},error:function(e){t.pushError("Upload error",e.message)},finish:function(){I.uploadSucceeded?I.waitChangeComplete(n,!0):I.isLoading=!1}})});var y={youtube:new RegExp(/(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|&v(?:i)?=))([^#&?]*).*/,"i"),vimeo:new RegExp(/vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^\/]*)\/videos\/|album\/(?:\d+)\/video\/|)(\d+)(?:$|\/|\?)/,"i"),dailymotion:new RegExp(/(?:dailymotion\.com(?:\/embed)?(?:\/video|\/hub)|dai\.ly)\/([0-9a-z]+)(?:[-_0-9a-zA-Z]+(?:#video=)?([a-z0-9]+)?)?/,"i")},L=new Vue({el:"#modal-editor-video",data:{link:""},methods:{open:function(o){e("#modal-editor-video").addClass("is-active"),e("#modal-editor-video input").focus()},cancel:function(o){k=!1,e("#modal-editor-video").removeClass("is-active"),L.link=""},insertVideo:function(e){F.codemirror.doc.somethingSelected()&&F.codemirror.execCommand("singleSelection");var o=_.findKey(y,function(e){return e.test(L.link)});_.isNil(o)&&(o="video");var t="[video]("+L.link+"){."+o+"}\n";F.codemirror.doc.replaceSelection(t),L.cancel()}}}),b=ace.require("ace/ext/modelist"),E=null,T=[],U=function(o){return e.ajax({url:"/js/ace/mode-"+o+".js",dataType:"script",cache:!0,beforeSend:function(){if(_.includes(T,o))return!1},success:function(){T.push(o)}})},N=new Vue({el:"#modal-editor-codeblock",data:{modes:b.modesByName,modeSelected:"text",initContent:""},watch:{modeSelected:function(e,o){U(e).done(function(){ace.require("ace/mode/"+e),E.getSession().setMode("ace/mode/"+e)})}},methods:{open:function(o){e("#modal-editor-codeblock").addClass("is-active"),_.delay(function(){E=ace.edit("codeblock-editor"),E.setTheme("ace/theme/tomorrow_night"),E.getSession().setMode("ace/mode/"+N.modeSelected),E.setOption("fontSize","14px"),E.setOption("hScrollBarAlwaysVisible",!1),E.setOption("wrap",!0),E.setValue(N.initContent),E.focus(),E.renderer.updateFull()},300)},cancel:function(o){k=!1,e("#modal-editor-codeblock").removeClass("is-active"),N.initContent=""},insertCode:function(e){F.codemirror.doc.somethingSelected()&&F.codemirror.execCommand("singleSelection");var o="\n```"+N.modeSelected+"\n"+E.getValue()+"\n```\n";F.codemirror.doc.replaceSelection(o),N.cancel()}}}),F=new SimpleMDE({autofocus:!0,autoDownloadFontAwesome:!1,element:e("#mk-editor").get(0),placeholder:"Enter Markdown formatted content here...",spellChecker:!1,status:!1,toolbar:[{name:"bold",action:SimpleMDE.toggleBold,className:"icon-bold",title:"Bold"},{name:"italic",action:SimpleMDE.toggleItalic,className:"icon-italic",title:"Italic"},{name:"strikethrough",action:SimpleMDE.toggleStrikethrough,className:"icon-strikethrough",title:"Strikethrough"},"|",{name:"heading-1",action:SimpleMDE.toggleHeading1,className:"icon-header fa-header-x fa-header-1",title:"Big Heading"},{name:"heading-2",action:SimpleMDE.toggleHeading2,className:"icon-header fa-header-x fa-header-2",title:"Medium Heading"},{name:"heading-3",action:SimpleMDE.toggleHeading3,className:"icon-header fa-header-x fa-header-3",title:"Small Heading"},{name:"quote",action:SimpleMDE.toggleBlockquote,className:"icon-quote-left",title:"Quote"},"|",{name:"unordered-list",action:SimpleMDE.toggleUnorderedList,className:"icon-th-list",title:"Bullet List"},{name:"ordered-list",action:SimpleMDE.toggleOrderedList,className:"icon-list-ol",title:"Numbered List"},"|",{name:"link",action:function(e){},className:"icon-link2",title:"Insert Link"},{name:"image",action:function(e){k||C.open()},className:"icon-image",title:"Insert Image"},{name:"file",action:function(e){k||I.open()},className:"icon-paper",title:"Insert File"},{name:"video",action:function(e){k||L.open()},className:"icon-video-camera2",title:"Insert Video Player"},"|",{name:"inline-code",action:function(e){if(!e.codemirror.doc.somethingSelected())return t.pushError("Invalid selection","You must select at least 1 character first.");var o=e.codemirror.doc.getSelections();o=_.map(o,function(e){return"`"+e+"`"}),e.codemirror.doc.replaceSelections(o)},className:"icon-terminal",title:"Inline Code"},{name:"code-block",action:function(e){k||(k=!0,F.codemirror.doc.somethingSelected()&&(N.initContent=F.codemirror.doc.getSelection()),N.open())},className:"icon-code",title:"Code Block"},"|",{name:"table",action:function(e){},className:"icon-table",title:"Insert Table"},{name:"horizontal-rule",action:SimpleMDE.drawHorizontalRule,className:"icon-minus2",title:"Horizontal Rule"}],shortcuts:{toggleBlockquote:null,toggleFullScreen:null}}),M=function(o){e.ajax(window.location.href,{data:{markdown:F.value()},dataType:"json",method:"PUT"}).then(function(e,o,n){e.ok?window.location.assign("/"+S):t.pushError("Something went wrong",e.error)},function(e,o,n){t.pushError("Something went wrong","Save operation failed.")})};e(".btn-edit-save, .btn-create-save").on("click",function(e){M(e)}),e(window).bind("keydown",function(e){if(e.ctrlKey||e.metaKey)switch(String.fromCharCode(e.which).toLowerCase()){case"s":e.preventDefault(),M(e)}})}}if(e("#page-type-source").length){var D=ace.edit("source-display");D.setTheme("ace/theme/tomorrow_night"),D.getSession().setMode("ace/mode/markdown"),D.setOption("fontSize","14px"),D.setOption("hScrollBarAlwaysVisible",!1),D.setOption("wrap",!0),D.setReadOnly(!0),D.renderer.updateFull();var V="home"!==e("#page-type-source").data("entrypath")?e("#page-type-source").data("entrypath"):"",R=V+"/new-page";e(".btn-create-prompt").on("click",function(o){e("#txt-create-prompt").val(R),e("#modal-create-prompt").toggleClass("is-active"),setInputSelection(e("#txt-create-prompt").get(0),V.length+1,R.length),e("#txt-create-prompt").removeClass("is-danger").next().addClass("is-hidden")}),e("#txt-create-prompt").on("keypress",function(o){13===o.which&&e(".btn-create-go").trigger("click")}),e(".btn-create-go").on("click",function(o){var t=makeSafePath(e("#txt-create-prompt").val());_.isEmpty(t)?e("#txt-create-prompt").addClass("is-danger").next().removeClass("is-hidden"):(e("#txt-create-prompt").parent().addClass("is-loading"),window.location.assign("/create/"+t))}),""!==V&&e(".btn-move-prompt").removeClass("is-hidden");var z=_.lastIndexOf(V,"/")+1;e(".btn-move-prompt").on("click",function(o){e("#txt-move-prompt").val(V),e("#modal-move-prompt").toggleClass("is-active"),setInputSelection(e("#txt-move-prompt").get(0),z,V.length),e("#txt-move-prompt").removeClass("is-danger").next().addClass("is-hidden")}),e("#txt-move-prompt").on("keypress",function(o){13===o.which&&e(".btn-move-go").trigger("click")}),e(".btn-move-go").on("click",function(o){var n=makeSafePath(e("#txt-move-prompt").val());_.isEmpty(n)||n===V||"home"===n?e("#txt-move-prompt").addClass("is-danger").next().removeClass("is-hidden"):(e("#txt-move-prompt").parent().addClass("is-loading"),e.ajax(window.location.href,{data:{move:n},dataType:"json",method:"PUT"}).then(function(e,o,i){e.ok?window.location.assign("/"+n):t.pushError("Something went wrong",e.error)},function(e,o,n){t.pushError("Something went wrong","Save operation failed.")}))})}if(e("#page-type-admin-profile").length)var $=new Vue({el:"#page-type-admin-profile",data:{password:"********",passwordVerify:"********",name:""},methods:{saveUser:function(o){if($.password!==$.passwordVerify)return void t.pushError("Error","Passwords don't match!");e.post(window.location.href,{password:$.password,name:$.name}).done(function(e){t.pushSuccess("Saved successfully","Changes have been applied.")}).fail(function(e,o,n){t.pushError("Error",n)})}},created:function(){this.name=usrDataName}});else if(e("#page-type-admin-users").length){var P=new Vue({el:"#modal-admin-users-create",data:{email:"",provider:"local",password:"",name:"",loading:!1},methods:{open:function(o){e("#modal-admin-users-create").addClass("is-active"),e("#modal-admin-users-create input").first().focus()},cancel:function(o){e("#modal-admin-users-create").removeClass("is-active"),P.email="",P.provider="local"},create:function(o){P.loading=!0,e.ajax("/admin/users/create",{data:{email:P.email,provider:P.provider,password:P.password,name:P.name},dataType:"json",method:"POST"}).then(function(e,o,n){P.loading=!1,e.ok?(P.cancel(),window.location.reload(!0)):t.pushError("Something went wrong",e.msg)},function(e,o,n){P.loading=!1,t.pushError("Error",e.responseJSON.msg)})}}});e(".btn-create-prompt").on("click",P.open)}else if(e("#page-type-admin-users-edit").length){var j=new Vue({el:"#page-type-admin-users-edit",data:{id:"",email:"",password:"********",name:"",rights:[],roleoverride:"none"},methods:{addRightsRow:function(e){j.rights.push({role:"write",path:"/",exact:!1,deny:!1})},removeRightsRow:function(e){_.pullAt(j.rights,e),j.$forceUpdate()},saveUser:function(o){var n=_.cloneDeep(j.rights);switch(j.roleoverride){case"admin":n.push({role:"admin",path:"/",exact:!1,deny:!1})}e.post(window.location.href,{password:j.password,name:j.name,rights:JSON.stringify(n)}).done(function(e){t.pushSuccess("Saved successfully","Changes have been applied.")}).fail(function(e,o,n){t.pushError("Error",n)})}},created:function(){this.id=usrData._id,this.email=usrData.email,this.name=usrData.name,_.find(usrData.rights,{role:"admin"})?(this.rights=_.reject(usrData.rights,["role","admin"]),this.roleoverride="admin"):this.rights=usrData.rights}}),G=new Vue({el:"#modal-admin-users-delete",data:{loading:!1},methods:{open:function(o){e("#modal-admin-users-delete").addClass("is-active")},cancel:function(o){e("#modal-admin-users-delete").removeClass("is-active")},deleteUser:function(o){G.loading=!0,e.ajax("/admin/users/"+usrData._id,{dataType:"json",method:"DELETE"}).then(function(e,o,t){G.loading=!1,G.cancel(),window.location.assign("/admin/users")},function(e,o,n){G.loading=!1,t.pushError("Error",e.responseJSON.msg)})}}});e(".btn-deluser-prompt").on("click",G.open)}else if(e("#page-type-admin-settings").length)var B=new Vue({el:"#page-type-admin-settings",data:{upgradeModal:{state:!1,step:"confirm",mode:"upgrade",error:"Something went wrong."}},methods:{upgrade:function(e){B.upgradeModal.mode="upgrade",B.upgradeModal.step="confirm",B.upgradeModal.state=!0},reinstall:function(e){B.upgradeModal.mode="re-install",B.upgradeModal.step="confirm",B.upgradeModal.state=!0},upgradeCancel:function(e){B.upgradeModal.state=!1},upgradeStart:function(o){B.upgradeModal.step="running",e.post("/admin/settings/install",{mode:B.upgradeModal.mode}).done(function(e){}).fail(function(e,o,t){B.upgradeModal.step="error",B.upgradeModal.error=e.responseText})},flushcache:function(e){window.alert("Coming soon!")},resetaccounts:function(e){window.alert("Coming soon!")},flushsessions:function(e){window.alert("Coming soon!")}}})});var Alerts=function(){function e(){_classCallCheck(this,e);var o=this;o.mdl=new Vue({el:"#alerts",data:{children:[]},methods:{acknowledge:function(e){o.close(e)}}}),o.uidNext=1}return _createClass(e,[{key:"push",value:function(e){var o=this,t=_.defaults(e,{_uid:o.uidNext,class:"info",message:"---",sticky:!1,title:"---"});o.mdl.children.push(t),t.sticky||_.delay(function(){o.close(t._uid)},5e3),o.uidNext++}},{key:"pushError",value:function(e,o){this.push({class:"error",message:o,sticky:!1,title:e})}},{key:"pushSuccess",value:function(e,o){this.push({class:"success",message:o,sticky:!1,title:e})}},{key:"close",value:function(e){var o=this,t=_.findIndex(o.mdl.children,["_uid",e]),n=_.nth(o.mdl.children,t);t>=0&&n&&(n.class+=" exit",Vue.set(o.mdl.children,t,n),_.delay(function(){o.mdl.children.splice(t,1)},500))}}]),e}(); |