Esempio n. 1
0
 /**
  * Adjust the behavior of the supplied field in the context of the supplied
  * table renderer so that it draws a "handle" that the user can grab to
  * drag the row around.  Adds some custom JS/CSS to pull that off.
  *
  * @param FieldInterface $field
  * @param TableCell $cellRenderer
  * @param string $primaryKeyName
  * @return void
  */
 public function assignToField(FieldInterface $field, TableCell $cellRenderer, $primaryKeyName)
 {
     $this->view->headScript()->appendFile($this->view->bowerUrl('/dewdrop/www/js/listing-sortable.js'));
     $this->view->headLink()->appendStylesheet($this->view->bowerUrl('/dewdrop/www/css/listing-sortable.css'));
     $cellRenderer->getContentRenderer()->assign($field->getId(), function ($helper, array $rowData) use($primaryKeyName) {
         /* @var $helper TableCell\Content */
         return sprintf('<span data-id="%d" class="handle glyphicon glyphicon-align-justify"></span>', $helper->getView()->escapeHtmlAttr($rowData[$primaryKeyName]));
     });
 }
 /**
  * Create a field object, configured to render a checkbox for use in selecting
  * items for the supplied BulkActions object.
  *
  * @param BulkActions $bulkActions
  * @param TableCellHelper $renderer
  * @return Field
  * @throws Exception
  */
 public function direct(BulkActions $bulkActions, TableCellHelper $renderer)
 {
     $field = new Field();
     $key = $bulkActions->getPrimaryKey()->getName();
     $field->setId($bulkActions->getId())->setVisible(true);
     $renderer->getHeaderRenderer()->assign($bulkActions->getId(), function () {
         return '';
     });
     $renderer->getContentRenderer()->assign($bulkActions->getId(), function ($helper, array $rowData) use($bulkActions, $key) {
         /* @var $helper \Dewdrop\Fields\Helper\TableCell\Content */
         if (!isset($rowData[$key])) {
             throw new Exception("{$key} not available in row data for bulk action checkbox render.");
         }
         $value = $rowData[$key];
         return sprintf('<input class="bulk-checkbox" type="checkbox" name="%s[]" value="%s" %s />', $helper->getView()->escapeHtmlAttr($bulkActions->getId()), $helper->getView()->escapeHtmlAttr($value), in_array($value, $bulkActions->getSelected()) ? 'checked="checked"' : '');
     });
     return $field;
 }
Esempio n. 3
0
 /**
  * Render all the &lt;th&gt; cells that will be contained in the &lt;thead&gt;.
  *
  * @param Fields $fields
  * @param TableCellHelper $renderer
  * @param SelectSort $sorter
  * @return string
  */
 protected function renderHeadCells(Fields $fields, TableCellHelper $renderer, SelectSort $sorter = null)
 {
     $out = '';
     foreach ($fields as $index => $field) {
         $out .= '<th scope="col">';
         $content = $renderer->getHeaderRenderer()->render($field);
         if (!$field->isSortable() || !$sorter) {
             $out .= $content;
         } else {
             $direction = 'asc';
             if ($sorter && $sorter->getSortedField() === $field && 'ASC' === $sorter->getSortedDirection()) {
                 $direction = 'desc';
             }
             $out .= $this->renderSortLink($content, $field->getQueryStringId(), $direction, $sorter);
         }
         $out .= '</th>';
     }
     return $out;
 }
Esempio n. 4
0
 public function testTdClassNamesRendererGetsView()
 {
     $this->assertInstanceOf('Dewdrop\\View\\View', $this->helper->getTdClassNamesRenderer()->getView());
 }
 /**
  * Render the supplied non-grouped fields in a Bootstrap table.
  *
  * @param Fields $fields
  * @param array $data
  * @param Renderer $renderer
  * @return string
  */
 protected function renderFields(Fields $fields, array $data, Renderer $renderer)
 {
     $rowIndex = 0;
     $out = '<div class="table-responsive">';
     $out .= '<table class="table">';
     foreach ($fields->getVisibleFields() as $field) {
         $out .= '<tr>';
         $content = $renderer->getContentRenderer()->render($field, $data, $rowIndex, 1);
         $classNames = $renderer->getTdClassNamesRenderer()->render($field, $data, $rowIndex, 1);
         $header = $renderer->getHeaderRenderer()->render($field);
         if (false !== stripos($content, '<table ')) {
             $out .= $this->renderTableContentInPanel($header, $classNames, $content);
         } else {
             $out .= $this->renderHeaderAndContent($header, $classNames, $content);
         }
         $out .= '</tr>';
         $rowIndex += 1;
     }
     $out .= '</table>';
     $out .= '</div>';
     return $out;
 }