Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Attach event parameters to functions like ShowConfirm
#1
Sometimes I use WebApplication.ShowConfirm() to get a confirmation from the user. For example the user wants to delete a record from a grid and clicks on a icon to delete a row. The row index is sent to the server where additional information is gathered based on the row index. A message is crafted to display to the user and ask for a confirmation. For this step ShowConfirm(msg, callback, etc) is used. Can I pass additional event parameters to this callback? Now I keep state information in the object serverside but I would like to pass these parameters from the browser to the callback if possible.
Reply
#2
Hi Jeroen,

It should be possible with some minor modification and/or custom code. Unfortunately, the word "callback" in IntraWeb is used for multiple different concepts and sometimes it is not clear what you want to achieve.

First, let's make things clear about what is what regarding callbacks:

- We have a JavaScript callback (some code that is called when the user closes the dialog)
- and we have the Server callback method (some registered method in the server which is called via AJAX)

Also, just to have a better understanding of the requirement, there are 2 ways of using a callback when dealing with WebApplication.ShowConfirm():

1) The callback parameter refers to some custom JavaScript function. This function may or may not call the server again, etc. Basically you can do whatever you want with it.
2) The callback parameter refers to a Server callback method. In this case, this method will be called via AJAX when the user closes the dialog.

From your description seems that you want to pass some custom data from your own JS code to the server, as a parameter when (2) is being called. Is that so?
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)