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

<table id="dgWXDevice" class="easyui-datagrid" style="width: 100%; height: auto;" data-options="
            toolbar: '#tbWXDevice',
			border: false,
			singleSelect: true,
			rownumbers: true,
			striped: true,
			fit: true,
			fitColumns: true,
			idField: 'ID',
			method: 'POST',
            url: '/RoomType/LoadRoomTypeWXDevice/',
			queryParams: { roomTypeID:<%: Convert.ToInt16(Request.QueryString.Get("roomTypeID")) %>,deviceType:1}
		">
    <thead>
        <tr>
            <th data-options="field:'ModalAddress',sortable:true,resizable:false">
                <%: Html.Language("ReturnAddress")%>
            </th>
            <th data-options="field:'Name',resizable:false">
                <%: Html.Language("Name")%>
            </th>
            <th data-options="field:'EnglishName',resizable:false">
                <%: Html.Language("EnglishName")%>
            </th>
            <th data-options="field:'TWName',sortable:true,resizable:false">
                <%: Html.Language("TWName")%>
            </th>
            <th data-options="field:'TypeName',sortable:true,resizable:false">
                <%: Html.Language("Type")%>
            </th>
            <th data-options="field:'Sort',sortable:true,align:'center',resizable:false">
                <%: Html.Language("Sort")%>
            </th>
            <th data-options="field: 'WXActiveIndicator',align: 'center',resizable:false,formatter: appApplyWXFormatter">
                <%: Html.Language("Display")%>
            </th>
        </tr>
    </thead>
</table>
<div id="tbWXDevice">
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true"
        onclick="$('#dgWXDevice').datagrid('reload',{roomTypeID:<%: Convert.ToInt16(Request.QueryString.Get("roomTypeID")) %>,deviceType:0})"><%: Html.Language("Refresh")%></a>
    <%--<label>
        <%: Html.Language("Type")%></label>
    <select id="cbxDeviceType1" class="easyui-combobox" style="width: 120px; text-align: left;"
        data-options="required:true,editable:false,panelHeight:'auto',onSelect:cbxDeviceTypeOnSelect1">
        <% foreach (var name in Enum.GetNames(typeof(Domain.DeviceType)))
           { %><option value="<%: name %>"><%: Html.Language(name) %></option>
        <%	} %>
    </select>--%>
</div>
<script type="text/javascript">
    function cbxDeviceTypeOnSelect1(r) {
        var queryParams = $('#dgWXDevice').datagrid('options').queryParams;
        queryParams.deviceType = r.value
        $("#dgWXDevice").datagrid('reload');
        $('#dgWXDevice').datagrid('clearSelections');
    }
    function appApplyWXFormatter(val, row) {
        if (val) {
            return '<input type="checkbox" checked="checked" onchange="appApplyWXOnChange(this,\'' + row.ID + '\',\'' + row.Name + '\')" />';
        } else {
            return '<input type="checkbox" onchange="appApplyWXOnChange(this,\'' + row.ID + '\',\'' + row.Name + '\')" />';
        }
    }
    function appApplyWXOnChange(sender, id, name) {
        var params = { id: id, activeIndicator: $(sender).is(":checked") };
        $.tools.post(params, '/RoomType/SaveRoomTypeWXDevice/');
    }
</script>
