torsten@292: /** torsten@292: * Controller for Orte torsten@292: */ torsten@109: Ext.define('Lada.controller.Orte', { torsten@292: extend: 'Lada.controller.Base', torsten@109: views: [ torsten@109: 'orte.List', torsten@109: 'orte.Create' torsten@109: ], torsten@109: stores: [ torsten@149: 'Orte', torsten@149: 'Ortedetails', torsten@149: 'Staaten', torsten@149: 'Verwaltungseinheiten' torsten@109: ], torsten@109: models: [ torsten@109: 'Ort' torsten@109: ], torsten@109: init: function() { torsten@109: console.log('Initialising the Orte controller'); torsten@292: this.callParent(); torsten@292: }, torsten@292: addListeners: function() { torsten@109: this.control({ torsten@109: 'ortelist': { torsten@292: itemdblclick: this.editItem torsten@109: }, torsten@109: 'ortelist toolbar button[action=add]': { torsten@292: click: this.addItem torsten@109: }, torsten@109: 'ortelist toolbar button[action=delete]': { torsten@292: click: this.deleteItem torsten@109: }, torsten@149: 'ortecreate button[action=save]': { torsten@292: click: this.saveItem torsten@149: }, torsten@109: 'ortecreate form': { torsten@109: savesuccess: this.createSuccess, torsten@109: savefailure: this.createFailure torsten@109: }, torsten@109: 'orteedit form': { torsten@109: savesuccess: this.editSuccess, torsten@109: savefailure: this.editFailure torsten@109: } torsten@109: }); torsten@109: }, torsten@292: saveItem: function(button) { torsten@149: console.log('Saving Ort'); torsten@149: var form = button.up('window').down('form'); torsten@154: var fform = form.getForm(); torsten@154: torsten@154: var ortdetail = null; torsten@154: var ortdetailstore = Ext.getStore('Ortedetails'); torsten@155: var newortdetail = false; torsten@154: torsten@216: var ortidfield = fform.findField('ortId'); torsten@216: var ortid = ortidfield.getValue(); torsten@154: if (ortid === null) { torsten@154: console.log('New Ortdetail'); torsten@154: ortdetail = Ext.create('Lada.model.Ortdetail'); torsten@154: ortdetailstore.add(ortdetail); torsten@154: newortdetail = true; torsten@154: } else { torsten@154: console.log('Editing Ortdetail'); torsten@154: ortdetail = ortdetailstore.getById(ortid); torsten@154: } torsten@154: torsten@154: var fields = ['beschreibung', 'bezeichnung', 'hoeheLand', torsten@154: 'latitude', 'longitude', 'staatId', 'gemId']; torsten@154: for (var i = fields.length - 1; i >= 0; i--){ torsten@154: ffield = fform.findField("ort_"+fields[i]); torsten@154: ortdetail.set(fields[i], ffield.getValue()); torsten@154: } torsten@154: // Create a new Ortedetail if nessecary torsten@154: ortdetailstore.sync({ torsten@155: success: function(batch, options) { torsten@154: if (newortdetail) { torsten@155: // Get ID from new created ortdetail and set it to the ort torsten@215: var response = options.operations.create[0].store.proxy.reader.jsonData; torsten@155: form.model.set('ortId', response.ortId); torsten@154: } torsten@216: ortidfield.setValue(ortid); torsten@154: form.commit(); torsten@154: }, torsten@154: failure: function() { torsten@154: console.log('Error on saving Ortdetails'); torsten@154: } torsten@154: }); torsten@154: torsten@149: }, torsten@292: addItem: function(button) { torsten@149: console.log('Adding new Ort for Probe ' + button.probeId); torsten@149: var ort = Ext.create('Lada.model.Ort'); torsten@149: ort.set('probeId', button.probeId); torsten@149: var view = Ext.widget('ortecreate', {model: ort}); torsten@109: }, torsten@292: editItem: function(grid, record) { torsten@109: console.log('Editing Ort'); torsten@109: var view = Ext.widget('ortecreate', {model: record}); torsten@109: console.log("Loaded Ort with ID " + record.getId()); //outputs ID torsten@109: }, torsten@109: createSuccess: function(form, record, operation) { torsten@109: // Reload store torsten@109: var store = this.getOrteStore(); torsten@109: store.reload(); torsten@109: var win = form.up('window'); torsten@109: win.close(); torsten@109: }, torsten@109: editSuccess: function(form, record, operation) { torsten@109: // Reload store torsten@109: var store = this.getOrteStore(); torsten@109: store.reload(); torsten@109: var win = form.up('window'); torsten@109: win.close(); torsten@109: } torsten@109: });