File: D:/HostingSpaces/SBogers47/leden.ehbocranendonck.nl/wwwroot/js/kms/kms.js
"use strict";function processSelectedFile(e,t){var o=$("#"+t).parent().parent().scope();o.block.image=e,o.$apply()}function initiateTinyMceWithDelay(e,t,o){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"))},o)}function initiateTinyMce(e,t,o,l){void 0===t&&(t=e.textboxId),void 0===o&&(o="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(i){t.save(),void 0===l?e.block[o]=t.getContent():e.block[o][l]=t.getContent(),e.$$phase||e.$apply()}),t.on("KeyUp",function(i){t.save(),void 0===l?e.block[o]=t.getContent():e.block[o][l]=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}},o={};return angular.forEach(e,function(e,l){o[l]=angular.merge(t[l],e)}),o}(app=angular.module("fileUpload",["ngFileUpload"])).controller("fileUploadController",["$scope","Upload","$timeout",function(e,t,o){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(l,i,a,n,r){console.log("upload for block with blockId: "+n+" and tabKey: "+r),console.log("uploadedFiles files:"),console.log(l);var s=document.querySelector("[ng-controller=KmsAttributeDynamicController]");if(e.forModel=s.dataset.forModel,e.forModelId=s.dataset.forModelId,console.log("fileUploadController uploading files For model: "+e.forModel+" with id: "+e.forModelId+" and blockId: "+n),void 0===e.files&&(e.files=[]),e.files.length>=a)return console.log("File upload not allowed. "+e.files.length+"/"+a+" uploaded"),!1;e.errFiles=i,angular.forEach(l,function(l){var i={loading:!0,thumb_image_url:"/images/kms/loading.gif"};e.files.push(i);var a=e.files.length-1;l.upload=t.upload({url:"/kms/upload",data:{file:l,uploadSizes:e.uploadSizes,dynamic:e.dynamic,subFolder:e.subFolder,attribute_key:e.attributeKey,forModelName:e.forModel,forModelId:e.forModelId,forBlockId:n,forTabId:r}}),l.upload.then(function(t){o(function(){console.log(t),console.log("Image Id: "+t.data.uploaded[0].id),e.files[a]=t.data.uploaded[0],console.log("$scope.files["+a+"] ="),console.log(e.files[a]);var o=t.data.uploaded[0].forBlockId,l=e.getBlocksData();for(var i in l)if(console.log("Looping over blocks to find a block with id: "+o+". Current block id: "+l[i].blockId),!1!==l.hasOwnProperty(i)&&!1!==l[i].hasOwnProperty("blockId")){if(l[i].blockId==o){console.log("found block with id: "+o);var n=[];t.data.uploaded[0].forTabId?(console.log("Uploaded an image for tab: "+t.data.uploaded[0].forTabId),n=t.data.uploaded[0].id+"#"+t.data.uploaded[0].forTabId):(console.log("Uploaded an image without tab: "+t.data.uploaded[0].id),n=t.data.uploaded[0].id);if(l[i].hasOwnProperty("fileIds")){var r=l[i].fileIds.length;l[i].fileIds[r]=n,console.log("Updating fileIds with image id: "+n)}else console.log("Setting fileIds to a new array with image id: "+n),l[i].fileIds=[n];console.log("files.length = "+l[i].fileIds.length+" maxImages = "+e.maxImages),e.canUploadNewImage=l[i].fileIds.length<e.maxImages}e.setBlocksData(l)}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){l.progress=Math.min(100,parseInt(100*e.loaded/e.total))})})},e.deleteImage=function(t,o,l){var i=e.files[t].id;console.log("idToDelete: "+i+" from blockId: "+o),e.files.splice(t,1),console.log("Current image amount: "+e.files.length);var a=e.getBlocksData();for(var n in a)if(!1!==a.hasOwnProperty(n)&&!1!==a[n].hasOwnProperty("blockId")){if(a[n].blockId==o)for(var t in console.log("found block with id: "+o),!1===a[n].hasOwnProperty("fileIdsToDelete")&&(a[n].fileIdsToDelete=[]),console.log("Current files to delete: "+a[n].fileIdsToDelete),i=void 0!==l?i+"#"+l:i,a[n].fileIds){var r=a[n].fileIds[t];if(void 0!==l?console.log("Looping over the file ids to find an image with id: "+i+" for tab: "+l+" ("+r+")"):console.log("Looping over the file ids to find an image with id: "+i),r==i){if(console.log("Image marked to delete on save: "+i),a[n].fileIdsToDelete[a[n].fileIdsToDelete.length]=i,a[n].fileIds.splice(t,1),void 0===l)e.canUploadNewImage=a[n].fileIds.length<e.maxImages;else{var s=0;for(var t in a[n].fileIds)a[n].fileIds[t].split("#")[1]==l&&s++;e.canUploadNewImage=s<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(a),delete e.errorMsg.toMany},e.initFiles=function(t,o,l){if(console.log("fileupload:initFiles: "+t+" maxImages: "+o),t){var i=[];if(void 0!==l)for(var a in t){var n=t[a].split("#");2===n.length&&(n[1]!=l?console.log("fileupload:initFiles: Ignoring image with id: "+n[0]+" because it belongs to tab "+n[1]+" and we are processing images for tab "+l):i[i.length]=t[a])}else i=t;i.length>0?$.ajax({type:"POST",url:"/kms/getimagedata",data:{fileIds:i},success:function(t){console.log("Retrieved files: "),console.log(t),e.files=t,void 0!==o&&(e.maxImages=o),console.log("files.length < $scope.maxImages: "+i.length<e.maxImages),e.canUploadNewImage=i.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=o,e.canUploadNewImage=!0,e.files=[])}else e.maxImages=o,e.canUploadNewImage=!0,e.files=[]},e.updateFiles=function(t){console.log("Updated files"),e.files=t},e.sortableOptions={update:function(t,o){o.item.sortable.cancel();var l=o.item.sortable.index,i=o.item.sortable.dropindex,a=e.files[l];e.files[l]=e.files[i],e.files[i]=a,e.setFileIds()}},console.log("fileuploadcontroller initialized")}]),angular.element(document).ready(function(){}),angular.module("kms.dynamic-attribute",[]).controller("KmsAttributeDynamicController",function(e,t,o,l){var i=$(t)[0];e.forModel=i.dataset.forModel,e.forModelId=i.dataset.forModelId,e.key=i.dataset.key;e.blocks=[];var a=$("#"+e.key+"_data",t).html();""!=a&&'""'!=a&&null!=a&&(e.blocks=JSON.parse(a)),e.blockSettings={};var n=document.getElementById("blockSettings");if(n){var r=n.value;""!=r&&'""'!=r&&(e.blockSettings=JSON.parse(r))}e.blockTypes=getBlockTypes(e.blockSettings),e.addBlock=function(t){angular.isUndefined(t)||e.blocks.push(angular.copy(t))},e.removeBlock=function(t){startToMove();var o=e.blocks.indexOf(t);e.blocks.splice(o,1),stopToMove()},e.upBlock=function(t){var o=e.blocks.indexOf(t);o<1||(startToMove(),e.blocks[o]=e.blocks[o-1],e.blocks[o-1]=t,stopToMove())},e.downBlock=function(t){var o=e.blocks.indexOf(t);o>=e.blocks.length-1||(startToMove(),e.blocks[o]=e.blocks[o+1],e.blocks[o+1]=t,stopToMove())},e.deleteImage=function(t,o,l,i){null==i?e.blocks[o].images.splice(l,1):e.blocks[o].tab[i].images.splice(l,1)},e.deleteFile=function(t){delete e.blocks[t].file},e.changeOrder=function(t,o,l,i){var a=l;if(null==i){var n=e.blocks[o].images[l];switch(t){case"left":if(0==a)return;e.blocks[o].images[l]=e.blocks[o].images[l-1],e.blocks[o].images[l-1]=n;break;case"right":if(a+1==e.blocks[o].images.length)return;e.blocks[o].images[l]=e.blocks[o].images[l+1],e.blocks[o].images[l+1]=n}}else{n=e.blocks[o].tab[i].images[l];switch(t){case"left":if(0==a)return;e.blocks[o].tab[i].images[l]=e.blocks[o].tab[i].images[l-1],e.blocks[o].tab[i].images[l-1]=n;break;case"right":if(a+1==e.blocks[o].tab[i].images.length)return;e.blocks[o].tab[i].images[l]=e.blocks[o].tab[i].images[l+1],e.blocks[o].tab[i].images[l+1]=n}}},e.addImageTab=function(t){e.blocks[t].tab.push({title:""});var o=e.blocks[t].tab.length;e.setActiveTab(t,o-1)},e.removeImageTab=function(t,o){e.blocks[t].tab.splice(o,1),e.setActiveTab(t,0)},e.setActiveTab=function(t,o){e.blocks[t].active_tab=o},e.moveTab=function(t,o,l){var i=e.blocks[o].tab[l];switch(t){case"left":if(0==l)return;e.blocks[o].tab[l]=e.blocks[o].tab[l-1],e.blocks[o].tab[l-1]=i;break;case"right":if(l+1==e.blocks[o].tab.length)return;e.blocks[o].tab[l]=e.blocks[o].tab[l+1],e.blocks[o].tab[l+1]=i}},e.setUniqueId=function(t){if(void 0===e.blocks[t].blockId){var o=(new Date).valueOf();e.blocks[t].blockId=Math.round(o+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,o,l){switch(t.block.typeSlug){case"content-block":t.imageBoxId=t.key+"-image-box-"+t.$index,t.textBoxId=t.key+"-text-box-"+t.$index,o.append(e("<content-block></content-block>")(t));break;case"view-block":o.append(e("<view-block></view-block>")(t));break;case"page-link-block":o.append(e("<page-link-block></page-link-block>")(t));break;case"image-slider-block":o.append(e("<image-slider-block></image-slider-block>")(t));break;case"video-block":o.append(e("<video-block></video-block>")(t));break;case"file-block":o.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",o.append(e("<two-column-block></two-column-block>")(t));break;case"full-text-block":t.textBoxId=t.key+"-text-box-"+t.$index,o.append(e("<full-text-block></full-text-block>")(t));break;case"full-image-block":o.append(e("<full-image-block></full-image-block>")(t));break;case"multiple-images-block":o.append(e("<multiple-images-block></multiple-images-block>")(t))}t.dataElement=document.querySelector(l.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(o,l,i){o.image="imageHolder",o.loopCount=t,t++,o.loopCount=o.key,initiateTinyMceWithDelay(o,e,100),o.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(o,l,i){o.image="imageHolder",o.loopCount=t,t++,o.loopCount=o.key,initiateTinyMceWithDelay(o,e,100),o.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,o,l){t.pages=[],e.get("/kms/api/pages").then(function(e){var o=[],l=function(e){for(var t in e)e[t].title&&o.push({value:e[t].id,label:e[t].title}),l(e[t].children)};l(e.data),t.pages=o})}}}).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"]');let e=document.querySelectorAll(".confirm"),t=e.length;for(let o=0;o<t;o++){let t=e[o];new ConfirmationController(t)}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 o=$(".entities-list-items .entities-list-item",t),l=0;l<o.length;l++){var i=o[l],a={thumbHtml:$(".entities-item-pre",i).html(),text:$(".entities-item-text",i).html(),status:$(".entities-item-status",i).html(),link:$("a",i).first().attr("href"),active:$(i).hasClass("active")};e.entities.push(a)}e.activateSorting=function(){e.isSorting=!0},e.deactivateSorting=function(){e.isSorting=!1},e.$watch("currentPage + numPerPage",function(){var t=(e.currentPage-1)*e.numPerPage,o=t+e.numPerPage;e.paginatedEntities=e.entities.slice(t,o)})}]),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,o){t.defaults.headers.post["Content-Type"]="application/x-www-form-urlencoded",e.data=[],e.treeOptions={dropped:function(l){t({method:"POST",url:"/kms/api/"+o.siteslug+"/"+o.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 l=function(){return angular.element(document.getElementById("tree-root").scope())};e.collapseAll=function(){l().collapseAll()},e.expandAll=function(){l().expandAll()},t.get("/kms/api/"+o.siteslug+"/"+o.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="ãàáäâẽèéëêìíïîõòóöôùúüûñç·/_,:;",o=0,l=t.length;o<l;o++)e=e.replace(new RegExp(t.charAt(o),"g"),"aaaaaeeeeeiiiiooooouuuunc------".charAt(o));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,o){e.attributes=attributes,e.initCurrencyField=function(t,l){void 0!==l&&(o.NUMBER_FORMATS.CURRENCY_SYM=l),attributes[e.modelString]={value:t/100,dec_value:t},e.$watch("attributes."+e.modelString+".value",function(t,o){t!==o&&(attributes[e.modelString].dec_value=100*t)})}}]),app.controller("KmsAttributePercentageFieldController",["$scope","$element","$timeout",function(e,t,o){e.attributes=attributes}]),app.controller("KmsAttributeTextFieldCurrencyController",["$scope","$element","$timeout",function(e,t,o){e.attributes=attributes;var l=$("input",t).attr("id"),i=$("[data-kms-tax-field]",t).attr("data-kms-tax-field"),a=l+"_tax",n=l+"_no_tax",r=function(e){var t=e.toString();return t=(t=(t=t.replace(/[.]/g,"")).replace(/[,]/g,".")).replace(/[^0-9\.]+/g,""),t*=100};e.$watch("attributes."+a,function(t,o){t!==o&&(e.attributes[l]=r(t))}),e.$watch("attributes."+n,function(t,o){t!==o&&(e.attributes[l]=Math.round(function(e){if(attributes[i].selected)return e*(1+attributes[i].selected.fullValue.rate/100)}(r(t))))});var s=function(t,o){if($.isNumeric(e.attributes[l])){var r=$("#"+a),s=$("#"+n);r.is(":focus")||r.val(e.attributes[l]/100),s.is(":focus")||s.val(Math.round(function(e){if(attributes[i].selected)return e/(1+attributes[i].selected.fullValue.rate/100)}(e.attributes[l]))/100)}};$("#"+a+", #"+n).blur(function(t){0==e.attributes[l]&&$("#"+a+", #"+n).val(0)}),e.$watch("attributes."+l,s),e.$watch("attributes."+i+".selected",s),e.attributes[l]=$("input",t).attr("value"),o(s,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 o=[],l=0;l<e.selectData.length;l++){for(var i=!1,a=0;a<t.length;a++)if(e.selectData[l].value==t[a]){i=!0;break}i&&o.push(e.selectData[l])}return o}}}]),app.controller("KmsAttributeSlugController",["$scope","$element",function(e,t){e.attributes=attributes;var o=$("[data-kms-slug-field]",t).attr("data-kms-slug-field");o=o.replace("[[itemCounter]]",e.itemCounter),e.$watch("attributes."+o,function(t,l){t!==l&&(attributes[e.modelString]=e.convertToSlug(attributes[o]))})}]),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,o){e.itemKey=t,e.maxFieldGroups=o,0==t&&e.addRow()}}]),app.controller("KmsAttributeRouteController",["$scope","$element",function(e,t){e.attributes=attributes;var o=$("input",t).attr("id");attributes[o]=$("input",t).attr("value");var l=$("[data-kms-slug-field]",t).attr("data-kms-slug-field");l=l.replace("[[itemCounter]]",e.itemCounter);var i=$("[data-kms-parent-field]",t).attr("data-kms-parent-field"),a=$("[data-kms-language-id]",t).attr("data-kms-language-id"),n=$("[data-kms-structure]",t).attr("data-kms-structure"),r=function(t,o){if(t!==o){var l="";attributes[i]&&(attributes[i].selected.routes||console.error("Routes are not set in the "+i+"field"),l=attributes[i].selected.routes[a]);var r="";r=(r=n.replace("{{parentSlugs}}",l)).replace("{{slug}}",e.convertToSlug(t)),attributes[e.modelString]=r}};e.$watch("attributes."+l,r),attributes[i]&&e.$watch("attributes."+i+".selected",r)}]),app.controller("KmsAttributeSorterController",["$scope","$element",function(e,t){e.attributes=attributes}]),app.filter("multiWordFilter",["$filter",function(e){return console.log("hoi"),function(t,o){for(var l=o?o.toLowerCase().split(/\s+/):[],i=l.length,a=0;a<i;a++)t=e("filter")(t,{text:l[a]});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 o=[];return angular.isArray(e)?e.forEach(function(e){for(var l=!1,i=Object.keys(t),a=0;a<i.length;a++){var n=i[a],r=t[n].toLowerCase();if(-1!==e[n].toString().toLowerCase().indexOf(r)){l=!0;break}}l&&o.push(e)}):o=e,o}});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 o=e("#entities .entities-list"),l=e(".entities-list-item.active",o).first();if(0!=l.length){var i=l.position().top;o.scrollTop(i),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 o=function(){e("#flash-message").fadeOut()};e("#flash-message").click(function(){o()}),setTimeout(function(){o()},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 l=jQuery("#sort_order"),i=(jQuery("#autoSubmit"),jQuery("#message-box"),jQuery(".fieldGroupItems"));i.children("li").each(function(){var e=jQuery(this);e.data("id",e.attr("title")).attr("title","")}),i.sortable({opacity:.7,update:function(){}}),jQuery("#dd-form").bind("submit",function(e){var t,o;e&&e.preventDefault(),t=!0,o=[],i.children("li").each(function(){o.push(jQuery(this).data("id"))}),l.val(o.join(",")),console.log(l.val()),t&&request()})}(jQuery),$(function(){for(var e=$("#sidebar .navigation li.active").parents(),t=e.length,o=0;o<=t;o++){var l=e[o];l&&"LI"==l.tagName&&l.classList.contains("has-sub-items")&&l.classList.add("active")}var i=document.querySelectorAll("#sidebar .navigation .has-sub-items"),a=i.length;for(o=0;o<a;o++){i[o].addEventListener("click",function(){this.classList.toggle("active")})}});