Mercurial > lada > lada-client
annotate app/controller/Kommentare.js @ 285:6c030e5739a7
Added Docstrings
author | Torsten Irländer <torsten.irlaender@intevation.de> |
---|---|
date | Fri, 09 Aug 2013 12:56:32 +0200 |
parents | 4a79323336c6 |
children | c509e9f6d4db |
rev | line source |
---|---|
285
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
1 /** |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
2 * Controller for Kommentare |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
3 * |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
4 * The controller defines the main logic of the application. It provides |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
5 * various methods which are bound to listeners and called when the defined |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
6 * events in the various UI elements occour (e.g User clicks on a button) |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
7 */ |
54
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
8 Ext.define('Lada.controller.Kommentare', { |
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
9 extend: 'Ext.app.Controller', |
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
10 views: [ |
107
84f32c62670f
Added form to create kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
61
diff
changeset
|
11 'kommentare.Create' |
54
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
12 ], |
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
13 stores: [ |
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
14 'Kommentare' |
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
15 ], |
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
16 models: [ |
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
17 'Kommentar' |
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
18 ], |
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
19 init: function() { |
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
20 console.log('Initialising the Kommentare controller'); |
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
21 this.control({ |
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
22 // CSS like selector to select element in the viewport. See |
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
23 // ComponentQuery documentation for more details. |
55
4fa3fba50f79
Added dialog for editing kommentare. Open the dialog on double click on a
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
54
diff
changeset
|
24 'kommentarelist': { |
4fa3fba50f79
Added dialog for editing kommentare. Open the dialog on double click on a
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
54
diff
changeset
|
25 itemdblclick: this.editKommentar |
59
9e23eca8dfc7
Added function to delete kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
55
diff
changeset
|
26 }, |
60
5db7ab34af6d
Implemented Adding und Editing Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
59
diff
changeset
|
27 'kommentarelist toolbar button[action=add]': { |
5db7ab34af6d
Implemented Adding und Editing Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
59
diff
changeset
|
28 click: this.addKommentar |
5db7ab34af6d
Implemented Adding und Editing Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
59
diff
changeset
|
29 }, |
59
9e23eca8dfc7
Added function to delete kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
55
diff
changeset
|
30 'kommentarelist toolbar button[action=delete]': { |
9e23eca8dfc7
Added function to delete kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
55
diff
changeset
|
31 click: this.deleteKommentar |
60
5db7ab34af6d
Implemented Adding und Editing Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
59
diff
changeset
|
32 }, |
144
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
33 'kommentarecreate button[action=save]': { |
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
34 click: this.saveKommentar |
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
35 }, |
111
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
36 'kommentarecreate form': { |
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
37 savesuccess: this.createSuccess, |
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
38 savefailure: this.createFailure |
55
4fa3fba50f79
Added dialog for editing kommentare. Open the dialog on double click on a
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
54
diff
changeset
|
39 } |
54
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
40 }); |
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
41 }, |
285
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
42 /** |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
43 * Method to save the kommentar in the database. The method is called when |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
44 * the user clicks on the "Save" button |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
45 */ |
144
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
46 saveKommentar: function(button) { |
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
47 console.log('Saving Kommentar'); |
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
48 var form = button.up('window').down('form'); |
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
49 form.commit(); |
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
50 }, |
285
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
51 /** |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
52 * Method to open a window to enter the values for a new kommentar. |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
53 * The method is called when the user clicks on the "Add" button in the |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
54 * grid toolbar. |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
55 */ |
60
5db7ab34af6d
Implemented Adding und Editing Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
59
diff
changeset
|
56 addKommentar: function(button) { |
144
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
57 console.log('Adding new Kommentar for Probe ' + button.probeId); |
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
58 var kommentar = Ext.create('Lada.model.Kommentar'); |
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
59 kommentar.set('probeId', button.probeId); |
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
60 var view = Ext.widget('kommentarecreate', {model: kommentar}); |
111
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
61 }, |
285
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
62 /** |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
63 * Method to open a window to edit the values for an existing kommentar. |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
64 * The method is called when the user doubleclicks on the item in the |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
65 * grid. |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
66 */ |
111
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
67 editKommentar: function(grid, record) { |
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
68 console.log('Editing Kommentar'); |
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
69 var view = Ext.widget('kommentarecreate', {model: record}); |
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
70 console.log("Loaded Kommentar with ID " + record.getId()); //outputs ID |
60
5db7ab34af6d
Implemented Adding und Editing Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
59
diff
changeset
|
71 }, |
285
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
72 /** |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
73 * Method to delete a kommentar. This will trigger the display of a |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
74 * Confirmation dialog. After the deletion the related store will be |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
75 * refreshed. |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
76 * The method is called when the user selects the item in the grid and |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
77 * selects the delete button in the grid toolbar. |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
78 */ |
59
9e23eca8dfc7
Added function to delete kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
55
diff
changeset
|
79 deleteKommentar: function(button) { |
9e23eca8dfc7
Added function to delete kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
55
diff
changeset
|
80 // Get selected item in grid |
9e23eca8dfc7
Added function to delete kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
55
diff
changeset
|
81 var grid = button.up('grid'); |
9e23eca8dfc7
Added function to delete kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
55
diff
changeset
|
82 var selection = grid.getView().getSelectionModel().getSelection()[0]; |
9e23eca8dfc7
Added function to delete kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
55
diff
changeset
|
83 Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn){ |
9e23eca8dfc7
Added function to delete kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
55
diff
changeset
|
84 if(btn === 'yes'){ |
9e23eca8dfc7
Added function to delete kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
55
diff
changeset
|
85 var store = grid.getStore(); |
144
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
86 var deleteUrl = selection.getProxy().url + selection.getEidi(); |
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
87 Ext.Ajax.request({ |
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
88 url: deleteUrl, |
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
89 method: 'DELETE', |
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
90 success: function(response, opts) { |
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
91 store.reload(); |
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
92 } |
7b1140bd8b3d
Re-Added Kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
111
diff
changeset
|
93 }); |
59
9e23eca8dfc7
Added function to delete kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
55
diff
changeset
|
94 console.log('Deleting Kommentar'); |
9e23eca8dfc7
Added function to delete kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
55
diff
changeset
|
95 } else { |
9e23eca8dfc7
Added function to delete kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
55
diff
changeset
|
96 console.log('Cancel Deleting Kommentar'); |
9e23eca8dfc7
Added function to delete kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
55
diff
changeset
|
97 } |
9e23eca8dfc7
Added function to delete kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
55
diff
changeset
|
98 }); |
9e23eca8dfc7
Added function to delete kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
55
diff
changeset
|
99 }, |
285
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
100 /** |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
101 * Method to trigger the action after successfull save (create or edit). |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
102 * In this case the related store is refreshed and the window is closed. |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
103 */ |
111
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
104 createSuccess: function(form, record, operation) { |
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
105 // Reload store |
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
106 var store = this.getKommentareStore(); |
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
107 store.reload(); |
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
108 var win = form.up('window'); |
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
109 win.close(); |
54
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
110 }, |
285
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
111 /** |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
112 * Method to trigger the action after save (create or edit) fails. |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
113 * In this case a Message Boss with a general error is shown. |
6c030e5739a7
Added Docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
204
diff
changeset
|
114 */ |
111
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
115 createFailure: function(form, record, operation) { |
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
116 Ext.MessageBox.show({ |
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
117 title: 'Fehler beim Speichern', |
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
118 msg: form.message, |
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
119 icon: Ext.MessageBox.ERROR, |
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
120 buttons: Ext.Msg.OK |
6273b73b4b27
Replaced Logic for Kommentare. Use copied code form Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
107
diff
changeset
|
121 }); |
54
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
122 } |
3c7bfff8bd64
Added Controller for kommentare
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
123 }); |