Skip to content

Commit

Permalink
ADD: label to metadata definition and general ENH in forms
Browse files Browse the repository at this point in the history
  • Loading branch information
glpzzz committed Aug 15, 2020
1 parent 8d3ace1 commit 1164f67
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace daxslab\website\migrations;

/**
* Handles adding columns to table `{{%metadata_definition}}`.
*/
class m200815_005933_add_label_column_to_metadata_definition_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('{{%metadata_definition}}', 'label', $this->string()->null());
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('{{%metadata_definition}}', 'label');
}
}
5 changes: 4 additions & 1 deletion models/MetadataDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace daxslab\website\models;

use Yii;
use yii\helpers\Inflector;

/**
* This is the model class for table "metadata_definition".
*
* @property int $id
* @property string $name
* @property string $label
* @property string $type
* @property string $params
* @property int $page_type_id
Expand Down Expand Up @@ -36,7 +38,7 @@ public function rules()
{
return [
[['name', 'type'], 'required'],
[['params'], 'string'],
[['params', 'label'], 'string'],
[['page_type_id'], 'integer'],
[['name', 'type'], 'string', 'max' => 255],
[['page_type_id', 'name'], 'unique', 'targetAttribute' => ['page_type_id', 'name']],
Expand All @@ -57,6 +59,7 @@ public function attributeLabels()
return array_merge(parent::attributeLabels(), [
'id' => Yii::t('website','ID'),
'name' => Yii::t('website','Name'),
'label' => Yii::t('website','Label'),
'type' => Yii::t('website','Type'),
'params' => Yii::t('website','Params'),
'page_type_id' => Yii::t('website','Page Type ID'),
Expand Down
2 changes: 1 addition & 1 deletion views/backend/media/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/* @var $this yii\web\View */
/* @var $model backend\models\Media */
/* @var $form yii\widgets\ActiveForm */
/* @var $form yii\bootstrap4\ActiveForm */
?>

<div class="media-form">
Expand Down
6 changes: 3 additions & 3 deletions views/backend/menu-item/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/* @var $this yii\web\View */
/* @var $model backend\models\MenuItem */
/* @var $form yii\widgets\ActiveForm */
/* @var $form yii\bootstrap4\ActiveForm */
?>

<div class="menu-item-form">
Expand Down Expand Up @@ -35,7 +35,7 @@

<?php \yii\bootstrap4\Modal::begin([
'id' => 'select-content-modal',
'title' => Html::tag('h4', Yii::t('website','Select content'), ['class' => 'modal-title']),
'title' => Html::tag('h4', Yii::t('website', 'Select content'), ['class' => 'modal-title']),
'options' => [
'data' => [
'target-field' => '#menuitem-url',
Expand All @@ -53,7 +53,7 @@
<?php \yii\bootstrap4\Modal::end() ?>

<div class="form-group">
<?= Html::submitButton(Yii::t('website','Save'), ['class' => 'btn btn-success']) ?>
<?= Html::submitButton(Yii::t('website', 'Save'), ['class' => 'btn btn-success']) ?>
</div>

<?php ActiveForm::end(); ?>
Expand Down
16 changes: 9 additions & 7 deletions views/backend/menu/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/* @var $this yii\web\View */
/* @var $model daxslab\website\models\Menu */
/* @var $form yii\widgets\ActiveForm */
/* @var $form yii\bootstrap4\ActiveForm */
?>

<div class="menu-form">
Expand All @@ -21,12 +21,14 @@
<?= Html::activeHiddenInput($model, 'website_id') ?>

<div class="form-group">
<?= Html::submitButton(Yii::t('website','Save'), ['class' => 'btn btn-success']) ?>
<?= Html::a(Yii::t('website','Delete'), \daxslab\website\components\Lookup::getLink($model, 'delete'), [
'class' => 'btn btn-danger',
'data-method' => 'post',
'data-confirm' => Yii::t('website','Are you sure you want to delete this item?')
]) ?>
<?= Html::submitButton(Yii::t('website', 'Save'), ['class' => 'btn btn-success']) ?>
<?php if (!$model->isNewRecord): ?>
<?= Html::a(Yii::t('website', 'Delete'), \daxslab\website\components\Lookup::getLink($model, 'delete'), [
'class' => 'btn btn-danger',
'data-method' => 'post',
'data-confirm' => Yii::t('website', 'Are you sure you want to delete this item?')
]) ?>
<?php endif; ?>
</div>

<?php ActiveForm::end(); ?>
Expand Down
23 changes: 14 additions & 9 deletions views/backend/metadata-definition/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/* @var $this yii\web\View */
/* @var $model daxslab\website\models\MetadataDefinition */
/* @var $form yii\widgets\ActiveForm */
/* @var $form yii\bootstrap4\ActiveForm */

$typeOptions = [
\yii\validators\BooleanValidator::class => 'boolean',
Expand All @@ -25,23 +25,28 @@
<?php $form = ActiveForm::begin(); ?>

<div class="row">
<div class="col-md-6">
<div class="col-md-4">
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
</div>
<div class="col-md-6">
<div class="col-md-4">
<?= $form->field($model, 'label')->textInput(['maxlength' => true, 'placeholder' => Yii::t('app', 'Optional')]) ?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'type')->dropDownList($typeOptions) ?>
</div>
</div>

<?= $form->field($model, 'params')->textarea(['rows' => 6]) ?>

<div class="form-group">
<?= Html::submitButton(Yii::t('website','Save'), ['class' => 'btn btn-success']) ?>
<?= Html::a(Yii::t('website','Delete'), Lookup::getLink($model, 'delete'), [
'class' => 'btn btn-danger',
'data-method' => 'post',
'data-confirm' => Yii::t('website','Are you sure you want to delete this item?')
]) ?>
<?= Html::submitButton(Yii::t('website', 'Save'), ['class' => 'btn btn-success']) ?>
<?php if (!$model->isNewRecord): ?>
<?= Html::a(Yii::t('website', 'Delete'), Lookup::getLink($model, 'delete'), [
'class' => 'btn btn-danger',
'data-method' => 'post',
'data-confirm' => Yii::t('website', 'Are you sure you want to delete this item?')
]) ?>
<?php endif; ?>
</div>

<?php ActiveForm::end(); ?>
Expand Down
5 changes: 4 additions & 1 deletion views/backend/metadata-definition/_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
?>

<li id="<?= $model->id ?>">
<h3><?= Html::a(Html::encode($model->name), ["/$module/metadata-definition/update", 'id' => $model->id]) ?></h3>
<h3><?= Html::a(Yii::t('app', '{label} {name}', [
'label' => Html::encode($model->label),
'name' => Html::tag('span', '(' . Html::encode($model->name) . ')', ['class' => 'text-muted']),
]), ["/$module/metadata-definition/update", 'id' => $model->id]) ?></h3>
<p><?= $model->type ?></p>
</li>

16 changes: 9 additions & 7 deletions views/backend/page-type/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/* @var $this yii\web\View */
/* @var $model daxslab\website\models\PageType */
/* @var $form yii\widgets\ActiveForm */
/* @var $form yii\bootstrap4\ActiveForm */
?>

<div class="page-type-form">
Expand All @@ -18,12 +18,14 @@
<?= Html::activeHiddenInput($model, 'website_id') ?>

<div class="form-group">
<?= Html::submitButton(Yii::t('website','Save'), ['class' => 'btn btn-success']) ?>
<?= Html::a(Yii::t('website','Delete'), Lookup::getLink($model, 'delete'), [
'class' => 'btn btn-danger',
'data-method' => 'post',
'data-confirm' => Yii::t('website','Are you sure you want to delete this item?')
]) ?>
<?= Html::submitButton(Yii::t('website', 'Save'), ['class' => 'btn btn-success']) ?>
<?php if (!$model->isNewRecord): ?>
<?= Html::a(Yii::t('website', 'Delete'), Lookup::getLink($model, 'delete'), [
'class' => 'btn btn-danger',
'data-method' => 'post',
'data-confirm' => Yii::t('website', 'Are you sure you want to delete this item?')
]) ?>
<?php endif; ?>
</div>

<?php ActiveForm::end(); ?>
Expand Down
109 changes: 60 additions & 49 deletions views/backend/page/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,56 @@

<?= Html::errorSummary(array_merge([$model], $metadatas), ['class' => 'alert alert-danger']) ?>

<div class="row">
<div class="col-md-8">
<?= $form->field($model, 'title') ?>
</div>
<div class="col-md-2">
<?= $form->field($model, 'page_type_id')->widget(\dosamigos\selectize\SelectizeDropDownList::class, [
'items' => $pageTypeOptions,
]) ?>
</div>
<div class="col-md-2">
<?= $form->field($model, 'status')->widget(\kartik\switchinput\SwitchInput::class, [
'pluginOptions' => [
'onText' => Yii::t('website', 'Published'),
'offText' => Yii::t('app', 'Draft'),
],
'options' => [
'onchange' => "this.form.submit()",
]
]) ?>
</div>
</div>
<div class="row">
<div class="col-md-8">

<?= $form->field($model, 'abstract')->textarea(['rows' => 3]) ?>

<div class="row">
<div class="col-md-8">
<?= $form->field($model, 'title') ?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'page_type_id')->widget(\dosamigos\selectize\SelectizeDropDownList::class, [
'items' => $pageTypeOptions,
]) ?>
<?php if (!empty($metadatas)): ?>
<div class="row">
<?php foreach ($metadatas as $index => $md): ?>
<div class="col-md-6">
<?php if ($md->metadataDefinition->type == \yii\validators\BooleanValidator::class): ?>
<?= $form
->field($md, "[{$index}]value")
->checkbox()
->label(Yii::t('app', '{label} {name}', [
'label' => Html::encode($md->metadataDefinition->label),
'name' => Html::tag('span', '(' . Html::encode($md->metadataDefinition->name) . ')', ['class' => 'text-muted']),
])) ?>
<?php else: ?>
<?= $form
->field($md, "[{$index}]value")
->label(Yii::t('app', '{label} {name}', [
'label' => Html::encode($md->metadataDefinition->label),
'name' => Html::tag('span', '(' . Html::encode($md->metadataDefinition->name) . ')', ['class' => 'text-muted']),
])) ?>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
</div>

<?= $form->field($model, 'abstract')->textarea(['rows' => 3]) ?>
<?php endif; ?>

<?php
// add showprotected ckeditor plugin for allowing usage of components
Expand Down Expand Up @@ -73,33 +107,12 @@
$this->registerJs($script, View::POS_END);
?>

<h2><?= Yii::t('website', 'Subpages') ?></h2>

<?= $model->id == null
? Html::tag('div', Yii::t('website', 'You must save this page before adding subpages'), ['class' => 'alert alert-info'])
: Yii::$app->runAction("/{$module}/page/index", [
'parent_id' => $model->id,
'language' => $model->language,
]) ?>


</div>
<div class="col-md-4">

<?= $form->field($model, 'status')->widget(\kartik\switchinput\SwitchInput::class, [
'pluginOptions' => [
'onText' => Yii::t('website', 'Published'),
'offText' => Yii::t('app', 'Draft'),
],
'options' => [
'onchange' => "this.form.submit()",
]
]) ?>

<div class="card mb-4">
<?= Html::activeLabel($model, 'image', ['class' => 'card-header']) ?>
<?= Html::img(isset($model->image) ? $model->image : $defaultImage, ['id' => 'page-image-preview', 'class' => 'img-fluid']) ?>
<div class="image-area card-body p-0">
<div class="mb-4">
<?= Html::activeLabel($model, 'image') ?>
<div class="image-area">
<div class="form-group mb-0">
<div class="input-group">
<?= Html::activeTextInput($model, 'image', ['class' => 'form-control']) ?>
Expand Down Expand Up @@ -134,23 +147,11 @@
<?php \yii\bootstrap4\Modal::end() ?>
</div>
</div>
<?= Html::img(isset($model->image) ? $model->image : $defaultImage, ['id' => 'page-image-preview', 'class' => 'img-fluid']) ?>
</div>

<?php foreach ($metadatas as $index => $md): ?>
<?php if ($md->metadataDefinition->type == \yii\validators\BooleanValidator::class): ?>
<?= $form
->field($md, "[{$index}]value")
->checkbox()
->label($md->metadataDefinition->name) ?>
<?php else: ?>
<?= $form
->field($md, "[{$index}]value")
->label($md->metadataDefinition->name) ?>
<?php endif; ?>
<?php endforeach; ?>

<div class="form-group">
<?= Html::submitButton(Yii::t('website', 'Save'), ['class' => 'btn btn-primary']) ?>
<?= Html::submitButton(Yii::t('website', 'Save'), ['class' => 'btn btn-success']) ?>
<?php if (!$model->isNewRecord): ?>
<?= Html::a(Yii::t('website', 'Delete'), Lookup::getLink($model, 'delete'), ['class' => 'btn btn-danger',
'data-method' => 'post',
Expand All @@ -163,4 +164,14 @@

<?php ActiveForm::end(); ?>

<h2><?= Yii::t('website', 'Subpages') ?></h2>

<?= $model->id == null
? Html::tag('div', Yii::t('website', 'You must save this page before adding subpages'), ['class' => 'alert alert-info'])
: Yii::$app->runAction("/{$module}/page/index", [
'parent_id' => $model->id,
'language' => $model->language,
]) ?>


</div><!-- _form -->
2 changes: 1 addition & 1 deletion views/backend/website/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/* @var $this yii\web\View */
/* @var $model daxslab\website\models\Website */
/* @var $form yii\widgets\ActiveForm */
/* @var $form yii\bootstrap4\ActiveForm */
?>

<div class="website-form">
Expand Down

0 comments on commit 1164f67

Please sign in to comment.