comparison app/controller/Kommentare.js @ 111:6273b73b4b27

Replaced Logic for Kommentare. Use copied code form Orte.
author Torsten Irländer <torsten.irlaender@intevation.de>
date Wed, 19 Jun 2013 14:11:35 +0200
parents 84f32c62670f
children 7b1140bd8b3d
comparison
equal deleted inserted replaced
110:c4f97a5a9939 111:6273b73b4b27
1 Ext.define('Lada.controller.Kommentare', { 1 Ext.define('Lada.controller.Kommentare', {
2 extend: 'Ext.app.Controller', 2 extend: 'Ext.app.Controller',
3 views: [ 3 views: [
4 'kommentare.List', 4 'kommentare.List',
5 'kommentare.Edit',
6 'kommentare.Create' 5 'kommentare.Create'
7 ], 6 ],
8 stores: [ 7 stores: [
9 'Kommentare' 8 'Kommentare'
10 ], 9 ],
15 console.log('Initialising the Kommentare controller'); 14 console.log('Initialising the Kommentare controller');
16 this.control({ 15 this.control({
17 // CSS like selector to select element in the viewport. See 16 // CSS like selector to select element in the viewport. See
18 // ComponentQuery documentation for more details. 17 // ComponentQuery documentation for more details.
19 'kommentarelist': { 18 'kommentarelist': {
20 // Map Doubleclick on rows of the probenlist.
21 itemdblclick: this.editKommentar 19 itemdblclick: this.editKommentar
22 }, 20 },
23 'kommentarelist toolbar button[action=add]': { 21 'kommentarelist toolbar button[action=add]': {
24 click: this.addKommentar 22 click: this.addKommentar
25 }, 23 },
26 'kommentarelist toolbar button[action=delete]': { 24 'kommentarelist toolbar button[action=delete]': {
27 click: this.deleteKommentar 25 click: this.deleteKommentar
28 }, 26 },
29 'kommentaredit button[action=save]': { 27 'kommentarecreate form': {
30 click: this.saveKommentar 28 savesuccess: this.createSuccess,
29 savefailure: this.createFailure
30 },
31 'kommentareedit form': {
32 savesuccess: this.editSuccess,
33 savefailure: this.editFailure
31 } 34 }
32 }); 35 });
33 }, 36 },
34 addKommentar: function(button) { 37 addKommentar: function(button) {
35 console.log('Adding new Kommentar'); 38 console.log('Adding new Kommentar');
36 var view = Ext.create('Lada.view.kommentare.Create'); 39 var view = Ext.widget('kommentarecreate');
37 var form = view.down('form'); 40 },
38 // Set probeId 41 editKommentar: function(grid, record) {
39 var probenform = button.up('form'); 42 console.log('Editing Kommentar');
40 var probe = probenform.getRecord(); 43 var view = Ext.widget('kommentarecreate', {model: record});
41 var probeId = probe.get('probeId'); 44 console.log("Loaded Kommentar with ID " + record.getId()); //outputs ID
42 form.model.set('probeId', probeId);
43 }, 45 },
44 deleteKommentar: function(button) { 46 deleteKommentar: function(button) {
45 // Get selected item in grid 47 // Get selected item in grid
46 var grid = button.up('grid'); 48 var grid = button.up('grid');
47 var selection = grid.getView().getSelectionModel().getSelection()[0]; 49 var selection = grid.getView().getSelectionModel().getSelection()[0];
54 } else { 56 } else {
55 console.log('Cancel Deleting Kommentar'); 57 console.log('Cancel Deleting Kommentar');
56 } 58 }
57 }); 59 });
58 }, 60 },
59 editKommentar: function(grid, record) { 61 createSuccess: function(form, record, operation) {
60 // Create new window to edit the seletced record. 62 // Reload store
61 var view = Ext.widget('kommentaredit'); 63 var store = this.getKommentareStore();
62 var form = view.down('form'); 64 store.reload();
63 form.loadRecord(record); 65 var win = form.up('window');
66 win.close();
64 }, 67 },
65 saveKommentar: function(button) { 68 createFailure: function(form, record, operation) {
66 var win = button.up('window'); 69 Ext.MessageBox.show({
67 var form = win.down('form'); 70 title: 'Fehler beim Speichern',
68 var record = form.getRecord(); 71 msg: form.message,
69 var values = form.getValues(); 72 icon: Ext.MessageBox.ERROR,
73 buttons: Ext.Msg.OK
74 });
75 },
76 editSuccess: function(form, record, operation) {
77 // Reload store
70 var store = this.getKommentareStore(); 78 var store = this.getKommentareStore();
71 record.set(values); 79 store.reload();
72 store.add(record); 80 var win = form.up('window');
73 store.sync();
74 console.log('Saving Kommentar');
75 win.close(); 81 win.close();
82 },
83 editFailure: function(form, record, operation) {
84 Ext.MessageBox.show({
85 title: 'Fehler beim Speichern',
86 msg: form.message,
87 icon: Ext.MessageBox.ERROR,
88 buttons: Ext.Msg.OK
89 });
76 } 90 }
77 }); 91 });

http://lada.wald.intevation.org