Skip to content

Commit

Permalink
- minor fixes
Browse files Browse the repository at this point in the history
- DataGridAction: name of key used in link generation can be now specified

git-svn-id: http://nette-datagrid.googlecode.com/svn/trunk@40 a552be54-3675-11de-a996-7ff70a941223
  • Loading branch information
romansklenar committed Jul 20, 2009
1 parent 5c3be5b commit 418135c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/components/DataGrid/Columns/PositionColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct($caption = NULL, $destination = NULL, array $moves =

$this->useAjax = $useAjax;

if ($moves === NULL) {
if (empty($moves)) {
$this->moves['up'] = 'Move up';
$this->moves['down'] = 'Move down';
} else {
Expand Down
7 changes: 4 additions & 3 deletions app/components/DataGrid/DataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -1090,16 +1090,17 @@ public function setCurrentActionColumn(ActionColumn $column)
* @param string textual link destination
* @param Html element which is added to a generated link
* @param bool use ajax? (add class self::$ajaxClass into generated link)
* @param bool generate link with argument? (variable $keyName must be defined in data grid)
* @param mixed generate link with argument? (if yes you can specify name of parameter
* otherwise variable DataGrid::$keyName will be used and must be defined)
* @return DataGridAction
*/
public function addAction($title, $signal, $icon = NULL, $useAjax = FALSE, $type = DataGridAction::WITH_KEY)
public function addAction($title, $signal, $icon = NULL, $useAjax = FALSE, $key = DataGridAction::WITH_KEY)
{
if (!$this->hasColumns('ActionColumn')) {
throw new InvalidStateException('No ActionColumn defined. Use DataGrid::addActionColumn before you add actions.');
}

return $this->currentActionColumn->addAction($title, $signal, $icon, $useAjax, $type);
return $this->currentActionColumn->addAction($title, $signal, $icon, $useAjax, $key);
}


Expand Down
28 changes: 17 additions & 11 deletions app/components/DataGrid/DataGridAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class DataGridAction extends Component implements IDataGridAction
/** @var string */
static public $ajaxClass = 'datagrid-ajax';

/** @var string */
public $type;

/** @var string */
public $destination;

/** @var bool|string */
public $key;


/**
Expand All @@ -43,14 +43,15 @@ class DataGridAction extends Component implements IDataGridAction
* @param string textual link destination
* @param Html element which is added to a generated link
* @param bool use ajax? (add class self::$ajaxClass into generated link)
* @param bool generate link with argument? (variable $keyName must be defined in data grid)
* @param mixed generate link with argument? (if yes you can specify name of parameter
* otherwise variable DataGrid::$keyName will be used and must be defined)
* @return void
*/
public function __construct($title, $destination, Html $icon = NULL, $useAjax = FALSE, $type = self::WITH_KEY)
public function __construct($title, $destination, Html $icon = NULL, $useAjax = FALSE, $key = self::WITH_KEY)
{
parent::__construct();
$this->type = $type;
$this->destination = $destination;
$this->key = $key;

$a = Html::el('a')->title($title);
if ($useAjax) $a->addClass(self::$ajaxClass);
Expand All @@ -70,11 +71,16 @@ public function __construct($title, $destination, Html $icon = NULL, $useAjax =
*/
public function generateLink(array $args = NULL)
{
$control = $this->lookup('DataGrid', TRUE)->lookup('Nette\Application\Control', TRUE);
switch ($this->type) {
case self::WITHOUT_KEY: $link = $control->link($this->destination); break;
case self::WITH_KEY: $link = $control->link($this->destination, $args); break;
default: throw new InvalidArgumentException("Invalid type of action.");
$dataGrid = $this->lookup('DataGrid', TRUE);
$control = $dataGrid->lookup('Nette\Application\Control', TRUE);

switch ($this->key) {
case self::WITHOUT_KEY:
$link = $control->link($this->destination); break;
case self::WITH_KEY:
default:
$key = $this->key == NULL || is_bool($this->key) ? $dataGrid->keyName : $this->key;
$link = $control->link($this->destination, array($key => $args[$dataGrid->keyName])); break;
}

$this->html->href($link);
Expand Down
4 changes: 2 additions & 2 deletions app/components/DataGrid/DataGridRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function render(DataGrid $dataGrid, $mode = NULL)
}

if ($mode !== NULL) {
return call_user_func_array(array($this, 'render' . $mode), NULL);
return call_user_func_array(array($this, 'render' . $mode), array());
}

$template = $this->dataGrid->getTemplate();
Expand Down Expand Up @@ -513,7 +513,7 @@ protected function generateContentRow($data)

if ($this->dataGrid->hasOperations() || $this->dataGrid->hasActions()) {
$primary = $this->dataGrid->keyName;
if (!array_key_exists($primary, $data)) {
if (!isset($data[$primary])) {
throw new InvalidArgumentException("Invalid name of key for group operations or actions. Column '" . $primary . "' does not exist in data source.");
}
}
Expand Down
10 changes: 5 additions & 5 deletions app/config.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[common]
variable.modelsDir = "%appDir%/models"
variable.tempDir = "%appDir%/temp"
variable.componentsDir = "%appDir%/components"
variable.templatesDir = "%appDir%/templates"
variable.sessionDir = "%appDir%/sessions"
variable.modelsDir = "%appDir%/models"
variable.tempDir = "%appDir%/temp"
variable.componentsDir = "%appDir%/components"
variable.templatesDir = "%appDir%/templates"
variable.sessionDir = "%appDir%/sessions"

; dalsi volitelne nastaveni promennych pro upraveni cest
variable.cacheBase = "%tempDir%/cache-"
Expand Down
13 changes: 9 additions & 4 deletions document_root/js/datagrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ $(function () {

// prolínací efekt při updatu snippetu
jQuery.extend({
updateSnippet: function (id, html) {
$("#" + id).fadeTo("fast", 0.3, function () {
$(this).html(html).fadeTo("fast", 1);
});
nette: {
updateSnippet: function (id, html) {
$("#" + id).fadeTo("fast", 0.3, function () {
$(this).html(html).fadeTo("fast", 1);
$.nette.registerAfterUpdate();
});
},

registerAfterUpdate: function() { }
}
});

Expand Down

0 comments on commit 418135c

Please sign in to comment.