| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace Encore\Admin\Grid;
- trait HasElementNames
- {
- /**
- * Grid name.
- *
- * @var string
- */
- protected $name;
- /**
- * HTML element names.
- *
- * @var array
- */
- protected $elementNames = [
- 'grid_row' => 'grid-row',
- 'grid_select_all' => 'grid-select-all',
- 'grid_per_page' => 'grid-per-pager',
- 'grid_batch' => 'grid-batch',
- 'export_selected' => 'export-selected',
- 'selected_rows' => 'selectedRows',
- ];
- /**
- * Set name to grid.
- *
- * @param string $name
- *
- * @return $this
- */
- public function setName($name)
- {
- $this->name = $name;
- $this->model()->setPerPageName("{$name}_{$this->model()->getPerPageName()}");
- $this->getFilter()->setName($name);
- return $this;
- }
- /**
- * Get name of grid.
- *
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
- /**
- * @return string
- */
- public function getGridRowName()
- {
- return $this->elementNameWithPrefix('grid_row');
- }
- /**
- * @return string
- */
- public function getSelectAllName()
- {
- return $this->elementNameWithPrefix('grid_select_all');
- }
- /**
- * @return string
- */
- public function getPerPageName()
- {
- return $this->elementNameWithPrefix('grid_per_page');
- }
- /**
- * @return string
- */
- public function getGridBatchName()
- {
- return $this->elementNameWithPrefix('grid_batch');
- }
- /**
- * @return string
- */
- public function getExportSelectedName()
- {
- return $this->elementNameWithPrefix('export_selected');
- }
- /**
- * @return string
- */
- public function getSelectedRowsName()
- {
- $elementName = $this->elementNames['selected_rows'];
- if ($this->name) {
- return sprintf('%s%s', $this->name, ucfirst($elementName));
- }
- return $elementName;
- }
- /**
- * @return string
- */
- protected function elementNameWithPrefix($name)
- {
- $elementName = $this->elementNames[$name];
- if ($this->name) {
- return sprintf('%s-%s', $this->name, $elementName);
- }
- return $elementName;
- }
- }
|