Mercurial > lada > lada-client
comparison app/controller/MKommentare.js @ 291:e95662994c50
Inherit from Base controller
author | Torsten Irländer <torsten.irlaender@intevation.de> |
---|---|
date | Fri, 09 Aug 2013 15:00:06 +0200 |
parents | 62e116cd3e3b |
children | 6a7a9267e00f |
comparison
equal
deleted
inserted
replaced
290:fe51239321d9 | 291:e95662994c50 |
---|---|
1 /** | |
2 * Controller for Kommentare on Messungen | |
3 */ | |
1 Ext.define('Lada.controller.MKommentare', { | 4 Ext.define('Lada.controller.MKommentare', { |
2 extend: 'Ext.app.Controller', | 5 extend: 'Lada.controller.Base', |
3 views: [ | 6 views: [ |
4 'mkommentare.Create' | 7 'mkommentare.Create' |
5 ], | 8 ], |
6 stores: [ | 9 stores: [ |
7 'MKommentare' | 10 'MKommentare' |
9 models: [ | 12 models: [ |
10 'MKommentar' | 13 'MKommentar' |
11 ], | 14 ], |
12 init: function() { | 15 init: function() { |
13 console.log('Initialising the MKommentare controller'); | 16 console.log('Initialising the MKommentare controller'); |
17 this.callParent(); | |
18 }, | |
19 addListeners: function() { | |
14 this.control({ | 20 this.control({ |
15 // CSS like selector to select element in the viewport. See | |
16 // ComponentQuery documentation for more details. | |
17 'mkommentarelist': { | 21 'mkommentarelist': { |
18 itemdblclick: this.editKommentar | 22 itemdblclick: this.editItem |
19 }, | 23 }, |
20 'mkommentarelist toolbar button[action=add]': { | 24 'mkommentarelist toolbar button[action=add]': { |
21 click: this.addKommentar | 25 click: this.addItem |
22 }, | 26 }, |
23 'mkommentarelist toolbar button[action=delete]': { | 27 'mkommentarelist toolbar button[action=delete]': { |
24 click: this.deleteKommentar | 28 click: this.deleteItem |
25 }, | 29 }, |
26 'mkommentarecreate button[action=save]': { | 30 'mkommentarecreate button[action=save]': { |
27 click: this.saveKommentar | 31 click: this.saveItem |
28 }, | 32 }, |
29 'mkommentarecreate form': { | 33 'mkommentarecreate form': { |
30 savesuccess: this.createSuccess, | 34 savesuccess: this.createSuccess, |
31 savefailure: this.createFailure | 35 savefailure: this.createFailure |
32 } | 36 } |
33 }); | 37 }); |
34 }, | 38 }, |
35 saveKommentar: function(button) { | 39 addItem: function(button) { |
36 console.log('Saving MKommentar'); | |
37 var form = button.up('window').down('form'); | |
38 form.commit(); | |
39 }, | |
40 addKommentar: function(button) { | |
41 console.log('Adding new MKommentar for Messung ' + button.parentId + ' Probe ' + button.probeId); | 40 console.log('Adding new MKommentar for Messung ' + button.parentId + ' Probe ' + button.probeId); |
42 var kommentar = Ext.create('Lada.model.MKommentar'); | 41 var kommentar = Ext.create('Lada.model.MKommentar'); |
43 kommentar.set('probeId', button.probeId); | 42 kommentar.set('probeId', button.probeId); |
44 kommentar.set('messungsId', button.parentId); | 43 kommentar.set('messungsId', button.parentId); |
45 var view = Ext.widget('mkommentarecreate', {model: kommentar}); | 44 var view = Ext.widget('mkommentarecreate', {model: kommentar}); |
46 }, | 45 }, |
47 editKommentar: function(grid, record) { | 46 editItem: function(grid, record) { |
48 console.log('Editing Kommentar'); | 47 console.log('Editing Kommentar'); |
49 var view = Ext.widget('mkommentarecreate', {model: record}); | 48 var view = Ext.widget('mkommentarecreate', {model: record}); |
50 console.log("Loaded MKommentar with ID " + record.getId()); //outputs ID | 49 console.log("Loaded MKommentar with ID " + record.getId()); //outputs ID |
51 }, | |
52 deleteKommentar: function(button) { | |
53 // Get selected item in grid | |
54 var grid = button.up('grid'); | |
55 var selection = grid.getView().getSelectionModel().getSelection()[0]; | |
56 Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn){ | |
57 if(btn === 'yes'){ | |
58 var store = grid.getStore(); | |
59 var deleteUrl = selection.getProxy().url + selection.getEidi(); | |
60 Ext.Ajax.request({ | |
61 url: deleteUrl, | |
62 method: 'DELETE', | |
63 success: function(response, opts) { | |
64 store.reload(); | |
65 } | |
66 }); | |
67 console.log('Deleting MKommentar'); | |
68 } else { | |
69 console.log('Cancel Deleting MKommentar'); | |
70 } | |
71 }); | |
72 }, | 50 }, |
73 createSuccess: function(form, record, operation) { | 51 createSuccess: function(form, record, operation) { |
74 // Reload store | 52 // Reload store |
75 var store = this.getMKommentareStore(); | 53 var store = this.getMKommentareStore(); |
76 store.reload(); | 54 store.reload(); |
77 var win = form.up('window'); | 55 var win = form.up('window'); |
78 win.close(); | 56 win.close(); |
79 }, | |
80 createFailure: function(form, record, operation) { | |
81 Ext.MessageBox.show({ | |
82 title: 'Fehler beim Speichern', | |
83 msg: form.message, | |
84 icon: Ext.MessageBox.ERROR, | |
85 buttons: Ext.Msg.OK | |
86 }); | |
87 } | 57 } |
88 }); | 58 }); |