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

<!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>
                <script src="/Scripts/jquery-1.6.4.min.js"></script>
</head>
    <script language=javascript>
        var forPortlet = "<%=forPortlet%>";
        
        Ext.onReady(function () {
            Ext.QuickTips.init();

            var gridStore=Ext.create('Ext.data.Store', {
                pageSize: 20,
                remoteSort: true,
                autoLoad: true,
                fields: ['NickName', 'MAC', 'IP', 'ID', 'Location', 'Online'],
                proxy: {
                    type: 'ajax',
                    
                    url: 'Handler.ashx?action=GetDeviceStatus',
                    reader: {
                        type: 'json',
                        root: 'items',
                        totalProperty: 'totalCount'
                    },
                    simpleSortMode: true
                },
                sorters: [{
                    property: "Online",
                    direction: "ASC"
                }],
                listeners: {
                    beforeload: function (store, operation, eOpts) {
                        store.proxy.extraParams = { option: Ext.getCmp("statusFilter").getValue() };
                    }
                }
            });


            Ext.create('Ext.container.Viewport', {
                layout: {
                    type: 'fit'
                },
                items: [
                    {
                        xtype: 'grid',
                        id:'StatusGrid',
                        title:forPortlet=="Y"?"":"<%=GetGlobalResourceObject("CMSResource", "DeviceOnlineCheck")%>",
                        store: gridStore,
                        columns: [
                            { xtype: 'rownumberer',width:40 },
                            { text: '<%=GetGlobalResourceObject("CMSResource", "DeviceName")%>', dataIndex: 'NickName', flex: 1 },
                            { text: '<%=GetGlobalResourceObject("CMSResource", "DeviceLocation")%>', dataIndex: 'Location', flex: 1 },
                            { text: 'IP', dataIndex: 'IP',width:120},
                            {
                                text: '<%=GetGlobalResourceObject("CMSResource", "OnlineStatus")%>', dataIndex: 'Online',
                                align: 'center',
            renderer: function (value) {
                if (value == "") return;
                //return value == "1" ? '<img src=/Common/DMZ/Images/16x16/enabled.png />' : '<img src=/Common/DMZ/Images/16x16/alert.png />';
                switch (value) {
                    case "1":
                        return '<img src=/Common/DMZ/Images/16x16/enabled.png />';
                        break;
                    case "-1":
                        return '<img src=/Common/DMZ/Images/16x16/question.png />';
                        break;
                    default:
                        return '<img src=/Common/DMZ/Images/16x16/alert.png />';
                        break;
                }
            } },
                            { text: 'MAC', dataIndex: 'MAC',width:120, hidden: true },
                            { text: 'ID', dataIndex: 'ID', width: 120, hidden: true }
                        ],
                        dockedItems: [{
                            xtype: 'pagingtoolbar',
                            store: gridStore,
                            dock: 'bottom',
                            displayInfo: false,
                            items: [
                                '-',
                                Ext.create('Ext.form.ComboBox', {
                                    id:"statusFilter",
                                    fieldLabel: '<%=GetGlobalResourceObject("CMSResource", "Display")%>' + '<%=GetGlobalResourceObject("CMSResource", "Status")%>',
                                    labelWidth: 60,
                                    width: 140,
                                    editable:false,
                                store: Ext.create('Ext.data.Store', {
                                    fields: ['abbr', 'name'],
                                    data: [
                                        { "abbr": "2", "name": "<%=GetGlobalResourceObject("CMSResource", "All")%>" },
                                        { "abbr": "1", "name": "<%=GetGlobalResourceObject("CMSResource", "Online")%>" },
                                        { "abbr": "0", "name": "<%=GetGlobalResourceObject("CMSResource", "Offline")%>" }
                                    ]
                                }),
                                queryMode: 'local',
                                displayField: 'name',
                                valueField: 'abbr',
                                value: forPortlet == "Y" ? "0" : "2",
                                listeners: {
                                    'change': function () {
                                        gridStore.load();
                                    }
                                }
                            }),
       '->',
       {
           xtype: 'text',
           itemId: 'displayItem'
       }]
                        }],
                        listeners: {
                                                    'itemcontextmenu': function (view, record, item, index, event) {
                                                        //if (record.get("Online")=="1") {
                                var menu = Ext.create('Ext.menu.Menu', {
                                    items: [ {
                                        text: '<%=GetGlobalResourceObject("CMSResource", "Parameters")%>',
                                        icon: '/Common/DMZ/Images/16x16/gear.png',
                                        handler: function () {

                                            var w = parent.Ext.create('Ext.window.Window', {
                                                title: '<%=GetGlobalResourceObject("CMSResource", "ParamMainten")%>',
                                                layout: 'fit',
                                                modal: true,
                                                constrain: true,
                                                shadow: true,
                                                shadowOffset: 50,
                                                width: '95%',
                                                height: '95%',
                                                maximizable: true,
                                                items: [
                                                   {
                                                       xtype: "component",
                                                       border: false,
                                                       autoEl: {
                                                           tag: "iframe",
                                                           src: "/Apps/DeviceSystem/DeviceParameter.aspx?MAC=" + record.get("MAC")
                                                       }
                                                   }
                                                ],
                                                buttons: [
                         {
                             text: '<%=GetGlobalResourceObject("CMSResource", "Close")%>',
                             handler: function () {
                                 this.up("window").close();
                             }
                         }
                                                ]
                                            }).show();
                                        }
                                    }, {
                                        text: '<%=GetGlobalResourceObject("CMSResource", "Action")%>',
                                        menu: Ext.create('Ext.menu.Menu', {
                                            items: [
                                                {
                                                    text: '<%=GetGlobalResourceObject("CMSResource", "CallIdent")%>',
                                                    icon: '/Common/DMZ/Images/16x16/bell.png',
                                                    handler: function () {

                                                        Ext.Ajax.request({
                                                            url: 'Handler.ashx?action=HandsUP',
                                                            params: {
                                                                ip: record.get("IP")
                                                            }
                                                        });
                                                    }
                                                }, '-',
                                                    {
                                                        text: '<%=GetGlobalResourceObject("CMSResource", "Reboot")%>',
                                                        icon: '/Common/DMZ/Images/16x16/reload_all_tabs.png',
                                                        handler: function () {
                                                            if (confirm("<%=GetGlobalResourceObject("CMSResource", "RebootConfirm")%>")) {
                                                                Ext.Ajax.request({
                                                                    url: 'Handler.ashx?action=Reboot',
                                                                    params: {
                                                                        ip: record.get("IP")
                                                                    }
                                                                });
                                                            }
                                                        }
                                                    }
                                            ]
                                        })
                                    }]
                                });
                                menu.showAt(event.getXY());
                                event.stopEvent();
                            //}

                        }
                        }
                    }
                ]
            });
        });


       
    </script>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
        <audio id="audio">
    <source src="/Common/DMZ/Audio/alert.wav" type="audio/wav" />
    
</audio>
    </form>
</body>
</html>
