!function(e){ko.validation.init({insertMessages:!1,decorateElement:!0,errorElementClass:"error"}),ko.applyBindings(new function(){var o=this;o.popoverplacement="right",o.id=e(document).getUrlParam("id"),o.availableHostStatuses=["Active","Inactive","Ignored"],o.ipaddrin=ko.observable(""),o.portin=ko.observable(""),o.sslin=ko.observable(0),o.monitid=ko.observable(""),o.lastmodified=ko.observable(""),o.poll=ko.observable(3),o.hostname=ko.observable("").extend({required:!0,maxLength:255}),o.keepname=ko.observable(0),o.monituser=ko.observable().extend({required:!0,maxLength:55}),o.monitpassword=ko.observable().extend({required:!0,maxLength:55}),o.description=ko.observable("").extend({maxLength:1024}),o.status=ko.observable(1),o.skew=ko.observable().extend({number:!0,min:1}),o.defaultskew=ko.observable(),o.connectionStatus=ko.observable(""),o.connectionInfo=ko.observable(""),o.enableNetworkOverride=ko.observable(!1),o.ipaddrout=ko.observable().extend({maxLength:255}),o.portout=ko.observable().extend({number:!0}),o.sslout=ko.observable(-1),o.ssl=ko.computed({read:function(){return!!(-1==o.sslout()?o.sslin():o.sslout())},write:function(e){o.sslout(e?1:0)},owner:o}),o.hostname.subscribe((function(){o.keepname(1)})),o.skewSubscription=o.skew.subscribe((function(e){parseInt(e)<1&&o.skew(1)})),o.deleteHost=function(){e.post("../../admin/hosts/delete","id="+o.id,(function(){window.location="."})).fail(MMONIT.error.json)},o.updateHost=function(){var t=e("#theform").serialize();e.post("../../admin/hosts/update",t+"&id="+o.id,(function(){window.location="."})).fail(MMONIT.error.json)},o.toggleNetworkOverride=function(){o.enableNetworkOverride(!o.enableNetworkOverride())},o.hasErrors=function(){return!(o.hostname.isValid()&&o.ipaddrout.isValid()&&o.portout.isValid()&&o.monituser.isValid()&&o.monitpassword.isValid())},o.cancel=function(){window.location="."},o.test=function(t,n){if(o.connectionStatus("spin"),o.connectionInfo("Connecting..."),o.hasErrors())o.connectionStatus("orange"),o.connectionInfo("Required fields (Monit address, port, user and password) are invalid or not set."),t&&e("#connection-status").popover("show");else{var s={ipaddr:""!=o.ipaddrout()?o.ipaddrout():o.ipaddrin(),port:o.portout()>0?o.portout():o.portin(),ssl:(-1==o.sslout()?o.sslin():o.sslout())?1:0,monituser:o.monituser(),monitpassword:o.monitpassword()};e.ajax({url:"../../admin/hosts/test",data:e.param(s),type:"GET",dataType:"json",timeout:3e4,success:function(n,s,i){o.connectionStatus(n.status),o.connectionInfo(n.description),t&&e("#connection-status").popover("show")},error:function(n,s,i){o.connectionStatus("red"),o.connectionInfo(n.responseText),t&&e("#connection-status").popover("show")}})}},e.getJSON("../../admin/hosts/json/get?id="+o.id,(function(e){ko.mapping.fromJS(e,{},o);var t=new Date(1e3*e.lastmodified);o.lastmodified(t.toLocaleDateString()+" "+(t.getHours()<10?"0":"")+t.getHours()+":"+(t.getMinutes()<10?"0":"")+t.getMinutes()+":"+(t.getSeconds()<10?"0":"")+t.getSeconds()),o.portout()<=0&&o.portout(""),(o.ipaddrout().trim().length||""!=o.portout()||-1!=o.sslout())&&o.toggleNetworkOverride(),o.defaultskew(e.defaultskew),0==o.status()&&o.test()})).fail(MMONIT.error.json),ISPHONE?(o.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);