{
    "type": "Ext.data.TreeStore",
    "reference": {
        "name": "items",
        "type": "array"
    },
    "codeClass": null,
    "userConfig": {
        "autoLoad": true,
        "autoSync": true,
        "designer|userClassName": "CurrentRuleTreeStore",
        "filterOnLoad": null,
        "model": "CurrentRuleTreeModel",
        "remoteSort": null,
        "singleton": null,
        "sortOnLoad": null,
        "storeId": "IdCurrentRuleTreeStore"
    },
    "designerId": "b8519316-aaa6-4c50-a604-29e339d91617",
    "cn": [
        {
            "type": "Ext.data.proxy.Ajax",
            "reference": {
                "name": "proxy",
                "type": "object"
            },
            "codeClass": null,
            "userConfig": {
                "url": "../../service/common_risk_treestore.php"
            },
            "designerId": "57afd859-1fbb-4ad8-8586-20cfad2eef63",
            "cn": [
                {
                    "type": "Ext.data.reader.Json",
                    "reference": {
                        "name": "reader",
                        "type": "object"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "idProperty": "tree_id"
                    },
                    "designerId": "b18f3bee-d50e-4eb3-a139-9d4c87322410"
                }
            ]
        },
        {
            "type": "basiceventbinding",
            "reference": {
                "name": "listeners",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "buffer": null,
                "fn": "onTreeStoreBeforeLoad",
                "implHandler": [
                    "var params = Ext.Object.fromQueryString(document.location.search);\r",
                    "params.risktype = \"crit_role\";\r",
                    "var extra = store.proxy.extraParams;\r",
                    "var newParams = Ext.Object.merge(params, extra);\r",
                    "store.proxy.extraParams = newParams;"
                ],
                "name": "beforeload",
                "scope": "me"
            },
            "designerId": "652d116b-46c6-42fe-a6c8-17bcfa0e316f"
        },
        {
            "type": "basiceventbinding",
            "reference": {
                "name": "listeners",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "onTreeStoreLoad",
                "implHandler": [
                    "var urlParams = Ext.Object.fromQueryString(document.location.search);\r",
                    "\r",
                    "//expand last selected (in order to expand after add)\r",
                    "var grid = Ext.ComponentQuery.query('#treegrid')[0];\r",
                    "var model = grid.getSelectionModel();\r",
                    "var lastSelected = model.getLastSelected();\r",
                    "if(lastSelected !== undefined && lastSelected !== null) {\r",
                    "\tvar record;\r",
                    "\tif(lastSelected.data.groupId === \"\") {\r",
                    "\t\trecord = treestore.getRootNode().findChild('id', lastSelected.data.id, true);\r",
                    "\t} else {\r",
                    "\t\trecord = treestore.getRootNode().findChild('ruleId', lastSelected.data.ruleId, true);\r",
                    "\t\tvar group = treestore.getRootNode().findChild('id', record.data.groupId, true);\r",
                    "\t\tgrid.expand(group);\r",
                    "\t\tgroup.expand();\r",
                    "\t}\r",
                    "\r",
                    "\tmodel.doSelect(record);\r",
                    "\tgrid.expand(record);\r",
                    "\trecord.expand();\r",
                    "}\r",
                    "else if(urlParams.risk_id) { //find risk with the id transferred from another page (lagecy)\r",
                    "\tvar groups = treestore.getRootNode().childNodes;\r",
                    "\tExt.Array.each(groups, function(group) {\r",
                    "\t\tvar record = group.findChild('id', urlParams.risk_id);\r",
                    "\t\tif(!Ext.isEmpty(record)) {\r",
                    "\t\t\tgroup.expand();\r",
                    "\t\t\trecord.expand();\r",
                    "\t\t\tmodel.doSelect(record);\r",
                    "\t\t}\r",
                    "\t});\r",
                    "\t//cleanup url\r",
                    "\tdelete urlParams.risk_id;\r",
                    "\twindow.history.pushState(urlParams, document.title, location.protocol + '//' + location.host +\r",
                    "\t\t\t\t\t\t\tlocation.pathname +\"?\"+ Ext.urlEncode(urlParams) );\r",
                    "}\r",
                    "treestore.proxy.extraParams = Ext.Object.fromQueryString(document.location.search);\r",
                    "MyApp.app.getController('GUIController').selectionHasChanged();"
                ],
                "name": "load",
                "scope": "me"
            },
            "designerId": "ce7a5dcd-0f09-4f49-b05f-aad4eede071c"
        },
        {
            "type": "basiceventbinding",
            "reference": {
                "name": "listeners",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "onTreeStoreWrite",
                "implHandler": [
                    "var record = operation.records[0];\r",
                    "//select rule or group record\r",
                    "if(!record.isLeaf() && operation.action == \"create\") {\r",
                    "\tvar grid  = Ext.ComponentQuery.query('#treegrid')[0];\r",
                    "\tvar model = grid.getSelectionModel();\r",
                    "\tmodel.doSelect(record);\r",
                    "\tgrid.expand(record);\r",
                    "}"
                ],
                "name": "write",
                "scope": "me"
            },
            "designerId": "c665e7a5-1eee-4f5c-a55a-f5bdf3db267d"
        },
        {
            "type": "basiceventbinding",
            "reference": {
                "name": "listeners",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "onTreeStoreBeforeSync",
                "implHandler": [
                    "var store = eOpts.scope;\r",
                    "var params = Ext.Object.fromQueryString(document.location.search);\r",
                    "params.risktype = \"crit_role\";\r",
                    "store.proxy.extraParams = params;"
                ],
                "name": "beforesync",
                "scope": "me"
            },
            "designerId": "eb2ddfe9-e8ed-4a43-958e-4ddfef76b02a"
        }
    ]
}