annotate app/controller/Orte.js @ 187:ef7b8499c924

Added readonly attribute.
author Torsten Irländer <torsten.irlaender@intevation.de>
date Fri, 05 Jul 2013 14:46:43 +0200
parents 5414e611097e
children 19d79b41f95d
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
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
52 var ortid = fform.findField('ortId').getValue();
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
53 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
54 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
55 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
56 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
57 newortdetail = true;
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
58 } else {
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('Editing 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 = 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
61 }
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 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
64 '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
65 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
66 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
67 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
68 }
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
69 // 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
70 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
71 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
72 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
73 // Get ID from new created ortdetail and set it to the ort
5414e611097e Set ortId in l_ort if new ortdetail was created.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 154
diff changeset
74 var response = options.operations.update[0].store.proxy.reader.jsonData;
5414e611097e Set ortId in l_ort if new ortdetail was created.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 154
diff changeset
75 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
76 }
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
77 form.commit();
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
78 },
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
79 failure: function() {
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
80 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
81 }
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
82 });
16ba7e2465fd Implemented creating and editing new l_ort. Created editing orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 149
diff changeset
83
149
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
84 },
109
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
85 addOrt: function(button) {
149
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
86 console.log('Adding new Ort for Probe ' + button.probeId);
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
87 var ort = Ext.create('Lada.model.Ort');
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
88 ort.set('probeId', button.probeId);
26ac4c99f8c4 Added Orte.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 109
diff changeset
89 var view = Ext.widget('ortecreate', {model: ort});
109
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
90 },
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
91 editOrt: function(grid, record) {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
92 console.log('Editing Ort');
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
93 var view = Ext.widget('ortecreate', {model: record});
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
94 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
95 },
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
96 deleteOrt: function(button) {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
97 // Get selected item in grid
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
98 var grid = button.up('grid');
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
99 var selection = grid.getView().getSelectionModel().getSelection()[0];
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
100 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
101 if(btn === 'yes'){
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
102 var store = grid.getStore();
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
103 store.remove(selection);
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
104 store.sync();
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
105 console.log('Deleting Kommentar');
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
106 } else {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
107 console.log('Cancel Deleting Kommentar');
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
108 }
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 },
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
111 createSuccess: function(form, record, operation) {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
112 // Reload store
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
113 var store = this.getOrteStore();
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
114 store.reload();
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
115 var win = form.up('window');
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
116 win.close();
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
117 },
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
118 createFailure: function(form, record, operation) {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
119 Ext.MessageBox.show({
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
120 title: 'Fehler beim Speichern',
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
121 msg: form.message,
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
122 icon: Ext.MessageBox.ERROR,
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
123 buttons: Ext.Msg.OK
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
124 });
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
125 },
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
126 editSuccess: function(form, record, operation) {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
127 // Reload store
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
128 var store = this.getOrteStore();
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
129 store.reload();
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
130 var win = form.up('window');
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
131 win.close();
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
132 },
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
133 editFailure: function(form, record, operation) {
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
134 Ext.MessageBox.show({
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
135 title: 'Fehler beim Speichern',
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
136 msg: form.message,
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
137 icon: Ext.MessageBox.ERROR,
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
138 buttons: Ext.Msg.OK
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
139 });
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
140 }
2308094f5a8c Added forms to add Orte
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
141 });

http://lada.wald.intevation.org