{
    "type": "Ext.app.Controller",
    "reference": {
        "name": "items",
        "type": "array"
    },
    "codeClass": null,
    "userConfig": {
        "designer|userClassName": "Download"
    },
    "designerId": "7f94a03b-a5ba-4a56-935d-89e14cccba07",
    "cn": [
        {
            "type": "fixedfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "application"
                ],
                "fn": "init",
                "implHandler": [
                    "this.control({\r",
                    "    '#downloadTemplate': {\r",
                    "        click: function() {\r",
                    "            this.download('template');\r",
                    "        }\r",
                    "    },\r",
                    "\t'#downloadControls': {\r",
                    "        click: function() {\r",
                    "            this.download('control');\r",
                    "        }\r",
                    "    },\r",
                    "\t'#downloadRiskTemplate': {\r",
                    "        click: function() {\r",
                    "            this.download('risk_template');\r",
                    "        }\r",
                    "    },\r",
                    "\t'#downloadRisk': {\r",
                    "        click: function() {\r",
                    "            this.download('risk');\r",
                    "        }\r",
                    "    },\r",
                    "\t'#downloadAreaTemplate': {\r",
                    "        click: function() {\r",
                    "            this.download('area_template');\r",
                    "        }\r",
                    "    },\r",
                    "\t'#downloadArea': {\r",
                    "        click: function() {\r",
                    "            this.download('area');\r",
                    "        }\r",
                    "    },\r",
                    "\t'#uploadControlsBtn': {\r",
                    "\t\tclick: function() {\r",
                    "            this.getUploadControlWindow().show();\r",
                    "        }\r",
                    "\t},\r",
                    "\t'#uploadControlCancelBtn': {\r",
                    "\t\tclick: function() {\r",
                    "            this.getUploadControlWindow().close();\r",
                    "        }\r",
                    "\t},\r",
                    "\t'#uploadControlSaveBtn': {\r",
                    "\t\tclick: function() {\r",
                    "            this.uploadControl();\r",
                    "        }\r",
                    "\t},\r",
                    "\t'#uploadRisksBtn': {\r",
                    "\t\tclick: function() {\r",
                    "            this.getUploadRiskWindow().show();\r",
                    "        }\r",
                    "\t},\r",
                    "\t'#uploadRiskCancelBtn': {\r",
                    "\t\tclick: function() {\r",
                    "            this.getUploadRiskWindow().close();\r",
                    "        }\r",
                    "\t},\r",
                    "\t'#uploadRiskSaveBtn': {\r",
                    "\t\tclick: function() {\r",
                    "            this.uploadRisk();\r",
                    "        }\r",
                    "\t},\r",
                    "\t'#uploadAreasBtn': {\r",
                    "\t\tclick: function() {\r",
                    "            this.getUploadAreaWindow().show();\r",
                    "        }\r",
                    "\t},\r",
                    "\t'#uploadAreaCancelBtn': {\r",
                    "\t\tclick: function() {\r",
                    "            this.getUploadAreaWindow().close();\r",
                    "        }\r",
                    "\t},\r",
                    "\t'#uploadAreaSaveBtn': {\r",
                    "\t\tclick: function() {\r",
                    "            this.uploadArea();\r",
                    "        }\r",
                    "\t}\r",
                    "});"
                ]
            },
            "designerId": "af2e3b35-19d5-4621-ac2f-b511b4ee57d8"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "type"
                ],
                "fn": "download",
                "implHandler": [
                    "var iframe = document.getElementById(\"hiddenIFrameCurrent\"+type);\r",
                    "if(iframe === null) {\r",
                    "    iframe = document.createElement('iframe');\r",
                    "    iframe.id = \"hiddenIFrameCurrent\"+type;\r",
                    "    iframe.style.display = 'none';\r",
                    "    document.body.appendChild(iframe);\r",
                    "}\r",
                    "iframe.src = '../../service/download.php' + document.location.search + '&type='+type;"
                ]
            },
            "designerId": "dffb7e2f-7869-423d-89c9-8670297bec7b"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "downloadTemplate",
                "selector": "#downloadTemplate"
            },
            "designerId": "cdadf74c-6961-4fbc-be2b-5ce856de48e3"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "downloadControls",
                "selector": "#downloadControls"
            },
            "designerId": "db33de41-6987-4aed-b66f-e59610595e7c"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "autoCreate": true,
                "ref": "uploadControlWindow",
                "selector": "#uploadControlWindow",
                "xtype": "uploadControlWindow"
            },
            "designerId": "bd625a3f-b5a7-4e4d-a055-b5075e7a0d25"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "btn"
                ],
                "fn": "uploadControl",
                "implHandler": [
                    "var logText = this.getLogText();\r",
                    "var ctx = this;\r",
                    "var check = this.checkLastUploadControl;\r",
                    "logText.setValue('');\r",
                    "var form = this.getUploadForm().getForm();\r",
                    "if (form.isValid()) {\r",
                    "    form.submit({\r",
                    "        url: '../../service/upload.php?type=control',\r",
                    "        params: Ext.Object.fromQueryString(document.location.search),\r",
                    "        waitMsg: CCS.Translator.getText('Uploading file...'),\r",
                    "        success: function(form, action) {\r",
                    "            logText.setValue(CCS.Translator.getText('Upload task started...'));\r",
                    "\t\t\tconsole.log('task request');\r",
                    "            var task = new Ext.util.DelayedTask(check, ctx);\r",
                    "\t\t\tconsole.log('task start delay');\r",
                    "            task.delay(2000);\r",
                    "\t\t\tconsole.log('uppload close');\r",
                    "\t\t\tctx.getUploadControlWindow().close();\r",
                    "        },\r",
                    "        failure: function(form, action) {\r",
                    "            switch (action.failureType) {\r",
                    "                case Ext.form.action.Action.CLIENT_INVALID:\r",
                    "                    Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values', this.closeDialog, this);\r",
                    "                    break;\r",
                    "                case Ext.form.action.Action.CONNECT_FAILURE:\r",
                    "                    Ext.Msg.alert('Failure', 'Ajax communication failed', this.closeDialog, this);\r",
                    "                    break;\r",
                    "                case Ext.form.action.Action.SERVER_INVALID:\r",
                    "                    Ext.Msg.alert('Upload failed', action.result.errors[0].msg, this.closeDialog, this);\r",
                    "            }\r",
                    "\t\t\tctx.getUploadControlWindow().close();\r",
                    "        }\r",
                    "    });\r",
                    "}"
                ]
            },
            "designerId": "3b74889a-d87e-4e77-944b-1a9617740e5f"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "btn"
                ],
                "fn": "uploadRisk",
                "implHandler": [
                    "var logText = this.getLogText();\r",
                    "var ctx = this;\r",
                    "var check = this.checkLastUploadRisk;\r",
                    "logText.setValue('');\r",
                    "var form = this.getUploadRiskForm().getForm();\r",
                    "if (form.isValid()) {\r",
                    "    form.submit({\r",
                    "        url: '../../service/upload.php?type=risk',\r",
                    "        params: Ext.Object.fromQueryString(document.location.search),\r",
                    "        waitMsg: CCS.Translator.getText('Uploading file...'),\r",
                    "        success: function(form, action) {\r",
                    "            logText.setValue(CCS.Translator.getText('Upload task started...'));\r",
                    "            var task = new Ext.util.DelayedTask(check, ctx);\r",
                    "            task.delay(2000);\r",
                    "\t\t\tctx.getUploadRiskWindow().close();\r",
                    "        },\r",
                    "        failure: function(form, action) {\r",
                    "            switch (action.failureType) {\r",
                    "                case Ext.form.action.Action.CLIENT_INVALID:\r",
                    "                    Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values', this.closeDialog, this);\r",
                    "                    break;\r",
                    "                case Ext.form.action.Action.CONNECT_FAILURE:\r",
                    "                    Ext.Msg.alert('Failure', 'Ajax communication failed', this.closeDialog, this);\r",
                    "                    break;\r",
                    "                case Ext.form.action.Action.SERVER_INVALID:\r",
                    "                    Ext.Msg.alert('Upload failed', action.result.errors[0].msg, this.closeDialog, this);\r",
                    "            }\r",
                    "\t\t\tctx.getUploadRiskWindow().close();\r",
                    "        }\r",
                    "    });\r",
                    "}"
                ]
            },
            "designerId": "2dcc8051-fa7c-4603-87fb-c8b953741339"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "btn"
                ],
                "fn": "uploadArea",
                "implHandler": [
                    "var logText = this.getLogText();\r",
                    "var ctx = this;\r",
                    "var check = this.checkLastUploadArea;\r",
                    "logText.setValue('');\r",
                    "var form = this.getUploadAreaForm().getForm();\r",
                    "if (form.isValid()) {\r",
                    "    form.submit({\r",
                    "        url: '../../service/upload.php?type=area',\r",
                    "        params: Ext.Object.fromQueryString(document.location.search),\r",
                    "        waitMsg: CCS.Translator.getText('Uploading file...'),\r",
                    "        success: function(form, action) {\r",
                    "            logText.setValue(CCS.Translator.getText('Upload task started...'));\r",
                    "            var task = new Ext.util.DelayedTask(check, ctx);\r",
                    "            task.delay(2000);\r",
                    "\t\t\tctx.getUploadAreaWindow().close();\r",
                    "        },\r",
                    "        failure: function(form, action) {\r",
                    "            switch (action.failureType) {\r",
                    "                case Ext.form.action.Action.CLIENT_INVALID:\r",
                    "                    Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values', this.closeDialog, this);\r",
                    "                    break;\r",
                    "                case Ext.form.action.Action.CONNECT_FAILURE:\r",
                    "                    Ext.Msg.alert('Failure', 'Ajax communication failed', this.closeDialog, this);\r",
                    "                    break;\r",
                    "                case Ext.form.action.Action.SERVER_INVALID:\r",
                    "                    Ext.Msg.alert('Upload failed', action.result.errors[0].msg, this.closeDialog, this);\r",
                    "            }\r",
                    "\t\t\tctx.getUploadAreaWindow().close();\r",
                    "        }\r",
                    "    });\r",
                    "}"
                ]
            },
            "designerId": "a7ddb366-5d80-4793-ba51-e7c76f80b174"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "logText",
                "selector": "#logText"
            },
            "designerId": "be9f6961-36dc-4c14-8690-183c65577743"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "designer|params": [
                    "type"
                ],
                "fn": "checkLastUpload",
                "implHandler": [
                    "var params = Ext.Object.fromQueryString(document.location.search);\r",
                    "var logText = this.getLogText();\r",
                    "logText.setValue('');\r",
                    "logText.setLoading('Updating...');\r",
                    "Ext.Ajax.request({\r",
                    "    url: '../../service/upload.php?type='+type,\r",
                    "    method: 'GET',\r",
                    "    params: params,\r",
                    "    success: function(response, object){\r",
                    "        var poll = false;\r",
                    "        var text = response.responseText;\r",
                    "        var result = Ext.JSON.decode(text);\r",
                    "        if (result.result.status > 1) {  // task has completed\r",
                    "            logText.setValue(result.result.log);\r",
                    "        } else if (result.result.status === 0) {  //task is queued\r",
                    "            logText.setValue(CCS.Translator.getText('Upload task queued...'));\r",
                    "            poll = true;\r",
                    "        } else if (result.result.status === 1) {  //task is running\r",
                    "            logText.setValue(CCS.Translator.getText('Upload task running...'));\r",
                    "            poll = true;\r",
                    "        }\r",
                    "        logText.setLoading(false);\r",
                    "        if (poll) {\r",
                    "            var task = new Ext.util.DelayedTask(this.checkLastUpload(type), this);\r",
                    "            task.delay(2000);\r",
                    "        }\r",
                    "    },\r",
                    "    failure: function(response, object){\r",
                    "        var text = response.responseText;\r",
                    "        logText.setValue('Failed to get task status: ' + text);\r",
                    "        logText.setLoading(false);\r",
                    "    },\r",
                    "    scope: this\r",
                    "});"
                ]
            },
            "designerId": "eaac1da3-4533-4236-888d-4ab7b68b7ccd"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "checkLastUploadControl",
                "implHandler": [
                    "var params = Ext.Object.fromQueryString(document.location.search);\r",
                    "var logText = this.getLogText();\r",
                    "logText.setValue('');\r",
                    "logText.setLoading('Updating...');\r",
                    "Ext.Ajax.request({\r",
                    "    url: '../../service/upload.php?type=control',\r",
                    "    method: 'GET',\r",
                    "    params: params,\r",
                    "    success: function(response, object){\r",
                    "        var poll = false;\r",
                    "        var text = response.responseText;\r",
                    "        var result = Ext.JSON.decode(text);\r",
                    "        if (result.result.status > 1) {  // task has completed\r",
                    "            logText.setValue(result.result.log);\r",
                    "        } else if (result.result.status === 0) {  //task is queued\r",
                    "            logText.setValue(CCS.Translator.getText('Upload task queued...'));\r",
                    "            poll = true;\r",
                    "        } else if (result.result.status === 1) {  //task is running\r",
                    "            logText.setValue(CCS.Translator.getText('Upload task running...'));\r",
                    "            poll = true;\r",
                    "        }\r",
                    "        logText.setLoading(false);\r",
                    "        if (poll) {\r",
                    "            var task = new Ext.util.DelayedTask(this.checkLastUploadControl, this);\r",
                    "            task.delay(2000);\r",
                    "        }\r",
                    "    },\r",
                    "    failure: function(response, object){\r",
                    "        var text = response.responseText;\r",
                    "        logText.setValue('Failed to get task status: ' + text);\r",
                    "        logText.setLoading(false);\r",
                    "    },\r",
                    "    scope: this\r",
                    "});"
                ]
            },
            "designerId": "2f4a2ac5-28a6-4c45-8a21-20e378ee1b16"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "checkLastUploadRisk",
                "implHandler": [
                    "var params = Ext.Object.fromQueryString(document.location.search);\r",
                    "var logText = this.getLogText();\r",
                    "logText.setValue('');\r",
                    "logText.setLoading('Updating...');\r",
                    "Ext.Ajax.request({\r",
                    "    url: '../../service/upload.php?type=risk',\r",
                    "    method: 'GET',\r",
                    "    params: params,\r",
                    "    success: function(response, object){\r",
                    "        var poll = false;\r",
                    "        var text = response.responseText;\r",
                    "        var result = Ext.JSON.decode(text);\r",
                    "        if (result.result.status > 1) {  // task has completed\r",
                    "            logText.setValue(result.result.log);\r",
                    "        } else if (result.result.status === 0) {  //task is queued\r",
                    "            logText.setValue(CCS.Translator.getText('Upload task queued...'));\r",
                    "            poll = true;\r",
                    "        } else if (result.result.status === 1) {  //task is running\r",
                    "            logText.setValue(CCS.Translator.getText('Upload task running...'));\r",
                    "            poll = true;\r",
                    "        }\r",
                    "        logText.setLoading(false);\r",
                    "        if (poll) {\r",
                    "            var task = new Ext.util.DelayedTask(this.checkLastUploadRisk, this);\r",
                    "            task.delay(2000);\r",
                    "        }\r",
                    "    },\r",
                    "    failure: function(response, object){\r",
                    "        var text = response.responseText;\r",
                    "        logText.setValue('Failed to get task status: ' + text);\r",
                    "        logText.setLoading(false);\r",
                    "    },\r",
                    "    scope: this\r",
                    "});"
                ]
            },
            "designerId": "738265b9-380a-4965-a891-23bab5233c54"
        },
        {
            "type": "basicfunction",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "checkLastUploadArea",
                "implHandler": [
                    "var params = Ext.Object.fromQueryString(document.location.search);\r",
                    "var logText = this.getLogText();\r",
                    "logText.setValue('');\r",
                    "logText.setLoading('Updating...');\r",
                    "Ext.Ajax.request({\r",
                    "    url: '../../service/upload.php?type=area',\r",
                    "    method: 'GET',\r",
                    "    params: params,\r",
                    "    success: function(response, object){\r",
                    "        var poll = false;\r",
                    "        var text = response.responseText;\r",
                    "        var result = Ext.JSON.decode(text);\r",
                    "        if (result.result.status > 1) {  // task has completed\r",
                    "            logText.setValue(result.result.log);\r",
                    "        } else if (result.result.status === 0) {  //task is queued\r",
                    "            logText.setValue(CCS.Translator.getText('Upload task queued...'));\r",
                    "            poll = true;\r",
                    "        } else if (result.result.status === 1) {  //task is running\r",
                    "            logText.setValue(CCS.Translator.getText('Upload task running...'));\r",
                    "            poll = true;\r",
                    "        }\r",
                    "        logText.setLoading(false);\r",
                    "        if (poll) {\r",
                    "            var task = new Ext.util.DelayedTask(this.checkLastUploadArea, this);\r",
                    "            task.delay(2000);\r",
                    "        }\r",
                    "    },\r",
                    "    failure: function(response, object){\r",
                    "        var text = response.responseText;\r",
                    "        logText.setValue('Failed to get task status: ' + text);\r",
                    "        logText.setLoading(false);\r",
                    "    },\r",
                    "    scope: this\r",
                    "});"
                ]
            },
            "designerId": "305e5ed4-e582-4d0a-88d1-14959a4137b7"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "uploadControlsBtn",
                "selector": "#uploadControlsBtn"
            },
            "designerId": "a174b993-335d-4987-8698-e1c9a4096cc3"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "uploadForm",
                "selector": "#uploadForm"
            },
            "designerId": "c85e2cb2-d5d7-4ef2-a43c-85820b970f0f"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "downloadRisk",
                "selector": "#downloadRisk"
            },
            "designerId": "7d920408-9405-4906-bfdf-6c61ee4884b6"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "downloadRiskTemplate",
                "selector": "#downloadRiskTemplate"
            },
            "designerId": "ff7716bb-ff84-4a5e-8137-7b76bacf69db"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "uploadRiskSaveBtn",
                "selector": "#uploadRiskSaveBtn"
            },
            "designerId": "7d57be42-8fd6-47d0-843f-62f9f579d800"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "uploadRiskCancelBtn",
                "selector": "#uploadRiskCancelBtn"
            },
            "designerId": "fb68fa40-8b02-427f-888c-2dd5fa5f39f6"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "uploadAreaSaveBtn",
                "selector": "#uploadAreaSaveBtn"
            },
            "designerId": "40da134a-8af5-419e-923e-ae8fc8cba5d9"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "uploadAreaCancelBtn",
                "selector": "#uploadAreaCancelBtn"
            },
            "designerId": "b1471c15-f181-41d9-95df-f37e4e7855b2"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "uploadRisksBtn",
                "selector": "#uploadRisksBtn"
            },
            "designerId": "eaf2d529-5f4b-41f2-bff3-b091c7e8085f"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "uploadAreasBtn",
                "selector": "#uploadAreasBtn"
            },
            "designerId": "c2ad7d20-dfcd-44fc-9503-19281526a04a"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "uploadRiskForm",
                "selector": "#uploadRiskForm"
            },
            "designerId": "7f9a606e-2efc-47fa-8c42-80f325c583af"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "uploadAreaForm",
                "selector": "#uploadAreaForm"
            },
            "designerId": "7d8d0f48-23ba-4a96-95b9-c12e37531c5d"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "autoCreate": true,
                "ref": "uploadRiskWindow",
                "selector": "#uploadRiskWindow",
                "xtype": "uploadRiskWindow"
            },
            "designerId": "197cea30-3a7a-4ea1-ae7c-607e8accd5bd"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "autoCreate": true,
                "ref": "uploadAreaWindow",
                "selector": "#uploadAreaWindow",
                "xtype": "uploadAreaWindow"
            },
            "designerId": "3be5db32-932f-4335-8b20-e0b598383e5c"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "downloadArea",
                "selector": "#downloadArea"
            },
            "designerId": "48ffffe7-bd61-4128-b553-69edca01c842"
        },
        {
            "type": "controllerref",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "ref": "downloadAreaTemplate",
                "selector": "#downloadAreaTemplate"
            },
            "designerId": "21f07053-678c-48f3-be5a-a9702770779d"
        }
    ]
}