Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Attach event parameters to functions like ShowConfirm
#3
Hi Alexandre,

Not sure... I think it's situation 2. I'll let my code tell the situation.

Code:
procedure TDlgAfboekingen.RegisterCallbacks;
begin
  inherited;
  WebApplication.RegisterCallBack('DeleteRestantCallback', DeleteRestantCallback);
end;

// 1. Called after user clicks [delete] button in bootstrap grid row
procedure TDlgAfboekingen.dbGridCustomAsyncEvents1AsyncEvent(Sender: TObject; EventParams: TStringList);
var
  PerceelIndex: string;
begin
  // add tag as callback data
  PerceelIndex := EventParams.Values['row'];
 
  // <snip> some processing based on PerceelIndex
 
  // here I store information that will be retrieved from DeleteRestantCallback()
  // CallbackData is a property of TDlgAfboekingen. I would prefer to pass this information
  // to DeleteRestantCallback by using event parameters similar to DeleteRestantCallback?PerceelIndex=1
  CallbackData.AddPair('PerceelIndex', PerceelIndex);

  // show question. result will be handled by callback asynchronous
  WebApplication.ShowConfirm(
    _('Some question?'),
    'DeleteRestantCallback',
    '',
    _('Yes'),
    _('No'));
end;

// 2. Called after user closes confirmation dialog
procedure TDlgAfboekingen.DeleteRestantCallback(EventParams: TStringList);
var
  PerceelIndex: integer;
  Perceel: TPerceel;
  OK: boolean;
  js: string;
begin
  // Confirm callback has 1 main parameters:
  // RetValue (Boolean), indicates if the first button (Yes/OK/custom) was choosen
  OK := SameText(EventParams.Values['RetValue'], 'True');
  if OK
  then begin
    PerceelIndex := StrToIntDef(CallbackData.Values['PerceelIndex'], -1);

    // <snip> process detele action

    // refresh table on webpage
    js := '$(''#DBGRID'').bootstrapTable(''refresh'', {silent: true});';
    WebApplication.CallBackResponse.AddJavaScriptToExecuteAsCDATA(js);
  end;

  // remove all callback data
  CallbackData.Clear;
end;
Reply


Messages In This Thread
RE: Attach event parameters to functions like ShowConfirm - by jeroen.rottink - 11-24-2020, 10:02 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)