Skip to content
This repository
Browse code

ENHANCEMENT SSF-124 customise displayed fields of page list view, add…

… children list view links
  • Loading branch information...
commit 7d9873472b51c362910f6d5610b9b855f3ae48b2 1 parent ea377b6
Normann Lou authored April 05, 2012
44  code/controllers/CMSMain.php
@@ -524,7 +524,7 @@ public function getEditForm($id = null, $fields = null) {
524 524
 	 * 
525 525
 	 * @return SS_List
526 526
 	 */
527  
-	public function getList() {
  527
+	public function getList(&$filterOnOff) {
528 528
 		$list = new DataList($this->stat('tree_class'));
529 529
 		
530 530
 		$request = $this->request;
@@ -535,26 +535,51 @@ public function getList() {
535 535
 				throw new Exception(sprintf('Invalid filter class passed: %s', $filterClass));
536 536
 			}
537 537
 			$filter = new $filterClass($request->requestVars());
  538
+			$filterOn = true;
538 539
 			foreach($pages=$filter->pagesIncluded() as $pageMap){
539 540
 				$ids[] = $pageMap['ID'];
540 541
 			}
  542
+			if(count($ids)) $list->where('"'.$this->stat('tree_class').'"."ID" IN ('.implode(",", $ids).')');
  543
+		}else{
  544
+			$list->filter("ParentID", 0);
541 545
 		}
542  
-		
543  
-		if(count($ids)) $list->where('"'.$this->stat('tree_class').'"."ID" IN ('.implode(",", $ids).')');
  546
+
544 547
 		return $list;
545 548
 	}
546 549
 	
547 550
 	public function getListView(){
548  
-		$list = $this->getList();
  551
+		$filterOn = false;
  552
+		$list = $this->getList($filterOn);
549 553
 		$gridFieldConfig = GridFieldConfig::create()->addComponents(
550 554
 			new GridFieldSortableHeader(),
551 555
 			new GridFieldDataColumns(),
552 556
 			new GridFieldPaginator(15),
553 557
 			new GridFieldEditButton(),
554  
-			new GridFieldDeleteAction(),
555 558
 			new GridFieldDetailForm()
556 559
 		);
557 560
 		$gridField = new GridField('Page','Pages', $list, $gridFieldConfig);
  561
+		
  562
+		if($filterOn){
  563
+			$gridField->setDisplayFields(array(
  564
+				'getTreeTitle' => _t('SiteTree.PAGETITLE', 'Page Title'),
  565
+				'Created' => _t('SiteTree.CREATED', 'Date Created'),
  566
+				'LastEdited' => _t('SiteTree.LASTUPDATED', 'Last Updated'),
  567
+			));
  568
+		}else{
  569
+			$gridField->setDisplayFields(array(
  570
+				'listChildrenLink' => "",
  571
+				'getTreeTitle' => _t('SiteTree.PAGETITLE', 'Page Title'),
  572
+				'Created' => _t('SiteTree.CREATED', 'Date Created'),
  573
+				'LastEdited' => _t('SiteTree.LASTUPDATED', 'Last Updated'),
  574
+			));
  575
+		}
  576
+		
  577
+		$gridField->setFieldCasting(array(
  578
+			'Created' => 'Date->Ago',
  579
+			'LastEdited' => 'Date->Ago',
  580
+			
  581
+		));
  582
+		
558 583
 		$listview = new Form(
559 584
 			$this,
560 585
 			'ListView',
@@ -563,6 +588,7 @@ public function getListView(){
563 588
 		);
564 589
 
565 590
 		$this->extend('updateListView', $listview);
  591
+		
566 592
 		$listview->disableSecurityToken();
567 593
 		return $listview;
568 594
 	}
@@ -587,6 +613,14 @@ public function currentPageID() {
587 613
 		
588 614
 		return $id;
589 615
 	}
  616
+	
  617
+	public function listchildren(){
  618
+		if(Director::is_ajax()){
  619
+			return $this;
  620
+		}else{
  621
+			
  622
+		}
  623
+	}
590 624
 
591 625
 	//------------------------------------------------------------------------------------------//
592 626
 	// Data saving handlers
7  code/model/SiteTree.php
@@ -2448,6 +2448,13 @@ function TreeTitle() {
2448 2448
 		Deprecation::notice('3.0', 'Use getTreeTitle() instead.');
2449 2449
 		return $this->getTreeTitle();
2450 2450
 	}
  2451
+	
  2452
+	function listChildrenLink(){
  2453
+		if($num = $this->numChildren()){
  2454
+			$link = singleton('CMSPagesController')->Link('listchildren')."/".$this->ID;
  2455
+			return '<a href="'.$link.'" class="list-children-link">'.$num.'</a>';
  2456
+		}
  2457
+	}
2451 2458
 
2452 2459
 	/**
2453 2460
 	 * TitleWithStatus will return the title in an <ins>, <del> or

0 notes on commit 7d98734

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