From 7e9fb74be4ec0b1ac4c5442c0916ff2372f38067 Mon Sep 17 00:00:00 2001 From: Samuel Hapak Date: Sun, 26 Jun 2011 20:20:10 +0200 Subject: [PATCH 01/13] 1.) Add formatting option to Columns and Buttons using syntax 'blah blah blah %key_name% blah' 2.) Fixed XSS vulnerability (echo $record['something'] without escaping it) 3.) Add type property to enable explicitly set a type of column and new type email renderer 4.) Add length property specifying maximal length of column --- Button.php | 4 +- Column.php | 531 ++++++++++++++++++++++++++++++++--------------------- Grid.php | 12 +- 3 files changed, 332 insertions(+), 215 deletions(-) diff --git a/Button.php b/Button.php index 248de05..a9f86e0 100644 --- a/Button.php +++ b/Button.php @@ -52,7 +52,7 @@ public function getConfirmationQuestion($row) if (is_callable($this->confirmationQuestion)) { return call_user_func($this->confirmationQuestion, $row); } else { - return $this->confirmationQuestion; + return Grid::formatRecordString($row, $this->confirmationQuestion); } } @@ -103,4 +103,4 @@ protected function createButton($row = null) return $el; } -} \ No newline at end of file +} diff --git a/Column.php b/Column.php index 03874bf..05320d8 100644 --- a/Column.php +++ b/Column.php @@ -1,6 +1,8 @@ + // - /** @var string */ - private $label; + /** @var string */ + private $label; - /** @var callback */ - private $renderer = null; + /** @var callback */ + private $renderer = null; - /** @var bool */ - private $sortable = false; + /** @var int */ + private $maxlen = null; - /** @var string */ - private $dateTimeFormat = "j.n.Y G:i"; + /** @var string */ + private $type = 'string'; - /** @var string|callable */ - private $cellClass = null; + /** @var bool */ + private $sortable = false; - // - - // - - public function setCellClass($class) - { - $this->cellClass = $class; - return $this; - } - - - - public function getCellClass($iterator, $row) - { - if (is_callable($this->cellClass)) { - return call_user_func($this->cellClass, $iterator, $row); - } elseif (is_string($this->cellClass)) { - return $this->cellClass; - } else { - return null; - } - } - - - - /** - * Get label - * @return string - */ - public function getLabel() - { - return $this->label; - } - - - - /** - * Set label - * @param string label - * @return Column - */ - public function setLabel($label) - { - $this->label = $label; - return $this; - } - - - - /** - * Get cell renderer - * @return callback - */ - public function getRenderer() - { - return $this->renderer; - } - - - - /** - * Set cell renderer - * @param callback cell renderer - * @return Column - */ - public function setRenderer($cellRenderer) - { - $this->renderer = $cellRenderer; - return $this; - } - - - - /** - * Is sortable? - * @return bool - */ - public function isSortable() { - return $this->sortable; - } - - - - /** - * Set sortable - * @param bool sortable - * @return Column - */ - public function setSortable($sortable) { - $this->sortable = $sortable; - return $this; - } - - - - /** - * Get sorting - * @return string|null asc, desc or null - */ - public function getSorting() - { - $grid = $this->getGrid(); - if ($grid->sortColumn === $this->getName()) { - return $grid->sortType; - } else { - return null; - } - } - - - - /** - * Get date/time format - * @return string - */ - public function getDateTimeFormat() { - return $this->dateTimeFormat; - } - - - - /** - * Set date/time format - * @param string datetime format - * @return Column - */ - public function setDateTimeFormat($dateTimeFormat) { - $this->dateTimeFormat = $dateTimeFormat; - return $this; - } - - - - /** - * Get grid - * @return Grid - */ - public function getGrid() { - return $this->getParent()->getParent(); - } - - // - - /** - * Render boolean - * @param bool value - */ - public static function renderBoolean($value) - { - $icon = $value ? "check" : "closethick"; - echo ''; - } - - - - /** - * Render datetime - * @param Datetime value - * @param string datetime format - */ - public static function renderDateTime($value, $format) - { - echo $value->format($format); - } - - - - /** - * Default cell renderer - * @param mixed $record - * @param Column $column - */ - public function defaultCellRenderer($record, $column) { - $name = $column->getName(); - $value = $record->$name; - - // boolean - if (is_bool($value)) { - self::renderBoolean($value); - - // date - } elseif ($value instanceof \DateTime) { - self::renderDateTime($value, $this->dateTimeFormat); - - // other - } else { - echo $value; - } - } - - - - /** - * Render cell - * @param mixed record - */ - public function renderCell($record) { - call_user_func($this->renderer ?: array($this, "defaultCellRenderer"), $record, $this); - } - -} \ No newline at end of file + /** @var string */ + private $dateTimeFormat = "j.n.Y G:i"; + + /** @var string|callable */ + private $cellClass = null; + + /** @var string */ + private $format = null; + + // + + // + + public function setCellClass($class) + { + $this->cellClass = $class; + return $this; + } + + + + public function getCellClass($iterator, $row) + { + if (is_callable($this->cellClass)) { + return call_user_func($this->cellClass, $iterator, $row); + } elseif (is_string($this->cellClass)) { + return $this->cellClass; + } else { + return null; + } + } + + + + /** + * Get label + * @return string + */ + public function getLabel() + { + return $this->label; + } + + + + /** + * Set label + * @param string label + * @return Column + */ + public function setLabel($label) + { + $this->label = $label; + return $this; + } + + + + /** + * Get cell renderer + * @return callback + */ + public function getRenderer() + { + return $this->renderer; + } + + + + /** + * Set cell renderer + * @param callback cell renderer + * @return Column + */ + public function setRenderer($cellRenderer) + { + $this->renderer = $cellRenderer; + return $this; + } + + /** + * Set maximal length of cell + * @param $maxlen + * @return Column + */ + public function setLength($maxlen) + { + $this->maxlen = $maxlen; + return $this; + } + + /** + * Get maximal length of cell + * @return int + */ + public function getLength() + { + return $this->maxlen; + } + + /** + * Set the type of cell + * @param string type + * @return Column + */ + public function setType($type) + { + $this->type = $type; + return $this; + } + + /** + * Get the type of cell + * @return string type + */ + public function getType($type) + { + return $this->type; + } + + /** + * Set format of the cell + * @param mixed format + * @return Column + */ + public function setFormat($format) + { + $this->format = $format; + return $this; + } + + /** + * Get the format + * @return mixed + */ + public function getFormat() + { + return $this->format; + } + + + /** + * Is sortable? + * @return bool + */ + public function isSortable() { + return $this->sortable; + } + + + + /** + * Set sortable + * @param bool sortable + * @return Column + */ + public function setSortable($sortable) { + $this->sortable = $sortable; + return $this; + } + + + + /** + * Get sorting + * @return string|null asc, desc or null + */ + public function getSorting() + { + $grid = $this->getGrid(); + if ($grid->sortColumn === $this->getName()) { + return $grid->sortType; + } else { + return null; + } + } + + + + /** + * Get date/time format + * @return string + */ + public function getDateTimeFormat() { + return $this->dateTimeFormat; + } + + + + /** + * Set date/time format + * @param string datetime format + * @return Column + */ + public function setDateTimeFormat($dateTimeFormat) { + $this->dateTimeFormat = $dateTimeFormat; + return $this; + } + + + + /** + * Get grid + * @return Grid + */ + public function getGrid() { + return $this->getParent()->getParent(); + } + + // + + /** + * Render boolean + * @param bool value + */ + public static function renderBoolean($value) + { + $icon = $value ? "check" : "closethick"; + echo ''; + } + + + + /** + * Render datetime + * @param Datetime value + * @param string datetime format + */ + public static function renderDateTime($value, $format) + { + echo $value->format($format); + } + + /** + * Render the text, takes care of length + * @param string $text text to render + * @param int $maxlen maximum length of text + */ + public static function renderText($text, $maxlen) + { + if (is_null($maxlen) || Strings::length($text) < $maxlen) { + echo htmlspecialchars($text, ENT_NOQUOTES); + } else { + echo Html::el('span')->title($text) + ->setText(Strings::truncate($text, $maxlen)); + } + } + + /** + * Render the email address, takes care of length + * @param string $email email address + * @param int $maxlen maximum length of text + */ + public static function renderEmail($email, $maxlen) + { + $el = Html::el('a')->href('mailto:' . $email); + if (is_null($maxlen) || Strings::length($email) < $maxlen) { + echo $el->setText($email); + } else { + echo $el->title($email) + ->setText(Strings::truncate($email, $maxlen)); + } + } + + + /** + * Default cell renderer + * @param mixed $record + * @param Column $column + */ + public function defaultCellRenderer($record, $column) { + $name = $column->getName(); + $value = $record->$name; + + // boolean + if (in_array($this->type, array('bool', 'boolean')) || is_bool($value)) { + self::renderBoolean($value); + + // date + } elseif ($value instanceof \DateTime) { + self::renderDateTime($value, $this->dateTimeFormat); + + // email + } elseif ($this->type == 'email') { + self::renderEmail($value, $this->maxlen); + + // other + } else { + if (!is_null($this->format)) { + $value = Grid::formatRecordString($record, $this->format); + } + self::renderText($value, $this->maxlen); + } + } + + + + /** + * Render cell + * @param mixed record + */ + public function renderCell($record) { + call_user_func($this->renderer ?: array($this, "defaultCellRenderer"), $record, $this); + } + +} diff --git a/Grid.php b/Grid.php index cc7b52e..f6eafc2 100644 --- a/Grid.php +++ b/Grid.php @@ -3,6 +3,7 @@ namespace Gridito; use Nette\ComponentModel\Container, Nette\Environment, Nette\Utils\Paginator; +use Nette\Utils\Strings; /** * Grid @@ -66,6 +67,15 @@ public function __construct(\Nette\ComponentModel\IContainer $parent = null, $na $this->paginator->setItemsPerPage($this->defaultItemsPerPage); } + public static function formatRecordString($record, $formatString) + { + return Strings::replace($formatString, '#%[^%]*%#u', + function ($m) use ($record) { + $m = Strings::trim($m[0], '%'); + return $m != '' ? $record[$m] : "%"; + }); + } + // // @@ -401,4 +411,4 @@ protected function setOptions($object, $options) } } -} \ No newline at end of file +} From 13ae5dd2f56cf081f799a7f1de56af9e7d237910 Mon Sep 17 00:00:00 2001 From: Samuel Hapak Date: Mon, 27 Jun 2011 01:17:04 +0200 Subject: [PATCH 02/13] Add NetteModel (using Nette\Database) --- models/NetteModel.php | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 models/NetteModel.php diff --git a/models/NetteModel.php b/models/NetteModel.php new file mode 100644 index 0000000..28e9b82 --- /dev/null +++ b/models/NetteModel.php @@ -0,0 +1,65 @@ +selection = $selection; + } + + + + public function getItemByUniqueId($uniqueId) + { + $select = clone $this->selection; + return $select->where('?=?', $this->getPrimaryKey(), $uniqueId) + ->fetch(); + } + + + + public function getItems() + { + $select = clone $this->selection; + + list($sortColumn, $sortType) = $this->getSorting(); + if ($sortColumn) { + $select->order("$sortColumn $sortType"); + } + return $select->limit($this->getLimit(), $this->getOffset()) + ->fetchPairs($this->getPrimaryKey()); + } + + + + /** + * Item count + * @return int + */ + protected function _count() + { + return $this->selection->count(); + } + +} From ddf8fb59e19168b040c61831fd0ca945f4415183 Mon Sep 17 00:00:00 2001 From: Samuel Hapak Date: Wed, 29 Jun 2011 16:05:20 +0200 Subject: [PATCH 03/13] NetteModel bug fixed --- models/NetteModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/NetteModel.php b/models/NetteModel.php index 28e9b82..80df8c5 100644 --- a/models/NetteModel.php +++ b/models/NetteModel.php @@ -33,7 +33,7 @@ public function __construct(Selection $selection) public function getItemByUniqueId($uniqueId) { $select = clone $this->selection; - return $select->where('?=?', $this->getPrimaryKey(), $uniqueId) + return $select->where($this->getPrimaryKey(), $uniqueId) ->fetch(); } From 58f0eb8da79a914cc452f732c4a9cb6c571a88ac Mon Sep 17 00:00:00 2001 From: Samuel Hapak Date: Fri, 1 Jul 2011 13:29:47 +0200 Subject: [PATCH 04/13] Pridany Nette Model --- models/NetteModel.php | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 models/NetteModel.php diff --git a/models/NetteModel.php b/models/NetteModel.php new file mode 100644 index 0000000..075e7ef --- /dev/null +++ b/models/NetteModel.php @@ -0,0 +1,57 @@ +selection = $selection; + } + + public function getItemByUniqueId($uniqueId) + { + $select = clone $this->selection; + return $select->where($this->getPrimaryKey(), $uniqueId) + ->fetch(); + } + + public function getItems() + { + $select = clone $this->selection; + + list($sortColumn, $sortType) = $this->getSorting(); + if ($sortColumn) { + $select->order("$sortColumn $sortType"); + } + return $select->limit($this->getLimit(), $this->getOffset()) + ->fetchPairs($this->getPrimaryKey()); + } + + + /** + * Item count + * @return int + */ + protected function _count() + { + return $this->selection->count(); + } + +} From 4849972dcbe2e937d4718eabd27aa3701ba1bf1d Mon Sep 17 00:00:00 2001 From: Samuel Hapak Date: Fri, 1 Jul 2011 13:37:59 +0200 Subject: [PATCH 05/13] FIX: XSS --- Column.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Column.php b/Column.php index 03874bf..ad55a6b 100644 --- a/Column.php +++ b/Column.php @@ -213,7 +213,7 @@ public function defaultCellRenderer($record, $column) { // other } else { - echo $value; + echo htmlspecialchars($value, ENT_NOQUOTES); } } @@ -227,4 +227,4 @@ public function renderCell($record) { call_user_func($this->renderer ?: array($this, "defaultCellRenderer"), $record, $this); } -} \ No newline at end of file +} From 18451c21db8708b5e5a8c126da2549d02d9f7d5f Mon Sep 17 00:00:00 2001 From: Samuel Hapak Date: Fri, 1 Jul 2011 13:44:41 +0200 Subject: [PATCH 06/13] Add property maxlen --- Column.php | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/Column.php b/Column.php index ad55a6b..b2fcffd 100644 --- a/Column.php +++ b/Column.php @@ -18,6 +18,8 @@ class Column extends \Nette\Application\UI\Control /** @var callback */ private $renderer = null; + /** @var int */ + private $maxlen = null; /** @var bool */ private $sortable = false; @@ -33,7 +35,7 @@ class Column extends \Nette\Application\UI\Control public function setCellClass($class) { - $this->cellClass = $class; + $this->cellClass = $class; return $this; } @@ -98,6 +100,25 @@ public function setRenderer($cellRenderer) return $this; } + /** + * Set maximal length of cell + * @param $maxlen + * @return Column + */ + public function setLength($maxlen) + { + $this->maxlen = $maxlen; + return $this; + } + + /** + * Get maximal length of cell + * @return int + */ + public function getLength() + { + return $this->maxlen; + } /** @@ -192,6 +213,21 @@ public static function renderDateTime($value, $format) echo $value->format($format); } + /** + * Render the text, takes care of length + * @param string $text text to render + * @param int $maxlen maximum length of text + */ + public static function renderText($text, $maxlen) + { + if (is_null($maxlen) || Strings::length($text) < $maxlen) { + echo htmlspecialchars($text, ENT_NOQUOTES); + } else { + echo Html::el('span')->title($text) + ->setText(Strings::truncate($text, $maxlen)); + } + } + /** @@ -213,7 +249,7 @@ public function defaultCellRenderer($record, $column) { // other } else { - echo htmlspecialchars($value, ENT_NOQUOTES); + self::renderText($value, $this->maxlen); } } From 159d81bbe17b1ae7cc91aa4d68c9efdeadcc2741 Mon Sep 17 00:00:00 2001 From: Samuel Hapak Date: Fri, 1 Jul 2011 13:47:05 +0200 Subject: [PATCH 07/13] Add property type --- Column.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Column.php b/Column.php index b2fcffd..9670b43 100644 --- a/Column.php +++ b/Column.php @@ -20,6 +20,10 @@ class Column extends \Nette\Application\UI\Control /** @var int */ private $maxlen = null; + + /** @var string */ + private $type = 'string'; + /** @var bool */ private $sortable = false; @@ -120,6 +124,25 @@ public function getLength() return $this->maxlen; } + /** + * Set the type of cell + * @param string type + * @return Column + */ + public function setType($type) + { + $this->type = $type; + return $this; + } + + /** + * Get the type of cell + * @return string type + */ + public function getType($type) + { + return $this->type; + } /** * Is sortable? @@ -240,7 +263,7 @@ public function defaultCellRenderer($record, $column) { $value = $record->$name; // boolean - if (is_bool($value)) { + if (in_array($this->type, array('bool', 'boolean')) || is_bool($value)) { self::renderBoolean($value); // date From cd99c438c6eef2606364d4be5404cd2d517cd9de Mon Sep 17 00:00:00 2001 From: Samuel Hapak Date: Fri, 1 Jul 2011 13:48:33 +0200 Subject: [PATCH 08/13] Add email renderer --- Column.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Column.php b/Column.php index 9670b43..76e90a7 100644 --- a/Column.php +++ b/Column.php @@ -251,6 +251,21 @@ public static function renderText($text, $maxlen) } } + /** + * Render the email address, takes care of length + * @param string $email email address + * @param int $maxlen maximum length of text + */ + public static function renderEmail($email, $maxlen) + { + $el = Html::el('a')->href('mailto:' . $email); + if (is_null($maxlen) || Strings::length($email) < $maxlen) { + echo $el->setText($email); + } else { + echo $el->title($email) + ->setText(Strings::truncate($email, $maxlen)); + } + } /** @@ -270,6 +285,10 @@ public function defaultCellRenderer($record, $column) { } elseif ($value instanceof \DateTime) { self::renderDateTime($value, $this->dateTimeFormat); + // email + } elseif ($this->type == 'email') { + self::renderEmail($value, $this->maxlen); + // other } else { self::renderText($value, $this->maxlen); From d3904e7a76e62da20d5e3a4f25a307e8c7bdb8d2 Mon Sep 17 00:00:00 2001 From: Samuel Hapak Date: Fri, 1 Jul 2011 13:49:18 +0200 Subject: [PATCH 09/13] Fix: forgotten use ... --- Column.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Column.php b/Column.php index 76e90a7..c23f330 100644 --- a/Column.php +++ b/Column.php @@ -1,6 +1,8 @@ Date: Fri, 1 Jul 2011 13:55:42 +0200 Subject: [PATCH 10/13] Add formating --- Button.php | 4 ++-- Column.php | 26 ++++++++++++++++++++++++++ Grid.php | 12 +++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Button.php b/Button.php index 248de05..a9f86e0 100644 --- a/Button.php +++ b/Button.php @@ -52,7 +52,7 @@ public function getConfirmationQuestion($row) if (is_callable($this->confirmationQuestion)) { return call_user_func($this->confirmationQuestion, $row); } else { - return $this->confirmationQuestion; + return Grid::formatRecordString($row, $this->confirmationQuestion); } } @@ -103,4 +103,4 @@ protected function createButton($row = null) return $el; } -} \ No newline at end of file +} diff --git a/Column.php b/Column.php index c23f330..11de479 100644 --- a/Column.php +++ b/Column.php @@ -35,6 +35,9 @@ class Column extends \Nette\Application\UI\Control /** @var string|callable */ private $cellClass = null; + /** @var string */ + private $format = null; + // // @@ -146,6 +149,26 @@ public function getType($type) return $this->type; } + /** + * Set format of the cell + * @param mixed format + * @return Column + */ + public function setFormat($format) + { + $this->format = $format; + return $this; + } + + /** + * Get the format + * @return mixed + */ + public function getFormat() + { + return $this->format; + } + /** * Is sortable? * @return bool @@ -293,6 +316,9 @@ public function defaultCellRenderer($record, $column) { // other } else { + if (!is_null($this->format)) { + $value = Grid::formatRecordString($record, $this->format); + } self::renderText($value, $this->maxlen); } } diff --git a/Grid.php b/Grid.php index cc7b52e..00ec0e3 100644 --- a/Grid.php +++ b/Grid.php @@ -3,6 +3,7 @@ namespace Gridito; use Nette\ComponentModel\Container, Nette\Environment, Nette\Utils\Paginator; +use Nette\Utils\Strings; /** * Grid @@ -66,6 +67,15 @@ public function __construct(\Nette\ComponentModel\IContainer $parent = null, $na $this->paginator->setItemsPerPage($this->defaultItemsPerPage); } + public static function formatRecordString($record, $formatString) + { + return Strings::replace($formatString, '#%[^%]*%#u', + function ($m) use ($record) { + $m = Strings::trim($m[0], '%'); + return $m != '' ? $record[$m] : "%"; + }); + } + // // @@ -401,4 +411,4 @@ protected function setOptions($object, $options) } } -} \ No newline at end of file +} From 7e5f06aa3273ff6e642f5770e5b31a7d7c077331 Mon Sep 17 00:00:00 2001 From: Samuel Hapak Date: Sat, 2 Jul 2011 00:34:22 +0200 Subject: [PATCH 11/13] FIX: Posahany merge z testingu --- Column.php | 18 +++++++++--------- css/{gridito.css => _gridito.scss} | 0 2 files changed, 9 insertions(+), 9 deletions(-) rename css/{gridito.css => _gridito.scss} (100%) diff --git a/Column.php b/Column.php index d28de78..11de479 100644 --- a/Column.php +++ b/Column.php @@ -12,13 +12,13 @@ */ class Column extends \Nette\Application\UI\Control { - // + // - /** @var string */ - private $label; + /** @var string */ + private $label; - /** @var callback */ - private $renderer = null; + /** @var callback */ + private $renderer = null; /** @var int */ private $maxlen = null; @@ -29,11 +29,11 @@ class Column extends \Nette\Application\UI\Control /** @var bool */ private $sortable = false; - /** @var string */ - private $type = 'string'; + /** @var string */ + private $dateTimeFormat = "j.n.Y G:i"; - /** @var bool */ - private $sortable = false; + /** @var string|callable */ + private $cellClass = null; /** @var string */ private $format = null; diff --git a/css/gridito.css b/css/_gridito.scss similarity index 100% rename from css/gridito.css rename to css/_gridito.scss From 6db49224419ef0394dc2d46e1469e2eb556f7e67 Mon Sep 17 00:00:00 2001 From: Samuel Hapak Date: Sat, 2 Jul 2011 00:36:49 +0200 Subject: [PATCH 12/13] FIX: delete use Dibi\Fluent from NetteModel --- models/NetteModel.php | 1 - 1 file changed, 1 deletion(-) diff --git a/models/NetteModel.php b/models/NetteModel.php index 075e7ef..565197d 100644 --- a/models/NetteModel.php +++ b/models/NetteModel.php @@ -2,7 +2,6 @@ namespace Gridito; -use DibiFluent; use Nette\Database\Table\Selection; /** From efd90ba29693fc20dd8d19074db1d809943baad2 Mon Sep 17 00:00:00 2001 From: Samuel Hapak Date: Sat, 2 Jul 2011 14:29:56 +0200 Subject: [PATCH 13/13] Zbavena zavislost aplikovania csska na js kode. --- BaseButton.php | 24 +++++++-- css/_gridito.scss | 108 ++++++++++++++++++++++++++++++++-------- js/jquery.ui.gridito.js | 36 +------------- templates/grid.phtml | 16 +++--- 4 files changed, 118 insertions(+), 66 deletions(-) diff --git a/BaseButton.php b/BaseButton.php index f144148..fc64d91 100644 --- a/BaseButton.php +++ b/BaseButton.php @@ -239,11 +239,29 @@ public function handleClick($token, $uniqueId = null) */ protected function createButton($row = null) { + $button = Html::el('a')->href($this->getLink($row)); + $button->class[] = 'gridito-button'; + if ($this->icon && $this->showText) { + $button->class[] = 'button-icon-text'; + } elseif ($this->icon) { + $button->class[] = 'button-icon'; + $button->class[] = 'gridito-hide-text'; + $button->title($this->label); + } else { + $button->class[] = 'button-text'; + } + + if ($this->icon) { + $button->create('span')->class(array('gridito-icon', $this->icon)); + } + $button->create('span class="gridito-text"')->setText($this->label); + return $button; + return Html::el("a") ->href($this->getLink($row)) ->data("gridito-icon", $this->icon) - ->class(array("gridito-button", $this->showText ? null : "gridito-hide-text")) - ->setText($this->label); + ->class(array("gridito-button js-disabled", $this->showText ? null : "gridito-hide-text")) + ->add(Html::el('span')->setText($this->label)); } @@ -259,4 +277,4 @@ public function render($row = null) } } -} \ No newline at end of file +} diff --git a/css/_gridito.scss b/css/_gridito.scss index 6591fcd..d1340c6 100644 --- a/css/_gridito.scss +++ b/css/_gridito.scss @@ -1,3 +1,4 @@ +@import '_jquery.ui.scss'; /** * Gridito CSS */ @@ -24,43 +25,108 @@ div.gridito-flash .ui-icon { .gridito-table { border-collapse: collapse; width: 100%; + @extend .ui-widget; + @extend .ui-widget-content; + th { + padding: 0.5em; + text-align: left; + @extend .ui-widget-header; + .gridito-sorting { + float:right; + margin-left: 0.5em; + position: relative; + top: 0.2em; + .sorting-no, .sorting-asc, .sorting-desc { + @extend .ui-icon; + } + .sorting-no { + opacity: 0.5; + &:hover { + opacity: 1; + } + } + .sorting-no, .sorting-desc:hover { + @extend .ui-icon-carat-2-n-s; + } + .sorting-asc, .sorting-no:hover { + @extend .ui-icon-triangle-1-n; + } + .sorting-desc, .sorting-asc:hover { + @extend .ui-icon-triangle-1-s; + } + } + &:hover .gridito-sorting .sorting-no { + opacity: 1; + } + } + tbody tr:hover { + @extend .ui-state-hover; + } } .gridito-table th { - padding: 0.5em; - text-align: left; } .gridito-table td { padding: 0.5em; border: 1px solid #BBB; + &.highlight { + @extend .ui-state-highlight; + } +} + +.gridito-table tr { + max-height: 2ex; +} + +.gridito-button { + @extend .ui-button; + @extend .ui-widget; + @extend .ui-state-default; + @extend .ui-corner-all; + + &.button-text { + @extend .ui-button-text-only; + } + &.button-icon { + @extend .ui-button-icon-only; + } + &.button-icon-text { + @extend .ui-button-text-icon-primary; + } + &.disabled { + @extend .ui-button-disabled; + @extend .ui-state-disabled; + } + &:hover { + @extend .ui-state-hover; + } + &:active { + @extend .ui-state-active; + } + &:focus { + @extend .ui-state-focus; + } +} +span.gridito-icon { + @extend .ui-button-icon-primary; + @extend .ui-icon; +} +span.gridito-text { + @extend .ui-button-text; } .gridito-table .ui-state-hover .gridito-cell { - font-weight: normal; +font-weight: normal; } .gridito-actioncell .ui-button { - margin: 0 0.5em 0 0; +margin: 0 0.5em 0 0; } .gridito-actioncell .ui-button:first-child { - margin-left: 0; +margin-left: 0; } .gridito-actioncell { - text-align: center; -} - -/* th */ -.gridito-table th .gridito-sorting { - float:right; - margin-left: 0.5em; - position: relative; - top: 0.2em; -} -.gridito-table th .gridito-sorting .ui-icon { - opacity: 0.5 -} -.gridito-table th:hover .gridito-sorting .ui-icon, .gridito-table th .gridito-sorting .ui-icon.ui-icon-triangle-1-s, .gridito-table th .gridito-sorting .ui-icon.ui-icon-triangle-1-n { - opacity: 1 +text-align: center; } /* paginator */ .gridito-paginator { margin-top: 1em; -} \ No newline at end of file +} diff --git a/js/jquery.ui.gridito.js b/js/jquery.ui.gridito.js index f1ebe19..94ace2a 100644 --- a/js/jquery.ui.gridito.js +++ b/js/jquery.ui.gridito.js @@ -2,46 +2,14 @@ $.widget("ui.gridito", { - options: { - - }, - + options: {}, _create: function () { var _this = this; - this.table = this.element.find("table.gridito-table"); - this.table.addClass("ui-widget ui-widget-content"); - this.table.find("th").addClass("ui-widget-header"); - this.table.find("tbody tr").hover(function () { - $(this).addClass("ui-state-hover"); - }, function () { - $(this).removeClass("ui-state-hover"); - }); - - // sorting icons - function initSortingIcons(normalClass, hoverClass) { - _this.table.find("thead th ." + normalClass).hover(function () { - $(this).removeClass(normalClass).addClass(hoverClass); - }, function () { - $(this).removeClass(hoverClass).addClass(normalClass); - }); - }; - - initSortingIcons("ui-icon-carat-2-n-s", "ui-icon-triangle-1-n"); - initSortingIcons("ui-icon-triangle-1-n", "ui-icon-triangle-1-s"); - initSortingIcons("ui-icon-triangle-1-s", "ui-icon-carat-2-n-s"); - // buttons this.element.find("a.gridito-button").each(function () { var el = $(this); - el.button({ - icons: { - primary: el.attr("data-gridito-icon") - }, - text: !el.hasClass("gridito-hide-text"), - disabled: el.hasClass("disabled") - }); // window button if (el.hasClass("gridito-window-button")) { @@ -73,4 +41,4 @@ $.widget("ui.gridito", { }); -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/templates/grid.phtml b/templates/grid.phtml index 0777c1e..3a7b579 100644 --- a/templates/grid.phtml +++ b/templates/grid.phtml @@ -41,9 +41,9 @@ {block tableheadercontent} - - - + + + {$column->getLabel()} {/block} @@ -55,7 +55,7 @@ {block tablebody} - + {control $column:cell $item} @@ -76,17 +76,17 @@ {block paginator} {var $paginator = $control->getPaginator()}
- Previous + Previous {for $i = 1; $i <= $paginator->pageCount; $i++} - {$i} + {$i} {/for} - Next + Next
{/block} {/block} {/if} -{/snippet} \ No newline at end of file +{/snippet}