BUGFIX Switching all ajax implementations to consistently use jQuery.ajax instead of Prototype's Ajax.Request() (AjaxUniqueTextField, InlineFormAction, TableField, TableListField, TreeSelectorField)

This commit is contained in:
Ingo Schommer 2011-03-02 17:14:47 +13:00
parent cc795c4326
commit e78b700f7c
5 changed files with 88 additions and 81 deletions

View File

@ -76,17 +76,19 @@ JS;
Behaviour.register({ Behaviour.register({
'#$id' : { '#$id' : {
onkeyup: function() { onkeyup: function() {
var self = this;
if(this.checkValid()) { 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', method: 'get',
onSuccess: function(response) { success: function(response) {
if(response.responseText == 'ok') if(response.responseText == 'ok')
Element.removeClassName(this, 'inuse'); Element.removeClassName(self, 'inuse');
else { else {
Element.addClassName(this, 'inuse'); Element.addClassName(self, 'inuse');
} }
}.bind(this), }
onFailure: function(response) { error: function(response) {
} }
}); });

View File

@ -6,9 +6,10 @@ Behaviour.register({
onclick: function() { onclick: function() {
var url = jQuery('base').attr('href') + 'admin-custom/' + this.name.substring(7) + '?ID=' + $('Form_EditForm_ID').value + '&ajax=1'; var url = jQuery('base').attr('href') + 'admin-custom/' + this.name.substring(7) + '?ID=' + $('Form_EditForm_ID').value + '&ajax=1';
new Ajax.Request( url, { jQuery.ajax({
onSuccess: Ajax.Evaluator, 'url': url,
onFailure: Ajax.Evaluator success: Ajax.Evaluator,
success: Ajax.Evaluator
}); });
return false; return false;

View File

@ -52,6 +52,7 @@ TableField.prototype = {
var params = link.getAttribute("href").toQueryParams(); var params = link.getAttribute("href").toQueryParams();
var isEmpty = true; var isEmpty = true;
var recordID = row.getRecordId(); var recordID = row.getRecordId();
var self = this;
// Check to see if there is a dataobject to delete first, otherwise remove the row. // 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) // or: Check if a childID is set (not present on new items)
@ -77,12 +78,11 @@ TableField.prototype = {
var confirmed = confirm(ss.i18n._t('TABLEFIELD.DELETECONFIRMMESSAGE', 'Are you sure you want to delete this record?')); var confirmed = confirm(ss.i18n._t('TABLEFIELD.DELETECONFIRMMESSAGE', 'Are you sure you want to delete this record?'));
if(confirmed){ if(confirmed){
img.setAttribute("src",'cms/images/network-save.gif'); // TODO doesn't work img.setAttribute("src",'cms/images/network-save.gif'); // TODO doesn't work
new Ajax.Request( jQuery.ajax({
link.getAttribute("href"), 'url': link.getAttribute("href"),
{ 'method': 'post',
method: 'post', 'data': {ajax: 1, 'SecurityID': $('SecurityID') ? $('SecurityID').value : null},
postBody: 'ajax=1' + ($('SecurityID') ? '&SecurityID=' + $('SecurityID').value : ''), 'success': function(response){
onComplete: function(response){
Effect.Fade( Effect.Fade(
row, row,
{ {
@ -91,16 +91,15 @@ TableField.prototype = {
obj.element.parentNode.removeChild(obj.element); obj.element.parentNode.removeChild(obj.element);
// recalculate summary if needed (assumes that TableListField.js is present) // recalculate summary if needed (assumes that TableListField.js is present)
// TODO Proper inheritance // TODO Proper inheritance
if(this._summarise) this._summarise(); if(self._summarise) self._summarise();
// custom callback // custom callback
if(this.callback_deleteRecord) this.callback_deleteRecord(e); if(self.callback_deleteRecord) self.callback_deleteRecord(e);
}.bind(this) }
}
);
}.bind(this),
onFailure: ajaxErrorHandler
} }
); );
},
'error': ajaxErrorHandler
});
} }
Event.stop(e); Event.stop(e);
return false; return false;

View File

@ -87,18 +87,18 @@ TableListField.prototype = {
var img = Event.element(e); var img = Event.element(e);
var link = Event.findElement(e,"a"); var link = Event.findElement(e,"a");
var row = Event.findElement(e,"tr"); var row = Event.findElement(e,"tr");
var self = this;
// TODO ajaxErrorHandler and loading-image are dependent on cms, but formfield is in sapphire // 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?')); var confirmed = confirm(ss.i18n._t('TABLEFIELD.DELETECONFIRMMESSAGE', 'Are you sure you want to delete this record?'));
if(confirmed) if(confirmed)
{ {
img.setAttribute("src",'cms/images/network-save.gif'); // TODO doesn't work img.setAttribute("src",'cms/images/network-save.gif'); // TODO doesn't work
new Ajax.Request( jQuery.ajax({
link.getAttribute("href"), 'url': link.getAttribute("href"),
{ 'method': 'post',
method: 'post', 'data': {forceajax: 1, SecurityID: $('SecurityID') ? $('SecurityID').value : null},
postBody: 'forceajax=1' + ($('SecurityID') ? '&SecurityID=' + $('SecurityID').value : ''), 'success': function(){
onComplete: function(){
Effect.Fade( Effect.Fade(
row, row,
{ {
@ -107,16 +107,15 @@ TableListField.prototype = {
obj.element.parentNode.removeChild(obj.element); obj.element.parentNode.removeChild(obj.element);
// recalculate summary if needed (assumes that TableListField.js is present) // recalculate summary if needed (assumes that TableListField.js is present)
// TODO Proper inheritance // TODO Proper inheritance
if(this._summarise) this._summarise(); if(self._summarise) self._summarise();
// custom callback // custom callback
if(this.callback_deleteRecord) this.callback_deleteRecord(e); if(self.callback_deleteRecord) self.callback_deleteRecord(e);
}.bind(this) }
}
);
}.bind(this),
onFailure: this.ajaxErrorHandler
} }
); );
},
'error': this.ajaxErrorHandler
});
} }
Event.stop(e); Event.stop(e);
}, },
@ -172,6 +171,8 @@ TableListField.prototype = {
}, },
refresh: function(e) { refresh: function(e) {
var self = this;
if(e) { if(e) {
var el = Event.element(e); var el = Event.element(e);
if(el.nodeName != "a") el = Event.findElement(e,"a"); if(el.nodeName != "a") el = Event.findElement(e,"a");
@ -180,19 +181,17 @@ TableListField.prototype = {
} }
if(el.getAttribute('href')) { if(el.getAttribute('href')) {
new Ajax.Request( jQuery.ajax({
el.getAttribute('href'), 'url': el.getAttribute('href'),
{ 'data': {'update': 1, 'params': (params)},
postBody: 'update=1' + (params) ? '&' + params : '', 'success': function(response) {
onComplete: function(response) { Element.replace(self.id, response.responseText);
Element.replace(this.id, response.responseText);
// reapply behaviour and reattach methods to TF container node // reapply behaviour and reattach methods to TF container node
// e.g. <div class="TableListField"> // e.g. <div class="TableListField">
Behaviour.apply($(this.id), true); Behaviour.apply($(self.id), true);
if(oncomplete) oncomplete.apply(response); if(oncomplete) oncomplete.apply(response);
}.bind(this)
} }
); });
} }
if(e) Event.stop(e); if(e) Event.stop(e);
@ -322,6 +321,7 @@ TableListRecord.prototype = {
}, },
ajaxRequest : function(url, subform) { ajaxRequest : function(url, subform) {
var self = this;
// Highlight the new row // Highlight the new row
if(this.parentNode.selectedRow) { if(this.parentNode.selectedRow) {
Element.removeClassName(this.parentNode.selectedRow,'current'); Element.removeClassName(this.parentNode.selectedRow,'current');
@ -332,11 +332,14 @@ TableListRecord.prototype = {
this.subform = $(subform); this.subform = $(subform);
Element.addClassName(this, 'loading'); Element.addClassName(this, 'loading');
statusMessage('loading'); statusMessage('loading');
new Ajax.Request(url + this.id.replace('record-',''), { jQuery.ajax({
method : 'post', 'url': url + this.id.replace('record-',''),
postBody : 'ajax=1', 'method' : 'post',
onSuccess : this.select_success.bind(this), 'data' : {'ajax': 1},
onFailure : ajaxErrorHandler success : function() {
self.select_success();
}
failure : ajaxErrorHandler
}); });
}, },

View File

@ -195,11 +195,12 @@ TreeDropdownField.prototype = {
if(localeField.length) {ajaxURL += "&locale=" + localeField.val();} if(localeField.length) {ajaxURL += "&locale=" + localeField.val();}
if(this.inputTag.value) ajaxURL += '&forceValue=' + this.inputTag.value; if(this.inputTag.value) ajaxURL += '&forceValue=' + this.inputTag.value;
if(this.search() != null) ajaxURL += "&search=" + this.search(); if(this.search() != null) ajaxURL += "&search=" + this.search();
new Ajax.Request(ajaxURL, { jQuery.ajax({
method : 'get', 'url': ajaxURL,
onSuccess : after, 'method' : 'get',
onFailure : function(response) { errorMessage("Error getting data", response); } 'success' : after,
}) 'error' : function(response) { errorMessage("Error getting data", response); }
});
}, },
search: function() { search: function() {
@ -248,9 +249,10 @@ TreeDropdownField.prototype = {
// ajaxExpansion is called in context of TreeNode, not Tree, so search() doesn't exist. // ajaxExpansion is called in context of TreeNode, not Tree, so search() doesn't exist.
if (this.search && this.search() != null) ajaxURL += "&search=" + this.search(); if (this.search && this.search() != null) ajaxURL += "&search=" + this.search();
new Ajax.Request(ajaxURL, { jQuery.ajax({
onSuccess : this.installSubtree.bind(this), 'url': ajaxURL,
onFailure : function(response) { errorMessage('error loading subtree', response); } 'success' : this.installSubtree.bind(this),
'error' : function(response) { errorMessage('error loading subtree', response); }
}); });
}, },