Mercurial > lada > lada-client
view app/controller/form/Messung.js @ 724:876456ce0a01
Added new depencies: filesaver[1] and upload[2].
[1] https://github.com/eligrey/FileSaver.js/
[2] https://github.com/ivan-novakov/extjs-upload-widget
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 16 Apr 2015 15:53:53 +0200 |
parents | c2a6f7caa71b |
children | 6e28ebbe1a73 |
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'); formPanel.setLoading(true); 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(); } } formPanel.setLoading(false); }, 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')); } formPanel.clearMessages(); formPanel.setRecord(record); formPanel.setMessages(json.errors, json.warnings); formPanel.up('window').initData(); formPanel.up('window').grid.store.reload(); } else { Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), Lada.getApplication().bundle.getMsg('err.msg.response.body')); } formPanel.setLoading(false); } }); }, 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); //Only enable children if the form was not readOnly if (!form.getRecord().get('readonly')) { form.owner.up('window').enableChildren(); } } } });