{
    "type": "Ext.window.Window",
    "reference": {
        "name": "items",
        "type": "array"
    },
    "codeClass": null,
    "userConfig": {
        "designer|userAlias": "LicenseWindow",
        "designer|userClassName": "LicenseWindow",
        "height": null,
        "itemId": "LicenseWindow",
        "layout": "fit",
        "modal": true,
        "title": "Add/Edit License",
        "width": 400
    },
    "designerId": "1fcaff27-8504-48d6-ae3d-552152c1007e",
    "cn": [
        {
            "type": "Ext.form.Panel",
            "reference": {
                "name": "items",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "bodyPadding": 10,
                "header": false,
                "itemId": "licenseCategoryForm",
                "pollForChanges": null,
                "title": "My Form"
            },
            "designerId": "2fe8358c-3650-4d9c-8533-0dd5cc86c8d1",
            "cn": [
                {
                    "type": "Ext.container.Container",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "container|align": "stretch",
                        "container|pack": "end",
                        "layout": "vbox"
                    },
                    "designerId": "55c42672-24c2-41d8-a5f2-3e575a30db87",
                    "cn": [
                        {
                            "type": "Ext.form.Panel",
                            "reference": {
                                "name": "items",
                                "type": "array"
                            },
                            "codeClass": null,
                            "userConfig": {
                                "bodyPadding": null,
                                "border": false,
                                "container|align": "stretch",
                                "header": false,
                                "itemId": "uploadForm1",
                                "layout": "vbox",
                                "layout|flex": 1,
                                "maxWidth": null,
                                "title": "Upload file"
                            },
                            "designerId": "bf3f754f-2a43-41fc-90e9-8bc57531b5c6",
                            "cn": [
                                {
                                    "type": "Ext.form.field.File",
                                    "reference": {
                                        "name": "items",
                                        "type": "array"
                                    },
                                    "codeClass": null,
                                    "userConfig": {
                                        "allowBlank": false,
                                        "buttonText": "Select file",
                                        "fieldLabel": "File",
                                        "id": null,
                                        "itemId": "fileUploadField",
                                        "labelSeparator": " ",
                                        "layout|flex": 1,
                                        "msgTarget": "side",
                                        "name": "file"
                                    },
                                    "designerId": "62f2294b-e5e2-4b77-bb0f-7d147ba07dff"
                                },
                                {
                                    "type": "Ext.form.field.Date",
                                    "reference": {
                                        "name": "items",
                                        "type": "array"
                                    },
                                    "codeClass": null,
                                    "userConfig": {
                                        "allowBlank": false,
                                        "fieldLabel": "Purchase date",
                                        "format": "Y-m-d",
                                        "itemId": "invoiceDateField",
                                        "labelSeparator": " ",
                                        "layout|flex": null,
                                        "name": "invoicedate",
                                        "padding": null
                                    },
                                    "designerId": "f0547c77-5b3f-464b-a5ec-f9afc03c57ef"
                                },
                                {
                                    "type": "Ext.form.field.Number",
                                    "reference": {
                                        "name": "items",
                                        "type": "array"
                                    },
                                    "codeClass": null,
                                    "userConfig": {
                                        "allowBlank": false,
                                        "fieldLabel": "Amount",
                                        "itemId": "amountField",
                                        "labelSeparator": " ",
                                        "layout|flex": null,
                                        "name": "amount",
                                        "padding": null
                                    },
                                    "designerId": "f37c0b2f-70a5-4a09-be52-6497f6f3d53f"
                                },
                                {
                                    "type": "Ext.form.field.TextArea",
                                    "reference": {
                                        "name": "items",
                                        "type": "array"
                                    },
                                    "codeClass": null,
                                    "userConfig": {
                                        "fieldLabel": "Comment",
                                        "itemId": "commentField",
                                        "labelSeparator": " ",
                                        "layout|flex": null,
                                        "name": "comment"
                                    },
                                    "configAlternates": {
                                        "resizable": "boolean"
                                    },
                                    "designerId": "f398b743-4dfd-47d1-8cbe-85600701da21"
                                },
                                {
                                    "type": "Ext.toolbar.Spacer",
                                    "reference": {
                                        "name": "items",
                                        "type": "array"
                                    },
                                    "codeClass": null,
                                    "userConfig": {
                                        "layout|flex": 1
                                    },
                                    "designerId": "3e0a6a7c-6179-480d-9a27-9a410d97f015"
                                }
                            ]
                        },
                        {
                            "type": "Ext.container.Container",
                            "reference": {
                                "name": "items",
                                "type": "array"
                            },
                            "codeClass": null,
                            "userConfig": {
                                "container|align": "stretch",
                                "layout": "hbox",
                                "layout|flex": 1
                            },
                            "designerId": "0ef144fc-5701-4fc0-a225-7b678806b86d",
                            "cn": [
                                {
                                    "type": "Ext.toolbar.Spacer",
                                    "reference": {
                                        "name": "items",
                                        "type": "array"
                                    },
                                    "codeClass": null,
                                    "userConfig": {
                                        "layout|flex": 1
                                    },
                                    "designerId": "968def84-429a-408e-a738-3bcc6b3b1389"
                                },
                                {
                                    "type": "Ext.button.Button",
                                    "reference": {
                                        "name": "items",
                                        "type": "array"
                                    },
                                    "codeClass": null,
                                    "userConfig": {
                                        "icon": "../gfx/add.png",
                                        "itemId": "uploadButton",
                                        "layout|flex": null,
                                        "scale": "medium",
                                        "text": "Save"
                                    },
                                    "designerId": "5647149f-2a5d-48ff-9f4e-146acf4d4449",
                                    "cn": [
                                        {
                                            "type": "fixedfunction",
                                            "reference": {
                                                "name": "items",
                                                "type": "array"
                                            },
                                            "codeClass": null,
                                            "userConfig": {
                                                "designer|params": [
                                                    "button",
                                                    "e"
                                                ],
                                                "fn": "handler",
                                                "implHandler": [
                                                    "var orgParams = Ext.Object.fromQueryString(document.location.search);\r",
                                                    "\r",
                                                    "var tempurl = '../../service/upload_file.php?user=' + orgParams.user;\r",
                                                    "\r",
                                                    "var form = this.up('form').getForm();\r",
                                                    "var gridPanel = MyApp.app.getController('GridController').getGridPanel();\r",
                                                    "\r",
                                                    "/*var uploadField = MyApp.app.getController('GridController').getFileUploadField();\r",
                                                    "console.log(uploadField);\r",
                                                    "console.log(uploadField.getEl());*/\r",
                                                    "\r",
                                                    "\r",
                                                    "if (form.isValid())\r",
                                                    "{\r",
                                                    "\tgridPanel.setLoading(CCS.Translator.getText('Loading...'));\r",
                                                    "\r",
                                                    "\t//console.log('UPLOAD FILE');\r",
                                                    "\r",
                                                    "\tform.submit({\r",
                                                    "\t\turl: tempurl,\r",
                                                    "\t\twaitMsg: 'Uploading file',\r",
                                                    "\t\tsuccess: function(fp, o) {\r",
                                                    "\t\t\tconsole.log(o.result.data);\r",
                                                    "\r",
                                                    "\t\t\tgridPanel.setLoading(false);\r",
                                                    "\t\t\tgridPanel.getStore().load();\r",
                                                    "\t\t\tif (o.result.data !== undefined || o.result.data !== null)\r",
                                                    "\t\t\t{\r",
                                                    "\t\t\t\tvar convertedSize = convertSize(o.result.data.size);\r",
                                                    "\t\t\t\tExt.Msg.alert(o.result.msg, 'Upload: <b>' + o.result.data.name + '</b> <br> Size: <b>' + convertedSize + '</b>');\r",
                                                    "\r",
                                                    "\t\t\t\tvar periodDateField = MyApp.app.getController('GridController').getPeriodDateField();\r",
                                                    "\t\t\t\t//periodDateField.reset();\r",
                                                    "\t\t\t\tvar invoiceDateField = MyApp.app.getController('GridController').getInvoiceDateField();\r",
                                                    "\t\t\t\t//invoiceDateField.reset();\r",
                                                    "\t\t\t\tvar amountField = MyApp.app.getController('GridController').getAmountField();\r",
                                                    "\t\t\t\t//amountField.reset();\r",
                                                    "\t\t\t}\r",
                                                    "\t\t},\r",
                                                    "\t\tfailure: function(fp, o) {\r",
                                                    "\t\t\t//console.log('FAILURE');\r",
                                                    "\r",
                                                    "\t\t\tgridPanel.setLoading(false);\r",
                                                    "\t\t\tvar message = \"\";\r",
                                                    "\t\t\tif (o.result.data !== undefined || o.result.data !== null)\r",
                                                    "\t\t\t{\r",
                                                    "\t\t\t\tvar convertedSize = convertSize(o.result.data.size);\r",
                                                    "\t\t\t\tif (o.result.data.error == \"size\")\r",
                                                    "\t\t\t\t{\r",
                                                    "\t\t\t\tvar convetedMaxSize = convertSize(o.result.data.maxsize);\r",
                                                    "\t\t\t\tmessage = 'The file <b>' + o.result.data.name + '</b> is <b>' + convertedSize + '</b><br>';\r",
                                                    "\t\t\t\tmessage += 'Max file size is <b>'+ convetedMaxSize +'</b>';\r",
                                                    "\t\t\t\t}\r",
                                                    "\t\t\t\telse if (o.result.data.error == \"file\")\r",
                                                    "\t\t\t\t{\r",
                                                    "\t\t\t\t\tmessage = o.result.data.errormsg;\r",
                                                    "\t\t\t\t}\r",
                                                    "\r",
                                                    "\t\t\t\tExt.Msg.alert(o.result.msg, message);\r",
                                                    "\t\t\t}\r",
                                                    "\t\t}\r",
                                                    "\t});\r",
                                                    "}\r",
                                                    "\r",
                                                    "\r",
                                                    "function convertSize(size) {\r",
                                                    "\tif (size >= (1024*1024)) // 1 MB\r",
                                                    "\t{\r",
                                                    "\t\tvalue = size / (1024 * 1024);\r",
                                                    "\t\treturn value.toFixed(1) + \" MB\";\r",
                                                    "\t}\r",
                                                    "\telse if (size >= 1024) // 1 KB\r",
                                                    "\t{\r",
                                                    "\t\tvalue = size / 1024;\r",
                                                    "\t\treturn value.toFixed(1) + \" KB\";\r",
                                                    "\t}\r",
                                                    "\telse\r",
                                                    "\t{\r",
                                                    "\t\treturn size + \" B\";\r",
                                                    "\t}\r",
                                                    "}"
                                                ]
                                            },
                                            "designerId": "15a4abcb-2278-40de-b7fc-79eae5168c36"
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}