Topic: back button plugin and dynamic pagination

Hello,

today I found the back button plugin here and tried to implement it on my project. There I have e.g. 5 items listed, more items can be accessed via a pagination (< | 1 | 2 | 3 | >). This pagination uses xajax and it would be great to have the ability to bookmark and/or use the back button here.

What I tried: I placed the files dhtmlHistory.inc.php and dhtmlHistory.js in xajax_plugins\response, the blank.html in my doc root.
Then I edited my xajax.functions.php and added the following:

require_once (PATH_XAJAX_CORE     .'xajax.inc.php');
$oXajax = new xajax();
require_once (PATH_XAJAX_PLUGINS .'response/dhtmlHistory.inc.php');
function waypoint_handler($sWaypointName, $sWaypointData) {
    $oResponse = new xajaxResponse();
    if ($sWaypointName!='') {
        $aWaypointData = decodeWaypointData($sWaypointData);


        ob_start();
        echo 'waypointName: ';
        var_dump($sWaypointName);
        echo '<br>waypointData: <pre>';
        var_dump($aWaypointData);
        echo '</pre>';            
        $sContent = ob_get_contents();
        ob_end_clean();
        $oResponse->assign("debug", "innerHTML", "<h1>$sContent</h1>");
    }
    else 
        $oResponse->assign("debug", "innerHTML", "<h1>Back home</h1>");
    
    return $oResponse;
}
$oXajax->register(XAJAX_FUNCTION,'waypoint_handler');
$oXajax->processRequest();
$aMain['XAJAX'] = $oXajax->getJavascript();

I then expanded the function which is called when someone clicks on the pagination links to get the next elements loaded:

function getScenarios ($sAction = '',$sLink = '#',$sID = 'first',$z = 0,$sColumn = PAGENAVI_COLUMN,$sOrder = PAGENAVI_ORDER,$sGet = '') {
        
    global $oPDO,$iUserID,$oAuth,$oSmarty;
    
    $oResponse = new xajaxMyResponse();

    //********************
    $aParams         = array('getScenarios');//,$sAction,$sLink,$sID,$z,$sColumn,$sOrder,$sGet);
    $sWaypointName = 'getScenarios';  // waypoint name
   $aWaypointData = $aParams;  // some sample waypoint data
   // this will add a new waypoint into the backbutton history
   dhtmlHistoryAdd($oResponse, $sWaypointName, $aWaypointData); 
    //********************
    
    [...]
}

Did I miss something? It's not working properly sad and I get the javascript error
this.listener has no properties
{firebug additional output}
fireHistoryEvent("")
checkLocation()
locationHandler()
this.listener.call(null, newHash, historyData);
{/firebug}

I already changed the dhtmlHistory.inc.php to link the js-file instead of including it - with the same result...

Cheers,
Manu

Vegetarier essen meinem Essen das Essen weg.

Re: back button plugin and dynamic pagination

I haven't used this plugin yet, so I can't give you any detailed advice.
I know that this plugin was fixed for 0.5beta3 but I don't know if it's still compatible with the latest beta4b release. Please make sure that you got the latest version: http://code.goldenzazu.de/xajax_backbutton.php and perhaps, try using it with beta3.

Re: back button plugin and dynamic pagination

Hi q_no,

thank you for your advice. I think I'm using 0.5beta3 - where can I verify this?
The xajax.inc.php says @version $Id: xajax.inc.php 362 2007-05-29 15:32:24Z calltoconstruct $

Vegetarier essen meinem Essen das Essen weg.

Re: back button plugin and dynamic pagination

You can find the version info in the readme.txt - @version $Id: xajax.inc.php 362 2007-05-29 15:32:24Z calltoconstruct $ is beta4.

Re: back button plugin and dynamic pagination

Hi Manu,

I just updated the plugin to work with the latest RSH script which also supports Opera and Safari.
The test page also uses the latest xajax from svn now.

Having a quick look at your code I wonder about:

$oXajax->register(XAJAX_FUNCTION,'waypoint_handler');

Is XAJAX_FUNCTION == 'waypoint_handler'?

Can you provide access to your test page?

Ralf

Re: back button plugin and dynamic pagination

Hi Ralf,

great! Thank you for your answer and for updating RSH...
I'll test it asap - hopefully this morning in a couple of hours - and give you a note...

According to my code: instead of writing
$xajax->registerFunction('waypoint_handler','waypoint.inc.php');
I accustomed registering functions, etc. in this way
$oXajax->register(XAJAX_FUNCTION,'waypoint_handler'); - of course in my xajax.functions.php with included waypoint_handler-function...

Unfortunately I can't give access the project I'm working on at the moment - my boss would kill me smile
But I plan to implement rsh also on other projects (eg. I use 'my' pagination in many projects) - there I can provide you with access... But It might take a couple of days to implement....

Cheers,
Manu

Vegetarier essen meinem Essen das Essen weg.

7 (edited by Manu71193 2007-12-04 5:07:01 PM)

Re: back button plugin and dynamic pagination

Hi again,

I tried it out with no success sad

Firebug shows an error directly after loading the first page: "location is not defined". After clicking the pagination links it shows "this.listener has no properties"

Now I assume that my construction of how I build up the page causes that error:
I load a nearly blank template ('form_scenario_empty.tpl'), having a xajax-call in the onload event ('xajax_getScenarios') which builds up the content containing my 5 datasets and the pagination. I put the dhtmlHistoryAdd-function in xajax_getScenarios (where I'll get the params for the navi, initialisated by defaults).

So please tell me that I'm wrong in my assumptions wink

Would like to give more code examples, but I've posted the relevant stuff already above...ok, I'll post the php file which I can call from the browser:

if(!isset($aMain['CONTENT'])) {

    if(is_object($oUser) && $oUser->mayI($sPos)) {
        
        $aValues['OPEN']     = 1;
        $oSmarty->assign($aValues);
       $aMain['CONTENT']  = $oSmarty->fetch('form_scenario_empty.tpl');
        
        $aMain['ERROR']     .= CTools::getErrorMessages();
        $aMain['SUCCESS'] .= CTools::getSuccessMessages();
        
        $aMain['ONLOAD']     = 'xajax_getScenarios(\'open\');';
        
    } else {
    
        $aMain['CONTENT'] = $oSmarty->fetch('no_permission.tpl');
    
    }
}
Vegetarier essen meinem Essen das Essen weg.

Re: back button plugin and dynamic pagination

@Manu
From the rsh page (http://code.google.com/p/reallysimplehi … structions)

Always call dhtmlHistory.initialize() and dhtmlHistory.addListener() from within a window.onload event. RSH will break, especially in IE, if you try to initialize it from any flavor of DOMContentLoaded. IE doesn't load up its saved cross-session form values until just after the body.onload event, so DOMContentLoaded is not an appropriate event for the initialization of RSH.

Your code:

$aMain['XAJAX'] = $oXajax->getJavascript();

At what time do you print the javascript part?
The dhtmlHistory.initialize() which is called from within the js code may not be called correctly?

Re: back button plugin and dynamic pagination

Hi Ralf,

oh, I didn't read about initializing those functions in the onload event... I'll try that asap (when I've got some time left today)...

At what time do you print the javascript part?

First I collect relevant stuff to display/integrate it in the page in my $aMain-Array, at the very last I assign this to my smarty template when the page is freshly reloaded...

The dhtmlHistory.initialize() which is called from within the js code may not be called correctly?

I'll check this first...

Vegetarier essen meinem Essen das Essen weg.

Re: back button plugin and dynamic pagination

Ok, I tried it again with no success... It still says 'location is not defined'.
I also put dhtmlHistory.initialize() and dhtmlHistory.addListener()  directly in the onload event with the same result...

I assume that it's not working 'cause I've got stuff in the onload event already (I had this before in another project - window.onload=xxx; did not work because there was already something to autoload...

I cleaned up my sourcecode a bit to show it here (hopefully without cut'n'paste errors):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title></title>

        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
        
        <link href="favicon.ico" rel="SHORTCUT ICON" />

        <link href="css/style.css" type="text/css" rel="stylesheet" />
        <link rel="stylesheet" type="text/css" href="css/office_xp.css" />
    
        <script type="text/javascript">defaultStatus = "";</script>
        
        <script type="text/javascript" src="js/common.js"></script>
        <script type="text/javascript" src="js/jsdomenu.js"></script>
        <script type="text/javascript" src="js/jsdomenubar.js"></script>
        <script type="text/javascript" src="js/cal.js"></script>

        <script type="text/javascript" src="js/general.js"></script>

        <script type="text/javascript" src="js/yahoo/yahoo-min.js"></script>
        <script type="text/javascript" src="js/yahoo/event-min.js"></script>
        <script type="text/javascript" src="js/yahoo/treeview-min.js"></script>
        <script type="text/javascript" src="js/yahoo/TaskNode.js"></script>
        <script type="text/javascript" src="js/yahoo/CheckboxNode.js"></script>

<script type='text/javascript' charset='UTF-8'>
/* <![CDATA[ */
try { if (undefined == xajax.config) xajax.config = {}; } catch (e) { xajax = {}; xajax.config = {}; };
xajax.config.requestURI = 'http://192.168.1.1/xxx/scenarios_open.php';
xajax.config.statusMessages = false;
xajax.config.waitCursor = true;
xajax.config.version = 'unknown';
xajax.config.legacy = false;
xajax.config.defaultMode = 'asynchronous';
xajax.config.defaultMethod = 'POST';
/* ]]> */
</script>
<script type='text/javascript' src='xajax_js/xajax_core.js' charset='UTF-8'></script>
<script type='text/javascript' charset='UTF-8'>
/* <![CDATA[ */
window.setTimeout(
 function () {
  var scriptExists = false;
  try { if (xajax.isLoaded) scriptExists = true; }
  catch (e) {}
  if (!scriptExists) {
   alert('Error: the xajax Javascript component could not be included. Perhaps the URL is incorrect?\nURL: xajax_js/xajax_core.js');
  }
 },
2000
);
/* ]]> */
</script>

<script type='text/javascript' charset='UTF-8'>
/* <![CDATA[ */

xajax_getScenarios = function() { return xajax.request( { xjxfun: 'getScenarios' }, { parameters: arguments } ); };

xajax_waypoint_handler = function() { return xajax.request( { xjxfun: 'waypoint_handler' }, { parameters: arguments } ); };
/* ]]> */
</script>

<script type='text/javascript' src='js/json2007.js'  charset='UTF-8'></script>

<script type='text/javascript' src='js/rsh.compressed.js'  charset='UTF-8'></script>

<script type='text/javascript'  charset='UTF-8'>
/* <![CDATA[ */


window.dhtmlHistory.create(); 


function dhtmlHistoryInit() { 
    if (realOnLoadBB)
        realOnLoadBB();
    dhtmlHistory.initialize();
    dhtmlHistory.addListener(xajax_waypoint_handler);
    var s=dhtmlHistory.getCurrentLocation(); // check for bookmark hash value
    if (s.length>0)
        xajax_waypoint_handler(s,null);
}
        var realOnLoadBB = null;
        if (window.onload)
            realOnLoadBB=window.onload;
        window.onload=dhtmlHistoryInit;
/* ]]> */
</script>

    </head>
<body onload="xajax_getScenarios('open');" class="default">

<div id="content">

    <div id="login">
        <table cellspacing="2" cellpadding="2" border="0" class="bd" width="100%">
            <tr>
                <td style="width:50%;">
                    <strong>Basis</strong>:xxx</span>
                </td>
                <td style="width:50%;text-align:right;">    
                    Eingeloggt an <strong>xyz</strong> als: <strong>user1</strong> seit: <div id="logintime" style="display:inline;"><strong>1 std., 39 min., 11 sek.</strong></div>
                </td>
            </tr>
        </table>
    </div>

    <div id="content_div">
        <div id="formfield2">
        </div>
    </div>

</div>

</body>
</html>
Vegetarier essen meinem Essen das Essen weg.

Re: back button plugin and dynamic pagination

try:

<body onload="dhtmlHistoryInit(); xajax_getScenarios('open');" class="default">

Re: back button plugin and dynamic pagination

Hi Manu71193, your plugin is cool, but not easy to develop.
I have a problem in your plugin.
I want to add input value in function waypoint_handler (ex: waypoint_handler($sWaypointName, $sWaypointData, $arrExt...)) What do i do?
Thanks.

13 (edited by ralf 2008-03-11 8:59:08 PM)

Re: back button plugin and dynamic pagination

@boyjoy

you can use WaypointData to save your values ...

$objResponse = new xajaxResponse();

$aWaypointData = array('my data to recover','this waypoint', 12, 9998);

dhtmlHistoryAdd($objResponse, $sWaypointName, $aWaypointData);

Your WaypointHandler will the get this data passed.

Re: back button plugin and dynamic pagination

Hi boyjoy,

ralf is the developer of this plugin, I tried to get it to run, but ran out of time.
I'll try it again but unfortunately I'm right busy now...

Vegetarier essen meinem Essen das Essen weg.

Re: back button plugin and dynamic pagination

Hi,
Thank ralf and Manu71193 very much.
Best regards.