-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDW.VCL.InputForm.pas
293 lines (248 loc) · 7.78 KB
/
DW.VCL.InputForm.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
unit DW.VCL.InputForm;
interface
uses
Classes, System.SysUtils, VCL.Controls, DW.VCL.CustomRegion, DWElementTag, DWTypes,
DW.VCL.Common;
type
TDWFormOptions = class(TPersistent)
private
FCaptionsSize: TDWGridOptions;
FInputsSize: TDWGridOptions;
protected
procedure SetCaptionsSize(const Value: TDWGridOptions);
procedure SetInputsSize(const Value: TDWGridOptions);
public
constructor Create(AOwner: TControl);
destructor Destroy; override;
function GetOffsetClassString: string;
procedure Assign(Source: TPersistent); override;
published
property CaptionsSize: TDWGridOptions read FCaptionsSize write SetCaptionsSize;
property InputsSize: TDWGridOptions read FInputsSize write SetInputsSize;
end;
TDWCustomInputForm = class(TDWCustomRegion)
private
FValidationEnabled: Boolean;
protected
procedure SetValidationEnabled(const Value: Boolean);
function Hasvalidator: Boolean;
function RenderHTML: TDWElementTag; override;
procedure InternalRenderScript(Const AHTMLName: string; AScript: TStringList); override;
public
constructor Create(AOwner: TComponent); override;
published
// For enable/disable Validations on this form
property ValidationEnabled: Boolean read FValidationEnabled write SetValidationEnabled
default True;
end;
TDWInputForm = class(TDWCustomInputForm)
private
FEncType: TDWFormEncType;
FFormType: TDWFormType;
FFormOptions: TDWFormOptions;
FOnSubmit: TDWInputFormSubmitEvent;
procedure DoSubmit(aParams: TStringList);
procedure SetEncType(const Value: TDWFormEncType);
procedure SetFormType(const Value: TDWFormType);
protected
procedure InternalRenderCss(var ACss: string); override;
function RenderHTML: TDWElementTag; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function GetRoleString: string; override;
published
property BSFormType: TDWFormType read FFormType write SetFormType default bsftVertical;
property BSFormOptions: TDWFormOptions read FFormOptions write FFormOptions;
property EncType: TDWFormEncType read FEncType write SetEncType default bsfeDefault;
property OnSubmit: TDWInputFormSubmitEvent read FOnSubmit write FOnSubmit;
end;
TDWInputGroup = class(TDWCustomRegion)
private
FCaption: string;
FRelativeSize: TDWRelativeSize;
procedure SetCaption(const Value: string);
procedure SetRelativeSize(const Value: TDWRelativeSize);
protected
procedure InternalRenderCss(var ACss: string); override;
public
constructor Create(AOwner: TComponent); override;
function RenderHTML: TDWElementTag; override;
published
property Caption: string read FCaption write SetCaption;
property BSRelativeSize: TDWRelativeSize read FRelativeSize write SetRelativeSize
default bsrzDefault;
property Visible;
end;
TDWFormControl = class(TDWCustomRegion)
private
FCaption: string;
procedure SetCaption(const Value: string);
public
function RenderHTML: TDWElementTag; override;
published
property Caption: string read FCaption write SetCaption;
end;
implementation
uses
DWUtils, DW.VCL.NavBar;
{ TDWCustomInputForm }
constructor TDWCustomInputForm.Create(AOwner: TComponent);
begin
inherited;
FTagName := 'form';
FValidationEnabled := True;
end;
function TDWCustomInputForm.Hasvalidator: Boolean;
begin
raise Exception.Create('Need to implement TDWCustomInputForm.Hasvalidator');
end;
procedure TDWCustomInputForm.InternalRenderScript(const AHTMLName: string; AScript: TStringList);
begin
inherited;
end;
function TDWCustomInputForm.RenderHTML: TDWElementTag;
begin
Result := inherited;
end;
procedure TDWCustomInputForm.SetValidationEnabled(const Value: Boolean);
begin
FValidationEnabled := Value;
end;
{ TDWFormOptions }
procedure TDWFormOptions.Assign(Source: TPersistent);
begin
if Source is TDWFormOptions then
begin
CaptionsSize.Assign(TDWFormOptions(Source).CaptionsSize);
InputsSize.Assign(TDWFormOptions(Source).InputsSize);
end
else
inherited;
end;
constructor TDWFormOptions.Create(AOwner: TControl);
begin
FCaptionsSize := TDWGridOptions.Create(AOwner);
FInputsSize := TDWGridOptions.Create(AOwner);
end;
destructor TDWFormOptions.Destroy;
begin
FreeAndNil(FCaptionsSize);
FreeAndNil(FInputsSize);
inherited;
end;
function TDWFormOptions.GetOffsetClassString: string;
begin
Result := FInputsSize.GetClassString(FCaptionsSize.GridXSOffset + FCaptionsSize.GridXSSpan,
FCaptionsSize.GridSMOffset + FCaptionsSize.GridSMSpan, FCaptionsSize.GridMDOffset +
FCaptionsSize.GridMDSpan, FCaptionsSize.GridLGOffset + FCaptionsSize.GridLGSpan);
end;
procedure TDWFormOptions.SetCaptionsSize(const Value: TDWGridOptions);
begin
FCaptionsSize.Assign(Value);
end;
procedure TDWFormOptions.SetInputsSize(const Value: TDWGridOptions);
begin
FInputsSize.Assign(Value);
end;
{ TDWInputForm }
constructor TDWInputForm.Create(AOwner: TComponent);
begin
inherited;
end;
destructor TDWInputForm.Destroy;
begin
inherited;
end;
procedure TDWInputForm.DoSubmit(aParams: TStringList);
begin
if Assigned(FOnSubmit) then
FOnSubmit(aParams);
raise Exception.Create('Need to implement SendRedirect in TDWInputForm.DoSubmit');
// aReply.SendRedirect(aApplication.SessionInternalUrlBase);
end;
function TDWInputForm.GetRoleString: string;
begin
end;
procedure TDWInputForm.InternalRenderCss(var ACss: string);
begin
if FFormType = bsftInline then
TDWBSCommon.AddCssClass(ACss, 'form-inline')
else if FFormType = bsftHorizontal then
TDWBSCommon.AddCssClass(ACss, 'form-horizontal');
if (Parent is TDWNavBarBase) then
TDWBSCommon.AddCssClass(ACss, 'navbar-form');
inherited;
end;
function TDWInputForm.RenderHTML: TDWElementTag;
var
LParentForm: TDWInputForm;
begin
LParentForm := DWFindParentInputForm(Parent);
if LParentForm <> nil then
raise Exception.Create('forms can not be nested, you try to put ' + Name + ' inside ' +
LParentForm.Name);
Result := inherited;
if Assigned(FOnSubmit) then
begin
Result.AddStringParam('method', 'post');
if FEncType = bsfeMultipart then
Result.AddStringParam('enctype', 'multipart/form-data')
else if FEncType = bsfeText then
Result.AddStringParam('enctype', 'text/plain');
Result.AddStringParam('action', DWApplication.RegisterCallBack(Self, ae_submit, DoSubmit));
end
else
{ TODO 1 -oDELCIO -cIMPLEMENT : FormDefaultSubmit() }
Result.AddStringParam('onSubmit', 'return FormDefaultSubmit();');
end;
procedure TDWInputForm.SetEncType(const Value: TDWFormEncType);
begin
FEncType := Value;
Invalidate;
end;
procedure TDWInputForm.SetFormType(const Value: TDWFormType);
begin
FFormType := Value;
Invalidate;
end;
{ TDWInputGroup }
constructor TDWInputGroup.Create(AOwner: TComponent);
begin
inherited;
FRelativeSize := bsrzDefault;
end;
procedure TDWInputGroup.InternalRenderCss(var ACss: string);
begin
TDWBSCommon.AddCssClass(ACss, 'input-group');
if FRelativeSize <> bsrzDefault then
TDWBSCommon.AddCssClass(ACss, 'input-group-' + aDWRelativeSize[FRelativeSize]);
inherited;
end;
function TDWInputGroup.RenderHTML: TDWElementTag;
begin
Result := inherited;
Result := DWCreateInputFormGroup(Self, Parent, Result, FCaption, HTMLName);
end;
procedure TDWInputGroup.SetCaption(const Value: string);
begin
FCaption := Value;
Invalidate;
end;
procedure TDWInputGroup.SetRelativeSize(const Value: TDWRelativeSize);
begin
FRelativeSize := Value;
Invalidate;
end;
{ TDWFormControl }
function TDWFormControl.RenderHTML: TDWElementTag;
begin
Result := Inherited;
Result := DWCreateInputFormGroup(Self, Parent, Result, FCaption, HTMLName);
end;
procedure TDWFormControl.SetCaption(const Value: string);
begin
FCaption := Value;
Invalidate;
end;
end.