annotate app/view/widgets/LadaForm.js @ 509:4ac3eee22f96

Updated 'create messung' window.
author Raimund Renkert <raimund.renkert@intevation.de>
date Sat, 13 Dec 2014 14:12:52 +0100
parents 2b5aa0e6e641
children 66f3c5d258e2
rev   line source
472
debfcc7713e3 Added license header to each file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 406
diff changeset
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
debfcc7713e3 Added license header to each file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 406
diff changeset
2 * Software engineering by Intevation GmbH
debfcc7713e3 Added license header to each file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 406
diff changeset
3 *
debfcc7713e3 Added license header to each file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 406
diff changeset
4 * This file is Free Software under the GNU GPL (v>=3)
debfcc7713e3 Added license header to each file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 406
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
6 * the documentation coming with IMIS-Labordaten-Application for details.
472
debfcc7713e3 Added license header to each file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 406
diff changeset
7 */
debfcc7713e3 Added license header to each file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 406
diff changeset
8
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
9 /**
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
10 * Generic Lada specific form.
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
11 *
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
12 * See http://moduscreate.com/expert-ext-js-model-integration-in-forms/ for
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
13 * more details
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
14 */
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
15 Ext.define('Lada.view.widgets.LadaForm', {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
16 extend: 'Ext.form.Panel',
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
17
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
18 alias: 'widget.ladaform',
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
19 bodyPadding: '10 10',
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
20 border: 0,
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
21
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
22 /**
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
23 * Can be a reference to a model instance or a model class name.
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
24 */
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
25 model: null,
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
26 /**
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
27 * Set to the id of the model instance and the model will be loaded for you.
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
28 * Only applicable if model provided is a model class name (string).
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
29 */
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
30 modelId: null,
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
31 /**
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
32 * List of errors in the form.
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
33 * Typically set after the server validates the form submission
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
34 */
75
4a82e28dfcc4 Translate error codes and store them as attributes of the form
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 74
diff changeset
35 errors: null,
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
36 /**
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
37 * List of warnings in the form.
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
38 * Typically set after the server validates the form submission
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
39 */
75
4a82e28dfcc4 Translate error codes and store them as attributes of the form
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 74
diff changeset
40 warnings: null,
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
41 /**
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
42 * The generic (error) message for the form.
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
43 * Typically set after the server validates the form submission
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
44 */
75
4a82e28dfcc4 Translate error codes and store them as attributes of the form
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 74
diff changeset
45 message: null,
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
46 /**
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
47 * Flag to indicate if the validation succeeds.
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
48 * Typically set after the server validates the form submission
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
49 */
133
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
50 success: null,
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
51 /**
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
52 * Flag to indicate if the form should be rendered in readonly mode. Will
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
53 * be set after calling the {setReadOnly} function.
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
54 */
87
ee1d1305dcff Added field for netzbetreiber. Is needed because of FK constraints.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 85
diff changeset
55 readonly: false,
75
4a82e28dfcc4 Translate error codes and store them as attributes of the form
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 74
diff changeset
56
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
57 initComponent: function() {
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
58 this.callParent(arguments);
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
59
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
60 this.getForm().trackResetOnLoad = true; // Workaround
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
61
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
62 if (Ext.isString(this.model)) {
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
63 // Load a model to be updated
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
64 if (this.modelId) {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
65 Ext.ClassManager.get(this.model).load(this.modelId, {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
66 failure: this.onModelLoadFailure,
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
67 success: this.onModelLoadSuccess,
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
68 scope: this
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
69 });
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
70 // Load an empty record to be inserted
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
71 }
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
72 else {
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
73 this.bindModel(Ext.create(this.model, {}));
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
74 }
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
75 }
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
76 else {
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
77 // Bind the provided model to be updated
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
78 this.bindModel(this.model);
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
79 }
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
80 this.addEvents(
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
81 'loadsuccess',
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
82 'loadfailure',
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
83 'savesuccess',
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
84 'savefailure');
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
85 },
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
86
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
87 bindModel: function(model) {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
88 this.model = model;
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
89 this.loadRecord(model);
189
214d1b274a50 As the model now should have a readonly flag, the check if the form must be
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 188
diff changeset
90 // Set the form to readonly if the models readonly attribute is
211
401d559e0461 Fix rendering the form readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 189
diff changeset
91 // true
401d559e0461 Fix rendering the form readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 189
diff changeset
92 if (model.get('readonly') === true) {
189
214d1b274a50 As the model now should have a readonly flag, the check if the form must be
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 188
diff changeset
93 this.setReadOnly(true);
214d1b274a50 As the model now should have a readonly flag, the check if the form must be
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 188
diff changeset
94 }
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
95 },
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
96
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
97 commit: function() {
84
5ad82cff1a21 Only submit form if internal validation is ok.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 83
diff changeset
98 if (this.form.isDirty() && this.form.isValid()) {
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
99 this.form.updateRecord(this.model);
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
100
133
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
101 var data = this.model.getAllData();
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
102 var baseUrl = this.model.getProxy().url;
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
103 var url = baseUrl;
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
104 var method = 'POST';
133
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
105 if (this.model.getId()) {
490
446e99cfd425 Updated views and controllers using the new model and stores.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 472
diff changeset
106 url += this.model.getId();
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
107 method = 'PUT';
133
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
108 }
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
109
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
110 Ext.Ajax.request({
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
111 url: url,
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
112 jsonData: data,
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
113 method: method,
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
114 callback: function(option, success, response) {
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
115 this.parseResponse(response);
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
116 if (this.success) {
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
117 this.fireEvent(
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
118 'savesuccess',
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
119 this,
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
120 this.model,
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
121 response);
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
122 }
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
123 else {
75
4a82e28dfcc4 Translate error codes and store them as attributes of the form
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 74
diff changeset
124 this.form.markInvalid(this.errors);
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
125 this.fireEvent(
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
126 'savefailure',
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
127 this,
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
128 this.model,
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
129 response);
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
130 }
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
131 },
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
132 scope: this
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
133 });
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
134 }
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
135 },
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
136
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
137 onModelLoadSuccess: function(record, operation) {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
138 this.bindModel(record);
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
139 this.parseResponse(operation.response);
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
140 this.fireEvent('loadsuccess', this, record, operation);
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
141 },
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
142
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
143 onModelLoadFailure: function(record, operation) {
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
144 this.parseResponse(operation.response);
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
145 this.fireEvent('loadfailure', this, record, operation);
74
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
146 },
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
147
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
148 translateReturnCodes: function(codes) {
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
149 var translated = {};
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
150 for (var k in codes) {
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
151 translated[k] = Lada.getApplication().bundle.getMsg(codes[k]);
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
152 }
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
153 return translated;
83
8525e3525538 Move parsing the response in a seperate function.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 75
diff changeset
154 },
280
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
155 /**
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
156 * Will set the form into readonly state.
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
157 * @param {Boolean} Flag to indicate if the form should be set to readonly
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
158 * or not.
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
159 * @param {Array} [ignoreFields="[]"] A list of fieldnames to ignore.
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
160 */
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
161 setReadOnly: function (bReadOnly, ignoreFields) {
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
162 if (typeof (ignoreFields) === 'undefined') {
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
163 ignoreFields = [];
280
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
164 }
221
cf83b382dc02 setReadOnly now also iterates over the toolbars within the form and hide them
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 211
diff changeset
165 /* Iterate over all fields and set them readonly */
228
08144d625b2b Only iterate over fields of the form is readonly. This increases the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 221
diff changeset
166 if (bReadOnly) {
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
167 this.getForm().getFields().each(function (field) {
280
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
168 // Check if the field name is in the list of fields to ignore
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
169 var ignore = false;
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
170 var k;
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
171 for (k = ignoreFields.length - 1; k >= 0; k--) {
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
172 if (ignoreFields[k] === field.getName(true)) {
280
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
173 ignore = true;
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
174 }
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
175 }
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
176 // field.setDisabled(bReadOnly);
280
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
177 if (!ignore) {
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
178 field.setReadOnly(true);
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
179 }
228
08144d625b2b Only iterate over fields of the form is readonly. This increases the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 221
diff changeset
180 });
08144d625b2b Only iterate over fields of the form is readonly. This increases the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 221
diff changeset
181 /* Iterate over all toolbars of lists and hide them */
08144d625b2b Only iterate over fields of the form is readonly. This increases the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 221
diff changeset
182 var childs = this.query('toolbar');
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
183 for (var i = childs.length - 1; i >= 0; i--) {
228
08144d625b2b Only iterate over fields of the form is readonly. This increases the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 221
diff changeset
184 childs[i].setVisible(false);
08144d625b2b Only iterate over fields of the form is readonly. This increases the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 221
diff changeset
185 }
361
8a3991b5c200 Only hide save buttons if there are no fields which should be ignore while
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 283
diff changeset
186 /*
8a3991b5c200 Only hide save buttons if there are no fields which should be ignore while
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 283
diff changeset
187 * Find Save-Button and hide it. Only hide it if there are not
8a3991b5c200 Only hide save buttons if there are no fields which should be ignore while
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 283
diff changeset
188 * fields left in the form which are editable
8a3991b5c200 Only hide save buttons if there are no fields which should be ignore while
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 283
diff changeset
189 * */
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
190 if (ignoreFields.length === 0) {
361
8a3991b5c200 Only hide save buttons if there are no fields which should be ignore while
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 283
diff changeset
191 var win = this.up('window');
8a3991b5c200 Only hide save buttons if there are no fields which should be ignore while
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 283
diff changeset
192 var buttons = win.query('.button');
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
193 for (var j = buttons.length - 1; j >= 0; j--) {
361
8a3991b5c200 Only hide save buttons if there are no fields which should be ignore while
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 283
diff changeset
194 if (buttons[j].text === 'Speichern') {
8a3991b5c200 Only hide save buttons if there are no fields which should be ignore while
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 283
diff changeset
195 buttons[j].setVisible(false);
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
196 }
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
197 }
361
8a3991b5c200 Only hide save buttons if there are no fields which should be ignore while
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 283
diff changeset
198 }
221
cf83b382dc02 setReadOnly now also iterates over the toolbars within the form and hide them
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 211
diff changeset
199 }
85
079f99229eff Added function to mark the form as readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 84
diff changeset
200 },
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
201
133
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
202 parseResponse: function(response) {
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
203 var json = Ext.decode(response.responseText);
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
204 if (json) {
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
205 this.success = json.success;
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
206 this.errors = this.translateReturnCodes(json.errors);
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
207 this.warnings = this.translateReturnCodes(json.warnings);
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
208 this.message = Lada.getApplication().bundle.getMsg(json.message);
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
209 if (!Ext.Object.isEmpty(this.warnings) ||
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
210 !Ext.Object.isEmpty(this.errors)) {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
211 this.createMessages();
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
212 }
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
213 }
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
214 else {
211
401d559e0461 Fix rendering the form readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 189
diff changeset
215 this.setReadOnly(this.model.get('readonly'));
133
819bfedb70de Do not use the model.save mathod to store items in the databut but trigger a
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 87
diff changeset
216 }
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
217 },
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
218
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
219 createMessages: function() {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
220 var messages = Ext.create('Ext.form.Panel', {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
221 bodyPadding: '5 5 5 5'
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
222 });
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
223 var key;
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
224 var label;
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
225 for (key in this.warnings) {
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
226 label = Ext.create('Ext.container.Container', {
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
227 layout: 'hbox',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
228 bodyPadding: '5 5 5 5',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
229 items: [{
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
230 xtype: 'image',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
231 src: 'gfx/icon-warning.gif',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
232 width: 18,
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
233 height: 18
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
234 }, {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
235 xtype: 'label',
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
236 text: key + ': ' + this.warnings[key],
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
237 margin: '4 0 0 5'
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
238 }]
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
239 });
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
240 messages.insert(0, label);
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
241 }
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
242 for (key in this.errors) {
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
243 label = Ext.create('Ext.container.Container', {
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
244 layout: 'hbox',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
245 bodyPadding: '5 5 5 5',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
246 items: [{
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
247 xtype: 'image',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
248 src: 'gfx/icon-error.gif',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
249 width: 18,
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
250 height: 18
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
251 }, {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
252 xtype: 'label',
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
253 text: key + ': ' + this.errors[key],
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
254 margin: '4 0 0 5'
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
255 }]
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
256 });
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
257 messages.insert(0, label);
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
258 }
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
259 this.insert(0, messages);
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
260 }
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
261 });

http://lada.wald.intevation.org