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 torsten@472: * 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', torsten@197: views: [ torsten@197: 'messwerte.Create' torsten@197: ], torsten@197: stores: [ torsten@284: 'Proben', torsten@197: 'Messungen', torsten@197: 'Messwerte', torsten@197: 'Messeinheit', torsten@197: 'Messgroessen' torsten@197: ], torsten@197: init: function() { torsten@290: console.log('Initialising the Messwert controller'); torsten@290: this.callParent(); torsten@290: }, torsten@290: addListeners: function() { torsten@197: this.control({ torsten@197: 'messwertelist': { torsten@290: itemdblclick: this.editItem torsten@197: }, 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: }, torsten@290: saveItem: function(button) { torsten@197: console.log('Saving MesswerMesswert'); torsten@197: var form = button.up('window').down('form'); torsten@197: form.commit(); torsten@197: }, torsten@290: addItem: function(button) { torsten@213: console.log('Adding new Messwert for Messung ' + button.parentId + ' for Probe ' + button.probeId); torsten@197: var messung = Ext.create('Lada.model.Messwert'); torsten@197: messung.set('probeId', button.probeId); torsten@213: messung.set('messungsId', button.parentId); torsten@197: var view = Ext.widget('messwertecreate', {model: messung}); torsten@197: }, torsten@290: editItem: function(grid, record) { torsten@197: console.log('Editing Messwert'); torsten@453: record.getAuthInfo(this.initEditWindow); torsten@362: console.log("Loaded Messwert with ID " + record.getId()); //outputs ID torsten@362: }, torsten@362: initEditWindow: function(record, readonly, owner) { torsten@197: var view = Ext.widget('messwertecreate', {model: record}); torsten@362: var ignore = Array(); torsten@362: if (readonly) { torsten@284: var form = view.down('form'); torsten@362: form.setReadOnly(true, ignore); torsten@284: } torsten@197: }, torsten@290: deleteItem: function(button) { torsten@197: var grid = button.up('grid'); torsten@197: var selection = grid.getView().getSelectionModel().getSelection()[0]; torsten@197: Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn){ torsten@197: if(btn === 'yes'){ torsten@197: var store = grid.getStore(); torsten@219: var deleteUrl = selection.getProxy().url + selection.getEidi(); torsten@219: Ext.Ajax.request({ torsten@219: url: deleteUrl, torsten@219: method: 'DELETE', torsten@219: success: function(response, opts) { torsten@219: store.reload(); torsten@219: } torsten@219: }); torsten@219: console.log('Deleting Messwert'); torsten@197: } else { torsten@219: console.log('Cancel Deleting Messwert'); torsten@197: } torsten@197: }); torsten@197: }, torsten@197: createSuccess: function(form, record, operation) { 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: }, torsten@197: createFailure: function(form, record, operation) { 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: editSuccess: function(form, record, operation) { 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: }, torsten@197: editFailure: function(form, record, operation) { 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: });