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, dustin@945: canceledit: this.cancelEdit, dustin@945: select: this.toggleAllowedPermissions raimund@594: }, raimund@594: 'statusgrid button[action=add]': { raimund@594: click: this.add 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@974: * it also tries to refresh the ProbeWindow and the messunggrid dustin@742: * On failure it displays a message dustin@742: */ dustin@742: gridSave: function(editor, context) { mstanko@944: context.record.set('sdatum', new Date()); raimund@594: context.record.save({ raimund@594: success: function() { raimund@594: context.grid.initData(); dustin@974: var win = context.grid.up('window'); dustin@974: win.initData(); dustin@974: try { dustin@974: win.parentWindow.initData(); dustin@974: win.parentWindow.down('messunggrid').store.reload(); dustin@974: } dustin@974: catch(e) { dustin@974: } 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: }); dustin@970: //Set the Date dustin@970: record.data.datum = new Date(); dustin@945: var lastrow = button.up('statusgrid').store.count() dustin@945: button.up('statusgrid').store.insert(lastrow, record); dustin@945: button.up('statusgrid').rowEditing.startEdit(lastrow, 1); raimund@594: }, raimund@594: dustin@945: dustin@945: /** dustin@945: * When a row in a grid is selected, dustin@945: * this function checks if the row may be edited, dustin@945: * or if the row can be removed dustin@945: */ dustin@945: toggleAllowedPermissions: function(context, record, index){ dustin@945: dustin@945: //retrieve the readOnly parameters raimund@969: var statusEdit = context.view.up('window').record.get('statusEdit'); dustin@945: dustin@945: var grid = context.view.up('grid'); dustin@945: dustin@945: //retrieve the last record of the store raimund@969: var lastRecord = context.getStore().last(); dustin@945: dustin@945: //Check if edit is allowed raimund@969: if (lastRecord != record || raimund@969: statusEdit === false) { raimund@969: grid.getPlugin('rowedit').cancelEdit(); dustin@945: } raimund@594: } dustin@945: raimund@594: });