From e9554df6bfd5ea4d62f1b4b5238a8acae550a41e Mon Sep 17 00:00:00 2001 From: Zac White Date: Tue, 15 Aug 2023 17:02:09 -0400 Subject: [PATCH] Corrected code quality issues --- core/Piranha.Manager/assets/dist/js/piranha.js | 7 ++++--- core/Piranha.Manager/assets/dist/js/piranha.min.js | 2 +- core/Piranha.Manager/assets/src/js/piranha.pagepicker.js | 7 ++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/core/Piranha.Manager/assets/dist/js/piranha.js b/core/Piranha.Manager/assets/dist/js/piranha.js index 8b8d7ac2d..fc35ccb18 100644 --- a/core/Piranha.Manager/assets/dist/js/piranha.js +++ b/core/Piranha.Manager/assets/dist/js/piranha.js @@ -934,11 +934,12 @@ piranha.pagepicker = new Vue({ filteredItems: function () { let self = this; - if (self.search.length < 1) - return this.items; + if (self.search && self.search.length < 1) { + return this.items; + } let items = Object.assign([], this.items); - let searchTerm = self.search ? self.search.toLowerCase() : ''; + let searchTerm = self.search ? self.search.toLowerCase() : ""; let filterRecursive = function(arr) { return arr.reduce(function(acc, item){ diff --git a/core/Piranha.Manager/assets/dist/js/piranha.min.js b/core/Piranha.Manager/assets/dist/js/piranha.min.js index 57f83416d..b25e56975 100644 --- a/core/Piranha.Manager/assets/dist/js/piranha.min.js +++ b/core/Piranha.Manager/assets/dist/js/piranha.min.js @@ -1 +1 @@ -Vue.prototype.eventBus=new Vue,piranha.accessibility=new function(){"use strict";var e=this;e.focus=null,e.removeBlock=function(e){var t=$(":focus").parents(".block");if(1===t.length){if(tinymce){var i=tinymce.activeEditor;i&&i.inline&&i.destroy()}t.find(".block-remove").click()}},$(document).on("show.bs.modal",".modal",function(){e.focus=$(":focus")}),$(document).on("hidden.bs.modal",".modal",function(){e.focus&&(e.focus.focus(),e.focus=null)}),$(window).on("keydown",function(t){$(".main-nav");t.altKey&&(67===t.keyCode?$("#contentSelector").click():8===t.keyCode&&e.removeBlock(t))})},piranha.alert=new Vue({el:"#alert",data:{title:null,body:null,confirmCss:null,confirmIcon:null,confirmText:null,cancelCss:null,cancelIcon:null,cancelText:null,onConfirm:null,onCancel:null,verifyPhrase:null,verifyPlaceholder:null,verifyText:null,verifyInput:null},methods:{open:function(e){e&&(this.title=e.title,this.body=e.body,this.confirmCss=e.confirmCss?e.confirmCss:"btn-success",this.confirmIcon=e.confirmIcon,this.confirmText=e.confirmText?e.confirmText:piranha.resources.texts.ok,this.cancelCss=e.cancelCss?e.cancelCss:"btn-secondary",this.cancelIcon=e.cancelIcon,this.cancelText=e.cancelText?e.cancelText:piranha.resources.texts.cancel,this.onConfirm=e.onConfirm,this.onCancel=e.onCancel,this.verifyPhrase=e.verifyPhrase,this.verifyPlaceholder=e.verifyPlaceholder,this.verifyText=e.verifyText,$("#alert").modal("show"))},confirm:function(){this.onConfirm&&(this.onConfirm(),this.clear()),$("#alert").modal("hide")},cancel:function(){this.onCancel&&(this.onCancel(),this.clear()),$("#alert").modal("hide")},canConfirm:function(){return!this.verifyPhrase||this.verifyPhrase===this.verifyInput},clear:function(){this.onCancel=null,this.onConfirm=null,this.verifyInput=null}}}),piranha.archivepicker=new Vue({el:"#archivepicker",data:{search:"",sites:[],items:[],currentSiteId:null,currentSiteTitle:null,filter:null,callback:null},computed:{filteredItems:function(){var e=this;return this.items.filter(function(t){return!(e.search.length>0)||t.title.toLowerCase().indexOf(e.search.toLowerCase())>-1})}},methods:{load:function(e){var t=piranha.baseUrl+"manager/api/page/archives"+(e?"/"+e:""),i=this;fetch(t).then(function(e){return e.json()}).then(function(e){i.currentSiteId=e.siteId,i.currentSiteTitle=e.siteTitle,i.sites=e.sites,i.items=e.items}).catch(function(e){console.log("error:",e)})},refresh:function(){this.load(piranha.archivepicker.currentSiteId)},open:function(e,t){this.search="",this.callback=e,this.load(t),$("#archivepicker").modal("show")},onEnter:function(){1==this.filteredItems.length&&this.select(this.filteredItems[0])},select:function(e){this.callback(JSON.parse(JSON.stringify(e))),this.callback=null,this.search="",$("#archivepicker").modal("hide")}}}),$(document).ready(function(){$("#archivepicker").on("shown.bs.modal",function(){$("#archivepickerSearch").trigger("focus")})}),Dropzone.autoDiscover=!1,piranha.dropzone=new function(){this.init=function(e,t){t||(t={});var i={paramName:"Uploads",url:piranha.baseUrl+"manager/api/media/upload",headers:piranha.utils.antiForgeryHeaders(!1),thumbnailWidth:70,thumbnailHeight:70,previewsContainer:e+" .media-list",previewTemplate:document.querySelector("#media-upload-template").innerHTML,uploadMultiple:!0,timeout:1e3*piranha.xhrTimeout,init:function(){t.addedfile||(t.addedfile=function(e){}),t.removedfile||(t.removedfile=function(e){}),t.error||(t.error=function(e){}),t.complete||(t.complete=function(e){if("success"!==e.status&&""!==e.xhr.responseText){var t=JSON.parse(e.xhr.responseText);e.previewElement.querySelector("[data-dz-errormessage]").innerText=t.body}}),t.queuecomplete||(t.queuecomplete=function(){}),this.on("addedfile",t.addedfile),this.on("removedfile",t.removedfile),this.on("complete",t.complete),this.on("queuecomplete",t.queuecomplete)}},n=Object.assign(i,t);return new Dropzone(e+" form",n)}},piranha.permissions={loaded:!1,aliases:{edit:!1,delete:!1},comments:{approve:!1,delete:!1},media:{add:!1,addFolder:!1,delete:!1,deleteFolder:!1,edit:!1},pages:{add:!1,delete:!1,edit:!1,preview:!1,publish:!1,save:!1},posts:{add:!1,delete:!1,edit:!1,preview:!1,publish:!1,save:!1},sites:{add:!1,delete:!1,edit:!1,save:!1},load:function(e){var t=this;this.loaded?e&&e():fetch(piranha.baseUrl+"manager/api/permissions").then(function(e){return e.json()}).then(function(i){t.aliases=i.aliases,t.comments=i.comments,t.media=i.media,t.pages=i.pages,t.posts=i.posts,t.sites=i.sites,t.loaded=!0,e&&e()}).catch(function(t){console.log("error:",t),e&&e()})}},piranha.utils={getOrigin:()=>window.location.origin,formatUrl:function(e){return e.replace("~/",piranha.baseUrl)},isEmptyHtml:function(e){return null==e||""==e.replace(/(<([^>]+)>)/gi,"").replace(/\s/g,"")&&-1===e.indexOf(""==e.replace(/\s/g,"")},strLength:function(e){return null!=e?e.length:0},antiForgery:function(){const e=document.cookie.split(";");for(let t=0;ti){var n=t.outerHeight();e>i+n?$(this).css({top:n+"px"}):$(this).css({top:e-i+"px"})}else $(this).removeAttr("style")})}),piranha.blockpicker=new Vue({el:"#blockpicker",data:{filter:"",categories:[],index:0,callback:null},computed:{filteredCategories:function(){var e=this;return this.categories.filter(function(t){return e.filterBlockTypes(t).length>0})}},methods:{open:function(e,t,i){var n=this,r=piranha.baseUrl+"manager/api/content/blocktypes";piranha.pageedit?r+="/page/"+piranha.pageedit.typeId:piranha.postedit&&(r+="/post/"+piranha.postedit.typeId),fetch(r+(null!=i?"/"+i:"")).then(function(e){return e.json()}).then(function(i){i.typeCount>1?(n.filter="",n.index=t,n.callback=e,n.categories=i.categories,$("#blockpicker").modal("show")):e(i.categories[0].items[0].type,t)}).catch(function(e){console.log("error:",e)})},select:function(e){this.callback(e.type,this.index),this.index=0,this.callback=null,$("#blockpicker").modal("hide")},selectSingleItem:function(){var e=this.filteredCategories;if(1===e.length){var t=this.filterBlockTypes(e[0]);1===t.length&&this.select(t[0])}},filterBlockTypes:function(e){var t=this;return e.items.filter(function(e){return e.name.toLowerCase().indexOf(t.filter.toLowerCase())>-1})}},created:function(){}}),$(document).ready(function(){$("#blockpicker").on("shown.bs.modal",function(){$("#blockpickerSearch").trigger("focus")})}),piranha.notifications=new Vue({el:"#notification-hub",data:{items:[]},methods:{unauthorized:function(){this.push({type:"danger",body:"Request sender could not be verified by the server.",hide:!0})},push:function(e){e.style={visible:!1,"notification-info":"info"===e.type,"notification-danger":"danger"===e.type,"notification-success":"success"===e.type,"notification-warning":"warning"===e.type},piranha.notifications.items.push(e),setTimeout(function(){e.style.visible=!0,e.hide&&setTimeout(function(){e.style.visible=!1,setTimeout(function(){piranha.notifications.items.shift()},200)},5e3)},200)}}}),piranha.contentpicker=new Vue({el:"#contentpicker",data:{search:"",groups:[],items:[],currentGroupId:null,currentGroupTitle:null,currentGroupIcon:null,filter:null,callback:null},computed:{filteredItems:function(){var e=this;return this.items.filter(function(t){return!(e.search.length>0)||t.title.toLowerCase().indexOf(e.search.toLowerCase())>-1})}},methods:{bind:function(e,t){this.currentGroupId=e.group.id,this.currentGroupTitle=e.group.title,this.currentGroupIcon=e.group.icon,this.types=e.types,this.items=e.items.map(function(t){var i=e.types.find(function(e){return e.id===t.typeId});return t.type=i.title||t.typeId,t}),t||(this.groups=e.groups)},load:function(e,t){var i=piranha.baseUrl+"manager/api/content/"+(e?e+"/":"")+"list",n=this;fetch(i).then(function(e){return e.json()}).then(function(e){n.bind(e,t)}).catch(function(e){console.log("error:",e)})},loadGroups:function(){},refresh:function(){this.load(piranha.contentpicker.currentGroupId,!0)},open:function(e,t){this.search="",this.callback=t,this.load(e),$("#contentpicker").modal("show")},onEnter:function(){1==this.filteredItems.length&&this.select(this.filteredItems[0])},select:function(e){this.callback(JSON.parse(JSON.stringify(e))),this.callback=null,this.search="",$("#contentpicker").modal("hide")}}}),$(document).ready(function(){$("#contentpicker").on("shown.bs.modal",function(){$("#contentpickerSearch").trigger("focus")})}),piranha.mediapicker=new Vue({el:"#mediapicker",data:{search:"",folderName:"",listView:!0,currentFolderId:null,parentFolderId:null,currentDocumentFolderId:null,parentDocumentFolderId:null,currentImageFolderId:null,parentImageFolderId:null,currentVideoFolderId:null,parentVideoFolderId:null,currentFolderBreadcrumb:null,folders:[],items:[],folder:{name:null},filter:null,callback:null,dropzone:null},computed:{filteredFolders:function(){return this.folders.filter(function(e){return!(piranha.mediapicker.search.length>0)||e.name.toLowerCase().indexOf(piranha.mediapicker.search.toLowerCase())>-1})},filteredItems:function(){return this.items.filter(function(e){return!(piranha.mediapicker.search.length>0)||e.filename.toLowerCase().indexOf(piranha.mediapicker.search.toLowerCase())>-1})}},methods:{toggle:function(){this.listView=!this.listView},load:function(e){var t=this,i=piranha.baseUrl+"manager/api/media/list"+(e?"/"+e:"")+"/?width=210&height=160";t.filter&&(i+="&filter="+t.filter),fetch(i).then(function(e){return e.json()}).then(function(e){if(t.currentFolderId=e.currentFolderId,t.parentFolderId=e.parentFolderId,t.folders=e.folders,t.items=e.media,t.listView="list"===e.viewMode,t.search="",t.currentFolderBreadcrumb=e.currentFolderBreadcrumb,t.filter)switch(t.filter.toLowerCase()){case"document":t.currentDocumentFolderId=e.currentFolderId,t.parentDocumentFolderId=e.parentFolderId;break;case"image":t.currentImageFolderId=e.currentFolderId,t.parentImageFolderId=e.parentFolderId;break;case"video":t.currentVideoFolderId=e.currentFolderId,t.parentVideoFolderId=e.parentFolderId}}).catch(function(e){console.log("error:",e)})},getThumbnailUrl:function(e){return null!==e.altVersionUrl?e.altVersionUrl:piranha.baseUrl+"manager/api/media/url/"+e.id+"/210/160"},refresh:function(){piranha.mediapicker.load(piranha.mediapicker.currentFolderId)},open:function(e,t,i){this.search="",this.callback=e,this.filter=t,this.load(i),$("#mediapicker").modal("show")},openCurrentFolder:function(e,t){this.callback=e,this.filter=t;var i=this.currentFolderId;if(t)switch(t.toLowerCase()){case"document":i=this.currentDocumentFolderId?this.currentDocumentFolderId:i;break;case"image":i=this.currentImageFolderId?this.currentImageFolderId:i;break;case"video":i=this.currentVideoFolderId?this.currentVideoFolderId:i}this.load(i),$("#mediapicker").modal("show")},onEnter:function(){0===this.filteredItems.length&&1===this.filteredFolders.length&&(this.load(this.filteredFolders[0].id),this.search=""),1===this.filteredItems.length&&0===this.filteredFolders.length&&this.select(this.filteredItems[0])},select:function(e){this.callback(JSON.parse(JSON.stringify(e))),this.callback=null,this.search="",$("#mediapicker").modal("hide")},savefolder:function(){var e=this;""!==e.folderName&&fetch(piranha.baseUrl+"manager/api/media/folder/save"+(e.filter?"?filter="+e.filter:""),{method:"post",headers:piranha.utils.antiForgeryHeaders(),body:JSON.stringify({parentId:e.currentFolderId,name:e.folderName})}).then(function(e){return e.json()}).then(function(t){"success"===t.status.type&&(e.folderName=null,e.folders=t.folders,e.items=t.media),400!==t.status?piranha.notifications.push(t.status):piranha.notifications.unauthorized()}).catch(function(e){console.log("error:",e)})}},mounted:function(){var e=this;piranha.permissions.load(function(){piranha.permissions.media.add&&(e.dropzone=piranha.dropzone.init("#mediapicker-upload-container"),e.dropzone.on("complete",function(t){"success"===t.status&&setTimeout(function(){e.dropzone.removeFile(t)},3e3)}),e.dropzone.on("queuecomplete",function(){piranha.mediapicker.refresh()}))})}}),$(document).ready(function(){$("#mediapicker").on("shown.bs.modal",function(){$("#mediapickerSearch").trigger("focus")})}),piranha.pagepicker=new Vue({el:"#pagepicker",data:{search:"",sites:[],items:[],currentSiteId:null,currentSiteTitle:null,filter:null,callback:null},computed:{filteredItems:function(){if(this.search.length<1)return this.items;let e=Object.assign([],this.items),t=this.search?this.search.toLowerCase():"",i=function(e){return e.reduce(function(e,n){let r=Object.assign({},n);return r.items&&(r.items=i(n.items),r.isExpanded=r.items.length>0),r.title&&(r.title.toLowerCase().indexOf(t)>-1||r.isExpanded)&&e.push(r),e},[])};return i(e)}},methods:{load:function(e){var t=piranha.baseUrl+"manager/api/page/sitemap"+(e?"/"+e:""),i=this;fetch(t).then(function(e){return e.json()}).then(function(e){i.currentSiteId=e.siteId,i.currentSiteTitle=e.siteTitle,i.sites=e.sites,i.items=e.items}).catch(function(e){console.log("error:",e)})},refresh:function(){this.load(piranha.pagepicker.currentSiteId)},open:function(e,t){this.search="",this.callback=e,this.load(t),$("#pagepicker").modal("show")},onEnter:function(){1==this.filteredItems.length&&this.select(this.filteredItems[0])},select:function(e){this.callback(JSON.parse(JSON.stringify(e))),this.callback=null,this.search="",$("#pagepicker").modal("hide")}}}),$(document).ready(function(){$("#pagepicker").on("shown.bs.modal",function(){$("#pagepickerSearch").trigger("focus")})}),piranha.postpicker=new Vue({el:"#postpicker",data:{search:"",sites:[],archives:[],posts:[],currentSiteId:null,currentArchiveId:null,currentSiteTitle:null,currentArchiveTitle:null,filter:null,callback:null},computed:{filteredPosts:function(){return this.posts.filter(function(e){return!(piranha.postpicker.search.length>0)||e.title.toLowerCase().indexOf(piranha.postpicker.search.toLowerCase())>-1})}},methods:{load:function(e,t){var i=piranha.baseUrl+"manager/api/post/modal";e&&(i+="?siteId="+e,t&&(i+="&archiveId="+t)),fetch(i).then(function(e){return e.json()}).then(function(e){piranha.postpicker.sites=e.sites,piranha.postpicker.archives=e.archives,piranha.postpicker.posts=e.posts,piranha.postpicker.currentSiteId=e.siteId,piranha.postpicker.currentArchiveId=e.archiveId,piranha.postpicker.currentSiteTitle=e.siteTitle,piranha.postpicker.currentArchiveTitle=e.archiveTitle}).catch(function(e){console.log("error:",e)})},refresh:function(){this.load(this.currentSiteId,this.currentArchiveId)},open:function(e,t,i,n){this.search="",this.callback=e,this.load(t,i),$("#postpicker").modal("show")},onEnter:function(){1==this.filteredPosts.length&&this.select(this.filteredPosts[0])},select:function(e){this.callback(JSON.parse(JSON.stringify(e))),this.callback=null,this.search="",$("#postpicker").modal("hide")}}}),$(document).ready(function(){$("#postpicker").on("shown.bs.modal",function(){$("#postpickerSearch").trigger("focus")})}),piranha.preview=new Vue({el:"#previewModal",data:{empty:{filename:null,type:null,contentType:null,publicUrl:null,size:null,width:null,height:null,title:null,altText:null,description:null,lastModified:null},media:null,dropzone:null},methods:{openItem:function(e){piranha.preview.media=e,piranha.preview.show()},open:function(e){piranha.preview.load(e),piranha.preview.show()},load:function(e){var t=this;fetch(piranha.baseUrl+"manager/api/media/"+e).then(function(e){return e.json()}).then(function(e){t.media=e}).catch(function(e){console.log("error:",e)})},saveMeta:function(e){var t=this,i={id:e.id,title:e.title,altText:e.altText,description:e.description,properties:e.properties};fetch(piranha.baseUrl+"manager/api/media/meta/save",{method:"post",headers:piranha.utils.antiForgeryHeaders(),body:JSON.stringify(i)}).then(function(e){return e.json()}).then(function(e){piranha.notifications.push(e),"success"===e.type&&t.close()}).catch(function(e){console.log("error:",e)})},show:function(){$("#previewModal").modal("show")},close:function(){$("#previewModal").modal("hide"),setTimeout(function(){piranha.preview.clear()},300)},clear:function(){this.media=this.empty}},created:function(){this.clear()},mounted:function(){this.dropzone=piranha.dropzone.init("#media-update-container",{uploadMultiple:!1}),this.dropzone.on("complete",function(e){setTimeout(function(){piranha.preview.dropzone.removeFile(e)},3e3)}),this.dropzone.on("queuecomplete",function(){piranha.preview.load(piranha.preview.media.id),piranha.media.refresh()})}}),piranha.languageedit=new Vue({el:"#languageedit",data:{loading:!0,items:[],originalDefault:null,currentDefault:null,showDefaultInfo:!1,currentDelete:null,showDeleteInfo:!1},methods:{bind:function(e){for(var t=0;t\n
\n \n
\n {{ item.typeName }}\n
\n
\n
    \n \n \n
\n\n'}); \ No newline at end of file +Vue.prototype.eventBus=new Vue,piranha.accessibility=new function(){"use strict";var e=this;e.focus=null,e.removeBlock=function(e){var t=$(":focus").parents(".block");if(1===t.length){if(tinymce){var i=tinymce.activeEditor;i&&i.inline&&i.destroy()}t.find(".block-remove").click()}},$(document).on("show.bs.modal",".modal",function(){e.focus=$(":focus")}),$(document).on("hidden.bs.modal",".modal",function(){e.focus&&(e.focus.focus(),e.focus=null)}),$(window).on("keydown",function(t){$(".main-nav");t.altKey&&(67===t.keyCode?$("#contentSelector").click():8===t.keyCode&&e.removeBlock(t))})},piranha.alert=new Vue({el:"#alert",data:{title:null,body:null,confirmCss:null,confirmIcon:null,confirmText:null,cancelCss:null,cancelIcon:null,cancelText:null,onConfirm:null,onCancel:null,verifyPhrase:null,verifyPlaceholder:null,verifyText:null,verifyInput:null},methods:{open:function(e){e&&(this.title=e.title,this.body=e.body,this.confirmCss=e.confirmCss?e.confirmCss:"btn-success",this.confirmIcon=e.confirmIcon,this.confirmText=e.confirmText?e.confirmText:piranha.resources.texts.ok,this.cancelCss=e.cancelCss?e.cancelCss:"btn-secondary",this.cancelIcon=e.cancelIcon,this.cancelText=e.cancelText?e.cancelText:piranha.resources.texts.cancel,this.onConfirm=e.onConfirm,this.onCancel=e.onCancel,this.verifyPhrase=e.verifyPhrase,this.verifyPlaceholder=e.verifyPlaceholder,this.verifyText=e.verifyText,$("#alert").modal("show"))},confirm:function(){this.onConfirm&&(this.onConfirm(),this.clear()),$("#alert").modal("hide")},cancel:function(){this.onCancel&&(this.onCancel(),this.clear()),$("#alert").modal("hide")},canConfirm:function(){return!this.verifyPhrase||this.verifyPhrase===this.verifyInput},clear:function(){this.onCancel=null,this.onConfirm=null,this.verifyInput=null}}}),piranha.archivepicker=new Vue({el:"#archivepicker",data:{search:"",sites:[],items:[],currentSiteId:null,currentSiteTitle:null,filter:null,callback:null},computed:{filteredItems:function(){var e=this;return this.items.filter(function(t){return!(e.search.length>0)||t.title.toLowerCase().indexOf(e.search.toLowerCase())>-1})}},methods:{load:function(e){var t=piranha.baseUrl+"manager/api/page/archives"+(e?"/"+e:""),i=this;fetch(t).then(function(e){return e.json()}).then(function(e){i.currentSiteId=e.siteId,i.currentSiteTitle=e.siteTitle,i.sites=e.sites,i.items=e.items}).catch(function(e){console.log("error:",e)})},refresh:function(){this.load(piranha.archivepicker.currentSiteId)},open:function(e,t){this.search="",this.callback=e,this.load(t),$("#archivepicker").modal("show")},onEnter:function(){1==this.filteredItems.length&&this.select(this.filteredItems[0])},select:function(e){this.callback(JSON.parse(JSON.stringify(e))),this.callback=null,this.search="",$("#archivepicker").modal("hide")}}}),$(document).ready(function(){$("#archivepicker").on("shown.bs.modal",function(){$("#archivepickerSearch").trigger("focus")})}),Dropzone.autoDiscover=!1,piranha.dropzone=new function(){this.init=function(e,t){t||(t={});var i={paramName:"Uploads",url:piranha.baseUrl+"manager/api/media/upload",headers:piranha.utils.antiForgeryHeaders(!1),thumbnailWidth:70,thumbnailHeight:70,previewsContainer:e+" .media-list",previewTemplate:document.querySelector("#media-upload-template").innerHTML,uploadMultiple:!0,timeout:1e3*piranha.xhrTimeout,init:function(){t.addedfile||(t.addedfile=function(e){}),t.removedfile||(t.removedfile=function(e){}),t.error||(t.error=function(e){}),t.complete||(t.complete=function(e){if("success"!==e.status&&""!==e.xhr.responseText){var t=JSON.parse(e.xhr.responseText);e.previewElement.querySelector("[data-dz-errormessage]").innerText=t.body}}),t.queuecomplete||(t.queuecomplete=function(){}),this.on("addedfile",t.addedfile),this.on("removedfile",t.removedfile),this.on("complete",t.complete),this.on("queuecomplete",t.queuecomplete)}},n=Object.assign(i,t);return new Dropzone(e+" form",n)}},piranha.permissions={loaded:!1,aliases:{edit:!1,delete:!1},comments:{approve:!1,delete:!1},media:{add:!1,addFolder:!1,delete:!1,deleteFolder:!1,edit:!1},pages:{add:!1,delete:!1,edit:!1,preview:!1,publish:!1,save:!1},posts:{add:!1,delete:!1,edit:!1,preview:!1,publish:!1,save:!1},sites:{add:!1,delete:!1,edit:!1,save:!1},load:function(e){var t=this;this.loaded?e&&e():fetch(piranha.baseUrl+"manager/api/permissions").then(function(e){return e.json()}).then(function(i){t.aliases=i.aliases,t.comments=i.comments,t.media=i.media,t.pages=i.pages,t.posts=i.posts,t.sites=i.sites,t.loaded=!0,e&&e()}).catch(function(t){console.log("error:",t),e&&e()})}},piranha.utils={getOrigin:()=>window.location.origin,formatUrl:function(e){return e.replace("~/",piranha.baseUrl)},isEmptyHtml:function(e){return null==e||""==e.replace(/(<([^>]+)>)/gi,"").replace(/\s/g,"")&&-1===e.indexOf(""==e.replace(/\s/g,"")},strLength:function(e){return null!=e?e.length:0},antiForgery:function(){const e=document.cookie.split(";");for(let t=0;ti){var n=t.outerHeight();e>i+n?$(this).css({top:n+"px"}):$(this).css({top:e-i+"px"})}else $(this).removeAttr("style")})}),piranha.blockpicker=new Vue({el:"#blockpicker",data:{filter:"",categories:[],index:0,callback:null},computed:{filteredCategories:function(){var e=this;return this.categories.filter(function(t){return e.filterBlockTypes(t).length>0})}},methods:{open:function(e,t,i){var n=this,r=piranha.baseUrl+"manager/api/content/blocktypes";piranha.pageedit?r+="/page/"+piranha.pageedit.typeId:piranha.postedit&&(r+="/post/"+piranha.postedit.typeId),fetch(r+(null!=i?"/"+i:"")).then(function(e){return e.json()}).then(function(i){i.typeCount>1?(n.filter="",n.index=t,n.callback=e,n.categories=i.categories,$("#blockpicker").modal("show")):e(i.categories[0].items[0].type,t)}).catch(function(e){console.log("error:",e)})},select:function(e){this.callback(e.type,this.index),this.index=0,this.callback=null,$("#blockpicker").modal("hide")},selectSingleItem:function(){var e=this.filteredCategories;if(1===e.length){var t=this.filterBlockTypes(e[0]);1===t.length&&this.select(t[0])}},filterBlockTypes:function(e){var t=this;return e.items.filter(function(e){return e.name.toLowerCase().indexOf(t.filter.toLowerCase())>-1})}},created:function(){}}),$(document).ready(function(){$("#blockpicker").on("shown.bs.modal",function(){$("#blockpickerSearch").trigger("focus")})}),piranha.notifications=new Vue({el:"#notification-hub",data:{items:[]},methods:{unauthorized:function(){this.push({type:"danger",body:"Request sender could not be verified by the server.",hide:!0})},push:function(e){e.style={visible:!1,"notification-info":"info"===e.type,"notification-danger":"danger"===e.type,"notification-success":"success"===e.type,"notification-warning":"warning"===e.type},piranha.notifications.items.push(e),setTimeout(function(){e.style.visible=!0,e.hide&&setTimeout(function(){e.style.visible=!1,setTimeout(function(){piranha.notifications.items.shift()},200)},5e3)},200)}}}),piranha.contentpicker=new Vue({el:"#contentpicker",data:{search:"",groups:[],items:[],currentGroupId:null,currentGroupTitle:null,currentGroupIcon:null,filter:null,callback:null},computed:{filteredItems:function(){var e=this;return this.items.filter(function(t){return!(e.search.length>0)||t.title.toLowerCase().indexOf(e.search.toLowerCase())>-1})}},methods:{bind:function(e,t){this.currentGroupId=e.group.id,this.currentGroupTitle=e.group.title,this.currentGroupIcon=e.group.icon,this.types=e.types,this.items=e.items.map(function(t){var i=e.types.find(function(e){return e.id===t.typeId});return t.type=i.title||t.typeId,t}),t||(this.groups=e.groups)},load:function(e,t){var i=piranha.baseUrl+"manager/api/content/"+(e?e+"/":"")+"list",n=this;fetch(i).then(function(e){return e.json()}).then(function(e){n.bind(e,t)}).catch(function(e){console.log("error:",e)})},loadGroups:function(){},refresh:function(){this.load(piranha.contentpicker.currentGroupId,!0)},open:function(e,t){this.search="",this.callback=t,this.load(e),$("#contentpicker").modal("show")},onEnter:function(){1==this.filteredItems.length&&this.select(this.filteredItems[0])},select:function(e){this.callback(JSON.parse(JSON.stringify(e))),this.callback=null,this.search="",$("#contentpicker").modal("hide")}}}),$(document).ready(function(){$("#contentpicker").on("shown.bs.modal",function(){$("#contentpickerSearch").trigger("focus")})}),piranha.mediapicker=new Vue({el:"#mediapicker",data:{search:"",folderName:"",listView:!0,currentFolderId:null,parentFolderId:null,currentDocumentFolderId:null,parentDocumentFolderId:null,currentImageFolderId:null,parentImageFolderId:null,currentVideoFolderId:null,parentVideoFolderId:null,currentFolderBreadcrumb:null,folders:[],items:[],folder:{name:null},filter:null,callback:null,dropzone:null},computed:{filteredFolders:function(){return this.folders.filter(function(e){return!(piranha.mediapicker.search.length>0)||e.name.toLowerCase().indexOf(piranha.mediapicker.search.toLowerCase())>-1})},filteredItems:function(){return this.items.filter(function(e){return!(piranha.mediapicker.search.length>0)||e.filename.toLowerCase().indexOf(piranha.mediapicker.search.toLowerCase())>-1})}},methods:{toggle:function(){this.listView=!this.listView},load:function(e){var t=this,i=piranha.baseUrl+"manager/api/media/list"+(e?"/"+e:"")+"/?width=210&height=160";t.filter&&(i+="&filter="+t.filter),fetch(i).then(function(e){return e.json()}).then(function(e){if(t.currentFolderId=e.currentFolderId,t.parentFolderId=e.parentFolderId,t.folders=e.folders,t.items=e.media,t.listView="list"===e.viewMode,t.search="",t.currentFolderBreadcrumb=e.currentFolderBreadcrumb,t.filter)switch(t.filter.toLowerCase()){case"document":t.currentDocumentFolderId=e.currentFolderId,t.parentDocumentFolderId=e.parentFolderId;break;case"image":t.currentImageFolderId=e.currentFolderId,t.parentImageFolderId=e.parentFolderId;break;case"video":t.currentVideoFolderId=e.currentFolderId,t.parentVideoFolderId=e.parentFolderId}}).catch(function(e){console.log("error:",e)})},getThumbnailUrl:function(e){return null!==e.altVersionUrl?e.altVersionUrl:piranha.baseUrl+"manager/api/media/url/"+e.id+"/210/160"},refresh:function(){piranha.mediapicker.load(piranha.mediapicker.currentFolderId)},open:function(e,t,i){this.search="",this.callback=e,this.filter=t,this.load(i),$("#mediapicker").modal("show")},openCurrentFolder:function(e,t){this.callback=e,this.filter=t;var i=this.currentFolderId;if(t)switch(t.toLowerCase()){case"document":i=this.currentDocumentFolderId?this.currentDocumentFolderId:i;break;case"image":i=this.currentImageFolderId?this.currentImageFolderId:i;break;case"video":i=this.currentVideoFolderId?this.currentVideoFolderId:i}this.load(i),$("#mediapicker").modal("show")},onEnter:function(){0===this.filteredItems.length&&1===this.filteredFolders.length&&(this.load(this.filteredFolders[0].id),this.search=""),1===this.filteredItems.length&&0===this.filteredFolders.length&&this.select(this.filteredItems[0])},select:function(e){this.callback(JSON.parse(JSON.stringify(e))),this.callback=null,this.search="",$("#mediapicker").modal("hide")},savefolder:function(){var e=this;""!==e.folderName&&fetch(piranha.baseUrl+"manager/api/media/folder/save"+(e.filter?"?filter="+e.filter:""),{method:"post",headers:piranha.utils.antiForgeryHeaders(),body:JSON.stringify({parentId:e.currentFolderId,name:e.folderName})}).then(function(e){return e.json()}).then(function(t){"success"===t.status.type&&(e.folderName=null,e.folders=t.folders,e.items=t.media),400!==t.status?piranha.notifications.push(t.status):piranha.notifications.unauthorized()}).catch(function(e){console.log("error:",e)})}},mounted:function(){var e=this;piranha.permissions.load(function(){piranha.permissions.media.add&&(e.dropzone=piranha.dropzone.init("#mediapicker-upload-container"),e.dropzone.on("complete",function(t){"success"===t.status&&setTimeout(function(){e.dropzone.removeFile(t)},3e3)}),e.dropzone.on("queuecomplete",function(){piranha.mediapicker.refresh()}))})}}),$(document).ready(function(){$("#mediapicker").on("shown.bs.modal",function(){$("#mediapickerSearch").trigger("focus")})}),piranha.pagepicker=new Vue({el:"#pagepicker",data:{search:"",sites:[],items:[],currentSiteId:null,currentSiteTitle:null,filter:null,callback:null},computed:{filteredItems:function(){if(this.search&&this.search.length<1)return this.items;let e=Object.assign([],this.items),t=this.search?this.search.toLowerCase():"",i=function(e){return e.reduce(function(e,n){let r=Object.assign({},n);return r.items&&(r.items=i(n.items),r.isExpanded=r.items.length>0),r.title&&(r.title.toLowerCase().indexOf(t)>-1||r.isExpanded)&&e.push(r),e},[])};return i(e)}},methods:{load:function(e){var t=piranha.baseUrl+"manager/api/page/sitemap"+(e?"/"+e:""),i=this;fetch(t).then(function(e){return e.json()}).then(function(e){i.currentSiteId=e.siteId,i.currentSiteTitle=e.siteTitle,i.sites=e.sites,i.items=e.items}).catch(function(e){console.log("error:",e)})},refresh:function(){this.load(piranha.pagepicker.currentSiteId)},open:function(e,t){this.search="",this.callback=e,this.load(t),$("#pagepicker").modal("show")},onEnter:function(){1==this.filteredItems.length&&this.select(this.filteredItems[0])},select:function(e){this.callback(JSON.parse(JSON.stringify(e))),this.callback=null,this.search="",$("#pagepicker").modal("hide")}}}),$(document).ready(function(){$("#pagepicker").on("shown.bs.modal",function(){$("#pagepickerSearch").trigger("focus")})}),piranha.postpicker=new Vue({el:"#postpicker",data:{search:"",sites:[],archives:[],posts:[],currentSiteId:null,currentArchiveId:null,currentSiteTitle:null,currentArchiveTitle:null,filter:null,callback:null},computed:{filteredPosts:function(){return this.posts.filter(function(e){return!(piranha.postpicker.search.length>0)||e.title.toLowerCase().indexOf(piranha.postpicker.search.toLowerCase())>-1})}},methods:{load:function(e,t){var i=piranha.baseUrl+"manager/api/post/modal";e&&(i+="?siteId="+e,t&&(i+="&archiveId="+t)),fetch(i).then(function(e){return e.json()}).then(function(e){piranha.postpicker.sites=e.sites,piranha.postpicker.archives=e.archives,piranha.postpicker.posts=e.posts,piranha.postpicker.currentSiteId=e.siteId,piranha.postpicker.currentArchiveId=e.archiveId,piranha.postpicker.currentSiteTitle=e.siteTitle,piranha.postpicker.currentArchiveTitle=e.archiveTitle}).catch(function(e){console.log("error:",e)})},refresh:function(){this.load(this.currentSiteId,this.currentArchiveId)},open:function(e,t,i,n){this.search="",this.callback=e,this.load(t,i),$("#postpicker").modal("show")},onEnter:function(){1==this.filteredPosts.length&&this.select(this.filteredPosts[0])},select:function(e){this.callback(JSON.parse(JSON.stringify(e))),this.callback=null,this.search="",$("#postpicker").modal("hide")}}}),$(document).ready(function(){$("#postpicker").on("shown.bs.modal",function(){$("#postpickerSearch").trigger("focus")})}),piranha.preview=new Vue({el:"#previewModal",data:{empty:{filename:null,type:null,contentType:null,publicUrl:null,size:null,width:null,height:null,title:null,altText:null,description:null,lastModified:null},media:null,dropzone:null},methods:{openItem:function(e){piranha.preview.media=e,piranha.preview.show()},open:function(e){piranha.preview.load(e),piranha.preview.show()},load:function(e){var t=this;fetch(piranha.baseUrl+"manager/api/media/"+e).then(function(e){return e.json()}).then(function(e){t.media=e}).catch(function(e){console.log("error:",e)})},saveMeta:function(e){var t=this,i={id:e.id,title:e.title,altText:e.altText,description:e.description,properties:e.properties};fetch(piranha.baseUrl+"manager/api/media/meta/save",{method:"post",headers:piranha.utils.antiForgeryHeaders(),body:JSON.stringify(i)}).then(function(e){return e.json()}).then(function(e){piranha.notifications.push(e),"success"===e.type&&t.close()}).catch(function(e){console.log("error:",e)})},show:function(){$("#previewModal").modal("show")},close:function(){$("#previewModal").modal("hide"),setTimeout(function(){piranha.preview.clear()},300)},clear:function(){this.media=this.empty}},created:function(){this.clear()},mounted:function(){this.dropzone=piranha.dropzone.init("#media-update-container",{uploadMultiple:!1}),this.dropzone.on("complete",function(e){setTimeout(function(){piranha.preview.dropzone.removeFile(e)},3e3)}),this.dropzone.on("queuecomplete",function(){piranha.preview.load(piranha.preview.media.id),piranha.media.refresh()})}}),piranha.languageedit=new Vue({el:"#languageedit",data:{loading:!0,items:[],originalDefault:null,currentDefault:null,showDefaultInfo:!1,currentDelete:null,showDeleteInfo:!1},methods:{bind:function(e){for(var t=0;t\n
\n \n
\n {{ item.typeName }}\n
\n
\n
    \n \n \n
\n\n'}); \ No newline at end of file diff --git a/core/Piranha.Manager/assets/src/js/piranha.pagepicker.js b/core/Piranha.Manager/assets/src/js/piranha.pagepicker.js index 9e6a23676..b98123690 100644 --- a/core/Piranha.Manager/assets/src/js/piranha.pagepicker.js +++ b/core/Piranha.Manager/assets/src/js/piranha.pagepicker.js @@ -17,11 +17,12 @@ piranha.pagepicker = new Vue({ filteredItems: function () { let self = this; - if (self.search.length < 1) - return this.items; + if (self.search && self.search.length < 1) { + return this.items; + } let items = Object.assign([], this.items); - let searchTerm = self.search ? self.search.toLowerCase() : ''; + let searchTerm = self.search ? self.search.toLowerCase() : ""; let filterRecursive = function(arr) { return arr.reduce(function(acc, item){