annotate app/controller/form/Messung.js @ 710:f204f30b824a

Handle readonly mode and refresh operations.
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 08 Apr 2015 10:50:33 +0200
parents f0bc5387abcc
children baef70abfe71
rev   line source
611
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
3 *
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU GPL (v>=3)
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
6 * the documentation coming with IMIS-Labordaten-Application for details.
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
7 */
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
8
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
9 Ext.define('Lada.controller.form.Messung', {
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
10 extend: 'Ext.app.Controller',
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
11
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
12 init: function() {
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
13 this.control({
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
14 'messungform button[action=save]': {
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
15 click: this.save
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
16 },
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
17 'messungform button[action=discard]': {
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
18 click: this.discard
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
19 },
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
20 'messungform': {
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
21 dirtychange: this.dirtyForm
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
22 }
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
23 });
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
24 },
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
25
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
26 save: function(button) {
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
27 var formPanel = button.up('form');
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
28 var data = formPanel.getForm().getFieldValues(true);
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
29 for (var key in data) {
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
30 formPanel.getForm().getRecord().set(key, data[key]);
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
31 }
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
32 formPanel.getForm().getRecord().save({
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
33 success: function(record, response) {
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
34 var json = Ext.decode(response.response.responseText);
622
ee92e352be20 Open messung create window on button click.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 611
diff changeset
35 if (json) {
611
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
36 button.setDisabled(true);
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
37 button.up('toolbar').down('button[action=discard]')
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
38 .setDisabled(true);
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
39 formPanel.clearMessages();
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
40 formPanel.setRecord(record);
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
41 formPanel.setMessages(json.errors, json.warnings);
710
f204f30b824a Handle readonly mode and refresh operations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 701
diff changeset
42 formPanel.up('window').initData();
644
71e8b84d7829 Reload grids on messung or ort changed/added.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 639
diff changeset
43 formPanel.up('window').grid.store.reload();
710
f204f30b824a Handle readonly mode and refresh operations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 701
diff changeset
44 var parentWin = button.up('window').grid.up('window');
f204f30b824a Handle readonly mode and refresh operations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 701
diff changeset
45 parentWin.initData();
639
fdaabab6f4cc Open Probe-/Messung-Edit window automatically if a new item was saved
Raimund Renkert <raimund.renkert@intevation.de>
parents: 622
diff changeset
46 if (response.action === 'create' && json.success) {
710
f204f30b824a Handle readonly mode and refresh operations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 701
diff changeset
47 var oldWin = button.up('window');
f204f30b824a Handle readonly mode and refresh operations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 701
diff changeset
48 var probe = oldWin.record;
f204f30b824a Handle readonly mode and refresh operations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 701
diff changeset
49 oldWin.close();
639
fdaabab6f4cc Open Probe-/Messung-Edit window automatically if a new item was saved
Raimund Renkert <raimund.renkert@intevation.de>
parents: 622
diff changeset
50 var win = Ext.create('Lada.view.window.MessungEdit', {
710
f204f30b824a Handle readonly mode and refresh operations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 701
diff changeset
51 probe: probe,
f204f30b824a Handle readonly mode and refresh operations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 701
diff changeset
52 parentWindow: parentWin,
f204f30b824a Handle readonly mode and refresh operations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 701
diff changeset
53 grid: oldWin.grid,
639
fdaabab6f4cc Open Probe-/Messung-Edit window automatically if a new item was saved
Raimund Renkert <raimund.renkert@intevation.de>
parents: 622
diff changeset
54 record: record
fdaabab6f4cc Open Probe-/Messung-Edit window automatically if a new item was saved
Raimund Renkert <raimund.renkert@intevation.de>
parents: 622
diff changeset
55 });
fdaabab6f4cc Open Probe-/Messung-Edit window automatically if a new item was saved
Raimund Renkert <raimund.renkert@intevation.de>
parents: 622
diff changeset
56 win.show();
fdaabab6f4cc Open Probe-/Messung-Edit window automatically if a new item was saved
Raimund Renkert <raimund.renkert@intevation.de>
parents: 622
diff changeset
57 win.initData();
fdaabab6f4cc Open Probe-/Messung-Edit window automatically if a new item was saved
Raimund Renkert <raimund.renkert@intevation.de>
parents: 622
diff changeset
58 }
611
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
59 }
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
60 },
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
61 failure: function(record, response) {
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
62 button.setDisabled(true);
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
63 button.up('toolbar').down('button[action=discard]')
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
64 .setDisabled(true);
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
65 formPanel.getForm().loadRecord(formPanel.getForm().getRecord());
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
66 var json = response.request.scope.reader.jsonData;
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
67 if (json) {
693
817524db4017 Readonly was missing
Dustin Demuth <dustin@intevation.de>
parents: 687
diff changeset
68 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0) {
817524db4017 Readonly was missing
Dustin Demuth <dustin@intevation.de>
parents: 687
diff changeset
69 formPanel.setMessages(json.errors, json.warnings);
817524db4017 Readonly was missing
Dustin Demuth <dustin@intevation.de>
parents: 687
diff changeset
70 }
817524db4017 Readonly was missing
Dustin Demuth <dustin@intevation.de>
parents: 687
diff changeset
71
817524db4017 Readonly was missing
Dustin Demuth <dustin@intevation.de>
parents: 687
diff changeset
72 if(json.message){
701
f0bc5387abcc Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents: 695
diff changeset
73 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title')
f0bc5387abcc Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents: 695
diff changeset
74 +' #'+json.message,
695
d6ef146e1a9f Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents: 693
diff changeset
75 Lada.getApplication().bundle.getMsg(json.message));
701
f0bc5387abcc Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents: 695
diff changeset
76 } else {
f0bc5387abcc Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents: 695
diff changeset
77 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
f0bc5387abcc Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents: 695
diff changeset
78 Lada.getApplication().bundle.getMsg('err.msg.generic.body'));
693
817524db4017 Readonly was missing
Dustin Demuth <dustin@intevation.de>
parents: 687
diff changeset
79 }
701
f0bc5387abcc Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents: 695
diff changeset
80 } else {
f0bc5387abcc Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents: 695
diff changeset
81 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
f0bc5387abcc Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents: 695
diff changeset
82 Lada.getApplication().bundle.getMsg('err.msg.response.body'));
611
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
83 }
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
84 }
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
85 });
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
86 },
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
87
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
88 discard: function(button) {
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
89 var formPanel = button.up('form');
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
90 formPanel.getForm().loadRecord(formPanel.getForm().getRecord());
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
91 },
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
92
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
93 dirtyForm: function(form, dirty) {
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
94 if (dirty) {
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
95 form.owner.down('button[action=save]').setDisabled(false);
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
96 form.owner.down('button[action=discard]').setDisabled(false);
687
aedf0709af92 Applied ReadOnlyParadigm to a Messung Window
Dustin Demuth <dustin@intevation.de>
parents: 644
diff changeset
97 form.owner.up('window').disableChildren();
611
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
98 }
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
99 else {
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
100 form.owner.down('button[action=save]').setDisabled(true);
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
101 form.owner.down('button[action=discard]').setDisabled(true);
687
aedf0709af92 Applied ReadOnlyParadigm to a Messung Window
Dustin Demuth <dustin@intevation.de>
parents: 644
diff changeset
102 form.owner.up('window').enableChildren();
611
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
103 }
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
104 }
8a156a7fbe67 added a controller for messungforms, modified testdatensatz-widget to load a local store, removed dirtychange listeners from probe-form
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
105 });

http://lada.wald.intevation.org