From 20da9d2735ef5b8dc11579b400d9cb8436753eb7 Mon Sep 17 00:00:00 2001 From: Pavel Zelezny Date: Thu, 9 Aug 2012 14:58:49 +0200 Subject: [PATCH 1/3] All messages in English Little design improvements for Twitter Bootstrap --- Grid.php | 24 ++++++------ templates/grid.latte | 79 ++++++++++++++++++++++++++------------- templates/paginator.latte | 60 +++++++++++++++++------------ 3 files changed, 101 insertions(+), 62 deletions(-) diff --git a/Grid.php b/Grid.php index 5a98bad..799ac29 100644 --- a/Grid.php +++ b/Grid.php @@ -482,11 +482,11 @@ protected function filterData() $filters = array(); foreach($this->filter as $name => $value){ if(!$this->columnExists($name)){ - throw new UnknownColumnException("Neexistující sloupec $name"); + throw new UnknownColumnException("Unknown column $name"); } if(!$this['columns-'.$name]->hasFilter()){ - throw new UnknownFilterException("Neexistující filtr pro sloupec $name"); + throw new UnknownFilterException("Unknown filter for column $name"); } $type = $this['columns-'.$name]->getFilterType(); @@ -501,10 +501,10 @@ protected function filterData() } $filters[] = $filter; }else{ - throw new InvalidFilterException("Neplatný filtr"); + throw new InvalidFilterException("Invalid filter"); } }else{ - throw new InvalidFilterException("Neplatný filtr"); + throw new InvalidFilterException("Invalid filter"); } } return $this->dataSource->filterData($filters); @@ -530,7 +530,7 @@ protected function orderData($order) if(in_array($order[0], $this->getColumnNames()) && in_array($order[1], array("ASC", "DESC")) && $this['columns']->components[$order[0]]->isSortable()){ $this->dataSource->orderData($order[0], $order[1]); }else{ - throw new InvalidOrderException("Neplatné seřazení."); + throw new InvalidOrderException("Invalid order."); } } catch(InvalidOrderException $e){ @@ -653,20 +653,20 @@ protected function createComponentGridForm() $form->addContainer($this->name); $form[$this->name]->addContainer("rowForm"); - $form[$this->name]['rowForm']->addSubmit("send","Uložit"); + $form[$this->name]['rowForm']->addSubmit("send","Save"); $form[$this->name]['rowForm']['send']->getControlPrototype()->addClass("grid-editable"); $form[$this->name]->addContainer("filter"); - $form[$this->name]['filter']->addSubmit("send","Filtrovat"); + $form[$this->name]['filter']->addSubmit("send","Filter"); $form[$this->name]->addContainer("action"); - $form[$this->name]['action']->addSelect("action_name","Označené:"); - $form[$this->name]['action']->addSubmit("send","Potvrdit") + $form[$this->name]['action']->addSelect("action_name","Mark:"); + $form[$this->name]['action']->addSubmit("send","Confirm") ->getControlPrototype() ->addData("select", $form[$this->name]["action"]["action_name"]->getControl()->name); $form[$this->name]->addContainer('perPage'); - $form[$this->name]['perPage']->addSelect("perPage","Záznamů na stranu:", $this->perPageValues) + $form[$this->name]['perPage']->addSelect("perPage","Records per page:", $this->perPageValues) ->getControlPrototype() ->addClass("grid-changeperpage") ->addData("gridname", $this->getGridPath()) @@ -769,9 +769,9 @@ public function actionFormSubmitted($values, $gridName) } catch(NoRowSelectedException $e){ if($subGrid){ - $this[$gridName]->flashMessage("Nebyl vybrán žádný záznam.","grid-error"); + $this[$gridName]->flashMessage("No record selected","grid-error"); }else{ - $this->flashMessage("Nebyl vybrán žádný záznam.","grid-error"); + $this->flashMessage("No record selected","grid-error"); } $this->redirect("this"); } diff --git a/templates/grid.latte b/templates/grid.latte index f579d9a..826e539 100644 --- a/templates/grid.latte +++ b/templates/grid.latte @@ -10,46 +10,72 @@ *} {snippet} {if !$control->isSubGrid} -{$control['gridForm']->render('begin')} + {? $control['gridForm']->getElementPrototype()->class = 'grid-gridForm form-inline'} + {$control['gridForm']->render('begin')} {/if} - +
- - - + {* + + + + *} - + - + - - + @@ -70,7 +96,7 @@ - + {/if} @@ -95,24 +121,25 @@ - - -
-
- celkem {$results} {($results == 1) ? "záznam" : (($results >= 2 && $results <= 4) ? "záznamy" : "záznamů")}{if $paginate} {if (boolean)$results}(Zobrazeno {$viewedFrom} až {$viewedTo}){/if}{/if} + + {_'Total %s values', $results} + {if $paginate} + {if (boolean)$results} + {_'(Viewed %s to %s values)', array($viewedFrom, $viewedTo)} + {/if} + {/if}
- {$flash->message} -
-
+ {$flash->message} +
+
+ + {if $control->hasEnabledSorting() && $column->isSortable()}{var $order = ($control->order == $column->name.' ASC') ? " DESC" : " ASC"}{$column->label}{else}{$column->label}{/if} -
- - -
+
+ {if $control->hasEnabledSorting() && $column->isSortable()} + {var $order = ($control->order == $column->name.' ASC') ? " DESC" : " ASC"} + {$column->label} + + {if ($control->order && ($control->order == $column->name.' ASC'))} + + {elseif ($control->order && ($control->order == $column->name.' DESC'))} + + {/if} + + {else} + {$column->label} + {/if} + + {_'Actions'} Akce
{if $column->hasFilter()} + {? $control['gridForm'][$control->name]['filter']['send']->setAttribute('class', 'btn btn-primary')} {$control['gridForm'][$control->name]['filter'][$column->name]->getControl()} {/if} {$control['gridForm'][$control->name]['filter']['send']->getControl()}{$control['gridForm'][$control->name]['filter']['send']->getControl()} + + + +
{if $control->activeRowForm == $row[$primaryKey] && $control->isEditable()} {$control['gridForm'][$control->name]['rowForm']['send']->getControl()} - + {$control['gridForm'][$control->name]['rowForm'][$primaryKey]->getControl()} {else} {foreach $buttons as $button} @@ -87,7 +113,7 @@ {/foreach} {else}
Žádné záznamy{_'No records'}
+ {? $control['gridForm'][$control->name]['action']['send']->setAttribute('class', 'btn btn-primary')} {$control['gridForm'][$control->name]['action']['action_name']->label} {$control['gridForm'][$control->name]['action']['action_name']->getControl()} {$control['gridForm'][$control->name]['action']['send']->getControl()} - + + {? $control['gridForm'][$control->name]['perPage']['perPage']->getLabelPrototype()->class = 'control-label'} + {? $control['gridForm'][$control->name]['perPage']['perPage']->setAttribute('class', 'grid-changeperpage chzn-select input-small')} + {? $control['gridForm'][$control->name]['perPage']['send']->setAttribute('class', 'btn btn-primary')} + {$control['gridForm'][$control->name]['perPage']['perPage']->label} {$control['gridForm'][$control->name]['perPage']['perPage']->getControl()} {$control['gridForm'][$control->name]['perPage']['send']->getControl()}
- {control paginator} -
+{control paginator} {if !$control->isSubGrid} {$control['gridForm']->render('end')} {/if} diff --git a/templates/paginator.latte b/templates/paginator.latte index ce65ee0..94697b4 100755 --- a/templates/paginator.latte +++ b/templates/paginator.latte @@ -9,29 +9,41 @@ */ *} {if $paginator->pageCount > 1} -
- {foreach range($paginator->getBase(), $paginator->getPageCount()) as $page} - {/foreach} - {if !$paginator->isFirst()} - << - {else} - << - {/if} - {if $paginator->getPage() - 1 >= $paginator->getFirstPage()} - < - {else} - < - {/if} - {$paginator->getPage()} - {if $paginator->getPage() + 1 <= $paginator->getLastPage()} - > - {else} - > - {/if} - {if !$paginator->isLast()} - >> - {else} - >> - {/if} + {/if} \ No newline at end of file From 0875a04824d6f193554095e2a9a863647be189e0 Mon Sep 17 00:00:00 2001 From: Pavel Zelezny Date: Fri, 10 Aug 2012 09:36:01 +0200 Subject: [PATCH 2/3] Add posibility to set exact TEXT filter --- Components/Column.php | 4 ++-- FilterCondition.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Components/Column.php b/Components/Column.php index 57ea544..1c210c0 100644 --- a/Components/Column.php +++ b/Components/Column.php @@ -329,10 +329,10 @@ public function getFilterType() /** * @return Column */ - public function setTextFilter() + public function setTextFilter($exact = FALSE) { $this->parent['gridForm'][$this->parent->name]['filter']->addText($this->name, $this->label.":"); - $this->filterType = FilterCondition::TEXT; + $this->filterType = ($exact === FALSE) ? (FilterCondition::TEXT) : (FilterCondition::EQUAL); return $this; } diff --git a/FilterCondition.php b/FilterCondition.php index a39b916..cf6c752 100644 --- a/FilterCondition.php +++ b/FilterCondition.php @@ -95,8 +95,8 @@ public static function getConditionsByType($type) */ public static function prepareFilter($value, $type) { - /* select nebo boolean muze byt pouze equal */ - if($type == self::SELECT || $type == self::BOOLEAN) + /* select, boolean a equal muze byt pouze equal */ + if(($type == self::SELECT) || ($type == self::BOOLEAN) || ($type == self::EQUAL)) return array( "condition" => self::EQUAL, "value" => $value From fcb8c53a5b06fba9586d805f413b38504dcde69a Mon Sep 17 00:00:00 2001 From: Pavel Zelezny Date: Fri, 17 Aug 2012 14:13:24 +0200 Subject: [PATCH 3/3] Add posibility to use equalLower and equalHigher to numeric --- FilterCondition.php | 87 +++++++++++++++++++++++++++++++-------------- 1 file changed, 60 insertions(+), 27 deletions(-) diff --git a/FilterCondition.php b/FilterCondition.php index cf6c752..6a25eec 100644 --- a/FilterCondition.php +++ b/FilterCondition.php @@ -1,4 +1,5 @@ "%", self::STARTSWITH => "%", ); - elseif($type == self::DATE) + elseif ($type == self::DATE) return array( self::DATE_EQUAL => "=", self::DATE_DIFFERENT => "<>", @@ -76,8 +81,10 @@ public static function getConditionsByType($type) self::DATE_LOWEREQUAL => "<=", self::DATE_LOWER => "<", ); - elseif($type == self::NUMERIC) + elseif ($type == self::NUMERIC) return array( + self::EQUALLOWER => "=<", + self::EQUALHIGHER => "=>", self::EQUAL => "=", self::DIFFERENT => "<>", self::HIGHEREQUAL => ">=", @@ -96,32 +103,36 @@ public static function getConditionsByType($type) public static function prepareFilter($value, $type) { /* select, boolean a equal muze byt pouze equal */ - if(($type == self::SELECT) || ($type == self::BOOLEAN) || ($type == self::EQUAL)) + if (($type == self::SELECT) || ($type == self::BOOLEAN) || ($type == self::EQUAL)) return array( "condition" => self::EQUAL, "value" => $value ); - elseif($type == self::TEXT){ - foreach(self::getConditionsByType(self::TEXT) as $name => $condition){ - if(Strings::endsWith($value, $condition) && !Strings::startsWith($value, $condition) && $name == self::STARTSWITH) - return array( - "condition" => $name, - "value" => Strings::substring($value, 0,"-".Strings::length($condition)) - ); - elseif(Strings::startsWith($value, $condition) && !Strings::endsWith($value, $condition) && $name == self::ENDSWITH) - return array( - "condition" => $name, - "value" => Strings::substring($value, Strings::length($condition)) - ); + elseif ($type == self::TEXT) + { + foreach (self::getConditionsByType(self::TEXT) as $name => $condition) + { + if (Strings::endsWith($value, $condition) && !Strings::startsWith($value, $condition) && $name == self::STARTSWITH) + return array( + "condition" => $name, + "value" => Strings::substring($value, 0, "-" . Strings::length($condition)) + ); + elseif (Strings::startsWith($value, $condition) && !Strings::endsWith($value, $condition) && $name == self::ENDSWITH) + return array( + "condition" => $name, + "value" => Strings::substring($value, Strings::length($condition)) + ); } return array( "condition" => self::CONTAINS, "value" => $value ); } - elseif($type == self::DATE){ - foreach(self::getConditionsByType(self::DATE) as $name => $condition){ - if(Strings::startsWith($value, $condition)) + elseif ($type == self::DATE) + { + foreach (self::getConditionsByType(self::DATE) as $name => $condition) + { + if (Strings::startsWith($value, $condition)) return array( "condition" => $name, "value" => Strings::substring($value, Strings::length($condition)) @@ -132,9 +143,11 @@ public static function prepareFilter($value, $type) "value" => $value ); } - elseif($type == self::NUMERIC){ - foreach(self::getConditionsByType(self::NUMERIC) as $name => $condition){ - if(Strings::startsWith($value, $condition)) + elseif ($type == self::NUMERIC) + { + foreach (self::getConditionsByType(self::NUMERIC) as $name => $condition) + { + if (Strings::startsWith($value, $condition)) return array( "condition" => $name, "value" => (int) Strings::substring($value, Strings::length($condition)) @@ -158,7 +171,7 @@ public static function contains($value) "type" => self::WHERE, "datatype" => self::TEXT, "cond" => " LIKE ?", - "value" => "%".self::like($value)."%", + "value" => "%" . self::like($value) . "%", ); } @@ -188,7 +201,7 @@ public static function startsWith($value) "type" => self::WHERE, "datatype" => self::TEXT, "cond" => " LIKE ?", - "value" => self::like($value)."%", + "value" => self::like($value) . "%", ); } @@ -203,7 +216,7 @@ public static function endsWith($value) "type" => self::WHERE, "datatype" => self::TEXT, "cond" => " LIKE ?", - "value" => "%".self::like($value), + "value" => "%" . self::like($value), ); } @@ -237,6 +250,16 @@ public static function higherEqual($value) ); } + /** + * @static + * @param string $value + * @return array + */ + public static function equalHigher($value) + { + return self::higherEqual($value); + } + /** * @static * @param string $value @@ -267,6 +290,16 @@ public static function lowerEqual($value) ); } + /** + * @static + * @param string $value + * @return array + */ + public static function equalLower($value) + { + return self::lowerEqual($value); + } + /** * @static * @param string $value