/**
  * Place the export button in a <p> tag below the field
  */
 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');
     $button->addExtraClass('font-icon-down-circled');
     return array($this->targetFragment => '<p class="grid-csv-button">' . $button->Field() . '</p>');
 }
 /**
  * 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>');
 }
 /**
  * Returns a map where the keys are fragment names and the values are
  * pieces of HTML to add to these fragments.
  *
  * Here are 4 built-in fragments: 'header', 'footer', 'before', and
  * 'after', but components may also specify fragments of their own.
  *
  * To specify a new fragment, specify a new fragment by including the
  * text "$DefineFragment(fragmentname)" in the HTML that you return.
  *
  * Fragment names should only contain alphanumerics, -, and _.
  *
  * If you attempt to return HTML for a fragment that doesn't exist, an
  * exception will be thrown when the {@link GridField} is rendered.
  *
  * @param GridField $gridField
  * @return array
  */
 public function getHTMLFragments($gridField)
 {
     $button = new GridField_FormAction($gridField, $this->actionName, $this->buttonText, $this->actionName, null);
     $button->addExtraClass('multiselect-button');
     if (!empty($this->buttonConfig['icon'])) {
         $button->setAttribute('data-icon', $this->buttonConfig['icon']);
     }
     if (!empty($this->buttonConfig['class'])) {
         $button->addExtraClass($this->buttonConfig['class']);
     }
     if (!empty($this->buttonConfig['confirm'])) {
         $button->setAttribute('data-confirm', $this->buttonConfig['confirm']);
     }
     return array($this->targetFragment => $button->Field());
 }
 /**
  * Place the export button in a <p> tag below the field
  */
 public function getHTMLFragments($gridField)
 {
     $button = new GridField_FormAction($gridField, 'export_all', _t('GridFieldExportAllButton.LABEL', 'Export all to CSV'), 'export_all', null);
     $button->setAttribute('data-icon', 'download-csv');
     $button->addExtraClass('no-ajax');
     return array($this->targetFragment => '<p class="grid-csv-button">' . $button->Field() . '</p>');
 }
 public function getHTMLFragments($gridField)
 {
     $button = new GridField_FormAction($gridField, 'syncwithyoutube', _t('GridFieldSyncYoutubeVideos.CTA', 'Sync with Youtube'), 'syncwithyoutube', null);
     $button->setAttribute('data-icon', 'accept');
     $button->addExtraClass('no-ajax');
     return array($this->targetFragment => '<p class="grid-csv-button">' . $button->Field() . '<br><br></p>');
 }
 /**
  * Place the export button in a <p> tag below the field
  */
 public function getHTMLFragments($gridField)
 {
     $button = new GridField_FormAction($gridField, 'excelexport', _t('TableListField.XLSEXPORT', 'Export to Excel'), 'excelexport', null);
     $button->setAttribute('data-icon', 'download-excel');
     $button->addExtraClass('no-ajax action_export');
     $button->setForm($gridField->getForm());
     return array($this->targetFragment => '<p class="grid-excel-button">' . $button->Field() . '</p>');
 }
 /**
  * Get the html/css button and upload field to perform import.
  */
 public function getHTMLFragments($gridField)
 {
     $button = new GridField_FormAction($gridField, 'import', _t('TableListField.CSVIMPORT', 'Import from CSV'), 'import', null);
     $button->setAttribute('data-icon', 'drive-upload');
     $button->addExtraClass('no-ajax');
     $uploadfield = $this->getUploadField($gridField);
     $data = array('Button' => $button, 'UploadField' => $uploadfield);
     $importerHTML = ArrayData::create($data)->renderWith("GridFieldImporter");
     Requirements::javascript('importexport/javascript/GridFieldImporter.js');
     return array($this->targetFragment => $importerHTML);
 }
 /**
  * @inheritdoc
  *
  * Create the split button with all the export options.
  *
  * @param  GridField $gridField
  * @return array
  */
 public function getHTMLFragments($gridField)
 {
     // Set up the split button
     $splitButton = new SplitButton('Export', 'Export');
     $splitButton->setAttribute('data-icon', 'download-csv');
     // XLSX option
     $button = new GridField_FormAction($gridField, 'xlsxexport', _t('firebrandhq.EXCELEXPORT', 'Export to Excel (XLSX)'), 'xlsxexport', null);
     $button->addExtraClass('no-ajax');
     $splitButton->push($button);
     // XLS option
     $button = new GridField_FormAction($gridField, 'xlsexport', _t('firebrandhq.EXCELEXPORT', 'Export to Excel (XLS)'), 'xlsexport', null);
     $button->addExtraClass('no-ajax');
     $splitButton->push($button);
     // CSV option
     $button = new GridField_FormAction($gridField, 'csvexport', _t('firebrandhq.EXCELEXPORT', 'Export to CSV'), 'csvexport', null);
     $button->addExtraClass('no-ajax');
     $splitButton->push($button);
     // Return the fragment
     return array($this->targetFragment => $splitButton->Field());
 }
 /**
  * Place the export button in a <p> tag below the field
  */
 public function getHTMLFragments($gridField)
 {
     $button = new GridField_FormAction($gridField, 'fake_locations', _t('DevToolkitFakeLocationsButton.TITLE', 'Add fake locations'), 'fake_locations', null);
     $button->addExtraClass('no-ajax');
     return array($this->targetFragment => '<p class="grid-dump-button">' . $button->Field() . '</p>');
 }
 /**
  * Adds the form fields for the batch actions
  * 
  * @param GridField $gridField GridField to get HTML fragments for
  * 
  * @return array
  */
 public function getHTMLFragments($gridField)
 {
     Requirements::css('silvercart/admin/css/SilvercartGridFieldBatchController.css');
     Requirements::javascript('silvercart/admin/javascript/SilvercartGridFieldBatchController.js');
     $source = array('' => 'Bitte wählen');
     $targetBatchActionObjects = $this->getTargetBatchActionObjects();
     foreach ($targetBatchActionObjects as $targetBatchAction => $targetBatchActionObject) {
         $source[$targetBatchAction] = $targetBatchActionObject->getTitle();
         $targetBatchActionObject->RequireJavascript();
     }
     $dropdown = new DropdownField($this->getDropdownName(), $this->getDropdownName(), $source);
     $dropdown->addExtraClass('grid-batch-action-selector');
     $button = new GridField_FormAction($gridField, 'execute_batch_action', _t('Silvercart.EXECUTE', 'Execute'), 'handleBatchAction', null);
     $button->setAttribute('data-icon', 'navigation');
     $button->addExtraClass('gridfield-button-batch');
     return array($this->targetFragment => '<div class="grid-batch-action-button"><div class="field dropdown plain">' . $dropdown->Field() . '</div><div class="grid-batch-action-callback-target"></div>' . $button->Field() . '</div>');
 }
 /**
  * Determines arguments to be passed to the template for building this field
  * @return ArrayData|null 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('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('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('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('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));
     }
 }
示例#12
0
	/**
	 *
	 * @param GridField $gridField
	 * @return array
	 */
	public function getHTMLFragments($gridField) {
		if(!$this->checkDataType($gridField->getList())) return;
		
		$state = $gridField->State->GridFieldPaginator;
		if(!is_int($state->currentPage))
			$state->currentPage = 1;

		// Figure out which page and record range we're on
		$totalRows = $this->totalItems;
		if(!$totalRows) return array();

		$totalPages = 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;


		// First page button
		$firstPage = new GridField_FormAction($gridField, 'pagination_first', 'First', 'paginate', 1);
		$firstPage->addExtraClass('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('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('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('ss-gridfield-lastpage');
		if($state->currentPage == $totalPages)
			$lastPage = $lastPage->performDisabledTransformation();


		// Render in template
		$forTemplate = new ArrayData(array(
			'FirstPage' => $firstPage,
			'PreviousPage' => $previousPage,
			'CurrentPageNum' => $state->currentPage,
			'NumPages' => $totalPages,
			'NextPage' => $nextPage,
			'LastPage' => $lastPage,
			'FirstShownRecord' => $firstShownRecord,
			'LastShownRecord' => $lastShownRecord,
			'NumRecords' => $totalRows
		));
		return array(
			'footer' => $forTemplate->renderWith('GridFieldPaginator_Row', array('Colspan'=>count($gridField->getColumns()))),
		);
	}
 public function getHTMLFragments($grid)
 {
     // Check create permission
     $singleton = singleton($grid->getModelClass());
     if (!$singleton->canCreate()) {
         return array();
     }
     // Get button name
     $buttonName = $this->getButtonName();
     if (!$buttonName) {
         // provide a default button name, can be changed by calling {@link setButtonName()} on this component
         $objectName = $singleton->i18n_singular_name();
         $buttonName = _t('GridField.Add', 'Add {name}', array('name' => $objectName));
     }
     $addAction = new GridField_FormAction($grid, $this->getAction(), $buttonName, $this->getAction(), array());
     $addAction->setAttribute('data-icon', 'add');
     if ($this->getButtonClass()) {
         $addAction->addExtraClass($this->getButtonClass());
     }
     return array($this->targetFragment => $addAction->forTemplate());
 }
 /**
  * Place the export button in a <p> tag below the field
  */
 public function getHTMLFragments($gridField)
 {
     $button = new GridField_FormAction($gridField, $this->actionName, $this->getBtnTitle(), $this->actionName, null);
     $button->setAttribute('data-icon', 'download-csv');
     $button->addExtraClass('no-ajax');
     return array($this->targetFragment => '<p class="grid-csv-button">' . $button->Field() . '</p>');
 }
 /**
  *
  * @param GridField $gridField
  * @return string - HTML
  */
 public function getHTMLFragments($gridField)
 {
     $dataClass = $gridField->getList()->dataClass();
     $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);
     }
     return array($this->targetFragment => $forTemplate->renderWith($this->itemClass));
 }