Skip to content

Commit

Permalink
Allow managing of global event types from container side
Browse files Browse the repository at this point in the history
  • Loading branch information
yurabakhtin committed Sep 27, 2023
1 parent 5ad00c8 commit 9a7555e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
16 changes: 13 additions & 3 deletions controllers/AbstractConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use humhub\modules\calendar\models\DefaultSettings;
use humhub\modules\calendar\models\forms\BasicSettings;
use humhub\modules\calendar\models\participation\ParticipationSettings;
use humhub\modules\content\components\ContentContainerActiveRecord;
use humhub\modules\content\components\ContentContainerController;
use humhub\modules\content\models\ContentContainer;
use Yii;
use yii\data\ActiveDataProvider;
use yii\web\HttpException;
Expand Down Expand Up @@ -84,9 +86,11 @@ public function actionDeleteType($id)

$this->validateEntry($model);

$model->delete();
if ($model->delete()) {
$this->view->success(Yii::t('CalendarModule.base', 'Deleted'));
}

return $this->htmlRedirect(Url::toConfigTypes($this->contentContainer));
return $this->htmlRedirect(Url::toConfigTypes($this->contentContainer ?? $this->getContainerFromRequest()));
}

public function actionEditType($id = null)
Expand All @@ -100,7 +104,7 @@ public function actionEditType($id = null)

if($model->load(Yii::$app->request->post()) && $model->save()) {
$this->view->saved();
return $this->htmlRedirect(URL::toConfigTypes($this->contentContainer));
return $this->htmlRedirect(URL::toConfigTypes($this->contentContainer ?? $this->getContainerFromRequest()));
}

return $this->renderAjax(static::VIEW_CONFIG_EDIT_TYPE_MODAL, ['model' => $model]);
Expand Down Expand Up @@ -164,4 +168,10 @@ protected function getContentContainerId()
{
return $this->contentContainer ? $this->contentContainer->contentcontainer_id : null;
}

protected function getContainerFromRequest(): ?ContentContainerActiveRecord
{
$guid = Yii::$app->request->get('guid', Yii::$app->request->post('guid'));
return $guid ? ContentContainer::findRecord($guid) : null;
}
}
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
-----------------------
- Enh #424: Tests for `next` version
- Enh #423: Add Create Button
- Enh #379: Allow managing of global event types from container side

1.5.3 (September 14, 2023)
--------------------------
Expand Down
20 changes: 14 additions & 6 deletions helpers/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ public static function toConfigTypes(ContentContainerActiveRecord $container = n

public static function toEditType(CalendarEntryType $model, ContentContainerActiveRecord $container = null)
{
if($container) {
return $container->createUrl('/calendar/container-config/edit-type', ['id' => $model->id] );
if ($model->container instanceof ContentContainerActiveRecord) {
return $model->container->createUrl('/calendar/container-config/edit-type', ['id' => $model->id] );
}

return static::to(['/calendar/config/edit-type', 'id' => $model->id]) ;
$params = ['/calendar/config/edit-type', 'id' => $model->id];
if ($container !== null) {
$params['guid'] = $container->guid;
}
return static::to($params);
}

public static function toCreateType(ContentContainerActiveRecord $container = null)
Expand All @@ -53,11 +57,15 @@ public static function toCreateType(ContentContainerActiveRecord $container = nu

public static function toDeleteType(CalendarEntryType $model, ContentContainerActiveRecord $container = null)
{
if($container) {
return $container->createUrl('/calendar/container-config/delete-type', ['id' => $model->id]);
if ($model->container instanceof ContentContainerActiveRecord) {
return $model->container->createUrl('/calendar/container-config/delete-type', ['id' => $model->id]);
}

return static::to(['/calendar/config/delete-type', 'id' => $model->id]);
$params = ['/calendar/config/delete-type', 'id' => $model->id];
if ($container !== null) {
$params['guid'] = $container->guid;
}
return static::to($params);
}

public static function toConfigCalendars(ContentContainerActiveRecord $container = null)
Expand Down
20 changes: 14 additions & 6 deletions views/common/_calendarTypeItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
*
*/

use yii\helpers\Html;
use humhub\modules\admin\permissions\ManageModules;
use humhub\widgets\Label;
use humhub\widgets\ModalButton;
use yii\helpers\Html;

/* @var $editUrl string */
/* @var $deleteUrl string */
Expand All @@ -23,11 +25,17 @@
<span class="input-group-addon">
<i style="display:inline-block;width:16px;height:16px;background-color: <?= Html::encode($color)?>"></i>
</span>
<input class="form-control" value="<?= Html::encode($title) ?><?= ($disabled ? ' - '.Yii::t('CalendarModule.config', '(disabled)') : '') ?>" title="<?= Yii::t('CalendarModule.base', 'Event type color');?>" type="text" readonly>
<span class="form-control" readonly>
<?= Html::encode($title) ?>
<?php if ($disabled) : ?>
<?= Label::warning(Yii::t('CalendarModule.base', 'disabled')) ?>
<?php endif; ?>
<?php if ($isSpaceGlobal) : ?>
<?= Label::info(Yii::t('CalendarModule.base', 'global')) ?>
<?php endif; ?>
</span>
<span class="input-group-addon">
<?php if($isSpaceGlobal) : ?>
<small><?= Yii::t('CalendarModule.config', '(global)') ?></small>
<?php else: ?>
<?php if(!$isSpaceGlobal || Yii::$app->user->can([ManageModules::class])) : ?>
<?= ModalButton::primary()->load($editUrl)->icon('fa-pencil')->xs() ?>
<?php if(!empty($deleteUrl)) : ?>
<?= ModalButton::danger()->post($deleteUrl)->confirm(
Expand All @@ -39,4 +47,4 @@
</span>
</div>
</div>
</div>
</div>

0 comments on commit 9a7555e

Please sign in to comment.