text: var ApiAlarmIntegration={};ApiAlarmIntegration=ApiAlarmIntegration||{},ApiAlarmIntegration.FetchAlarms=function(a){function t(){document.addEventListener("DOMContentLoaded",function(){a('[data-api-alarm-integration="load"]').each(function(t,e){this.init(e),a(e).removeAttr("data-api-alarm-integration")}.bind(this)),a(document).on("click",'[data-action="api-alarm-integration-load-more"]',function(a){this.loadMore(a.target)}.bind(this)),a(document).on("click",'[data-action="api-alarm-integration-toggle-filters"]',function(t){var e=a(this).siblings(".filters");e.hasClass("hidden")&&(e.removeClass("hidden").hide(),e.addClass("open")),e.slideToggle(),e.hasClass("open")?(a(this).find("i.pricon").removeClass("pricon-caret-down").addClass("pricon-caret-up"),a(this).find("span").text(ApiAlarmIntegrationLang.hide_filters),e.removeClass("open")):(a(this).find("i.pricon").removeClass("pricon-caret-up").addClass("pricon-caret-down"),a(this).find("span").text(ApiAlarmIntegrationLang.show_filters),e.addClass("open"))}),a(document).on("click",'[data-alarm-filter="search"]',function(t){var e=a(t.target).parents(".box-content").parent().find(".accordion");this.loadAlarms(e,!0)}.bind(this)),a(document).on("alarms:loaded",function(t){var e=(a(t.target),window.location.hash);window.location.hash="",window.location.hash=e})}.bind(this))}return t.prototype.init=function(a){this.loadAlarms(a)},t.prototype.getFilters=function(t){var e=a(t).parents(".box-content").parent().find('[data-alarm-filter="text"]').val(),r=a(t).parents(".box-content").parent().find('[data-alarm-filter="place"]').val(),n=a(t).parents(".box-content").parent().find('[data-alarm-filter="date-from"]').val(),i=a(t).parents(".box-content").parent().find('[data-alarm-filter="date-to"]').val(),o={};return e.length>0&&(o.search=e),r.length>0&&(o.place=r),n.length>0&&(o.date_from=n),i.length>0&&(o.date_to=i),o},t.prototype.loadAlarms=function(t,e){"undefined"==typeof e&&(e=!1);var r=a(t).attr("data-alarm-api"),n=a(t).attr("data-alamrs-per-page"),i=a(t).attr("data-alamrs-current-page"),o=r+"wp/v2/alarm",l={per_page:n,page:parseInt(i)+1},p=this.getFilters(t);for(var d in p)l[d]=p[d];e&&a(t).empty();var s=ApiAlarmIntegration.Helper.Template.render("api-alarm-integration-loading");a(t).append(s),a.getJSON(o,l,function(e){a.each(e,function(e,r){a(t).find("[data-alarms-loading]").remove(),this.addAlarmToList(t,r)}.bind(this)),a(t).find("[data-api-alarms-load-more]").remove();var r=ApiAlarmIntegration.Helper.Template.render("api-alarm-integration-load-more");a(t).append(r),a(t).trigger("alarms:loaded")}.bind(this))},t.prototype.loadMore=function(t){var e=a(t).parents(".alarms-container"),r=(e.attr("data-alarm-api"),e.attr("data-alamrs-per-page"),e.attr("data-alamrs-current-page")+1);e.attr("data-alamrs-current-page",r),a(t).closest("[data-api-alarms-load-more]").remove(),this.loadAlarms(e)},t.prototype.addAlarmToList=function(t,e){e.date=e.date.replace("T"," ").substring(0,e.date.length-3);var r=ApiAlarmIntegration.Helper.Template.render("api-alarm-integration-row",e);a(t).append(r)},new t}(jQuery),Object.byString=function(a,t){t=t.replace(/\[(\w+)\]/g,".$1"),t=t.replace(/^\./,"");for(var e=t.split("."),r=0,n=e.length;r<n;++r){var i=e[r];if(!(i in a))return;a=a[i]}return a},ApiAlarmIntegration=ApiAlarmIntegration||{},ApiAlarmIntegration.Helper=ApiAlarmIntegration.Helper||{},ApiAlarmIntegration.Helper.Template=function(){function Template(){this.getTemplates()}var _templates=[];return Template.prototype.render=function(key,data){var template=_templates[key];return template=template.replace(/{#\s*([\w\.\[\]]+)\s*#}/g,function(a,t){return Object.byString(data,t)}),template=template.replace(/{##\s*if(.*)\s*##}([\s\S]*?){##\s*endif\s*##}/gm,function($1,$2,$3){return eval($2)?$3:""})},Template.prototype.getTemplates=function(){for(var a=document.querySelectorAll("[data-template]"),t=0;t<a.length;t++){var e=a[t],r=e.getAttribute("data-template"),n=e.outerHTML.replace(/data-template="([^\"]*)"/gi,"");_templates[r]=n,e.parentElement.removeChild(e)}},new Template}();