annotate app/view/widgets/LadaForm.js @ 479:d00cc841a876

Set size on initialize in windows.
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 21 Jan 2014 15:08:53 +0100
parents debfcc7713e3
children 446e99cfd425
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
debfcc7713e3 Added license header to each file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 406
diff changeset
6 * the documentation coming with IMIS-Labordaten-Application for details.
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 /**
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
32 * List of errors in the form. Typically set after the server validates the form submission
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
33 */
75
4a82e28dfcc4 Translate error codes and store them as attributes of the form
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 74
diff changeset
34 errors: null,
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
35 /**
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
36 * List of warnings in the form. Typically set after the server validates the form submission
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
37 */
75
4a82e28dfcc4 Translate error codes and store them as attributes of the form
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 74
diff changeset
38 warnings: null,
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
39 /**
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
40 * The generic (error) message for the form. Typically set after the server validates the form submission
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
41 */
75
4a82e28dfcc4 Translate error codes and store them as attributes of the form
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 74
diff changeset
42 message: null,
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
43 /**
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
44 * Flag to indicate if the validation succeeds. Typically set after the server validates the form submission
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
45 */
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
46 success: null,
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
47 /**
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
48 * 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
49 * be set after calling the {setReadOnly} function.
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
50 */
87
ee1d1305dcff Added field for netzbetreiber. Is needed because of FK constraints.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 85
diff changeset
51 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
52
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
53 initComponent: function() {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
54
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
55 this.callParent();
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
56
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
57 this.getForm().trackResetOnLoad = true; //Workaround
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
58
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
59 if (Ext.isString(this.model)) {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
60
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
61 //Load a model to be updated
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
62 if (this.modelId) {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
63
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
64 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
65 failure: this.onModelLoadFailure,
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
66 success: this.onModelLoadSuccess,
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
67 scope: this
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
68 });
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
69
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
70 //Load an empty record to be inserted
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
71 } else {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
72 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
73 }
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
74
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
75 } else {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
76
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
77 //Bind the provided model to be updated
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
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
80 }
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
81
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
82 this.addEvents('loadsuccess', 'loadfailure', 'savesuccess', 'savefailure');
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
83 },
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
84
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
85 bindModel: function(model) {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
86 this.model = model;
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
87 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
88 // 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
89 // true
401d559e0461 Fix rendering the form readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 189
diff changeset
90 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
91 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
92 }
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
93 },
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
94
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
95 commit: function(callback, scope) {
84
5ad82cff1a21 Only submit form if internal validation is ok.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 83
diff changeset
96 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
97 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
98
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
99 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
100 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
101 var url = baseUrl;
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 method = "POST";
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 if (this.model.getId()) {
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
104 url += this.model.getEidi();
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 method = "PUT";
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
106 }
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
107
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 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
109 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
110 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
111 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
112 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
113 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
114 if (this.success) {
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
115 console.log('Save was successfull');
255
82118c01bc52 #57: Open Edit-Dialog after creating a new Probe.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 228
diff changeset
116 this.fireEvent('savesuccess', this, this.model, response);
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
117 } else {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
118 console.log('Save was not successfull');
75
4a82e28dfcc4 Translate error codes and store them as attributes of the form
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 74
diff changeset
119 this.form.markInvalid(this.errors);
255
82118c01bc52 #57: Open Edit-Dialog after creating a new Probe.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 228
diff changeset
120 this.fireEvent('savefailure', this, this.model, response);
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
121 }
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
122 },
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
123 scope: this
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
124 });
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
125 }
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
126 },
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
127
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
128 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
129 this.bindModel(record);
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
130 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
131 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
132 },
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 onModelLoadFailure: function(record, operation) {
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
135 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
136 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
137 },
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
138
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
139 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
140 var translated = {};
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
141 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
142 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
143 }
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
144 return translated;
83
8525e3525538 Move parsing the response in a seperate function.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 75
diff changeset
145 },
280
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
146 /**
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
147 * 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
148 * @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
149 * 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
150 * @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
151 */
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
152 setReadOnly: function (bReadOnly, ignoreFields) {
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
153 if(typeof(ignoreFields)==='undefined') {
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
154 ignoreFields = Array();
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
155 }
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
156 /* 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
157 if (bReadOnly) {
08144d625b2b Only iterate over fields of the form is readonly. This increases the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 221
diff changeset
158 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
159 // 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
160 var ignore = false;
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
161 for (var i = ignoreFields.length - 1; i >= 0; i--){
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
162 console.log(ignoreFields[i] + "===" + field.getName());
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
163 if (ignoreFields[i] === field.getName(true)) {
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
164 ignore = true;
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
165 };
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
166 };
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
167 //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
168 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
169 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
170 }
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
171 });
08144d625b2b Only iterate over fields of the form is readonly. This increases the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 221
diff changeset
172 /* 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
173 var childs = this.query('toolbar');
08144d625b2b Only iterate over fields of the form is readonly. This increases the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 221
diff changeset
174 for (var i = childs.length - 1; i >= 0; i--){
08144d625b2b Only iterate over fields of the form is readonly. This increases the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 221
diff changeset
175 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
176 }
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
177 /*
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
178 * 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
179 * 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
180 * */
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
181 if (ignoreFields.length == 0) {
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
182 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
183 var buttons = win.query('.button');
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
184 for (var j = buttons.length - 1; j >= 0; j--){
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
185 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
186 buttons[j].setVisible(false);
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 };
270
0d6552bb28ea Add cancel Button to the editproben window and only show save button if the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 255
diff changeset
188 };
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
189 }
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
190 }
85
079f99229eff Added function to mark the form as readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 84
diff changeset
191 },
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
192 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
193 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
194 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
195 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
196 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
197 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
198 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
199 var e = Ext.Object.isEmpty(this.warnings);
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
200 if (!Ext.Object.isEmpty(this.warnings) ||
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
201 !Ext.Object.isEmpty(this.errors)) {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
202 this.createMessages();
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
203 }
185
df5dcdff7b69 Enabled readonly mode
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 133
diff changeset
204 } else {
211
401d559e0461 Fix rendering the form readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 189
diff changeset
205 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
206 }
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
207 },
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
208 createMessages: function() {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
209 var messages = Ext.create('Ext.form.Panel', {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
210 bodyPadding: '5 5 5 5'
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
211 });
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
212 for (var key in this.warnings) {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
213 var label = Ext.create('Ext.container.Container', {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
214 layout: 'hbox',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
215 bodyPadding: '5 5 5 5',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
216 items: [{
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
217 xtype: 'image',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
218 src: 'gfx/icon-warning.gif',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
219 width: 18,
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
220 height: 18
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
221 }, {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
222 xtype: 'label',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
223 text: key + ": " + this.warnings[key],
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
224 margin: '4 0 0 5'
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
225 }]
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
226 });
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
227 messages.insert(0, label);
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
228 }
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
229 for (var key in this.errors) {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
230 var label = Ext.create('Ext.container.Container', {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
231 layout: 'hbox',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
232 bodyPadding: '5 5 5 5',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
233 items: [{
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
234 xtype: 'image',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
235 src: 'gfx/icon-error.gif',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
236 width: 18,
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
237 height: 18
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 xtype: 'label',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
240 text: key + ": " + this.errors[key],
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
241 margin: '4 0 0 5'
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
242 }]
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
243 });
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
244 messages.insert(0, label);
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
245 }
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
246 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
247 }
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
248 });

http://lada.wald.intevation.org