-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Events: Added parent parameter to rename-node event.
- Loading branch information
Showing
1 changed file
with
51 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,51 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Pehape libraries (http://pehape.cz) | ||
* Copyright (c) 2016 Tomas Rathouz <trathouz at gmail.com> | ||
*/ | ||
|
||
namespace Pehape\DataTree\Events; | ||
|
||
use Nette\Utils\ArrayHash; | ||
use Pehape\DataTree\Components\DataTree; | ||
use Pehape\DataTree\Exceptions; | ||
|
||
|
||
/** | ||
* RenameNodeEvent. | ||
* | ||
* @author Tomas Rathouz <trathouz at gmail.com> | ||
*/ | ||
class RenameNodeEvent extends BaseEvent | ||
{ | ||
|
||
/** @var array */ | ||
protected $parameters = [ | ||
'id' => 'data.node.id', | ||
'text' => 'data.node.text', | ||
'type' => 'data.node.type', | ||
]; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->callback = $this->getDefaultCallback(); | ||
} | ||
|
||
public function getDefaultCallback() | ||
{ | ||
return function (DataTree $tree, ArrayHash $parameters) { | ||
try { | ||
$tree->getDataSource()->updateNode($parameters->id, ['name' => $parameters->text]); | ||
} catch (Exceptions\DataSourceException $e) { | ||
$tree->sendErrorResponse([]); | ||
} | ||
|
||
$tree->sendSuccessResponse([]); | ||
}; | ||
} | ||
|
||
|
||
} | ||
<?php | ||
|
||
/** | ||
* This file is part of the Pehape libraries (http://pehape.cz) | ||
* Copyright (c) 2016 Tomas Rathouz <trathouz at gmail.com> | ||
*/ | ||
|
||
namespace Pehape\DataTree\Events; | ||
|
||
use Nette\Utils\ArrayHash; | ||
use Pehape\DataTree\Components\DataTree; | ||
use Pehape\DataTree\Exceptions; | ||
|
||
|
||
/** | ||
* RenameNodeEvent. | ||
* | ||
* @author Tomas Rathouz <trathouz at gmail.com> | ||
*/ | ||
class RenameNodeEvent extends BaseEvent | ||
{ | ||
|
||
/** @var array */ | ||
protected $parameters = [ | ||
'id' => 'data.node.id', | ||
'text' => 'data.node.text', | ||
'type' => 'data.node.type', | ||
'parent' => 'data.node.parent', | ||
]; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->callback = $this->getDefaultCallback(); | ||
} | ||
|
||
public function getDefaultCallback() | ||
{ | ||
return function (DataTree $tree, ArrayHash $parameters) { | ||
try { | ||
$tree->getDataSource()->updateNode($parameters->id, ['name' => $parameters->text]); | ||
} catch (Exceptions\DataSourceException $e) { | ||
$tree->sendErrorResponse([]); | ||
} | ||
|
||
$tree->sendSuccessResponse([]); | ||
}; | ||
} | ||
|
||
|
||
} |