Ejemplo n.º 1
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);
 }
 function updateEditForm(Form $form)
 {
     /* @var $owner ModelAdmin */
     $owner = $this->owner;
     $class = $owner->modelClass;
     $classConfig = $owner->config();
     $gridfield = $form->Fields()->dataFieldByName($class);
     if (!$gridfield) {
         return;
     }
     /* @var $config GridFieldConfig */
     $config = $gridfield->getConfig();
     // Bulk manage
     if ($classConfig->bulk_manage && class_exists('GridFieldBulkManager')) {
         $already = $config->getComponentByType('GridFieldBulkManager');
         if (!$already) {
             $config->addComponent($bulkManager = new GridFieldBulkManager());
             $bulkManager->removeBulkAction('unLink');
         }
     }
     if ($classConfig->export_csv) {
         /* @var $export GridFieldExportButton */
         $export = $config->getComponentByType('GridFieldExportButton');
         $export->setExportColumns(ExcelImportExport::exportFieldsForClass($class));
     } else {
         $config->removeComponentsByType('GridFieldExportButton');
     }
     if ($classConfig->export_excel) {
         $config->addComponent(new ExcelGridFieldExportButton('buttons-before-left'));
     }
 }
 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);
 }
 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;
 }
 protected function setupGridField(GridField $gridfield, Config_ForClass $classConfig)
 {
     if (!$gridfield) {
         return;
     }
     $config = $gridfield->getConfig();
     $class = $gridfield->getModelClass();
     // More item per page
     $paginator = $config->getComponentByType('GridFieldPaginator');
     $paginator->setItemsPerPage(50);
     // Bulk manage
     if ($classConfig->bulk_manage && class_exists('GridFieldBulkManager')) {
         $already = $config->getComponentByType('GridFieldBulkManager');
         if (!$already) {
             $config->addComponent($bulkManager = new GridFieldBulkManager());
             $bulkManager->removeBulkAction('unLink');
         }
     }
     // Better export
     if ($classConfig->export_csv) {
         /* @var $export GridFieldExportButton */
         $export = $config->getComponentByType('GridFieldExportButton');
         $export->setExportColumns(ExcelImportExport::exportFieldsForClass($class));
     } else {
         $config->removeComponentsByType('GridFieldExportButton');
     }
     if ($classConfig->export_excel) {
         if ($class == 'Group') {
             $config->addComponent(new GridFieldButtonRow('after'));
         }
         $config->addComponent(new ExcelGridFieldExportButton('buttons-after-left'));
     }
 }
 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;
 }
Ejemplo n.º 8
0
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $gridFieldConfig = GridFieldConfig_RecordEditor::create();
     //$gridFieldConfig->addComponent(new GridFieldBulkEditingTools());
     $gridFieldConfig->addComponent($gbu = new GridFieldBulkUpload());
     $editableFields = array('Title', 'Caption', 'Aperture', 'ShutterSpeed', 'Image');
     $gridFieldConfig->addComponent($gbm = new GridFieldBulkManager($editableFields));
     $gridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder'));
     $galleryimagesi18n = _t('GalleryImage.PLURALNAME', 'Gallery Images');
     //$gbu->setConfig('fileRelationName','Image');
     $gbu->setUfConfig('folderName', 'galleries/' . $this->ID);
     $gbm->setConfig('editableFields', $editableFields);
     // This is no longer available... $gbm->setConfig('fieldsNameBlacklist', array('Lat', 'Lon', 'ZoomLevel'));
     $gridfield = new GridField('GalleryImages', $galleryimagesi18n, $this->GalleryImages()->sort('"SortOrder"'), $gridFieldConfig);
     $fields->addFieldToTab('Root.' . $galleryimagesi18n, $gridfield);
     $fields->addFieldToTab('Root.Date', new DateField('GalleryDate'));
     return $fields;
 }
 /**
  *
  * @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);
 }
Ejemplo n.º 10
0
 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;
 }
 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);
     $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;
 }