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

<!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>
            <style>
        .treenode-no-icon
{
    display : none !important;
}

            .x-action-col-cell img.application_link-empty {
background-image: url("");
cursor:default;
}
.x-action-col-cell img.application_link {
    background-image: url("/Common/DMZ/Images/16x16/application_link.png");
}

            .x-action-col-cell img.edit-empty {
background-image: url("");
cursor:default;
}
.x-action-col-cell img.edit {
    background-image: url("/Common/DMZ/Images/16x16/edit.png");
}
    </style>
         <script language=javascript>
             var tree;
             var iot = "<%=iot%>";
             Ext.onReady(function () {
                 Ext.QuickTips.init();

                 Ext.apply(Ext.form.field.VTypes, {
                     //  vtype validation function
                     file: function (val, field) {
                         var fileName = /^.*\.(DeviceDB)$/i;
                         return fileName.test(val);
                     },
                     // vtype Text property to display error Text
                     // when the validation function returns false
                     fileText: "File must be .DeviceDB",
                     // vtype Mask property for keystroke filter mask
                     fileMask: /[a-z_\.]/i
                 });

                 var store = Ext.create('Ext.data.TreeStore', {
                     fields: [
                        'JSONcount', 'children', 'expanded', 'icon', 'id', 'leaf', 'Code', 'SubCode', 'Name_GA', 'Model_GA', 'Name_KCA', 'Model_KCA', 'Name_BOSCH', 'Model_BOSCH',
                     ],
                     proxy: {
                         type: 'ajax',
                         url: 'Handler.ashx?action=GetDeviceDBGridData&iot=' + iot
                     },
                     root: {
                         expanded: true,
                         text: 'ROOT',
                        allowDrag: false,
                        id: '-1'
                    }
                });

                tree = Ext.create('Ext.tree.Panel', {
                    id: 'Tree',
                    border: true,
                    store: store,
                    useArrows: true,
                    rootVisible: false,
                    multiSelect: false,
                    singleExpand: false,
                    viewConfig: {
                        stripeRows: true
                    },
                    sortableColumns: false,
                    tbar: [
                        {
                            xtype: 'tbtext',
                            text: '<%=GetGlobalResourceObject("CMSResource", "DeviceDB")%>'
                        }, {
                            text: 'Import',
                            cls: 'x-btn-default-small',
                            border: 1,
                            style: {
                                borderColor: 'gray',
                                borderStyle: 'solid'
                            },
                            handler: function () {
                                var win = Ext.create('Ext.window.Window', {
                                    title: 'Choose Import File',
                                    layout: 'fit',
                                    modal: true,
                                    constrain: true,
                                    shadow: true,
                                    shadowOffset: 50,
                                    width: 300,
                                    items: [
                                        {
                                            xtype: 'form',
                                            border: false,
                                            bodyPadding: 5,
                                            layout: 'anchor',
                                            url: 'ImportExport.ashx?action=Import&type=DeviceDB&iot=' + iot,
                                            defaults: {
                                                anchor: '100%',
                                                labelWidth: 60
                                            },
                                            items: [
                                                {
                                                    xtype: 'filefield',
                                                    name: 'uploadFile',
                                                    //fieldLabel: '<%=GetGlobalResourceObject("CMSResource", "Plan")%>',
                                                    labelWidth: 50,
                                                    msgTarget: 'side',
                                                    allowBlank: false,
                                                    anchor: '100%',
                                                    //buttonText: '<%=GetGlobalResourceObject("CMSResource", "ChoosePic")%>...',
                                                    vtype: 'file'
                                                }],
                                            buttons: [
                                                {
                                                    text: '<%=GetGlobalResourceObject("CMSResource", "OK")%>',
                                                    border: 1,
                                                    style: {
                                                        borderColor: 'gray',
                                                        borderStyle: 'solid'
                                                    },
                                                    formBind: false,
                                                    handler: function () {
                                                        var form = this.up("form");
                                                        form.submit({
                                                            waitMsg: '<%=GetGlobalResourceObject("CMSResource", "Saving")%>',
                                                            success: function () {
                                                                tree.getStore().load({ node: tree.getRootNode() });
                                                                win.close();
                                                            }
                                                        });
                                                    }
                                                }
                                            ]
                                        }
                                    ]
                                }).show();
                            }
                        },
                                                    {
                                                        text: 'Export',
                                                        cls: 'x-btn-default-small',
                                                        border: 1,
                                                        style: {
                                                            borderColor: 'gray',
                                                            borderStyle: 'solid'
                                                        },
                                                        handler: function () {
                                                            try {
                                                                parent.CMSClientDownload("/Apps/DeviceSystem/ImportExport.ashx?action=Export&type=DeviceDB&iot=" + iot);
                                                            } catch (e) {
                                                                window.open("ImportExport.ashx?action=Export&type=DeviceDB&iot=" + iot, "CMSDownloadIFrame");
                                                            }
                                                            
                                                        }
                                                    },
                        '->',
                        {
                            text: '<%=GetGlobalResourceObject("CMSResource", "NewDevice")%>',
                            id: 'NewDevice',
                            cls: 'x-btn-default-small',
                            border: 1,
                            style: {
                                borderColor: 'gray',
                                borderStyle: 'solid'
                            },
                            icon: '/Common/DMZ/Images/16x16/folder_add.png',
                            handler: function () {
                                ShowWin4Device("","");
                            }
                        },
                        {
                            text: '<%=GetGlobalResourceObject("CMSResource", "NewVersion")%>',
                            id: 'NewVersion',
                            cls: 'x-btn-default-small',
                            border: 1,
                            style: {
                                borderColor: 'gray',
                                borderStyle: 'solid'
                            },
                            icon: '/Common/DMZ/Images/16x16/form_add.png',
                            disabled: true,
                            handler: function () {
                                ShowWin4Version("", "");
                            }
                        }
                    ],
                    columns: [{
                        xtype: 'treecolumn',
                        text: 'Model(GA)　∕　DB Version',
                        flex: 1,
                        sortable: false,
                        dataIndex: 'Model_GA'
                    }, {
                        text: 'Name(GA)',
                        dataIndex: 'Name_GA',
                        sortable: false
                    }, {
                        text: 'Model ID',
                        dataIndex: 'Code',
                        width:40,
                        sortable: false
                    }, {
                        text: 'Model SubID',
                        dataIndex: 'SubCode',
                        width: 60,
                        sortable: false
                    }, {
                        text: 'Name(KCA)',
                        dataIndex: 'Name_KCA',
                        sortable: false,
                        hidden:true
                    }, {
                        text: 'Model(KCA)',
                        dataIndex: 'Model_KCA',
                        sortable: false,
                        hidden: true
                    }, {
                        text: 'Name(BOSCH)',
                        dataIndex: 'Name_BOSCH',
                        sortable: false,
                        hidden: true
                    }, {
                        text: 'Model(BOSCH)',
                        dataIndex: 'Model_BOSCH',
                        sortable: false,
                        hidden: true
                    }, {
                        xtype: 'actioncolumn',
                        width: 30,
                        sortable: false,
                        menuDisabled: true,
                        align: 'center',
                        items: [{
                            //icon: '/Common/DMZ/Images/16x16/application_link.png',
                            tooltip: '<%=GetGlobalResourceObject("CMSResource", "JSONStructure")%>',
                            scope: this,
                            getClass: function (v, meta, rec) {
                                if (!rec.get('leaf')) {
                                    return 'application_link-empty';
                                } else {
                                    return 'application_link';
                                }
                            },
                                handler: function (view, rowIndex, colIndex, item, e, record, row) {
                                    ShowWin4JSON(record.parentNode.get("Code"), record.parentNode.get("SubCode"), record.get("Model_GA"), record.get("id"), record.get("JSONcount"));
                                },
                                isDisabled: function (view, rowIndex, colIndex, item, record) {
                                    return !record.get("leaf");
                                }
                            }]
                    }, {
                        dataIndex: 'JSONcount',
                        width: 30,
                        sortable: false,
                        hidden: false,
                        renderer: function (value) {

                            return value == "0" ? "" : value;
                        }
                    }, {
                            xtype: 'actioncolumn',
                            width: 30,
                            sortable: false,
                            menuDisabled: true,
                            align: 'center',
                            items: [{
                                //icon: '/Common/DMZ/Images/16x16/edit.png',
                                tooltip: '<%=GetGlobalResourceObject("CMSResource", "Eidt")%>',
                                scope: this,
                                getClass: function (v, meta, rec) {
                                    if (rec.get('leaf')) {
                                        return 'edit-empty';
                                    } else {
                                        return 'edit';
                                    }
                                },
                                handler: function (view, rowIndex, colIndex, item, e, record, row) {
                                    if (record.get("leaf")) {
                                        //版本
                                        ShowWin4Version(record.get("Code"), record.get("SubCode"));
                                    } else {
                                        //設備
                                        ShowWin4Device(record.get("Code"), record.get("SubCode"));
                                    }
                                },
                                isDisabled: function (view, rowIndex, colIndex, item, record) {
                                    return record.get("leaf");
                                }
                            }]
                        },
                        {
                            xtype: 'actioncolumn',
                            width: 30,
                            sortable: false,
                            menuDisabled: true,
                            align: 'center',
                            items: [{
                                icon: '/Common/DMZ/Images/16x16/delete.png',
                                tooltip: '<%=GetGlobalResourceObject("CMSResource", "Delete")%>',
                                scope: this,
                                handler: function (view, rowIndex, colIndex, item, e, record, row) {
                                    if (confirm("<%=GetGlobalResourceObject("CMSResource", "SureDelete")%>【" + record.get("Model_GA") + "】？")) {

                                        if (record.get("leaf")) {
                                            //版次
                                            Ext.Ajax.request({
                                                url: 'Handler.ashx',
                                                params: {
                                                    iot:iot,
                                                    action: 'DelVersionData',
                                                    id: record.get("id")
                                                },
                                                success: function (response) {
                                                    var result = Ext.decode(response.responseText);
                                                    if (result.success) {
                                                        var node = tree.store.getNodeById(record.get("id"));
                                                        if (node) {
                                                            tree.store.load({ node: node.parentNode });


                                                        }

                                                    }

                                                }
                                            });
                                        }
                                        else {
                                            //設備
                                            Ext.Ajax.request({
                                                url: 'Handler.ashx',
                                                params: {
                                                    iot: iot,
                                                    action: 'DelDeviceData',
                                                    Code: record.get("Code"),
                                                    SubCode: record.get("SubCode")
                                                },
                                                success: function (response) {
                                                    var result = Ext.decode(response.responseText);
                                                    if (result.success) {
                                                        tree.store.load({ node: tree.store.getRootNode() });
                                                    }

                                                }
                                            });
                                        }


                                    }
                                }
                            }]
                        }],
                    listeners: {
                        'itemclick': function (tree, record, item, index, e, eOpts) {

                            var btnVersion = Ext.getCmp("NewVersion");
                            btnVersion.setDisabled(record.get("leaf"));
                         

                        }
                    }
                });

                Ext.create('Ext.container.Viewport', {
                    layout: {
                        type: 'fit'
                    },
                    items: tree
                });

                tree.getSelectionModel().select(0); //Select Root

             });

             function ShowWin4JSON(Code, SubCode, Version, id, selectedCount) {

                 var store1 = Ext.create('Ext.data.TreeStore', {
                     fields: [
                       'checked',  'children', 'expanded', 'icon', 'id', 'leaf', 'name', 'UIText', 'ObjType', 'content', 'default_value', 'ObjDesc', 'childrenCount'
                     ],
                     proxy: {
                         type: 'ajax',
                         url: 'Handler.ashx?action=GetAllJSONTree&code=' + Code + '&subCode=' + SubCode + '&version=' + Version + "&iot=" + iot
                     },
                     root: {
                         expanded: true,
                         name: 'Root',
                         allowDrag: false,
                         iconCls: 'treenode-no-icon',
                         id: '-1'
                     }
                 });

                 var tree1 = Ext.create('Ext.tree.Panel', {
                     //id: 'Tree',
                     border: false,
                     store: store1,
                     useArrows: true,
                     rootVisible: false,
                     //multiSelect: false,
                     //singleExpand: false,
                     viewConfig: {
                         stripeRows: true
                     },
                     //sortableColumns: false,
                         listeners: {
                     checkchange: function (node, checked) {

                         node.cascadeBy(function (child) {
                             child.set("checked", checked);
                         });
                         parentnode(node);

                         var selectedCount=0;
                         tree1.getRootNode().cascadeBy(function (child) {
                             if(child.get("checked")){
                                 selectedCount++;
                             }
                         });
                         
                         //Ext.getCmp("selectedCount").setText("<font color=red>已勾選 " + (selectedCount - 1) + " 個屬性</font>");
                         Ext.getCmp("selectedCount").setText("<font color=red>" + String.format('<%=GetGlobalResourceObject("CMSResource", "SelectedProp")%>', (selectedCount - 1)) + "</font>");
                     }
                         },
                         bbar: ['->',
                             {
                                 xtype: 'tbtext',
                                 id:'selectedCount',
                                 text: "<font color=red>" + String.format('<%=GetGlobalResourceObject("CMSResource", "SelectedProp")%>', selectedCount) + "</font>"
                             },
                             '->'
                         ],
                     columns: [{
                         xtype: 'treecolumn',
                         text: '<%=GetGlobalResourceObject("CMSResource", "PropID")%>',
                         flex: 2,
                         sortable: false,
                         dataIndex: 'name',
                         menuDisabled: true,
                         renderer: function (value, metaData, record) {

                             var tip = "";
                             switch (record.get("ObjType")) {
                                 case "0":
                                 case "6":
                                     tip = "&nbsp;&nbsp;<font color=gray>{" + record.get("childrenCount") + "}</font>";
                                     break;

                                 case "4":
                                 case "5":
                                     tip = "&nbsp;&nbsp;<font color=gray>[" + record.get("childrenCount") + "]</font>";
                                     break;
                             }

                             return record.get("name") + tip;
                         }
                     }, {
                         text: '<%=GetGlobalResourceObject("CMSResource", "PropName")%>',
                         dataIndex: 'UIText',
                         sortable: false,
                         flex: 1,
                         menuDisabled: true
                     }, {
                         text: '<%=GetGlobalResourceObject("CMSResource", "PropType")%>',
                         dataIndex: 'type',
                         width: 120,
                         sortable: false,
                         menuDisabled: true,
                         hidden: true,
                         renderer: function (value, metaData, record) {
                             switch (record.get("ObjType")) {
                                 case "0":
                                     return "<font color=#FFA500>Object</font>";
                                     break;
                                 case "1":
                                     return "<font color=#0000FF>String</font>";
                                     break;
                                 case "2":
                                     return "<font color=#008000>Option</font>";
                                     break;
                                 case "3":
                                     return "<font color=#800080>Number</font>";
                                     break;
                                 case "4":
                                     return "<font color=#808000>Object-Array</font>";
                                     break;
                                 case "5":
                                     return "<font color=#FF0000>String-Array</font>";
                                     break;
                                 case "6":
                                     return "<font color=gray>Template-Object</font>";
                                     break;
                             }

                         }
                     }, {
                         text: '<%=GetGlobalResourceObject("CMSResource", "OptionRange")%>',
                         dataIndex: 'content',
                         sortable: false,
                         menuDisabled: true,
                         renderer: function (value, metaData, record) {
                             var DispText = "";
                             switch (record.get("ObjType")) {
                                 case "0":
                                     break;
                                 case "1":
                                     break;
                                 case "2":
                                     Ext.Array.each(value.split("@"), function (v) {
                                         if (DispText != "") DispText = DispText + "<br>";

                                         if (record.get("default_value") == v.split("#")[1])
                                             DispText = DispText + "<b>" + v.split("#")[1] + " = " + v.split("#")[0] + "</b>";
                                         else
                                             DispText = DispText + v.split("#")[1] + " = " + v.split("#")[0];
                                     });
                                     break;
                                 case "3":
                                     DispText = value.split("@")[0] + " ～ " + value.split("@")[1];
                                     break;
                                 case "4":

                                     break;
                                 case "5":

                                     break;
                             }
                             return DispText;
                         }
                     }, {
                         text: '<%=GetGlobalResourceObject("CMSResource", "DefaultValue")%>',
                         dataIndex: 'default_value',
                         sortable: false,
                         width: 70,
                         menuDisabled: true
                     }, {
                         text: '<%=GetGlobalResourceObject("CMSResource", "Explanation")%>',
                         flex: 1,
                         dataIndex: 'ObjDesc',
                         sortable: false,
                         menuDisabled: true
                     }]
                 });

                 var w = Ext.create('Ext.window.Window', {
                     title: '<%=GetGlobalResourceObject("CMSResource", "JSONStructure")%>',
                     layout: 'fit',
                     modal: true,
                     constrain: true,
                     shadow: true,
                     shadowOffset: 50,
                     width: '80%',
                     height: '80%',
                     items: [tree1
                     ],
                     buttons: [
    {
        text: '<%=GetGlobalResourceObject("CMSResource", "Save")%>',
                             formBind: true,
                             handler: function () {
                                 var list = "";
                                 tree1.getRootNode().cascadeBy(function (child) {
                                     if (child.get("id") != tree1.getRootNode().get("id") && child.get("checked")) {
                                         if (list != "") list = list + ",";
                                         list = list + child.get("id");
                                     }
                                 });

                                 if (list != "") list ="-1," + list;

                                 Ext.Ajax.request({
                                     url: 'Handler.ashx',
                                     params: {
                                         iot: iot,
                                         action: 'SaveJSONLink',
                                         code: Code,
                                         subCode: SubCode,
                                         version: Version,
                                         list: list
                                     },
                                     success: function (response) {
                                         var result = Ext.decode(response.responseText);
                                         if (result.success) {
                                             tree.store.load({ node: tree.store.getNodeById(id).parentNode });
                                             w.close();
                                    
                                }

                            }
                                  });
                             }
                         },
                        {
                            text: '<%=GetGlobalResourceObject("CMSResource", "Cancel")%>',
                            handler: function () {
                                this.up("window").close();
                            }
                        }
                                          ]
                 }).show();

                 //var myMask = new Ext.LoadMask(w, { msg: "Please wait..." });
                 //store1.getRootNode().expand(true);
             }

             function ShowWin4Version(Code, SubCode) {

                 var title;
                 title = "<%=GetGlobalResourceObject("CMSResource", "NewVersion")%>";
                 var parentId = tree.getSelectionModel().getLastSelected().get("id");

                 var contentForm = Ext.create('Ext.form.Panel', {
                     border: false,
                     bodyPadding: 5,
                     layout: 'anchor',
                     url: 'Handler.ashx?action=SaveVersionData&iot=' + iot,
                     defaults: {
                         anchor: '100%',
                         labelWidth: 90
                     },
                     defaultType: 'textfield',
                     items: [{
                         xtype: 'hiddenfield',
                         name: 'Code',
                         value: tree.getSelectionModel().getLastSelected().get("Code")
                     }, {
                         xtype: 'hiddenfield',
                         name: 'SubCode',
                         value: tree.getSelectionModel().getLastSelected().get("SubCode")
                     }, {
                         fieldLabel: '<b>Version</b>',
                         name: 'Version',
                         id: 'Version',
                         allowBlank: false
                     } ],
                     buttons: [
                         {
                             text: '<%=GetGlobalResourceObject("CMSResource", "Save")%>',
                            formBind: true,
                            handler: function () {
                                var form = this.up('form').getForm();

                                if (form.isValid()) {
                                    form.submit({
                                        success: function (f, action) {
                                            var node = tree.store.getNodeById(parentId);
                                            if (node) {
                                                if (!node.isExpanded()) node.expand();
                                                tree.store.load({ node: node });
                                                
                                                
                                            }
                                            w.close();
                                        },
                                        failure: function (f, action) {

                                        }
                                    });
                                }
                            }
                        },
                        {
                            text: '<%=GetGlobalResourceObject("CMSResource", "Cancel")%>',
                            handler: function () {
                                this.up("window").close();
                            }
                        }
                    ]
                });

                var w = Ext.create('Ext.window.Window', {
                    title: title,
                    layout: 'fit',
                    modal: true,
                    constrain: true,
                    shadow: true,
                    shadowOffset: 50,
                    width: 200,
                    items: contentForm
                }).show();
                Ext.getCmp('Version').focus(false, 200);
            }

             function ShowWin4Device(Code, SubCode) {

                 var title;
                 title = Code == "" ? "<%=GetGlobalResourceObject("CMSResource", "NewDevice")%>" : "<%=GetGlobalResourceObject("CMSResource", "ModifyDevice")%>";

                var contentForm = Ext.create('Ext.form.Panel', {
                    border: false,
                    bodyPadding: 5,
                    layout: 'anchor',
                    url: 'Handler.ashx?action=SaveDeviceData&iot=' + iot,
                    defaults: {
                        anchor: '100%',
                        labelWidth: 90
                    },
                    defaultType: 'textfield',
                    items: [{
                        xtype: 'hiddenfield',
                        name: 'isUpdate',
                        value: Code==""?"0":"1"
                    },{
                        fieldLabel: '<b>Model ID</b>',
                        name: 'Code',
                        id: 'Code',
                        anchor: '50%',
                        readOnly: Code != "",
                        allowBlank: false
                    }, {
                        fieldLabel: 'Model SubID',
                        name: 'SubCode',
                        id: 'SubCode',
                        anchor: '50%',
                        readOnly: Code != ""
                    }, {
                        fieldLabel: '<b>Name(GA)</b>',
                        name: 'Name_GA',
                        id: 'Name_GA',
                        allowBlank: false
                    }, {
                        fieldLabel: '<b>Model(GA)</b>',
                        name: 'Model_GA',
                        id: 'Model_GA',
                        allowBlank: false
                    }, {
                        fieldLabel: 'Name(KCA)',
                        name: 'Name_KCA',
                        id: 'Name_KCA'
                    }, {
                        fieldLabel: 'Model(KCA)',
                        name: 'Model_KCA',
                        id: 'Model_KCA'
                    }, {
                        fieldLabel: 'Name(BOSCH)',
                        name: 'Name_BOSCH',
                        id: 'Name_BOSCH'
                    }, {
                        fieldLabel: 'Model(BOSCH)',
                        name: 'Model_BOSCH',
                        id: 'Model_BOSCH'
                    }, {
                        xtype: 'radiogroup',
                        fieldLabel: '<%=GetGlobalResourceObject("CMSResource", "Icon")%>',
                        columns: 5,
                        vertical: true,
                        items: [
                             { boxLabel: '<img src=/Common/DMZ/Images/16x16/gt_admin.png>', name: 'Icon', inputValue: 'gt_admin' },
                              { boxLabel: '<img src=/Common/DMZ/Images/16x16/gt_bdoor.png>', name: 'Icon', inputValue: 'gt_bdoor' },
                               { boxLabel: '<img src=/Common/DMZ/Images/16x16/gt_home.png>', name: 'Icon', inputValue: 'gt_home', checked: true },
                                { boxLabel: '<img src=/Common/DMZ/Images/16x16/gt_sdoor.png>', name: 'Icon', inputValue: 'gt_sdoor' },
                            { boxLabel: '<img src=/Common/DMZ/Images/16x16/network_hub.png>', name: 'Icon', inputValue: 'network_hub' },
                            { boxLabel: '<img src=/Common/DMZ/Images/16x16/device-desktop.png>', name: 'Icon', inputValue: 'device-desktop' },
                            { boxLabel: '<img src=/Common/DMZ/Images/16x16/kfm_home.png>', name: 'Icon', inputValue: 'kfm_home' },
                            { boxLabel: '<img src=/Common/DMZ/Images/16x16/admin_phone.png>', name: 'Icon', inputValue: 'admin_phone' },
                            { boxLabel: '<img src=/Common/DMZ/Images/16x16/cctv_camera.png>', name: 'Icon', inputValue: 'cctv_camera' }
                        ]
                    }
                    ],
                    buttons: [
                        {
                            text: '<%=GetGlobalResourceObject("CMSResource", "Save")%>',
                            formBind: true,
                            handler: function () {
                                var form = this.up('form').getForm();

                                if (form.isValid()) {
                                    form.submit({
                                        success: function (f, action) {
                                            tree.store.load({ node: tree.store.getRootNode() });
                                            w.close();
                                        },
                                        failure: function (f, action) {

                                        }
                                    });
                                }
                            }
                        },
                        {
                            text: '<%=GetGlobalResourceObject("CMSResource", "Cancel")%>',
                            handler: function () {
                                this.up("window").close();
                            }
                        }
                    ]
                });

                if (Code != "") {
                    contentForm.getForm().load({
                        url: 'Handler.ashx?action=GetDeviceData&Code=' + Code + '&SubCode=' + SubCode + "&iot=" + iot
                    });
                }

                var w = Ext.create('Ext.window.Window', {
                    title: title,
                    layout: 'fit',
                    modal: true,
                    constrain: true,
                    shadow: true,
                    shadowOffset: 50,
                    width: 400,
                    items: contentForm
                }).show();
                Ext.getCmp('Code').focus(false, 200);
            }

             var nodep = function (node) {
                 var bnode = false;
                 Ext.Array.each(node.childNodes, function (v) {
                     if (v.data.checked) {
                         bnode = true;
                         return;
                     }
                 });
                 return bnode;
             };
             var parentnode = function (node) {
                 if (node.parentNode != null) {
                     if (nodep(node.parentNode)) {
                         node.parentNode.set('checked', true);
                     } else {
                         node.parentNode.set('checked', false);
                     }
                     parentnode(node.parentNode);
                 }
             };
        </script>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
        <iframe id="CMSDownloadIFrame" name="CMSDownloadIFrame" style="width:0px;height:0px"></iframe>
    </form>
</body>
</html>
