annotate app/view/widgets/LadaForm.js @ 497:7c0653e8d9f7

Fixed some js related issues (unused vars, arrays, etc.) and code style.
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 06 Nov 2014 10:38:17 +0100
parents 850ccfe5f3c4
children 8b4ec61c5752
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) {
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
117 console.log('Save was successfull');
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
118 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
119 'savesuccess',
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,
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
121 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
122 response);
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
123 }
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
124 else {
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
125 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
126 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
127 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
128 'savefailure',
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
129 this,
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
130 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
131 response);
66
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 scope: this
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 },
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
138
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
139 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
140 this.bindModel(record);
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
141 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
142 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
143 },
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
144
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
145 onModelLoadFailure: function(record, operation) {
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
146 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
147 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
148 },
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
149
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
150 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
151 var translated = {};
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
152 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
153 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
154 }
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
155 return translated;
83
8525e3525538 Move parsing the response in a seperate function.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 75
diff changeset
156 },
280
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
157 /**
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
158 * 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
159 * @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
160 * 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
161 * @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
162 */
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
163 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
164 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
165 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
166 }
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
167 /* 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
168 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
169 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
170 // 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
171 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
172 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
173 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
174 console.log(ignoreFields[k] + '===' + field.getName());
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
175 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
176 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
177 }
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
178 }
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
179 // 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
180 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
181 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
182 }
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
183 });
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 /* 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
185 var childs = this.query('toolbar');
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
186 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
187 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
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 /*
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
190 * 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
191 * 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
192 * */
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
193 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
194 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
195 var buttons = win.query('.button');
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
196 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
197 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
198 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
199 }
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
200 }
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
201 }
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
202 }
85
079f99229eff Added function to mark the form as readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 84
diff changeset
203 },
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
204
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
205 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
206 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
207 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
208 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
209 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
210 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
211 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
212 if (!Ext.Object.isEmpty(this.warnings) ||
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
213 !Ext.Object.isEmpty(this.errors)) {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
214 this.createMessages();
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
215 }
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
216 }
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
217 else {
211
401d559e0461 Fix rendering the form readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 189
diff changeset
218 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
219 }
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
220 },
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
221
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
222 createMessages: function() {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
223 var messages = Ext.create('Ext.form.Panel', {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
224 bodyPadding: '5 5 5 5'
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
225 });
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
226 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
227 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
228 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
229 label = Ext.create('Ext.container.Container', {
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
230 layout: 'hbox',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
231 bodyPadding: '5 5 5 5',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
232 items: [{
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
233 xtype: 'image',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
234 src: 'gfx/icon-warning.gif',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
235 width: 18,
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
236 height: 18
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
237 }, {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
238 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
239 text: key + ': ' + this.warnings[key],
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
240 margin: '4 0 0 5'
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
241 }]
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 messages.insert(0, label);
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
244 }
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
245 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
246 label = Ext.create('Ext.container.Container', {
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
247 layout: 'hbox',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
248 bodyPadding: '5 5 5 5',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
249 items: [{
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
250 xtype: 'image',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
251 src: 'gfx/icon-error.gif',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
252 width: 18,
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
253 height: 18
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
254 }, {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
255 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
256 text: key + ': ' + this.errors[key],
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
257 margin: '4 0 0 5'
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 });
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
260 messages.insert(0, label);
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
261 }
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
262 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
263 }
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
264 });

http://lada.wald.intevation.org