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@289: /** torsten@289: * Controller for Messungen torsten@289: */ torsten@108: Ext.define('Lada.controller.Messungen', { torsten@289: extend: 'Lada.controller.Base', raimund@491: torsten@172: views: [ torsten@232: 'messungen.Create', torsten@232: 'messungen.Edit' torsten@172: ], raimund@491: torsten@108: stores: [ torsten@229: 'Proben', torsten@163: 'Messungen', torsten@168: 'Messwerte', raimund@490: 'KommentareM', raimund@496: 'Status' torsten@108: ], raimund@491: torsten@108: init: function() { torsten@312: this.callParent(); torsten@289: }, raimund@491: torsten@289: addListeners: function() { torsten@108: this.control({ roland@511: 'messungenlist toolbar button[action=open]': { roland@511: click: this.editItem torsten@108: }, torsten@108: 'messungenlist toolbar button[action=add]': { torsten@289: click: this.addItem torsten@108: }, torsten@108: 'messungenlist toolbar button[action=delete]': { torsten@289: click: this.deleteItem torsten@193: }, torsten@193: 'messungencreate button[action=save]': { torsten@289: click: this.saveItem torsten@108: }, torsten@233: 'messungenedit button[action=save]': { torsten@289: click: this.saveItem torsten@233: }, torsten@108: 'messungencreate form': { torsten@108: savesuccess: this.createSuccess, torsten@108: savefailure: this.createFailure torsten@108: }, torsten@108: 'messungenedit form': { torsten@108: savesuccess: this.editSuccess, torsten@108: savefailure: this.editFailure torsten@108: } torsten@108: }); torsten@108: }, raimund@491: torsten@289: saveItem: function(button) { torsten@194: var form = button.up('window').down('form'); torsten@194: form.commit(); torsten@194: }, raimund@491: torsten@289: addItem: function(button) { torsten@172: var messung = Ext.create('Lada.model.Messung'); torsten@172: messung.set('probeId', button.probeId); raimund@497: Ext.widget('messungencreate', { raimund@497: model: messung raimund@497: }); torsten@108: }, raimund@491: roland@511: editItem: function(button) { roland@511: var grid = button.up('grid'); roland@511: var selection = grid.getView().getSelectionModel().getSelection()[0]; roland@511: var messungsId = selection.getId(); roland@511: var record = selection.store.getById(messungsId); roland@511: raimund@490: var kstore = this.getKommentareMStore(); torsten@195: kstore.load({ torsten@195: params: { torsten@224: probeId: record.get('probeId'), raimund@490: messungsId: record.get('id') torsten@195: } torsten@195: }); torsten@195: var sstore = this.getStatusStore(); torsten@195: sstore.load({ torsten@195: params: { torsten@224: probeId: record.get('probeId'), raimund@490: messungsId: record.get('id') torsten@195: } torsten@195: }); torsten@224: var mstore = this.getMesswerteStore(); torsten@195: mstore.load({ torsten@195: params: { torsten@224: probeId: record.get('probeId'), raimund@490: messungsId: record.get('id') torsten@195: } torsten@195: }); torsten@362: record.getAuthInfo(this.initEditWindow); torsten@362: }, raimund@491: torsten@362: initEditWindow: function(record, readonly, owner) { raimund@491: var view = Ext.widget('messungenedit', { raimund@491: model: record raimund@491: }); raimund@497: var ignore = []; torsten@362: if (owner) { raimund@497: ignore.push('fertig'); torsten@362: } torsten@362: if (readonly) { torsten@232: var form = view.down('form'); torsten@281: form.setReadOnly(true, ignore); torsten@232: } torsten@108: }, raimund@491: torsten@289: deleteItem: function(button) { torsten@108: // Get selected item in grid torsten@108: var grid = button.up('grid'); torsten@108: var selection = grid.getView().getSelectionModel().getSelection()[0]; raimund@491: Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn) { raimund@491: if (btn === 'yes') { torsten@108: var store = grid.getStore(); raimund@490: var deleteUrl = selection.getProxy().url + selection.getId(); torsten@218: Ext.Ajax.request({ torsten@218: url: deleteUrl, torsten@218: method: 'DELETE', raimund@497: success: function() { torsten@218: store.reload(); torsten@218: } torsten@218: }); torsten@108: } torsten@108: }); torsten@108: }, raimund@491: raimund@497: createSuccess: function(form) { torsten@108: var store = this.getMessungenStore(); torsten@108: store.reload(); torsten@108: var win = form.up('window'); torsten@108: win.close(); torsten@108: }, raimund@491: raimund@497: createFailure: function(form) { torsten@108: Ext.MessageBox.show({ torsten@108: title: 'Fehler beim Speichern', torsten@108: msg: form.message, torsten@108: icon: Ext.MessageBox.ERROR, torsten@108: buttons: Ext.Msg.OK torsten@108: }); torsten@108: }, raimund@491: raimund@497: editSuccess: function(form) { torsten@108: var store = this.getMessungenStore(); torsten@108: store.reload(); torsten@108: var win = form.up('window'); torsten@108: win.close(); torsten@108: }, raimund@491: raimund@497: editFailure: function(form) { torsten@108: Ext.MessageBox.show({ torsten@108: title: 'Fehler beim Speichern', torsten@108: msg: form.message, torsten@108: icon: Ext.MessageBox.ERROR, torsten@108: buttons: Ext.Msg.OK torsten@108: }); torsten@108: } torsten@108: });