<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<table id="dgRoomModal" class="easyui-datagrid" style="width: 100%; height: auto;"
    data-options="
			url: '/RoomType/LoadRoomTypeModalsWithPage/',
			queryParams: { roomTypeID: <%: Model %>,deviceType:1},
			toolbar: '#tbRelationDevice',
			border: false,
			singleSelect: true,
			checkOnSelect: true,
			selectOnCheck: true,
			pagination: false,
			pageSize: 50,
			rownumbers: true,
			striped: true,
			sortName: 'Sort',
			sortOrder: 'asc',
			fit: true,
			fitColumns: true,
			idField: 'ID',
			method: 'POST',
			onDblClickRow: function(index, row) { editRoomTypeModal(row); }
		">
    <thead>
        <tr>
            <th data-options="field:'TypeName',sortable:true,resizable:false">
                <%: Html.Language("Type")%>
            </th>
            <th data-options="field:'ModalAddress',sortable:true,resizable:false">
                <%: Html.Language("ReturnAddress")%>
            </th>
            <%--<th data-options="field:'Outlet',sortable:true,resizable:false">
                <%: Html.Language("DeliveryOutlet")%>
            </th>--%>
            <th data-options="field:'Name',sortable:true,resizable:false">
                <%: Html.Language("ChineseName")%>
            </th>
            <th data-options="field:'EnglishName',sortable:true,resizable:false">
                <%: Html.Language("EnglishName")%>
            </th>
            <th data-options="field:'TWName',sortable:true,resizable:false">
                <%: Html.Language("TWName")%>
            </th>
            <th data-options="field:'AliasName',sortable:true,resizable:false">
                <%: Html.Language("AliasName")%>
            </th>
            <th data-options="field:'Power',sortable:true,resizable:false">
                <%: Html.Language("PowerWatt")%>
            </th>
            <th data-options="field:'LowPower',sortable:true,resizable:false">
                <%: Html.Language("LowElectricityValue")%>
            </th>
            <%--<th data-options="field:'Subtype',sortable:true,resizable:false">
				<%: Html.Language("Subtype") %>
            </th>--%>
            <th data-options="field:'ActiveIndicator',align:'center',resizable:false,formatter:deviceCheck">
                <%: Html.Language("Display")%>
            </th>
            <th data-options="field:'OfflineDisplay',align:'center',resizable:false,formatter:offlineCheck">
                <%: Html.Language("Offline")%>
            </th>
            <th data-options="field:'LowPowerDisplay',align:'center',resizable:false,formatter:lowPowerCheck">
                <%: Html.Language("LowPower")%>
            </th>
            <th data-options="field:'Beep',align:'center',resizable:false,formatter:beepCheck">
                <%: Html.Language("SoundAlarm")%>
            </th>
            <th data-options="field:'Abnormal',align:'center',resizable:false,formatter:abnormalCheck">
                <%: Html.Language("Abnormal")%>
            </th>
            <th data-options="field:'Sort',align:'center',sortable:true,resizable:false">
                <%: Html.Language("Sort")%>
            </th>
            <!--阿宝添加的-->
            <th data-options="field:'TCLDeviceName',align:'center',sortable:true,resizable:false">
               TCL设备名
            </th>
            <th data-options="field:'MultipleGroupID',align:'center',sortable:true,resizable:false">
               组设备编号
            </th>
            <th data-options="field:'MultipleTCLName',align:'center',sortable:true,resizable:false">
               组设备名
            </th>
        </tr>
    </thead>
</table>
<div id="tbRelationDevice">
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true"
        onclick="$('#dgRoomModal').datagrid('reload');">
        <%: Html.Language("Refresh")%></a> <a href="javascript:void(0)" class="easyui-linkbutton"
            data-options="iconCls:'icon-add',plain:true" onclick="addRoomTypeModal(<%: Model %>)">
            <%: Html.Language("New")%></a> <a href="javascript:void(0)" class="easyui-linkbutton"
                data-options="iconCls:'icon-edit',plain:true" onclick="editRoomTypeModal()">
                <%: Html.Language("Edit")%></a> <a href="javascript:void(0)" class="easyui-linkbutton"
                    data-options="iconCls:'icon-remove',plain:true" onclick="delRoomTypeModal()">
                    <%: Html.Language("Delete")%></a>
    <%--<label>
        <%: Html.Language("Type")%></label>
    <select id="cbxDeviceType" class="easyui-combobox" style="width: 120px; text-align: left;"
        data-options="required:true,editable:false,panelHeight:'auto',onSelect:cbxDeviceTypeOnSelect">
        <% foreach (var name in Enum.GetNames(typeof(Domain.DeviceType)))
           { %><option value="<%: name %>"><%: Html.Language(name) %></option>
        <%	} %>
    </select>--%>
</div>
<script type="text/javascript">
    //回路是否显示
    function deviceCheck(val, row) {
        var url = '/RoomType/SaveDeviceDisplayChange/';
        if (val) {
            return '<input type="checkbox" checked="checked" onchange="updateDisplay(this,\'' + row.ID + '\',\'' + url + '\')" />';
        } else {
            return '<input type="checkbox" onchange="updateDisplay(this,\'' + row.ID + '\',\'' + url + '\')" />';
        }
    }
    //离线是否显示
    function offlineCheck(val, row) {
        var url = '/RoomType/SaveOfflineDisplayChange/';
        if (val) {
            return '<input type="checkbox" checked="checked" onchange="updateDisplay(this,\'' + row.ID + '\',\'' + url + '\')" />';
        } else {
            return '<input type="checkbox" onchange="updateDisplay(this,\'' + row.ID + '\',\'' + url + '\')" />';
        }
    }
    //低电是否显示
    function lowPowerCheck(val, row) {
        var url = '/RoomType/SaveLowPowerDisplayChange/';
        if (val) {
            return '<input type="checkbox" checked="checked" onchange="updateDisplay(this,\'' + row.ID + '\',\'' + url + '\')" />';
        } else {
            return '<input type="checkbox" onchange="updateDisplay(this,\'' + row.ID + '\',\'' + url + '\')" />';
        }
    }
    //是否报警
    function beepCheck(val, row) {
        var url = '/RoomType/SaveBeepDisplayChange/';
        var disabled = row.Type == 4 ? "" : "disabled";
        if (val) {
            return '<input type="checkbox" ' + disabled + ' checked="checked" onchange="updateDisplay(this,\'' + row.ID + '\',\'' + url + '\')" />';
        } else {
            return '<input type="checkbox" ' + disabled + ' onchange="updateDisplay(this,\'' + row.ID + '\',\'' + url + '\')" />';
        }
    }
    //是否异常判断
    function abnormalCheck(val, row) {
        var url = '/RoomType/SaveAbnormalChange/';
        //var disabled = row.Type == 4 ? "" : "disabled";
        var disabled = "";
        if (val) {
            return '<input type="checkbox" ' + disabled + ' checked="checked" onchange="updateDisplay(this,\'' + row.ID + '\',\'' + url + '\')" />';
        } else {
            return '<input type="checkbox" ' + disabled + ' onchange="updateDisplay(this,\'' + row.ID + '\',\'' + url + '\')" />';
        }
    }
    //更新显示
    function updateDisplay(sender, id, url) {
        if (id == 0) {
            $(sender).attr("checked", false);
            $.tools.alert(lang.PleaseEditLoop);
            return;            
        }
        var params = { id: id, activeIndicator: $(sender).is(":checked") };
        $.tools.post(params, url, function () { $("#dgRoomModal").datagrid('reload'); });
    }
</script>
