annotate app/view/widgets/LadaForm.js @ 504:44e054626bdd

Code cleanup.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 12 Dec 2014 12:18:22 +0100
parents 369917727c86
children 2b5aa0e6e641
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,
503
369917727c86 Refactored proben edit window.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 499
diff changeset
21 minWidth: 650,
66
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 /**
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
24 * 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
25 */
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
26 model: null,
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
27 /**
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
28 * 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
29 * 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
30 */
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
31 modelId: null,
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
32 /**
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
33 * 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
34 * Typically set after the server validates the form submission
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
35 */
75
4a82e28dfcc4 Translate error codes and store them as attributes of the form
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 74
diff changeset
36 errors: null,
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
37 /**
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
38 * 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
39 * Typically set after the server validates the form submission
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
40 */
75
4a82e28dfcc4 Translate error codes and store them as attributes of the form
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 74
diff changeset
41 warnings: null,
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
42 /**
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
43 * 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
44 * Typically set after the server validates the form submission
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
45 */
75
4a82e28dfcc4 Translate error codes and store them as attributes of the form
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 74
diff changeset
46 message: null,
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
47 /**
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
48 * 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
49 * Typically set after the server validates the form submission
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
50 */
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
51 success: null,
283
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
52 /**
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
53 * 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
54 * be set after calling the {setReadOnly} function.
dec0893d38e3 Added docstrings
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 280
diff changeset
55 */
87
ee1d1305dcff Added field for netzbetreiber. Is needed because of FK constraints.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 85
diff changeset
56 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
57
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
58 initComponent: function() {
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
59 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
60
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
61 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
62
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
63 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
64 // 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
65 if (this.modelId) {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
66 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
67 failure: this.onModelLoadFailure,
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
68 success: this.onModelLoadSuccess,
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
69 scope: this
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
70 });
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
71 // Load an empty record to be inserted
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
72 }
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
73 else {
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
74 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
75 }
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
76 }
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
77 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
78 // 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
79 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
80 }
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
81 this.addEvents(
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
82 'loadsuccess',
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
83 'loadfailure',
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
84 'savesuccess',
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
85 'savefailure');
66
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
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
88 bindModel: function(model) {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
89 this.model = model;
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
90 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
91 // 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
92 // true
401d559e0461 Fix rendering the form readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 189
diff changeset
93 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
94 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
95 }
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
96 },
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
97
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
98 commit: function() {
84
5ad82cff1a21 Only submit form if internal validation is ok.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 83
diff changeset
99 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
100 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
101
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
102 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
103 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
104 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
105 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
106 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
107 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
108 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
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
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 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
112 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
113 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
114 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
115 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
116 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
117 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
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 {
75
4a82e28dfcc4 Translate error codes and store them as attributes of the form
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 74
diff changeset
125 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
126 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
127 'savefailure',
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,
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.model,
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
130 response);
66
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 },
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
133 scope: this
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
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
138 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
139 this.bindModel(record);
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
140 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
141 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
142 },
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 onModelLoadFailure: function(record, operation) {
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
145 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
146 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
147 },
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 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
150 var translated = {};
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
151 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
152 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
153 }
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
154 return translated;
83
8525e3525538 Move parsing the response in a seperate function.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 75
diff changeset
155 },
280
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
156 /**
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
157 * 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
158 * @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
159 * 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
160 * @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
161 */
1afccc0cab90 Issue55: Added ignoreFields parameter to the setReadonly function to be able
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 270
diff changeset
162 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
163 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
164 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
165 }
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
166 /* 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
167 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
168 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
169 // 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
170 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
171 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
172 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
173 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
174 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
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 }
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
177 // 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
178 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
179 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
180 }
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
181 });
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 /* 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
183 var childs = this.query('toolbar');
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
184 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
185 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
186 }
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
187 /*
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 * 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
189 * 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
190 * */
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
191 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
192 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
193 var buttons = win.query('.button');
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
194 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
195 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
196 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
197 }
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
198 }
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
199 }
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
200 }
85
079f99229eff Added function to mark the form as readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 84
diff changeset
201 },
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
202
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
203 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
204 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
205 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
206 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
207 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
208 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
209 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
210 if (!Ext.Object.isEmpty(this.warnings) ||
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
211 !Ext.Object.isEmpty(this.errors)) {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
212 this.createMessages();
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
213 }
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
214 }
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
215 else {
211
401d559e0461 Fix rendering the form readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 189
diff changeset
216 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
217 }
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
218 },
491
850ccfe5f3c4 Code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 490
diff changeset
219
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
220 createMessages: function() {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
221 var messages = Ext.create('Ext.form.Panel', {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
222 bodyPadding: '5 5 5 5'
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
223 });
497
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 key;
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
225 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
226 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
227 label = Ext.create('Ext.container.Container', {
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
228 layout: 'hbox',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
229 bodyPadding: '5 5 5 5',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
230 items: [{
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
231 xtype: 'image',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
232 src: 'gfx/icon-warning.gif',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
233 width: 18,
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
234 height: 18
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
235 }, {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
236 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
237 text: key + ': ' + this.warnings[key],
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
238 margin: '4 0 0 5'
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 });
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
241 messages.insert(0, label);
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
242 }
497
7c0653e8d9f7 Fixed some js related issues (unused vars, arrays, etc.) and code style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 491
diff changeset
243 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
244 label = Ext.create('Ext.container.Container', {
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
245 layout: 'hbox',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
246 bodyPadding: '5 5 5 5',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
247 items: [{
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
248 xtype: 'image',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
249 src: 'gfx/icon-error.gif',
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
250 width: 18,
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
251 height: 18
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
252 }, {
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
253 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
254 text: key + ': ' + this.errors[key],
406
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
255 margin: '4 0 0 5'
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 });
de73dc41f1d3 Show warnings in proben edit form.
Raimund Renkert <rrenkert@intevation.de>
parents: 361
diff changeset
258 messages.insert(0, label);
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 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
261 }
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
262 });

http://lada.wald.intevation.org