From e78b700f7c97882c37bdc8cbdb62d32c7f43f9a0 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 2 Mar 2011 17:14:47 +1300 Subject: [PATCH] BUGFIX Switching all ajax implementations to consistently use jQuery.ajax instead of Prototype's Ajax.Request() (AjaxUniqueTextField, InlineFormAction, TableField, TableListField, TreeSelectorField) --- forms/AjaxUniqueTextField.php | 14 +++--- javascript/InlineFormAction.js | 7 +-- javascript/TableField.js | 45 +++++++++-------- javascript/TableListField.js | 85 +++++++++++++++++---------------- javascript/TreeSelectorField.js | 18 +++---- 5 files changed, 88 insertions(+), 81 deletions(-) diff --git a/forms/AjaxUniqueTextField.php b/forms/AjaxUniqueTextField.php index 63a3d2725..aa565d9c3 100644 --- a/forms/AjaxUniqueTextField.php +++ b/forms/AjaxUniqueTextField.php @@ -76,17 +76,19 @@ JS; 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) { } }); diff --git a/javascript/InlineFormAction.js b/javascript/InlineFormAction.js index 681f207f8..acaa6fe5d 100755 --- a/javascript/InlineFormAction.js +++ b/javascript/InlineFormAction.js @@ -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; diff --git a/javascript/TableField.js b/javascript/TableField.js index 25ad2076e..a247e37b9 100755 --- a/javascript/TableField.js +++ b/javascript/TableField.js @@ -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; diff --git a/javascript/TableListField.js b/javascript/TableListField.js index d2148e160..387aa5e22 100755 --- a/javascript/TableListField.js +++ b/javascript/TableListField.js @@ -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.
- 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.
+ 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 }); }, diff --git a/javascript/TreeSelectorField.js b/javascript/TreeSelectorField.js index e882cec62..6a4403ead 100755 --- a/javascript/TreeSelectorField.js +++ b/javascript/TreeSelectorField.js @@ -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); } }); },