From f101595921e2a3e03ba4ffbdd6afedf12e62568d Mon Sep 17 00:00:00 2001 From: Normann Lou Date: Thu, 5 Apr 2012 15:39:23 +1200 Subject: [PATCH] FEATURE SSF-124 first version of tree list view added --- code/controllers/CMSMain.php | 62 ++++++++++++++++++- javascript/CMSMain.js | 28 ++++++++- .../Includes/CMSPagesController_Content.ss | 11 ++-- 3 files changed, 93 insertions(+), 8 deletions(-) diff --git a/code/controllers/CMSMain.php b/code/controllers/CMSMain.php index 5ab2ae6c..bb2d6a47 100644 --- a/code/controllers/CMSMain.php +++ b/code/controllers/CMSMain.php @@ -43,6 +43,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr 'SiteTreeAsUL', 'getshowdeletedsubtree', 'batchactions', + 'ListView', + 'getListView', ); public function init() { @@ -434,6 +436,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr * @return Form */ public function getEditForm($id = null, $fields = null) { + if(!$id) $id = $this->currentPageID(); $form = parent::getEditForm($id); @@ -506,7 +509,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr } $this->extend('updateEditForm', $form); - return $form; } else if($id) { return new Form($this, "EditForm", new FieldList( @@ -515,6 +517,64 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr } } + /** + * Returns the files and subfolders contained in the currently selected folder, + * defaulting to the root node. Doubles as search results, if any search parameters + * are set through {@link SearchForm()}. + * + * @return SS_List + */ + public function getList() {//return 'haha'; + $list = new DataList($this->stat('tree_class')); + + $request = $this->request; + $filter = null; + if($filterClass = $request->requestVar('FilterClass')){ + if(!is_subclass_of($filterClass, 'CMSSiteTreeFilter')) { + throw new Exception(sprintf('Invalid filter class passed: %s', $filterClass)); + } + $filter = new $filterClass($request->requestVars()); + $ids = array(); + foreach($pages=$filter->pagesIncluded() as $pageMap){ + $ids[] = $pageMap['ID']; + } + } + + if(count($ids)) $list->where('"'.$this->stat('tree_class').'"."ID" IN ('.implode(",", $ids).')'); + return $list; + } + + public function getListView(){ + $list = $this->getList(); + $gridFieldConfig = GridFieldConfig::create()->addComponents( + new GridFieldSortableHeader(), + new GridFieldDataColumns(), + new GridFieldPaginator(15), + new GridFieldEditButton(), + new GridFieldDeleteAction(), + new GridFieldDetailForm() + ); + $gridField = new GridField('Page','Pages', $list, $gridFieldConfig); + $listview = new Form( + $this, + 'ListView', + new FieldList($gridField), + new FieldList() + ); + + $this->extend('updateListView', $listview); + $listview->disableSecurityToken(); + return $listview; + } + + public function getListViewHTML(){ + return $this->getListView()->forTemplate(); + } + + public function ListView() { + return $this->getListView(); + } + public function currentPageID() { $id = parent::currentPageID(); diff --git a/javascript/CMSMain.js b/javascript/CMSMain.js index 36abf2ac..a0d85f21 100644 --- a/javascript/CMSMain.js +++ b/javascript/CMSMain.js @@ -48,8 +48,10 @@ //this.find(':submit').attr('disabled', true); this.find(':submit[name=action_doSearchTree]').addClass('loading'); - - this._reloadSitetree(this.serializeArray()); + + var params = this.serializeArray(); + this._reloadSitetree(params); + this._reloadListview(params) return false; }, @@ -87,6 +89,28 @@ errorMessage('Could not filter site tree
' + response.responseText); } ); + }, + + _reloadListview: function(params){ + $('.cms-list').refresh(params); + + } + }); + + $('#cms-content-listview .cms-list').entwine({ + refresh: function(params){ + var self = this; + + $.ajax({ + url: this.data('url-list'), + data: params, + success: function(data, status, xhr) { + self.html(data); + }, + error: function(xhr, status, e) { + errorMessage(e); + } + }); } }); diff --git a/templates/Includes/CMSPagesController_Content.ss b/templates/Includes/CMSPagesController_Content.ss index 9d0b09c9..f4dbe2ee 100644 --- a/templates/Includes/CMSPagesController_Content.ss +++ b/templates/Includes/CMSPagesController_Content.ss @@ -15,10 +15,10 @@
  • <% _t('CMSPagesController.GalleryView', 'Gallery View') %>
  • + -->
  • <% _t('CMSPagesController.ListView', 'List View') %>
  • - --> @@ -43,12 +43,13 @@ - -