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