/**
  * Place the print button in a <p> tag below the field
  *
  * @param GridField
  *
  * @return array
  */
 public function getHTMLFragments($gridField)
 {
     $button = new GridField_FormAction($gridField, 'print', _t('TableListField.Print', 'Print'), 'print', null);
     $button->setAttribute('data-icon', 'grid_print');
     $button->addExtraClass('gridfield-button-print');
     $button->addExtraClass('font-icon-print');
     return array($this->targetFragment => '<p class="grid-print-button">' . $button->Field() . '</p>');
 }
 /**
  * Place the export button in a <p> tag below the field
  *
  * @param GridField $gridField
  * @return array
  */
 public function getHTMLFragments($gridField)
 {
     $button = new GridField_FormAction($gridField, 'export', _t('TableListField.CSVEXPORT', 'Export to CSV'), 'export', null);
     $button->setAttribute('data-icon', 'download-csv');
     $button->addExtraClass('no-ajax font-icon-down-circled action_export');
     $button->setForm($gridField->getForm());
     return array($this->targetFragment => '<p class="grid-csv-button">' . $button->Field() . '</p>');
 }
 /**
  *
  * @param GridField $gridField
  * @return string[] - HTML
  */
 public function getHTMLFragments($gridField)
 {
     $dataClass = $gridField->getModelClass();
     $forTemplate = new ArrayData(array());
     $forTemplate->Fields = new FieldList();
     $searchField = new TextField('gridfield_relationsearch', _t('GridField.RelationSearch', "Relation search"));
     $searchField->setAttribute('data-search-url', Controller::join_links($gridField->Link('search')));
     $searchField->setAttribute('placeholder', $this->getPlaceholderText($dataClass));
     $searchField->addExtraClass('relation-search no-change-track action_gridfield_relationsearch');
     $findAction = new GridField_FormAction($gridField, 'gridfield_relationfind', _t('GridField.Find', "Find"), 'find', 'find');
     $findAction->setAttribute('data-icon', 'relationfind');
     $findAction->addExtraClass('action_gridfield_relationfind');
     $addAction = new GridField_FormAction($gridField, 'gridfield_relationadd', _t('GridField.LinkExisting', "Link Existing"), 'addto', 'addto');
     $addAction->setAttribute('data-icon', 'chain--plus');
     $addAction->addExtraClass('action_gridfield_relationadd');
     // If an object is not found, disable the action
     if (!is_int($gridField->State->GridFieldAddRelation(null))) {
         $addAction->setReadonly(true);
     }
     $forTemplate->Fields->push($searchField);
     $forTemplate->Fields->push($findAction);
     $forTemplate->Fields->push($addAction);
     if ($form = $gridField->getForm()) {
         $forTemplate->Fields->setForm($form);
     }
     $template = SSViewer::get_templates_by_class($this, '', __CLASS__);
     return array($this->targetFragment => $forTemplate->renderWith($template));
 }
 /**
  * Determines arguments to be passed to the template for building this field
  *
  * @param GridField $gridField
  * @return ArrayData If paging is available this will be an ArrayData
  * object of paging details with these parameters:
  * <ul>
  *	<li>OnlyOnePage:				boolean - Is there only one page?</li>
  *  <li>FirstShownRecord:			integer - Number of the first record displayed</li>
  *  <li>LastShownRecord:			integer - Number of the last record displayed</li>
  *  <li>NumRecords:					integer - Total number of records</li>
  *	<li>NumPages:					integer - The number of pages</li>
  *	<li>CurrentPageNum (optional):	integer - If OnlyOnePage is false, the number of the current page</li>
  *  <li>FirstPage (optional):		GridField_FormAction - Button to go to the first page</li>
  *	<li>PreviousPage (optional):	GridField_FormAction - Button to go to the previous page</li>
  *	<li>NextPage (optional):		GridField_FormAction - Button to go to the next page</li>
  *	<li>LastPage (optional):		GridField_FormAction - Button to go to last page</li>
  * </ul>
  */
 public function getTemplateParameters(GridField $gridField)
 {
     if (!$this->checkDataType($gridField->getList())) {
         return null;
     }
     $state = $this->getGridPagerState($gridField);
     // Figure out which page and record range we're on
     $totalRows = $this->totalItems;
     if (!$totalRows) {
         return null;
     }
     $totalPages = (int) ceil($totalRows / $this->itemsPerPage);
     if ($totalPages == 0) {
         $totalPages = 1;
     }
     $firstShownRecord = ($state->currentPage - 1) * $this->itemsPerPage + 1;
     if ($firstShownRecord > $totalRows) {
         $firstShownRecord = $totalRows;
     }
     $lastShownRecord = $state->currentPage * $this->itemsPerPage;
     if ($lastShownRecord > $totalRows) {
         $lastShownRecord = $totalRows;
     }
     // If there is only 1 page for all the records in list, we don't need to go further
     // to sort out those first page, last page, pre and next pages, etc
     // we are not render those in to the paginator.
     if ($totalPages === 1) {
         return new ArrayData(array('OnlyOnePage' => true, 'FirstShownRecord' => $firstShownRecord, 'LastShownRecord' => $lastShownRecord, 'NumRecords' => $totalRows, 'NumPages' => $totalPages));
     } else {
         // First page button
         $firstPage = new GridField_FormAction($gridField, 'pagination_first', 'First', 'paginate', 1);
         $firstPage->addExtraClass('btn btn-secondary btn--no-text font-icon-angle-double-left ss-gridfield-firstpage');
         if ($state->currentPage == 1) {
             $firstPage = $firstPage->performDisabledTransformation();
         }
         // Previous page button
         $previousPageNum = $state->currentPage <= 1 ? 1 : $state->currentPage - 1;
         $previousPage = new GridField_FormAction($gridField, 'pagination_prev', 'Previous', 'paginate', $previousPageNum);
         $previousPage->addExtraClass('btn btn-secondary btn--no-text font-icon-angle-left ss-gridfield-previouspage');
         if ($state->currentPage == 1) {
             $previousPage = $previousPage->performDisabledTransformation();
         }
         // Next page button
         $nextPageNum = $state->currentPage >= $totalPages ? $totalPages : $state->currentPage + 1;
         $nextPage = new GridField_FormAction($gridField, 'pagination_next', 'Next', 'paginate', $nextPageNum);
         $nextPage->addExtraClass('btn btn-secondary btn--no-text font-icon-angle-right ss-gridfield-nextpage');
         if ($state->currentPage == $totalPages) {
             $nextPage = $nextPage->performDisabledTransformation();
         }
         // Last page button
         $lastPage = new GridField_FormAction($gridField, 'pagination_last', 'Last', 'paginate', $totalPages);
         $lastPage->addExtraClass('btn btn-secondary btn--no-text font-icon-angle-double-right ss-gridfield-lastpage');
         if ($state->currentPage == $totalPages) {
             $lastPage = $lastPage->performDisabledTransformation();
         }
         // Render in template
         return new ArrayData(array('OnlyOnePage' => false, 'FirstPage' => $firstPage, 'PreviousPage' => $previousPage, 'CurrentPageNum' => $state->currentPage, 'NumPages' => $totalPages, 'NextPage' => $nextPage, 'LastPage' => $lastPage, 'FirstShownRecord' => $firstShownRecord, 'LastShownRecord' => $lastShownRecord, 'NumRecords' => $totalRows));
     }
 }