comparison app/controller/Orte.js @ 497:7c0653e8d9f7

Fixed some js related issues (unused vars, arrays, etc.) and code style.
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 06 Nov 2014 10:38:17 +0100
parents d07e5086a64b
children 8b4ec61c5752
comparison
equal deleted inserted replaced
496:d07e5086a64b 497:7c0653e8d9f7
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz 1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
2 * Software engineering by Intevation GmbH 2 * Software engineering by Intevation GmbH
3 * 3 *
4 * This file is Free Software under the GNU GPL (v>=3) 4 * This file is Free Software under the GNU GPL (v>=3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out 5 * and comes with ABSOLUTELY NO WARRANTY! Check out
6 * the documentation coming with IMIS-Labordaten-Application for details. 6 * the documentation coming with IMIS-Labordaten-Application for details.
7 */ 7 */
8 8
9 /** 9 /**
10 * Controller for Orte 10 * Controller for Orte
11 */ 11 */
60 savefailure: this.editFailure 60 savefailure: this.editFailure
61 } 61 }
62 }); 62 });
63 }, 63 },
64 64
65 createOrt: function(button) { 65 createOrt: function() {
66 console.log('button clicked'); 66 console.log('button clicked');
67 var win = Ext.create('Lada.view.orte.CreateOrt',{}); 67 var win = Ext.create('Lada.view.orte.CreateOrt', {});
68 win.show(); 68 win.show();
69 }, 69 },
70 70
71 saveNewOrt: function(button) { 71 saveNewOrt: function(button) {
72 console.log('button clicked'); 72 console.log('button clicked');
74 var form = button.up('window').down('form').getForm(); 74 var form = button.up('window').down('form').getForm();
75 var ortdetailstore = Ext.getStore('Ortedetails'); 75 var ortdetailstore = Ext.getStore('Ortedetails');
76 var ortdetail = Ext.create('Lada.model.Ortdetail'); 76 var ortdetail = Ext.create('Lada.model.Ortdetail');
77 var fields = ['beschreibung', 'hoeheLand', 77 var fields = ['beschreibung', 'hoeheLand',
78 'latitude', 'longitude', 'staatId', 'gemId']; 78 'latitude', 'longitude', 'staatId', 'gemId'];
79 for (var i = fields.length - 1; i >= 0; i--) { 79 var i = 0;
80 var ffield = form.findField("ort_"+fields[i]); 80 var ffield;
81 for (i = fields.length - 1; i >= 0; i++) {
82 ffield = form.findField('ort_' + fields[i]);
81 ortdetail.set(fields[i], ffield.getValue()); 83 ortdetail.set(fields[i], ffield.getValue());
82 } 84 }
83 ortdetailstore.add(ortdetail); 85 ortdetailstore.add(ortdetail);
84 ortdetailstore.sync({ 86 ortdetailstore.sync({
85 success: function(batch, options) { 87 success: function(batch) {
86 console.log(batch); 88 console.log(batch);
87 var od = Ext.ComponentQuery.query('ortdetail'); 89 var od = Ext.ComponentQuery.query('ortdetail');
88 console.log(od); 90 console.log(od);
89 batch.operations[0].resultSet.records[0].data;
90 var response = batch.operations[0].resultSet.records[0].data; 91 var response = batch.operations[0].resultSet.records[0].data;
91 od[0].setValue(response.ortId); 92 od[0].setValue(response.ortId);
92 console.log('id:' + response.ortId); 93 console.log('id:' + response.ortId);
93 button.up('window').close(); 94 button.up('window').close();
94 }, 95 },
113 if (ortid === null) { 114 if (ortid === null) {
114 console.log('New Ortdetail'); 115 console.log('New Ortdetail');
115 ortdetail = Ext.create('Lada.model.Ortdetail'); 116 ortdetail = Ext.create('Lada.model.Ortdetail');
116 ortdetailstore.add(ortdetail); 117 ortdetailstore.add(ortdetail);
117 newortdetail = true; 118 newortdetail = true;
118 } else { 119 }
120 else {
119 console.log('Editing Ortdetail'); 121 console.log('Editing Ortdetail');
120 ortdetail = ortdetailstore.getById(ortid); 122 ortdetail = ortdetailstore.getById(ortid);
121 } 123 }
122 124
123 var fields = ['beschreibung', 'bezeichnung', 'hoeheLand', 125 var fields = ['beschreibung', 'bezeichnung', 'hoeheLand',
124 'latitude', 'longitude', 'staatId', 'gemId']; 126 'latitude', 'longitude', 'staatId', 'gemId'];
125 for (var i = fields.length - 1; i >= 0; i--){ 127 var i = 0;
126 ffield = fform.findField("ort_"+fields[i]); 128 var ffield;
129 for (i = fields.length - 1; i >= 0; i--) {
130 ffield = fform.findField('ort_' + fields[i]);
127 ortdetail.set(fields[i], ffield.getValue()); 131 ortdetail.set(fields[i], ffield.getValue());
128 } 132 }
129 // Create a new Ortedetail if nessecary 133 // Create a new Ortedetail if nessecary
130 ortdetailstore.sync({ 134 ortdetailstore.sync({
131 success: function(batch, options) { 135 success: function(batch, options) {
132 if (newortdetail) { 136 if (newortdetail) {
133 // Get ID from new created ortdetail and set it to the ort 137 // Get ID from new created ortdetail and set it to the ort
134 var response = 138 var response =
135 options.operations.create[0].store.proxy.reader.jsonData; 139 options.operations.create[0]
140 .store.proxy.reader.jsonData;
136 form.model.set('ortId', response.ortId); 141 form.model.set('ortId', response.ortId);
137 } 142 }
138 ortidfield.setValue(ortid); 143 ortidfield.setValue(ortid);
139 }, 144 },
140 failure: function() { 145 failure: function() {
146 151
147 addItem: function(button) { 152 addItem: function(button) {
148 console.log('Adding new Ort for Probe ' + button.probeId); 153 console.log('Adding new Ort for Probe ' + button.probeId);
149 var ort = Ext.create('Lada.model.Ort'); 154 var ort = Ext.create('Lada.model.Ort');
150 ort.set('probeId', button.probeId); 155 ort.set('probeId', button.probeId);
151 var view = Ext.widget('ortecreate', { 156 Ext.widget('ortecreate', {
152 model: ort 157 model: ort
153 }); 158 });
154 }, 159 },
155 160
156 editItem: function(grid, record) { 161 editItem: function(grid, record) {
157 console.log('Editing Ort'); 162 console.log('Editing Ort');
158 record.getAuthInfo(this.initEditWindow) 163 record.getAuthInfo(this.initEditWindow);
159 console.log("Loaded Ort with ID " + record.getId()); //outputs ID 164 console.log('Loaded Ort with ID ' + record.getId());
160 }, 165 },
161 166
162 initEditWindow: function(record, readonly, owner) { 167 initEditWindow: function(record, readonly) {
163 var view = Ext.widget('ortecreate', { 168 var view = Ext.widget('ortecreate', {
164 model: record, 169 model: record,
165 edit: true 170 edit: true
166 }); 171 });
167 var ignore = Array(); 172 var ignore = [];
168 if (readonly) { 173 if (readonly) {
169 var form = view.down('form'); 174 var form = view.down('form');
170 form.setReadOnly(true, ignore); 175 form.setReadOnly(true, ignore);
171 } 176 }
172 }, 177 },
173 178
174 createSuccess: function(form, record, operation) { 179 createSuccess: function(form) {
175 // Reload store 180 // Reload store
176 var store = this.getOrteStore(); 181 var store = this.getOrteStore();
177 store.reload(); 182 store.reload();
178 var win = form.up('window'); 183 var win = form.up('window');
179 win.close(); 184 win.close();
180 }, 185 },
181 186
182 editSuccess: function(form, record, operation) { 187 editSuccess: function(form) {
183 // Reload store 188 // Reload store
184 var store = this.getOrteStore(); 189 var store = this.getOrteStore();
185 store.reload(); 190 store.reload();
186 var win = form.up('window'); 191 var win = form.up('window');
187 win.close(); 192 win.close();

http://lada.wald.intevation.org