annotate app/controller/Orte.js @ 216:6aedf2026fb4

Fixed issue23
author Torsten Irländer <torsten.irlaender@intevation.de>
date Mon, 15 Jul 2013 15:30:52 +0200
parents 19d79b41f95d
children 4db982514a5f
rev   line source
109
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
1 Ext.define('Lada.controller.Orte', {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
2 extend: 'Ext.app.Controller',
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
3 views: [
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
4 'orte.List',
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
5 'orte.Create'
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
6 ],
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
7 stores: [
149
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
8 'Orte',
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
9 'Ortedetails',
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
10 'Staaten',
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
11 'Verwaltungseinheiten'
109
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
12 ],
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
13 models: [
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
14 'Ort'
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 init: function() {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
17 console.log('Initialising the Orte controller');
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
18 this.control({
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
19 // CSS like selector to select element in the viewport. See
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
20 // ComponentQuery documentation for more details.
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
21 'ortelist': {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
22 itemdblclick: this.editOrt
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
23 },
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
24 'ortelist toolbar button[action=add]': {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
25 click: this.addOrt
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
26 },
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
27 'ortelist toolbar button[action=delete]': {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
28 click: this.deleteOrt
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
29 },
149
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
30 'ortecreate button[action=save]': {
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
31 click: this.saveOrt
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
32 },
109
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
33 'ortecreate form': {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
34 savesuccess: this.createSuccess,
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
35 savefailure: this.createFailure
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
36 },
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
37 'orteedit form': {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
38 savesuccess: this.editSuccess,
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
39 savefailure: this.editFailure
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 });
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
42 },
149
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
43 saveOrt: function(button) {
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
44 console.log('Saving Ort');
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
45 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
46 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
47
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
48 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
49 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
50 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
51
216
6aedf2026fb4 Fixed issue23
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 215
diff changeset
52 var ortidfield = fform.findField('ortId');
6aedf2026fb4 Fixed issue23
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 215
diff changeset
53 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
54 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
55 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
56 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
57 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
58 newortdetail = true;
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
59 } else {
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
60 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
61 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
62 }
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
63
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
64 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
65 '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
66 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
67 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
68 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
69 }
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
70 // 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
71 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
72 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
73 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
74 // 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
75 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
76 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
77 }
216
6aedf2026fb4 Fixed issue23
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 215
diff changeset
78 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
79 form.commit();
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
80 },
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
81 failure: function() {
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
82 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
83 }
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
149
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
86 },
109
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
87 addOrt: function(button) {
149
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
88 console.log('Adding new Ort for Probe ' + button.probeId);
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
89 var ort = Ext.create('Lada.model.Ort');
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
90 ort.set('probeId', button.probeId);
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
91 var view = Ext.widget('ortecreate', {model: ort});
109
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
92 },
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
93 editOrt: function(grid, record) {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
94 console.log('Editing Ort');
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
95 var view = Ext.widget('ortecreate', {model: record});
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
96 console.log("Loaded Ort with ID " + record.getId()); //outputs ID
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
97 },
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
98 deleteOrt: function(button) {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
99 // Get selected item in grid
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
100 var grid = button.up('grid');
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
101 var selection = grid.getView().getSelectionModel().getSelection()[0];
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
102 Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn){
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
103 if(btn === 'yes'){
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
104 var store = grid.getStore();
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
105 store.remove(selection);
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
106 store.sync();
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
107 console.log('Deleting Kommentar');
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
108 } else {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
109 console.log('Cancel Deleting Kommentar');
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
110 }
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
111 });
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
112 },
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
113 createSuccess: function(form, record, operation) {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
114 // Reload store
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
115 var store = this.getOrteStore();
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
116 store.reload();
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
117 var win = form.up('window');
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
118 win.close();
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
119 },
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
120 createFailure: function(form, record, operation) {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
121 Ext.MessageBox.show({
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
122 title: 'Fehler beim Speichern',
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
123 msg: form.message,
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
124 icon: Ext.MessageBox.ERROR,
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
125 buttons: Ext.Msg.OK
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
126 });
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
127 },
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
128 editSuccess: function(form, record, operation) {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
129 // Reload store
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
130 var store = this.getOrteStore();
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
131 store.reload();
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
132 var win = form.up('window');
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
133 win.close();
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
134 },
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
135 editFailure: function(form, record, operation) {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
136 Ext.MessageBox.show({
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
137 title: 'Fehler beim Speichern',
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
138 msg: form.message,
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
139 icon: Ext.MessageBox.ERROR,
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
140 buttons: Ext.Msg.OK
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
141 });
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
142 }
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
143 });

http://lada.wald.intevation.org