mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 11:09:19 +02:00
* After insert/update/delete events
git-svn-id: trunk@15920 -
This commit is contained in:
parent
0dfd6f6675
commit
f2c8b59643
@ -31,12 +31,15 @@ type
|
|||||||
TExtJSJSONDataFormatter = Class(TExtJSDataFormatter)
|
TExtJSJSONDataFormatter = Class(TExtJSDataFormatter)
|
||||||
private
|
private
|
||||||
FAfterDataToJSON: TJSONObjectEvent;
|
FAfterDataToJSON: TJSONObjectEvent;
|
||||||
|
FAfterDelete: TJSONObjectEvent;
|
||||||
|
FAfterInsert: TJSONObjectEvent;
|
||||||
FAfterRowToJSON: TJSONObjectEvent;
|
FAfterRowToJSON: TJSONObjectEvent;
|
||||||
|
FAfterUpdate: TJSONObjectEvent;
|
||||||
FBeforeDataToJSON: TJSONObjectEvent;
|
FBeforeDataToJSON: TJSONObjectEvent;
|
||||||
FBeforeRowToJSON: TJSONObjectEvent;
|
FBeforeRowToJSON: TJSONObjectEvent;
|
||||||
FOnErrorResponse: TJSONExceptionObjectEvent;
|
FOnErrorResponse: TJSONExceptionObjectEvent;
|
||||||
FOnMetaDataToJSON: TJSONObjectEvent;
|
FOnMetaDataToJSON: TJSONObjectEvent;
|
||||||
procedure SendSuccess(ResponseContent: TStream; AddIDValue : Boolean = False);
|
procedure SendSuccess(ResponseContent: TStream; AddIDValue : Boolean = False; CallBack : TJSONObjectEvent = Nil);
|
||||||
protected
|
protected
|
||||||
Function CreateAdaptor(ARequest : TRequest) : TCustomWebdataInputAdaptor; override;
|
Function CreateAdaptor(ARequest : TRequest) : TCustomWebdataInputAdaptor; override;
|
||||||
Function AddFieldToJSON(O: TJSONObject; AFieldName: String; F: TField): TJSONData;
|
Function AddFieldToJSON(O: TJSONObject; AFieldName: String; F: TField): TJSONData;
|
||||||
@ -66,6 +69,12 @@ type
|
|||||||
Property BeforeDataToJSON : TJSONObjectEvent Read FBeforeDataToJSON Write FBeforeDataToJSON;
|
Property BeforeDataToJSON : TJSONObjectEvent Read FBeforeDataToJSON Write FBeforeDataToJSON;
|
||||||
// Called when an exception is caught and formatted.
|
// Called when an exception is caught and formatted.
|
||||||
Property OnErrorResponse : TJSONExceptionObjectEvent Read FOnErrorResponse Write FOnErrorResponse;
|
Property OnErrorResponse : TJSONExceptionObjectEvent Read FOnErrorResponse Write FOnErrorResponse;
|
||||||
|
// After a record was succesfully updated
|
||||||
|
Property AfterUpdate : TJSONObjectEvent Read FAfterUpdate Write FAfterUpdate;
|
||||||
|
// After a record was succesfully inserted.
|
||||||
|
Property AfterInsert : TJSONObjectEvent Read FAfterInsert Write FAfterInsert;
|
||||||
|
// After a record was succesfully inserted.
|
||||||
|
Property AfterDelete : TJSONObjectEvent Read FAfterDelete Write FAfterDelete;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -368,7 +377,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TExtJSJSONDataFormatter.SendSuccess(ResponseContent: TStream; AddIDValue : Boolean = False);
|
procedure TExtJSJSONDataFormatter.SendSuccess(ResponseContent: TStream; AddIDValue : Boolean = False; CallBack : TJSONObjectEvent = Nil);
|
||||||
|
|
||||||
Var
|
Var
|
||||||
Resp : TJSonObject;
|
Resp : TJSonObject;
|
||||||
@ -379,6 +388,8 @@ begin
|
|||||||
Resp:=TJsonObject.Create;
|
Resp:=TJsonObject.Create;
|
||||||
Resp.Add(SuccessProperty,True);
|
Resp.Add(SuccessProperty,True);
|
||||||
Resp.Add(Provider.IDFieldName,Provider.IDFieldValue);
|
Resp.Add(Provider.IDFieldName,Provider.IDFieldValue);
|
||||||
|
If Assigned(CallBack) then
|
||||||
|
CallBack(Self,Resp);
|
||||||
L:=Resp.AsJSON;
|
L:=Resp.AsJSON;
|
||||||
ResponseContent.WriteBuffer(L[1],Length(L));
|
ResponseContent.WriteBuffer(L[1],Length(L));
|
||||||
finally
|
finally
|
||||||
@ -390,19 +401,19 @@ procedure TExtJSJSONDataFormatter.DoInsertRecord(ResponseContent: TStream);
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
Inherited;
|
Inherited;
|
||||||
SendSuccess(ResponseContent,True);
|
SendSuccess(ResponseContent,True,FAfterInsert);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TExtJSJSONDataFormatter.DoUpdateRecord(ResponseContent: TStream);
|
procedure TExtJSJSONDataFormatter.DoUpdateRecord(ResponseContent: TStream);
|
||||||
begin
|
begin
|
||||||
inherited DoUpdateRecord(ResponseContent);
|
inherited DoUpdateRecord(ResponseContent);
|
||||||
SendSuccess(ResponseContent,False);
|
SendSuccess(ResponseContent,False,FAfterUpdate);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TExtJSJSONDataFormatter.DoDeleteRecord(ResponseContent: TStream);
|
procedure TExtJSJSONDataFormatter.DoDeleteRecord(ResponseContent: TStream);
|
||||||
begin
|
begin
|
||||||
inherited DoDeleteRecord(ResponseContent);
|
inherited DoDeleteRecord(ResponseContent);
|
||||||
SendSuccess(ResponseContent,False);
|
SendSuccess(ResponseContent,False,FAfterDelete);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TExtJSJSonWebdataInputAdaptor }
|
{ TExtJSJSonWebdataInputAdaptor }
|
||||||
|
Loading…
Reference in New Issue
Block a user