comparison app/controller/form/Probe.js @ 587:cf328526b5bb

Moved controller into subfolders.
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 11 Mar 2015 13:39:04 +0100
parents
children e0b966b32163
comparison
equal deleted inserted replaced
586:a9268f5cde26 587:cf328526b5bb
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.Probe', {
10 extend: 'Ext.app.Controller',
11
12 init: function() {
13 this.control({
14 'probeform button[action=save]': {
15 click: this.save
16 },
17 'probeform button[action=discard]': {
18 click: this.discard
19 },
20 'probeform': {
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