-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow resetting of file/image content to default
- Loading branch information
1 parent
58d23cb
commit 15f89f7
Showing
9 changed files
with
229 additions
and
70 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
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* @link https://www.humhub.org/ | ||
* @copyright Copyright (c) HumHub GmbH & Co. KG | ||
* @license https://www.humhub.com/licences | ||
*/ | ||
|
||
namespace humhub\modules\custom_pages\modules\template\widgets; | ||
|
||
use humhub\components\Widget; | ||
use humhub\modules\custom_pages\modules\template\models\OwnerContent; | ||
use humhub\modules\custom_pages\modules\template\models\PagePermission; | ||
use humhub\modules\custom_pages\modules\template\models\TemplateContentActiveRecord; | ||
use yii\helpers\Url; | ||
|
||
class DeleteContentButton extends Widget | ||
{ | ||
public ?TemplateContentActiveRecord $model = null; | ||
public string $previewId = ''; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function beforeRun() | ||
{ | ||
return parent::beforeRun() && $this->canDelete(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function run() | ||
{ | ||
return $this->render('deleteContentButton', [ | ||
'url' => Url::to(['/custom_pages/template/owner-content/delete-by-content']), | ||
'options' => $this->getOptions() | ||
]); | ||
} | ||
|
||
private function canDelete(): bool | ||
{ | ||
if (!$this->model instanceof TemplateContentActiveRecord) { | ||
return false; | ||
} | ||
|
||
if ($this->model->isNewRecord) { | ||
return false; | ||
} | ||
|
||
$ownerContent = OwnerContent::findByContent($this->model); | ||
|
||
if (!$ownerContent || $ownerContent->isDefault() || $ownerContent->isEmpty()) { | ||
return false; | ||
} | ||
|
||
return PagePermission::canEdit(); | ||
} | ||
|
||
private function getOptions(): array | ||
{ | ||
return ['data' => [ | ||
'placement' => 'bottom', | ||
'owner-content' => get_class($this->model), | ||
'owner-content-id' => $this->model->id, | ||
'preview-id' => $this->previewId | ||
]]; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* @link https://www.humhub.org/ | ||
* @copyright Copyright (c) HumHub GmbH & Co. KG | ||
* @license https://www.humhub.com/licences | ||
*/ | ||
|
||
use humhub\widgets\Button; | ||
|
||
/* @var string $url */ | ||
/* @var array $options */ | ||
?> | ||
<?= Button::danger(Yii::t('CustomPagesModule.base', 'Delete')) | ||
->action('custom_pages.template.deleteElementContent', $url) | ||
->icon('times') | ||
->tooltip(Yii::t('CustomPagesModule.base', 'Reset the content to default value')) | ||
->options($options) | ||
->confirm(Yii::t('CustomPagesModule.modules_template_controller_OwnerContentController', '<strong>Confirm</strong> content deletion'), | ||
Yii::t('CustomPagesModule.modules_template_widgets_views_confirmDeletionModal', 'Do you really want to delete this content?'), | ||
Yii::t('CustomPagesModule.base', 'Delete')) | ||
?> |
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,40 +1,45 @@ | ||
<?php | ||
/* @var $model humhub\modules\custom_pages\modules\template\models\template\FileContent */ | ||
/* @var $form \humhub\modules\ui\form\widgets\ActiveForm */ | ||
use humhub\modules\custom_pages\modules\template\models\FileContent; | ||
use humhub\modules\custom_pages\modules\template\widgets\DeleteContentButton; | ||
use humhub\modules\file\widgets\FilePreview; | ||
use humhub\modules\file\widgets\UploadButton; | ||
use humhub\modules\file\widgets\UploadProgress; | ||
use humhub\modules\ui\form\widgets\ActiveForm; | ||
|
||
use yii\helpers\Url; | ||
|
||
$uploadUrl = Url::to(['/file/file/upload']); | ||
/* @var $model FileContent */ | ||
/* @var $form ActiveForm */ | ||
|
||
$id = 'fileContent-' . $model->id; | ||
?> | ||
|
||
<?= $form->field($model, 'file_guid')->hiddenInput(['class' => 'file-guid'])->label(false); ?> | ||
|
||
<div id="<?= $id ?>" class="file-upload-container clearfix"> | ||
|
||
<?= | ||
\humhub\modules\file\widgets\UploadButton::widget([ | ||
'cssButtonClass' => 'btn-primary', | ||
'model' => $model, | ||
'single' => true, | ||
'label' => true, | ||
'attribute' => 'file_guid', | ||
'dropZone' => '#' . $id, | ||
'tooltip' => false, | ||
'preview' => '#' . $id . '-preview', | ||
'progress' => '#' . $id . '-progress', | ||
'buttonOptions' => ['style' => 'float:left;'] | ||
])?> | ||
|
||
|
||
<?= humhub\modules\file\widgets\FilePreview::widget([ | ||
'id' => $id . '-preview', | ||
'popoverPosition' => 'top', | ||
'items' => [$model->getFile()], | ||
'edit' => true, | ||
'options' => ['style' => 'display:block;margin-left:150px']]) ?> | ||
|
||
<?= humhub\modules\file\widgets\UploadProgress::widget(['id' => $id . '-progress', 'options' => ['style' => 'display:block;margin-left:150px;width:500px']]) ?> | ||
|
||
<div class="row"> | ||
<div class="col-md-4 uploadContainer"> | ||
<?= UploadButton::widget([ | ||
'cssButtonClass' => 'btn-primary', | ||
'model' => $model, | ||
'single' => true, | ||
'label' => true, | ||
'attribute' => 'file_guid', | ||
'dropZone' => '#' . $id, | ||
'tooltip' => false, | ||
'preview' => '#' . $id . '-preview', | ||
'progress' => '#' . $id . '-progress' | ||
]) ?> | ||
<?= DeleteContentButton::widget([ | ||
'model' => $model, | ||
'previewId' => $id . '-preview' | ||
]) ?> | ||
</div> | ||
<div class="col-md-8 previewContainer"> | ||
<?= FilePreview::widget([ | ||
'id' => $id . '-preview', | ||
'popoverPosition' => 'top', | ||
'items' => [$model->getFile()] | ||
]) ?> | ||
<?= UploadProgress::widget(['id' => $id . '-progress']) ?> | ||
</div> | ||
</div> | ||
</div> |
Oops, something went wrong.