-
Notifications
You must be signed in to change notification settings - Fork 10
/
DW.XHR.CallBackResp.pas
98 lines (83 loc) · 2.75 KB
/
DW.XHR.CallBackResp.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
unit DW.XHR.CallBackResp;
interface
uses Classes, DWElementTag;
type
TDWXhrCallbackResp = class
FDWApplication: TObject;
FExecuteFirstTag: TDWElementXHTMLTag;
FUpdateTag: TDWElementXHTMLTag;
FExecuteTag: TDWElementXHTMLTag;
public
constructor Create(aDWApplication: TObject);
destructor Destroy; override;
procedure Clear;
function Render: string;
procedure AddScriptToExecute(aScript: string; AsCDATA: Boolean = True);
procedure AddScriptToUpdate(aScript: string; AsCDATA: Boolean = True);
procedure AddScriptToExecuteFirst(aScript: string; AsCDATA: Boolean = True);
end;
implementation
uses DW.CORE.DWApplication, DWUtils;
{ TDWXhrCallbackResp }
procedure TDWXhrCallbackResp.AddScriptToExecute(aScript: string; AsCDATA: Boolean);
var
LTag: TDWElementXHTMLTag;
begin
if not DWApplication.IsCallBack then
Exit;
LTag := TDWElementXHTMLTag.CreateHTMLTag('item', FExecuteTag, AsCDATA);
LTag.Contents.AddText(aScript);
FExecuteTag.Contents.AddElemetAsObject(LTag, True);
end;
procedure TDWXhrCallbackResp.AddScriptToExecuteFirst(aScript: string; AsCDATA: Boolean);
var
LTag: TDWElementXHTMLTag;
begin
if not DWApplication.IsCallBack then
Exit;
LTag := TDWElementXHTMLTag.CreateHTMLTag('item', FExecuteFirstTag, AsCDATA);
LTag.Contents.AddText(aScript);
FExecuteFirstTag.Contents.AddElemetAsObject(LTag, True);
end;
procedure TDWXhrCallbackResp.AddScriptToUpdate(aScript: string; AsCDATA: Boolean);
var
LTag: TDWElementXHTMLTag;
begin
if not DWApplication.IsCallBack then
Exit;
LTag := TDWElementXHTMLTag.CreateHTMLTag('item', FUpdateTag, AsCDATA);
LTag.Contents.AddText(aScript);
FUpdateTag.Contents.AddElemetAsObject(LTag, True);
end;
procedure TDWXhrCallbackResp.Clear;
begin
FExecuteFirstTag.Clear;
FUpdateTag.Clear;
FExecuteTag.Clear;
end;
constructor TDWXhrCallbackResp.Create(aDWApplication: TObject);
begin
inherited Create;
FDWApplication := aDWApplication;
FExecuteFirstTag := TDWElementXHTMLTag.CreateHTMLTag('executefirst', nil, False);
FUpdateTag := TDWElementXHTMLTag.CreateHTMLTag('update', nil, False);
FExecuteTag := TDWElementXHTMLTag.CreateHTMLTag('execute', nil, False);
end;
destructor TDWXhrCallbackResp.Destroy;
begin
FExecuteFirstTag.Free;
FUpdateTag.Free;
FExecuteTag.Free;
inherited;
end;
function TDWXhrCallbackResp.Render: string;
begin
{ TODO 1 -oDELCIO -cVERIFY : check if Windows-1252 cause problems. I'm used this to avoid UTF8 encode(speed) }
Result := '<?xml version="1.0" encoding="Windows-1252" standalone="yes"?><response>';
Result := Result + FExecuteFirstTag.Render;
Result := Result + FUpdateTag.Render;
Result := Result + FExecuteTag.Render;
Result := Result + '</response>';
// Result:= UTF8Encode(Result);
end;
end.