comparison 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
comparison
equal deleted inserted replaced
356:166203f7119d 357:94884cd8f8c0
3 */ 3 */
4 Ext.define('Lada.controller.Proben', { 4 Ext.define('Lada.controller.Proben', {
5 extend: 'Lada.controller.Base', 5 extend: 'Lada.controller.Base',
6 views: [ 6 views: [
7 'proben.Edit', 7 'proben.Edit',
8 'proben.Create' 8 'proben.Create',
9 'proben.Import'
9 ], 10 ],
10 stores: [ 11 stores: [
11 'Proben', 12 'Proben',
12 'Zusatzwerte', 13 'Zusatzwerte',
13 'Probenzusatzwerte', 14 'Probenzusatzwerte',
25 itemdblclick: this.editItem 26 itemdblclick: this.editItem
26 }, 27 },
27 'probenlist toolbar button[action=add]': { 28 'probenlist toolbar button[action=add]': {
28 click: this.addItem 29 click: this.addItem
29 }, 30 },
31 'probenlist toolbar button[action=import]': {
32 click: this.selectUploadFile
33 },
30 'probencreate button[action=save]': { 34 'probencreate button[action=save]': {
31 click: this.saveItem 35 click: this.saveItem
32 }, 36 },
33 'probenedit button[action=save]': { 37 'probenedit button[action=save]': {
34 click: this.saveItem 38 click: this.saveItem
39 },
40 'probenimport button[action=save]': {
41 click: this.uploadItem
35 }, 42 },
36 'probencreate form': { 43 'probencreate form': {
37 savesuccess: this.createSuccess, 44 savesuccess: this.createSuccess,
38 savefailure: this.createFailure 45 savefailure: this.createFailure
39 }, 46 },
44 }); 51 });
45 }, 52 },
46 addItem: function(button) { 53 addItem: function(button) {
47 console.log('Adding new Probe'); 54 console.log('Adding new Probe');
48 var view = Ext.widget('probencreate'); 55 var view = Ext.widget('probencreate');
56 },
57 /**
58 * Opens a window with a file chooser to select the file to upload
59 * @private
60 */
61 selectUploadFile: function(button) {
62 console.log('Importing');
63 var view = Ext.widget('probenimport');
64 },
65 /** Uploads the selected file the the server
66 * @private
67 */
68 uploadItem: function(button) {
69 var win = button.up('window');
70 var form = win.down('form');
71 if(form.isValid()){
72 form.submit({
73 url: 'server/rest/proben/import',
74 waitMsg: 'Importiere...',
75 // TODO: Handle the response correct. o must must contain the
76 // filename (None) <2013-08-13 16:17>
77 success: function(fp, resp) {
78 Ext.Msg.alert('Erfolg! ', 'Die Datei"' + resp.result.file + '" wurde erfolgreich importiert.');
79 win.close();
80 },
81 failure: function(fp, resp) {
82 Ext.Msg.alert('Fehler! ', 'Die Datei"' + resp.result.file + '" wurde nicht importiert.');
83 win.close();
84 }
85 });
86 }
49 }, 87 },
50 editItem: function(grid, record) { 88 editItem: function(grid, record) {
51 console.log('Editing Probe'); 89 console.log('Editing Probe');
52 var id = record.get('probeId'); 90 var id = record.get('probeId');
53 var view = Ext.widget('probenedit', {modelId: id}); 91 var view = Ext.widget('probenedit', {modelId: id});

http://lada.wald.intevation.org