<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>

<style type="text/css">
	#changeRoomStatusForm ul {
		list-style-type: none;
		margin: 0;
		padding: 0;
	}
	#changeRoomStatusForm ul li{
		float: left;
		height: 25px;
		line-height: 25px;
		text-align: center;
		width: 100px;
	}
</style>

<div class="box">
	<div class="title"><%: Html.Language("RoomStatus")%></div>
	<div class="container" style="width:520px;">
		<div class="content" style="width:460px;">
			<table style="width:100%;">
				<tr>
					<td style="text-align:center;width:13%;"><span class="RoomNumber"><%: Model.RoomNumber %></span></td>
					<td style="text-align:center;width:13%;"><span class="RoomStatus"><%: Model.RoomStatus %></span></td>
					<td style="text-align:center;width:13%;"><span class="Status"><%: Model.HostStatus %></span></td>
					<%--<td style="text-align:center;width:13%;"><span class="IP"><%: Model.IP %></span></td>--%>
                    <%--<td style="text-align:center;width:20%;"><button class="easyui-linkbutton" onclick="changePowerSupply()"><%:ViewData["PowerSwitch"]%></button></td>--%><%--<%:ViewData["PowerSwitch"]%>--%>
                    <td style="width:33%; text-align:center;">
						<label><%: Html.Language("PowerStatus")%>：</label><label id="lblPowerStatus"><%: (Model.PowerSupply) ? Html.Language("Normal") : Html.Language("Lock") %></label>
					</td>
					<td style="width: 20%;">
						<a href="javascript:void(0)" class="easyui-linkbutton" onclick="changePowerSupply();"><%: Html.Language("PowerSwitch")%></a>
						<input id="hidHostID" type="hidden" value='<%: Model.HostID %>' />
						<input id="hidPowerSupply" type="hidden" value='<%: (Model.PowerSupply) ? "Lock" : "Normal" %>' />
					</td>
				</tr>
			</table>
		</div>
	</div>
</div>

<div class="box">
	<div class="title"><%:Html.Language("ChooseTheRoomStatus")%></div>
	<div class="container">
		<div class="content" style="height:33px;">
			<form id="changeRoomStatusForm" method="post" action="#">
				<input type="hidden" name="ID" value="<%=Model.HostID %>" />
				<ul class="clearfix">
					<% foreach (var item in ViewData["RoomStatus"] as IList<Domain.RoomStatus>) { %>
						<li><label><input type="radio" name="RoomStatusID" value="<%=item.ID %>" <%: Model.RoomStatus == item.Name ? "checked='checked'" : "" %> /><%=item.Name %></label></li>
					<% } %>
                    <li><a href="javascript:void(0)" class="easyui-linkbutton" onclick="changeRoomStatus();"><%:Html.Language("SendData")%></a></li>
				</ul>
			</form>
		</div>
	</div>
</div>
<script type="text/javascript">
	function changeRoomStatus() {
		var param = $("#changeRoomStatusForm").serializeJson();
		$.tools.post(param, "/Host/ChangeRoomStatus/", function () {
			$('#dialog').window('close');
			viewModel && viewModel.loadRooms();
		}, this);
	}
	function changePowerSupply(id, ctrl) {
	    var hostID = $("#hidHostID").val();
	    var powerSupply = $("#hidPowerSupply").val();

	    $.ajax({
	        url: '/Host/ChangePowerSupply/',
	        type: 'POST',
	        async: false,
	        dataType: 'JSON',
	        data: {
	            hostID: hostID,
	            ctrl: powerSupply
	        }, success: function (r) {
	            if (r.IsSuccess) {
	                if (powerSupply == 'Normal') {
	                    $("#lblPowerStatus").html(lang.Normal);
	                    $("#hidPowerSupply").val("Lock");
	                } else {
	                    $("#lblPowerStatus").html(lang.Lock);
	                    $("#hidPowerSupply").val("Normal");
	                }
	            }
	            $.tools.alert(r.Message);
	        }
	    });
	}
</script>