Mercurial > lada > lada-client
comparison app/controller/form/Ort.js @ 603:9d0113bc2f70
Added ort form and controller.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 12 Mar 2015 15:51:24 +0100 |
parents | |
children | 3d33c65319f3 |
comparison
equal
deleted
inserted
replaced
602:e1ab24758392 | 603:9d0113bc2f70 |
---|---|
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.Ort', { | |
10 extend: 'Ext.app.Controller', | |
11 | |
12 init: function() { | |
13 this.control({ | |
14 'ortform button[action=save]': { | |
15 click: this.save | |
16 }, | |
17 'ortform button[action=discard]': { | |
18 click: this.discard | |
19 }, | |
20 'ortform': { | |
21 dirtychange: this.dirtyForm | |
22 }, | |
23 'ortform combobox[name=ort]': { | |
24 select: this.updateDetails | |
25 } | |
26 }); | |
27 }, | |
28 | |
29 save: function(button) { | |
30 var formPanel = button.up('form'); | |
31 var data = formPanel.getForm().getFieldValues(true); | |
32 for (var key in data) { | |
33 formPanel.getForm().getRecord().set(key, data[key]); | |
34 } | |
35 formPanel.getForm().getRecord().save({ | |
36 success: function(record, response) { | |
37 var json = Ext.decode(response.response.responseText); | |
38 if (response.action !== 'create' && | |
39 json && | |
40 json.success) { | |
41 button.setDisabled(true); | |
42 button.up('toolbar').down('button[action=discard]') | |
43 .setDisabled(true); | |
44 formPanel.clearMessages(); | |
45 formPanel.setRecord(record); | |
46 formPanel.setMessages(json.errors, json.warnings); | |
47 } | |
48 }, | |
49 failure: function(record, response) { | |
50 button.setDisabled(true); | |
51 button.up('toolbar').down('button[action=discard]') | |
52 .setDisabled(true); | |
53 formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); | |
54 var json = response.request.scope.reader.jsonData; | |
55 if (json) { | |
56 formPanel.setMessages(json.errors, json.warnings); | |
57 } | |
58 } | |
59 }); | |
60 console.log('save'); | |
61 }, | |
62 | |
63 discard: function(button) { | |
64 var formPanel = button.up('form'); | |
65 formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); | |
66 }, | |
67 | |
68 dirtyForm: function(form, dirty) { | |
69 if (dirty) { | |
70 form.owner.down('button[action=save]').setDisabled(false); | |
71 form.owner.down('button[action=discard]').setDisabled(false); | |
72 } | |
73 else { | |
74 form.owner.down('button[action=save]').setDisabled(true); | |
75 form.owner.down('button[action=discard]').setDisabled(true); | |
76 } | |
77 }, | |
78 | |
79 updateDetails: function(combobox, record) { | |
80 console.log(record); | |
81 var win = combobox.up('window'); | |
82 var details = win.down('locationform'); | |
83 var id = record[0].get('id'); | |
84 if (details) { | |
85 Ext.ClassManager.get('Lada.model.Location').load(id, { | |
86 failure: function(record, action) { | |
87 // TODO | |
88 }, | |
89 success: function(record, response) { | |
90 win.down('locationform').setRecord(record); | |
91 }, | |
92 scope: this | |
93 }); | |
94 } | |
95 } | |
96 }); |