summaryrefslogtreecommitdiff
path: root/packages/fcl-web/examples/webdata
diff options
context:
space:
mode:
Diffstat (limited to 'packages/fcl-web/examples/webdata')
-rw-r--r--packages/fcl-web/examples/webdata/demo/wmusers.pp81
1 files changed, 25 insertions, 56 deletions
diff --git a/packages/fcl-web/examples/webdata/demo/wmusers.pp b/packages/fcl-web/examples/webdata/demo/wmusers.pp
index 468bc27d23..72aff3fb6e 100644
--- a/packages/fcl-web/examples/webdata/demo/wmusers.pp
+++ b/packages/fcl-web/examples/webdata/demo/wmusers.pp
@@ -24,6 +24,7 @@ type
AResponse: TResponse; var Handled: Boolean);
private
{ private declarations }
+ procedure GetAdaptorAndFormatter(P : TFPWebDataProvider; Var F :TExtJSDataFormatter; ARequest : TRequest; AResponse : TResponse);
public
{ public declarations }
end;
@@ -55,6 +56,26 @@ begin
end;
end;
+procedure TFPWebModule1.GetAdaptorAndFormatter(P : TFPWebDataProvider; Var F :TExtJSDataFormatter; ARequest : TRequest; AResponse : TResponse);
+
+begin
+ If Request.QueryFields.values['format']='xml' then
+ begin
+ F:=TExtJSXMLDataFormatter.Create(Self);
+ TExtJSXMLDataFormatter(F).TotalProperty:='total';
+ AResponse.ContentType:='text/xml';
+ P.Adaptor:=TExtJSXMLWebdataInputAdaptor.Create(Nil);
+ end
+ else
+ begin
+ P.Adaptor:=TExtJSJSonWebdataInputAdaptor.Create(Nil);
+ F:=TExtJSJSONDataFormatter.Create(Self);
+ end;
+ P.Adaptor.Request:=ARequest;
+ F.Adaptor:=P.Adaptor;
+ F.Provider:=P;
+end;
+
procedure TFPWebModule1.TFPWebActions0Request(Sender: TObject;
ARequest: TRequest; AResponse: TResponse; var Handled: Boolean);
@@ -69,19 +90,9 @@ Var
begin
// Providername;
PN:=ARequest.GetNextPathInfo;
-// P:=GetWebDataProvider(PN);
P:=TFPWebDataProvider.Create(Self);
try
- P.Adaptor:=TWebDataInputAdaptor.Create(Self);
- P.Adaptor.Request:=ARequest;
- If Request.QueryFields.values['format']='xml' then
- begin
- F:=TExtJSXMLDataFormatter.Create(Self);
- TExtJSXMLDataFormatter(F).TotalProperty:='total';
- AResponse.ContentType:='text/xml';
- end
- else
- F:=TExtJSJSONDataFormatter.Create(Self);
+ GetAdaptorAndFormatter(P,F,ARequest,AResponse);
{$ifdef wmdebug} SendDebug(className+' '+F.ClassName);{$endif}
try
DS:=TDatasource.Create(Self);
@@ -90,11 +101,9 @@ begin
DS.Dataset:=DBf1;
DBF1.Open;
try
- F.ADaptor:=P.Adaptor;
P.Datasource:=DS;
P.Adaptor.Action:=wdaRead;
P.ApplyParams;
- F.Provider:=P;
M:=TMemoryStream.Create;
try
F.GetContent(ARequest,M,Handled);
@@ -137,18 +146,7 @@ begin
P:=TFPWebDataProvider.Create(Self);
try
P.IDFieldName:='ID';
- If Request.QueryFields.values['format']='xml' then
- begin
- F:=TExtJSXMLDataFormatter.Create(Self);
- AResponse.ContentType:='text/xml';
- P.Adaptor:=TWebDataInputAdaptor.Create(Self);
- end
- else
- begin
- F:=TExtJSJSONDataFormatter.Create(Self);
- P.Adaptor:=TExtJSJSonWebdataInputAdaptor.Create(Self);
- end;
- P.Adaptor.Request:=ARequest;
+ GetAdaptorAndFormatter(P,F,ARequest,AResponse);
{$ifdef wmdebug} SendDebug(className+' '+F.ClassName);{$endif}
try
DS:=TDatasource.Create(Self);
@@ -157,11 +155,9 @@ begin
DS.Dataset:=DBf1;
DBF1.Open;
try
- F.ADaptor:=P.Adaptor;
P.Datasource:=DS;
P.Adaptor.Action:=wdaInsert;
P.ApplyParams;
- F.Provider:=P;
M:=TMemoryStream.Create;
try
F.GetContent(ARequest,M,Handled);
@@ -205,19 +201,7 @@ begin
P:=TFPWebDataProvider.Create(Self);
try
P.IDFieldName:='ID';
- If Request.QueryFields.values['format']='xml' then
- begin
- {$ifdef wmdebug} SendDebug('Update request received in XML');{$endif}
- F:=TExtJSXMLDataFormatter.Create(Self);
- AResponse.ContentType:='text/xml';
- P.Adaptor:=TWebDataInputAdaptor.Create(Self);
- end
- else
- begin
- F:=TExtJSJSONDataFormatter.Create(Self);
- P.Adaptor:=TExtJSJSonWebdataInputAdaptor.Create(Self);
- end;
- P.Adaptor.Request:=ARequest;
+ GetAdaptorAndFormatter(P,F,ARequest,AResponse);
{$ifdef wmdebug} SendDebug(className+' '+F.ClassName);{$endif}
try
DS:=TDatasource.Create(Self);
@@ -226,11 +210,9 @@ begin
DS.Dataset:=DBf1;
DBF1.Open;
try
- F.ADaptor:=P.Adaptor;
P.Datasource:=DS;
P.Adaptor.Action:=wdaUpdate;
P.ApplyParams;
- F.Provider:=P;
M:=TMemoryStream.Create;
try
F.GetContent(ARequest,M,Handled);
@@ -274,18 +256,7 @@ begin
P:=TFPWebDataProvider.Create(Self);
try
P.IDFieldName:='ID';
- If Request.QueryFields.values['format']='xml' then
- begin
- F:=TExtJSXMLDataFormatter.Create(Self);
- AResponse.ContentType:='text/xml';
- P.Adaptor:=TWebDataInputAdaptor.Create(Self);
- end
- else
- begin
- F:=TExtJSJSONDataFormatter.Create(Self);
- P.Adaptor:=TExtJSJSonWebdataInputAdaptor.Create(Self);
- end;
- P.Adaptor.Request:=ARequest;
+ GetAdaptorAndFormatter(P,F,ARequest,AResponse);
{$ifdef wmdebug} SendDebug('className '+F.ClassName);{$endif}
try
DS:=TDatasource.Create(Self);
@@ -294,11 +265,9 @@ begin
DS.Dataset:=DBf1;
DBF1.Open;
try
- F.ADaptor:=P.Adaptor;
P.Datasource:=DS;
P.Adaptor.Action:=wdaDelete;
P.ApplyParams;
- F.Provider:=P;
M:=TMemoryStream.Create;
try
F.GetContent(ARequest,M,Handled);