comparison app/controller/form/Messung.js @ 611:8a156a7fbe67

added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
author Dustin Demuth <dustin@intevation.de>
date Fri, 13 Mar 2015 15:11:12 +0100
parents
children ee92e352be20
comparison
equal deleted inserted replaced
610:f240fe19ff5d 611:8a156a7fbe67
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU GPL (v>=3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out
6 * the documentation coming with IMIS-Labordaten-Application for details.
7 */
8
9 Ext.define('Lada.controller.form.Messung', {
10 extend: 'Ext.app.Controller',
11
12 init: function() {
13 this.control({
14 'messungform button[action=save]': {
15 click: this.save
16 },
17 'messungform button[action=discard]': {
18 click: this.discard
19 },
20 'messungform': {
21 dirtychange: this.dirtyForm
22 }
23 });
24 },
25
26 save: function(button) {
27 var formPanel = button.up('form');
28 var data = formPanel.getForm().getFieldValues(true);
29 for (var key in data) {
30 formPanel.getForm().getRecord().set(key, data[key]);
31 }
32 formPanel.getForm().getRecord().save({
33 success: function(record, response) {
34 var json = Ext.decode(response.response.responseText);
35 if (response.action !== 'create' &&
36 json &&
37 json.success) {
38 button.setDisabled(true);
39 button.up('toolbar').down('button[action=discard]')
40 .setDisabled(true);
41 formPanel.clearMessages();
42 formPanel.setRecord(record);
43 formPanel.setMessages(json.errors, json.warnings);
44 }
45 },
46 failure: function(record, response) {
47 button.setDisabled(true);
48 button.up('toolbar').down('button[action=discard]')
49 .setDisabled(true);
50 formPanel.getForm().loadRecord(formPanel.getForm().getRecord());
51 var json = response.request.scope.reader.jsonData;
52 if (json) {
53 formPanel.setMessages(json.errors, json.warnings);
54 }
55 }
56 });
57 console.log('save');
58 },
59
60 discard: function(button) {
61 var formPanel = button.up('form');
62 formPanel.getForm().loadRecord(formPanel.getForm().getRecord());
63 },
64
65 dirtyForm: function(form, dirty) {
66 if (dirty) {
67 form.owner.down('button[action=save]').setDisabled(false);
68 form.owner.down('button[action=discard]').setDisabled(false);
69 }
70 else {
71 form.owner.down('button[action=save]').setDisabled(true);
72 form.owner.down('button[action=discard]').setDisabled(true);
73 }
74 }
75 });

http://lada.wald.intevation.org