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