raimund@587: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz raimund@587: * Software engineering by Intevation GmbH raimund@587: * raimund@587: * This file is Free Software under the GNU GPL (v>=3) raimund@587: * and comes with ABSOLUTELY NO WARRANTY! Check out raimund@587: * the documentation coming with IMIS-Labordaten-Application for details. raimund@587: */ raimund@587: raimund@587: Ext.define('Lada.controller.grid.PKommentar', { raimund@587: extend: 'Ext.app.Controller', raimund@587: raimund@587: init: function() { raimund@587: this.control({ raimund@587: 'pkommentargrid': { dustin@701: edit: this.gridSave, raimund@637: canceledit: this.cancelEdit raimund@587: }, raimund@587: 'pkommentargrid button[action=add]': { raimund@587: click: this.add raimund@587: }, raimund@587: 'pkommentargrid button[action=delete]': { raimund@587: click: this.remove raimund@587: } raimund@587: }); raimund@587: }, raimund@587: dustin@701: gridSave: function(editor, context) { raimund@587: context.record.save({ raimund@587: success: function() { raimund@587: context.grid.store.reload(); raimund@587: context.grid.up('window').initData(); raimund@587: }, 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@587: } raimund@587: }); raimund@587: }, raimund@587: raimund@637: 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: raimund@587: add: function(button) { raimund@587: var record = Ext.create('Lada.model.PKommentar'); raimund@587: record.set('probeId', button.up('pkommentargrid').recordId); raimund@587: button.up('pkommentargrid').store.insert(0, record); raimund@587: button.up('pkommentargrid').rowEditing.startEdit(0, 1); raimund@587: }, raimund@587: raimund@587: remove: function(button) { raimund@587: var grid = button.up('grid'); raimund@587: var selection = grid.getView().getSelectionModel().getSelection()[0]; raimund@587: Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn) { raimund@587: if (btn === 'yes') { raimund@587: selection.destroy({ raimund@587: success: function() { raimund@587: button.up('window').initData(); raimund@587: }, 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@587: } raimund@587: }); raimund@587: } raimund@587: }); raimund@587: } raimund@587: });