{
    "type": "Ext.app.Controller",
    "reference": {
        "name": "items",
        "type": "array"
    },
    "codeClass": null,
    "userConfig": {
        "designer|userClassName": "LicenseMapping"
    },
    "designerId": "5f95edbc-9107-409c-be10-c978ca9765f1",
    "cn": [
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "licenseMap",
                "selector": "#licenseMap"
            },
            "designerId": "ba7f1ac4-eff6-4fb4-94f6-b35e55ea72ce"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "autoCreate": true,
                "ref": "mappingWindow",
                "selector": "#MappingWindow",
                "xtype": "MappingWindow"
            },
            "designerId": "bd4af0c3-f2ca-49ea-8ff1-c100f7bd5ab9"
        },
        {
            "type": "fixedfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "application"
                ],
                "fn": "init",
                "implHandler": [
                    "this.control({\r",
                    "\t'#btnCreate': {\r",
                    "\t\tclick: function(btn) {\r",
                    "\t\t\tvar record = this.getLicenseMap().getSelectionModel().getSelection()[0];\r",
                    "\t\t\tthis.createOpenWindow(btn, record);\r",
                    "\t\t}\r",
                    "\t},\r",
                    "\t'#btnLocalLicenseCreate': {\r",
                    "\t\tclick: function(btn) {\r",
                    "\t\t\tbtn.disable();\r",
                    "\t\t\tthis.create();\r",
                    "\t\t}\r",
                    "\t},\r",
                    "\t'#btnLocalLicenseEdit': {\r",
                    "\t\tclick: function(btn) {\r",
                    "\t\t\tbtn.disable();\r",
                    "\t\t\tthis.edit();\r",
                    "\t\t}\r",
                    "\t},\r",
                    "\t'#btnMapExisting': {\r",
                    "\t\tclick: function(btn) {\r",
                    "\t\t\tvar record = this.getLicenseMap().getSelectionModel().getSelection()[0];\r",
                    "\t\t\tthis.mapExistingOpenWindow(btn, record);\r",
                    "\t\t}\r",
                    "\t},\r",
                    "\t'#btnMapExistingSave': {\r",
                    "\t\tclick: function(btn) {\r",
                    "\t\t\tbtn.disable();\r",
                    "\t\t\tthis.mapExisting();\r",
                    "\t\t}\r",
                    "\t},\r",
                    "\t'#btnMapSap': {\r",
                    "\t\tclick: function(btn) {\r",
                    "\t\t\tvar record = this.getLicenseMap().getSelectionModel().getSelection()[0];\r",
                    "\t\t\tthis.mapSU01OpenWindow(btn, record);\r",
                    "\t\t}\r",
                    "\t},\r",
                    "\t'#btnMapSU01Save': {\r",
                    "\t\tclick: function(btn) {\r",
                    "\t\t\tbtn.disable();\r",
                    "\t\t\tthis.mapSU01();\r",
                    "\t\t}\r",
                    "\t},\r",
                    "\t'#btnEdit': {\r",
                    "\t\tclick: function(btn) {\r",
                    "\t\t\tvar record = this.getLicenseMap().getSelectionModel().getSelection()[0];\r",
                    "\t\t\tthis.createOpenWindow(btn, record);\r",
                    "\t\t}\r",
                    "\t},\r",
                    "\t'#btnDeleteLocal': {\r",
                    "\t\tclick: function(btn) {\r",
                    "\t\t\tthis.deleteCategory();\r",
                    "\t\t}\r",
                    "\t},\r",
                    "\t'#btnUnmap': {\r",
                    "\t\tclick: function(btn) {\r",
                    "\t\t\tthis.unMapCategory();\r",
                    "\t\t}\r",
                    "\t}\r",
                    "});\r",
                    ""
                ]
            },
            "designerId": "d054a34c-598c-4b7d-9f4f-d18c463fc4a0"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "button",
                    "record"
                ],
                "fn": "mapExistingOpenWindow",
                "implHandler": [
                    "var syscli = record.get('syscli');\r",
                    "\r",
                    "var unassignedCategory = this.getLicenseMap().getStore().getById(0);\r",
                    "\r",
                    "//if there are no unmapped categories\r",
                    "if(Ext.isEmpty(unassignedCategory)) {\r",
                    "\tExt.MessageBox.alert(CCS.Translator.getText('Error'), CCS.Translator.getText('No categories to map to.'), function() {\r",
                    "\t\t//action to complete when user clicks ok.\r",
                    "\t});\r",
                    "\treturn false;\r",
                    "}\r",
                    "\r",
                    "var unassigned = [];\r",
                    "for(var key in unassignedCategory.childNodes) {\r",
                    "\tif(unassignedCategory.childNodes[key].get('syscli') == syscli)\r",
                    "\t\tunassigned.push(unassignedCategory.childNodes[key]);\r",
                    "}\r",
                    "\r",
                    "//if there is nothing to map to on that system / client\r",
                    "if(unassigned.length === 0) {\r",
                    "\tExt.MessageBox.alert(CCS.Translator.getText('Error'), CCS.Translator.getText('No categories to map to.'), function() {\r",
                    "\t\t//action to complete when user clicks ok.\r",
                    "\t});\r",
                    "\treturn false;\r",
                    "}\r",
                    "\r",
                    "//create store for combo\r",
                    "var model = this.getLicenseMap().getStore().model;\r",
                    "var store = Ext.create('Ext.data.ArrayStore', {\r",
                    "\tmodel:\tmodel,\r",
                    "\tdata:\tunassigned\r",
                    "});\r",
                    "\r",
                    "this.getMappingWindow().animateTarget = button;\r",
                    "this.getMappingWindow().show();\r",
                    "var form = this.getMappingWindow().down('form');\r",
                    "var combo = form.getForm().findField('mappingTarget');\r",
                    "combo.bindStore(store);\r",
                    "\r",
                    "//focus needs to happen after window has fully opened\r",
                    "var task = new Ext.util.DelayedTask(function(){\r",
                    "\tcombo.focus();\r",
                    "\tcombo.expand();\r",
                    "}, this);\r",
                    "\r",
                    "task.delay(350);"
                ]
            },
            "designerId": "19607928-17de-4869-a9de-95e4da0cb603"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "target"
                ],
                "fn": "mapExisting",
                "implHandler": [
                    "var combo = this.getMappingWindow().down('form').getForm().findField('mappingTarget');\r",
                    "var myRecordId = combo.getValue();\r",
                    "var target = combo.getStore().findRecord('localId', myRecordId);\r",
                    "\r",
                    "var consolidated = this.getLicenseMap().getSelectionModel().getSelection()[0].parentNode;\r",
                    "\r",
                    "//set properties\r",
                    "target.set('license_category_consolidated_id', consolidated.get('id'));\r",
                    "target.set('cost', consolidated.get('cost'));\r",
                    "target.set('command', 'mapExisting');\r",
                    "\r",
                    "//add to consolidate and update to store (service)\r",
                    "consolidated.appendChild(target);\r",
                    "\r",
                    "this.updateLicenseGrid();\r",
                    "this.getMappingWindow().close();"
                ]
            },
            "designerId": "0e231a16-77ed-4c8a-b9d9-a3b7c7556ebf"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "btnMapExistingSave",
                "selector": "#btnMapExistingSave"
            },
            "designerId": "d3498d96-fb7c-4664-b141-07ec7cd2db3c"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "button",
                    "record"
                ],
                "fn": "mapSU01OpenWindow",
                "implHandler": [
                    "this.getMappingWindow().animateTarget = button;\r",
                    "this.getMappingWindow().show();\r",
                    "this.getBtnMapExistingSave().hide();\r",
                    "this.getBtnMapSU01Save().show();\r",
                    "this.getMappingWindow().disable();\r",
                    "\r",
                    "//get local SU01 license categories\r",
                    "var store = MyApp.app.getStore('SU01License');\r",
                    "store.getProxy().extraParams.system = record.get('system');\r",
                    "store.getProxy().extraParams.client = record.get('client');\r",
                    "store.getProxy().extraParams.language = Ext.Object.fromQueryString(document.location.search).language;\r",
                    "store.load({\r",
                    "\tcallback: function(records, eOpts, success) {\r",
                    "\t\tif (records.length > 0) {\r",
                    "\t\t\t//create store for combo\r",
                    "\t\t\tvar model = this.getLicenseMap().getStore().model;\r",
                    "\t\t\tvar store = Ext.create('Ext.data.ArrayStore', {\r",
                    "\t\t\t\tmodel:\tmodel,\r",
                    "\t\t\t\tdata:\trecords\r",
                    "\t\t\t});\r",
                    "\r",
                    "\t\t\tvar form = this.getMappingWindow().down('form');\r",
                    "\t\t\tvar combo = form.getForm().findField('mappingTarget');\r",
                    "\t\t\tcombo.bindStore(store);\r",
                    "\r",
                    "\t\t\tthis.getMappingWindow().enable();\r",
                    "\r",
                    "\t\t\tvar chosen = Ext.isEmpty(record.get('license_map_su01'))?\r",
                    "\t\t\t\tcombo.getStore().first() : combo.getStore().findRecord('localId',record.get('license_map_su01'));\r",
                    "\r",
                    "\t\t\t//focus needs to happen after window has fully opened\r",
                    "\t\t\tvar task = new Ext.util.DelayedTask(function(){\r",
                    "\t\t\t\tcombo.select(chosen);\r",
                    "\t\t\t\tcombo.focus();\r",
                    "\t\t\t\tcombo.expand();\r",
                    "\t\t\t}, this);\r",
                    "\r",
                    "\t\t\ttask.delay(350);\r",
                    "\t\t}\r",
                    "\t\telse {\r",
                    "\t\t\t//if there are no SU01 categories\r",
                    "\t\t\tvar me = this;\r",
                    "\t\t\tExt.MessageBox.alert(CCS.Translator.getText('Error'), CCS.Translator.getText('No categories to map to.'), function() {\r",
                    "\t\t\t\t//action to complete when user clicks ok.\r",
                    "\t\t\t\tme.getMappingWindow().close();\r",
                    "\t\t\t});\r",
                    "\t\t\treturn false;\r",
                    "\t\t}\r",
                    "\t},\r",
                    "\tscope: this\r",
                    "});"
                ]
            },
            "designerId": "8ed2867d-e766-4f36-a140-803e9da98fb3"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "mapSU01",
                "implHandler": [
                    "var su01_id = this.getMappingWindow().down('form').getForm().getValues().mappingTarget;\r",
                    "var name = this.getMappingWindow().down('form').getForm().findField('mappingTarget').getStore().findRecord('localId', su01_id).get('category');\r",
                    "var record = this.getLicenseMap().getSelectionModel().getSelection()[0];\r",
                    "\r",
                    "//set properties\r",
                    "record.set('license_map_su01', su01_id);\r",
                    "record.set('sapLicense', name);\r",
                    "record.set('command', 'mapSU01');\r",
                    "\r",
                    "this.updateLicenseGrid();\r",
                    "this.getMappingWindow().close();"
                ]
            },
            "designerId": "fe931c80-9b7d-4acd-8118-f8ab9680fd9b"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "btnMapSU01Save",
                "selector": "#btnMapSU01Save"
            },
            "designerId": "0b94f31e-0495-4c97-8e5d-eb8ce6e1a8a4"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "button",
                    "record"
                ],
                "fn": "createOpenWindow",
                "implHandler": [
                    "this.getLocalLicenseWindow().animateTarget = button;\r",
                    "this.getLocalLicenseWindow().show();\r",
                    "\r",
                    "if (button.itemId == 'btnCreate') {\r",
                    "\tthis.getLocalLicenseWindow().down('form').getForm().loadRecord(record.parentNode);\r",
                    "\r",
                    "\tthis.getBtnLocalLicenseCreate().enable();\r",
                    "\tthis.getBtnLocalLicenseCreate().setVisible(true);\r",
                    "\tthis.getBtnLocalLicenseEdit().disable();\r",
                    "\tthis.getBtnLocalLicenseEdit().setVisible(false);\r",
                    "}\r",
                    "else if (button.itemId == 'btnEdit') {\r",
                    "\tthis.getLocalLicenseWindow().down('form').getForm().loadRecord(record);\r",
                    "\r",
                    "\tthis.getBtnLocalLicenseCreate().disable();\r",
                    "\tthis.getBtnLocalLicenseCreate().setVisible(false);\r",
                    "\tthis.getBtnLocalLicenseEdit().enable();\r",
                    "\tthis.getBtnLocalLicenseEdit().setVisible(true);\r",
                    "}\r",
                    "\r",
                    "var store = MyApp.app.getStore('SU01License');\r",
                    "store.getProxy().extraParams.system = record.get('system');\r",
                    "store.getProxy().extraParams.client = record.get('client');\r",
                    "store.getProxy().extraParams.language = Ext.Object.fromQueryString(document.location.search).language;\r",
                    "\r",
                    "store.load({\r",
                    "\tcallback: function(records, eOpts, success) {\r",
                    "\t\t//focus needs to happen after window has fully opened\r",
                    "\t\tvar task = new Ext.util.DelayedTask(function(){\r",
                    "\t\t\t//this.getLocalLicenseWindow().down('form').getForm().findField('license_map_su01').expand();\r",
                    "\t\t\tthis.getLocalLicenseWindow().down('form').getForm().findField('category').focus();\r",
                    "\t\t\tthis.getLocalLicenseWindow().down('form').getForm().loadRecord(record);\r",
                    "\t\t}, this);\r",
                    "\r",
                    "\t\ttask.delay(350);\r",
                    "\t},\r",
                    "\tscope: this\r",
                    "});"
                ]
            },
            "designerId": "81291779-f049-4852-9e7e-234bea2d35bd"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "create",
                "implHandler": [
                    "var record = this.getLicenseMap().getSelectionModel().getSelection()[0];\r",
                    "\r",
                    "var consolidated = record.parentNode;\r",
                    "var form = this.getLocalLicenseWindow().down('form').getForm();\r",
                    "var data = form.getValues();\r",
                    "\r",
                    "var sapLicenseRecord = form.findField('license_map_su01').getStore().findRecord('license_map_su01', data.license_map_su01);\r",
                    "var sapLicense = (Ext.isEmpty(sapLicenseRecord))? '' : sapLicenseRecord.get('sapLicense');\r",
                    "\r",
                    "//set properties\r",
                    "record.set('category', data.category);\r",
                    "record.set('dash_abbr', data.dash_abbr);\r",
                    "record.set('license_map_su01', data.license_map_su01);\r",
                    "record.set('sapLicense', sapLicense);\r",
                    "\r",
                    "record.set('dash_incl', consolidated.get('dash_incl'));\r",
                    "record.set('cost', consolidated.get('cost'));\r",
                    "record.set('license_category_consolidated_id', consolidated.get('id'));\r",
                    "\r",
                    "record.set('command', 'createLocal');\r",
                    "\r",
                    "this.updateLicenseGrid();\r",
                    "this.getLocalLicenseWindow().close();"
                ]
            },
            "designerId": "4c3d3a00-8703-442d-a529-71fc83753043"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "autoCreate": true,
                "ref": "localLicenseWindow",
                "selector": "#LocalLicenseWindow",
                "xtype": "LocalLicenseWindow"
            },
            "designerId": "f2792745-3e6c-4961-9a6a-391f7e8576b8"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "btnLocalLicenseCreate",
                "selector": "#btnLocalLicenseCreate"
            },
            "designerId": "a63758c8-6a5b-453a-876f-7bf2e3afb3a0"
        },
        {
            "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": "ee37145d-bd6f-42a4-84f1-8655aecd614a"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "btnLocalLicenseEdit",
                "selector": "#btnLocalLicenseEdit"
            },
            "designerId": "f5831659-eb92-469b-8903-ec9f56c35bc9"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "edit",
                "implHandler": [
                    "var record = this.getLicenseMap().getSelectionModel().getSelection()[0];\r",
                    "\r",
                    "var consolidated = record.parentNode;\r",
                    "var form = this.getLocalLicenseWindow().down('form').getForm();\r",
                    "var data = form.getValues();\r",
                    "\r",
                    "var sapLicenseRecord = form.findField('license_map_su01').getStore().findRecord('license_map_su01', data.license_map_su01);\r",
                    "var sapLicense = (Ext.isEmpty(sapLicenseRecord))? '' : sapLicenseRecord.get('sapLicense');\r",
                    "\r",
                    "record.set('category', data.category);\r",
                    "record.set('dash_abbr', data.dash_abbr);\r",
                    "record.set('license_map_su01', data.license_map_su01);\r",
                    "record.set('sapLicense', sapLicense);\r",
                    "\r",
                    "record.set('dash_incl', consolidated.get('dash_incl'));\r",
                    "record.set('cost', consolidated.get('cost'));\r",
                    "record.set('license_category_consolidated_id', consolidated.get('id'));\r",
                    "\r",
                    "record.set('command', 'editLocal');\r",
                    "\r",
                    "console.log(record);\r",
                    "\r",
                    "this.updateLicenseGrid();\r",
                    "this.getLocalLicenseWindow().close();"
                ]
            },
            "designerId": "cc00ec4d-18cd-4009-899f-7421c66c7a25"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "btnDeleteLocal",
                "selector": "#btnDeleteLocal"
            },
            "designerId": "621535a1-38b8-41ff-9d50-f81c07eaafc3"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "deleteCategory",
                "implHandler": [
                    "var me = this;\r",
                    "var record = this.getLicenseMap().getSelectionModel().getSelection()[0];\r",
                    "record.set('command', 'deleteLocal');\r",
                    "\r",
                    "Ext.MessageBox.confirm('Delete', 'Are you sure?', function(btn){\r",
                    "\tif (btn == 'yes') {\r",
                    "\t\tconfirm();\r",
                    "\t}\r",
                    "});\r",
                    "\r",
                    "\r",
                    "\r",
                    "function confirm() {\r",
                    "\tme.updateLicenseGrid();\r",
                    "}"
                ]
            },
            "designerId": "0ee37cae-1322-4478-87ec-ef9f565f66bf"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "btnUnmap",
                "selector": "#btnUnmap"
            },
            "designerId": "d2510bec-4513-4c3b-849c-e8fe1f7a0339"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "unMapCategory",
                "implHandler": [
                    "var me = this;\r",
                    "var record = this.getLicenseMap().getSelectionModel().getSelection()[0];\r",
                    "record.set('command', 'unMapLocal');\r",
                    "\r",
                    "Ext.MessageBox.confirm('Delete', 'Are you sure?', function(btn){\r",
                    "\tif (btn == 'yes') {\r",
                    "\t\tconfirm();\r",
                    "\t}\r",
                    "});\r",
                    "\r",
                    "\r",
                    "\r",
                    "function confirm() {\r",
                    "\tme.updateLicenseGrid();\r",
                    "}"
                ]
            },
            "designerId": "36727bfe-7224-44c7-8512-0ae101631bbb"
        }
    ]
}