From b4e681dc83cafe49f80f91dc1dea2f50d1e9b5cf Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 28 Aug 2008 04:26:59 +0000 Subject: [PATCH] BUGFIX: Removed use of deprecated TableListField_Item::BaseLink() And TableListField::ajax_refresh() from CommentTableField and MemberTableField BUGFIX: Fixed styling, searching, and pagination of CommentTableField git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@61686 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/CommentTableField.php | 6 +-- javascript/CommentTableField.js | 49 ++++++++++++------------- javascript/MemberTableField.js | 42 ++++++++++++--------- templates/Includes/CommentTableField.ss | 2 +- 4 files changed, 53 insertions(+), 46 deletions(-) diff --git a/code/CommentTableField.php b/code/CommentTableField.php index 1700d5fa..74550fe3 100644 --- a/code/CommentTableField.php +++ b/code/CommentTableField.php @@ -172,15 +172,15 @@ class CommentTableField_Item extends ComplexTableField_Item { } function SpamLink() { - return $this->BaseLink() . "&methodName=spam"; + return Controller::join_links($this->Link(), "?methodName=spam"); } function HamLink() { - return $this->BaseLink() . "&methodName=ham"; + return Controller::join_links($this->Link(), "?methodName=ham"); } function ApproveLink() { - return $this->BaseLink() . "&methodName=approve"; + return Controller::join_links($this->Link(), "?methodName=approve"); } } diff --git a/javascript/CommentTableField.js b/javascript/CommentTableField.js index 3582950a..58f309a5 100644 --- a/javascript/CommentTableField.js +++ b/javascript/CommentTableField.js @@ -14,13 +14,10 @@ CommentTableField.prototype = { rules['#'+this.id+' table.data a.hamlink'] = { onclick: this.removeRowAfterAjax.bind(this) }; - rules['#Form_EditForm div.CommentFilter input'] = { onkeypress : this.prepareSearch.bind(this) }; - - rules['#Form_EditForm'] = { changeDetection_fieldsToIgnore : { 'ctf[start]' : true, @@ -76,7 +73,7 @@ CommentTableField.prototype = { CommentTableField.applyTo('div.CommentTableField'); CommentFilterButton = Class.create(); -CommentFilterButton.applyTo('#Form_EditForm #CommentFilterButton'); +CommentFilterButton.applyTo('#CommentFilterButton'); CommentFilterButton.prototype = { initialize: function() { this.inputFields = new Array(); @@ -107,28 +104,30 @@ CommentFilterButton.prototype = { }, onclick: function(e) { - //if(!$('ctf-ID') || !$('CommentFieldName')) { - // return false; - //} - - var updateURL = ""; - updateURL += Event.findElement(e,"form").action; - // we can't set "fieldName" as a HiddenField because there might be multiple ComplexTableFields in a single EditForm-container - updateURL += "&fieldName="+$('CommentFieldName').value; - updateURL += "&action_callfieldmethod&&methodName=ajax_refresh&"; - for( var index = 0; index < this.inputFields.length; index++ ) { - if( this.inputFields[index].tagName ) { - updateURL += this.inputFields[index].name + '=' + encodeURIComponent( this.inputFields[index].value ) + '&'; - } - } - updateURL += 'ajax=1' + ($('SecurityID') ? '&SecurityID=' + $('SecurityID').value : ''); + try { + var form = Event.findElement(e,"form"); + var fieldName = $('CommentFieldName').value; + var fieldID = form.id + '_' + fieldName; + + var updateURL = form.action + '/field/' + fieldName + '?ajax=1'; + for( var index = 0; index < this.inputFields.length; index++ ) { + if( this.inputFields[index].tagName ) { + updateURL += '&' + this.inputFields[index].name + '=' + encodeURIComponent( this.inputFields[index].value ); + } + } + updateURL += ($('SecurityID') ? '&SecurityID=' + $('SecurityID').value : ''); - new Ajax.Request( updateURL, { - onSuccess: Ajax.Evaluator, - onFailure: function( response ) { - errorMessage('Could not filter results: ' + response.responseText ); - }.bind(this) - }); + new Ajax.Updater( fieldID, updateURL, { + onSuccess: function() { + Behaviour.apply(fieldID, true); + }, + onFailure: function( response ) { + errorMessage('Could not filter results: ' + response.responseText ); + }.bind(this) + }); + } catch(er) { + errorMessage('Error searching'); + } return false; } diff --git a/javascript/MemberTableField.js b/javascript/MemberTableField.js index 3dcc4ba9..3704d63d 100755 --- a/javascript/MemberTableField.js +++ b/javascript/MemberTableField.js @@ -243,24 +243,32 @@ MemberFilterButton.prototype = { if(!$('ctf-ID') || !$('MemberFieldName')) { return false; } - - var updateURL = ""; - updateURL += Event.findElement(e,"form").action; - updateURL += '/field/' + $('MemberFieldName').value + '/ajax_refresh?ajax=1&'; - for( var index = 0; index < this.inputFields.length; index++ ) { - if( this.inputFields[index].tagName ) { - updateURL += this.inputFields[index].name + '=' + encodeURIComponent( this.inputFields[index].value ) + '&'; - } - } - updateURL += 'ajax=1' + ($('SecurityID') ? '&SecurityID=' + $('SecurityID').value : ''); - new Ajax.Request( updateURL, { - onSuccess: Ajax.Evaluator, - onFailure: function( response ) { - errorMessage('Could not filter results: ' + response.responseText ); - }.bind(this) - }); - + try { + var form = Event.findElement(e,"form"); + var fieldName = $('MemberFieldName').value; + var fieldID = form.id + '_' + fieldName; + + var updateURL = form.action + '/field/' + fieldName + '?ajax=1'; + for( var index = 0; index < this.inputFields.length; index++ ) { + if( this.inputFields[index].tagName ) { + updateURL += '&' + this.inputFields[index].name + '=' + encodeURIComponent( this.inputFields[index].value ); + } + } + updateURL += ($('SecurityID') ? '&SecurityID=' + $('SecurityID').value : ''); + + new Ajax.Updater( fieldID, updateURL, { + onSuccess: function() { + Behaviour.apply(fieldID, true); + }, + onFailure: function( response ) { + errorMessage('Could not filter results: ' + response.responseText ); + }.bind(this) + }); + } catch(er) { + errorMessage('Error searching'); + } + return false; } } diff --git a/templates/Includes/CommentTableField.ss b/templates/Includes/CommentTableField.ss index ce40c52a..bec40a75 100644 --- a/templates/Includes/CommentTableField.ss +++ b/templates/Includes/CommentTableField.ss @@ -1,4 +1,4 @@ -
+
$SearchForm