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