annotate app/view/widgets/LadaForm.js @ 95:453985cacb39

Set flex option in grid for "Gemeindebezeichnung"
author Torsten Irländer <torsten.irlaender@intevation.de>
date Thu, 13 Jun 2013 14:26:37 +0200
parents ee1d1305dcff
children 819bfedb70de
rev   line source
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
1 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
2 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
3
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
4 alias: 'widget.ladaform',
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
5 /**
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
6 * http://moduscreate.com/expert-ext-js-model-integration-in-forms/
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
7 */
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
8
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
9 /**
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
10 * 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
11 */
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
12 model: null,
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
13 /**
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
14 * 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
15 * 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
16 */
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
17 modelId: null,
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
18 bodyPadding: '10 10',
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
19 border: 0,
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
20
75
4a82e28dfcc4 Translate error codes and store them as attributes of the form
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 74
diff changeset
21 errors: null,
4a82e28dfcc4 Translate error codes and store them as attributes of the form
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 74
diff changeset
22 warnings: null,
4a82e28dfcc4 Translate error codes and store them as attributes of the form
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 74
diff changeset
23 message: null,
87
ee1d1305dcff Added field for netzbetreiber. Is needed because of FK constraints.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 85
diff changeset
24 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
25
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
26 initComponent: function() {
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 this.callParent();
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 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
31
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
32 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
33
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
34 //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
35 if (this.modelId) {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
36
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
37 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
38 failure: this.onModelLoadFailure,
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
39 success: this.onModelLoadSuccess,
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
40 scope: this
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
41 });
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
42
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
43 //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
44 } else {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
45 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
46 }
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
47
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
48 } else {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
49
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
50 //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
51 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
52
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
53 }
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.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
56 },
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
57
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
58 bindModel: function(model) {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
59 this.model = model;
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
60 this.loadRecord(model);
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
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
63 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
64 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
65 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
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
67 this.model.save({
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
68 callback: function(records, operation) {
83
8525e3525538 Move parsing the response in a seperate function.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 75
diff changeset
69 this.parseResponse(operation);
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
70 if (operation.wasSuccessful()) {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
71 console.log('Save was successfull');
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
72 this.fireEvent('savesuccess', this, records, operation);
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
73 } else {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
74 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
75 this.form.markInvalid(this.errors);
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
76 this.fireEvent('savefailure', this, records, operation);
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
77 }
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
78 if (callback) {
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
79 callback.call(scope || this, this, operation.wasSuccessful(), this.model);
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 scope: this
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 },
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 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
88 this.bindModel(record);
83
8525e3525538 Move parsing the response in a seperate function.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 75
diff changeset
89 this.parseResponse(operation);
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
90 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
91 },
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
92
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
93 onModelLoadFailure: function(record, operation) {
83
8525e3525538 Move parsing the response in a seperate function.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 75
diff changeset
94 this.parseResponse(operation);
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
95 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
96 },
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
97
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
98 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
99 var translated = {};
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
100 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
101 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
102 }
5c58c0e8936b Add function which translates the errorcodes returned from the server.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 66
diff changeset
103 return translated;
83
8525e3525538 Move parsing the response in a seperate function.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 75
diff changeset
104 },
85
079f99229eff Added function to mark the form as readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 84
diff changeset
105 setReadOnly: function (bReadOnly) {
079f99229eff Added function to mark the form as readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 84
diff changeset
106 this.getForm().getFields().each (function (field) {
079f99229eff Added function to mark the form as readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 84
diff changeset
107 //field.setDisabled(bReadOnly);
079f99229eff Added function to mark the form as readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 84
diff changeset
108 field.setReadOnly(bReadOnly);
079f99229eff Added function to mark the form as readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 84
diff changeset
109 });
079f99229eff Added function to mark the form as readonly.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 84
diff changeset
110 },
83
8525e3525538 Move parsing the response in a seperate function.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 75
diff changeset
111 parseResponse: function(operation) {
8525e3525538 Move parsing the response in a seperate function.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 75
diff changeset
112 this.errors = this.translateReturnCodes(operation.request.scope.reader.jsonData["errors"]);
8525e3525538 Move parsing the response in a seperate function.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 75
diff changeset
113 this.warnings = this.translateReturnCodes(operation.request.scope.reader.jsonData["warnings"]);
8525e3525538 Move parsing the response in a seperate function.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 75
diff changeset
114 this.message = Lada.getApplication().bundle.getMsg(operation.request.scope.reader.jsonData["message"]);
87
ee1d1305dcff Added field for netzbetreiber. Is needed because of FK constraints.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 85
diff changeset
115 //this.setReadOnly(true);
66
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
116 }
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
117
fcb63271d1bd Created custom Form element which is bound to the model
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
118 });

http://lada.wald.intevation.org