Mercurial > lada > lada-client
annotate app/controller/form/Probe.js @ 687:aedf0709af92
Applied ReadOnlyParadigm to a Messung Window
author | Dustin Demuth <dustin@intevation.de> |
---|---|
date | Wed, 25 Mar 2015 15:45:33 +0100 |
parents | 14ac75f80ba1 |
children | 817524db4017 |
rev | line source |
---|---|
587
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
3 * |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
4 * This file is Free Software under the GNU GPL (v>=3) |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
6 * the documentation coming with IMIS-Labordaten-Application for details. |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
7 */ |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
8 |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
9 Ext.define('Lada.controller.form.Probe', { |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
10 extend: 'Ext.app.Controller', |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
11 |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
12 init: function() { |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
13 this.control({ |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 'probeform button[action=save]': { |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
15 click: this.save |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
16 }, |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
17 'probeform button[action=discard]': { |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
18 click: this.discard |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
19 }, |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
20 'probeform': { |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
21 dirtychange: this.dirtyForm |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
22 } |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
23 }); |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
24 }, |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
25 |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
26 save: function(button) { |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 var formPanel = button.up('form'); |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
28 var data = formPanel.getForm().getFieldValues(true); |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
29 for (var key in data) { |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
30 formPanel.getForm().getRecord().set(key, data[key]); |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
31 } |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
32 formPanel.getForm().getRecord().save({ |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
33 success: function(record, response) { |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
34 var json = Ext.decode(response.response.responseText); |
620
e0b966b32163
Open probe create window on button click.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
587
diff
changeset
|
35 if (json) { |
587
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
36 button.setDisabled(true); |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
37 button.up('toolbar').down('button[action=discard]') |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
38 .setDisabled(true); |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
39 formPanel.clearMessages(); |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
40 formPanel.setRecord(record); |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
41 formPanel.setMessages(json.errors, json.warnings); |
639
fdaabab6f4cc
Open Probe-/Messung-Edit window automatically if a new item was saved
Raimund Renkert <raimund.renkert@intevation.de>
parents:
620
diff
changeset
|
42 if (response.action === 'create' && json.success) { |
fdaabab6f4cc
Open Probe-/Messung-Edit window automatically if a new item was saved
Raimund Renkert <raimund.renkert@intevation.de>
parents:
620
diff
changeset
|
43 button.up('window').close(); |
fdaabab6f4cc
Open Probe-/Messung-Edit window automatically if a new item was saved
Raimund Renkert <raimund.renkert@intevation.de>
parents:
620
diff
changeset
|
44 var win = Ext.create('Lada.view.window.ProbeEdit', { |
fdaabab6f4cc
Open Probe-/Messung-Edit window automatically if a new item was saved
Raimund Renkert <raimund.renkert@intevation.de>
parents:
620
diff
changeset
|
45 record: record |
fdaabab6f4cc
Open Probe-/Messung-Edit window automatically if a new item was saved
Raimund Renkert <raimund.renkert@intevation.de>
parents:
620
diff
changeset
|
46 }); |
fdaabab6f4cc
Open Probe-/Messung-Edit window automatically if a new item was saved
Raimund Renkert <raimund.renkert@intevation.de>
parents:
620
diff
changeset
|
47 win.show(); |
fdaabab6f4cc
Open Probe-/Messung-Edit window automatically if a new item was saved
Raimund Renkert <raimund.renkert@intevation.de>
parents:
620
diff
changeset
|
48 win.initData(); |
fdaabab6f4cc
Open Probe-/Messung-Edit window automatically if a new item was saved
Raimund Renkert <raimund.renkert@intevation.de>
parents:
620
diff
changeset
|
49 } |
587
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
50 } |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
51 }, |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
52 failure: function(record, response) { |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
53 button.setDisabled(true); |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
54 button.up('toolbar').down('button[action=discard]') |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
55 .setDisabled(true); |
678
a24db43b13b5
Set record dirty flag to false if commit failed.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
639
diff
changeset
|
56 var rec = formPanel.getForm().getRecord(); |
a24db43b13b5
Set record dirty flag to false if commit failed.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
639
diff
changeset
|
57 rec.dirty = false; |
a24db43b13b5
Set record dirty flag to false if commit failed.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
639
diff
changeset
|
58 formPanel.getForm().loadRecord(rec); |
587
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
59 var json = response.request.scope.reader.jsonData; |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 if (json) { |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 formPanel.setMessages(json.errors, json.warnings); |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
62 } |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
63 } |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
64 }); |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
65 console.log('save'); |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
66 }, |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
67 |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
68 discard: function(button) { |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
69 var formPanel = button.up('form'); |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
70 formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
71 }, |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
72 |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
73 dirtyForm: function(form, dirty) { |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
74 if (dirty) { |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
75 form.owner.down('button[action=save]').setDisabled(false); |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
76 form.owner.down('button[action=discard]').setDisabled(false); |
686
14ac75f80ba1
Forgot to commit the controller for commit 684
Dustin Demuth <dustin@intevation.de>
parents:
678
diff
changeset
|
77 form.owner.up('window').disableChildren(); |
587
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
78 } |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
79 else { |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
80 form.owner.down('button[action=save]').setDisabled(true); |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
81 form.owner.down('button[action=discard]').setDisabled(true); |
686
14ac75f80ba1
Forgot to commit the controller for commit 684
Dustin Demuth <dustin@intevation.de>
parents:
678
diff
changeset
|
82 form.owner.up('window').enableChildren(); // todo this might not be true in all cases |
587
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
83 } |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
84 } |
cf328526b5bb
Moved controller into subfolders.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
85 }); |