Mercurial > lada > lada-client
view app/controller/form/Messung.js @ 712:baef70abfe71
Cosmetics.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 08 Apr 2015 10:52:15 +0200 |
parents | f204f30b824a |
children | 2e478b3a587a |
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. */ Ext.define('Lada.controller.form.Messung', { extend: 'Ext.app.Controller', init: function() { this.control({ 'messungform button[action=save]': { click: this.save }, 'messungform button[action=discard]': { click: this.discard }, 'messungform': { dirtychange: this.dirtyForm } }); }, save: function(button) { var formPanel = button.up('form'); var data = formPanel.getForm().getFieldValues(true); for (var key in data) { formPanel.getForm().getRecord().set(key, data[key]); } formPanel.getForm().getRecord().save({ success: function(record, response) { var json = Ext.decode(response.response.responseText); if (json) { button.setDisabled(true); button.up('toolbar').down('button[action=discard]') .setDisabled(true); formPanel.clearMessages(); formPanel.setRecord(record); formPanel.setMessages(json.errors, json.warnings); formPanel.up('window').initData(); formPanel.up('window').grid.store.reload(); var parentWin = button.up('window').grid.up('window'); parentWin.initData(); if (response.action === 'create' && json.success) { var oldWin = button.up('window'); var probe = oldWin.record; oldWin.close(); var win = Ext.create('Lada.view.window.MessungEdit', { probe: probe, parentWindow: parentWin, grid: oldWin.grid, record: record }); win.show(); win.initData(); } } }, failure: function(record, response) { button.setDisabled(true); button.up('toolbar').down('button[action=discard]') .setDisabled(true); formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); var json = response.request.scope.reader.jsonData; if (json) { if (json.errors.totalCount > 0 || json.warnings.totalCount > 0) { formPanel.setMessages(json.errors, json.warnings); } 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')); } } }); }, discard: function(button) { var formPanel = button.up('form'); formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); }, dirtyForm: function(form, dirty) { if (dirty) { form.owner.down('button[action=save]').setDisabled(false); form.owner.down('button[action=discard]').setDisabled(false); form.owner.up('window').disableChildren(); } else { form.owner.down('button[action=save]').setDisabled(true); form.owner.down('button[action=discard]').setDisabled(true); form.owner.up('window').enableChildren(); } } });