Mercurial > lada > lada-client
annotate app/controller/Orte.js @ 420:eeeaea114249
Do not autoload the Verwaltungsgrenzen store.
author | Torsten Irländer <torsten.irlaender@intevation.de> |
---|---|
date | Fri, 11 Oct 2013 13:05:01 +0200 |
parents | 6a7a9267e00f |
children | 12231f31c112 |
rev | line source |
---|---|
292
73a2c114db64
Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
217
diff
changeset
|
1 /** |
73a2c114db64
Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
217
diff
changeset
|
2 * Controller for Orte |
73a2c114db64
Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
217
diff
changeset
|
3 */ |
109
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
4 Ext.define('Lada.controller.Orte', { |
292
73a2c114db64
Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
217
diff
changeset
|
5 extend: 'Lada.controller.Base', |
109
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
6 views: [ |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
7 'orte.List', |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
8 'orte.Create' |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
9 ], |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
10 stores: [ |
149
26ac4c99f8c4
Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
109
diff
changeset
|
11 'Orte', |
26ac4c99f8c4
Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
109
diff
changeset
|
12 'Ortedetails', |
26ac4c99f8c4
Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
109
diff
changeset
|
13 'Staaten', |
26ac4c99f8c4
Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
109
diff
changeset
|
14 'Verwaltungseinheiten' |
109
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
15 ], |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
16 models: [ |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
17 'Ort' |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
18 ], |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
19 init: function() { |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
20 console.log('Initialising the Orte controller'); |
292
73a2c114db64
Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
217
diff
changeset
|
21 this.callParent(); |
73a2c114db64
Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
217
diff
changeset
|
22 }, |
73a2c114db64
Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
217
diff
changeset
|
23 addListeners: function() { |
109
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
24 this.control({ |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
25 'ortelist': { |
292
73a2c114db64
Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
217
diff
changeset
|
26 itemdblclick: this.editItem |
109
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
27 }, |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
28 'ortelist toolbar button[action=add]': { |
292
73a2c114db64
Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
217
diff
changeset
|
29 click: this.addItem |
109
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
30 }, |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
31 'ortelist toolbar button[action=delete]': { |
292
73a2c114db64
Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
217
diff
changeset
|
32 click: this.deleteItem |
109
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
33 }, |
149
26ac4c99f8c4
Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
109
diff
changeset
|
34 'ortecreate button[action=save]': { |
292
73a2c114db64
Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
217
diff
changeset
|
35 click: this.saveItem |
149
26ac4c99f8c4
Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
109
diff
changeset
|
36 }, |
109
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
37 'ortecreate form': { |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
38 savesuccess: this.createSuccess, |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
39 savefailure: this.createFailure |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
40 }, |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
41 'orteedit form': { |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
42 savesuccess: this.editSuccess, |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
43 savefailure: this.editFailure |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
44 } |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
45 }); |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
46 }, |
292
73a2c114db64
Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
217
diff
changeset
|
47 saveItem: function(button) { |
149
26ac4c99f8c4
Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
109
diff
changeset
|
48 console.log('Saving Ort'); |
26ac4c99f8c4
Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
109
diff
changeset
|
49 var form = button.up('window').down('form'); |
154
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
50 var fform = form.getForm(); |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
51 |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
52 var ortdetail = null; |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
53 var ortdetailstore = Ext.getStore('Ortedetails'); |
155
5414e611097e
Set ortId in l_ort if new ortdetail was created.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
154
diff
changeset
|
54 var newortdetail = false; |
154
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
55 |
216
6aedf2026fb4
Fixed issue23
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
215
diff
changeset
|
56 var ortidfield = fform.findField('ortId'); |
6aedf2026fb4
Fixed issue23
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
215
diff
changeset
|
57 var ortid = ortidfield.getValue(); |
154
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
58 if (ortid === null) { |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
59 console.log('New Ortdetail'); |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
60 ortdetail = Ext.create('Lada.model.Ortdetail'); |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
61 ortdetailstore.add(ortdetail); |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
62 newortdetail = true; |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
63 } else { |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
64 console.log('Editing Ortdetail'); |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
65 ortdetail = ortdetailstore.getById(ortid); |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
66 } |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
67 |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
68 var fields = ['beschreibung', 'bezeichnung', 'hoeheLand', |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
69 'latitude', 'longitude', 'staatId', 'gemId']; |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
70 for (var i = fields.length - 1; i >= 0; i--){ |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
71 ffield = fform.findField("ort_"+fields[i]); |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
72 ortdetail.set(fields[i], ffield.getValue()); |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
73 } |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
74 // Create a new Ortedetail if nessecary |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
75 ortdetailstore.sync({ |
155
5414e611097e
Set ortId in l_ort if new ortdetail was created.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
154
diff
changeset
|
76 success: function(batch, options) { |
154
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
77 if (newortdetail) { |
155
5414e611097e
Set ortId in l_ort if new ortdetail was created.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
154
diff
changeset
|
78 // Get ID from new created ortdetail and set it to the ort |
215
19d79b41f95d
Fixed issue22
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
155
diff
changeset
|
79 var response = options.operations.create[0].store.proxy.reader.jsonData; |
155
5414e611097e
Set ortId in l_ort if new ortdetail was created.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
154
diff
changeset
|
80 form.model.set('ortId', response.ortId); |
154
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
81 } |
216
6aedf2026fb4
Fixed issue23
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
215
diff
changeset
|
82 ortidfield.setValue(ortid); |
154
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
83 form.commit(); |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
84 }, |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
85 failure: function() { |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
86 console.log('Error on saving Ortdetails'); |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
87 } |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
88 }); |
16ba7e2465fd
Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
149
diff
changeset
|
89 |
149
26ac4c99f8c4
Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
109
diff
changeset
|
90 }, |
292
73a2c114db64
Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
217
diff
changeset
|
91 addItem: function(button) { |
149
26ac4c99f8c4
Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
109
diff
changeset
|
92 console.log('Adding new Ort for Probe ' + button.probeId); |
26ac4c99f8c4
Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
109
diff
changeset
|
93 var ort = Ext.create('Lada.model.Ort'); |
26ac4c99f8c4
Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
109
diff
changeset
|
94 ort.set('probeId', button.probeId); |
26ac4c99f8c4
Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
109
diff
changeset
|
95 var view = Ext.widget('ortecreate', {model: ort}); |
109
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
96 }, |
292
73a2c114db64
Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
217
diff
changeset
|
97 editItem: function(grid, record) { |
109
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
98 console.log('Editing Ort'); |
362
6a7a9267e00f
Issue56: Changed way how to set the form and window to readonly. Now all dialogs should
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
292
diff
changeset
|
99 record.getAuthInfo(this.initEditWindow) |
6a7a9267e00f
Issue56: Changed way how to set the form and window to readonly. Now all dialogs should
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
292
diff
changeset
|
100 console.log("Loaded Ort with ID " + record.getId()); //outputs ID |
6a7a9267e00f
Issue56: Changed way how to set the form and window to readonly. Now all dialogs should
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
292
diff
changeset
|
101 }, |
6a7a9267e00f
Issue56: Changed way how to set the form and window to readonly. Now all dialogs should
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
292
diff
changeset
|
102 initEditWindow: function(record, readonly, owner) { |
109
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
103 var view = Ext.widget('ortecreate', {model: record}); |
362
6a7a9267e00f
Issue56: Changed way how to set the form and window to readonly. Now all dialogs should
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
292
diff
changeset
|
104 var ignore = Array(); |
6a7a9267e00f
Issue56: Changed way how to set the form and window to readonly. Now all dialogs should
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
292
diff
changeset
|
105 if (readonly) { |
6a7a9267e00f
Issue56: Changed way how to set the form and window to readonly. Now all dialogs should
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
292
diff
changeset
|
106 var form = view.down('form'); |
6a7a9267e00f
Issue56: Changed way how to set the form and window to readonly. Now all dialogs should
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
292
diff
changeset
|
107 form.setReadOnly(true, ignore); |
6a7a9267e00f
Issue56: Changed way how to set the form and window to readonly. Now all dialogs should
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
292
diff
changeset
|
108 } |
109
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
109 }, |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
110 createSuccess: function(form, record, operation) { |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
111 // Reload store |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
112 var store = this.getOrteStore(); |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
113 store.reload(); |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
114 var win = form.up('window'); |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
115 win.close(); |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
116 }, |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
117 editSuccess: function(form, record, operation) { |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
118 // Reload store |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
119 var store = this.getOrteStore(); |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
120 store.reload(); |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
121 var win = form.up('window'); |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
122 win.close(); |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
123 } |
2308094f5a8c
Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
124 }); |