# HG changeset patch # User Raimund Renkert # Date 1429192532 -7200 # Node ID 83c571b022f3f38006b1a09e3e80c8a0deb08951 # Parent 876456ce0a01ad40beb34212c7ddf453473e5433 Added window for laf file upload and use filtergrid buttons to export or import. diff -r 876456ce0a01 -r 83c571b022f3 app/controller/FilterResult.js --- a/app/controller/FilterResult.js Thu Apr 16 15:53:53 2015 +0200 +++ b/app/controller/FilterResult.js Thu Apr 16 15:55:32 2015 +0200 @@ -41,18 +41,42 @@ win.initData(); }, - addItem: function(button) { + addItem: function() { var win = Ext.create('Lada.view.window.ProbeCreate'); win.show(); win.initData(); - }, - uploadFile: function(button) { + uploadFile: function() { + var win = Ext.create('Lada.view.window.FileUpload', { + title: 'Datenimport', + modal: true + }); + win.show(); }, downloadFile: function(button) { + var grid = button.up('grid'); + var selection = grid.getView().getSelectionModel().getSelection(); + var proben = []; + for (var i = 0; i < selection.length; i++) { + proben.push(selection[i].get('id')); + } + Ext.Ajax.request({ + method: 'POST', + url: '/lada-server/export/laf', + jsonData: {'proben': proben}, + headers: {'X-OPENID-PARAMS': Lada.openIDParams}, + success: function(response) { + var content = response.responseText; + var blob = new Blob([content],{type: 'text/plain'}); + saveAs(blob, 'export.laf'); + }, + failure: function() { + Ext.Msg.alert('Fehler', 'Failed to create LAF-File!'); + } + }); } }); diff -r 876456ce0a01 -r 83c571b022f3 app/view/window/FileUpload.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/view/window/FileUpload.js Thu Apr 16 15:55:32 2015 +0200 @@ -0,0 +1,85 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ + +/** + */ +Ext.define('Lada.view.window.FileUpload', { + extend: 'Ext.window.Window', + + layout: 'hbox', + + file: null, + + initComponent: function() { + var me = this; + this.browseButton = Ext.create('Ext.ux.upload.BrowseButton', { + buttonText: 'Durchsuchen...', + margin: '3, 3, 3, 3' + }); + this.fileInput = Ext.create('Ext.form.field.Text', { + allowBlank: false, + emptyText: 'Wählen Sie eine Datei', + hideLabel: true, + margin: '3, 3, 3, 3' + }); + this.items = [ + this.fileInput, + this.browseButton + ]; + this.buttons = [{ + text: 'Speichern', + handler: this.uploadFile + }, { + text: 'Abbrechen', + handler: this.abort + }]; + this.on('afterrender', function() { + this.browseButton.fileInputEl.dom.removeAttribute('multiple', '0'); + }, this); + this.browseButton.on('fileselected', this.fileSelected, this); + this.callParent(arguments); + }, + + abort: function(button) { + var win = button.up('window'); + win.close(); + }, + + fileSelected: function(input, file) { + var item = Ext.create('Ext.ux.upload.Item', { + fileApiObject: file[0] + }); + this.fileInput.setValue(item.getName()); + this.file = item; + }, + + uploadFile: function(button) { + var win = button.up('window'); + var uploader = Ext.create('Ext.ux.upload.uploader.ExtJsUploader', { + extraHeaders: { + 'X-OPENID-PARAMS': Lada.openIDParams + }, + method: 'POST', + url: '/lada-server/import/laf' + }); + this.mon(uploader, 'uploadsuccess', win.uploadSuccess, win); + this.mon(uploader, 'uploadfailure', win.uploadFailure, win); + console.log(button.up('window')); + if (button.up('window').file !== null) { + uploader.uploadItem(button.up('window').file); + } + }, + + uploadSuccess: function() { + this.close(); + }, + + uploadFailure: function() { + this.close(); + } +});