File: D:/HostingSpaces/SBogers47/leden.ehbocranendonck.nl/wwwroot/js/kms/core.js
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i<t.length;i++){var a=t[i];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function _createClass(e,t,i){return t&&_defineProperties(e.prototype,t),i&&_defineProperties(e,i),e}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function processSelectedFile(e,t){var i=$("#"+t).parent().parent().scope();i.block.image=e,i.$apply()}function initiateTinyMceWithDelay(e,t,i){t(function(){initiateTinyMce(e,e.textBoxId),void 0!==e.textBoxIds&&(null!=e.textBoxIds.left&&initiateTinyMce(e,e.textBoxIds.left,"description","left"),null!=e.textBoxIds.right&&initiateTinyMce(e,e.textBoxIds.right,"description","right"))},i)}function initiateTinyMce(e,t,i,a){void 0===t&&(t=e.textboxId),void 0===i&&(i="description"),tinymce.init({elements:t,mode:"exact",skin:"kms",menubar:!1,statusbar:!1,plugins:["code","paste","link","table"],toolbar:"styleselect | bold italic underline | bullist numlist | indent | link | code",height:"200",default_link_target:"_blank",paste_as_text:!0,style_formats:[{title:"Titel 1",block:"h1"},{title:"Titel 2",block:"h2"},{title:"Titel 3",block:"h3"},{title:"Titel 4",block:"h4"}],convert_urls:!1,setup:function(t){t.on("change",function(n){t.save(),void 0===a?e.block[i]=t.getContent():e.block[i][a]=t.getContent(),e.$$phase||e.$apply()}),t.on("KeyUp",function(n){t.save(),void 0===a?e.block[i]=t.getContent():e.block[i][a]=t.getContent(),e.$$phase||e.$apply()})}})}function startToMove(){$(document).find("textarea").each(function(){tinyMCE.execCommand("mceFocus",!1,$(this).attr("id")),tinyMCE.execCommand("mceRemoveEditor",!1,$(this).attr("id"))})}function stopToMove(){setTimeout(function(){$(document).find("textarea").each(function(){tinymce.execCommand("mceAddEditor",!0,$(this).attr("id"))})},100)}function getBlockTypes(e){var t={two_column_block:{typeSlug:"two-column-block",code_name:"",view:"",typeName:"Twee tekstkolommen",status:!0,description:{left:"",right:""},textWidth:"50"},content_block:{typeSlug:"content-block",code_name:"",view:"",typeName:"Afbeelding en tekst",status:!0,location:"left",textWidth:"66",description:"",subFolder:"dynamic",image:null,link:"",link_text:"Lees meer"},view_block:{typeSlug:"view-block",code_name:"",view:"",typeName:"View",status:!0},full_image_block:{typeSlug:"full-image-block",code_name:"",view:"",typeName:"100% Afbeelding",subFolder:"dynamic",max_images:1,status:!0,image:null},full_text_block:{typeSlug:"full-text-block",code_name:"",view:"",typeName:"Een tekstkolom",description:"",status:!0,link:"",link_text:"Lees meer"},multiple_images_block:{typeSlug:"multiple-images-block",code_name:"",view:"",typeName:"Meerdere afbeeldingen",tab:[{title:"Afbeelding 1",max_images:1},{title:"Afbeelding 2a",max_images:2},{title:"Afbeelding 2b (optioneel)",max_images:1}],status:!0,location:"left",subFolder:"dynamic",textWidth:"66"},page_link_block:{typeSlug:"page-link-block",code_name:"",view:"",typeName:"Page-link block",link_text:"Lees meer",special:0,status:!0,pageId:null},image_slider_block:{typeSlug:"image-slider-block",code_name:"",view:"",typeName:"Image gallery",tab:[{title:""}],subFolder:"dynamic",status:!0,pageId:null},video_block:{typeSlug:"video-block",code_name:"",view:"",typeName:"Video",youtube:"",status:!0,pageId:null},file_block:{typeSlug:"file-block",code_name:"",view:"",typeName:"Bestand block",title:"",special:0,download_text:"Download",file:"",status:!0,pageId:null}},i={};return angular.forEach(e,function(e,a){i[a]=angular.merge(t[a],e)}),i}(app=angular.module("fileUpload",["ngFileUpload"])).controller("fileUploadController",["$scope","Upload","$timeout",function(e,t,i){console.log("fileuploadcontroller loading"),e.files=[],e.dynamic=!1,e.uploadSizes="",e.maxImages,e.errorMsg={},e.subFolder=!1,e.attributeKey="",e.forModel,e.forModelId,e.canUploadNewImage,e.uploadFiles=function(a,n,l,o,s){console.log("upload for block with blockId: "+o+" and tabKey: "+s),console.log("uploadedFiles files:"),console.log(a);var r=document.querySelector("[ng-controller=KmsAttributeDynamicController]");if(e.forModel=r.dataset.forModel,e.forModelId=r.dataset.forModelId,console.log("fileUploadController uploading files For model: "+e.forModel+" with id: "+e.forModelId+" and blockId: "+o),void 0===e.files&&(e.files=[]),e.files.length>=l)return console.log("File upload not allowed. "+e.files.length+"/"+l+" uploaded"),!1;e.errFiles=n,angular.forEach(a,function(a){var n={loading:!0,thumb_image_url:"/images/kms/loading.gif"};e.files.push(n);var l=e.files.length-1;a.upload=t.upload({url:"/kms/upload",data:{file:a,uploadSizes:e.uploadSizes,dynamic:e.dynamic,subFolder:e.subFolder,attribute_key:e.attributeKey,forModelName:e.forModel,forModelId:e.forModelId,forBlockId:o,forTabId:s}}),a.upload.then(function(t){i(function(){console.log(t),console.log("Image Id: "+t.data.uploaded[0].id),e.files[l]=t.data.uploaded[0],console.log("$scope.files["+l+"] ="),console.log(e.files[l]);var i=t.data.uploaded[0].forBlockId,a=e.getBlocksData();for(var n in a)if(console.log("Looping over blocks to find a block with id: "+i+". Current block id: "+a[n].blockId),!1!==a.hasOwnProperty(n)&&!1!==a[n].hasOwnProperty("blockId")){if(a[n].blockId==i){console.log("found block with id: "+i);var o=[];t.data.uploaded[0].forTabId?(console.log("Uploaded an image for tab: "+t.data.uploaded[0].forTabId),o=t.data.uploaded[0].id+"#"+t.data.uploaded[0].forTabId):(console.log("Uploaded an image without tab: "+t.data.uploaded[0].id),o=t.data.uploaded[0].id);if(a[n].hasOwnProperty("fileIds")){var s=a[n].fileIds.length;a[n].fileIds[s]=o,console.log("Updating fileIds with image id: "+o)}else console.log("Setting fileIds to a new array with image id: "+o),a[n].fileIds=[o];console.log("files.length = "+a[n].fileIds.length+" maxImages = "+e.maxImages),e.canUploadNewImage=a[n].fileIds.length<e.maxImages}e.setBlocksData(a)}else console.warn("Detected block data without a block id. Because of this, it is not possible to upload a file for that block. This does not mean that the uploaded image can be linked to the block your uploading currently for")})},function(t){t.status>0&&(e.errorMsg=t.status+": "+t.data),console.error("Error: "+e.errorMsg)},function(e){a.progress=Math.min(100,parseInt(100*e.loaded/e.total))})})},e.deleteImage=function(t,i,a){var n=e.files[t].id;console.log("idToDelete: "+n+" from blockId: "+i),e.files.splice(t,1),console.log("Current image amount: "+e.files.length);var l=e.getBlocksData();for(var o in l)if(!1!==l.hasOwnProperty(o)&&!1!==l[o].hasOwnProperty("blockId")){if(l[o].blockId==i)for(var t in console.log("found block with id: "+i),!1===l[o].hasOwnProperty("fileIdsToDelete")&&(l[o].fileIdsToDelete=[]),console.log("Current files to delete: "+l[o].fileIdsToDelete),n=void 0!==a?n+"#"+a:n,l[o].fileIds){var s=l[o].fileIds[t];if(void 0!==a?console.log("Looping over the file ids to find an image with id: "+n+" for tab: "+a+" ("+s+")"):console.log("Looping over the file ids to find an image with id: "+n),s==n){if(console.log("Image marked to delete on save: "+n),l[o].fileIdsToDelete[l[o].fileIdsToDelete.length]=n,l[o].fileIds.splice(t,1),void 0===a)e.canUploadNewImage=l[o].fileIds.length<e.maxImages;else{var r=0;for(var t in l[o].fileIds)l[o].fileIds[t].split("#")[1]==a&&r++;e.canUploadNewImage=r<e.maxImages}break}}}else console.warn("Detected block data without a block id. Because of this, it is not possible to upload a file for that block. This does not mean that the uploaded image can be linked to the block your uploading currently for");e.setBlocksData(l),delete e.errorMsg.toMany},e.initFiles=function(t,i,a){if(console.log("fileupload:initFiles: "+t+" maxImages: "+i),t){var n=[];if(void 0!==a)for(var l in t){var o=t[l].split("#");2===o.length&&(o[1]!=a?console.log("fileupload:initFiles: Ignoring image with id: "+o[0]+" because it belongs to tab "+o[1]+" and we are processing images for tab "+a):n[n.length]=t[l])}else n=t;n.length>0?$.ajax({type:"POST",url:"/kms/getimagedata",data:{fileIds:n},success:function(t){console.log("Retrieved files: "),console.log(t),e.files=t,void 0!==i&&(e.maxImages=i),console.log("files.length < $scope.maxImages: "+n.length<e.maxImages),e.canUploadNewImage=n.length<e.maxImages,e.$apply()},error:function(){console.log("An error occured while retrieving image(s)")},headers:{"X-CSRF-TOKEN":$('meta[name="csrf-token"]').attr("content")},dataType:"json"}):(e.maxImages=i,e.canUploadNewImage=!0,e.files=[])}else e.maxImages=i,e.canUploadNewImage=!0,e.files=[]},e.updateFiles=function(t){console.log("Updated files"),e.files=t},e.sortableOptions={update:function(t,i){i.item.sortable.cancel();var a=i.item.sortable.index,n=i.item.sortable.dropindex,l=e.files[a];e.files[a]=e.files[n],e.files[n]=l,e.setFileIds()}},console.log("fileuploadcontroller initialized")}]),angular.element(document).ready(function(){}),angular.module("kms.dynamic-attribute",[]).controller("KmsAttributeDynamicController",function(e,t,i,a){var n=$(t)[0];e.forModel=n.dataset.forModel,e.forModelId=n.dataset.forModelId,e.key=n.dataset.key;e.blocks=[];var l=$("#"+e.key+"_data",t).html();""!=l&&'""'!=l&&null!=l&&(e.blocks=JSON.parse(l)),e.blockSettings={};var o=document.getElementById("blockSettings");if(o){var s=o.value;""!=s&&'""'!=s&&(e.blockSettings=JSON.parse(s))}e.blockTypes=getBlockTypes(e.blockSettings),e.addBlock=function(t){angular.isUndefined(t)||e.blocks.push(angular.copy(t))},e.removeBlock=function(t){startToMove();var i=e.blocks.indexOf(t);e.blocks.splice(i,1),stopToMove()},e.upBlock=function(t){var i=e.blocks.indexOf(t);i<1||(startToMove(),e.blocks[i]=e.blocks[i-1],e.blocks[i-1]=t,stopToMove())},e.downBlock=function(t){var i=e.blocks.indexOf(t);i>=e.blocks.length-1||(startToMove(),e.blocks[i]=e.blocks[i+1],e.blocks[i+1]=t,stopToMove())},e.deleteImage=function(t,i,a,n){null==n?e.blocks[i].images.splice(a,1):e.blocks[i].tab[n].images.splice(a,1)},e.deleteFile=function(t){delete e.blocks[t].file},e.changeOrder=function(t,i,a,n){var l=a;if(null==n){var o=e.blocks[i].images[a];switch(t){case"left":if(0==l)return;e.blocks[i].images[a]=e.blocks[i].images[a-1],e.blocks[i].images[a-1]=o;break;case"right":if(l+1==e.blocks[i].images.length)return;e.blocks[i].images[a]=e.blocks[i].images[a+1],e.blocks[i].images[a+1]=o}}else{o=e.blocks[i].tab[n].images[a];switch(t){case"left":if(0==l)return;e.blocks[i].tab[n].images[a]=e.blocks[i].tab[n].images[a-1],e.blocks[i].tab[n].images[a-1]=o;break;case"right":if(l+1==e.blocks[i].tab[n].images.length)return;e.blocks[i].tab[n].images[a]=e.blocks[i].tab[n].images[a+1],e.blocks[i].tab[n].images[a+1]=o}}},e.addImageTab=function(t){e.blocks[t].tab.push({title:""});var i=e.blocks[t].tab.length;e.setActiveTab(t,i-1)},e.removeImageTab=function(t,i){e.blocks[t].tab.splice(i,1),e.setActiveTab(t,0)},e.setActiveTab=function(t,i){e.blocks[t].active_tab=i},e.moveTab=function(t,i,a){var n=e.blocks[i].tab[a];switch(t){case"left":if(0==a)return;e.blocks[i].tab[a]=e.blocks[i].tab[a-1],e.blocks[i].tab[a-1]=n;break;case"right":if(a+1==e.blocks[i].tab.length)return;e.blocks[i].tab[a]=e.blocks[i].tab[a+1],e.blocks[i].tab[a+1]=n}},e.setUniqueId=function(t){if(void 0===e.blocks[t].blockId){var i=(new Date).valueOf();e.blocks[t].blockId=Math.round(i+1e3*Math.random())}},e.debug=function(){}}).directive("block",function(e){return{restrict:"E",template:'<div class="header"><div class="start"><div class="block-title">{{block.typeName}}</div><div class="buttons"><div class="position-button up" ng-click="upBlock(block)"></div><div class="position-button down" ng-click="downBlock(block)"></div></div></div><div class="end"><div class="btn btn-danger btn-trash" ng-click="removeBlock(block)"> </div></div></div>',link:function(t,i,a){switch(t.block.typeSlug){case"content-block":t.imageBoxId=t.key+"-image-box-"+t.$index,t.textBoxId=t.key+"-text-box-"+t.$index,i.append(e("<content-block></content-block>")(t));break;case"view-block":i.append(e("<view-block></view-block>")(t));break;case"page-link-block":i.append(e("<page-link-block></page-link-block>")(t));break;case"image-slider-block":i.append(e("<image-slider-block></image-slider-block>")(t));break;case"video-block":i.append(e("<video-block></video-block>")(t));break;case"file-block":i.append(e("<file-block></file-block>")(t));break;case"two-column-block":t.textBoxIds=[],t.textBoxIds.left=t.key+"-text-box-"+t.$index+"-left",t.textBoxIds.right=t.key+"-text-box-"+t.$index+"-right",i.append(e("<two-column-block></two-column-block>")(t));break;case"full-text-block":t.textBoxId=t.key+"-text-box-"+t.$index,i.append(e("<full-text-block></full-text-block>")(t));break;case"full-image-block":i.append(e("<full-image-block></full-image-block>")(t));break;case"multiple-images-block":i.append(e("<multiple-images-block></multiple-images-block>")(t))}t.dataElement=document.querySelector(a.dataElement),t.getBlocksData=function(){return JSON.parse(t.dataElement.getAttribute("value"))},t.setBlocksData=function(e){t.dataElement.setAttribute("value",JSON.stringify(e))}}}}).directive("contentBlock",function(e){var t=0;return{restrict:"E",templateUrl:"/kms/api/template/dynamic-page-content-block",link:function(i,a,n){i.image="imageHolder",i.loopCount=t,t++,i.loopCount=i.key,initiateTinyMceWithDelay(i,e,100),i.openBox=function(e){$.colorbox({href:"/kms/elfinder/standalonepopup/"+e,fastIframe:!0,iframe:!0,width:"70%",height:"520px"})}}}}).directive("viewBlock",function(e){return{restrict:"E",templateUrl:"/kms/api/template/dynamic-view",link:function(e){}}}).directive("twoColumnBlock",function(e){var t=0;return{restrict:"E",templateUrl:"/kms/api/template/two-column-block",link:function(i,a,n){i.image="imageHolder",i.loopCount=t,t++,i.loopCount=i.key,initiateTinyMceWithDelay(i,e,100),i.openBox=function(e){$.colorbox({href:"/kms/elfinder/standalonepopup/"+e,fastIframe:!0,iframe:!0,width:"70%",height:"520px"})}}}}).directive("imageSliderBlock",function(){return{restrict:"E",templateUrl:"/kms/api/template/dynamic-image-slider-block",link:function(e){}}}).directive("fullImageBlock",function(){return{restrict:"E",templateUrl:"/kms/api/template/dynamic-full-image-block",link:function(e){}}}).directive("fullTextBlock",function(e){return{restrict:"E",templateUrl:"/kms/api/template/dynamic-full-text-block",link:function(t){initiateTinyMceWithDelay(t,e,100)}}}).directive("multipleImagesBlock",function(){return{restrict:"E",templateUrl:"/kms/api/template/dynamic-multiple-images-block",link:function(e){}}}).directive("pageLinkBlock",function(e){return{restrict:"E",templateUrl:"/kms/api/template/dynamic-page-link-block",link:function(t,i,a){t.pages=[],e.get("/kms/api/pages").then(function(e){var i=[];!function e(t){for(var a in t)t[a].title&&i.push({value:t[a].id,label:t[a].title}),e(t[a].children)}(e.data),t.pages=i})}}}).directive("videoBlock",function(){return{restrict:"E",templateUrl:"/kms/api/template/dynamic-video-block",link:function(e){}}}).directive("fileBlock",function(){return{restrict:"E",templateUrl:"/kms/api/template/dynamic-file-block",link:function(e){}}}),document.addEventListener("DOMContentLoaded",function(){new TabsController("tab-content","entity-tabs","active",!0,'input[name="tabslug"]');for(var e=document.querySelectorAll(".confirm"),t=e.length,i=0;i<t;i++){var a=e[i];new ConfirmationController(a)}new PreventNavigationController(document.querySelector(".entity-attributes"))});var app,attributes={};(app=angular.module("kms",["ui.bootstrap","ngSanitize","kms.dynamic-attribute","fileUpload"])).controller("KmsEntities",["$scope","$element",function(e,t){e.entities=[],e.paginatedEntities=[],e.isSorting=!1,e.isSearching=function(){return e.searchEntitiesText.text.length>1},e.currentPage=1,e.numPerPage=5,e.maxSize=5;for(var i=$(".entities-list-items .entities-list-item",t),a=0;a<i.length;a++){var n=i[a],l={thumbHtml:$(".entities-item-pre",n).html(),text:$(".entities-item-text",n).html(),status:$(".entities-item-status",n).html(),link:$("a",n).first().attr("href"),active:$(n).hasClass("active")};e.entities.push(l)}e.activateSorting=function(){e.isSorting=!0},e.deactivateSorting=function(){e.isSorting=!1},e.$watch("currentPage + numPerPage",function(){var t=(e.currentPage-1)*e.numPerPage,i=t+e.numPerPage;e.paginatedEntities=e.entities.slice(t,i)})}]),app.controller("KmsEntity",["$scope","$element",function(e,t){e.save=function(){document.querySelector('input[value="submit-cloaked"]').click()}}]),app.controller("SortableTree",["$scope","$http","$attrs",function(e,t,i){t.defaults.headers.post["Content-Type"]="application/x-www-form-urlencoded",e.data=[],e.treeOptions={dropped:function(a){t({method:"POST",url:"/kms/api/"+i.siteslug+"/"+i.slug,data:{tree:angular.toJson(e.data)}}).then(function(e){})}},e.openLink=function(t){window.location=e.url+"/"+t},e.toggle=function(e){e.toggle()};var a=function(){return angular.element(document.getElementById("tree-root").scope())};e.collapseAll=function(){a().collapseAll()},e.expandAll=function(){a().expandAll()},t.get("/kms/api/"+i.siteslug+"/"+i.slug).then(function(t){e.data=t.data[0].children})}]),app.controller("KmsAttributes",["$scope",function(e){e.attributes=attributes,e.parse=function(e){if(e)return"object"==_typeof(e)?(console.log("Parse value: "+e),e):(console.log("Parse string to Json: "+JSON.parse(e)),JSON.parse(e));console.log("Parse without a value")},e.convertToSlug=function(e){e=(e=e.replace(/^\s+|\s+$/g,"")).toLowerCase();for(var t="ãàáäâẽèéëêìíïîõòóöôùúüûñç·/_,:;",i=0,a=t.length;i<a;i++)e=e.replace(new RegExp(t.charAt(i),"g"),"aaaaaeeeeeiiiiooooouuuunc------".charAt(i));return e=e.replace(/[^a-z0-9 -]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-")}}]),app.controller("KmsAttributeTextFieldController",["$scope","$element",function(e,t){e.attributes=attributes}]),app.controller("KmsAttributePasswordController",["$scope","$element",function(e,t){e.attributes=attributes,e.enabler=!0,$(".passwordField",t).attr("type","hidden"),e.enablePasswordField=function(){$(".passwordField",t).attr("type","password"),e.enabler=!1}}]),app.controller("KmsAttributeDateController",["$scope","$element",function(e,t){e.attributes=attributes,$("input[ui-date]",t).datepicker({changeYear:!0,changeMonth:!0,firstDay:1,dateFormat:"dd-mm-yy"})}]),app.controller("KmsAttributeCurrencyFieldController",["$scope","$element","$locale",function(e,t,i){e.attributes=attributes,e.initCurrencyField=function(t,a){void 0!==a&&(i.NUMBER_FORMATS.CURRENCY_SYM=a),attributes[e.modelString]={value:t/100,dec_value:t},e.$watch("attributes."+e.modelString+".value",function(t,i){t!==i&&(attributes[e.modelString].dec_value=100*t)})}}]),app.controller("KmsAttributePercentageFieldController",["$scope","$element","$timeout",function(e,t,i){e.attributes=attributes}]),app.controller("KmsAttributeTextFieldCurrencyController",["$scope","$element","$timeout",function(e,t,i){e.attributes=attributes;var a=$("input",t).attr("id"),n=$("[data-kms-tax-field]",t).attr("data-kms-tax-field"),l=a+"_tax",o=a+"_no_tax",s=function(e){var t=e.toString();return t=(t=(t=t.replace(/[.]/g,"")).replace(/[,]/g,".")).replace(/[^0-9\.]+/g,""),t*=100};e.$watch("attributes."+l,function(t,i){t!==i&&(e.attributes[a]=s(t))}),e.$watch("attributes."+o,function(t,i){t!==i&&(e.attributes[a]=Math.round(function(e){if(attributes[n].selected)return e*(1+attributes[n].selected.fullValue.rate/100)}(s(t))))});var r=function(t,i){if($.isNumeric(e.attributes[a])){var s=$("#"+l),r=$("#"+o);s.is(":focus")||s.val(e.attributes[a]/100),r.is(":focus")||r.val(Math.round(function(e){if(attributes[n].selected)return e/(1+attributes[n].selected.fullValue.rate/100)}(e.attributes[a]))/100)}};$("#"+l+", #"+o).blur(function(t){0==e.attributes[a]&&$("#"+l+", #"+o).val(0)}),e.$watch("attributes."+a,r),e.$watch("attributes."+n+".selected",r),e.attributes[a]=$("input",t).attr("value"),i(r,500)}]),app.controller("KmsAttributeMultiSelectController",["$scope","$element",function(e,t){e.attributes=attributes,e.selectData=[],e.initChoices=function(t){if(t)return"object"!=_typeof(t)&&(t=JSON.parse(t)),e.selectData=t,t},e.setValue=function(t){if(t){for(var i=[],a=0;a<e.selectData.length;a++){for(var n=!1,l=0;l<t.length;l++)if(e.selectData[a].value==t[l]){n=!0;break}n&&i.push(e.selectData[a])}return i}}}]),app.controller("KmsAttributeSlugController",["$scope","$element",function(e,t){e.attributes=attributes;var i=$("[data-kms-slug-field]",t).attr("data-kms-slug-field");i=i.replace("[[itemCounter]]",e.itemCounter),e.$watch("attributes."+i,function(t,a){t!==a&&(attributes[e.modelString]=e.convertToSlug(attributes[i]))})}]),app.controller("KmsAttributeFieldGroupController",["$scope","$element",function(e,t){e.number=0,e.itemKey=1,e.maxFieldGroups=null,e.getNumber=function(){return new Array(e.number)},e.addRow=function(){e.itemKey>=e.maxFieldGroups||(e.itemKey++,e.number++)},e.init=function(t,i){e.itemKey=t,e.maxFieldGroups=i,0==t&&e.addRow()}}]),app.controller("KmsAttributeRouteController",["$scope","$element",function(e,t){e.attributes=attributes;var i=$("input",t).attr("id");attributes[i]=$("input",t).attr("value");var a=$("[data-kms-slug-field]",t).attr("data-kms-slug-field");a=a.replace("[[itemCounter]]",e.itemCounter);var n=$("[data-kms-parent-field]",t).attr("data-kms-parent-field"),l=$("[data-kms-language-id]",t).attr("data-kms-language-id"),o=$("[data-kms-structure]",t).attr("data-kms-structure"),s=function(t,i){if(t!==i){var a="";attributes[n]&&(attributes[n].selected.routes||console.error("Routes are not set in the "+n+"field"),a=attributes[n].selected.routes[l]);var s="";s=(s=o.replace("{{parentSlugs}}",a)).replace("{{slug}}",e.convertToSlug(t)),attributes[e.modelString]=s}};e.$watch("attributes."+a,s),attributes[n]&&e.$watch("attributes."+n+".selected",s)}]),app.controller("KmsAttributeSorterController",["$scope","$element",function(e,t){e.attributes=attributes}]),app.filter("multiWordFilter",["$filter",function(e){return console.log("hoi"),function(t,i){for(var a=i?i.toLowerCase().split(/\s+/):[],n=a.length,l=0;l<n;l++)t=e("filter")(t,{text:a[l]});return t}}]),app.filter("valuesToArrayFilter",function(){return function(e){if(e)return e.map(function(e){return e.value})}}),app.filter("propsFilter",function(){return function(e,t){var i=[];return angular.isArray(e)?e.forEach(function(e){for(var a=!1,n=Object.keys(t),l=0;l<n.length;l++){var o=n[l],s=t[o].toLowerCase();if(-1!==e[o].toString().toLowerCase().indexOf(s)){a=!0;break}}a&&i.push(e)}):i=e,i}});var IsJsonString=function(e){try{JSON.parse(e)}catch(e){return!1}return!0};!function(e){tinymce.init({selector:"textarea.tiny-mce",skin:"kms",menubar:!1,statusbar:!1,plugins:["code","paste","link"],toolbar:"styleselect | bold italic underline | bullist numlist | indent | link image | code",height:"200",paste_as_text:!0,style_formats:[{title:"Titel 1",block:"h1"},{title:"Titel 2",block:"h2"},{title:"Titel 3",block:"h3"},{title:"Titel 4",block:"h4"}],convert_urls:!1}),e(".entities-list-item .dropdown-icon").click(function(t){t.preventDefault(),e(this).parent().parent().hasClass("open")?e(this).parent().parent().removeClass("open"):e(this).parent().parent().addClass("open")});var t=!0;e(window).load(function(){e("#entity-form .lock").hasClass("open")&&(t=!1,e("#entity-form").find("input, textarea").attr("disabled",t));var i=e("#entities .entities-list"),a=e(".entities-list-item.active",i).first();if(0!=a.length){var n=a.position().top;i.scrollTop(n),e(".site-brand-name input").attr("placeholder",e("#global_name").val())}}),e("#global_name").change(function(){e(".site-brand-name input").attr("placeholder",e(this).val())}),e(".error-accordion .collapsible-ul").hide(),e(".error-accordion h3").click(function(){e(this).parent().find(".collapsible-ul").toggle()}),e("#selectYearAndMonthForm select").change(function(){var t="/kms/orders/voltooid?month="+e("#selectYearAndMonthForm select#orderMonthSelector").val()+"&year="+e("#selectYearAndMonthForm select#orderYearSelector").val();window.location=t}),e("#productCategorySelector").change(function(){window.location="/kms/products?category="+encodeURIComponent(this.value)});var i=function(){e("#flash-message").fadeOut()};e("#flash-message").click(function(){i()}),setTimeout(function(){i()},5e3),e("#entity-form .lock").click(function(){e(this).toggleClass("open"),t=!t,e(this).parents("#entity-form").find("input, textarea").attr("disabled",t)});var a=jQuery("#sort_order"),n=(jQuery("#autoSubmit"),jQuery("#message-box"),jQuery(".fieldGroupItems"));n.children("li").each(function(){var e=jQuery(this);e.data("id",e.attr("title")).attr("title","")}),n.sortable({opacity:.7,update:function(){}}),jQuery("#dd-form").bind("submit",function(e){var t,i;e&&e.preventDefault(),t=!0,i=[],n.children("li").each(function(){i.push(jQuery(this).data("id"))}),a.val(i.join(",")),console.log(a.val()),t&&request()})}(jQuery),$(function(){for(var e=$("#sidebar .navigation li.active").parents(),t=e.length,i=0;i<=t;i++){var a=e[i];a&&"LI"==a.tagName&&a.classList.contains("has-sub-items")&&a.classList.add("active")}var n=document.querySelectorAll("#sidebar .navigation .has-sub-items"),l=n.length;for(i=0;i<l;i++){n[i].addEventListener("click",function(){this.classList.toggle("active")})}});var SearchController=function(){function e(t,i,a,n,l){_classCallCheck(this,e),this.apiUrl="",this.data="",this.dataToLoad="",this.editEntitiesUrl="",this.initialized=!1,this.sectionId=t,this.selector=i,this.mainUlId=n,this.resultCounterId=l,this.disabled=!0,this.inputSelector=a,this.listItemClass="entities-list-item",this.visibleClass="active",this.invisibleClass="hide",this.section=document.getElementById(this.sectionId);var o=document.querySelector(this.selector);this.siteSlug=o.dataset.siteSlug,this.slug=o.dataset.slug,this.activeId=o.dataset.activeId,axios.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}return _createClass(e,[{key:"init",value:function(e,t){"string"==typeof e?this.apiUrl=e:this.dataToLoad=e,this.editEntitiesUrl=t,this.initialized=!0}},{key:"load",value:function(){if(!1!==this.initialized){var e=this;return new Promise(function(t,i){!1===e.initialized&&i("Please initialize the controller with the init method first."),""!==e.apiUrl&&""===e.dataToLoad?axios.get(e.apiUrl).then(function(a){a.data&&0!=a.data.length?(a.data.children.forEach(function(t){e.createHtmlElement(t).forEach(function(t){document.querySelector(e.selector).appendChild(t)})}),e.initializeSearch(),t(document.querySelector(e.selector))):i("The searchable did not get any data from the api")}).catch(function(e){i(e)}):""===e.apiUrl&&""!==e.dataToLoad&&(e.dataToLoad.data.children.forEach(function(t){e.createHtmlElement(t).forEach(function(t){document.querySelector(e.selector).appendChild(t)})}),e.initializeSearch(),t(document.querySelector(e.selector)))})}console.error("Please initialize the controller with the init method first.")}},{key:"initializeSearch",value:function(){var e=this,t=this.section,i=document.querySelector(this.inputSelector),a=document.querySelector(this.selector),n=document.getElementById(this.resultCounterId);i.addEventListener("keyup",function(l){for(var o=document.getElementById(e.mainUlId),s=0,r=i.value.toLowerCase(),c=""==r,d=a.querySelectorAll("li"),u=d.length,m=0;m<u;m++){var f=d[m].dataset.title.toLowerCase(),h=JSON.parse(d[m].dataset.model),p=f.indexOf(r)>-1&&!1===c,b=!1;if(!p&&r.length>=3)for(var g in h)if(h.hasOwnProperty(g)&&-1!==String(h[g]).indexOf(r)){b=!0;break}p||b?(s++,d[m].classList.add(e.visibleClass)):d[m].classList.remove(e.visibleClass)}n.innerHTML=s+"",c?(t.classList.remove(e.visibleClass),o.classList.remove(e.invisibleClass)):(t.classList.add(e.visibleClass),o.classList.add(e.invisibleClass))}),a.classList.remove(this.visibleClass)}},{key:"createHtmlElement",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"";if(!1!==this.initialized){var a=this.activeId,n=e.id,l=e.title,o=e.model,s=e.children,r=e.status,c=e.thumbnail,d=i,u=""!==i?i+" | "+l:l,m=[],f=!0,h=!1,p=void 0;try{for(var b,g=s[Symbol.iterator]();!(f=(b=g.next()).done);f=!0){var v=b.value;m.push(this.createHtmlElement(v,t,u))}}catch(e){h=!0,p=e}finally{try{f||null==g.return||g.return()}finally{if(h)throw p}}var k='\n <span class="color-status" data-status-type="'.concat(r,'">\n \n </span>\n '),y='\n <div class="icon" '.concat(c?"style=\"background-image: url('".concat(c,"');\""):""," >\n ").concat(c?"":"<span>".concat(l?l.substring(0,1):"","</span>"),"\n </div>\n "),C='\n <li data-title="'.concat(l,"\" data-model='").concat(JSON.stringify(o)||JSON.stringify({}),"' class=\"").concat(this.listItemClass," ").concat(n==a?"active":"",'"> \n <a href="').concat(this.editEntitiesUrl,"/").concat(n,'">\n ').concat(k,"\n ").concat(y,'\n <p data-breadcrumb="').concat(d,'">').concat(l,"</p>\n </a>\n </li> \n "),I=(new DOMParser).parseFromString(C,"text/html");return t.push(I.body.firstChild),m.length>0&&m.forEach(function(e){t.push(e[0])}),t}console.error("Please initialize the controller with the init method first.")}}]),e}(),SortableController=function(){function e(t){_classCallCheck(this,e),this.apiUrl="",this.editEntitiesUrl="",this.initialized=!1,this.selector=t,this.disabled=!0,this.listItemClass="entities-list-item";var i=document.querySelector(this.selector);this.siteSlug=i.dataset.siteSlug,this.slug=i.dataset.slug,this.activeId=i.dataset.activeId,axios.defaults.headers.common["X-Requested-With"]="XMLHttpRequest"}return _createClass(e,[{key:"init",value:function(e,t){this.apiUrl=e,this.editEntitiesUrl=t,document.querySelectorAll(this.selector+" li ul").forEach(function(e,t){e.style.display="none"!==e.style.display?"none":""}),this.initialized=!0}},{key:"updateSortableJavascript",value:function(){$(".sortable").sortable({connectWith:".sortable",placeholder:"sortable-placeholder",disabled:this.disabled}),document.querySelectorAll(this.selector+" li ul").forEach(function(e,t){})}},{key:"enableSortable",value:function(){!1!==this.initialized?(this.disabled=!1,$(this.selector).sortable({disabled:this.disabled}).addClass("sorting"),this.updateSortableJavascript()):console.error("Please initialize the controller with the init method first.")}},{key:"disableSortable",value:function(){this.disabled=!0,$(this.selector).sortable({disabled:this.disabled}).removeClass("sorting"),this.save()}},{key:"save",value:function(){if(!1!==this.initialized){var e=this.itemsToJson(document.querySelector(this.selector)),t={id:1,routes:{},status:null,thumbnail:!1,title:null,children:e},i={tree:e=JSON.stringify(t)};axios.post(this.apiUrl,i).then(function(e){}).catch(function(e){console.error(e)})}else console.error("Please initialize the controller with the init method first.")}},{key:"itemsToJson",value:function(e){if(!1!==this.initialized){var t=[],i=!1,a=e.querySelectorAll(":scope > li."+this.listItemClass),n=!0,l=!1,o=void 0;try{for(var s,r=a[Symbol.iterator]();!(n=(s=r.next()).done);n=!0){var c=s.value;c.dataset.json||(console.error('One or more li HTMLElements with class "'+this.listItemClass+'" did not have data-json attribute set while it should.'),i=!0);var d=JSON.parse(c.dataset.json),u=c.querySelector("ul");u?(d.children=this.itemsToJson(u),d.children||(i=!0)):d.children=[],t.push(d)}}catch(e){l=!0,o=e}finally{try{n||null==r.return||r.return()}finally{if(l)throw o}}return i?null:t}console.error("Please initialize the controller with the init method first.")}},{key:"load",value:function(){if(!1!==this.initialized)return self=this,new Promise(function(e,t){!1===self.initialized&&t("Please initialize the controller with the init method first."),axios.get(self.apiUrl).then(function(i){if(i.data&&0!=i.data.length){console.log("data"),console.log(i.data);var a=[];i.data.children.forEach(function(e){a.push(self.createHtmlElement(e))}),a.forEach(function(e){document.querySelector(self.selector).appendChild(e)}),self.updateSortableJavascript(),e(document.querySelector(self.selector))}else t("The sortable did not get any data from the api")}).catch(function(e){t(e)})});console.error("Please initialize the controller with the init method first.")}},{key:"clearRootUl",value:function(){if(!1!==this.initialized)for(var e=document.querySelector(this.selector);e.firstChild;)e.removeChild(e.firstChild);else console.error("Please initialize the controller with the init method first.")}},{key:"createHtmlElement",value:function(e){if(!1!==this.initialized){self=this;var t=self.activeId,i=e.id,a=e.title||"-",n=e.thumbnail,l=e.children,o=e.status,s=e.routes,r={};for(var c in s)s.hasOwnProperty(c)&&(r[c]=s[c]);r=={}&&(r=[]);var d={id:e.id,title:e.title,thumbnail:e.thumbnail,routes:r,status:e.status};d=JSON.stringify(d);var u=[],m=!0,f=!1,h=void 0;try{for(var p,b=l[Symbol.iterator]();!(m=(p=b.next()).done);m=!0){var g=p.value;u.push(this.createHtmlElement(g))}}catch(e){f=!0,h=e}finally{try{m||null==b.return||b.return()}finally{if(f)throw h}}var v='\n <span class="color-status" data-status-type="'.concat(o,'">\n \n </span>\n '),k='\n <div class="icon" '.concat(n?"style=\"background-image: url('".concat(n,"');\""):""," >\n ").concat(n?"":"<span>".concat(a?a.substring(0,1):"","</span>"),"\n </div>\n "),y="\n <li data-json='".concat(d,"' class=\"").concat(this.listItemClass," ").concat(i==t?"active":"",'"> \n <a href="').concat(this.editEntitiesUrl,"/").concat(i,'">\n ').concat(v,"\n ").concat(k,"\n <p>").concat(a,"</p>\n </a>\n </li> \n "),C=(new DOMParser).parseFromString(y,"text/html"),I=C.body.firstChild;if(u.length>0){var w=C.createElement("ul");w.className="sortable",u.forEach(function(e){w.appendChild(e)}),I.appendChild(w)}return I}console.error("Please initialize the controller with the init method first.")}}]),e}(),ConfirmationController=function(){function e(t){_classCallCheck(this,e),!1!==this.validateElement(t)?(this.headerText=t.dataset.confirmHeader?t.dataset.confirmHeader:"",this.message=t.dataset.confirmMessage?t.dataset.confirmMessage:"",this.confirmText=t.dataset.confirmConfirmText?t.dataset.confirmConfirmText:"",this.cancelText=t.dataset.confirmCancelText?t.dataset.confirmCancelText:"",this.navigatableElement=t,this.onlyConfirmIfTrueCallback=null,this.confirmCallback=null,this.addListenersToNavigatable(this.navigatableElement)):console.error("The navigatableElement isn't valid. Did not enable the confirmation functionality for that navigatableElement. You passed a \""+t.tagName+'"')}return _createClass(e,[{key:"addListenersToNavigatable",value:function(e){var t;e.addEventListener("click",(t=this,function(i){var a=!1;(t.onlyConfirmIfTrueCallback&&!0===t.onlyConfirmIfTrueCallback.call()||!t.onlyConfirmIfTrueCallback)&&(a=!0),a&&(i.preventDefault(),t.showConfirmationPrompt(!0,e))}))}},{key:"setOnlyConfirmIfTrueCallback",value:function(e){this.onlyConfirmIfTrueCallback=e}},{key:"addListenersToModalButtons",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];arguments.length>1&&arguments[1];this.promptElement||console.error("First create the modal with the createPrompt method");var t=this.promptElement.querySelector("button.confirm"),i=this.promptElement.querySelector("button.cancel"),a=this.promptElement.querySelector("div.shader");t.removeEventListener("click",this.confirmClicked.bind(this)),i.removeEventListener("click",this.cancelClicked.bind(this)),a.removeEventListener("click",this.cancelClicked.bind(this)),e&&(t.addEventListener("click",this.confirmClicked.bind(this)),i.addEventListener("click",this.cancelClicked.bind(this)),a.addEventListener("click",this.cancelClicked.bind(this)))}},{key:"setConfirmCallback",value:function(e){return this.confirmCallback=e,this}},{key:"confirmClicked",value:function(e){e.preventDefault(),this.confirmCallback?this.confirmCallback.call():this.submitNearestForm(!1),this.showConfirmationPrompt(!1)}},{key:"submitNearestForm",value:function(){var e=this.findForm(this.navigatableElement);return e?(e.submit(),!0):(console.error("Could not submit the nearest form this navigatableElement should be in, because it isn't in a form."),!1)}},{key:"cancelClicked",value:function(e){e.preventDefault(),this.showConfirmationPrompt(!1)}},{key:"findForm",value:function(e){return!!e.parentNode&&("FORM"===e.parentNode.tagName?e.parentNode:this.findForm(e.parentNode))}},{key:"createPrompt",value:function(){var e='<div class="modal"><div class="header"><h4>'+this.headerText+'</h4></div><div class="body"><p class="message">'+this.message+'</p><div class="buttons"><button class="confirm">'+this.confirmText+'</button><button class="cancel">'+this.cancelText+'</button></div></div></div></div><div class="shader"></div>',t=document.createElement("div");return t.setAttribute("id","confirmBox"),t.innerHTML=e,t}},{key:"showConfirmationPrompt",value:function(e,t){this.promptElement||(this.promptElement=this.createPrompt(),this.addListenersToModalButtons(!0,t)),e?(this.promptElement.classList.add("show"),document.body.appendChild(this.promptElement)):(this.promptElement.classList.remove("show"),this.promptElement.parentElement&&this.promptElement.parentElement.removeChild(this.promptElement),this.promptElement=null)}},{key:"validateElement",value:function(e){return!!e&&(("BUTTON"===e.tagName||"INPUT"===e.tagName||"A"===e.tagName)&&("INPUT"!==e.tagName||"navigatableElement"===e.getAttribute("type").toLowerCase()||"submit"===e.getAttribute("type").toLowerCase()))}},{key:"setHeaderText",value:function(e){return this.headerText=e,this}},{key:"setMessage",value:function(e){return this.message=e,this}},{key:"setConfirmText",value:function(e){return this.confirmText=e,this}},{key:"setCancelText",value:function(e){return this.cancelText=e,this}}]),e}(),PreventNavigationController=function(){function e(t){_classCallCheck(this,e),this.inputs=[],this.wrapperElement=null,this.translation={headerText:"",message:"",confirmText:"",cancelText:""},this.changed=!1,t?t.dataset.translation?(this.wrapperElement=t,this.loadTranslation(),this.inputs=this.findAllInputsIn(t),this.interceptClicksOnNavigatableElements(),this.addListenersToInputs(this.inputs)):console.warn("No translation present. Not preventing navigation when not all changes have been saved."):console.warn("No wrapper element given. Not preventing navigation.")}return _createClass(e,[{key:"isTrackableElement",value:function(e){return"INPUT"===e.tagName||"SELECT"===e.tagName||"TEXTAREA"===e.tagName}},{key:"addListenersToInputs",value:function(e){for(var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],i=e.length,a=0;a<i;a++)t?e[a].addEventListener("change",this.inputChanged.bind(this)):e[a].removeEventListener("change",this.inputChanged.bind(this))}},{key:"inputChanged",value:function(e){this.changed=!0,console.log(this.changed)}},{key:"loadTranslation",value:function(){this.translation=JSON.parse(this.wrapperElement.dataset.translation)}},{key:"interceptClicksOnNavigatableElements",value:function(){for(var e=this,t=(!(arguments.length>0&&void 0!==arguments[0])||arguments[0],document.getElementsByTagName("A")),i=t.length,a=function(i){var a,n=t[i],l=n.getAttribute("href");l&&"#"!==l.substr(0,1)&&new ConfirmationController(n).setHeaderText(e.translation.headerText).setMessage(e.translation.message).setConfirmText(e.translation.confirmText).setCancelText(e.translation.cancelText).setConfirmCallback(function(){window.location=l}).setOnlyConfirmIfTrueCallback((a=e,function(){return a.hasChanged()}))},n=0;n<i;n++)a(n)}},{key:"hasChanged",value:function(){return this.changed}},{key:"findAllInputsIn",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],i=e.children.length;if(0===i)return t;for(var a=0;a<i;a++){var n=e.children[a];if(this.isTrackableElement(n)&&t.push(n),n.children.length>0){var l=this.findAllInputsIn(n,t);t.concat(l)}}return t}}]),e}(),TabsController=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"tab",i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:".tab-buttons",a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"active",n=arguments.length>3&&void 0!==arguments[3]&&arguments[3],l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0;_classCallCheck(this,e);document.querySelector(this.tabSlugInputId);this.tabButtonGroupSelector=i,this.tabContentDivsClassAndIdPrefix=t,this.tabSlugInputId=l,this.activeClass=a,this.reactToUrlHashChange=n,this.openTabFromHiddenSlugInput(),n&&this.addListenerForHashChange(n)}return _createClass(e,[{key:"openTabFromHiddenSlugInput",value:function(){if(void 0!==this.tabSlugInputId){var e=document.querySelector(this.tabSlugInputId);e&&this.openTab(e.value)}}},{key:"openTab",value:function(e){(e=this.removeLeftHandSlashInSlug(e))&&(this.updateTabSlugInput(e),this.showTabContentForTabWithSlug(e),this.makeTabButtonActiveForSlug(e))}},{key:"removeLeftHandSlashInSlug",value:function(e){return e.replace(/^\/(.*)/,"$1")}},{key:"updateTabSlugInput",value:function(e){if(void 0!==this.tabSlugInputId){var t=document.querySelector(this.tabSlugInputId);t&&(t.value=e)}}},{key:"makeTabButtonActiveForSlug",value:function(e){$(".entity-tabs >ul >li").removeClass("active"),$('.entity-tabs >ul >li a[href="#'+e+'"]').parent().addClass("active")}},{key:"showTabContentForTabWithSlug",value:function(e){for(var t=document.querySelectorAll("."+this.tabContentDivsClassAndIdPrefix),i=t.length,a=0;a<i;a++){t[a].classList.remove(this.activeClass)}var n=document.querySelector("#"+this.tabContentDivsClassAndIdPrefix+"-"+e);n?n.classList.add(this.activeClass):console.error("TabsController: Could not make content tab active. It should have an ID with: #"+this.tabContentDivsClassAndIdPrefix+"-"+e)}},{key:"addListenerForHashChange",value:function(e){e?(window.addEventListener("hashchange",this.hashChanged.bind(this)),window.addEventListener("load",this.hashChanged.bind(this))):(window.removeEventListener("hashchange",this.hashChanged),window.removeEventListener("load",this.hashChanged))}},{key:"hashChanged",value:function(e){var t=window.location.hash.substring(1);if(t)this.openTab(t);else{var i=document.querySelector(this.tabSlugInputId);i&&this.openTab(i.value)}}}]),e}();