var ViewModel=function(e){var t=this;t.inactiveMenu=[{id:"0",name:"Delete Inactive hosts older than?",interval:"0"},{id:"1",name:"now",interval:"0"},{id:"2",name:"1 hour",interval:"3600"},{id:"3",name:"12 hours",interval:"43200"},{id:"4",name:"1 day",interval:"86400"},{id:"5",name:"3 days",interval:"259200"}],t.selectedInactiveInterval=ko.observable(t.inactiveMenu[0]),t.confirmDeleteInactive=function(e){0!=e.id&&(t.selectedInactiveInterval(e),$("#confirmDeleteInactive").modal("show"))},t.performDeleteInactive=function(){$.post("delete",$.param({inactive:t.selectedInactiveInterval().interval},!0),(function(t){MMONIT.datatable.search.shouldRefreshCache=!0,e.load()})).fail(MMONIT.error.json)}},loader=new YAHOO.util.YUILoader({base:"../../lib/f/yui/2/",loadOptional:!1,require:["json","datatable","dom"],onSuccess:function(){YAHOO.util.Event.onDOMReady((function(){var e=this;e.selectedRow=null,e.searchResultLength=0,e.width=$("#main").outerWidth();var t=[{key:"hostname",label:"Host",sortable:!0,formatter:function(e,t,a,o){$(e).html('<a href="../../status/hosts/detail?id='+t.getData("id")+'">'+YAHOO.lang.escapeHTML(o)+"</a>")},width:350},{key:"ipaddr",label:"Address",sortable:!0,formatter:"text",minWidth:100},{key:"status",label:"Status",sortable:!0,formatter:"text"},{key:"monitversion",label:"Monit",sortable:!0,formatter:"text"},{key:"description",label:"Description",sortable:!1,formatter:"text",minWidth:200}];ISTABLET||t.push({key:"delete",label:"",sortable:!1,formatter:function(e,t,a,o){$(e).html('<span class="remove-button"></span>')}});e.myDataSource=new YAHOO.util.XHRDataSource("../../admin/hosts/list"),e.myDataSource.responseType=YAHOO.util.XHRDataSource.TYPE_JSON,e.myDataSource.responseSchema={resultsList:"records",fields:["id","hostname","ipaddr","description","monitversion","status"],metaFields:{totalRecords:"totalRecords",inactive:"inactive"}};var a={selectionMode:"single",sortedBy:{key:"hostname",dir:YAHOO.widget.DataTable.CLASS_DESC}};e.myDataTable=new YAHOO.widget.DataTable("hostTable",e.width<768?[{key:"hostname",label:"Host",sortable:!0,formatter:"text",minWidth:200}]:t,e.myDataSource,a),e.myDataTable.doBeforeLoadData=function(t,a,o){return a.error?(MMONIT.error.json(a,null,null,e.myDataTable),!1):($("#numHosts").text(a.meta.totalRecords),a.meta.inactive>0?$("#purgeInactiveHostsButton").show():$("#purgeInactiveHostsButton").hide(),a.results.sort((function(e,t){return e.hostname>t.hostname?1:t.hostname>e.hostname?-1:0})),!0)},ISPHONE||ISTABLET||(e.myDataTable.subscribe("rowMouseoverEvent",(function(t){var a=e.myDataTable.getRecord(t.target);a&&(e.myDataTable.highlightRow(a),$("#"+t.target.id+" .yui-dt-col-delete .remove-button").css("visibility","visible"))})),e.myDataTable.subscribe("rowMouseoutEvent",(function(t){var a=e.myDataTable.getRecord(t.target);a&&(e.myDataTable.unhighlightRow(a),$("#"+t.target.id+" .yui-dt-col-delete .remove-button").css("visibility","hidden"))}))),e.myDataTable.subscribe("rowClickEvent",(function(t){window.location="edit?id="+e.myDataTable.getRecord(t.target).getData("id")})),e.myDataTable.subscribe("cellClickEvent",(function(t){if(e.selectedRow=e.myDataTable.getRecord(t.target),"delete"==e.myDataTable.getColumn(t.target).key)return $("#confirmDelete .text-error").text(e.selectedRow.getData("hostname")),$("#confirmDelete").modal("show"),!1})),MMONIT.datatable.search.client(e.myDataTable,"hostname","searchfield",(function(t){e.searchResultLength=t,t>0?$("#purgeHostsButton").show():$("#purgeHostsButton").hide()})),e.resetSearch=function(){$("#searchfield").val(""),$("#searchfield").keyup()},$("#deletebtn").on("click",(function(t){var a="id="+e.selectedRow.getData("id");$.post("delete",a,(function(){e.myDataTable.deleteRow(e.selectedRow)})).fail(MMONIT.error.json)})),$("#purgeHostsButton").on("click",(function(t){return $("#confirmPurgeHosts .deletenumberofhosts").text(e.searchResultLength),$("#confirmPurgeHosts").modal("show"),!1})),$("#more").on("click",(function(e){return $("#more").hide(),$("#moretext").show(),!1})),$("#search-reset").on("click",(function(t){e.resetSearch()})),$("#performPurgeHosts").on("click",(function(t){var a=e.myDataTable.getRecordSet().getRecords().map((function(e){return"id="+e.getData("id")})).join("&");$.post("delete",a,(function(){MMONIT.datatable.search.shouldRefreshCache=!0,e.myDataTable.load(),e.resetSearch()})).fail(MMONIT.error.json)})),function(){if(e.width=$("#main").outerWidth(),e.width<768)e.myDataTable.setColumnWidth(e.myDataTable.getColumn("hostname"),e.width-24);else{var t=e.width-350;e.myDataTable.setColumnWidth(e.myDataTable.getColumn("hostname"),t/2),e.myDataTable.setColumnWidth(e.myDataTable.getColumn("description"),t/2)}ko.applyBindings(new ViewModel(e.myDataTable)),$(window).off("resize orientationchange").on("resize orientationchange",phone)}()}))}});loader.insert();