raimund@725: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz raimund@725: * Software engineering by Intevation GmbH raimund@725: * raimund@725: * This file is Free Software under the GNU GPL (v>=3) raimund@725: * and comes with ABSOLUTELY NO WARRANTY! Check out raimund@725: * the documentation coming with IMIS-Labordaten-Application for details. raimund@725: */ raimund@725: raimund@725: /** dustin@890: * This is a simple Fileupload Window, used to upload LAF-Files raimund@725: */ raimund@725: Ext.define('Lada.view.window.FileUpload', { raimund@725: extend: 'Ext.window.Window', tom@1227: requires: [ tom@1227: 'Ext.ux.upload.BrowseButton', tom@1227: 'Ext.ux.upload.Item', tom@1227: 'Ext.ux.upload.uploader.ExtJsUploader', tom@1227: 'Lada.view.window.ImportResponse' tom@1227: ], raimund@725: raimund@725: layout: 'hbox', raimund@725: raimund@725: file: null, raimund@725: dustin@890: /** dustin@890: * This function initialises the Window dustin@890: */ raimund@725: initComponent: function() { raimund@725: var me = this; raimund@725: this.browseButton = Ext.create('Ext.ux.upload.BrowseButton', { raimund@725: buttonText: 'Durchsuchen...', raimund@725: margin: '3, 3, 3, 3' raimund@725: }); raimund@725: this.fileInput = Ext.create('Ext.form.field.Text', { raimund@725: allowBlank: false, raimund@725: emptyText: 'Wählen Sie eine Datei', raimund@725: hideLabel: true, raimund@725: margin: '3, 3, 3, 3' raimund@725: }); raimund@725: this.items = [ raimund@725: this.fileInput, raimund@725: this.browseButton raimund@725: ]; raimund@725: this.buttons = [{ raimund@725: text: 'Speichern', raimund@725: handler: this.uploadFile raimund@725: }, { raimund@725: text: 'Abbrechen', raimund@725: handler: this.abort raimund@725: }]; raimund@725: this.on('afterrender', function() { raimund@725: this.browseButton.fileInputEl.dom.removeAttribute('multiple', '0'); raimund@725: }, this); raimund@725: this.browseButton.on('fileselected', this.fileSelected, this); raimund@725: this.callParent(arguments); raimund@725: }, raimund@725: dustin@890: /** dustin@890: * @private dustin@890: * A handler for a Abort-Button dustin@890: */ raimund@725: abort: function(button) { raimund@725: var win = button.up('window'); raimund@725: win.close(); raimund@725: }, raimund@725: dustin@890: /** dustin@890: * @private dustin@890: * A handler for the Input field dustin@890: */ raimund@725: fileSelected: function(input, file) { raimund@725: var item = Ext.create('Ext.ux.upload.Item', { raimund@725: fileApiObject: file[0] raimund@725: }); raimund@725: this.fileInput.setValue(item.getName()); raimund@725: this.file = item; raimund@725: }, raimund@725: dustin@890: /** dustin@890: * @private dustin@890: * A handler for the Upload-Button dustin@890: */ raimund@725: uploadFile: function(button) { dustin@809: // TODO Error handling ? raimund@725: var win = button.up('window'); raimund@725: var uploader = Ext.create('Ext.ux.upload.uploader.ExtJsUploader', { raimund@725: extraHeaders: { raimund@725: 'X-OPENID-PARAMS': Lada.openIDParams raimund@725: }, raimund@725: method: 'POST', raimund@1221: timeout: 600 * 1000, dustin@999: url: 'lada-server/data/import/laf' raimund@725: }); raimund@725: this.mon(uploader, 'uploadsuccess', win.uploadSuccess, win); raimund@725: this.mon(uploader, 'uploadfailure', win.uploadFailure, win); raimund@725: if (button.up('window').file !== null) { raimund@725: uploader.uploadItem(button.up('window').file); raimund@1221: win.setLoading(Lada.getApplication().bundle.getMsg('processingData')); raimund@725: } raimund@725: }, raimund@725: dustin@890: /** dustin@890: * @private dustin@890: */ raimund@730: uploadSuccess: function(file, response) { raimund@725: this.close(); raimund@730: var win = Ext.create('Lada.view.window.ImportResponse', { raimund@730: data: response.response.responseText, raimund@730: message: response.message, raimund@730: fileName: file.config.fileApiObject.name, raimund@730: title: 'Importergebnis' raimund@730: }); raimund@730: win.show(); raimund@725: }, raimund@725: dustin@890: /** dustin@890: * @private dustin@890: */ raimund@730: uploadFailure: function(file, response) { dustin@809: // TODO handle Errors correctly, especially AuthenticationTimeouts raimund@725: this.close(); raimund@730: var win = Ext.create('Lada.view.window.ImportResponse', { raimund@730: data: response.response.responseText, raimund@730: message: response.message, raimund@730: fileName: file.config.fileApiObject.name, raimund@730: title: 'Importergebnis' raimund@730: }); raimund@730: win.show(); raimund@725: } raimund@725: });