FEATURE SSF-124 first version of tree list view added

This commit is contained in:
Normann Lou 2012-04-05 15:39:23 +12:00
parent 68aa59b25e
commit f101595921
3 changed files with 93 additions and 8 deletions

View File

@ -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();

View File

@ -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<br />' + 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);
}
});
}
});

View File

@ -15,10 +15,10 @@
<li>
<a href="#cms-content-galleryview" class="content-galleryview"><% _t('CMSPagesController.GalleryView', 'Gallery View') %></a>
</li>
-->
<li>
<a href="#cms-content-listview" class="content-listview"><% _t('CMSPagesController.ListView', 'List View') %></a>
</li>
-->
</ul>
</div>
</div>
@ -43,12 +43,13 @@
</div>
</div>
<!--
<div id="cms-content-listview">
<i>Not implemented yet</i>
<div class="cms-list" data-url-list="$Link(getListViewHTML)">
$ListView
</div>
</div>
<!--
<div id="cms-content-galleryview">
<i>Not implemented yet</i>
</div>