dustin@758: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz dustin@758: * Software engineering by Intevation GmbH dustin@758: * dustin@758: * This file is Free Software under the GNU GPL (v>=3) dustin@758: * and comes with ABSOLUTELY NO WARRANTY! Check out dustin@758: * the documentation coming with IMIS-Labordaten-Application for details. dustin@758: */ dustin@758: dustin@758: /** dustin@758: * This is a controller for a grid of Messmethode dustin@758: */ dustin@758: Ext.define('Lada.controller.grid.Messmethode', { dustin@758: extend: 'Ext.app.Controller', dustin@758: dustin@758: /** dustin@758: * Inhitialize the controller dustin@758: * It has 3 listeners dustin@758: */ dustin@758: init: function() { dustin@758: this.control({ dustin@758: 'messmethodengrid': { dustin@758: edit: this.gridSave, dustin@758: canceledit: this.cancelEdit dustin@758: }, dustin@758: 'messmethodengrid button[action=add]': { dustin@758: click: this.add dustin@758: }, dustin@758: 'messmethodengrid button[action=delete]': { dustin@758: click: this.remove dustin@758: } dustin@758: }); dustin@758: }, dustin@758: dustin@758: /** dustin@758: * This function is called when the grids roweditor saves dustin@758: * the record. dustin@758: * On success it refreshes the windows which contains the grid dustin@758: * On failure it displays a message dustin@758: */ dustin@758: gridSave: function(editor, context) { dustin@758: console.log(context); dustin@758: context.record.save({ dustin@758: success: function() { dustin@758: context.grid.initData(); dustin@758: context.grid.up('window').initData(); dustin@758: }, dustin@758: failure: function(request, response) { dustin@758: var json = response.request.scope.reader.jsonData; dustin@758: if (json) { dustin@758: if (json.message){ dustin@758: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title') dustin@758: +' #'+json.message, dustin@758: Lada.getApplication().bundle.getMsg(json.message)); dustin@758: } else { dustin@758: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), dustin@758: Lada.getApplication().bundle.getMsg('err.msg.generic.body')); dustin@758: } dustin@758: } else { dustin@758: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), dustin@758: Lada.getApplication().bundle.getMsg('err.msg.response.body')); dustin@758: } dustin@758: } dustin@758: }); dustin@758: }, dustin@758: dustin@758: /** dustin@758: * When the edit was canceled, dustin@758: * the empty row might have been created by the roweditor is removed dustin@758: */ dustin@758: cancelEdit: function(editor, context) { dustin@758: if (!context.record.get('id') || dustin@758: context.record.get('id') === '') { dustin@758: editor.getCmp().store.remove(context.record); dustin@758: } dustin@758: }, dustin@758: dustin@758: /** dustin@758: * This function adds a new row dustin@758: */ dustin@758: add: function(button) { dustin@758: var record = Ext.create('Lada.model.MmtMessprogramm'); dustin@758: record.set('messprogrammId', button.up('messmethodengrid').recordId); dustin@758: button.up('messmethodengrid').store.insert(0, record); dustin@758: button.up('messmethodengrid').rowEditing.startEdit(0, 0); dustin@758: }, dustin@758: dustin@758: /** dustin@758: * A row can be removed from the grid with the remove dustin@758: * function. It asks the user for confirmation dustin@758: * If the removal was confirmed, it reloads the parent window on success, dustin@758: * on failure, an error message is shown. dustin@758: */ dustin@758: remove: function(button) { dustin@758: var grid = button.up('grid'); dustin@758: //TODO i18n dustin@758: var selection = grid.getView().getSelectionModel().getSelection()[0]; dustin@758: Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn) { dustin@758: if (btn === 'yes') { dustin@758: selection.destroy({ dustin@758: success: function() { dustin@758: button.up('window').initData(); dustin@758: }, dustin@758: failure: function(request, response) { dustin@758: var json = response.request.scope.reader.jsonData; dustin@758: if (json) { dustin@758: if (json.message){ dustin@758: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title') dustin@758: +' #'+json.message, dustin@758: Lada.getApplication().bundle.getMsg(json.message)); dustin@758: } else { dustin@758: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'), dustin@758: Lada.getApplication().bundle.getMsg('err.msg.generic.body')); dustin@758: } dustin@758: } else { dustin@758: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'), dustin@758: Lada.getApplication().bundle.getMsg('err.msg.response.body')); dustin@758: } dustin@758: } dustin@758: }); dustin@758: } dustin@758: }); dustin@758: } dustin@758: });