1 (edited by carlosaraujo46 2015-01-10 5:30:42 AM)

Topic: "confirmCommands(p1, p2)" from xajax & "confirm(p)" from javascrpt

You don't have or the same logic and/or functionality of the "confirmCommands(p1, p2)" xajax the "confirm(p)" from javascript?

2 (edited by carlosaraujo46 2015-01-10 5:26:44 AM)

Re: "confirmCommands(p1, p2)" from xajax & "confirm(p)" from javascrpt

Greetings, I have the following function in xajax version 0.5:

function archExiste($camino){
   if (file_exists("$camino")){
       $salida = 1;
       // Se instancia el objeto para generar la respuesta con xajax:
       $respuesta = new xajaxResponse();
       if ($respuesta->confirmCommands(1, "Warning: \nYou. already have an SCO with the name and type given here previously. \nPress \"OK\" to remove assets that currently make up the SCO or \"Cancel\" to change the name and/or type.")){
         if ($respuesta->confirmCommands(1, "Warning: \nThis will permanently delete assets that currently make up the SCO \nPress \"OK\" to confirm or \"Cancel\" for safekeeping.")){
           // Remove directory and all its contents recursively:
           eliminarDir($camino);
         }
         $respuesta->script("document.definirSCO.submit();");
       }
   }else{
       $salida = 0;
       // Se instancia el objeto para generar la respuesta con xajax:
       $respuesta = new xajaxResponse();
   }
   $respuesta->script("document.definirSCO.respuesta.value=\"$salida\";");
   $respuesta->script("alert(document.definirSCO.respuesta.value);");
   // Se devuelve la instanciación del objeto xajaxResponse
   return $respuesta;
}

This function is called from an event of a form element and runs. The problem I've noticed is that the "confirmCommands(p1, p2)" does not work in the same way that the "confirm(p)" javascript. In this case, you are not running me the statements enclosed in blocks demarcated for each "if confirmCommands(p1, p2)" but those instructions executed in a way that does not respect those blocks. For example, in the first "if confirmCommands(p1, p2)" if the user clicks the cancel button should not execute the instruction "$ response->script(" document.definirSCO.submit (); ");" and running (and what you should do is returned to the page -Note: the form element from where I'm calling the function is not <input type = "submit" ..> is type "button").
My question is: is or is not the same logic and / or functionality of the "confirmCommands(p1, p2)" xajax the "confirm(p)" from javascript? and if not: What should I do to make "confirmCommands(p1, p2)" xajax behave similar to "confirm(p)" from javascript?
Thanks in advance.

Re: "confirmCommands(p1, p2)" from xajax & "confirm(p)" from javascrpt

Hi Carlos,

I have not found a way to make confirmCommands() act like the js confirm() function.

Here's my solution:

<?php
/*
    xajax response confirm example.
*/
include_once("xajax/xajax_core/xajax.inc.php");
$xajax = new xajax();
$xajax->configure('javascript URI', 'xajax/');

//Called from the response to the confirm box
function continue_on($status)
{
    $resp = new xajaxResponse();
    
    if ($status==true)
        $resp->alert('You OK\'ed');
    elseif ($status==false)
        $resp->alert('You Cancelled');
    return $resp;
}

//Calls a js function that generates a confirm 
//dialog and sends the result to continue_on() above.
function ask()
{
    $resp = new xajaxResponse();    
    $resp->script("askUser('Continue?')");
    return $resp;
}

$xajax->register(XAJAX_FUNCTION, 'continue_on');
$xajax->register(XAJAX_FUNCTION, 'ask');
$xajax->processRequest();
?>
<!DOCTYPE html>
<html>
<head>
<title>Xajax Comfirm Test</title>
<?php $xajax->printJavascript(); ?>

<script>
//Do a confirm with the prompt 
//passed and send the result back to
//the server page.
function askUser(prompt)
{
    res = confirm(prompt);
    xajax_continue_on(res);
}
</script>

</head>
<body>
<input type="button" value="Call for Confirm" onclick="xajax_ask()"/><br>
</body>
</html>

You could make the ask function accept a prompt and send it.

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: "confirmCommands(p1, p2)" from xajax & "confirm(p)" from javascrpt

The simplest solution I've found in:
http: // http: //www.prettyscripts.com/ajax/xajax/xajax-confirmation-message

I thank "edrobinson" (Manager) by the proposed solution.