#677 bug
carloscurotto (at gmail)

PeriodicalUpdater not calling OnComplete function

Reported by carloscurotto (at gmail) | May 13th, 2009 @ 02:45 PM

The periodical updater object is not calling the onComplete function. However, the API tells that it should.

API Reference
http://www.prototypejs.org/api/ajax/periodicalUpdater
http://www.prototypejs.org/api/ajax/options

"onComplete: Triggered at the very end of a request's life-cycle, once the request completed, status-specific callbacks were called, and possible automatic behaviors were processed."

Problem:

The PeriodicalUpdater object is receiving the user's onComplete function into the options object and it is storing that function into its own onComplete attribute like this:

Ajax.PeriodicalUpdater ... {
...
    this.onComplete = this.options.onComplete;
...
}

Then, in the start function, it is rewriting the option's onComplete function with another one called updateComplete like this:

Ajax.PeriodicalUpdater ... {
...
  start: function() {
    ...
    this.options.onComplete = this.updateComplete.bind(this);
    ...
  },
...
}

Finally, it is passing the options object to the Ajax.Updater object constructor in the onTimerEvent function which has the new onComplete function insted of the one defined by the user, so, the user's onComplete function is never called.

Solution:

We have added a new attribute to the options object called onRequestComplete to store the user's onComplete function like this:

Ajax.PeriodicalUpdater ... {
...
  start: function() {
    ...
    this.options.onRequestComplete = this.onComplete;
    ...
  },
...
}

Then, in the Ajax.Updater object we have added the call to the user's onComplete function after the onComplete that prototype has rewritten before like this:

Ajax.Updater ... {
...

var onRequestComplete = options.onRequestComplete;

options.onComplete = (function(response, json) {    
  this.updateContent(response.responseText);
  if (Object.isFunction(onComplete)) {
    onComplete(response, json);
    onRequestComplete(response, json);
  }
}).bind(this);

... }

So, it will call the user's defined onComplete function as the API says after processing the request.

Additional Notes:

We have tested this with prototype 1.6.3.

If you have any questions, contact me at: carloscurotto@gmail.com

Thanks,
Carlos Curotto

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

Pages