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@290: /** torsten@290: * Controller for Messwerte torsten@290: */ torsten@197: Ext.define('Lada.controller.Messwert', { torsten@290: extend: 'Lada.controller.Base', raimund@491: torsten@197: views: [ torsten@197: 'messwerte.Create' torsten@197: ], raimund@491: torsten@197: stores: [ torsten@284: 'Proben', torsten@197: 'Messungen', raimund@496: 'Messwerte' torsten@197: ], raimund@491: torsten@197: init: function() { raimund@491: this.callParent(arguments); torsten@290: }, raimund@491: torsten@290: addListeners: function() { torsten@197: this.control({ roland@540: 'messwertelist toolbar button[action=open]': { roland@540: click: this.editItem roland@540: }, torsten@197: 'messwertelist toolbar button[action=add]': { torsten@290: click: this.addItem torsten@197: }, torsten@197: 'messwertelist toolbar button[action=delete]': { torsten@290: click: this.deleteItem torsten@197: }, torsten@197: 'messwertecreate button[action=save]': { torsten@290: click: this.saveItem torsten@197: }, torsten@197: 'messwertecreate form': { torsten@197: savesuccess: this.createSuccess, torsten@197: savefailure: this.createFailure torsten@197: } torsten@197: }); torsten@197: }, raimund@491: torsten@290: saveItem: function(button) { torsten@197: var form = button.up('window').down('form'); torsten@197: form.commit(); torsten@197: }, raimund@491: torsten@290: addItem: function(button) { torsten@197: var messung = Ext.create('Lada.model.Messwert'); torsten@197: messung.set('probeId', button.probeId); torsten@213: messung.set('messungsId', button.parentId); raimund@497: Ext.widget('messwertecreate', { raimund@497: model: messung raimund@497: }); torsten@197: }, raimund@491: roland@540: editItem: function(button) { roland@540: var grid = button.up('grid'); roland@540: var selection = grid.getView().getSelectionModel().getSelection()[0]; roland@540: var messwertId = selection.getId(); roland@540: var record = selection.store.getById(messwertId); roland@540: raimund@490: var mstore = Ext.data.StoreManager.get('Messungen'); raimund@497: var messung = mstore.getById(record.get('messungsId')); raimund@490: record.getAuthInfo(this.initEditWindow, messung.get('probeId')); torsten@362: }, raimund@491: raimund@497: initEditWindow: function(record, readonly) { raimund@491: var view = Ext.widget('messwertecreate', { raimund@491: model: record raimund@491: }); raimund@497: var ignore = []; torsten@362: if (readonly) { torsten@284: var form = view.down('form'); torsten@362: form.setReadOnly(true, ignore); torsten@284: } torsten@197: }, raimund@491: torsten@290: deleteItem: function(button) { torsten@197: var grid = button.up('grid'); torsten@197: 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@197: var store = grid.getStore(); raimund@490: var deleteUrl = selection.getProxy().url + selection.getId(); torsten@219: Ext.Ajax.request({ torsten@219: url: deleteUrl, torsten@219: method: 'DELETE', raimund@497: success: function() { torsten@219: store.reload(); torsten@219: } torsten@219: }); torsten@197: } torsten@197: }); torsten@197: }, raimund@491: raimund@497: createSuccess: function(form) { torsten@197: // Reload store torsten@453: var store = this.getMesswerteStore(); torsten@197: store.reload(); torsten@197: var win = form.up('window'); torsten@197: win.close(); torsten@197: }, raimund@491: raimund@497: createFailure: function(form) { torsten@197: Ext.MessageBox.show({ torsten@197: title: 'Fehler beim Speichern', torsten@197: msg: form.message, torsten@197: icon: Ext.MessageBox.ERROR, torsten@197: buttons: Ext.Msg.OK torsten@197: }); torsten@197: }, raimund@491: raimund@497: editSuccess: function(form) { torsten@197: // Reload store torsten@453: var store = this.getMesswerteStore(); torsten@197: store.reload(); torsten@197: var win = form.up('window'); torsten@197: win.close(); torsten@197: }, raimund@491: raimund@497: editFailure: function(form) { torsten@197: Ext.MessageBox.show({ torsten@197: title: 'Fehler beim Speichern', torsten@197: msg: form.message, torsten@197: icon: Ext.MessageBox.ERROR, torsten@197: buttons: Ext.Msg.OK torsten@197: }); torsten@197: } torsten@197: });