<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SenceMgt.aspx.cs" Inherits="GigaTech.CMS.Web.Apps.IOTDeviceSystem.SenceMgt" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head> <%
        Response.ExpiresAbsolute = DateTime.Now;
        Response.Expires = -1441;
        Response.CacheControl = "no-cache";
        Response.AddHeader("Pragma", "no-cache");
        Response.AddHeader("Pragma", "no-store");
        Response.AddHeader("cache-control", "no-cache");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetNoServerCaching();
         %>  <script language="javascript">
            var grid;

            Ext.onReady(function () {
                Ext.QuickTips.init();

              
                var gridStore = Ext.create('Ext.data.Store', {
                    pageSize: 30,
                    remoteSort: true,
                    autoLoad: true,
                    fields: ['name', 'logdatetime'],
                    proxy: {
                        type: 'ajax',
                        url: '/Apps/DeviceSystem/Handler.ashx?action=GetIOTScene',
                        reader: {
                            type: 'json',
                            root: 'items',
                            totalProperty: 'totalCount'
                        },
                        simpleSortMode: true,
                        extraParams: {
                            isSearch: '0',
                            MAC: '',
                            NickName: '',
                            IP: '',
                            IDs: '',
                            Name:''
                        }
                    },
                    sorters: [{
                        property: "logdatetime",
                        direction: "DESC"
                    }]
                }); 

                grid = Ext.create('Ext.grid.Panel', {
                    
                region: 'center',
                store: gridStore,
                columns: [
                    { text: '<%=GetGlobalResourceObject("CMSResource", "Name")%>', dataIndex: 'name', flex: 1 },
            
                ],
                dockedItems: [{
                    xtype: 'pagingtoolbar',
                    store: gridStore,
                    dock: 'bottom',
                    displayInfo: false
                }]
            });
                
            Ext.create('Ext.container.Viewport', {
                layout: {
                    type: 'border'
                },
                items: [grid]
                });
            });

            function ShowWin(mac) {
                var title = mac == '' ? '新增IOT设备' : '修改IOT设备';

                 var contentForm = Ext.create('Ext.form.Panel', {
                 border: false,
                 bodyPadding: 5,
                 layout: 'anchor',
                 url: 'Handler.ashx?action=SaveIOTData',
                 defaults: {
                     anchor: '100%',
                     labelWidth: 90
                 },
                 defaultType: 'textfield',
                 items: [{
                     xtype: 'hiddenfield',
                     fieldLabel: 'MAC',
                     name: 'MAC',
                     id: 'MAC',
                     readOnly:mac!="",
                    allowBlank: false
                 },{
                     fieldLabel: '<%=GetGlobalResourceObject("CMSResource", "DeviceCode")%>',
                     id: 'Model',
                name: 'Model',
                xtype: 'combo',
                store: Ext.create('Ext.data.Store', {
                    fields: ['abbr', 'name'],
                    data: [
                       
                    ]
                }),
                readOnly: mac!='',
                editable: false,
                queryMode: 'local',
                displayField: 'name',
                valueField: 'abbr',
                allowBlank: false
            }, {
                fieldLabel: '<%=GetGlobalResourceObject("CMSResource", "DeviceID")%>',
                name: 'ID',
                allowBlank: false,
                readOnly: mac != '',
                //vtype: 'alphanum'
                vtype: 'viotid'                
            },            
           {
                fieldLabel: '<%=GetGlobalResourceObject("CMSResource", "IPAddress")%>',
                name: 'IP'
                 },                 
                 {
                     fieldLabel: '<%=GetGlobalResourceObject("CMSResource", "Nick")%>',
                     id: 'NickName',
                     name: 'NickName',
                     allowBlank: false
                 },
                 {
                     fieldLabel: 'Note',
                     name: 'IpTableNote'
                 }],
            buttons: [
                {
                    text: '<%=GetGlobalResourceObject("CMSResource", "Save")%>',
                    formBind: true,
                    handler: function() {
                        var form = this.up('form').getForm();
                        if (form.isValid()) {
                            form.submit({
                                success: function(f, action) {
                                    grid.store.load();
                                    w.close();
                                },
                                failure: function(f, action) {
                                    var msg = "<%=GetGlobalResourceObject("CMSResource", "SaveFail")%>";
                                    if (action.result.msg != "") msg = action.result.msg;
                                    alert(msg);
                                }
                            });
                            }
                    }
                },
                {
                    text: '<%=GetGlobalResourceObject("CMSResource", "Cancel")%>',
                    handler: function() {
                        this.up("window").close();
                    }
                }
            ]
        });

            if (mac != "") {
            contentForm.getForm().load({
                url: 'Handler.ashx?action=GetIOTData&MAC=' + mac,
                success: function(form, action) {

                }
            });
            }

            var w = Ext.create('Ext.window.Window', {
                title: title,
                layout: 'fit',
                modal: true,
                constrain: true,
                shadow: true,
                shadowOffset: 50,
                width: 400,
                items: contentForm
            }).show();
            }
    </script>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>
