torsten@472: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz torsten@472: * Software engineering by Intevation GmbH torsten@472: * torsten@472: * This file is Free Software under the GNU GPL (v>=3) torsten@472: * and comes with ABSOLUTELY NO WARRANTY! Check out raimund@497: * the documentation coming with IMIS-Labordaten-Application for details. torsten@472: */ torsten@472: torsten@292: /** torsten@292: * Controller for Orte torsten@292: */ torsten@109: Ext.define('Lada.controller.Orte', { torsten@292: extend: 'Lada.controller.Base', raimund@491: torsten@109: views: [ torsten@109: 'orte.List', raimund@447: 'orte.Create', raimund@447: 'orte.CreateOrt' torsten@109: ], raimund@491: torsten@109: stores: [ raimund@496: 'Orte' torsten@109: ], raimund@491: torsten@109: models: [ torsten@109: 'Ort' torsten@109: ], raimund@491: torsten@109: init: function() { raimund@491: this.callParent(arguments); torsten@292: }, raimund@491: torsten@292: addListeners: function() { torsten@109: this.control({ roland@510: //'ortelist': { roland@510: // itemdblclick: this.editItem roland@510: //}, 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: }, raimund@447: 'ortecreate form button[action=newort]': { raimund@447: click: this.createOrt raimund@447: }, raimund@447: 'createortdetail button[action=save]': { raimund@447: click: this.saveNewOrt raimund@447: }, 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: }, raimund@491: raimund@497: createOrt: function() { raimund@497: var win = Ext.create('Lada.view.orte.CreateOrt', {}); raimund@447: win.show(); raimund@447: }, raimund@491: raimund@447: saveNewOrt: function(button) { raimund@447: var form = button.up('window').down('form').getForm(); raimund@447: var ortdetailstore = Ext.getStore('Ortedetails'); raimund@447: var ortdetail = Ext.create('Lada.model.Ortdetail'); raimund@447: var fields = ['beschreibung', 'hoeheLand', raimund@447: 'latitude', 'longitude', 'staatId', 'gemId']; raimund@497: var i = 0; raimund@497: var ffield; raimund@497: for (i = fields.length - 1; i >= 0; i++) { raimund@497: ffield = form.findField('ort_' + fields[i]); raimund@447: ortdetail.set(fields[i], ffield.getValue()); raimund@447: } raimund@447: ortdetailstore.add(ortdetail); raimund@447: ortdetailstore.sync({ raimund@497: success: function(batch) { raimund@447: var od = Ext.ComponentQuery.query('ortdetail'); raimund@447: var response = batch.operations[0].resultSet.records[0].data; raimund@447: od[0].setValue(response.ortId); raimund@447: button.up('window').close(); raimund@447: }, raimund@447: failure: function() { raimund@447: ortdetailstore.remove(ortdetail); raimund@447: } raimund@447: }); raimund@447: }, raimund@491: torsten@292: saveItem: function(button) { 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: ortdetail = Ext.create('Lada.model.Ortdetail'); torsten@154: ortdetailstore.add(ortdetail); torsten@154: newortdetail = true; raimund@497: } raimund@497: else { torsten@154: ortdetail = ortdetailstore.getById(ortid); torsten@154: } torsten@154: torsten@154: var fields = ['beschreibung', 'bezeichnung', 'hoeheLand', torsten@154: 'latitude', 'longitude', 'staatId', 'gemId']; raimund@497: var i = 0; raimund@497: var ffield; raimund@497: for (i = fields.length - 1; i >= 0; i--) { raimund@497: 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 raimund@491: var response = raimund@497: options.operations.create[0] raimund@497: .store.proxy.reader.jsonData; torsten@155: form.model.set('ortId', response.ortId); torsten@154: } torsten@216: ortidfield.setValue(ortid); torsten@154: }, torsten@154: failure: function() { torsten@154: } torsten@154: }); torsten@454: form.commit(); raimund@491: }, torsten@154: torsten@292: addItem: function(button) { torsten@149: var ort = Ext.create('Lada.model.Ort'); torsten@149: ort.set('probeId', button.probeId); raimund@497: Ext.widget('ortecreate', { raimund@491: model: ort raimund@491: }); torsten@109: }, raimund@491: torsten@292: editItem: function(grid, record) { raimund@497: record.getAuthInfo(this.initEditWindow); torsten@362: }, raimund@491: raimund@497: initEditWindow: function(record, readonly) { raimund@491: var view = Ext.widget('ortecreate', { raimund@491: model: record, raimund@491: edit: true raimund@491: }); raimund@497: var ignore = []; torsten@362: if (readonly) { torsten@362: var form = view.down('form'); torsten@362: form.setReadOnly(true, ignore); torsten@362: } torsten@109: }, raimund@491: raimund@497: createSuccess: function(form) { 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: }, raimund@491: raimund@497: editSuccess: function(form) { 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: });