/** * @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'); }
/** * @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($itemsPerPage = null) { parent::__construct($itemsPerPage); $this->addComponent(new GridFieldButtonRow('before')); $this->addComponent(new GridFieldSiteTreeAddNewButton('buttons-before-left')); $this->addComponent(new GridFieldToolbarHeader()); $this->addComponent(new GridFieldSortableHeader()); $this->addComponent(new GridFieldFilterHeader()); $this->addComponent(new GridFieldDataColumns()); $this->addComponent(new GridFieldSiteTreeEditButton()); $this->addComponent(new GridFieldPageCount('toolbar-header-right')); $this->addComponent($pagination = new GridFieldPaginator($itemsPerPage)); $this->addComponent(new GridFieldSiteTreeState()); $pagination->setThrowExceptionOnBadDataType(true); }
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'); }
/** * Manipulate the datalist as needed by this grid modifier. * @param GridField $gridField Grid Field Reference * @param SS_List $dataList Data List to adjust * @return DataList Modified Data List */ public function getManipulatedData(GridField $gridField, SS_List $dataList) { $this->setShowAllMode($gridField); $dataList = parent::getManipulatedData($gridField, $dataList); $showAllMode = $this->getShowAllMode(); if ($showAllMode) { $dataList = $dataList->limit(999, 0); $component = $gridField->getConfig()->getComponentByType('GridFieldPaginatorWithShowAll'); $component->setItemsPerPage(1 + $dataList->count()); } return $dataList; }
/** * * @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); }
/** * @return FieldList */ public function getCMSFields() { $self = $this; $this->beforeUpdateCMSFields(function ($fields) use($self) { // define tabs $fields->findOrMakeTab('Root.FormContent', _t('UserDefinedForm.FORM', 'Form')); $fields->findOrMakeTab('Root.FormOptions', _t('UserDefinedForm.CONFIGURATION', 'Configuration')); $fields->findOrMakeTab('Root.Recipients', _t('UserDefinedForm.RECIPIENTS', 'Recipients')); $fields->findOrMakeTab('Root.Submissions', _t('UserDefinedForm.SUBMISSIONS', 'Submissions')); // field editor $fields->addFieldToTab('Root.FormContent', new FieldEditor('Fields', 'Fields', '', $self)); // text to show on complete $onCompleteFieldSet = new CompositeField($label = new LabelField('OnCompleteMessageLabel', _t('UserDefinedForm.ONCOMPLETELABEL', 'Show on completion')), $editor = new HtmlEditorField('OnCompleteMessage', '', _t('UserDefinedForm.ONCOMPLETEMESSAGE', $self->OnCompleteMessage))); $onCompleteFieldSet->addExtraClass('field'); $editor->setRows(3); $label->addExtraClass('left'); // Define config for email recipients $emailRecipientsConfig = GridFieldConfig_RecordEditor::create(10); $emailRecipientsConfig->getComponentByType('GridFieldAddNewButton')->setButtonName(_t('UserDefinedForm.ADDEMAILRECIPIENT', 'Add Email Recipient')); // who do we email on submission $emailRecipients = new GridField('EmailRecipients', _t('UserDefinedForm.EMAILRECIPIENTS', 'Email Recipients'), $self->EmailRecipients(), $emailRecipientsConfig); $emailRecipients->getConfig()->getComponentByType('GridFieldDetailForm')->setItemRequestClass('UserDefinedForm_EmailRecipient_ItemRequest'); $fields->addFieldsToTab('Root.FormOptions', $onCompleteFieldSet); $fields->addFieldToTab('Root.Recipients', $emailRecipients); $fields->addFieldsToTab('Root.FormOptions', $self->getFormOptions()); // view the submissions $submissions = new GridField('Submissions', _t('UserDefinedForm.SUBMISSIONS', 'Submissions'), $self->Submissions()->sort('Created', 'DESC')); // make sure a numeric not a empty string is checked against this int column for SQL server $parentID = !empty($self->ID) ? $self->ID : 0; // get a list of all field names and values used for print and export CSV views of the GridField below. $columnSQL = <<<SQL SELECT "Name", "Title" FROM "SubmittedFormField" LEFT JOIN "SubmittedForm" ON "SubmittedForm"."ID" = "SubmittedFormField"."ParentID" WHERE "SubmittedForm"."ParentID" = '{$parentID}' ORDER BY "Title" ASC SQL; $columns = DB::query($columnSQL)->map(); $config = new GridFieldConfig(); $config->addComponent(new GridFieldToolbarHeader()); $config->addComponent($sort = new GridFieldSortableHeader()); $config->addComponent($filter = new UserFormsGridFieldFilterHeader()); $config->addComponent(new GridFieldDataColumns()); $config->addComponent(new GridFieldEditButton()); $config->addComponent(new GridState_Component()); $config->addComponent(new GridFieldDeleteAction()); $config->addComponent(new GridFieldPageCount('toolbar-header-right')); $config->addComponent($pagination = new GridFieldPaginator(25)); $config->addComponent(new GridFieldDetailForm()); $config->addComponent($export = new GridFieldExportButton()); $config->addComponent($print = new GridFieldPrintButton()); /** * Support for {@link https://github.com/colymba/GridFieldBulkEditingTools} */ if (class_exists('GridFieldBulkManager')) { $config->addComponent(new GridFieldBulkManager()); } $sort->setThrowExceptionOnBadDataType(false); $filter->setThrowExceptionOnBadDataType(false); $pagination->setThrowExceptionOnBadDataType(false); // attach every column to the print view form $columns['Created'] = 'Created'; $filter->setColumns($columns); // print configuration $print->setPrintHasHeader(true); $print->setPrintColumns($columns); // export configuration $export->setCsvHasHeader(true); $export->setExportColumns($columns); $submissions->setConfig($config); $fields->addFieldToTab('Root.Submissions', $submissions); $fields->addFieldToTab('Root.FormOptions', new CheckboxField('DisableSaveSubmissions', _t('UserDefinedForm.SAVESUBMISSIONS', 'Disable Saving Submissions to Server'))); }); $fields = parent::getCMSFields(); return $fields; }
/** * @return FieldList */ public function getCMSFields() { // call updateCMSFields after userforms SiteTree::disableCMSFieldsExtensions(); $fields = parent::getCMSFields(); SiteTree::enableCMSFieldsExtensions(); // define tabs $fields->findOrMakeTab('Root.FormContent', _t('UserDefinedForm.FORM', 'Form')); $fields->findOrMakeTab('Root.FormOptions', _t('UserDefinedForm.CONFIGURATION', 'Configuration')); $fields->findOrMakeTab('Root.Submissions', _t('UserDefinedForm.SUBMISSIONS', 'Submissions')); // field editor $fields->addFieldToTab("Root.FormContent", new FieldEditor("Fields", 'Fields', "", $this)); // text to show on complete $onCompleteFieldSet = new CompositeField($label = new LabelField('OnCompleteMessageLabel', _t('UserDefinedForm.ONCOMPLETELABEL', 'Show on completion')), $editor = new HtmlEditorField("OnCompleteMessage", "", _t('UserDefinedForm.ONCOMPLETEMESSAGE', $this->OnCompleteMessage))); $onCompleteFieldSet->addExtraClass('field'); $editor->setRows(3); $label->addExtraClass('left'); // Set the summary fields of UserDefinedForm_EmailRecipient dynamically via config system Config::inst()->update('UserDefinedForm_EmailRecipient', 'summary_fields', array('EmailAddress' => _t('UserDefinedForm.EMAILADDRESS', 'Email'), 'EmailSubject' => _t('UserDefinedForm.EMAILSUBJECT', 'Subject'), 'EmailFrom' => _t('UserDefinedForm.EMAILFROM', 'From'))); // who do we email on submission $emailRecipients = new GridField("EmailRecipients", _t('UserDefinedForm.EMAILRECIPIENTS', 'Email Recipients'), $this->EmailRecipients(), GridFieldConfig_RecordEditor::create(10)); $emailRecipients->getConfig()->getComponentByType('GridFieldAddNewButton')->setButtonName(_t('UserDefinedForm.ADDEMAILRECIPIENT', 'Add Email Recipient')); $fields->addFieldsToTab("Root.FormOptions", $onCompleteFieldSet); $fields->addFieldToTab("Root.FormOptions", $emailRecipients); $fields->addFieldsToTab("Root.FormOptions", $this->getFormOptions()); // view the submissions $submissions = new GridField("Reports", _t('UserDefinedForm.SUBMISSIONS', 'Submissions'), $this->Submissions()->sort('Created', 'DESC')); // make sure a numeric not a empty string is checked against this int column for SQL server $parentID = !empty($this->ID) ? $this->ID : 0; // get a list of all field names and values used for print and export CSV views of the GridField below. $columnSQL = <<<SQL SELECT "Name", "Title" FROM "SubmittedFormField" LEFT JOIN "SubmittedForm" ON "SubmittedForm"."ID" = "SubmittedFormField"."ParentID" WHERE "SubmittedForm"."ParentID" = '{$parentID}' ORDER BY "Title" ASC SQL; $columns = DB::query($columnSQL)->map(); $config = new GridFieldConfig(); $config->addComponent(new GridFieldToolbarHeader()); $config->addComponent($sort = new GridFieldSortableHeader()); $config->addComponent($filter = new UserFormsGridFieldFilterHeader()); $config->addComponent(new GridFieldDataColumns()); $config->addComponent(new GridFieldEditButton()); $config->addComponent(new GridState_Component()); $config->addComponent(new GridFieldDeleteAction()); $config->addComponent(new GridFieldPageCount('toolbar-header-right')); $config->addComponent($pagination = new GridFieldPaginator(25)); $config->addComponent(new GridFieldDetailForm()); $config->addComponent($export = new GridFieldExportButton()); $config->addComponent($print = new GridFieldPrintButton()); $sort->setThrowExceptionOnBadDataType(false); $filter->setThrowExceptionOnBadDataType(false); $pagination->setThrowExceptionOnBadDataType(false); // attach every column to the print view form $columns['Created'] = 'Created'; $filter->setColumns($columns); // print configuration $print->setPrintHasHeader(true); $print->setPrintColumns($columns); // export configuration $export->setCsvHasHeader(true); $export->setExportColumns($columns); $submissions->setConfig($config); $fields->addFieldToTab("Root.Submissions", $submissions); $fields->addFieldToTab("Root.FormOptions", new CheckboxField('DisableSaveSubmissions', _t('UserDefinedForm.SAVESUBMISSIONS', "Disable Saving Submissions to Server"))); $this->extend('updateCMSFields', $fields); return $fields; }
/** * * @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); }
/** * 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; })); }
/** * Returns a FieldList with which to create the CMS editing form * * @return FieldList The fields to be displayed in the CMS. */ function getCMSFields() { Requirements::javascript("forum/javascript/ForumAccess.js"); Requirements::css("forum/css/Forum_CMS.css"); $fields = parent::getCMSFields(); $fields->addFieldToTab("Root.Access", new HeaderField(_t('Forum.ACCESSPOST', 'Who can post to the forum?'), 2)); $fields->addFieldToTab("Root.Access", $optionSetField = new OptionsetField("CanPostType", "", array("Inherit" => "Inherit", "Anyone" => _t('Forum.READANYONE', 'Anyone'), "LoggedInUsers" => _t('Forum.READLOGGEDIN', 'Logged-in users'), "OnlyTheseUsers" => _t('Forum.READLIST', 'Only these people (choose from list)'), "NoOne" => _t('Forum.READNOONE', 'Nobody. Make Forum Read Only')))); $optionSetField->addExtraClass('ForumCanPostTypeSelector'); $fields->addFieldsToTab("Root.Access", array(new TreeMultiselectField("PosterGroups", _t('Forum.GROUPS', "Groups")), new OptionsetField("CanAttachFiles", _t('Forum.ACCESSATTACH', 'Can users attach files?'), array("1" => _t('Forum.YES', 'Yes'), "0" => _t('Forum.NO', 'No'))))); //Dropdown of forum category selection. $categories = ForumCategory::get()->map(); $fields->addFieldsToTab("Root.Main", DropdownField::create('CategoryID', _t('Forum.FORUMCATEGORY', 'Forum Category'), $categories), 'Content'); //GridField Config - only need to attach or detach Moderators with existing Member accounts. $moderatorsConfig = GridFieldConfig::create()->addComponent(new GridFieldButtonRow('before'))->addComponent(new GridFieldAddExistingAutocompleter('buttons-before-right'))->addComponent(new GridFieldToolbarHeader())->addComponent($sort = new GridFieldSortableHeader())->addComponent($columns = new GridFieldDataColumns())->addComponent(new GridFieldDeleteAction(true))->addComponent(new GridFieldPageCount('toolbar-header-right'))->addComponent($pagination = new GridFieldPaginator()); // Use GridField for Moderator management $moderators = GridField::create('Moderators', _t('MODERATORS', 'Moderators for this forum'), $this->Moderators(), $moderatorsConfig); $columns->setDisplayFields(array('Nickname' => 'Nickname', 'FirstName' => 'First name', 'Surname' => 'Surname', 'Email' => 'Email', 'LastVisited.Long' => 'Last Visit')); $sort->setThrowExceptionOnBadDataType(false); $pagination->setThrowExceptionOnBadDataType(false); $fields->addFieldToTab('Root.Moderators', $moderators); return $fields; }