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

<!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;
}
    </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 = /^.*\.(JSONDB)$/i;
                            return fileName.test(val);
                        },
                        // vtype Text property to display error Text
                        // when the validation function returns false
                        fileText: "File must be .JSONDB",
                        // vtype Mask property for keystroke filter mask
                        fileMask: /[a-z_\.]/i
                    });

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

                    tree = Ext.create('Ext.tree.Panel', {
                        id: 'Tree',
                        border: true,
                        store: store,
                        useArrows: true,
                        rootVisible: true,
                        multiSelect: false,
                        singleExpand: false,
                        viewConfig: {
                            stripeRows: true
                        },
                        sortableColumns: false,
                        tbar: [
                            {
                                xtype: 'tbtext',
                                text: '<%=GetGlobalResourceObject("CMSResource", "DeviceJSON")%>'
                            },
                             {
                                 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=JSONDB&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=JSONDB&iot=" + iot);
                                    } catch (e) {
                                        window.open("ImportExport.ashx?action=Export&type=JSONDB&iot=" + iot, "CMSDownloadIFrame");
                                    }
                                    //window.open("ImportExport.ashx?action=Export&type=JSONDB", "CMSDownloadIFrame");
                                }
                            },
                            '->',
                                                    {
                                                        text: 'New Object',
                                                        id: 'NewObject',
                                                        cls: 'x-btn-default-small',
                                                        border: 1,
                                                        style: {
                                                            borderColor: 'gray',
                                                            borderStyle: 'solid'
                                                        },
                                                        icon: '/Common/DMZ/Images/16x16/folder_add.png',
                                                        handler: function () {
                                                            ShowWin("", "0");
                                                        }
                                                    },
                            {
                                text: 'New String',
                                id: 'NewString',
                                cls: 'x-btn-default-small',
                                border: 1,
                                style: {
                                    borderColor: 'gray',
                                    borderStyle: 'solid'
                                },
                                disabled:true,
                                icon: '/Common/DMZ/Images/16x16/folder_add.png',
                                handler: function () {
                                    ShowWin("", "1");
                                }
                            },

                             {
                                 text: 'New Option',
                                 id: 'NewOption',
                                 cls: 'x-btn-default-small',
                                 border: 1,
                                 style: {
                                     borderColor: 'gray',
                                     borderStyle: 'solid'
                                 },
                                 disabled: true,
                                 icon: '/Common/DMZ/Images/16x16/folder_add.png',
                                 handler: function () {
                                     ShowWin("", "2");
                                 }
                             },
                             {
                                 text: 'New Number',
                                 id: 'NewNumber',
                                 cls: 'x-btn-default-small',
                                 border: 1,
                                 style: {
                                     borderColor: 'gray',
                                     borderStyle: 'solid'
                                 },
                                 disabled: true,
                                 icon: '/Common/DMZ/Images/16x16/folder_add.png',
                                 handler: function () {
                                     ShowWin("", "3");
                                 }
                             }, {
                                 text: 'New Object-Array',
                                 id: 'NewObjectArray',
                                 cls: 'x-btn-default-small',
                                 border: 1,
                                 style: {
                                     borderColor: 'gray',
                                     borderStyle: 'solid'
                                 },
                                 icon: '/Common/DMZ/Images/16x16/folder_add.png',
                                 handler: function () {
                                     ShowWin("", "4");
                                 }
                             },
                             {
                                 text: 'New String-Array',
                                 id: 'NewStringArray',
                                 cls: 'x-btn-default-small',
                                 border: 1,
                                 style: {
                                     borderColor: 'gray',
                                     borderStyle: 'solid'
                                 },
                                 disabled: true,
                                 icon: '/Common/DMZ/Images/16x16/folder_add.png',
                                 handler: function () {
                                     ShowWin("", "5");
                                 }
                             },
                             {
                                 text: 'New Customize-Option',
                                 id: 'NewCustomizeOption',
                                 cls: 'x-btn-default-small',
                                 border: 1,
                                 style: {
                                     borderColor: 'gray',
                                     borderStyle: 'solid'
                                 },
                                 disabled: true,
                                 hidden: true,
                                 icon: '/Common/DMZ/Images/16x16/folder_add.png',
                                 handler: function () {
                                     ShowWin("", "7");
                                 }
                             }
                        ],
                        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,

                        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;
                                case "7":
                                    return "<font color=#008000>Customize-Option</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;
                                case "7":
                                    DispText = "Customize-Option";
                                    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
                    },
                        {
                            xtype: 'actioncolumn',
                            width: 30,
                            sortable: false,
                            menuDisabled: true,
                            align: 'center',
                            items: [{
                                icon: '/Common/DMZ/Images/16x16/edit.png',
                                tooltip: '<%=GetGlobalResourceObject("CMSResource", "Eidt")%>',
                                scope: this,
                                handler: function (view, rowIndex, colIndex, item, e, record, row) {
                                    ShowWin(record.get("id"), record.get("ObjType"));
                                },
                                isDisabled: function (view, rowIndex, colIndex, item, record) {
                                    return rowIndex == 0 || record.get("ObjType")=="6";
                                }
                            }]
                        },
                        {
                            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("name") + "】？")) {
                                        var node = tree.store.getNodeById(record.get("id"));

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

                                            }
                                        });
                                    }
                                },
                                isDisabled: function (view, rowIndex, colIndex, item, record) {
                                    return rowIndex == 0 || record.get("ObjType") == "6";
                                }
                            }]
                        }, {
                            xtype: 'actioncolumn',
                            width: 30,
                            sortable: false,
                            menuDisabled: true,
                            align: 'center',
                            items: [{
                                icon: '/Common/DMZ/Images/16x16/arrow_up.png',
                                tooltip: '<%=GetGlobalResourceObject("CMSResource", "UpLayer")%>',
                                scope: this,
                                handler: function (view, rowIndex, colIndex, item, e, record, row) {
                                    var node = tree.store.getNodeById(record.get("id"));
                                    var parentNode = node.parentNode;
                                    if (parentNode.indexOf(node) == 0) {
                                        return;
                                    }

                                    var newIndex = parentNode.indexOf(node) - 1;
                                    parentNode.insertChild(newIndex, node);

                                    Save2Server(parentNode);
                                },
                                isDisabled: function (view, rowIndex, colIndex, item, record) {
                                    return rowIndex == 0 || record.get("ObjType") == "6";
                                }
                            }]
                        },
                        {
                            xtype: 'actioncolumn',
                            width: 30,
                            sortable: false,
                            menuDisabled: true,
                            align: 'center',
                            items: [{
                                icon: '/Common/DMZ/Images/16x16/arrow_down.png',
                                tooltip: '<%=GetGlobalResourceObject("CMSResource", "DownLayer")%>',
                                scope: this,
                                handler: function (view, rowIndex, colIndex, item, e, record, row) {
                                    var node = tree.store.getNodeById(record.get("id"));
                                    var parentNode = node.parentNode;
                                    if (parentNode.indexOf(node) == parentNode.childNodes.length - 1) {
                                        return;
                                    }

                                    var newIndex = parentNode.indexOf(node) + 2;
                                    parentNode.insertChild(newIndex, node);
                                    Save2Server(parentNode);
                                },
                                isDisabled: function (view, rowIndex, colIndex, item, record) {
                                    return rowIndex == 0 || record.get("ObjType") == "6";
                                }
                            }]
                        }],
                    listeners: {
                        'itemclick': function (tree, record, item, index, e, eOpts) {
                            var NewObject = Ext.getCmp("NewObject");
                            var NewString = Ext.getCmp("NewString");
                            var NewOption = Ext.getCmp("NewOption");
                            var NewNumber = Ext.getCmp("NewNumber");
                            var NewObjectArray = Ext.getCmp("NewObjectArray");
                            var NewStringArray = Ext.getCmp("NewStringArray");
                            var NewCustomizeOption = Ext.getCmp("NewCustomizeOption");
                            switch (record.get("ObjType")) {
                                case "0":
                                    NewObject.setDisabled(false);
                                    NewString.setDisabled(false);
                                    NewOption.setDisabled(false);
                                    NewNumber.setDisabled(false);
                                    NewObjectArray.setDisabled(false);
                                    NewStringArray.setDisabled(false);
                                    NewCustomizeOption.setDisabled(false);
                                    break;
                                case "1":
                                    NewObject.setDisabled(true);
                                    NewString.setDisabled(true);
                                    NewOption.setDisabled(true);
                                    NewNumber.setDisabled(true);
                                    NewObjectArray.setDisabled(true);
                                    NewStringArray.setDisabled(true);
                                    NewCustomizeOption.setDisabled(true);
                                    break;
                                case "2":
                                    NewObject.setDisabled(true);
                                    NewString.setDisabled(true);
                                    NewOption.setDisabled(true);
                                    NewNumber.setDisabled(true);
                                    NewObjectArray.setDisabled(true);
                                    NewStringArray.setDisabled(true);
                                    NewCustomizeOption.setDisabled(true);
                                    break;
                                case "3":
                                    NewObject.setDisabled(true);
                                    NewString.setDisabled(true);
                                    NewOption.setDisabled(true);
                                    NewNumber.setDisabled(true);
                                    NewObjectArray.setDisabled(true);
                                    NewStringArray.setDisabled(true);
                                    NewCustomizeOption.setDisabled(true);
                                    break;
                                case "4":
                                    NewObject.setDisabled(true);
                                    NewString.setDisabled(true);
                                    NewOption.setDisabled(true);
                                    NewNumber.setDisabled(true);
                                    NewObjectArray.setDisabled(true);
                                    NewStringArray.setDisabled(true);
                                    NewCustomizeOption.setDisabled(true);
                                    break;
                                case "5":
                                    NewObject.setDisabled(true);
                                    NewString.setDisabled(true);
                                    NewOption.setDisabled(true);
                                    NewNumber.setDisabled(true);
                                    NewObjectArray.setDisabled(true);
                                    NewStringArray.setDisabled(true);
                                    NewCustomizeOption.setDisabled(true);
                                    break;
                                case "6":
                                    NewObject.setDisabled(true);
                                    NewString.setDisabled(false);
                                    NewOption.setDisabled(false);
                                    NewNumber.setDisabled(false);
                                    NewObjectArray.setDisabled(true);
                                    NewStringArray.setDisabled(true);
                                    NewCustomizeOption.setDisabled(false);
                                    break;
                                case "7":
                                    NewObject.setDisabled(true);
                                    NewString.setDisabled(true);
                                    NewOption.setDisabled(true);
                                    NewNumber.setDisabled(true);
                                    NewObjectArray.setDisabled(true);
                                    NewStringArray.setDisabled(true);
                                    NewCustomizeOption.setDisabled(true);
                                    break;
                            }

                            if (index == 0) {
                                //ROOT
                                NewObject.setDisabled(false);
                                NewString.setDisabled(true);
                                NewOption.setDisabled(true);
                                NewNumber.setDisabled(true);
                                NewObjectArray.setDisabled(false);
                                NewStringArray.setDisabled(true);
                            }
                        }
                    }
                });

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

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

            });

                function ShowWin(ident, type) {
                    var parentId = tree.getSelectionModel().getLastSelected().get("id");
                    var title;

                    switch (type) {

                        case "0":   //Object
                            title = ident == '' ? 'New Object' : 'Modify Object';
                            break;

                        case "1":   //String
                            title = ident == '' ? 'New String' : 'Modify String';
                            break;


                        case "2":   //Option
                            title = ident == '' ? 'New Option' : 'Modify Option';
                            break;

                        case "3":   //Number
                            title = ident == '' ? 'New Number' : 'Modify Number';
                            break;

                        case "4":   //Object Array
                            title = ident == '' ? 'New Object-Array' : 'Modify Object-Array';
                            break;

                        case "5":   //String Array
                            title = ident == '' ? 'New String-Array' : 'Modify String-Array';
                            break;

                        case "7":   //String Array
                            title = ident == '' ? 'New Customize-Option' : 'Modify Customize-Option';
                            break;
                    }

                    

                    var contentForm = Ext.create('Ext.form.Panel', {
                        border: false,
                        bodyPadding: 5,
                        layout: 'anchor',
                        url: 'Handler.ashx?action=SaveJSONData&iot=' + iot,
                        defaults: {
                            anchor: '100%',
                            labelWidth: 70
                        },
                        defaultType: 'textfield',
                        items: [{
                            xtype: 'hiddenfield',
                            name: 'parentId',
                            value: parentId
                        }, {
                            xtype: 'hiddenfield',
                            name: 'ident',
                            value: ident
                        }, {
                            xtype: 'hiddenfield',
                            name: 'ObjType',
                            id: 'ObjType',
                            value: type
                        }, {
                            xtype: 'hiddenfield',
                            name: 'isFolder',
                            value: (type == "0" || type == "4" || type == "5") ? 1 : 0
                        }, {
                            fieldLabel: '<%=GetGlobalResourceObject("CMSResource", "PropID")%>',
                            name: 'name',
                            id: 'name',
                            allowBlank: false
                        }, {
                            fieldLabel: '<%=GetGlobalResourceObject("CMSResource", "PropName")%>',
                            name: 'UIText',
                            id: 'UIText',
                            allowBlank: false
                        },
                        {
                            xtype: 'hiddenfield',
                            name: 'optionValues',
                            id: 'optionValues'
                        },
                        {
                            xtype: 'grid',
                            id: 'optionGrid',
                            viewConfig: {
                                markDirty: false
                            },
                            title: '<%=GetGlobalResourceObject("CMSResource", "Options")%>',
                            store: Ext.create('Ext.data.Store', {
                                fields: ['optName', 'value'],
                                data: {
                                    'items': [
               { 'optName': '', "value": "" },
               { 'optName': '', "value": "" },
               { 'optName': '', "value": "" },
                { 'optName': '', "value": "" },
                 { 'optName': '', "value": "" },
                  { 'optName': '', "value": "" },
                   { 'optName': '', "value": "" },
                    { 'optName': '', "value": "" },
                     { 'optName': '', "value": "" },
                      { 'optName': '', "value": "" },
                       { 'optName': '', "value": "" },
                        { 'optName': '', "value": "" },
                         { 'optName': '', "value": "" },
                          { 'optName': '', "value": "" },
                           { 'optName': '', "value": "" },
                            { 'optName': '', "value": "" },
                             { 'optName': '', "value": "" },
                              { 'optName': '', "value": "" },
                               { 'optName': '', "value": "" },
                                { 'optName': '', "value": "" }
                                    ]
                                },
                                proxy: {
                                    type: 'memory',
                                    reader: {
                                        type: 'json',
                                        root: 'items'
                                    }
                                }
                            }),
                            selType: 'cellmodel',
                            plugins: [
                                Ext.create('Ext.grid.plugin.CellEditing', {
                                    clicksToEdit: 1
                                })
                            ],
                            columns: [

           {
               text: 'Value', dataIndex: 'value',width:50, editor: {
                   xtype: 'textfield'
               }
           },
                  {
                      text: 'Name', dataIndex: 'optName', flex: 1, editor: {
                          xtype: 'textfield'
                      }
                  }
                            ],
                            height: 200,
                            columnLines: true,
                            padding: '0 0 5 0',
                            hidden: type != '2'
                        },
                        {
                            fieldLabel: '<%=GetGlobalResourceObject("CMSResource", "Min")%>',
                            xtype: 'numberfield',
                            name: 'minValue',
                            id: 'minValue',
                            hidden: type != '3',
                            allowBlank: type != '3'
                        },
                          {
                              fieldLabel: '<%=GetGlobalResourceObject("CMSResource", "Max")%>',
                              xtype: 'numberfield',
                              name: 'maxValue',
                              id: 'maxValue',
                              hidden: type != '3',
                              allowBlank: type != '3'
                          },
                         {
                             fieldLabel: '<%=GetGlobalResourceObject("CMSResource", "DefaultValue")%>',
                             name: 'DefaultValue',
                             allowBlank: true,
                             hidden: type == '0' || type == '4' || type == '5'
                         },
                         {
                             fieldLabel: '<%=GetGlobalResourceObject("CMSResource", "Explanation")%>',
                             name: 'ObjDesc',
                             allowBlank: true
                         }],
                        buttons: [
                            {
                                text: '<%=GetGlobalResourceObject("CMSResource", "Save")%>',
                                formBind: true,
                                handler: function () {
                                    var form = this.up('form').getForm();

                                    if (form.isValid()) {

                                        var gridList = "";
                                        Ext.getCmp("optionGrid").store.each(function (record) {
                                            if (record.get("optName") != "" && record.get("value") != "") {
                                                if (gridList != "") gridList = gridList + "@";
                                                gridList = gridList + record.get("optName") + "#" + record.get("value");
                                            }
                                        });

                                        Ext.getCmp("optionValues").setValue(gridList);

                                        form.submit({
                                            success: function (f, action) {
                                                var node;
                                                if (ident == "") {
                                                    node = tree.store.getNodeById(parentId);
                                                    if (node) {
                                                        tree.store.load({ node: node });
                                                    }
                                                }
                                                else {
                                                    node = tree.store.getNodeById(ident);
                                                    if (node) {
                                                        tree.store.load({ node: node.parentNode });
                                                    }
                                                }
                                                w.close();
                                            },
                                            failure: function (f, action) {

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

                if (ident != "") {
                    contentForm.getForm().load({
                        url: 'Handler.ashx?action=GetJSONData&ident=' + ident + "&iot=" + iot,
                        success: function () {
                            var content = Ext.getCmp("optionValues").getValue();

                            switch (Ext.getCmp("ObjType").getValue()) {
                                case "2":
                                    //Option
                                    if (content != "") {
                                        var cnt = 0;
                                        Ext.getCmp("optionGrid").store.removeAll();
                                        Ext.Array.each(content.split("@"), function (v) {
                                            Ext.getCmp("optionGrid").store.insert(cnt, { value: v.split("#")[1], optName: v.split("#")[0] });
                                            cnt++;
                                        });

                                        for (var i = cnt; i < 20; i++) {
                                            Ext.getCmp("optionGrid").store.insert(i, { value: '', optName: '' });
                                        }
                                    }
                                    
                                    break;

                                case "3":
                                    //Number
                                    if (content != "") {
                                        Ext.getCmp("minValue").setValue(content.split("@")[0]);
                                        Ext.getCmp("maxValue").setValue(content.split("@")[1]);
                                    }


                                    break;
                            }
                        }
                    });
                }

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

                function Save2Server(parentNode) {
                    var list = "";
                    parentNode.eachChild(function (n) {
                        if (list != "") list = list + ",";
                        list = list + n.get("id");
                    });


                    Ext.Ajax.request({
                        url: 'Handler.ashx',
                        params: {
                            iot:iot,
                            action: 'SortJSONData',
                            list: list
                        },
                        success: function (response) {

                        }
                    });
                }
        </script>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
        <iframe id="CMSDownloadIFrame" name="CMSDownloadIFrame" style="width:0px;height:0px"></iframe>
    </form>
</body>
</html>
