From 5000d0a227d6a41791db4dab8a2204ec18190147 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 6 Aug 2008 03:43:48 +0000 Subject: [PATCH] (merged from branches/roa. use "svn log -c -g " for detailed commit message) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@59927 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/ModelAdmin.php | 65 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/code/ModelAdmin.php b/code/ModelAdmin.php index bef5e628..892c55f7 100644 --- a/code/ModelAdmin.php +++ b/code/ModelAdmin.php @@ -39,7 +39,7 @@ abstract class ModelAdmin extends LeftAndMain { public static $allowed_actions = array( 'add', 'edit', - 'delete', + 'delete' ); public function init() { @@ -181,8 +181,6 @@ abstract class ModelAdmin extends LeftAndMain { return $form; } - - // ############# Utility Methods ############## /** @@ -257,8 +255,67 @@ abstract class ModelAdmin extends LeftAndMain { new FormAction('search', _t('MemberTableField.SEARCH')) ) ); - + //$form->setFormMethod('get'); return $form; } + + /** + * Another counter intuitive hoop to jump through, as the Form constructor + * is still thoroughly confusing the hell out of me. + */ + function FormObjectLink($value) { + $value = str_replace('SearchForm_', '', $value); + return "admin/crm/$value/search"; + } + + /** + * Action to execute a search using the model context + */ + function search() { + $className = $this->urlParams['ClassName']; + if (in_array($className, $this->getManagedModels())) { + $model = singleton($className); + // @todo need to filter post vars + $searchKeys = array_intersect_key($_POST, $model->searchableFields()); + $context = $model->getDefaultSearchContext(); + $results = $context->getResultSet($searchKeys); + if ($results) { + echo ""; + foreach($results as $row) { + $uri = Director::absoluteBaseUrl(); + echo "ID\">"; + foreach($model->searchableFields() as $key=>$val) { + echo ""; + } + echo ""; + } + echo "
"; + echo $row->getField($key); + echo "
"; + } else { + echo "

No results found

"; + } + } + } + + function view() { + $className = $this->urlParams['ClassName']; + $ID = $this->urlParams['ID']; + + if (in_array($className, $this->getManagedModels())) { + + $model = DataObject::get_by_id($className, $ID); + + $fields = $model->getCMSFields(); + + $form = new Form($this, $className, $fields, new FieldSet()); + $form->makeReadonly(); + $form->loadNonBlankDataFrom($model); + echo $form->forTemplate(); + } + } + + + } ?> \ No newline at end of file