Searching in feedback admin

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@39808 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Andrew O'Neil 2007-08-10 00:03:30 +00:00
parent cf5cda9799
commit 6ecfafcc18
3 changed files with 95 additions and 7 deletions

View File

@ -6,9 +6,16 @@ class CommentTableField extends ComplexTableField {
function __construct($controller, $name, $sourceClass, $mode, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") {
$this->mode = $mode;
$this->Markable = true;
parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
$this->Markable = true;
// search
$search = isset($_REQUEST['CommentSearch']) ? Convert::raw2sql($_REQUEST['CommentSearch']) : null;
if(!empty($_REQUEST['CommentSearch'])) {
$this->sourceFilter[] = "( `Name` LIKE '%$search%' OR `Comment` LIKE '%$search%')";
}
Requirements::javascript('cms/javascript/CommentTableField.js');
}
@ -100,8 +107,9 @@ class CommentTableField extends ComplexTableField {
function SearchForm() {
$searchFields = new FieldGroup(
new TextField('MemberSearch', 'Search'),
new HiddenField("ctf[mode]",'',$this->mode)
new TextField('CommentSearch', 'Search'),
new HiddenField("ctf[ID]",'',$this->mode),
new HiddenField('CommentFieldName','',$this->name)
);
$actionFields = new LiteralField('CommentFilterButton','<input type="submit" name="CommentFilterButton" value="Filter" id="CommentFilterButton"/>');

View File

@ -29,17 +29,20 @@ class FeedbackAdmin extends LeftAndMain {
if($section == 'accepted') {
$filter = 'IsSpam=0 AND NeedsModeration=0';
$title = "<h2>Accepted Comments</h2>";
} else if($section == 'unmoderated') {
$filter = 'NeedsModeration=1';
$title = "<h2>Comments Awaiting Moderation</h2>";
} else {
$filter = 'IsSpam=1';
$title = "<h2>Spam</h2>";
}
$tableFields = array(
"Name" => "Author",
"Comment" => "Comment",
"PageTitle" => "Page"
);
);
$popupFields = new FieldSet(
new TextField("Name"),
@ -47,10 +50,10 @@ class FeedbackAdmin extends LeftAndMain {
);
$idField = new HiddenField('ID', '', $section);
$table = new CommentTableField($this, "Comments", "PageComment", $section, $tableFields, $popupFields, $filter);
$table = new CommentTableField($this, "Comments", "PageComment", $section, $tableFields, $popupFields, array($filter));
$table->setParentClass(false);
$fields = new FieldSet($idField, $table);
$fields = new FieldSet(new LiteralField("Title", $title), $idField, $table);
$actions = new FieldSet();

View File

@ -15,6 +15,10 @@ CommentTableField.prototype = {
onclick: this.removeRowAfterAjax.bind(this)
};
rules['#Form_EditForm div.CommentFilter input'] = {
onkeypress : this.prepareSearch.bind(this)
};
Behaviour.register(rules);
},
@ -36,7 +40,80 @@ CommentTableField.prototype = {
}
);
Event.stop(e);
},
// prevent submission of wrong form-button (CommentFilterButton)
prepareSearch: function(e) {
// IE6 doesnt send an event-object with onkeypress
var event = (e) ? e : window.event;
var keyCode = (event.keyCode) ? event.keyCode : event.which;
if(keyCode == Event.KEY_RETURN) {
var el = Event.element(event);
$('CommentFilterButton').onclick(event);
Event.stop(event);
return false;
}
}
}
CommentTableField.applyTo('div.CommentTableField');
CommentTableField.applyTo('div.CommentTableField');
CommentFilterButton = Class.create();
CommentFilterButton.applyTo('#Form_EditForm #CommentFilterButton');
CommentFilterButton.prototype = {
initialize: function() {
this.inputFields = new Array();
var childNodes = this.parentNode.getElementsByTagName('input');
for( var index = 0; index < childNodes.length; index++ ) {
if( childNodes[index].tagName ) {
childNodes[index].resetChanged = function() { return false; }
childNodes[index].isChanged = function() { return false; }
this.inputFields.push( childNodes[index] );
}
}
childNodes = this.parentNode.getElementsByTagName('select');
for( var index = 0; index < childNodes.length; index++ ) {
if( childNodes[index].tagName ) {
childNodes[index].resetChanged = function() { return false; }
childNodes[index].field_changed = function() { return false; }
this.inputFields.push( childNodes[index] );
}
}
},
isChanged: function() {
return false;
},
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';
new Ajax.Request( updateURL, {
onSuccess: Ajax.Evaluator,
onFailure: function( response ) {
errorMessage('Could not filter results: ' + response.responseText );
}.bind(this)
});
return false;
}
}