{
    "type": "Ext.app.Controller",
    "reference": {
        "name": "items",
        "type": "array"
    },
    "codeClass": null,
    "userConfig": {
        "designer|userClassName": "LicenseGUI"
    },
    "designerId": "eb2b6933-0055-4daa-90c2-16675a1205e0",
    "cn": [
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "licenseMap",
                "selector": "#licenseMap"
            },
            "designerId": "482ad127-2117-4ac9-8349-22338af6f7db"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "btnEditCategory",
                "selector": "#btnEditCategory"
            },
            "designerId": "d24eb38e-ee13-467b-827b-7b22ce33a22f"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "btnDeleteCategory",
                "selector": "#btnDeleteCategory"
            },
            "designerId": "0643e6e7-147c-4c3a-8329-bacdbafbf3be"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "btnCreate",
                "selector": "#btnCreate"
            },
            "designerId": "7ef6a477-66f3-49ef-8e7a-5f37fe7c536c"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "btnEdit",
                "selector": "#btnEdit"
            },
            "designerId": "de57c60a-8fb4-4dd3-902a-d2f6397fa52e"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "btnMapSap",
                "selector": "#btnMapSap"
            },
            "designerId": "1786e8cc-22ff-4fea-b4ce-5a0e93410b2b"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "btnMapExisting",
                "selector": "#btnMapExisting"
            },
            "designerId": "a4161c97-ffe8-4500-b07f-5e4cd016ef68"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "btnUnmap",
                "selector": "#btnUnmap"
            },
            "designerId": "313891c2-9542-408f-995d-d40ea89cdebb"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "btnDeleteLocal",
                "selector": "#btnDeleteLocal"
            },
            "designerId": "9e69b328-1b03-418d-9bb2-f1909d6b43ce"
        },
        {
            "type": "fixedfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "application"
                ],
                "fn": "init",
                "implHandler": [
                    "this.control({\r",
                    "\t'#licenseMap': {\r",
                    "\t\tselectionchange: function(component, selection) {\r",
                    "\t\t\tthis.selectionChanged(selection[0]);\r",
                    "\t\t\t//console.log(selection[0].data);\r",
                    "\t\t}\r",
                    "\t},\r",
                    "\t'#btnDeleteCategory': {\r",
                    "\t\tclick: function(btn) {\r",
                    "\t\t\tthis.deleteConsolidated();\r",
                    "\t\t}\r",
                    "\t},\r",
                    "\t'#btnMapExisting': {\r",
                    "\t\tclick: function(btn) {\r",
                    "\t\t\tconsole.log(\"map existing\");\r",
                    "\t\t}\r",
                    "\t}\r",
                    "});"
                ]
            },
            "designerId": "20084198-e2bf-41a0-989a-6477a058983c"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "newRecord"
                ],
                "fn": "selectionChanged",
                "implHandler": [
                    "this.selectedItem = newRecord;\r",
                    "//disable all btns then enable the ones that needs it\r",
                    "this.getBtnEditCategory().disable();\r",
                    "this.getBtnDeleteCategory().disable();\r",
                    "\r",
                    "this.getBtnCreate().disable();\r",
                    "this.getBtnEdit().disable();\r",
                    "this.getBtnMapExisting().disable();\r",
                    "this.getBtnMapSap().disable();\r",
                    "this.getBtnUnmap().disable();\r",
                    "this.getBtnDeleteLocal().disable();\r",
                    "\r",
                    "if(newRecord !== undefined) { //if store is cleared no buttons should be enabled\r",
                    "\tif(newRecord.parentNode == this.getLicenseMap().getStore().getRootNode()) {\r",
                    "\t\tif(newRecord.getId() !== 0) { //user cannot edit nor delete unassigned\r",
                    "\t\t\tthis.getBtnEditCategory().enable();\r",
                    "\t\t\tthis.getBtnDeleteCategory().enable();\r",
                    "\t\t}\r",
                    "\t}\r",
                    "\telse {\r",
                    "\t\tif(newRecord.parentNode.getId() !== 0) { //user cannot edit nor delete in unassigned\r",
                    "\t\t\tif(newRecord.get('localId') == 'X') { // non-existing categories can be mapped to unassigned or created as new\r",
                    "\t\t\t\tthis.getBtnMapExisting().enable();\r",
                    "\t\t\t\tthis.getBtnCreate().enable();\r",
                    "\t\t\t}\r",
                    "\r",
                    "\t\t\tif(newRecord.get('localId') != 'X') { //user cannot su01-map, edit, unmap nor delete a non-existing category\r",
                    "\t\t\t\tthis.getBtnEdit().enable();\r",
                    "\t\t\t\tthis.getBtnMapSap().enable();\r",
                    "\t\t\t\tthis.getBtnUnmap().enable();\r",
                    "\t\t\t\tthis.getBtnDeleteLocal().enable();\r",
                    "\t\t\t}\r",
                    "\t\t}\r",
                    "\t}\r",
                    "}"
                ]
            },
            "designerId": "e59eac2b-4bb6-42d6-bd46-7b2014c56910"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "deleteConsolidated",
                "implHandler": [
                    "console.log(this.selectedItem.data);\r",
                    "var me = this;\r",
                    "this.selectedItem.data.command = 'delete';\r",
                    "\r",
                    "Ext.MessageBox.confirm('Delete', 'Are you sure?', function(btn){\r",
                    "\tif (btn == 'yes') {\r",
                    "\t\tconfirm();\r",
                    "\t}\r",
                    "});\r",
                    "\r",
                    "\r",
                    "function confirm() {\r",
                    "\t//me.updateLicenseGrid();\r",
                    "\tExt.Ajax.request({\r",
                    "\t\turl: '../../service/licenseManagement_mapping.php',\r",
                    "\t\tmethod: 'POST',\r",
                    "\t\tjsonData: Ext.encode(me.selectedItem.data),\r",
                    "\t\tsuccess: function(response, object){\r",
                    "\t\t\tthis.getLicenseMap().getStore().load();\r",
                    "\t\t},\r",
                    "\t\tfailure: function(response, object){\r",
                    "\r",
                    "\t\t},\r",
                    "\t\tscope: me\r",
                    "\t});\r",
                    "}"
                ]
            },
            "designerId": "df4f48f3-253c-429b-a0ca-15a157c93d4c"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "updateLicenseGrid",
                "implHandler": [
                    "//update to store (service)\r",
                    "this.getLicenseMap().getStore().sync({\r",
                    "\tcallback: function() {\r",
                    "\t\tthis.getLicenseMap().getStore().load();\r",
                    "\t},\r",
                    "\tscope: this\r",
                    "});\r",
                    ""
                ]
            },
            "designerId": "b7ec204d-483e-45c5-b9a1-faa267550bea"
        }
    ]
}