File: D:/HostingSpaces/pietvanmierlo/stempelbv.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 o(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)}a(t.promise,i)}else(1===e._state?a:r)(t.promise,e._value)})):e._deferreds.push(t)}function a(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((o=n,a=t,function(){o.apply(a,arguments)}),e)}e._state=1,e._value=t,s(e)}catch(t){r(e,t)}var o,a}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++)o(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,a(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 o(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 o=i.length;function a(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){a(e,t)},n)}i[e]=r,0==--o&&t(i)}catch(e){n(e)}}for(var r=0;r<i.length;r++)a(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,o=e.length;i<o;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"),o=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,o.parentNode.insertBefore(n,o)},debounce=function(e,t,n){var i;return function(){var o=this,a=arguments,r=n&&!i;clearTimeout(i),i=setTimeout(function(){i=null,n||e.apply(o,a)},t),r&&e.apply(o,a)}},Cookie={set:function(e,t,n){var i,o,a,r,s;n?((a=new Date).setTime(a.getTime()+24*n*60*60*1e3),r="; expires="+a.toGMTString()):r="",1===(s=location.host).split(".").length?document.cookie=e+"="+t+r+"; path=/":((o=s.split(".")).shift(),i="."+o.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 o=n[i];" "===o.charAt(0);)o=o.substring(1,o.length);if(0===o.indexOf(t))return o.substring(t.length,o.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 o=isFinite(+e)?+e:0,a=isFinite(+t)?Math.abs(t):0,r=void 0===i?",":i,s=void 0===n?".":n,l="";return(l=(a?function(e,t){var n=Math.pow(10,t);return""+Math.round(e*n)/n}(o,a):""+Math.round(o)).split("."))[0].length>3&&(l[0]=l[0].replace(/\B(?=(?:\d{3})+(?!\d))/g,r)),(l[1]||"").length<a&&(l[1]=l[1]||"",l[1]+=new Array(a-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,o=document.querySelector('meta[name="csrf-token"]').content;i.open("post",e,!0),i.setRequestHeader("Content-Type","application/json"),i.setRequestHeader("X-CSRF-TOKEN",o),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 o=window.getSelection();o.removeAllRanges(),o.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(".js-open-confirmation");i&&new ConfirmationController(i);var o=document.getElementById("entity-form"),a=o?o.dataset.globalTranslations:{},r=new Initializer("#entity-form"),s=new Initializer("#entities");if(o){var l=new ComponentAreaCopier;r.bindSelectorToCallback(".js-components-area",function(e,t){var n=new ComponentAreaManager(t,new ComponentManagerApiController);l.registerComponentAreaManager(n),n.on("componentAdded",function(e,t){t&&u&&u.refresh()})})}r.bindSelectorToCallback(".entity-attribute-documents",function(e,n){var i=o.dataset.uploadRoute,r=o.dataset.maxPostSize,s=o.dataset.maxUploadSize,l=new HTML5Uploader(i,r,s,a),c=new DocumentManager(n,l,a);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(".js-confirm",function(e,t){new ConfirmationController(t)}),r.bindSelectorToCallback(".entity-attribute-select",function(e,t){new Select(t)}),r.bindSelectorToCallback(".entity-attribute-send-password-mail-button",function(e,t){new SendPasswordMailButton(t)}),r.bindSelectorToCallback("[data-to-copy]",function(e,t){console.log("found copy text element"),new CopyText(t)}),s.bindSelectorToCallback(".js-sortable",function(e,t){new SortableController(t).load().then(function(e){u&&(console.log("Refreshing the prevent navigation controller since there may be more anchors."),u.refresh())}).catch(function(e){console.error(e)})}),r.bindSelectorToCallback("textarea.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,menubar:!1,statusbar:!1,plugins:"code paste link lists directionality",toolbar:"styleselect | bold italic strikethrough | numlist bullist | link unlink | outdent indent | code ",height:"200",paste_as_text:!0,style_formats:[{title:"Paragraaf",block:"p"},{title:"Subtitel",block:"h3"},{title:"Titel",block:"h2"}],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(),s.startObserving();var c=document.querySelector(".entity-attributes"),u=null;c&&(u=new PreventNavigationController(c))}),function(e){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 o=i.position().top;n.scrollTop(o),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"),o=(jQuery("#autoSubmit"),jQuery("#message-box"),jQuery(".fieldGroupItems"));o.children("li").each(function(){var e=jQuery(this);e.data("id",e.attr("title")).attr("title","")}),o.sortable({opacity:.7,update:function(){}}),jQuery("#dd-form").bind("submit",function(e){var t,n;e&&e.preventDefault(),t=!0,n=[],o.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,o=0;o<i;o++){n[o].addEventListener("click",function(e){this.classList.toggle("active"),t(this),e.stopImmediatePropagation()})}});var SearchController=function(){function e(t,n,i,o,a){_classCallCheck(this,e),this.apiUrl="",this.data="",this.dataToLoad="",this.editEntitiesUrl="",this.initialized=!1,this.sectionId=t,this.selector=n,this.mainUlId=o,this.resultCounterId=a,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 o=i.data.children.length,a=0;a<o;a++)for(var r=e.createHtmlElement(i.data.children[a]),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,o=0;o<i;o++)for(var a=e.createHtmlElement(e.dataToLoad.data.children[o]),r=a.length,s=0;s<r;s++)document.querySelector(e.selector).appendChild(a[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),o=document.getElementById(this.resultCounterId);n.addEventListener("keyup",function(a){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"))}o.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,o=e.id,a=e.title,r=e.model,s=e.children,l=e.status,c=e.thumbnail,u=n,d=""!==n?n+" | "+a:a,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 _='\n <span class="color-status" data-status-type="'.concat(l,'">\n \n </span>\n '),y='\n <div class="icon" '.concat(c?"style=\"background-image: url('".concat(c,"');\""):""," >\n ").concat(c?"":"<span>".concat(a?a.substring(0,1):"","</span>"),"\n </div>\n "),C='\n <li data-title="'.concat(a,"\" data-model='").concat(JSON.stringify(r)||JSON.stringify({}),"' class=\"").concat(this.listItemClass," ").concat(o==i?"active":"",'"> \n <a href="').concat(this.editEntitiesUrl,"/").concat(o,'"> \n ').concat(_,"\n ").concat(y,'\n <p data-breadcrumb="').concat(u,'">').concat(a,"</p>\n </a>\n </li> \n "),k=(new DOMParser).parseFromString(C,"text/html");t.push(k.body.firstChild);var S=h.length;if(S>0)for(var w=0;w<S;w++){var E=h[w];t.push(E[0])}return t}console.error("Please initialize the controller with the init method first.")}}]),e}(),SortableController=function(){function e(t){_classCallCheck(this,e),t?(this._wrapper=t,this._list=this._wrapper.querySelector("ul"),this._list?"slug"in this._list.dataset?(this.slug=this._list.dataset.slug,this._apiUrl="/kms/api/"+this.slug,this._editEntitiesUrl="/kms/"+this.slug,this._disabled=!0,this._listItemClass="entities-list-item",this._enableSortButton=this._wrapper.querySelector(".entities-order .sortable-button.enable-sortable"),this._enableSortButton?(this._saveSortOrderButton=this._wrapper.querySelector(".entities-order .sortable-button.save-order"),this._saveSortOrderButton?(this._activeId=this._list.dataset.activeId,axios.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",this._updateVisibility(this._list),this.enableSortable=this.enableSortable.bind(this),this.disableSortable=this.disableSortable.bind(this),this._setSortButtonsEnabled(!0)):console.error("SortableController: The sort button could not be found inside the wrapper.",this._wrapper,'Selector: ".entities-order .sortable-button .save-order". Sortable controller stopped working')):console.error("SortableController: The sort button could not be found inside the wrapper.",this._wrapper,'Selector: ".entities-order .sortable-button .enable-sortable". Sortable controller stopped working')):console.error("Make sure that the wrapper contains the data-slug attribute that contains the slug. Sortable controller stopped working."):console.error("SortableController: Expected the wrapper to have an ul. But did not have any. Sortable controller stopped working")):console.error("SortableController: Expected a wrapper but did not get any. Sortable controller stopped working")}return _createClass(e,[{key:"_setSortButtonsEnabled",value:function(e){this._enableSortButton.removeEventListener("click",this.enableSortable),this._saveSortOrderButton.removeEventListener("click",this.disableSortable),e&&(this._enableSortButton.addEventListener("click",this.enableSortable),this._saveSortOrderButton.addEventListener("click",this.disableSortable))}},{key:"_updateVisibility",value:function(e){"UL"!==e.tagName&&console.error("sortableController: Could not update the unordered list diplay style state since the list is no <ul> tag");for(var t=e.querySelectorAll("li ul"),n=t.length,i=0;i<n;i++){var o=t[i];o.style.display="none"!==o.style.display?"none":"";for(var a=o.children.length,r=0;r<a;r++){var s=o.children[r];"UL"===s.tagName&&this._updateVisibility(s)}}}},{key:"_updateSortableJavascript",value:function(){$(".sortable").sortable({connectWith:".sortable",placeholder:"sortable-placeholder",disabled:this._disabled})}},{key:"enableSortable",value:function(){this._enableSortButton.classList.remove("show"),this._saveSortOrderButton.classList.add("show"),this._disabled=!1,$(this._wrapper).sortable({disabled:this._disabled}).addClass("sorting"),this._updateSortableJavascript()}},{key:"disableSortable",value:function(){this._enableSortButton.classList.add("show"),this._saveSortOrderButton.classList.remove("show"),this._disabled=!0,$(this._wrapper).sortable({disabled:this._disabled}).removeClass("sorting"),this._save()}},{key:"_save",value:function(){var e=this._itemsToJson(this._list),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)})}},{key:"_itemsToJson",value:function(e){for(var t=[],n=!1,i=e.querySelectorAll("li."+this._listItemClass),o=i.length,a=0;a<o;a++){var r=i[a];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}},{key:"load",value:function(){return self=this,new Promise(function(e,t){axios.get(self._apiUrl).then(function(n){if(n.data&&0!=n.data.length){for(var i=n.data.children.length,o=0;o<i;o++){var a=n.data.children[o];self._list.appendChild(self._createHtmlElement(a))}self._updateSortableJavascript(),e(self._list)}else t("The sortable did not get any data from the api")}).catch(function(e){t(e)})})}},{key:"clearList",value:function(){for(;this._list.firstChild;)this._list.removeChild(this._list.firstChild)}},{key:"_createHtmlElement",value:function(e){self=this;var t=self._activeId,n=e.id,i=e.title||"-",o=e.thumbnail,a=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=a.length,f=0;f<h;f++){var m=a[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">\n '.concat(o||"<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"),_=g.body.firstChild,y=d.length;if(y>0){var C=g.createElement("ul");C.className="sortable";for(var k=0;k<y;k++){var S=d[k];C.appendChild(S)}_.appendChild(C)}return _}}]),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._clickEventHandler=this._clickEventHandler.bind(this),this._confirmClicked=this._confirmClicked.bind(this),this._cancelClicked=this._cancelClicked.bind(this),this.enableListeners()):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:"enableListeners",value:function(){this.disableListeners(),this._navigatableElement.addEventListener("click",this._clickEventHandler)}},{key:"disableListeners",value:function(){this._navigatableElement.removeEventListener("click",this._clickEventHandler)}},{key:"_clickEventHandler",value:function(e){var t=!1;(this._onlyConfirmIfTrueCallback&&!0===this._onlyConfirmIfTrueCallback.call()||!this._onlyConfirmIfTrueCallback)&&(t=!0),t&&(e.preventDefault(),this._showConfirmationPrompt(!0,this._navigatableElement))}},{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),n.removeEventListener("click",this._cancelClicked),i.removeEventListener("click",this._cancelClicked),e&&(t.addEventListener("click",this._confirmClicked),n.addEventListener("click",this._cancelClicked),i.addEventListener("click",this._cancelClicked))}},{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 buttons"><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){console.log(e?"show confirmation prompt":"hide confirmation prompt"),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,o=i.length,a=0;a<o;a++){var r=i[a];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),o=i.length;if((n||o>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",""))),o>0))for(var a=0;a<o;a++){var r=i[a];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 o=this._wrapper.querySelectorAll(e);if(!o)return this;for(var a=o.length,r=0;r<a;r++)t(this,o[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._anchorsAndConfirmationControllers=[],this._changed=!1,t?t.dataset.translation?(this._wrapperElement=t,this._inputChanged=this._inputChanged.bind(this),this._loadTranslation(),this.refresh()):console.error("PreventNavigationController: No translation present. Not preventing navigation when not all changes have been saved."):console.error("PreventNavigationController: 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:"_setListenersOnInputs",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):e[i].removeEventListener("change",this._inputChanged)}},{key:"_inputChanged",value:function(e){this._changed=!0}},{key:"_loadTranslation",value:function(){this._translation=JSON.parse(this._wrapperElement.dataset.translation)}},{key:"refresh",value:function(){this._inputs=this._findAllInputsIn(this._wrapperElement),this._interceptClicksOnAnchors(),this._setListenersOnInputs(this._inputs)}},{key:"_interceptClicksOnAnchors",value:function(){var e=this;this._clearAnchorsAndControllers();for(var t=document.getElementsByTagName("A"),n=t.length,i=function(n){var i=t[n],o=i.getAttribute("href");if(o&&"#"!==o.substr(0,1)){var a=new ConfirmationController(i);a.setHeaderText(e._translation.headerText).setMessage(e._translation.message).setConfirmText(e._translation.confirmText).setCancelText(e._translation.cancelText).setConfirmCallback(function(){window.location=o}).setOnlyConfirmIfTrueCallback(function(e){return function(){return e._hasChanged()}}(e)),e._anchorsAndConfirmationControllers.push({anchor:i,controller:a})}},o=0;o<n;o++)i(o)}},{key:"_clearAnchorsAndControllers",value:function(){for(var e;e=this._anchorsAndConfirmationControllers.pop();){var t=e.controller;t.disableListeners(),t=null}}},{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 o=e.children[i];if(this._isTrackableElement(o)&&t.push(o),o.children.length>0){var a=this._findAllInputsIn(o,t);t.concat(a)}}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",o=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=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=a,this.activeClass=i,this.reactToUrlHashChange=o,o&&this.addListenerForHashChange(o)}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 o=document.querySelector("#"+this.tabContentDivsClassAndIdPrefix+"-"+e);o?(o.classList.add(this.activeClass),isset(sessionStorage.getItem("componentScrollPosition"))||(o.parentElement.scrollTop=0),o.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}();