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 "
"; + echo $row->getField($key); + echo " | "; + } + 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