{
    "type": "Ext.app.Controller",
    "reference": {
        "name": "items",
        "type": "array"
    },
    "codeClass": null,
    "userConfig": {
        "designer|userClassName": "CRUD"
    },
    "designerId": "666d29a3-0c08-4c00-b756-c4b19f60e795",
    "cn": [
        {
            "type": "fixedfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "application"
                ],
                "fn": "init",
                "implHandler": [
                    "this.control({\r",
                    "\t'#btnCreate': {\r",
                    "\t\tclick: this.openCreate\r",
                    "\t},\r",
                    "\t'#btnSave': {\r",
                    "\t\tclick: this.create\r",
                    "\t},\r",
                    "\t'#fieldScope': {\r",
                    "\t\tselect: this.setLabel,\r",
                    "\t\tchange: this.checkForm\r",
                    "\t},\r",
                    "\t'#typeCombo': {\r",
                    "\t\tselect: this.setupForm,\r",
                    "\t\tchange: this.checkForm\r",
                    "\t},\r",
                    "\t'#fieldField': {\r",
                    "\t\tselect: this.checkForm,\r",
                    "\t\tchange: this.checkForm\r",
                    "\t},\r",
                    "\t'#fieldLow': {\r",
                    "\t\tchange: function(comp, newValue, oldValue) {\r",
                    "\t\t\tif(newValue !== oldValue) {\r",
                    "\t\t\t\tcomp.setValue(newValue.toUpperCase());\r",
                    "\t\t\t\tthis.checkForm();\r",
                    "\t\t\t}\r",
                    "\t\t}\r",
                    "\t},\r",
                    "\t'#fieldHigh': {\r",
                    "\t\tchange: function(comp, newValue, oldValue) {\r",
                    "\t\t\tif(newValue !== oldValue) {\r",
                    "\t\t\t\tcomp.setValue(newValue.toUpperCase());\r",
                    "\t\t\t\tthis.checkForm();\r",
                    "\t\t\t}\r",
                    "\t\t}\r",
                    "\t}\r",
                    "});"
                ]
            },
            "designerId": "e16159a0-e81e-40d7-9494-fdef23a3dc0f"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "emptyContainer",
                "selector": "#emptyContainer"
            },
            "designerId": "6dc60605-5779-4b4b-80c5-2f356f272409"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "autoCreate": true,
                "ref": "restriction",
                "selector": "#Restriction",
                "xtype": "Restriction"
            },
            "designerId": "ed69b3fe-ab19-4b6c-bfaa-cc046902ad1b"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "restrictionForm",
                "selector": "#restrictionForm"
            },
            "designerId": "945ab9eb-7000-4b57-8c80-6ab9c8a13b26"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "btnSave",
                "selector": "#btnSave"
            },
            "designerId": "0b2958fa-2ff3-4666-a667-7da4faec733f"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "btn"
                ],
                "fn": "openCreate",
                "implHandler": [
                    "btn.blur();\r",
                    "this.getRestriction().animateTarget = btn;\r",
                    "this.getRestriction().show();\r",
                    "\r",
                    "var params = MyApp.app.getController('Content').params;\r",
                    "\r",
                    "var scope = this.getRestrictionForm().getForm().findField('scope');\r",
                    "if(params.project === true) {\r",
                    "\tscope.select(3);\r",
                    "}\r",
                    "else if(params.local === true) {\r",
                    "\tscope.select(2);\r",
                    "}\r",
                    "else if(params.global === true) {\r",
                    "\tscope.select(1);\r",
                    "}\r",
                    "else {\r",
                    "\tscope.select(2);\r",
                    "}\r",
                    "\r",
                    "this.setLabel(scope, [scope.getStore().getById(scope.getValue())]);\r",
                    "this.setupForm();\r",
                    "\r",
                    "var me = this;\r",
                    "setTimeout(function() {\r",
                    "\tme.getRestrictionForm().getForm().findField('type').expand();\r",
                    "}, 500);"
                ]
            },
            "designerId": "fee1127e-11b7-4ed9-a8fc-ee659e2b7b6b"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "component",
                    "selection"
                ],
                "fn": "setLabel",
                "implHandler": [
                    "if(selection.length > 0) {\r",
                    "\tvar params = MyApp.app.getController('Content').params;\r",
                    "\tswitch(selection[0].get('id')) {\r",
                    "\t\tcase 1:\r",
                    "\t\t\tthis.getFieldScopeLabel().setText('');\r",
                    "\t\tbreak;\r",
                    "\t\tcase 2:\r",
                    "\t\t\tthis.getFieldScopeLabel().setText(params.system +'/'+ params.client);\r",
                    "\t\tbreak;\r",
                    "\t\tcase 3:\r",
                    "\t\t\tthis.getFieldScopeLabel().setText(params.projectName);\r",
                    "\t\tbreak;\r",
                    "\t}\r",
                    "}\r",
                    "this.checkForm();"
                ]
            },
            "designerId": "c24d1dec-97c0-42ea-80e3-678706404162"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "setupForm",
                "implHandler": [
                    "/* depending on type selection the form will change */\r",
                    "\r",
                    "//disable all fields\r",
                    "var formFields = this.getRestrictionForm().items.items;\r",
                    "for(var x in formFields) {\r",
                    "\tvar field = this.getRestrictionForm().getForm().findField(formFields[x].name);\r",
                    "\tif(!Ext.isEmpty(field)) {\r",
                    "\t\tfield.disable();\r",
                    "\t}\r",
                    "}\r",
                    "//enable type and scope fields\r",
                    "this.getRestrictionForm().getForm().findField('scope').enable();\r",
                    "this.getRestrictionForm().getForm().findField('type').enable();\r",
                    "this.getRestrictionForm().getForm().findField('comment').enable();\r",
                    "\r",
                    "this.getRestrictionForm().getForm().findField('low').hide();\r",
                    "this.getRestrictionForm().getForm().findField('high').hide();\r",
                    "this.getRestrictionForm().getForm().findField('field').show();\r",
                    "\r",
                    "//enable field relevant to the type\r",
                    "var focusField = this.getRestrictionForm().getForm().findField('type');\r",
                    "\r",
                    "var type = this.getRestrictionForm().getForm().findField('type').getValue();\r",
                    "switch(type) {\r",
                    "\tcase 1:\r",
                    "\t\tfocusField = this.getRestrictionForm().getForm().findField('field');\r",
                    "\t\tfocusField.setFieldLabel(CCS.Translator.getText('Org Level'));\r",
                    "\t\tthis.getSapData('orglvl');\r",
                    "\tbreak;\r",
                    "\tcase 2:\r",
                    "\t\tfocusField = this.getRestrictionForm().getForm().findField('field');\r",
                    "\t\tfocusField.setFieldLabel(CCS.Translator.getText('Object Class'));\r",
                    "\t\tthis.getSapData('objclass');\r",
                    "\tbreak;\r",
                    "\tcase 3:\r",
                    "\t\tfocusField = this.getRestrictionForm().getForm().findField('field');\r",
                    "\t\tfocusField.setFieldLabel(CCS.Translator.getText('Object'));\r",
                    "\t\tthis.getSapData('object');\r",
                    "\tbreak;\r",
                    "\tcase 4:\r",
                    "\t\tfocusField = this.getRestrictionForm().getForm().findField('field');\r",
                    "\t\tfocusField.setFieldLabel(CCS.Translator.getText('Field'));\r",
                    "\t\tthis.getSapData('field');\r",
                    "\tbreak;\r",
                    "\tcase 5:\r",
                    "\t\tthis.getRestrictionForm().getForm().findField('field').hide();\r",
                    "\t\tthis.getRestrictionForm().getForm().findField('low').enable();\r",
                    "\t\tthis.getRestrictionForm().getForm().findField('high').enable();\r",
                    "\t\tthis.getRestrictionForm().getForm().findField('low').show();\r",
                    "\t\tthis.getRestrictionForm().getForm().findField('high').show();\r",
                    "\t\tfocusField = this.getRestrictionForm().getForm().findField('low');\r",
                    "\tbreak;\r",
                    "}\r",
                    "\r",
                    "focusField.enable();\r",
                    "setTimeout(function() {\r",
                    "\tfocusField.focus();\r",
                    "}, 150);\r",
                    "this.checkForm();"
                ]
            },
            "designerId": "ff441532-a322-4a2d-9497-bab5f92ff55c"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "checkForm",
                "implHandler": [
                    "this.getBtnSave().disable();\r",
                    "var value;\r",
                    "\r",
                    "var type = this.getRestrictionForm().getForm().findField('type').getValue();\r",
                    "switch(type) {\r",
                    "\tcase 1:\r",
                    "\tcase 2:\r",
                    "\tcase 3:\r",
                    "\tcase 4:\r",
                    "\t\tvalue = this.getRestrictionForm().getForm().findField('field').getValue();\r",
                    "\tbreak;\r",
                    "\tcase 5:\r",
                    "\t\tvalue = this.getRestrictionForm().getForm().findField('low').getValue();\r",
                    "\tbreak;\r",
                    "}\r",
                    "\r",
                    "if(!Ext.isEmpty(value))\r",
                    "\tthis.getBtnSave().enable();\r",
                    ""
                ]
            },
            "designerId": "ca1bf178-4e68-430f-aa27-acea91c12341"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "type"
                ],
                "fn": "getSapData",
                "implHandler": [
                    "this.getRestriction().setLoading(true);\r",
                    "\r",
                    "var org_params = MyApp.app.getController('Content').params;\r",
                    "\r",
                    "//create sapevent url\r",
                    "var url = \"SAPEVENT:TCR_CRE\";\r",
                    "\r",
                    "var params = {\r",
                    "\tguiid\t\t: org_params.guiid,\r",
                    "\ttype\t\t: type,\r",
                    "\tsystem\t\t: org_params.system,\r",
                    "\tclient\t\t: org_params.client,\r",
                    "\trfctarget\t: org_params.system+\"_\"+org_params.client\r",
                    "};\r",
                    "var par = Ext.Object.toQueryString(params);\r",
                    "//open sapevent in a hidden container\r",
                    "this.getEmptyContainer().update('<iframe src=\"'+url+\"?\"+par+'\" width=\"100%\" height=\"100%\" frameborder=\"0\" style=\"border-color: white;\"></iframe>');\r",
                    "\r",
                    "var me = this;\r",
                    "setTimeout( function() {\r",
                    "\tme.ping({\r",
                    "\t\tguiid\t: org_params.guiid,\r",
                    "\t\ttype\t: type\r",
                    "\t});\r",
                    "}, 750);"
                ]
            },
            "designerId": "da908305-eea9-4dba-9696-e07d2468ff2d"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "params"
                ],
                "fn": "ping",
                "implHandler": [
                    "var me = this;\r",
                    "Ext.Ajax.request({ //manual AJAX\r",
                    "\turl: '../../service/ping.php',\r",
                    "\tmethod: 'GET',\r",
                    "\tparams: params,\r",
                    "\tsuccess: function(response, object){\r",
                    "\t\tvar data = Ext.JSON.decode(response.responseText);\r",
                    "\t\tif(data.result) {\r",
                    "\t\t\tvar field = this.getRestrictionForm().getForm().findField('field');\r",
                    "\t\t\tvar store = field.getStore();\r",
                    "\r",
                    "\t\t\tstore.proxy.extraParams = params;\r",
                    "\t\t\tstore.load({callback: function(records) {\r",
                    "\t\t\t\tfield.enable();\r",
                    "\t\t\t\tif(records.length > 0)\r",
                    "\t\t\t\t\tfield.select(records[0]);\r",
                    "\t\t\t\tfield.expand();\r",
                    "\t\t\t}, scope: this});\r",
                    "\r",
                    "\t\t\tthis.getRestriction().setLoading(false);\r",
                    "\t\t}\r",
                    "\t\telse {\r",
                    "\t\t\tsetTimeout( function() {\r",
                    "\t\t\t\tme.ping(params);\r",
                    "\t\t\t}, 500); //ping again for result every 1/2 second\r",
                    "\t\t}\r",
                    "\t},\r",
                    "\tfailure: function(response, object){\r",
                    "\t\tvar userMessage = CCS.Translator.getText(\"Error code\")+': '+ response.status +\"<br />\"+\r",
                    "\t\t\t\t\"url: \"+ object.url +\"<br />\"+\r",
                    "\t\t\t\t\"text: \"+ response.statusText +\"<br />\"+\r",
                    "\t\t\t\t\"scope: \"+ response.request.options.scope.id +\"<br />\"+\r",
                    "\t\t\t\t\"timeout: \";\r",
                    "\t\tuserMessage += response.timedout === true? CCS.Translator.getText(\"Yes\") : CCS.Translator.getText(\"No\");\r",
                    "\t\tuserMessage += \"<br /><br />\"+CCS.Translator.getText(\"Are you sure you want to continue?\");\r",
                    "\r",
                    "\t\tExt.MessageBox.show({\r",
                    "\t\t\ticon: Ext.MessageBox.WARNING,\r",
                    "\t\t\ttitle: CCS.Translator.getText(\"Some errors occurred\"),\r",
                    "\t\t\tmsg: userMessage,\r",
                    "\t\t\tbuttons: Ext.MessageBox.OKCANCEL,\r",
                    "\t\t\tanimateTarget: me.getEmptyContainer(),\r",
                    "\r",
                    "\t\t\tfn: function(response) {\r",
                    "\t\t\t\tif(response == 'ok') {\r",
                    "\t\t\t\t\tsetTimeout(function() {\r",
                    "\t\t\t\t\t\tme.ping(guiid);\r",
                    "\t\t\t\t\t}, 2000); //ping again\r",
                    "\t\t\t\t}\r",
                    "\t\t\t\telse {\r",
                    "\t\t\t\t\tdocument.location.reload();\r",
                    "\t\t\t\t}\r",
                    "\t\t\t}\r",
                    "\t\t});\r",
                    "\t},\r",
                    "\tscope: this\r",
                    "});"
                ]
            },
            "designerId": "33b6754e-3fc5-4e05-90ea-2c43108633b3"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "btn"
                ],
                "fn": "create",
                "implHandler": [
                    "btn.blur();\r",
                    "this.getRestriction().setLoading(true);\r",
                    "var params = MyApp.app.getController('Content').params;\r",
                    "\r",
                    "var data = {\r",
                    "\tsystem : '', \r",
                    "\tclient : '', \r",
                    "\tproject: '', \r",
                    "\tobject_class : '',\r",
                    "\tobject: '', \r",
                    "\tfield : '', \r",
                    "\tcomment : this.getRestrictionForm().getForm().findField('comment').getValue(), \r",
                    "\tstatus : 'A', \r",
                    "\taudit_user : params.user, \r",
                    "\taudit_system : params.system, \r",
                    "\taudit_client : params.client, \r",
                    "\taudit_timestamp : null\r",
                    "};\r",
                    "\r",
                    "\r",
                    "var type = this.getRestrictionForm().getForm().findField('type').getValue();\r",
                    "switch(type) {\r",
                    "\tcase 1: //orglvl\r",
                    "\t\tdata.field = this.getRestrictionForm().getForm().findField('field').getValue();\r",
                    "\tbreak;\r",
                    "\tcase 2: //object class\r",
                    "\t\tdata.object_class = this.getRestrictionForm().getForm().findField('field').getValue();\r",
                    "\tbreak;\r",
                    "\tcase 3: //object\r",
                    "\t\tdata.object = this.getRestrictionForm().getForm().findField('field').getValue();\r",
                    "\tbreak;\r",
                    "\tcase 4: //field\r",
                    "\t\tdata.field = this.getRestrictionForm().getForm().findField('field').getValue();\r",
                    "\tbreak;\r",
                    "\tcase 5: //tcode\r",
                    "\t\tdata.object = 'S_TCODE';\r",
                    "\t\tdata.field = 'TCD';\r",
                    "\t\tdata.low = this.getRestrictionForm().getForm().findField('low').getValue();\r",
                    "\t\tdata.high= this.getRestrictionForm().getForm().findField('high').getValue();\r",
                    "\t\tdata.value = data.high.length > 0? data.low +\"-\"+ data.high : data.low;\r",
                    "\tbreak;\r",
                    "}\r",
                    "\r",
                    "var scope = this.getRestrictionForm().getForm().findField('scope').getValue();\r",
                    "switch(scope) {\r",
                    "\tcase 1:\r",
                    "\tbreak;\r",
                    "\tcase 2:\r",
                    "\t\tdata.system = params.system;\r",
                    "\t\tdata.client = params.client;\r",
                    "\tbreak;\r",
                    "\tcase 3:\r",
                    "\t\tdata.project = params.projectName;\r",
                    "\tbreak;\r",
                    "}\r",
                    "\r",
                    "var store = MyApp.app.getStore('restrictions');\r",
                    "var myNewRecord = new MyApp.model.restriction(data);\r",
                    "store.add(myNewRecord);\r",
                    "\r",
                    "var me = this;\r",
                    "setTimeout(function() {\r",
                    "\tme.getRestriction().close();\r",
                    "\tme.getRestriction().setLoading(false);\r",
                    "\tstore.load();\r",
                    "}, 500);\r",
                    ""
                ]
            },
            "designerId": "80d8ac32-f00f-48fa-9f99-c601c00fece6"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "fieldScopeLabel",
                "selector": "#fieldScopeLabel"
            },
            "designerId": "56ec1641-9c21-489a-b3d2-7d6337f99015"
        }
    ]
}