public function getEditForm($id = null, $fields = null)
 {
     $form = parent::getEditForm($id, $fields);
     if ($this->modelClass == 'Order') {
         $fields = $form->Fields();
         $gridField = $fields->fieldByName('Order');
         // Bulk manager
         $manager = new GridFieldBulkManager();
         $manager->removeBulkAction("bulkEdit");
         $manager->removeBulkAction("unLink");
         $manager->removeBulkAction("delete");
         $manager->addBulkAction('paid', 'Mark Paid', 'CommerceGridFieldBulkAction_Paid');
         $manager->addBulkAction('processing', 'Mark Processing', 'CommerceGridFieldBulkAction_Processing');
         $manager->addBulkAction('dispatched', 'Mark Dispatched', 'CommerceGridFieldBulkAction_Dispatched');
         // Add dispatch button
         $field_config = $gridField->getConfig();
         $field_config->addComponent($manager);
         // Update list of items for subsite (if used)
         if (class_exists('Subsite')) {
             $list = $gridField->getList()->filter(array('SubsiteID' => Subsite::currentSubsiteID()));
             $gridField->setList($list);
         }
     }
     $this->extend("updateEditForm", $form);
     return $form;
 }
 public function updateEditForm(&$form)
 {
     $commentsGrid = $form->Fields()->dataFieldByName("Comments");
     $gridConfig = $commentsGrid->getConfig();
     $bulkManger = $gridConfig->getComponentByType("GridFieldBulkManager");
     $gridConfig->removeComponent($bulkManger);
     // $bulkManger->removeBulkAction("markAsSpam");
     $manager = new GridFieldBulkManager(null, false);
     $manager->addBulkAction('markasmoderated', "Mark as Moderated", 'CommentsGridFieldBulkAction_MarkAsModerated', array('isAjax' => true, 'icon' => '', 'isDestructive' => false));
     $manager->addBulkAction('delete', _t('GRIDFIELD_BULK_MANAGER.DELETE_SELECT_LABEL', 'Delete'), 'GridFieldBulkActionDeleteHandler', array('isAjax' => true, 'icon' => 'delete', 'isDestructive' => true));
     $gridConfig->addComponent($manager);
 }
Esempio n. 3
0
 /**
  * @param string $sortField - Field to sort the blocks on. If this is set, it will also make the
  * 	blocks sortable in the CMS (requires SortableGridField module!)
  * @param array $allowedBlocks - a set of allowed class names, optionally mapped to titles
  * @param int $itemsPerPage - How many items per page should show up
  */
 public function __construct($sortField = null, $allowedBlocks = null, $itemsPerPage = null)
 {
     parent::__construct($itemsPerPage);
     // setup a bulk manager for block management
     $bulkManager = new GridFieldBulkManager();
     // remove the default actions
     $toRemove = array('bulkedit', 'bulkEdit', 'delete', 'unlink', 'unLink');
     $validActions = array_keys($bulkManager->getConfig('actions'));
     foreach ($toRemove as $key) {
         if (in_array($key, $validActions)) {
             $bulkManager->removeBulkAction($key);
         }
     }
     // add the actions in desired order
     $bulkManager->addBulkAction('publish', _t('PageBlock.PUBLISH', 'Publish'))->addBulkAction('unpublish', _t('PageBlock.UNPUBLISH', 'Unpublish'))->addBulkAction('bulkedit', _t('PageBlock.EDIT', 'Edit'), 'GridFieldBulkActionEditHandler', array('icon' => 'pencil'))->addBulkAction('versionedunlink', _t('PageBlock.UNLINK', 'Unlink'), 'GridFieldBulkActionVersionedUnlinkHandler', array('icon' => 'chain--minus'))->addBulkAction('versioneddelete', _t('PageBlock.DELETE', 'Delete'), 'GridFieldBulkActionVersionedDeleteHandler', array('isDestructive' => true, 'icon' => 'decline'));
     if ($sortField && class_exists('GridFieldOrderableRows')) {
         $this->addComponent(new GridFieldOrderableRows($sortField));
     }
     // remove the delete action, since unlinking is not required
     $this->removeComponent($this->getComponentByType('GridFieldDeleteAction'));
     // remove the search field since it doesn't make sense (cannot add existing, unless "stealing" from another page)
     $this->removeComponentsByType('GridFieldAddExistingAutocompleter');
     $this->addComponent(new GridFieldAddExistingSearchButton('buttons-before-right'));
     $this->addComponent(new GridFieldAddNewMultiClass(), 'GridFieldToolbarHeader');
     $this->addComponent($bulkManager);
     $this->getComponentByType('GridFieldDataColumns')->setDisplayFields(array('Title' => _t('Block.TITLE', 'Title'), 'i18n_singular_name' => _t('Block.TYPE', 'Type'), 'PublishedStatus' => _t('Block.STATUS', 'Status')));
     $this->setAllowedBlocks($allowedBlocks);
 }
 public function __construct($itemsPerPage = 25)
 {
     parent::__construct($itemsPerPage);
     // $this->addComponent(new GridFieldExportButton());
     $this->addComponent(new CommentsGridFieldAction());
     // Format column
     $columns = $this->getComponentByType('GridFieldDataColumns');
     $columns->setFieldFormatting(array('ParentTitle' => function ($value, &$item) {
         return sprintf('<a href="%s" class="cms-panel-link external-link action" target="_blank">%s</a>', Convert::raw2att($item->Link()), $item->obj('ParentTitle')->forTemplate());
     }));
     // Add bulk option
     $manager = new GridFieldBulkManager();
     $manager->addBulkAction('spam', 'Spam', 'CommentsGridFieldBulkAction_Handlers', array('isAjax' => true, 'icon' => 'cross', 'isDestructive' => false));
     $manager->addBulkAction('approve', 'Approve', 'CommentsGridFieldBulkAction_Handlers', array('isAjax' => true, 'icon' => 'cross', 'isDestructive' => false));
     $manager->removeBulkAction('bulkEdit');
     $manager->removeBulkAction('unLink');
     $this->addComponent($manager);
 }
 public function getEditForm($id = null, $fields = null)
 {
     $form = parent::getEditForm($id, $fields);
     $fields = $form->Fields();
     $config = null;
     // Bulk manager
     $manager = new GridFieldBulkManager();
     $manager->removeBulkAction("bulkEdit");
     $manager->removeBulkAction("unLink");
     // Manage orders
     if ($this->modelClass == 'Order') {
         $gridField = $fields->fieldByName('Order');
         $config = $gridField->getConfig();
         $manager->addBulkAction('cancelled', 'Mark Cancelled', 'OrdersFieldBulkActions');
         $manager->addBulkAction('paid', 'Mark Paid', 'OrdersFieldBulkActions');
         $manager->addBulkAction('processing', 'Mark Processing', 'OrdersFieldBulkActions');
         $manager->addBulkAction('dispatched', 'Mark Dispatched', 'OrdersFieldBulkActions');
         // Update list of items for subsite (if used)
         if (class_exists('Subsite')) {
             $list = $gridField->getList()->filter(array('SubsiteID' => Subsite::currentSubsiteID()));
             $gridField->setList($list);
         }
     }
     // Manage Estimates
     if ($this->modelClass == 'Estimate') {
         $gridField = $fields->fieldByName('Estimate');
         $config = $gridField->getConfig();
         // Update list of items for subsite (if used)
         if (class_exists('Subsite')) {
             $list = $gridField->getList()->filter(array('SubsiteID' => Subsite::currentSubsiteID()));
             $gridField->setList($list);
         }
     }
     // Set our default detailform and bulk manager
     if ($config) {
         $config->removeComponentsByType('GridFieldDetailForm')->addComponent($manager)->addComponent(new OrdersGridFieldDetailForm());
     }
     $this->extend("updateEditForm", $form);
     return $form;
 }
 /**
  *
  * @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);
 }
 public function updateEditForm(CMSForm &$form)
 {
     $fields = $form->Fields();
     $class = $this->owner->modelClass;
     $o = singleton($class);
     $gf = $form->Fields()->dataFieldByName($class);
     $config = $gf->getConfig();
     // If we have the bulk manager, enable by default
     if (class_exists('GridFieldBulkManager')) {
         if ($o->hasMethod('bulkManagerDisable') && $o->bulkManagerDisable) {
         } else {
             $config->addComponent($bulkManager = new GridFieldBulkManager());
             if ($o->hasMethod('bulkManagerAdd')) {
                 $actions = $o->bulkManagerAdd();
                 foreach ($actions as $key => $action) {
                     $bulkHandler = isset($action['Handler']) ? $action['Handler'] : null;
                     $bulkConfig = isset($action['Config']) ? $action['Config'] : null;
                     $bulkManager->addBulkAction($action['Name'], $action['Label'], $bulkHandler, $bulkConfig);
                 }
             }
         }
     }
     // If we have the export all button (form-extras module), enable
     if (class_exists('GridFieldExportAllButton')) {
         $config->addComponent(new GridFieldExportAllButton('before'));
     }
     if (!Director::isDev() || !Permission::check('ADMIN')) {
         return;
     }
     // Add buttons
     $config->addComponent(new GridFieldButtonRow('after'));
     $config->addComponent($btnEmpty = new DevToolkitEmptyButton('buttons-after-left'));
     if ($o->hasMethod('provideFake')) {
         $config->addComponent($btnAddFake = new DevToolkitAddFakeButton('buttons-after-left'));
     }
     if ($o->hasExtension('GeoExtension')) {
         $config->addComponent($btnAddFake = new DevToolkitFakeLocationsButton('buttons-after-left'));
     }
     $config->addComponent($btnDump = new DevToolkitDumpButton('buttons-after-left'));
     // Show session message
     $message = self::SessionMessage();
     if ($message) {
         $fields->insertBefore(new LiteralField("dev_message", "<div class='message {$message->Type}'>{$message->Content}</div>"), $gf->getName());
     }
 }
 public function getEditForm($id = null, $fields = null)
 {
     $form = parent::getEditForm($id, $fields);
     $class = $this->sanitiseClassName($this->modelClass);
     $gridField = $form->Fields()->fieldByName($class);
     $config = $gridField->getConfig();
     // Add bulk editing to gridfield
     $manager = new GridFieldBulkManager();
     $manager->removeBulkAction("unLink");
     if ($class == 'Contact') {
         $manager->addBulkAction("assign", _t("Contacts.AssignToList", "Assign to list"), "BulkActionAssignToList", array('isAjax' => false, 'icon' => 'pencil', 'isDestructive' => false));
     } else {
         $config->removeComponentsByType("GridFieldExportButton")->removeComponentsByType("GridFieldPrintButton");
     }
     $config->addComponents($manager);
     $this->extend("updateEditForm", $form);
     return $form;
 }
 public function getEditForm($id = null, $fields = null)
 {
     $form = parent::getEditForm($id, $fields);
     $params = $this->request->requestVar('q');
     // Bulk manager
     $manager = new GridFieldBulkManager();
     $manager->removeBulkAction("unLink");
     $manager->addBulkAction('disable', 'Disable', 'CatalogueProductBulkAction');
     $manager->addBulkAction('enable', 'Enable', 'CatalogueProductBulkAction');
     if ($this->modelClass == 'Product') {
         $gridField = $form->Fields()->fieldByName('Product');
         $field_config = $gridField->getConfig();
         // Re add creation button and update grid field
         $add_button = new GridFieldAddNewButton('buttons-before-left');
         $add_button->setButtonName(_t("CatalogueAdmin.AddProduct", "Add Product"));
         $field_config->removeComponentsByType('GridFieldPrintButton')->removeComponentsByType('GridFieldAddNewButton')->removeComponentsByType('GridFieldDetailForm')->addComponents($add_button, $manager, new CatalogueEnableDisableDetailForm());
         // Set the page length
         $field_config->getComponentByType('GridFieldPaginator')->setItemsPerPage($this->config()->product_page_length);
         // Update list of items for subsite (if used)
         if (class_exists('Subsite')) {
             $list = $gridField->getList()->filter(array('SubsiteID' => Subsite::currentSubsiteID()));
             $gridField->setList($list);
         }
     }
     // Alterations for Hiarachy on product cataloge
     if ($this->modelClass == 'Category') {
         $gridField = $form->Fields()->fieldByName('Category');
         // Set custom record editor
         $record_editor = new CatalogueEnableDisableDetailForm();
         $record_editor->setItemRequestClass('CatalogueCategory_ItemRequest');
         // Create add button and update grid field
         $add_button = new GridFieldAddNewButton('toolbar-header-left');
         $add_button->setButtonName(_t("CatalogueAdmin.AddCategory", "Add Category"));
         // Tidy up category config
         $field_config = $gridField->getConfig();
         $field_config->removeComponentsByType('GridFieldExportButton')->removeComponentsByType('GridFieldPrintButton')->removeComponentsByType('GridFieldDetailForm')->removeComponentsByType('GridFieldAddNewButton')->addComponents($record_editor, $add_button, $manager, GridFieldOrderableRows::create('Sort'));
         // Set the page length
         $field_config->getComponentByType('GridFieldPaginator')->setItemsPerPage($this->config()->category_page_length);
         // Setup hierarchy view
         $parentID = $this->request->requestVar('ParentID');
         if ($parentID) {
             $field_config->addComponent(GridFieldLevelup::create($parentID)->setLinkSpec('?ParentID=%d')->setAttributes(array('data-pjax' => 'ListViewForm,Breadcrumbs')));
         }
         // Find data colums, so we can add link to view children
         $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
         // Don't allow navigating into children nodes on filtered lists
         $fields = array('Title' => 'Title', 'URLSegment' => 'URLSegement');
         if (!$params) {
             $fields = array_merge(array('listChildrenLink' => ''), $fields);
         }
         $columns->setDisplayFields($fields);
         $columns->setFieldCasting(array('Title' => 'HTMLText', 'URLSegment' => 'Text'));
         $controller = $this;
         $columns->setFieldFormatting(array('listChildrenLink' => function ($value, &$item) use($controller) {
             return sprintf('<a class="list-children-link" data-pjax-target="ListViewForm" href="%s?ParentID=%d">&#9658;</a>', $controller->Link(), $item->ID);
         }));
         // Update list of items for subsite (if used)
         if (class_exists('Subsite')) {
             $list = $gridField->getList()->filter(array('SubsiteID' => Subsite::currentSubsiteID()));
             $gridField->setList($list);
         }
     }
     $this->extend("updateEditForm", $form);
     return $form;
 }