Logout dialog problem (web client)

I’ve wanted to add a dialog which confirms the user’s desire to log out of the application.

We’ve invented our own dialog mechanism because the built-in dialog plug-in doesn’t work for web client. Our mechanism works great for prompting the user for all sorts of things but I’m having trouble adapting it to work for the log out.

When a user clicks on the ‘Log Out’ button a call is made to a method called ‘logoutPreCheck()’
The logoutPreCheck() method invokes a method in the dialog form and passes the message and buttons to display and the method to run when any of the buttons are pressed.
In this case the message is ‘Are you sure you wish to log out’ and the buttons are ‘Yes’ and ‘No’. The method to run is called ‘logout()’ - the method is not part of the dialog form.
The method in the dialog form sets up the message and buttons then displays itself as modal.

When the user presses the ‘Yes’ button I want to close down the application and take the user to a different URL.

The problem is that my dialog form won’t go away and the URL gets displayed inside the dialog form.

Here’s some code snippets to help understand the mechanics of the dialog…

This is some code from my main application form…

function logoutPreCheck()
{
  var lv_msg = 'Are you sure you wish to log out?';
  forms.graphics_template_dialog.setup_dialog('logout','Logout',lv_msg,'Yes','No');
}

function logout()
{
  // check the return from the dialog
  var button_pushed = arguments[0];

  // if user pressed 'Yes' then go ahead and logout 
  if ( button_pushed == 1 )
  { 
    application.showURL('http://www.kelman.com','_self');
    security.logout();
  }

}

Here’s some code snippets from the dialog form.
Note, when a button on the dialog form gets pressed the method ‘setup_return_code()’ is called.
Please pardon some of the sloppy coding :shock: I promise to clean it up :wink:

function setup_dialog()
{
  /*
   * remember which form called us and which method to invoke on that form when we are done
   * setup the window title, message and buttons then show the dialog
  */
  calling_form = application.getMethodTriggerFormName();
  callback_method = arguments[0];
  var wtitle = arguments[1];
  var wmessage = arguments[2];
  the_window_message = wmessage;

  forms.graphics_template_dialog.elements.btn_1.visible = false;
  forms.graphics_template_dialog.elements.btn_2.visible = false;
  forms.graphics_template_dialog.elements.btn_3.visible = false;
  forms.graphics_template_dialog.elements.btn_4.visible = false;

  var argcount = arguments.length;
  var btnStartPos = 190;
  
  // we have 2 buttons
  if (argcount ==5)
    btnStartPos = 135;

  // we have 3 buttons
  if (argcount ==6)
    btnStartPos = 90;
  
  // we have 4 buttons
  if (argcount ==7)
    btnStartPos = 45;
  
  
  


  for ( var i = 3 ; i < argcount ; i++ )
	{
    if (i==3)
    {
      forms.graphics_template_dialog.elements.btn_1.visible = true;
      forms.graphics_template_dialog.elements.btn_1.text = arguments[i];
      forms.graphics_template_dialog.elements.btn_1.setLocation(btnStartPos,130);
    }
    if (i==4)
    {
      forms.graphics_template_dialog.elements.btn_2.visible = true;
      forms.graphics_template_dialog.elements.btn_2.text = arguments[i];
      forms.graphics_template_dialog.elements.btn_2.setLocation(btnStartPos+90,130);
    }
    if (i==5)
    {
      forms.graphics_template_dialog.elements.btn_3.visible = true;
      forms.graphics_template_dialog.elements.btn_3.text = arguments[i];
      forms.graphics_template_dialog.elements.btn_3.setLocation(btnStartPos+180,130);
    }
    if (i==6)
    {
      forms.graphics_template_dialog.elements.btn_4.visible = true;
      forms.graphics_template_dialog.elements.btn_4.text = arguments[i];
      forms.graphics_template_dialog.elements.btn_4.setLocation(btnStartPos+270,130);
    }
	}

  application.showFormInDialog(this,100,80,460,170,wtitle,false,false,wtitle,true);  
}

function setup_return_code()
{
  /*
   * determine the button that was pressed (format is btn_N  where N is the button number)
   * close the form and invoke the callback method on the form that called this dialog
  */
  var elementName = application.getMethodTriggerElementName();
  var args = elementName.split('_');
  var returncode = args[1];

  application.closeFormDialog(this);
  
  // if we were invoked from globals (i.e. the main form) then call the global handler method
  // that was passed to this form initially
  if ( callback_method.substr(0,8) == 'globals.' )
  {
    eval(callback_method + '(' + returncode + ')' );
  }
  else
  {
    //
    // look for a dot in the 'callback_method' 
    // if one is present it means that the callback_method already has the form name in it
    // this was required for the situation where 'list' forms embedded within 'main' forms make a call
    // to this dialog.  The 'calling_form' is interpreted as the MAIN form and NOT the list form.
    //
    var look4dot = callback_method.indexOf('.',1);
    if ( look4dot > 0 )
    {
      var form_method_call = 'forms.'+callback_method;
    }
    else
    {
      var form_method_call = 'forms.'+calling_form+'.'+callback_method;
    }
    eval(form_method_call + '(' + returncode + ')' );
  }

}

I thought of trying a ‘sleep’ function in my main form which calls the dialog thinking the dialog needed a second to close before the ‘showURL()’ method ran and that doesn’t change anything - nor does calling a ‘closeFormDialog(…)’ from my main form before I call the ‘showURL’ method.

Anyone have any ideas on how I can get my dialog to close properly before calling the showURL() and security.logout() ?

Thanks in advance
Mark

There is a ticket in our system about this problem. We are currently looking for a way to fix it.

Yep, I created it ;)

Hi Nicola, is that your case: 189332: Solution Logout from Dialog in WC ?

I was wrong, that’s not my case, I reported the issue directly to Servoy R&D.