Commit 0388e8aa by semenov

Новая форма для админки с табами ActiveFormUseTab

parent cd3f8a7a
<?php fltkf<?php
/** /**
* @author Semenov Alexander <semenov@skeeks.com> * @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/ * @link http://skeeks.com/
......
...@@ -24,7 +24,6 @@ class AdminFormFieldController extends AdminModelEditorSmartController ...@@ -24,7 +24,6 @@ class AdminFormFieldController extends AdminModelEditorSmartController
public function init() public function init()
{ {
$this->_label = "Управление email форм"; $this->_label = "Управление email форм";
$this->_modelShowAttribute = "value";
$this->_modelClassName = FormField::className(); $this->_modelClassName = FormField::className();
$this->modelValidate = true; $this->modelValidate = true;
$this->enableScenarios = true; $this->enableScenarios = true;
......
...@@ -38,6 +38,8 @@ class m150307_162735_create_form_field_table extends Migration ...@@ -38,6 +38,8 @@ class m150307_162735_create_form_field_table extends Migration
'widget' => Schema::TYPE_TEXT . ' NULL', 'widget' => Schema::TYPE_TEXT . ' NULL',
'rules' => Schema::TYPE_TEXT . ' NULL', 'rules' => Schema::TYPE_TEXT . ' NULL',
'priority' => Schema::TYPE_INTEGER . ' NOT NULL DEFAULT 0',
'attribute' => Schema::TYPE_STRING . '(255) NOT NULL', 'attribute' => Schema::TYPE_STRING . '(255) NOT NULL',
'form_id' => Schema::TYPE_INTEGER . '(255) NOT NULL', 'form_id' => Schema::TYPE_INTEGER . '(255) NOT NULL',
...@@ -50,6 +52,7 @@ class m150307_162735_create_form_field_table extends Migration ...@@ -50,6 +52,7 @@ class m150307_162735_create_form_field_table extends Migration
$this->execute("ALTER TABLE {{%form_field}} ADD INDEX(updated_at);"); $this->execute("ALTER TABLE {{%form_field}} ADD INDEX(updated_at);");
$this->execute("ALTER TABLE {{%form_field}} ADD INDEX(label);"); $this->execute("ALTER TABLE {{%form_field}} ADD INDEX(label);");
$this->execute("ALTER TABLE {{%form_field}} ADD INDEX(priority);");
$this->execute("ALTER TABLE {{%form_field}} ADD UNIQUE(attribute,form_id);"); $this->execute("ALTER TABLE {{%form_field}} ADD UNIQUE(attribute,form_id);");
$this->execute("ALTER TABLE {{%form_field}} COMMENT = 'Элементы форм';"); $this->execute("ALTER TABLE {{%form_field}} COMMENT = 'Элементы форм';");
......
...@@ -42,14 +42,20 @@ class FormField extends Core ...@@ -42,14 +42,20 @@ class FormField extends Core
{ {
return array_merge(parent::rules(), [ return array_merge(parent::rules(), [
[['created_by', 'updated_by', 'created_at', 'updated_at', 'form_id'], 'integer'], [['created_by', 'updated_by', 'created_at', 'updated_at', 'form_id'], 'integer'],
[['hint', 'widget', 'rules'], 'string'], [['hint'], 'string'],
[['attribute', 'form_id'], 'required'], [['widget', 'rules'], 'safe'],
[[ 'form_id'], 'required'],
['attribute', 'default', 'value' => function(FormField $model, $attribute)
{
return "sx-field-" . md5(rand(1, 10) . time());
}],
[['label', 'attribute'], 'string', 'max' => 255], [['label', 'attribute'], 'string', 'max' => 255],
[['attribute', 'form_id'], 'unique', 'targetAttribute' => ['attribute', 'form_id'], 'message' => 'Этот элемент уже привязан к форме'] [['attribute', 'form_id'], 'unique', 'targetAttribute' => ['attribute', 'form_id'], 'message' => 'Этот элемент уже привязан к форме']
]); ]);
} }
public function scenarios() public function scenarios()
{ {
$scenarios = parent::scenarios(); $scenarios = parent::scenarios();
...@@ -69,7 +75,25 @@ class FormField extends Core ...@@ -69,7 +75,25 @@ class FormField extends Core
'id' => \Yii::t('app', 'ID'), 'id' => \Yii::t('app', 'ID'),
'value' => \Yii::t('app', 'Email'), 'value' => \Yii::t('app', 'Email'),
'form_id' => \Yii::t('app', 'Форма'), 'form_id' => \Yii::t('app', 'Форма'),
'attribute' => \Yii::t('app', 'Уникальный код (необязательно)'),
'hint' => \Yii::t('app', 'Небольшая подсказка элемента'),
'label' => \Yii::t('app', 'Название'),
]); ]);
} }
/**
* @return \yii\db\ActiveQuery
*/
public function findForm()
{
return $this->hasOne(Form::className(), ['id' => 'form_id']);
}
/**
* @return Form
*/
public function fetchForm()
{
return $this->findForm()->one();
}
} }
\ No newline at end of file
...@@ -13,7 +13,20 @@ use common\models\User; ...@@ -13,7 +13,20 @@ use common\models\User;
<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>
<?php ?> <?php ?>
<?= $form->field($model, 'form_id')->hiddenInput(['value' => (int) \Yii::$app->request->get('form_id')])->label(false); ?> <? if ($form_id = \Yii::$app->request->get('form_id')) : ?>
<?= $form->field($model, 'form_id')->hiddenInput(['value' => $form_id])->label(false); ?>
<? else: ?>
<?= $form->field($model, 'form_id')->label('Форма')->widget(
\skeeks\widget\chosen\Chosen::className(), [
'items' => \yii\helpers\ArrayHelper::map(
\skeeks\modules\cms\form\models\Form::find()->all(),
"id",
"name"
),
]);
?>
<? endif; ?>
<?= $form->field($model, 'value')->textInput(); ?> <?= $form->field($model, 'value')->textInput(); ?>
<?= $form->buttonsCreateOrUpdate($model); ?> <?= $form->buttonsCreateOrUpdate($model); ?>
......
...@@ -13,8 +13,23 @@ use common\models\User; ...@@ -13,8 +13,23 @@ use common\models\User;
<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>
<?php ?> <?php ?>
<?= $form->field($model, 'form_id')->hiddenInput(['value' => (int) \Yii::$app->request->get('form_id')])->label(false); ?> <? if ($form_id = \Yii::$app->request->get('form_id')) : ?>
<?= $form->field($model, 'value')->textInput(); ?> <?= $form->field($model, 'form_id')->hiddenInput(['value' => $form_id])->label(false); ?>
<? else: ?>
<?= $form->field($model, 'form_id')->label('Форма')->widget(
\skeeks\widget\chosen\Chosen::className(), [
'items' => \yii\helpers\ArrayHelper::map(
\skeeks\modules\cms\form\models\Form::find()->all(),
"id",
"name"
),
]);
?>
<? endif; ?>
<?= $form->field($model, 'attribute')->textInput(); ?>
<?= $form->field($model, 'label')->textInput(); ?>
<?= $form->field($model, 'hint')->textInput(); ?>
<?= $form->buttonsCreateOrUpdate($model); ?> <?= $form->buttonsCreateOrUpdate($model); ?>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>
...@@ -13,7 +13,20 @@ use common\models\User; ...@@ -13,7 +13,20 @@ use common\models\User;
<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>
<?php ?> <?php ?>
<?= $form->field($model, 'form_id')->hiddenInput(['value' => (int) \Yii::$app->request->get('form_id')])->label(false); ?> <? if ($form_id = \Yii::$app->request->get('form_id')) : ?>
<?= $form->field($model, 'form_id')->hiddenInput(['value' => $form_id])->label(false); ?>
<? else: ?>
<?= $form->field($model, 'form_id')->label('Форма')->widget(
\skeeks\widget\chosen\Chosen::className(), [
'items' => \yii\helpers\ArrayHelper::map(
\skeeks\modules\cms\form\models\Form::find()->all(),
"id",
"name"
),
]);
?>
<? endif; ?>
<?= $form->field($model, 'value')->textInput(); ?> <?= $form->field($model, 'value')->textInput(); ?>
<?= $form->buttonsCreateOrUpdate($model); ?> <?= $form->buttonsCreateOrUpdate($model); ?>
......
...@@ -13,7 +13,19 @@ use common\models\User; ...@@ -13,7 +13,19 @@ use common\models\User;
<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>
<?php ?> <?php ?>
<?= $form->field($model, 'form_id')->hiddenInput(['value' => (int) \Yii::$app->request->get('form_id')])->label(false); ?> <? if ($form_id = \Yii::$app->request->get('form_id')) : ?>
<?= $form->field($model, 'form_id')->hiddenInput(['value' => $form_id])->label(false); ?>
<? else: ?>
<?= $form->field($model, 'form_id')->label('Форма')->widget(
\skeeks\widget\chosen\Chosen::className(), [
'items' => \yii\helpers\ArrayHelper::map(
\skeeks\modules\cms\form\models\Form::find()->all(),
"id",
"name"
),
]);
?>
<? endif; ?>
<?= $form->buttonsCreateOrUpdate($model); ?> <?= $form->buttonsCreateOrUpdate($model); ?>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>
<?php <?php
use yii\helpers\Html; use yii\helpers\Html;
use skeeks\cms\modules\admin\widgets\form\ActiveFormStyled as ActiveForm; use skeeks\cms\modules\admin\widgets\form\ActiveFormUseTab as ActiveForm;
use common\models\User; use common\models\User;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
...@@ -66,7 +66,9 @@ use common\models\User; ...@@ -66,7 +66,9 @@ use common\models\User;
'gridViewOptions' => [ 'gridViewOptions' => [
'columns' => [ 'columns' => [
//['class' => 'yii\grid\SerialColumn'], //['class' => 'yii\grid\SerialColumn'],
'value', 'attribute',
'label',
'hint',
], ],
], ],
]); ?> ]); ?>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment