comparison app/controller/Messwert.js @ 197:748614e867b1

Added messwerte controller to be able to add, edit and delete messwerte.
author Torsten Irländer <torsten.irlaender@intevation.de>
date Mon, 08 Jul 2013 16:12:34 +0200
parents
children f0c59e7ee0bc
comparison
equal deleted inserted replaced
196:2cf26580d75d 197:748614e867b1
1 Ext.define('Lada.controller.Messwert', {
2 extend: 'Ext.app.Controller',
3 views: [
4 'messwerte.Create'
5 ],
6 stores: [
7 'Messungen',
8 'Messwerte',
9 'Messeinheit',
10 'Messgroessen'
11 ],
12 init: function() {
13 console.log('Initialising the Messungen controller');
14 this.control({
15 // CSS like selector to select element in the viewpzusatzwert. See
16 // ComponentQuery documentation for more details.
17 'messwertelist': {
18 itemdblclick: this.editMesswert
19 },
20 'messwertelist toolbar button[action=add]': {
21 click: this.addMesswert
22 },
23 'messwertelist toolbar button[action=delete]': {
24 click: this.deleteMesswert
25 },
26 'messwertecreate button[action=save]': {
27 click: this.saveMesswert
28 },
29 'messwertecreate form': {
30 savesuccess: this.createSuccess,
31 savefailure: this.createFailure
32 }
33 });
34 },
35 saveMesswert: function(button) {
36 console.log('Saving MesswerMesswert');
37 var form = button.up('window').down('form');
38 form.commit();
39 },
40 addMesswert: function(button) {
41 console.log('Adding new Messung for Probe ' + button.probeId);
42 var messung = Ext.create('Lada.model.Messwert');
43 messung.set('probeId', button.probeId);
44 var view = Ext.widget('messwertecreate', {model: messung});
45 },
46 editMesswert: function(grid, record) {
47 console.log('Editing Messwert');
48 var view = Ext.widget('messwertecreate', {model: record});
49 console.log("Loaded Messwert with ID " + record.getId()); //outputs ID
50 },
51 deleteMesswert: function(button) {
52 // Get selected item in grid
53 var grid = button.up('grid');
54 var selection = grid.getView().getSelectionModel().getSelection()[0];
55 Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn){
56 if(btn === 'yes'){
57 var store = grid.getStore();
58 store.remove(selection);
59 store.sync();
60 console.log('Deleting Kommentar');
61 } else {
62 console.log('Cancel Deleting Kommentar');
63 }
64 });
65 },
66 createSuccess: function(form, record, operation) {
67 // Reload store
68 var store = this.getMessungenStore();
69 store.reload();
70 var win = form.up('window');
71 win.close();
72 },
73 createFailure: function(form, record, operation) {
74 Ext.MessageBox.show({
75 title: 'Fehler beim Speichern',
76 msg: form.message,
77 icon: Ext.MessageBox.ERROR,
78 buttons: Ext.Msg.OK
79 });
80 },
81 editSuccess: function(form, record, operation) {
82 // Reload store
83 var store = this.getMessungenStore();
84 store.reload();
85 var win = form.up('window');
86 win.close();
87 },
88 editFailure: function(form, record, operation) {
89 Ext.MessageBox.show({
90 title: 'Fehler beim Speichern',
91 msg: form.message,
92 icon: Ext.MessageBox.ERROR,
93 buttons: Ext.Msg.OK
94 });
95 }
96 });

http://lada.wald.intevation.org