{
    "type": "Ext.app.Controller",
    "reference": {
        "name": "items",
        "type": "array"
    },
    "codeClass": null,
    "userConfig": {
        "designer|userAlias": "RiskSearchController",
        "designer|userClassName": "RiskSearchController"
    },
    "designerId": "73f2419c-f577-4b68-be6a-e6dfc02f679c",
    "cn": [
        {
            "type": "fixedfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "application"
                ],
                "fn": "init",
                "implHandler": [
                    "//add listener to treegrid\r",
                    "this.control({\r",
                    "\t'#searchGroupCombo': {\r",
                    "\t\tspecialkey: function(field, e) {\r",
                    "\t\t\tif (e.getKey() == e.ENTER) {\r",
                    "\t\t\t\tthis.prepareSearch();\r",
                    "\t\t\t}\r",
                    "\t\t}\r",
                    "\t},\r",
                    "    '#searchRiskIdTrigger': {\r",
                    "\t\tspecialkey: function(field, e) {\r",
                    "\t\t\tif (e.getKey() == e.ENTER) {\r",
                    "\t\t\t\tthis.prepareSearch();\r",
                    "\t\t\t}\r",
                    "\t\t}\r",
                    "    },\r",
                    "\t'#searchNameTrigger': {\r",
                    "\t\tspecialkey: function(field, e) {\r",
                    "\t\t\tif (e.getKey() == e.ENTER) {\r",
                    "\t\t\t\tthis.prepareSearch();\r",
                    "\t\t\t}\r",
                    "\t\t}\r",
                    "\t},\r",
                    "\t'#searchContentTrigger': {\r",
                    "\t\tspecialkey: function(field, e) {\r",
                    "\t\t\tif (e.getKey() == e.ENTER) {\r",
                    "\t\t\t\tthis.prepareSearch();\r",
                    "\t\t\t}\r",
                    "\t\t}\r",
                    "\t}\r",
                    "});\r",
                    ""
                ]
            },
            "designerId": "bdca8409-f928-4156-8ba0-0368a6c43bb2"
        },
        {
            "type": "fixedfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "onLaunch",
                "implHandler": [
                    "this.getTreegrid().addDocked({\r",
                    "    xtype: 'RiskSearchToolBar',\r",
                    "    dock: 'bottom'\r",
                    "});\r",
                    "var me = this;\r",
                    "this.getSearchRiskIdTrigger().onTriggerClick = function(event) {\r",
                    "\tme.prepareSearch();\r",
                    "};\r",
                    "this.getSearchNameTrigger().onTriggerClick = function(event) {\r",
                    "\tme.prepareSearch();\r",
                    "};\r",
                    "this.getSearchContentTrigger().onTriggerClick = function(event) {\r",
                    "\tme.prepareSearch();\r",
                    "};\r",
                    "this.getSearchRiskIdTrigger().focus();"
                ]
            },
            "designerId": "1924dcce-3dce-4548-9e15-162c8a3aad4a"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "prepareSearch",
                "implHandler": [
                    "this.getSearchGroupCombo().disable();\r",
                    "this.getSearchRiskIdTrigger().disable();\r",
                    "this.getSearchNameTrigger().disable();\r",
                    "this.getSearchContentTrigger().disable();\r",
                    "this.getTreegrid().setLoading(CCS.Translator.getText('Loading...'));\r",
                    "this.getTreegrid().collapseAll();\r",
                    "\r",
                    "//delay actual search so tree has time to both collapse and setLoading\r",
                    "var me = this;\r",
                    "setTimeout(function() {\r",
                    "    me.search();\r",
                    "}, 400);"
                ]
            },
            "designerId": "8f9f556d-aea1-4623-9a53-3d6eef41d337"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "search",
                "implHandler": [
                    "this.getTreegrid().suspendLayout = true;\r",
                    "var grpsearch = this.getSearchGroupCombo().getValue();\r",
                    "var intsearch = parseInt(this.getSearchRiskIdTrigger().getValue(), 10);\r",
                    "var chrsearch = this.getSearchRiskIdTrigger().getValue();\r",
                    "var namesearch= this.getSearchNameTrigger().getValue().toUpperCase();\r",
                    "var contsearch= this.getSearchContentTrigger().getValue().toUpperCase();\r",
                    "\r",
                    "var root = this.getTreegrid().getStore().getRootNode();\r",
                    "\r",
                    "var groups = [];\r",
                    "var risks = [];\r",
                    "Ext.Array.each(root.childNodes, function(group) {\r",
                    "\tif(Ext.isEmpty(grpsearch) || group.get('id') == grpsearch) {\r",
                    "\t\tExt.Array.each(group.childNodes, function(risk) {\r",
                    "\t\t\tif(risk.get('id') == intsearch ||\r",
                    "               (risk.get('ruleId').indexOf(chrsearch) >= 0 && chrsearch.length > 0)||\r",
                    "               (risk.get('name').toUpperCase().indexOf(namesearch) >= 0 && namesearch.length > 0)\r",
                    "              ) {\r",
                    "                if(contsearch.length > 0) { //if risk hasn't been selected by id or name try children\r",
                    "                    //sod_role2 has different children than other rules (risks)\r",
                    "                    if(risk.get('rule_type') == 'sod_role2') {\r",
                    "                        Ext.Array.each(risk.childNodes, function(child) {\r",
                    "                            if(child.get('description').toUpperCase().indexOf(contsearch) >= 0) {\r",
                    "                                groups.push(group);\r",
                    "                                risks.push(risk);\r",
                    "                            }\r",
                    "                        });\r",
                    "                    }\r",
                    "                    else {\r",
                    "                        Ext.Array.each(risk.childNodes, function(child) {\r",
                    "                            if(child.get('name').toUpperCase().indexOf(contsearch) >= 0) {\r",
                    "                                groups.push(group);\r",
                    "                                risks.push(risk);\r",
                    "                            }\r",
                    "                        });\r",
                    "                    }\r",
                    "                }\r",
                    "                else {\r",
                    "                    groups.push(group);\r",
                    "                    risks.push(risk);\r",
                    "                }\r",
                    "\t\t\t}\r",
                    "            //search on role/tcode/func only\r",
                    "            else if(chrsearch.length === 0 && namesearch.length === 0 && contsearch.length > 0) {\r",
                    "                //sod_role2 has different children than other rules (risks)\r",
                    "                 console.log(risk);\r",
                    "                if(risk.get('rule_type') == 'sod_role2') {\r",
                    "                    Ext.Array.each(risk.childNodes, function(child) {\r",
                    "                        if(child.get('description').toUpperCase().indexOf(contsearch) >= 0) {\r",
                    "                            groups.push(group);\r",
                    "                            risks.push(risk);\r",
                    "                        }\r",
                    "                    });\r",
                    "                }\r",
                    "                else {\r",
                    "                    Ext.Array.each(risk.childNodes, function(child) {\r",
                    "                        if(child.get('name').toUpperCase().indexOf(contsearch) >= 0) {\r",
                    "                            groups.push(group);\r",
                    "                            risks.push(risk);\r",
                    "                        }\r",
                    "                    });\r",
                    "                }\r",
                    "            }\r",
                    "\t\t});\r",
                    "\t}\r",
                    "});\r",
                    "\r",
                    "this.expandGroups(Ext.Array.unique(groups));\r",
                    "\r",
                    "//delay expansion to give grid time to update the group nodes\r",
                    "var me = this;\r",
                    "setTimeout(function() {\r",
                    "    me.expandRisks(risks);\r",
                    "    setTimeout(function() {\r",
                    "        me.afterSearch();\r",
                    "    }, 50*risks.length);\r",
                    "}, 50*groups.length);\r",
                    ""
                ]
            },
            "designerId": "88ec3437-2afd-454b-beb0-5967fc7b3fa7"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "groups"
                ],
                "fn": "expandGroups",
                "implHandler": [
                    "Ext.Array.each(groups, function(group) {\r",
                    "\tgroup.expand();\r",
                    "});"
                ]
            },
            "designerId": "40938558-d1f3-4cdf-8f19-d545bd562de8"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "risks"
                ],
                "fn": "expandRisks",
                "implHandler": [
                    "Ext.Array.each(risks, function(risk) {\r",
                    "\trisk.expand();\r",
                    "\tif(risks.length == 1) //only one result do select\r",
                    "\t\tthis.getTreegrid().getSelectionModel().doSelect(risk);\r",
                    "}, this);\r",
                    ""
                ]
            },
            "designerId": "7239872e-4870-489e-b871-bacffe8978d5"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "afterSearch",
                "implHandler": [
                    "this.getTreegrid().suspendLayout = false;\r",
                    "this.getTreegrid().doLayout();\r",
                    "this.getTreegrid().setLoading(false);\r",
                    "\r",
                    "this.getSearchGroupCombo().enable();\r",
                    "this.getSearchNameTrigger().enable();\r",
                    "this.getSearchContentTrigger().enable();\r",
                    "\r",
                    "this.getSearchRiskIdTrigger().enable();\r",
                    "this.getSearchRiskIdTrigger().focus();"
                ]
            },
            "designerId": "fbdf01ab-c8a8-41aa-bf4c-40d37a276cea"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "treegrid",
                "selector": "#treegrid"
            },
            "designerId": "1dd666af-54d1-4a59-988f-5e4077d2e449"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "searchGroupCombo",
                "selector": "#searchGroupCombo"
            },
            "designerId": "88ed4ca7-b223-40a4-b6d5-d31cedb6e180"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "searchRiskIdTrigger",
                "selector": "#searchRiskIdTrigger"
            },
            "designerId": "7bb89bca-3d99-4ae3-9296-fef05c0a469a"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "searchNameTrigger",
                "selector": "#searchNameTrigger"
            },
            "designerId": "8a8b87e3-aaae-4597-a80e-82ecc4b47319"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "searchContentTrigger",
                "selector": "#searchContentTrigger"
            },
            "designerId": "36c95ed7-2503-4052-892c-cd4ff5d8c5e0"
        }
    ]
}