From 876c809a7da4bf68a4a1c9c695e9c8a823f430e4 Mon Sep 17 00:00:00 2001 From: Stig Lindqvist Date: Tue, 21 Feb 2012 16:02:54 +1300 Subject: [PATCH] ENHANCEMENT Filterpanel for assetadmin --- code/controllers/AssetAdmin.php | 35 ++++++++++++++++++++++++++ templates/Includes/AssetAdmin_Tools.ss | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/code/controllers/AssetAdmin.php b/code/controllers/AssetAdmin.php index e083c1ea..177cc1c6 100644 --- a/code/controllers/AssetAdmin.php +++ b/code/controllers/AssetAdmin.php @@ -31,6 +31,7 @@ class AssetAdmin extends LeftAndMain { 'savefile', 'deleteUnusedThumbnails' => 'ADMIN', 'SyncForm', + 'filter', ); /** @@ -103,6 +104,40 @@ JS return $form; } + /** + * Returns a form for filtering of files and assets gridfield + * + * @return Form + * @see AssetAdmin.js + */ + public function FilterForm() { + $fields = new FieldList(); + // Below is the filters that this field should filter on + $fields->push(new TextField('Title')); + $fields->push(new TextField('ClassName','Type')); + + $actions = new FieldList(); + $actions->push(new FormAction('doFilter', 'Filter')); + $actions->push(new ResetFormAction('doResetFilter', 'Clear Filter')); + + $form = new Form($this, 'filter', $fields, $actions); + $form->addExtraClass('cms-filter-form'); + // This have to match data-name attribute on the gridfield so that the javascript selectors work + $form->setAttribute('data-gridfield', 'File'); + return $form; + } + + /** + * If this method get's called, it means that javascript didn't hook into to the submit on + * FilterForm and we can currently not do a Filter without javascript. + * + * @param SS_HTTPRequest $data + * @throws SS_HTTPResponse_Exception + */ + public function filter(SS_HTTPRequest $data) { + throw new SS_HTTPResponse_Exception('Filterpanel doesn\'t work without javascript enabled.'); + } + public function AddForm() { $form = parent::AddForm(); $form->Actions()->fieldByName('action_doAdd')->setTitle(_t('AssetAdmin.ActionAdd', 'Add folder')); diff --git a/templates/Includes/AssetAdmin_Tools.ss b/templates/Includes/AssetAdmin_Tools.ss index 6431b873..60f37ce1 100644 --- a/templates/Includes/AssetAdmin_Tools.ss +++ b/templates/Includes/AssetAdmin_Tools.ss @@ -1,7 +1,7 @@