dustin@611: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz dustin@611: * Software engineering by Intevation GmbH dustin@611: * dustin@611: * This file is Free Software under the GNU GPL (v>=3) dustin@611: * and comes with ABSOLUTELY NO WARRANTY! Check out dustin@611: * the documentation coming with IMIS-Labordaten-Application for details. dustin@611: */ dustin@611: dustin@611: Ext.define('Lada.controller.form.Messung', { dustin@611: extend: 'Ext.app.Controller', dustin@611: dustin@611: init: function() { dustin@611: this.control({ dustin@611: 'messungform button[action=save]': { dustin@611: click: this.save dustin@611: }, dustin@611: 'messungform button[action=discard]': { dustin@611: click: this.discard dustin@611: }, dustin@611: 'messungform': { dustin@611: dirtychange: this.dirtyForm dustin@611: } dustin@611: }); dustin@611: }, dustin@611: dustin@611: save: function(button) { dustin@611: var formPanel = button.up('form'); dustin@611: var data = formPanel.getForm().getFieldValues(true); dustin@611: for (var key in data) { dustin@611: formPanel.getForm().getRecord().set(key, data[key]); dustin@611: } dustin@611: formPanel.getForm().getRecord().save({ dustin@611: success: function(record, response) { dustin@611: var json = Ext.decode(response.response.responseText); dustin@611: if (response.action !== 'create' && dustin@611: json && dustin@611: json.success) { dustin@611: button.setDisabled(true); dustin@611: button.up('toolbar').down('button[action=discard]') dustin@611: .setDisabled(true); dustin@611: formPanel.clearMessages(); dustin@611: formPanel.setRecord(record); dustin@611: formPanel.setMessages(json.errors, json.warnings); dustin@611: } dustin@611: }, dustin@611: failure: function(record, response) { dustin@611: button.setDisabled(true); dustin@611: button.up('toolbar').down('button[action=discard]') dustin@611: .setDisabled(true); dustin@611: formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); dustin@611: var json = response.request.scope.reader.jsonData; dustin@611: if (json) { dustin@611: formPanel.setMessages(json.errors, json.warnings); dustin@611: } dustin@611: } dustin@611: }); dustin@611: console.log('save'); dustin@611: }, dustin@611: dustin@611: discard: function(button) { dustin@611: var formPanel = button.up('form'); dustin@611: formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); dustin@611: }, dustin@611: dustin@611: dirtyForm: function(form, dirty) { dustin@611: if (dirty) { dustin@611: form.owner.down('button[action=save]').setDisabled(false); dustin@611: form.owner.down('button[action=discard]').setDisabled(false); dustin@611: } dustin@611: else { dustin@611: form.owner.down('button[action=save]').setDisabled(true); dustin@611: form.owner.down('button[action=discard]').setDisabled(true); dustin@611: } dustin@611: } dustin@611: });