Mercurial > lada > lada-client
view app/controller/grid/Status.js @ 990:c2a726887dd7
The last status can not be edited anymore. When a new status is added, the new record is preset with ALL previous variables, this includes the StatusStufe! The Date is corrected to the current date. Also the store is sorted by Datum now.
author | Dustin Demuth <dustin@intevation.de> |
---|---|
date | Wed, 16 Dec 2015 09:49:09 +0100 |
parents | ea477f62a667 |
children | 77ea9a5c5f1d |
line wrap: on
line source
/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz * Software engineering by Intevation GmbH * * This file is Free Software under the GNU GPL (v>=3) * and comes with ABSOLUTELY NO WARRANTY! Check out * the documentation coming with IMIS-Labordaten-Application for details. */ /** * This is a controller for a grid of Status */ Ext.define('Lada.controller.grid.Status', { extend: 'Ext.app.Controller', /** * Initialize the Controller with * 3 Listeners */ init: function() { this.control({ 'statusgrid': { edit: this.gridSave, canceledit: this.cancelEdit, }, 'statusgrid button[action=add]': { click: this.add } }); }, /** * This function is called when the grids roweditor saves * the record. * On success it refreshes the windows which contains the grid * it also tries to refresh the ProbeWindow and the messunggrid * On failure it displays a message */ gridSave: function(editor, context) { context.record.set('sdatum', new Date()); context.record.save({ success: function() { context.grid.initData(); var win = context.grid.up('window'); win.initData(); try { win.parentWindow.initData(); win.parentWindow.down('messunggrid').store.reload(); } catch(e) { } }, failure: function(request, response) { var json = response.request.scope.reader.jsonData; if (json) { if (json.message){ Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title') +' #'+json.message, Lada.getApplication().bundle.getMsg(json.message)); } else { Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), Lada.getApplication().bundle.getMsg('err.msg.generic.body')); } } else { Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), Lada.getApplication().bundle.getMsg('err.msg.response.body')); } } }); }, /** * When the edit was canceled, * the empty row might have been created by the roweditor is removed */ cancelEdit: function(editor, context) { if (!context.record.get('id') || context.record.get('id') === '') { editor.getCmp().store.remove(context.record); } }, /** * This function adds a new row to add a Status * and copies the data of the previous status into the new one * if possible. */ add: function(button) { var lastrow = button.up('statusgrid').store.count() //If possible copy the previous record into the new one. //this assumes the store is ordered correctly, most recent status last. if (lastrow > 0) { //clone the old one var recentStatus = button.up('statusgrid').store.getAt(lastrow-1); var record = recentStatus.copy() record.set('id', null); } else { //create a new one var record = Ext.create('Lada.model.Status', { messungsId: button.up('statusgrid').recordId }); } //Set the Date record.set('datum', new Date()); button.up('statusgrid').store.insert(lastrow, record); button.up('statusgrid').getPlugin('rowedit').startEdit(lastrow, 1); } });