-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate wall entry context menu for task on details and list pages
- Loading branch information
1 parent
393fec1
commit 075b852
Showing
11 changed files
with
149 additions
and
140 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,58 +1,123 @@ | ||
<?php | ||
/** | ||
* @link https://www.humhub.org/ | ||
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG | ||
* @copyright Copyright (c) HumHub GmbH & Co. KG | ||
* @license https://www.humhub.com/licences | ||
* | ||
*/ | ||
|
||
namespace humhub\modules\tasks\widgets; | ||
|
||
use humhub\libs\Html; | ||
use humhub\modules\content\widgets\WallEntryControls; | ||
use humhub\modules\tasks\helpers\TaskUrl; | ||
use humhub\modules\tasks\models\Task; | ||
use yii\base\Widget; | ||
use humhub\modules\ui\menu\MenuLink; | ||
use humhub\widgets\Link; | ||
use Yii; | ||
|
||
/** | ||
* Widget for rendering the menue buttons for a Task. | ||
* Widget for rendering the menu buttons for a Task. | ||
* @author davidborn | ||
*/ | ||
class TaskContextMenu extends Widget | ||
class TaskContextMenu extends WallEntryControls | ||
{ | ||
/** | ||
* @inheritdoc | ||
* Use this plugin for methods like `makePublicLink`, `lockComments`, `pin`, etc. | ||
*/ | ||
public $jsWidget = 'stream.StreamEntry'; | ||
|
||
/** | ||
* @var Task | ||
* @inheritdoc | ||
*/ | ||
public $task; | ||
public $template = 'taskContextMenu'; | ||
|
||
public ?Task $task = null; | ||
|
||
public string $mode = 'details'; | ||
|
||
public ?string $align = null; | ||
|
||
/** | ||
* @var \humhub\modules\content\components\ContentContainerActiveRecord Current content container. | ||
* @inheritdoc | ||
*/ | ||
public $contentContainer; | ||
public function beforeRun() | ||
{ | ||
return parent::beforeRun() && $this->task->content->canEdit(); | ||
} | ||
|
||
/** | ||
* @var boolean Determines if the user has write permissions. | ||
* @inheritdoc | ||
*/ | ||
public $canEdit; | ||
public function init() | ||
{ | ||
$this->object = $this->task; | ||
$this->wallEntryWidget = new WallEntry(['model' => $this->task]); | ||
|
||
parent::init(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function run() | ||
public function getAttributes() | ||
{ | ||
if(!$this->task->content->canEdit()) { | ||
return ''; | ||
$attrs = parent::getAttributes(); | ||
Html::addCssClass($attrs, 'task-preferences'); | ||
return $attrs; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getViewParams() | ||
{ | ||
$params = parent::getViewParams(); | ||
$params['toggler'] = $this->getToggler(); | ||
return $params; | ||
} | ||
|
||
public function initControls() | ||
{ | ||
$this->renderOptions->disableControlsEntryEdit(); | ||
$this->renderOptions->disableControlsEntryDelete(); | ||
|
||
if ($this->task->content->canEdit()) { | ||
$this->addEntry(new MenuLink([ | ||
'label' => Yii::t('TasksModule.base', 'Edit'), | ||
'url' => '#', | ||
'icon' => 'pencil', | ||
'sortOrder' => 100, | ||
'htmlOptions' => [ | ||
'data-action-click' => 'ui.modal.post', | ||
'data-action-click-url' => TaskUrl::editTask($this->task), | ||
], | ||
])); | ||
|
||
$this->addEntry(new MenuLink([ | ||
'label' => Yii::t('TasksModule.base', 'Delete'), | ||
'url' => '#', | ||
'icon' => 'trash', | ||
'sortOrder' => 300, | ||
'htmlOptions' => [ | ||
'data-action-click' => 'ui.modal.post', | ||
'data-action-click-url' => TaskUrl::deleteTask($this->task), | ||
'data-action-confirm-header' => Yii::t('TasksModule.base', '<strong>Confirm</strong> task deletion'), | ||
'data-action-confirm' => Yii::t('TasksModule.base', 'Do you really want to delete this task?'), | ||
'data-action-confirm-text' => Yii::t('TasksModule.base', 'Delete') | ||
], | ||
])); | ||
} | ||
|
||
return $this->render('taskMenuDropdown', [ | ||
'deleteUrl' => TaskUrl::deleteTask($this->task, null, 1), | ||
'editUrl' => TaskUrl::editTask($this->task, null, 1), | ||
'task' => $this->task, | ||
'extensionRequestUrl' => TaskUrl::requestExtension($this->task), | ||
'resetUrl' => TaskUrl::resetTask($this->task), | ||
'canEdit' => $this->task->content->canEdit(), | ||
'canRequestExtension' => ( $this->task->schedule->canRequestExtension()), | ||
'canReset' => $this->task->canResetTask() | ||
]); | ||
parent::initControls(); | ||
} | ||
|
||
private function getToggler(): Link | ||
{ | ||
if ($this->mode === 'details') { | ||
return Link::asLink('<span class="caret"></span>')->icon('cog'); | ||
} | ||
|
||
return Link::asLink()->icon('ellipsis-v'); | ||
} | ||
} |
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
Oops, something went wrong.