!function(e){let o=e=>{const o=new Date(1e3*e);return localIsoLikeDateString=o.toLocaleDateString("en-CA")+" "+o.toLocaleTimeString([],{hourCycle:"h23",hour:"2-digit",minute:"2-digit",second:"2-digit"})};ko.validation.init({insertMessages:!1,decorateElement:!0,errorElementClass:"error"}),ko.applyBindings(new function(){var t=this;t.popoverplacement="right",t.id=e(document).getUrlParam("id"),t.availableHostStatuses=["Active","Inactive","Ignored"],t.ipaddrin=ko.observable(""),t.portin=ko.observable(""),t.sslin=ko.observable(0),t.monitid=ko.observable(""),t.monitversion=ko.observable(""),t.lastmodified=ko.observable(),t.created_at=ko.observable(),t.poll=ko.observable(3),t.hostname=ko.observable("").extend({required:!0,maxLength:255}),t.keepname=ko.observable(!1),t.monituser=ko.observable().extend({required:!0,maxLength:55}),t.monitpassword=ko.observable().extend({required:!0,maxLength:55}),t.description=ko.observable("").extend({maxLength:1024}),t.status=ko.observable(1),t.led=ko.observable(2),t.skew=ko.observable().extend({number:!0,min:1}),t.defaultskew=ko.observable(),t.modified=ko.observable(!1),t.connectionStatus=ko.observable(""),t.connectionInfo=ko.observable(""),t.enableNetworkOverride=ko.observable(!1),t.ipaddrout=ko.observable().extend({maxLength:255}),t.portout=ko.observable().extend({number:!0}),t.sslout=ko.observable(-1),t.ssl=ko.computed({read:function(){return!!(-1==t.sslout()?t.sslin():t.sslout())},write:function(e){t.sslout(e?1:0)},owner:t}),t.hostname.subscribe((function(){t.keepname(1)})),t.skewSubscription=t.skew.subscribe((function(e){parseInt(e)<1&&t.skew(1)})),t.setModified=function(){return t.modified(!0),!0},t.deleteHost=function(){e.post("../../admin/hosts/delete","id="+t.id,(function(){window.location="."})).fail(MMONIT.error.json)},t.updateHost=function(){var o=e("#theform").serialize();e.post("../../admin/hosts/update",o+"&id="+t.id,(function(){window.location="."})).fail(MMONIT.error.json)},t.toggleKeepName=function(){t.keepname(!t.keepname())},t.toggleNetworkOverride=function(){t.enableNetworkOverride(!t.enableNetworkOverride())},t.toggleSSL=function(){t.ssl(!t.ssl())},t.hasErrors=function(){return!(t.hostname.isValid()&&t.ipaddrout.isValid()&&t.portout.isValid()&&t.monituser.isValid()&&t.monitpassword.isValid())},t.cancel=function(){window.location="."},t.test=function(o,n){if(t.connectionStatus("spin"),t.connectionInfo("Connecting..."),t.hasErrors())t.connectionStatus("orange"),t.connectionInfo("Required fields (Monit address, port, user and password) are invalid or not set."),o&&e("#connection-status").popover("show");else{var s={ipaddr:""!=t.ipaddrout()?t.ipaddrout():t.ipaddrin(),port:t.portout()>0?t.portout():t.portin(),ssl:(-1==t.sslout()?t.sslin():t.sslout())?1:0,monituser:t.monituser(),monitpassword:t.monitpassword()};e.ajax({url:"../../admin/hosts/test",data:e.param(s),type:"GET",dataType:"json",timeout:3e4,success:function(n,s,i){t.connectionStatus(n.status),t.connectionInfo(n.description),o&&e("#connection-status").popover("show")},error:function(n,s,i){t.connectionStatus("red"),t.connectionInfo(n.responseText),o&&e("#connection-status").popover("show")}})}},e.getJSON("../../admin/hosts/json/get?id="+t.id,(function(e){t.modified(!0),ko.mapping.fromJS(e,{},t),t.lastmodified(o(e.lastmodified)),t.created_at(o(e.created_at)),t.portout()<=0&&t.portout(""),(t.ipaddrout().trim().length||""!=t.portout()||-1!=t.sslout())&&t.toggleNetworkOverride(),t.defaultskew(e.defaultskew),0==t.status()&&t.test()})).fail(MMONIT.error.json),ISPHONE?(t.popoverplacement="left",e("#actions .btn").addClass("btn-block")):e("span.accessory input").prop("size",100),ISPHONE||ISTABLET||e("#connection-status").on("mouseenter",(function(o){e(o.target).popover("show")})).on("mouseleave",(function(o){e(o.target).popover("hide")})),e(document).on("vclick",(function(o){e(o.target).parents("#test-connection").length||e("#connection-status").popover("hide")}))}),e(window).on("resize orientationchange",(function(o){e("#connection-status").popover("hide")}))}(jQuery);