Mercurial > lada > lada-client
annotate app/controller/Base.js @ 491:850ccfe5f3c4
Code style.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 31 Oct 2014 23:23:32 +0100 |
parents | 446e99cfd425 |
children | 7c0653e8d9f7 |
rev | line source |
---|---|
472
debfcc7713e3
Added license header to each file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
360
diff
changeset
|
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz |
debfcc7713e3
Added license header to each file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
360
diff
changeset
|
2 * Software engineering by Intevation GmbH |
debfcc7713e3
Added license header to each file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
360
diff
changeset
|
3 * |
debfcc7713e3
Added license header to each file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
360
diff
changeset
|
4 * This file is Free Software under the GNU GPL (v>=3) |
debfcc7713e3
Added license header to each file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
360
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out |
debfcc7713e3
Added license header to each file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
360
diff
changeset
|
6 * the documentation coming with IMIS-Labordaten-Application for details. |
debfcc7713e3
Added license header to each file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
360
diff
changeset
|
7 */ |
debfcc7713e3
Added license header to each file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
360
diff
changeset
|
8 |
286
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
9 /** |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
10 * Base Controller |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
11 * |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
12 * The controller defines the main logic of the application. It provides |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
13 * various methods which are bound to listeners and called when the defined |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
14 * events in the various UI elements occour (e.g User clicks on a button) |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
15 */ |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
16 Ext.define('Lada.controller.Base', { |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
17 extend: 'Ext.app.Controller', |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
18 /** |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
19 * Define required views for this controller |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
20 */ |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
21 views: [], |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
22 /** |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
23 * Define required stores for this controller |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
24 */ |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
25 stores: [], |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
26 /** |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
27 * Define required models for this controller |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
28 */ |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
29 models: [], |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
30 init: function() { |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
31 this.addListeners(); |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
32 }, |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
33 /** |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
34 * Function to add listeners for various events in UI items. The UI Items are selected |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
35 * with a CSS like selector.See ComponentQuery documentation for more |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
36 * details. The function is called while initializing the controller. |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
37 * |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
38 * The function should be overwritten by a specfic implementation. |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
39 */ |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
40 addListeners: function() { |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
41 this.control({}); |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
42 }, |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
43 /** |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
44 * Method to save the kommentar in the database. The method is called when |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
45 * the user clicks on the "Save" button |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
46 */ |
287
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
47 saveItem: function(button) { |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
48 console.log('Saving ...'); |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
49 var form = button.up('window').down('form'); |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
50 form.commit(); |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
51 }, |
286
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
52 /** |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
53 * Method to open a window to enter the values for a new kommentar. |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
54 * The method is called when the user clicks on the "Add" button in the |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
55 * grid toolbar. |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
56 */ |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
57 addItem: function(button) {}, |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
58 /** |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
59 * Method to open a window to edit the values for an existing kommentar. |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
60 * The method is called when the user doubleclicks on the item in the |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
61 * grid. |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
62 */ |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
63 editItem: function(grid, record) {}, |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
64 /** |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
65 * Method to delete a kommentar. This will trigger the display of a |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
66 * Confirmation dialog. After the deletion the related store will be |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
67 * refreshed. |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
68 * The method is called when the user selects the item in the grid and |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
69 * selects the delete button in the grid toolbar. |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
70 */ |
287
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
71 deleteItem: function(button) { |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
72 var grid = button.up('grid'); |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
73 var selection = grid.getView().getSelectionModel().getSelection()[0]; |
491
850ccfe5f3c4
Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
490
diff
changeset
|
74 Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn) { |
850ccfe5f3c4
Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
490
diff
changeset
|
75 if (btn === 'yes') { |
287
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
76 var store = grid.getStore(); |
490
446e99cfd425
Updated views and controllers using the new model and stores.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
472
diff
changeset
|
77 var deleteUrl = selection.getProxy().url + selection.getId(); |
287
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
78 Ext.Ajax.request({ |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
79 url: deleteUrl, |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
80 method: 'DELETE', |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
81 success: function(response, opts) { |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
82 store.reload(); |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
83 } |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
84 }); |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
85 console.log('Deleting ' + selection); |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
86 } else { |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
87 console.log('Cancel Deleting ' + selection); |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
88 } |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
89 }); |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
90 }, |
286
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
91 /** |
287
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
92 * Method to trigger the action after successfull save (create). |
286
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
93 * In this case the related store is refreshed and the window is closed. |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
94 */ |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
95 createSuccess: function(form, record, operation) {}, |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
96 /** |
287
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
97 * Method to trigger the action after save (create) fails. |
286
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
98 * In this case a Message Boss with a general error is shown. |
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
99 */ |
287
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
100 createFailure: function(form, record, operation) { |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
101 Ext.MessageBox.show({ |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
102 title: 'Fehler beim Speichern', |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
103 msg: form.message, |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
104 icon: Ext.MessageBox.ERROR, |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
105 buttons: Ext.Msg.OK |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
106 }); |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
107 }, |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
108 /** |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
109 * Method to trigger the action after successfull save (edit). |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
110 * In this case the related store is refreshed and the window is closed. |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
111 */ |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
112 editSuccess: function(form, record, operation) {}, |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
113 /** |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
114 * Method to trigger the action after save ( edit) fails. |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
115 * In this case a Message Boss with a general error is shown. |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
116 */ |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
117 editFailure: function(form, record, operation) { |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
118 Ext.MessageBox.show({ |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
119 title: 'Fehler beim Speichern', |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
120 msg: form.message, |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
121 icon: Ext.MessageBox.ERROR, |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
122 buttons: Ext.Msg.OK |
12e7f0ef90b6
Move more methods into the BaseController.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
286
diff
changeset
|
123 }); |
360
302db31ac50a
Fixed syntax
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
287
diff
changeset
|
124 } |
286
c509e9f6d4db
Added BaseController and inherit Kommentar controller from it.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
125 }); |