Hi Galdan,
ok here is a little help:
function remoteTimer($options = null) {
$frequency = (isset($options['frequency'])) ?
$options['frequency'] : 10;
$timervar = (isset($options['timervar'])) ? $options['timervar'] .
'=' : '';
$code = $timervar . "new PeriodicalExecuter(function() {" . $this-
>remoteFunction($options) . "}, $frequency)";
return $this->Javascript->codeBlock($code);
}
<?php
echo $ajax->remoteTimer(array('url' => array('controller' =>
'posts', 'action' => 'view'),
'update' => 'mydiv',
'frequency' => 5,
'timervar' =>
'mytimer'));
echo $form->checkbox('pause', array('onclick' => 'if (this.checked)
{mytimer.stop();}'));
?>
But this is only good if you want to stop the timer once and restart
it with a page reload.
Now in your case you said you want to enable and disable it, so you
also have to start a new timer when the checkbox is unchecked again,
so in your case I advise to not change the ajax-helper (which is not
the best idea anyway) but to write it all in javascript.
Just include the following javascript code into your app:
var mytimer = null;
function startTimer(url, update, frequency) {
mytimer = new PeriodicalExecuter(function() {new
Ajax.Updater(update, url , {asynchronous:true, evalScripts:true,
requestHeaders:['X-Update', update]})}, frequency);
}
function stopTimer() {
mytimer.stop();
}
And this is how your view could look like:
echo $javascript->codeBlock("startTimer('/yourapp/posts/view',
'mydiv', 5)");
echo $form->checkbox('pause', array('onclick' => 'if (this.checked)
{startTimer('/yourapp/posts/view', 'mydiv', 5);} else
{stopTimer();}'));
I hope this works for you,
Michael
On 5 Nov., 09:33, Galdan <[EMAIL PROTECTED]> wrote:
> Hi Michaeal,
>
> thank you for your response. I've taken a look to the ajax helper, and
> basically i understand what you mean.
>
> But I'am not experienced enough to do this :-(
>
> On 4 Nov., 23:57, schneimi <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > this is not supported by the ajax helper, I think you have to stop and
> > overwrite the PeriodicalExecuter manually. See
> > herehttp://www.prototypejs.org/api/periodicalExecuterandherehttp://www.prototypejs.org/api/periodicalExecuter/stop.
>
> > You could try to change the ajax helper remoteTimer() so that the
> > PeriodicalExecuter is put into a variable which you may then use to
> > stop it and overwrite it with a new PeriodicalExecuter on click on
> > your checkbox.
>
> > Not sure if this works, but I hope this helps anyway,
>
> > Michael
>
> > On 4 Nov., 21:51, Galdan <[EMAIL PROTECTED]> wrote:
>
> > > Hi together,
>
> > > i use $ajax->remoteTimer(); to refresh a DIV all 30 seconds.
>
> > > I wan't to enable/disable this by an checkbox, but i have absolutely
> > > no idea to handle this.
>
> > > Could you help me?
>
> > > Thank you very much in advance!
>
> > > byebye
> > > Tom
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---