Permalink
Browse files

BUGFIX Switching all ajax implementations to consistently use jQuery.…

…ajax instead of Prototype's Ajax.Request() (AjaxUniqueTextField, InlineFormAction, TableField, TableListField, TreeSelectorField)
  • Loading branch information...
1 parent cc795c4 commit e78b700f7c97882c37bdc8cbdb62d32c7f43f9a0 @chillu chillu committed Mar 2, 2011
@@ -76,17 +76,19 @@ function jsValidation() {
Behaviour.register({
'#$id' : {
onkeyup: function() {
+ var self = this;
if(this.checkValid()) {
- new Ajax.Request('{$url}?ajax=1&{$this->name}=' + encodeURIComponent(this.value), {
+ jQuery.ajax({
+ 'url': '{$url}?ajax=1&{$this->name}=' + encodeURIComponent(this.value),
method: 'get',
- onSuccess: function(response) {
+ success: function(response) {
if(response.responseText == 'ok')
- Element.removeClassName(this, 'inuse');
+ Element.removeClassName(self, 'inuse');
else {
- Element.addClassName(this, 'inuse');
+ Element.addClassName(self, 'inuse');
}
- }.bind(this),
- onFailure: function(response) {
+ }
+ error: function(response) {
}
});
@@ -6,9 +6,10 @@ Behaviour.register({
onclick: function() {
var url = jQuery('base').attr('href') + 'admin-custom/' + this.name.substring(7) + '?ID=' + $('Form_EditForm_ID').value + '&ajax=1';
- new Ajax.Request( url, {
- onSuccess: Ajax.Evaluator,
- onFailure: Ajax.Evaluator
+ jQuery.ajax({
+ 'url': url,
+ success: Ajax.Evaluator,
+ success: Ajax.Evaluator
});
return false;
View
@@ -52,6 +52,7 @@ TableField.prototype = {
var params = link.getAttribute("href").toQueryParams();
var isEmpty = true;
var recordID = row.getRecordId();
+ var self = this;
// Check to see if there is a dataobject to delete first, otherwise remove the row.
// or: Check if a childID is set (not present on new items)
@@ -77,30 +78,28 @@ TableField.prototype = {
var confirmed = confirm(ss.i18n._t('TABLEFIELD.DELETECONFIRMMESSAGE', 'Are you sure you want to delete this record?'));
if(confirmed){
img.setAttribute("src",'cms/images/network-save.gif'); // TODO doesn't work
- new Ajax.Request(
- link.getAttribute("href"),
- {
- method: 'post',
- postBody: 'ajax=1' + ($('SecurityID') ? '&SecurityID=' + $('SecurityID').value : ''),
- onComplete: function(response){
- Effect.Fade(
- row,
- {
- afterFinish: function(obj) {
- // remove row from DOM
- obj.element.parentNode.removeChild(obj.element);
- // recalculate summary if needed (assumes that TableListField.js is present)
- // TODO Proper inheritance
- if(this._summarise) this._summarise();
- // custom callback
- if(this.callback_deleteRecord) this.callback_deleteRecord(e);
- }.bind(this)
+ jQuery.ajax({
+ 'url': link.getAttribute("href"),
+ 'method': 'post',
+ 'data': {ajax: 1, 'SecurityID': $('SecurityID') ? $('SecurityID').value : null},
+ 'success': function(response){
+ Effect.Fade(
+ row,
+ {
+ afterFinish: function(obj) {
+ // remove row from DOM
+ obj.element.parentNode.removeChild(obj.element);
+ // recalculate summary if needed (assumes that TableListField.js is present)
+ // TODO Proper inheritance
+ if(self._summarise) self._summarise();
+ // custom callback
+ if(self.callback_deleteRecord) self.callback_deleteRecord(e);
}
- );
- }.bind(this),
- onFailure: ajaxErrorHandler
- }
- );
+ }
+ );
+ },
+ 'error': ajaxErrorHandler
+ });
}
Event.stop(e);
return false;
@@ -87,36 +87,35 @@ TableListField.prototype = {
var img = Event.element(e);
var link = Event.findElement(e,"a");
var row = Event.findElement(e,"tr");
+ var self = this;
// TODO ajaxErrorHandler and loading-image are dependent on cms, but formfield is in sapphire
var confirmed = confirm(ss.i18n._t('TABLEFIELD.DELETECONFIRMMESSAGE', 'Are you sure you want to delete this record?'));
if(confirmed)
{
img.setAttribute("src",'cms/images/network-save.gif'); // TODO doesn't work
- new Ajax.Request(
- link.getAttribute("href"),
- {
- method: 'post',
- postBody: 'forceajax=1' + ($('SecurityID') ? '&SecurityID=' + $('SecurityID').value : ''),
- onComplete: function(){
- Effect.Fade(
- row,
- {
- afterFinish: function(obj) {
- // remove row from DOM
- obj.element.parentNode.removeChild(obj.element);
- // recalculate summary if needed (assumes that TableListField.js is present)
- // TODO Proper inheritance
- if(this._summarise) this._summarise();
- // custom callback
- if(this.callback_deleteRecord) this.callback_deleteRecord(e);
- }.bind(this)
+ jQuery.ajax({
+ 'url': link.getAttribute("href"),
+ 'method': 'post',
+ 'data': {forceajax: 1, SecurityID: $('SecurityID') ? $('SecurityID').value : null},
+ 'success': function(){
+ Effect.Fade(
+ row,
+ {
+ afterFinish: function(obj) {
+ // remove row from DOM
+ obj.element.parentNode.removeChild(obj.element);
+ // recalculate summary if needed (assumes that TableListField.js is present)
+ // TODO Proper inheritance
+ if(self._summarise) self._summarise();
+ // custom callback
+ if(self.callback_deleteRecord) self.callback_deleteRecord(e);
}
- );
- }.bind(this),
- onFailure: this.ajaxErrorHandler
- }
- );
+ }
+ );
+ },
+ 'error': this.ajaxErrorHandler
+ });
}
Event.stop(e);
},
@@ -172,6 +171,8 @@ TableListField.prototype = {
},
refresh: function(e) {
+ var self = this;
+
if(e) {
var el = Event.element(e);
if(el.nodeName != "a") el = Event.findElement(e,"a");
@@ -180,19 +181,17 @@ TableListField.prototype = {
}
if(el.getAttribute('href')) {
- new Ajax.Request(
- el.getAttribute('href'),
- {
- postBody: 'update=1' + (params) ? '&' + params : '',
- onComplete: function(response) {
- Element.replace(this.id, response.responseText);
- // reapply behaviour and reattach methods to TF container node
- // e.g. <div class="TableListField">
- Behaviour.apply($(this.id), true);
- if(oncomplete) oncomplete.apply(response);
- }.bind(this)
- }
- );
+ jQuery.ajax({
+ 'url': el.getAttribute('href'),
+ 'data': {'update': 1, 'params': (params)},
+ 'success': function(response) {
+ Element.replace(self.id, response.responseText);
+ // reapply behaviour and reattach methods to TF container node
+ // e.g. <div class="TableListField">
+ Behaviour.apply($(self.id), true);
+ if(oncomplete) oncomplete.apply(response);
+ }
+ });
}
if(e) Event.stop(e);
@@ -322,6 +321,7 @@ TableListRecord.prototype = {
},
ajaxRequest : function(url, subform) {
+ var self = this;
// Highlight the new row
if(this.parentNode.selectedRow) {
Element.removeClassName(this.parentNode.selectedRow,'current');
@@ -332,11 +332,14 @@ TableListRecord.prototype = {
this.subform = $(subform);
Element.addClassName(this, 'loading');
statusMessage('loading');
- new Ajax.Request(url + this.id.replace('record-',''), {
- method : 'post',
- postBody : 'ajax=1',
- onSuccess : this.select_success.bind(this),
- onFailure : ajaxErrorHandler
+ jQuery.ajax({
+ 'url': url + this.id.replace('record-',''),
+ 'method' : 'post',
+ 'data' : {'ajax': 1},
+ success : function() {
+ self.select_success();
+ }
+ failure : ajaxErrorHandler
});
},
@@ -195,11 +195,12 @@ TreeDropdownField.prototype = {
if(localeField.length) {ajaxURL += "&locale=" + localeField.val();}
if(this.inputTag.value) ajaxURL += '&forceValue=' + this.inputTag.value;
if(this.search() != null) ajaxURL += "&search=" + this.search();
- new Ajax.Request(ajaxURL, {
- method : 'get',
- onSuccess : after,
- onFailure : function(response) { errorMessage("Error getting data", response); }
- })
+ jQuery.ajax({
+ 'url': ajaxURL,
+ 'method' : 'get',
+ 'success' : after,
+ 'error' : function(response) { errorMessage("Error getting data", response); }
+ });
},
search: function() {
@@ -248,9 +249,10 @@ TreeDropdownField.prototype = {
// ajaxExpansion is called in context of TreeNode, not Tree, so search() doesn't exist.
if (this.search && this.search() != null) ajaxURL += "&search=" + this.search();
- new Ajax.Request(ajaxURL, {
- onSuccess : this.installSubtree.bind(this),
- onFailure : function(response) { errorMessage('error loading subtree', response); }
+ jQuery.ajax({
+ 'url': ajaxURL,
+ 'success' : this.installSubtree.bind(this),
+ 'error' : function(response) { errorMessage('error loading subtree', response); }
});
},

0 comments on commit e78b700

Please sign in to comment.