File: D:/HostingSpaces/slenders/slenders.nl/wwwroot/js/kms/core.js
function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),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 createNewEvent(e){var t;return"function"==typeof Event?t=new Event(e):(t=document.createEvent("Event")).initEvent(e,!0,!0),t}function dispatchEventForElement(e,t){document.createEvent?e.dispatchEvent(t):e.fireEvent("on"+t.eventType,t)}Number.isInteger=Number.isInteger||function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e},function(e,t){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,function(){"use strict";function e(e){var t=this.constructor;return this.then(function(n){return t.resolve(e()).then(function(){return n})},function(n){return t.resolve(e()).then(function(){return t.reject(n)})})}var t=setTimeout;function n(){}function i(e){if(!(this instanceof i))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],c(e,this)}function a(e,t){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,i._immediateFn(function(){var n=1===e._state?t.onFulfilled:t.onRejected;if(null!==n){var i;try{i=n(e._value)}catch(e){return void r(t.promise,e)}o(t.promise,i)}else(1===e._state?o:r)(t.promise,e._value)})):e._deferreds.push(t)}function o(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"===_typeof(t)||"function"==typeof t)){var n=t.then;if(t instanceof i)return e._state=3,e._value=t,void s(e);if("function"==typeof n)return void c((a=n,o=t,function(){a.apply(o,arguments)}),e)}e._state=1,e._value=t,s(e)}catch(t){r(e,t)}var a,o}function r(e,t){e._state=2,e._value=t,s(e)}function s(e){2===e._state&&0===e._deferreds.length&&i._immediateFn(function(){e._handled||i._unhandledRejectionFn(e._value)});for(var t=0,n=e._deferreds.length;t<n;t++)a(e,e._deferreds[t]);e._deferreds=null}function l(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}function c(e,t){var n=!1;try{e(function(e){n||(n=!0,o(t,e))},function(e){n||(n=!0,r(t,e))})}catch(e){if(n)return;n=!0,r(t,e)}}i.prototype.catch=function(e){return this.then(null,e)},i.prototype.then=function(e,t){var i=new this.constructor(n);return a(this,new l(e,t,i)),i},i.prototype.finally=e,i.all=function(e){return new i(function(t,n){if(!e||void 0===e.length)throw new TypeError("Promise.all accepts an array");var i=Array.prototype.slice.call(e);if(0===i.length)return t([]);var a=i.length;function o(e,r){try{if(r&&("object"===_typeof(r)||"function"==typeof r)){var s=r.then;if("function"==typeof s)return void s.call(r,function(t){o(e,t)},n)}i[e]=r,0==--a&&t(i)}catch(e){n(e)}}for(var r=0;r<i.length;r++)o(r,i[r])})},i.resolve=function(e){return e&&"object"===_typeof(e)&&e.constructor===i?e:new i(function(t){t(e)})},i.reject=function(e){return new i(function(t,n){n(e)})},i.race=function(e){return new i(function(t,n){for(var i=0,a=e.length;i<a;i++)e[i].then(t,n)})},i._immediateFn="function"==typeof setImmediate&&function(e){setImmediate(e)}||function(e){t(e,0)},i._unhandledRejectionFn=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};var u=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")}();"Promise"in u?u.Promise.prototype.finally||(u.Promise.prototype.finally=e):u.Promise=i});var isset=function(e){return null!=e},EasingFunctions={linear:function(e){return e},easeInQuad:function(e){return e*e},easeOutQuad:function(e){return e*(2-e)},easeInOutQuad:function(e){return e<.5?2*e*e:(4-2*e)*e-1},easeInCubic:function(e){return e*e*e},easeOutCubic:function(e){return--e*e*e+1},easeInOutCubic:function(e){return e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},easeInQuart:function(e){return e*e*e*e},easeOutQuart:function(e){return 1- --e*e*e*e},easeInOutQuart:function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},easeInQuint:function(e){return e*e*e*e*e},easeOutQuint:function(e){return 1+--e*e*e*e*e},easeInOutQuint:function(e){return e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e}},getScript=function(e,t){var n=document.createElement("script");n.async=1;var i=document.getElementsByTagName("script"),a=i[i.length-1];n.onload=n.onreadystatechange=function(e,i){(i||!n.readyState||/loaded|complete/.test(n.readyState))&&(n.onload=n.onreadystatechange=null,n=void 0,i||t&&t())},n.src=e,a.parentNode.insertBefore(n,a)},debounce=function(e,t,n){var i;return function(){var a=this,o=arguments,r=n&&!i;clearTimeout(i),i=setTimeout(function(){i=null,n||e.apply(a,o)},t),r&&e.apply(a,o)}},Cookie={set:function(e,t,n){var i,a,o,r,s;n?((o=new Date).setTime(o.getTime()+24*n*60*60*1e3),r="; expires="+o.toGMTString()):r="",1===(s=location.host).split(".").length?document.cookie=e+"="+t+r+"; path=/":((a=s.split(".")).shift(),i="."+a.join("."),document.cookie=e+"="+t+r+"; path=/; domain="+i,null!=Cookie.get(e)&&Cookie.get(e)==t||(i="."+s,document.cookie=e+"="+t+r+"; path=/; domain="+i))},get:function(e){for(var t=e+"=",n=document.cookie.split(";"),i=0;i<n.length;i++){for(var a=n[i];" "===a.charAt(0);)a=a.substring(1,a.length);if(0===a.indexOf(t))return a.substring(t.length,a.length)}return null},erase:function(e){Cookie.set(e,"",-1)}},number_format=function(e,t,n,i){e=(e+"").replace(/[^0-9+\-Ee.]/g,"");var a=isFinite(+e)?+e:0,o=isFinite(+t)?Math.abs(t):0,r=void 0===i?",":i,s=void 0===n?".":n,l="";return(l=(o?function(e,t){var n=Math.pow(10,t);return""+Math.round(e*n)/n}(a,o):""+Math.round(a)).split("."))[0].length>3&&(l[0]=l[0].replace(/\B(?=(?:\d{3})+(?!\d))/g,r)),(l[1]||"").length<o&&(l[1]=l[1]||"",l[1]+=new Array(o-l[1].length+1).join("0")),l.join(s)};Element.prototype.closest||(Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector),Element.prototype.closest=function(e){var t=this;if(!document.documentElement.contains(this))return null;do{if(t.matches(e))return t;t=t.parentElement}while(null!==t);return null});var Ajax={get:function(e,t){var n=new XMLHttpRequest,i=document.querySelector('meta[name="csrf-token"]').content;n.open("get",e,!0),n.setRequestHeader("Content-Type","application/json"),n.setRequestHeader("X-CSRF-TOKEN",i),n.setRequestHeader("X-Requested-With","XMLHttpRequest"),n.onreadystatechange=function(){4===n.readyState&&t(n)},n.send()},post:function(e,t,n){var i=new XMLHttpRequest,a=document.querySelector('meta[name="csrf-token"]').content;i.open("post",e,!0),i.setRequestHeader("Content-Type","application/json"),i.setRequestHeader("X-CSRF-TOKEN",a),i.setRequestHeader("X-Requested-With","XMLHttpRequest"),i.onreadystatechange=function(){4===i.readyState&&n(i)},i.send(JSON.stringify(t))}},capitalizeFirstLetter=function(e){return e.charAt(0).toUpperCase()+e.slice(1)};function snakeToCamel(e){return e.replace(/(\-\w)/g,function(e){return e[1].toUpperCase()})}function indexInParent(e){for(var t=e.parentNode.childNodes,n=0,i=0;i<t.length;i++){if(t[i]==e)return n;1==t[i].nodeType&&n++}return-1}function copyToClipboard(e){if(e="string"==typeof e?document.querySelector(e):e,navigator.userAgent.match(/ipad|ipod|iphone/i)){var t=e.contentEditable,n=e.readOnly;e.contentEditable=!0,e.readOnly=!0;var i=document.createRange();i.selectNodeContents(e);var a=window.getSelection();a.removeAllRanges(),a.addRange(i),e.setSelectionRange(0,999999),e.contentEditable=t,e.readOnly=n}else e.select();document.execCommand("copy")}document.addEventListener("DOMContentLoaded",function(){window.axios.defaults.headers.common={"X-Requested-With":"XMLHttpRequest","X-CSRF-TOKEN":document.querySelector('meta[name="csrf-token"]').getAttribute("content")},new TabsController("tab-content","entity-tabs","active",!0,'input[name="tabslug"]');var e=document.getElementById("save-button"),t=new styleClassController(e);if(e){var n=document.querySelector('input[value="submit-cloaked"]');e.addEventListener("click",function(e){e.preventDefault(),t.requestAddClass("disabled"),n.click()})}var i=document.querySelector("input.trash.confirm");i&&new ConfirmationController(i);var a=document.getElementById("entity-form"),o=a?a.dataset.globalTranslations:{},r=new Initializer("#entity-form");r.bindSelectorToCallback(".js-components-area",function(e,t){new ComponentAreaManager(t,new ComponentManagerApiController)}),r.bindSelectorToCallback(".entity-attribute-documents",function(e,n){var i=a.dataset.uploadRoute,r=a.dataset.maxPostSize,s=a.dataset.maxUploadSize,l=new HTML5Uploader(i,r,s,o),c=new DocumentManager(n,l);new FileDragAndDropHandler(n.querySelector(".drag-and-drop-area")).hookTo(c),l.on("uploadStart",function(){t.requestAddClass("disabled")}),l.on("uploadComplete",function(){t.requestRemoveClass("disabled")}),l.on("uploadCanceled",function(){t.requestRemoveClass("disabled")}),l.on("uploadFailed",function(){t.requestRemoveClass("disabled")})}),r.bindSelectorToCallback(".entity-attribute-multiselect-combo-box",function(e,t){if("false"===t.dataset.readonly)new MultiSelect(t)}),r.bindSelectorToCallback(".entity-attribute-on-off",function(e,t){new OnOff(t)}),r.bindSelectorToCallback(".js-video",function(e,t){new Video(t)}),r.bindSelectorToCallback(".confirm",function(e,t){new ConfirmationController(t)}),r.bindSelectorToCallback(".entity-attribute-select",function(e,t){new Select(t)}),r.bindSelectorToCallback("[data-to-copy]",function(e,t){console.log("found copy text element"),new CopyText(t)}),r.bindSelectorToCallback(".tiny-mce",function(e,t){t.id||(t.id=(new Date).getTime()+Math.random().toString(36).substring(7)),tinymce.remove("#"+t.id),tinymce.init({target:t,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,setup:function(e){e.on("change",function(n){!function(e,t){e.save();var n=createNewEvent("change");dispatchEventForElement(t,n)}(e,t)})}})},!1),r.startObserving(),new PreventNavigationController(document.querySelector(".entity-attributes"))}),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 n=e("#entities .entities-list:visible"),i=e(".active",n).first();if(0!=i.length){var a=i.position().top;n.scrollTop(a),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 n=function(){e("#flash-message").fadeOut()};e("#flash-message").click(function(){n()}),setTimeout(function(){n()},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 i=jQuery("#sort_order"),a=(jQuery("#autoSubmit"),jQuery("#message-box"),jQuery(".fieldGroupItems"));a.children("li").each(function(){var e=jQuery(this);e.data("id",e.attr("title")).attr("title","")}),a.sortable({opacity:.7,update:function(){}}),jQuery("#dd-form").bind("submit",function(e){var t,n;e&&e.preventDefault(),t=!0,n=[],a.children("li").each(function(){n.push(jQuery(this).data("id"))}),i.val(n.join(",")),console.log(i.val()),t&&request()})}(jQuery),document.addEventListener("DOMContentLoaded",function(){var e=document.querySelector("#sidebar .navigation li.active");function t(e){var n=e.parentElement?e.parentElement:e.parentNode;n.classList.contains("has-sub-items")&&"LI"===n.tagName&&(n.classList.add("active"),t(n))}e&&t(e);for(var n=document.querySelectorAll("#sidebar .navigation .has-sub-items"),i=n.length,a=0;a<i;a++){n[a].addEventListener("click",function(e){this.classList.toggle("active"),t(this),e.stopImmediatePropagation()})}});var SearchController=function(){function e(t,n,i,a,o){_classCallCheck(this,e),this.apiUrl="",this.data="",this.dataToLoad="",this.editEntitiesUrl="",this.initialized=!1,this.sectionId=t,this.selector=n,this.mainUlId=a,this.resultCounterId=o,this.disabled=!0,this.inputSelector=i,this.listItemClass="entities-list-item",this.visibleClass="active",this.invisibleClass="hide",this.section=document.getElementById(this.sectionId);var r=document.querySelector(this.selector);this.siteSlug=r.dataset.siteSlug,this.slug=r.dataset.slug,this.activeId=r.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,n){if(!1===e.initialized&&n("Please initialize the controller with the init method first."),""!==e.apiUrl&&""===e.dataToLoad)axios.get(e.apiUrl).then(function(i){if(i.data&&0!=i.data.length){for(var a=i.data.children.length,o=0;o<a;o++)for(var r=e.createHtmlElement(i.data.children[o]),s=r.length,l=0;l<s;l++)document.querySelector(e.selector).appendChild(r[l]);e.initializeSearch(),t(document.querySelector(e.selector))}else n("The searchable did not get any data from the api")}).catch(function(e){n(e)});else if(""===e.apiUrl&&""!==e.dataToLoad){for(var i=e.dataToLoad.data.children.length,a=0;a<i;a++)for(var o=e.createHtmlElement(e.dataToLoad.data.children[a]),r=o.length,s=0;s<r;s++)document.querySelector(e.selector).appendChild(o[s]);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,n=document.querySelector(this.inputSelector),i=document.querySelector(this.selector),a=document.getElementById(this.resultCounterId);n.addEventListener("keyup",function(o){for(var r=document.getElementById(e.mainUlId),s=0,l=n.value.toLowerCase(),c=""==l,u=i.querySelectorAll("li"),d=u.length,h=0;h<d;h++){var f=u[h].dataset.title.toLowerCase(),m=JSON.parse(u[h].dataset.model),v=f.indexOf(l)>-1&&!1===c,p=!1;if(!v&&l.length>=3)for(var b in m)if(m.hasOwnProperty(b)&&-1!==String(m[b]).toLowerCase().indexOf(l.toLowerCase())){p=!0;break}v||p?(s++,u[h].classList.add(e.visibleClass),u[h].setAttribute("dusk","found_search_item")):(u[h].classList.remove(e.visibleClass),u[h].removeAttribute("dusk"))}a.innerHTML=s+"",c?(t.classList.remove(e.visibleClass),r.classList.remove(e.invisibleClass)):(t.classList.add(e.visibleClass),r.classList.add(e.invisibleClass))}),i.classList.remove(this.visibleClass)}},{key:"createHtmlElement",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"";if(!1!==this.initialized){var i=this.activeId,a=e.id,o=e.title,r=e.model,s=e.children,l=e.status,c=e.thumbnail,u=n,d=""!==n?n+" | "+o:o,h=[],f=!0,m=!1,v=void 0;try{for(var p,b=s[Symbol.iterator]();!(f=(p=b.next()).done);f=!0){var g=p.value;h.push(this.createHtmlElement(g,t,d))}}catch(e){m=!0,v=e}finally{try{f||null==b.return||b.return()}finally{if(m)throw v}}var y='\n <span class="color-status" data-status-type="'.concat(l,'">\n \n </span>\n '),C='\n <div class="icon" '.concat(c?"style=\"background-image: url('".concat(c,"');\""):""," >\n ").concat(c?"":"<span>".concat(o?o.substring(0,1):"","</span>"),"\n </div>\n "),k='\n <li data-title="'.concat(o,"\" data-model='").concat(JSON.stringify(r)||JSON.stringify({}),"' class=\"").concat(this.listItemClass," ").concat(a==i?"active":"",'"> \n <a href="').concat(this.editEntitiesUrl,"/").concat(a,'"> \n ').concat(y,"\n ").concat(C,'\n <p data-breadcrumb="').concat(u,'">').concat(o,"</p>\n </a>\n </li> \n "),T=(new DOMParser).parseFromString(k,"text/html");t.push(T.body.firstChild);var w=h.length;if(w>0)for(var E=0;E<w;E++){var S=h[E];t.push(S[0])}return 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 n=document.querySelector(this.selector);this.siteSlug=n.dataset.siteSlug,this.slug=n.dataset.slug,this.activeId=n.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;for(var n=document.querySelectorAll(this.selector+" li ul"),i=n.length,a=0;a<i;a++){var o=n[a];o.style.display="none"!==o.style.display?"none":""}this.initialized=!0}},{key:"updateSortableJavascript",value:function(){$(".sortable").sortable({connectWith:".sortable",placeholder:"sortable-placeholder",disabled:this.disabled})}},{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},n={tree:e=JSON.stringify(t)};axios.post(this.apiUrl,n).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){for(var t=[],n=!1,i=e.querySelectorAll("li."+this.listItemClass),a=i.length,o=0;o<a;o++){var r=i[o];if(r.parentElement===e){r.dataset.json||(console.error('One or more li HTMLElements with class "'+this.listItemClass+'" did not have data-json attribute set while it should.'),n=!0);var s=JSON.parse(r.dataset.json),l=r.querySelector("ul");l?(s.children=this.itemsToJson(l),s.children||(n=!0)):s.children=[],t.push(s)}}return n?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(n){if(n.data&&0!=n.data.length){for(var i=n.data.children.length,a=0;a<i;a++){var o=n.data.children[a];document.querySelector(self.selector).appendChild(self.createHtmlElement(o))}self.updateSortableJavascript(),new PreventNavigationController(document.querySelector(".entity-attributes")),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,n=e.id,i=e.title||"-",a=e.thumbnail,o=e.children,r=e.status,s=e.routes,l={};for(var c in s)s.hasOwnProperty(c)&&(l[c]=s[c]);l=={}&&(l=[]);var u={id:e.id,title:e.title,thumbnail:e.thumbnail,routes:l,status:e.status};u=JSON.stringify(u);for(var d=[],h=o.length,f=0;f<h;f++){var m=o[f];d.push(this.createHtmlElement(m))}var v='\n <span class="color-status" data-status-type="'.concat(r,'">\n \n </span>\n '),p='\n <div class="icon" '.concat(a?"style=\"background-image: url('".concat(a,"');\""):""," >\n ").concat(a?"":"<span>".concat(i?i.substring(0,1):"","</span>"),"\n </div>\n "),b="\n <li data-json='".concat(u,"' class=\"").concat(this.listItemClass," ").concat(n==t?"active":"",'"> \n <a href="').concat(this.editEntitiesUrl,"/").concat(n,'">\n ').concat(v,"\n ").concat(p,"\n <p>").concat(i,"</p>\n </a>\n </li> \n "),g=(new DOMParser).parseFromString(b,"text/html"),y=g.body.firstChild,C=d.length;if(C>0){var k=g.createElement("ul");k.className="sortable";for(var T=0;T<C;T++){var w=d[T];k.appendChild(w)}y.appendChild(k)}return y}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(n){var i=!1;(t.onlyConfirmIfTrueCallback&&!0===t.onlyConfirmIfTrueCallback.call()||!t.onlyConfirmIfTrueCallback)&&(i=!0),i&&(n.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"),n=this.promptElement.querySelector("button.cancel"),i=this.promptElement.querySelector("div.shader");t.removeEventListener("click",this.confirmClicked.bind(this)),n.removeEventListener("click",this.cancelClicked.bind(this)),i.removeEventListener("click",this.cancelClicked.bind(this)),e&&(t.addEventListener("click",this.confirmClicked.bind(this)),n.addEventListener("click",this.cancelClicked.bind(this)),i.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.addNavigatableElementValueToForm(),this.submitNearestForm(!1)),this.showConfirmationPrompt(!1)}},{key:"addNavigatableElementValueToForm",value:function(){if(this.navigatableElement.hasAttribute("value")&&this.navigatableElement.hasAttribute("name")){var e=this.findForm(this.navigatableElement);if(!e)return;var t=document.createElement("INPUT");t.setAttribute("type","hidden"),t.setAttribute("name",this.navigatableElement.getAttribute("name")),t.setAttribute("value",this.navigatableElement.getAttribute("value")),e.appendChild(t)}}},{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="navigatableElements"><button class="confirm" dusk="confirmation_confirm">'+this.confirmText+'</button><button class="cancel" dusk="confirmation_cancel">'+this.cancelText+'</button></div></div></div></div><div class="shader"></div>',t=document.createElement("div");return t.setAttribute("id","confirmBox"),t.setAttribute("dusk","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}(),Initializer=function(){function e(t){_classCallCheck(this,e),this._bindings={},this._onceBindings={},this._booted=!1,this._observer=null,this._isObserving=!1,this._showDebugInformation=!1,this._observerConfiguration={subtree:!0,childList:!0},this._wrapper=document.querySelector(t),this._wrapper?this._boot():console.info('The selector "'+t+'" does not match any element. Could not monitor html elements and initialize them when needed.')}return _createClass(e,[{key:"_boot",value:function(){this._booted||(this._booted=!0,this._observer=new MutationObserver(this._mutationsObserved.bind(this)))}},{key:"startObserving",value:function(){return this._booted?(this._showDebugInformation&&console.log("Starting to observe"),this._observer.takeRecords(),this._observer.observe(this._wrapper,this._observerConfiguration),this._isObserving=!0,this):this}},{key:"stopObserving",value:function(){return this._booted?(this._showDebugInformation&&console.log("Stopped to observe"),this._observer.disconnect(),this._isObserving=!1,this):this}},{key:"_mutationsObserved",value:function(e){if(!this._booted)return this;var t=e.length;this._showDebugInformation&&console.info("Detected "+t+" changes");for(var n=0;n<t;n++)for(var i=e[n].addedNodes,a=i.length,o=0;o<a;o++){var r=i[o];this._triggerBoundCallbacksIfElementMatchesSelector(r)}}},{key:"_triggerBoundCallbacksIfElementMatchesSelector",value:function(e){if(e&&e instanceof HTMLElement)for(var t in this._bindings){var n=e.matches(t),i=e.querySelectorAll(t),a=i.length;if((n||a>0)&&(n&&(e.hasAttribute("initialized")&&!1!==this._onceBindings[t]||(this._showDebugInformation&&console.log('Calling callback for selector "'+t+'". HTMLElement',e),this._bindings[t](this,e),e.setAttribute("initialized",""))),a>0))for(var o=0;o<a;o++){var r=i[o];r.hasAttribute("initialized")&&!1!==this._onceBindings[t]||(this._showDebugInformation&&console.log('Calling callback for selector "'+t+'". HTMLElement',r),this._bindings[t](this,r),r.setAttribute("initialized",""))}}}},{key:"bindSelectorToCallback",value:function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!this._booted)return this;if("string"!=typeof e)return console.error("Initializer:bind The selector must be a string"),this;if("function"!=typeof t)return console.error("Initializer:bind The callback must be a function"),this;if("boolean"!=typeof n)return console.error("Initializer:bind The once variable must be a boolean"),this;this._bindings[e]=t,this._onceBindings[e]=n,this._showDebugInformation&&console.log('bound selector "'+e+'" to a callback');var i=this._isObserving;this._isObserving&&this.stopObserving();var a=this._wrapper.querySelectorAll(e);if(!a)return this;for(var o=a.length,r=0;r<o;r++)t(this,a[r]);return i&&this.startObserving(),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],n=e.length,i=0;i<n;i++)t?e[i].addEventListener("change",this.inputChanged.bind(this)):e[i].removeEventListener("change",this.inputChanged.bind(this))}},{key:"inputChanged",value:function(e){this.changed=!0}},{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")),n=t.length,i=function(n){var i,a=t[n],o=a.getAttribute("href");o&&"#"!==o.substr(0,1)&&new ConfirmationController(a).setHeaderText(e.translation.headerText).setMessage(e.translation.message).setConfirmText(e.translation.confirmText).setCancelText(e.translation.cancelText).setConfirmCallback(function(){window.location=o}).setOnlyConfirmIfTrueCallback((i=e,function(){return i.hasChanged()}))},a=0;a<n;a++)i(a)}},{key:"hasChanged",value:function(){return this.changed}},{key:"findAllInputsIn",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=e.children.length;if(0===n)return t;for(var i=0;i<n;i++){var a=e.children[i];if(this.isTrackableElement(a)&&t.push(a),a.children.length>0){var o=this.findAllInputsIn(a,t);t.concat(o)}}return t}}]),e}(),TabsController=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"tab",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:".tab-buttons",i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"active",a=arguments.length>3&&void 0!==arguments[3]&&arguments[3],o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0;_classCallCheck(this,e);document.querySelector(this.tabSlugInputId);this.tabButtonGroupSelector=n,this.tabContentDivsClassAndIdPrefix=t,this.tabSlugInputId=o,this.activeClass=i,this.reactToUrlHashChange=a,a&&this.addListenerForHashChange(a)}return _createClass(e,[{key:"openTab",value:function(e,t){(e=this.removeLeftHandSlashInSlug(e))&&(t&&sessionStorage.clear(),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){for(var t=document.querySelectorAll(".entity-tabs > ul > li"),n=t.length,i=0;i<n;i++){t[i].classList.remove("active")}document.querySelector('.entity-tabs > ul > li a[href="#'+e+'"]').parentElement.classList.add("active")}},{key:"showTabContentForTabWithSlug",value:function(e){for(var t=document.querySelectorAll("."+this.tabContentDivsClassAndIdPrefix),n=t.length,i=0;i<n;i++){t[i].classList.remove(this.activeClass)}var a=document.querySelector("#"+this.tabContentDivsClassAndIdPrefix+"-"+e);a?(a.classList.add(this.activeClass),isset(sessionStorage.getItem("componentScrollPosition"))||(a.parentElement.scrollTop=0),a.parentElement.addEventListener("scroll",function(e){sessionStorage.componentScrollPosition=e.currentTarget.scrollTop})):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,!0);else{var n=document.querySelector(this.tabSlugInputId);n&&this.openTab(n.value,!1)}}}]),e}();