/**
  * @covers GridField::__construct
  * @covers GridField::getConfig
  * @covers GridField::setComponents
  * @covers GridField::getDefaultConfig
  */
 public function testGridFieldDefaultConfig()
 {
     $obj = new GridField('testfield', 'testfield');
     $expectedComponents = new ArrayList(array(new GridFieldToolbarHeader(), $sort = new GridFieldSortableHeader(), $filter = new GridFieldFilterHeader(), new GridFieldDataColumns(), new GridFieldPageCount('toolbar-header-right'), $pagination = new GridFieldPaginator(), new GridState_Component()));
     $sort->setThrowExceptionOnBadDataType(false);
     $filter->setThrowExceptionOnBadDataType(false);
     $pagination->setThrowExceptionOnBadDataType(false);
     $this->assertEquals($expectedComponents, $obj->getConfig()->getComponents(), 'Testing default Config');
 }
    public function __construct($canAdd = true, $canEdit = true, $canDelete = true, $editableRows = false, $aboveOrBelow = false)
    {
        parent::__construct();
        $this->blockManager = Injector::inst()->get('BlockManager');
        $controllerClass = Controller::curr()->class;
        // Get available Areas (for page) or all in case of ModelAdmin
        if ($controllerClass == 'CMSPageEditController') {
            $currentPage = Controller::curr()->currentPage();
            $areasFieldSource = $this->blockManager->getAreasForPageType($currentPage->ClassName);
        } else {
            $areasFieldSource = $this->blockManager->getAreasForTheme();
        }
        // EditableColumns only makes sense on Saveable parenst (eg Page), or inline changes won't be saved
        if ($editableRows) {
            $this->addComponent($editable = new GridFieldEditableColumns());
            $displayfields = array('TypeForGridfield' => array('title' => _t('Block.BlockType', 'Block Type'), 'field' => 'LiteralField'), 'Title' => array('title' => _t('Block.Title', 'Title'), 'field' => 'ReadonlyField'), 'BlockArea' => array('title' => _t('Block.BlockArea', 'Block Area') . '
						            ', 'callback' => function () use($areasFieldSource) {
                return DropdownField::create('BlockArea', 'Block Area', $areasFieldSource)->setHasEmptyDefault(true);
            }), 'isPublishedNice' => array('title' => _t('Block.IsPublishedField', 'Published'), 'field' => 'ReadonlyField'), 'UsageListAsString' => array('title' => _t('Block.UsageListAsString', 'Used on'), 'field' => 'LiteralField'));
            if ($aboveOrBelow) {
                $displayfields['AboveOrBelow'] = array('title' => _t('GridFieldConfigBlockManager.AboveOrBelow', 'Above or Below'), 'callback' => function () {
                    return DropdownField::create('AboveOrBelow', _t('GridFieldConfigBlockManager.AboveOrBelow', 'Above or Below'), BlockSet::config()->get('above_or_below_options'));
                });
            }
            $editable->setDisplayFields($displayfields);
        } else {
            $this->addComponent($dcols = new GridFieldDataColumns());
            $displayfields = array('singular_name' => _t('Block.BlockType', 'Block Type'), 'Title' => _t('Block.Title', 'Title'), 'BlockArea' => _t('Block.BlockArea', 'Block Area'), 'isPublishedNice' => _t('Block.IsPublishedField', 'Published'), 'UsageListAsString' => _t('Block.UsageListAsString', 'Used on'));
            $dcols->setDisplayFields($displayfields);
            $dcols->setFieldCasting(array('UsageListAsString' => 'HTMLText->Raw'));
        }
        $this->addComponent(new GridFieldButtonRow('before'));
        $this->addComponent(new GridFieldToolbarHeader());
        $this->addComponent(new GridFieldDetailForm());
        $this->addComponent($sort = new GridFieldSortableHeader());
        $this->addComponent($filter = new GridFieldFilterHeader());
        $this->addComponent(new GridFieldDetailForm());
        if ($controllerClass == 'BlockAdmin' && class_exists('GridFieldCopyButton')) {
            $this->addComponent(new GridFieldCopyButton());
        }
        $filter->setThrowExceptionOnBadDataType(false);
        $sort->setThrowExceptionOnBadDataType(false);
        if ($canAdd) {
            $multiClass = new GridFieldAddNewMultiClass();
            $classes = $this->blockManager->getBlockClasses();
            $multiClass->setClasses($classes);
            $this->addComponent($multiClass);
            //$this->addComponent(new GridFieldAddNewButton());
        }
        if ($canEdit) {
            $this->addComponent(new GridFieldEditButton());
        }
        if ($canDelete) {
            $this->addComponent(new GridFieldDeleteAction(true));
        }
        return $this;
    }
 /**
  * @param int $itemsPerPage - How many items per page should show up
  */
 public function __construct($itemsPerPage = null)
 {
     parent::__construct();
     $this->addComponent(new GridFieldToolbarHeader());
     $this->addComponent($sort = new GridFieldSortableHeader());
     $this->addComponent($filter = new GridFieldFilterHeader());
     $this->addComponent(new GridFieldDataColumns());
     $this->addComponent(new GridFieldPageCount('toolbar-header-right'));
     $this->addComponent($pagination = new GridFieldPaginator($itemsPerPage));
     $sort->setThrowExceptionOnBadDataType(false);
     $filter->setThrowExceptionOnBadDataType(false);
     $pagination->setThrowExceptionOnBadDataType(false);
     $this->extend('updateConfig');
 }
 public function __construct()
 {
     parent::__construct();
     $this->addComponent(new GridFieldButtonRow('before'));
     $this->addComponent(new GridFieldAddNewButton('buttons-before-left'));
     $this->addComponent(new GridFieldToolbarHeader());
     $this->addComponent($sort = new GridFieldSortableHeader());
     $this->addComponent($filter = new GridFieldFilterHeader());
     $this->addComponent(new GridFieldModuleColumns());
     $this->addComponent(new GridFieldDataColumns());
     $this->addComponent(new GridFieldEditButton());
     $this->addComponent(new GridFieldDeleteAction());
     $this->addComponent(new PageModuleVersionedDataObjectDetailsForm());
     $sort->setThrowExceptionOnBadDataType(false);
     $filter->setThrowExceptionOnBadDataType(false);
     $this->extend('updateConfig');
 }
 public function __construct($flexi)
 {
     $this->addComponent(new GridFieldToolbarHeader());
     $this->addComponent($sort = new GridFieldSortableHeader());
     $this->addComponent($filter = new GridFieldFilterHeader());
     $this->addComponent(new GridFieldDataColumns());
     $this->addComponent(new GridFieldEditButton());
     $this->addComponent(new GridFieldDeleteAction(false));
     $this->addComponent(new GridFieldDetailForm());
     $this->addComponent($export = new GridFieldExportButton());
     $this->addComponent($pagination = new GridFieldPaginator());
     $sort->setThrowExceptionOnBadDataType(false);
     $filter->setThrowExceptionOnBadDataType(false);
     $pagination->setThrowExceptionOnBadDataType(false);
     // add submission values to exports
     ///////////////////////////////////
     $export->setExportColumns($this->getCSVColumns($flexi));
 }
 /**
  *
  * @param int $itemsPerPage - How many items per page should show up
  */
 public function __construct($itemsPerPage = null)
 {
     parent::__construct();
     $this->addComponent(new GridFieldButtonRow('before'));
     $this->addComponent(new GridFieldAddNewButton('buttons-before-left'));
     $this->addComponent(new GridFieldToolbarHeader());
     $this->addComponent($sort = new GridFieldSortableHeader());
     $this->addComponent($filter = new GridFieldFilterHeader());
     $this->addComponent(new GridFieldDataColumns());
     $this->addComponent(new GridFieldEditButton());
     $this->addComponent(new GridFieldDeleteAction());
     $this->addComponent(new GridFieldPageCount('toolbar-header-right'));
     $this->addComponent($pagination = new GridFieldPaginator($itemsPerPage));
     $this->addComponent(new GridFieldDetailForm());
     $sort->setThrowExceptionOnBadDataType(false);
     $filter->setThrowExceptionOnBadDataType(false);
     $pagination->setThrowExceptionOnBadDataType(false);
     $this->extend('updateConfig');
 }
 /**
  *
  * @param array $classname Name of class who's subclasses will be added to form
  * @param int $itemsPerPage - How many items per page should show up
  * @param boolean | string $sorting Allow sorting of rows, either false or the name of the sort column
  */
 public function __construct($classname, $itemsPerPage = null, $sort_col = false)
 {
     parent::__construct();
     // Setup Bulk manager
     $manager = new GridFieldBulkManager();
     $manager->removeBulkAction("unLink");
     $manager->addBulkAction('disable', 'Disable', 'CatalogueProductBulkAction');
     $manager->addBulkAction('enable', 'Enable', 'CatalogueProductBulkAction');
     /// Setup add new button
     $add_button = new GridFieldAddNewMultiClass("buttons-before-left");
     $add_button->setClasses($this->get_subclasses($classname));
     $this->addComponent(new GridFieldButtonRow('before'));
     $this->addComponent(new GridFieldToolbarHeader());
     $this->addComponent($sort = new GridFieldSortableHeader());
     $this->addComponent($filter = new GridFieldFilterHeader());
     $this->addComponent(new GridFieldDataColumns());
     $this->addComponent(new GridFieldEditButton());
     $this->addComponent(new GridFieldDeleteAction());
     $this->addComponent(new GridFieldPageCount('toolbar-header-right'));
     $this->addComponent($pagination = new GridFieldPaginator($itemsPerPage));
     $this->addComponent(new GridFieldExportButton("buttons-before-right"));
     // If we are manageing a category, use the relevent field, else use
     // product
     if ($classname == "Category") {
         $this->addComponent(new CatalogueCategoryDetailForm());
         $add_button->setItemRequestClass("CatalogueCategoryDetailForm_ItemRequest");
     } else {
         $this->addComponent(new CatalogueEnableDisableDetailForm());
         $add_button->setItemRequestClass("CatalogueEnableDisableDetailForm_ItemRequest");
     }
     $this->addComponent($add_button);
     if ($sort_col) {
         $this->addComponent(GridFieldOrderableRows::create($sort_col));
     }
     $sort->setThrowExceptionOnBadDataType(false);
     $filter->setThrowExceptionOnBadDataType(false);
     $pagination->setThrowExceptionOnBadDataType(false);
 }
Exemplo n.º 8
0
	/**
	 *
	 * @param int $itemsPerPage - How many items per page should show up
	 */
	public function __construct($itemsPerPage=null) {
		$this->addComponent(new GridFieldToolbarHeader());
		$this->addComponent(new GridFieldAddExistingAutocompleter('toolbar-header-left'));
		$this->addComponent(new GridFieldAddNewButton('toolbar-header-right'));
		$this->addComponent($sort = new GridFieldSortableHeader());
		$this->addComponent($filter = new GridFieldFilterHeader());
		$this->addComponent(new GridFieldDataColumns());
		$this->addComponent(new GridFieldEditButton());
		$this->addComponent(new GridFieldDeleteAction());
		$this->addComponent($pagination = new GridFieldPaginator($itemsPerPage));
		$this->addComponent(new GridFieldDetailForm());

		$sort->setThrowExceptionOnBadDataType(false);
		$filter->setThrowExceptionOnBadDataType(false);
		$pagination->setThrowExceptionOnBadDataType(false);
	}
Exemplo n.º 9
0
 /**
  * Constructor
  * 
  * @param Int $itemsPerPage How many items on each page to display
  */
 public function __construct($itemsPerPage = null)
 {
     $this->addComponent(new GridFieldButtonRow('before'));
     $this->addComponent(new GridFieldAddNewButton('buttons-before-left'));
     $this->addComponent(new GridFieldToolbarHeader());
     $this->addComponent($sort = new GridFieldSortableHeader());
     $this->addComponent($filter = new GridFieldFilterHeader());
     $this->addComponent(new GridFieldDataColumns());
     $this->addComponent(new GridFieldEditButton());
     $this->addComponent(new GridFieldDeleteAction());
     $this->addComponent($pagination = new GridFieldPaginator($itemsPerPage));
     $detailForm = new GridFieldDetailForm();
     $detailForm->setItemRequestClass('GridFieldDetailForm_HasManyItemRequest');
     $this->addComponent($detailForm);
     $sort->setThrowExceptionOnBadDataType(false);
     $filter->setThrowExceptionOnBadDataType(false);
     $pagination->setThrowExceptionOnBadDataType(false);
 }
 /**
  * Loads the components, sets default properties.
  *
  * @param int $itemsPerPage How many items per page should show up
  * 
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 08.03.2013
  */
 public function __construct($itemsPerPage = null)
 {
     $this->addComponent($sort = new GridFieldSortableHeader());
     $this->addComponent($filter = new GridFieldFilterHeader());
     $this->addComponent(new SilvercartGridFieldDataColumns());
     $this->addComponent($pagination = new GridFieldPaginator($itemsPerPage));
     $this->addComponent(new GridFieldDetailForm());
     $sort->setThrowExceptionOnBadDataType(false);
     $filter->setThrowExceptionOnBadDataType(false);
     $pagination->setThrowExceptionOnBadDataType(false);
 }
 /**
  *
  * @param int $itemsPerPage - How many items per page should show up
  */
 public function __construct($itemsPerPage = null, $currentStage = 'Latest')
 {
     $this->addComponent(new PublishableGridFieldStage($currentStage));
     $this->addComponent(new GridFieldButtonRow('before'));
     $this->addComponent(new GridFieldAddNewButton('buttons-before-left'));
     $this->addComponent(new GridFieldToolbarHeader());
     $this->addComponent($sort = new GridFieldSortableHeader());
     $this->addComponent($filter = new GridFieldFilterHeader());
     $this->addComponent($columns = new GridFieldDataColumns());
     $this->addComponent(new PublishableGridFieldDeleteAction());
     $this->addComponent(new PublishableGridFieldPublishAction());
     $this->addComponent(new PublishableGridFieldEditButton());
     $this->addComponent(new GridFieldPageCount('toolbar-header-right'));
     $this->addComponent($pagination = new GridFieldPaginator($itemsPerPage));
     $this->addComponent(new PublishableGridFieldDetailForm());
     $sort->setThrowExceptionOnBadDataType(false);
     $filter->setThrowExceptionOnBadDataType(false);
     $pagination->setThrowExceptionOnBadDataType(false);
     $columns->setFieldFormatting(array('Title' => function ($value, &$item) {
         $badge = array();
         if ($item->ExistsOnLive && $item->IsModifiedOnStage) {
             $badge['class'] = 'modified';
             $badge['title'] = _t('PublishableGridFieldStatusColumns.ModifiedStage', 'Modified');
         } elseif ($item->IsAddedToStage) {
             $badge['class'] = 'addedtodraft';
             $badge['title'] = _t('PublishableGridFieldStatusColumns.Stage', 'Draft');
         }
         $return = $item->Title;
         if (isset($badge['class']) && isset($badge['title'])) {
             $return .= sprintf("<span class=\"badge %s\">%s</span>", 'status-' . Convert::raw2xml($badge['class']), Convert::raw2xml($badge['title']));
         }
         return $return;
     }));
 }
    public function __construct($canAdd = true, $canEdit = true, $canDelete = true, $editableRows = false, $aboveOrBelow = false)
    {
        parent::__construct();
        $this->blockManager = Injector::inst()->get('BlockManager');
        $controllerClass = Controller::curr()->class;
        // Get available Areas (for page) or all in case of ModelAdmin
        if ($controllerClass == 'CMSPageEditController') {
            $currentPage = Controller::curr()->currentPage();
            $areasFieldSource = $this->blockManager->getAreasForPageType($currentPage->ClassName);
        } else {
            $areasFieldSource = $this->blockManager->getAreasForTheme();
        }
        // EDIT
        $blockTypeArray = $this->blockManager->getBlockClasses();
        // /EDIT
        // EditableColumns only makes sense on Saveable parenst (eg Page), or inline changes won't be saved
        if ($editableRows) {
            // set project-dir in cookie to be accessible as fallback from js
            Cookie::set('js-project-dir', project(), 90, null, null, false, false);
            $this->addComponent($editable = new GridFieldEditableColumns());
            $displayfields = array('ClassName' => array('title' => _t('Block.BlockType', 'Block Type') . '
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'callback' => function () use($blockTypeArray) {
                return DropdownField::create('ClassName', 'Block Type', $blockTypeArray)->addExtraClass('select2blocktype')->setAttribute('data-project-dir', project());
            }), 'Title' => array('title' => _t('Block.TitleName', 'Block Name'), 'field' => 'TextField'), 'BlockArea' => array('title' => _t('Block.BlockArea', 'Block Area') . '
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'callback' => function () use($areasFieldSource) {
                return DropdownField::create('BlockArea', 'Block Area', $areasFieldSource)->setHasEmptyDefault(true);
            }), 'isPublishedNice' => array('title' => _t('Block.IsPublishedField', 'Published'), 'field' => 'ReadonlyField'), 'UsageListAsString' => array('title' => _t('Block.UsageListAsString', 'Used on'), 'field' => 'ReadonlyField'));
            if ($aboveOrBelow) {
                $displayfields['AboveOrBelow'] = array('title' => _t('GridFieldConfigBlockManager.AboveOrBelow', 'Above or Below'), 'callback' => function () {
                    return DropdownField::create('AboveOrBelow', _t('GridFieldConfigBlockManager.AboveOrBelow', 'Above or Below'), BlockSet::config()->get('above_or_below_options'));
                });
            }
            $editable->setDisplayFields($displayfields);
            // EDIT
            $this->addComponent($erow = new EditableBlockRow());
            // /EDIT
        } else {
            $this->addComponent($dcols = new GridFieldDataColumns());
            $displayfields = array('singular_name' => _t('Block.BlockType', 'Block Type'), 'Title' => _t('Block.TitleName', 'Block Name'), 'BlockArea' => _t('Block.BlockArea', 'Block Area'), 'isPublishedNice' => _t('Block.IsPublishedField', 'Published'), 'UsageListAsString' => _t('Block.UsageListAsString', 'Used on'));
            $dcols->setDisplayFields($displayfields);
            $dcols->setFieldCasting(array('UsageListAsString' => 'HTMLText->Raw'));
        }
        $this->addComponent(new GridFieldButtonRow('before'));
        // EDIT
        $this->addComponent(new GridFieldButtonRow('after'));
        // /EDIT
        $this->addComponent(new GridFieldToolbarHeader());
        $this->addComponent(new GridFieldDetailForm());
        // EDIT
        //$this->addComponent($sort = new GridFieldSortableHeader());
        //$this->addComponent($filter = new GridFieldFilterHeader());
        //$this->addComponent(new GridFieldDetailForm());
        //$filter->setThrowExceptionOnBadDataType(false);
        //$sort->setThrowExceptionOnBadDataType(false);
        // load enhancements module (eg inline editing etc, needs save action @TODO: move to SiteTree only?
        if (class_exists('GF_BlockEnhancements')) {
            $this->addComponent(new GF_BlockEnhancements());
        }
        // stuff only for BlockAdmin
        if ($controllerClass == 'BlockAdmin') {
            $this->addComponent($sort = new GridFieldSortableHeader());
            $sort->setThrowExceptionOnBadDataType(false);
            $this->addComponent($filter = new GridFieldFilterHeader());
            $filter->setThrowExceptionOnBadDataType(false);
        } else {
            // only for GF on SiteTree
            $this->addComponent(new GridFieldTitleHeader());
            $this->addComponent(new GridFieldFooter());
            // groupable
            $this->addComponent(new GridFieldGroupable('BlockArea', 'Area', 'none', $areasFieldSource));
            //            var_dump($areasFieldSource);
            //            // Get available Areas (for page) enhancements inactive when in ModelAdmin/BlockAdmin
            //            if (Controller::curr() && Controller::curr()->class == 'CMSPageEditController') {
            //                // Provide defined blockAreas to JS
            //                $blockManager = Injector::inst()->get('BlockManager');
            ////            $blockAreas = $blockManager->getAreasForPageType( Controller::curr()->currentPage()->ClassName );
            //                $blockAreas = $blockManager->getAreasForPageType( Controller::curr()->currentPage()->ClassName );
            //            }
        }
        if ($canAdd) {
            $multiClass = new GridFieldAddNewMultiClass('after');
            $classes = $this->blockManager->getBlockClasses();
            $multiClass->setClasses($classes);
            $this->addComponent($multiClass);
            //$this->addComponent(new GridFieldAddNewButton());
        }
        // /EDIT
        if ($controllerClass == 'BlockAdmin' && class_exists('GridFieldCopyButton')) {
            $this->addComponent(new GridFieldCopyButton());
        }
        if ($canEdit) {
            $this->addComponent(new GridFieldEditButton());
        }
        if ($canDelete) {
            $this->addComponent(new GridFieldDeleteAction(true));
        }
        return $this;
    }