Skip to content
This repository
Browse code

FEATURE SSF-124 first version of tree list view added

  • Loading branch information...
commit f101595921e2a3e03ba4ffbdd6afedf12e62568d 1 parent 68aa59b
Normann Lou authored April 05, 2012
62  code/controllers/CMSMain.php
@@ -43,6 +43,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
43 43
 		'SiteTreeAsUL',
44 44
 		'getshowdeletedsubtree',
45 45
 		'batchactions',
  46
+		'ListView',
  47
+		'getListView',
46 48
 	);
47 49
 	
48 50
 	public function init() {
@@ -434,6 +436,7 @@ public function getRecord($id, $versionID = null) {
434 436
 	 * @return Form
435 437
 	 */
436 438
 	public function getEditForm($id = null, $fields = null) {
  439
+
437 440
 		if(!$id) $id = $this->currentPageID();
438 441
 		$form = parent::getEditForm($id);
439 442
 		
@@ -506,7 +509,6 @@ public function getEditForm($id = null, $fields = null) {
506 509
 			}
507 510
 
508 511
 			$this->extend('updateEditForm', $form);
509  
-
510 512
 			return $form;
511 513
 		} else if($id) {
512 514
 			return new Form($this, "EditForm", new FieldList(
@@ -515,6 +517,64 @@ public function getEditForm($id = null, $fields = null) {
515 517
 		}
516 518
 	}
517 519
 	
  520
+	/**
  521
+	 * Returns the files and subfolders contained in the currently selected folder,
  522
+	 * defaulting to the root node. Doubles as search results, if any search parameters
  523
+	 * are set through {@link SearchForm()}.
  524
+	 * 
  525
+	 * @return SS_List
  526
+	 */
  527
+	public function getList() {//return 'haha';
  528
+		$list = new DataList($this->stat('tree_class'));
  529
+		
  530
+		$request = $this->request;
  531
+		$filter = null;
  532
+		if($filterClass = $request->requestVar('FilterClass')){
  533
+			if(!is_subclass_of($filterClass, 'CMSSiteTreeFilter')) {
  534
+				throw new Exception(sprintf('Invalid filter class passed: %s', $filterClass));
  535
+			}
  536
+			$filter = new $filterClass($request->requestVars());
  537
+			$ids = array();
  538
+			foreach($pages=$filter->pagesIncluded() as $pageMap){
  539
+				$ids[] = $pageMap['ID'];
  540
+			}
  541
+		}
  542
+		
  543
+		if(count($ids)) $list->where('"'.$this->stat('tree_class').'"."ID" IN ('.implode(",", $ids).')');
  544
+		return $list;
  545
+	}
  546
+	
  547
+	public function getListView(){
  548
+		$list = $this->getList();
  549
+		$gridFieldConfig = GridFieldConfig::create()->addComponents(
  550
+			new GridFieldSortableHeader(),
  551
+			new GridFieldDataColumns(),
  552
+			new GridFieldPaginator(15),
  553
+			new GridFieldEditButton(),
  554
+			new GridFieldDeleteAction(),
  555
+			new GridFieldDetailForm()
  556
+		);
  557
+		$gridField = new GridField('Page','Pages', $list, $gridFieldConfig);
  558
+		$listview = new Form(
  559
+			$this,
  560
+			'ListView',
  561
+			new FieldList($gridField),
  562
+			new FieldList()
  563
+		);
  564
+
  565
+		$this->extend('updateListView', $listview);
  566
+		$listview->disableSecurityToken();
  567
+		return $listview;
  568
+	}
  569
+	
  570
+	public function getListViewHTML(){
  571
+		return $this->getListView()->forTemplate();
  572
+	}
  573
+	
  574
+	public function ListView() {
  575
+		return $this->getListView();
  576
+	}
  577
+	
518 578
 	public function currentPageID() {
519 579
 		$id = parent::currentPageID();
520 580
 		
28  javascript/CMSMain.js
@@ -48,8 +48,10 @@
48 48
 				//this.find(':submit').attr('disabled', true);
49 49
 		
50 50
 				this.find(':submit[name=action_doSearchTree]').addClass('loading');
51  
-		
52  
-				this._reloadSitetree(this.serializeArray());
  51
+				
  52
+				var params = this.serializeArray();
  53
+				this._reloadSitetree(params);
  54
+				this._reloadListview(params)
53 55
 
54 56
 				return false;
55 57
 			},
@@ -87,6 +89,28 @@
87 89
 						errorMessage('Could not filter site tree<br />' + response.responseText);
88 90
 					}
89 91
 				);		
  92
+			},
  93
+			
  94
+			_reloadListview: function(params){
  95
+				$('.cms-list').refresh(params);
  96
+				
  97
+			}
  98
+		});
  99
+		
  100
+		$('#cms-content-listview .cms-list').entwine({
  101
+			refresh: function(params){
  102
+				var self = this;
  103
+				
  104
+				$.ajax({
  105
+					url: this.data('url-list'),
  106
+					data: params,
  107
+					success: function(data, status, xhr) {
  108
+						self.html(data);
  109
+					},
  110
+					error: function(xhr, status, e) {
  111
+						errorMessage(e);
  112
+					}
  113
+				});
90 114
 			}
91 115
 		});
92 116
 	
11  templates/Includes/CMSPagesController_Content.ss
@@ -15,10 +15,10 @@
15 15
 					<li>
16 16
 						<a href="#cms-content-galleryview" class="content-galleryview"><% _t('CMSPagesController.GalleryView', 'Gallery View') %></a>
17 17
 					</li>
  18
+					-->
18 19
 					<li>
19 20
 						<a href="#cms-content-listview" class="content-listview"><% _t('CMSPagesController.ListView', 'List View') %></a>
20 21
 					</li>
21  
-					-->
22 22
 				</ul>
23 23
 			</div>
24 24
 		</div>
@@ -43,12 +43,13 @@
43 43
 			</div>
44 44
 
45 45
 		</div>
46  
-
47  
-		<!--		
  46
+	
48 47
 		<div id="cms-content-listview">
49  
-			<i>Not implemented yet</i>
  48
+			<div class="cms-list" data-url-list="$Link(getListViewHTML)">
  49
+				$ListView
  50
+			</div>
50 51
 		</div>
51  
-		
  52
+		<!--
52 53
 		<div id="cms-content-galleryview">
53 54
 			<i>Not implemented yet</i>
54 55
 		</div>

0 notes on commit f101595

Please sign in to comment.
Something went wrong with that request. Please try again.