diff app/controller/Proben.js @ 357:94884cd8f8c0

Added logic to upload a file to the server.
author Torsten Irländer <torsten.irlaender@intevation.de>
date Tue, 13 Aug 2013 16:21:08 +0200
parents bd77b6055791
children 6a7a9267e00f
line wrap: on
line diff
--- 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');

http://lada.wald.intevation.org