[Lada-commits] [PATCH 4 of 5] Added logic to upload a file to the server

Wald Commits scm-commit at wald.intevation.org
Tue Aug 13 16:23:32 CEST 2013


# HG changeset patch
# User Torsten Irländer <torsten.irlaender at intevation.de>
# Date 1376403668 -7200
# Node ID 94884cd8f8c0a27d4c21748b1b3cef43bdaeac8f
# Parent  166203f7119deb11fb41f9ddf263bc75047a152b
Added logic to upload a file to the server.

diff -r 166203f7119d -r 94884cd8f8c0 app/controller/Proben.js
--- a/app/controller/Proben.js	Tue Aug 13 12:37:03 2013 +0200
+++ b/app/controller/Proben.js	Tue Aug 13 16:21:08 2013 +0200
@@ -5,7 +5,8 @@
     extend: 'Lada.controller.Base',
     views: [
         'proben.Edit',
-        'proben.Create'
+        'proben.Create',
+        'proben.Import'
     ],
     stores: [
         'Proben',
@@ -27,12 +28,18 @@
             'probenlist toolbar button[action=add]': {
                 click: this.addItem
             },
+            'probenlist toolbar button[action=import]': {
+                click: this.selectUploadFile
+            },
             'probencreate button[action=save]': {
                 click: this.saveItem
             },
             'probenedit button[action=save]': {
                 click: this.saveItem
             },
+            'probenimport button[action=save]': {
+                click: this.uploadItem
+            },
             'probencreate form': {
                 savesuccess: this.createSuccess,
                 savefailure: this.createFailure
@@ -47,6 +54,37 @@
         console.log('Adding new Probe');
         var view = Ext.widget('probencreate');
     },
+    /**
+     * Opens a window with a file chooser to select the file to upload
+     * @private
+     */
+    selectUploadFile: function(button) {
+        console.log('Importing');
+        var view = Ext.widget('probenimport');
+    },
+    /** Uploads the selected file the the server
+     * @private
+     */
+    uploadItem: function(button) {
+        var win = button.up('window');
+        var form = win.down('form');
+        if(form.isValid()){
+            form.submit({
+                url: 'server/rest/proben/import',
+                waitMsg: 'Importiere...',
+                // TODO: Handle the response correct. o must must contain the
+                // filename (None) <2013-08-13 16:17>
+                success: function(fp, resp) {
+                    Ext.Msg.alert('Erfolg! ', 'Die Datei"' + resp.result.file + '" wurde erfolgreich importiert.');
+                    win.close();
+                },
+                failure: function(fp, resp) {
+                    Ext.Msg.alert('Fehler! ', 'Die Datei"' + resp.result.file + '" wurde nicht importiert.');
+                    win.close();
+                }
+            });
+        }
+    },
     editItem: function(grid, record) {
         console.log('Editing Probe');
         var id = record.get('probeId');
diff -r 166203f7119d -r 94884cd8f8c0 app/view/Viewport.js
--- a/app/view/Viewport.js	Tue Aug 13 12:37:03 2013 +0200
+++ b/app/view/Viewport.js	Tue Aug 13 16:21:08 2013 +0200
@@ -17,7 +17,7 @@
     ],
     initComponent: function() {
         console.log('Setting up Viewport');
-        //this.initSearch();
+        this.initSearch();
 
         // Development related: 
         // Disable "initSearch" call and enable one of the following init
@@ -26,9 +26,9 @@
         //this.initProbe();
         //this.initOrt();
         //this.initMessung();
-        this.initMesswert();
+        //this.initMesswert();
 
-        //this.setInfo();
+        this.setInfo();
         this.callParent(arguments);
     },
     /**
diff -r 166203f7119d -r 94884cd8f8c0 app/view/proben/Import.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/view/proben/Import.js	Tue Aug 13 16:21:08 2013 +0200
@@ -0,0 +1,28 @@
+/*
+ * Window to import a Probe
+ */
+Ext.define('Lada.view.proben.Import', {
+    extend: 'Ext.window.Window',
+    alias: 'widget.probenimport',
+
+    title: 'Maske für §3-Proben Import',
+    autoShow: true,
+    autoScroll: true,
+    modal: true,
+    initComponent: function() {
+        this.buttons = [
+            {
+                text: 'Speichern',
+                action: 'save',
+            },
+            {
+                text: 'Abbrechen',
+                scope: this,
+                handler: this.close,
+            }
+        ];
+        var form = Ext.create('Lada.view.proben.ImportForm');
+        this.items = [form];
+        this.callParent();
+    }
+});
diff -r 166203f7119d -r 94884cd8f8c0 app/view/proben/ImportForm.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/view/proben/ImportForm.js	Tue Aug 13 16:21:08 2013 +0200
@@ -0,0 +1,15 @@
+/*
+ * Formular to create a Probe
+ */
+Ext.define('Lada.view.proben.ImportForm', {
+    extend: 'Ext.form.Panel',
+    initComponent: function() {
+       this.items = [
+            {
+                xtype: 'fileuploadfield',
+                title: 'Importdate'
+            }
+        ];
+        this.callParent();
+    }
+});
diff -r 166203f7119d -r 94884cd8f8c0 app/view/proben/List.js
--- a/app/view/proben/List.js	Tue Aug 13 12:37:03 2013 +0200
+++ b/app/view/proben/List.js	Tue Aug 13 16:21:08 2013 +0200
@@ -35,6 +35,11 @@
                         text: 'Hinzufügen',
                         icon: 'gfx/plus.gif',
                         action: 'add'
+                    },
+                    {
+                        text: 'Import',
+                        icon: 'gfx/plus.gif',
+                        action: 'import'
                     }
                 ]
             }


More information about the Lada-commits mailing list