public function testShowEditLinksWithAdminPermission() { $this->logInWithPermission('ADMIN'); $content = new CSSContentParser($this->gridField->FieldHolder()); $editLinks = $content->getBySelector('.edit-link'); $this->assertEquals(2, count($editLinks), 'Edit links should show when logged in.'); }
public function testShowDeleteButtonsWithAdminPermission() { $this->logInWithPermission('ADMIN'); $content = new CSSContentParser($this->gridField->FieldHolder()); $deleteButtons = $content->getBySelector('.gridfield-button-delete'); $this->assertEquals(3, count($deleteButtons), 'Delete buttons should show when logged in.'); }
function testThereIsNoPaginatorWhenOnlyOnePage() { // We set the itemsPerPage to an reasonably big number so as to avoid test broke from small changes on the fixture YML file $total = $this->list->count(); $this->gridField->getConfig()->getComponentByType("GridFieldPaginator")->setItemsPerPage($total); $fieldHolder = $this->gridField->FieldHolder(); $content = new CSSContentParser($fieldHolder); // Check that there is no paginator render into the footer $this->assertEquals(0, count($content->getBySelector('.datagrid-pagination'))); // Check that there is still 'View 1 - 4 of 4' part on the left of the paginator $this->assertEquals(1, count($content->getBySelector('.pagination-records-number'))); }
/** * Returns the whole gridfield rendered with all the attached components * * @param array $properties * @return string */ public function FieldHolder($properties = array()) { Requirements::javascript(THIRDPARTY_DIR . '/jquery-livequery/jquery.livequery.min.js'); $modulePath = dirname(dirname(__FILE__)); $modulePath = str_replace(BASE_PATH, '', $modulePath); $modulePath = substr($modulePath, 1); Requirements::javascript($modulePath . '/js/feedblock_manager.js'); Requirements::css($modulePath . '/css/GridFieldRefreshButton.css'); return parent::FieldHolder($properties); }
/** * Returns the whole gridfield rendered with all the attached components * @return string */ public function FieldHolder($properties = array()) { Requirements::block(FRAMEWORK_DIR . '/css/GridField.css'); Requirements::themedCSS('FrontEndGridField', FRONTEND_GRIDFIELD_BASE); Requirements::add_i18n_javascript(FRAMEWORK_DIR . '/javascript/lang'); Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js'); Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/javascript/ssui.core.js'); Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/javascript/lib.js'); Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js'); Requirements::javascript(FRONTEND_GRIDFIELD_BASE . '/javascript/FrontEndGridField.js'); return parent::FieldHolder(); }
/** * @covers GridField::FieldHolder */ public function testCanViewOnlyOddIDs() { $this->logInWithPermission(); $list = new ArrayList(array(new GridFieldTest_Permissions(array("ID" => 1, "Email" => "*****@*****.**", 'Name' => 'Ongi Schwimmer')), new GridFieldTest_Permissions(array("ID" => 2, "Email" => "*****@*****.**", 'Name' => 'Klaus Lozenge')), new GridFieldTest_Permissions(array("ID" => 3, "Email" => "*****@*****.**", 'Name' => 'Otto Fischer')))); $config = new GridFieldConfig(); $config->addComponent(new GridFieldDataColumns()); $obj = new GridField('testfield', 'testfield', $list, $config); $form = new Form(new Controller(), 'mockform', new FieldList(array($obj)), new FieldList()); $content = new CSSContentParser($obj->FieldHolder()); $members = $content->getBySelector('.ss-gridfield-item tr'); $this->assertEquals(2, count($members)); $this->assertEquals((string) $members[0]->td[0], 'Ongi Schwimmer', 'First object Name should be Ongi Schwimmer'); $this->assertEquals((string) $members[0]->td[1], '*****@*****.**', 'First object Email should be ongi.schwimmer@example.org'); $this->assertEquals((string) $members[1]->td[0], 'Otto Fischer', 'Second object Name should be Otto Fischer'); $this->assertEquals((string) $members[1]->td[1], '*****@*****.**', 'Second object Email should be otto.fischer@example.org'); }
/** * Handles the action. * Prepares the popup to load the pring preview * * @param GridField $gridField GridField to handle action for * @param array $recordIDs Record IDs to handle action for * @param array $data Data to handle action for * * @return void * * @author Sebastian Diel <*****@*****.**> * @since 14.03.2013 */ public function handle(GridField $gridField, $recordIDs, $data) { $orders = new ArrayList(); foreach ($recordIDs as $orderID) { $order = SilvercartOrder::get_by_id('SilvercartOrder', $orderID); if ($order->exists()) { $order->markAsSeen(); $orders->push($order); } } $gridField->getConfig()->addComponent(new SilvercartGridFieldPopupTrigger(SilvercartPrint::getPrintURLForMany($orders))); return $gridField->FieldHolder(); }
/** * Handles requests to assign a new block area to a block item * * @param GridField $grid * @param SS_HTTPRequest $request * @return SS_HTTPResponse */ public function handleBlockTypeAssignment($grid, $request) { $list = $grid->getList(); // @TODO: do we need this? (copied from GridFieldOrderableRows::handleReorder) // $modelClass = $grid->getModelClass(); // if ($list instanceof ManyManyList && !singleton($modelClass)->canView()) { // $this->httpError(403); // } else if(!($list instanceof ManyManyList) && !singleton($modelClass)->canEdit()) { // $this->httpError(403); // } $blockid = $request->postVar('block_id'); $blocktype = $request->postVar('block_type'); $block = $list->byID($blockid); // Update item with correct Area assigned (custom query required to write m_m_extraField) $block->ClassName = $blocktype; $block->write(); //print_r($block->record); // // @TODO: improve this custom query to be more robust? // DB::query(sprintf( // "UPDATE `%s` SET `%s` = '%s' WHERE `BlockID` = %d", // 'SiteTree_Blocks', // 'BlockArea', // $blockarea, // $blockid // )); return $grid->FieldHolder(); }
/** * Handles requests to move an item to the previous or next page. */ public function handleMoveToPage(GridField $grid, $request) { if (!($paginator = $grid->getConfig()->getComponentByType('GridFieldPaginator'))) { $this->httpError(404, 'Paginator component not found'); } $move = $request->postVar('move'); $field = $this->getSortField(); $list = $grid->getList(); $manip = $grid->getManipulatedList(); $existing = $manip->map('ID', $field)->toArray(); $values = $existing; $order = array(); $id = isset($move['id']) ? (int) $move['id'] : null; $to = isset($move['page']) ? $move['page'] : null; if (!isset($values[$id])) { $this->httpError(400, 'Invalid item ID'); } $this->populateSortValues($list); $page = (int) $grid->getState()->GridFieldPaginator->currentPage ?: 1; $per = $paginator->getItemsPerPage(); if ($to == 'prev') { $swap = $list->limit(1, ($page - 1) * $per - 1)->first(); $values[$swap->ID] = $swap->{$field}; $order[] = $id; $order[] = $swap->ID; foreach ($existing as $_id => $sort) { if ($id != $_id) { $order[] = $_id; } } } elseif ($to == 'next') { $swap = $list->limit(1, $page * $per)->first(); $values[$swap->ID] = $swap->{$field}; foreach ($existing as $_id => $sort) { if ($id != $_id) { $order[] = $_id; } } $order[] = $swap->ID; $order[] = $id; } else { $this->httpError(400, 'Invalid page target'); } $this->reorderItems($list, $values, $order); return $grid->FieldHolder(); }
/** * @param array $properties * @return HTMLText */ public function FieldHolder($properties = array()) { $stateHash = $this->getStateHash(); if ($previousState = Session::get($stateHash)) { $this->state->setValue($previousState); } return parent::FieldHolder($properties); }