_form.php
4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
use artbox\core\admin\assets\Switchery;
use dosamigos\tinymce\TinyMce;
use kartik\file\FileInput;
use kartik\select2\Select2;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\web\JsExpression;
use yii\web\View;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model \common\models\Book */
/* @var $form yii\widgets\ActiveForm */
/* @var array $data*/
Switchery::register($this);
$js = <<< JS
$('.switchery').each(function(idx, elem) {
new Switchery(elem, {
color:'#46b749',
secondaryColor:'#e2e2e2'
});
});
JS;
$this->registerJs($js, View::POS_READY);
if (!empty($model->image)) {
$files[] ='<img src="/storage/books/' . $model->id . '/' . $model->image . '" class="file-preview-image kv-preview-data rotate-35921 is-portrait-gt4" style="width:200px;" title="' . $model->image . '">';
$config [] = ["url" => "delete-image", "key" => 0, 'extra' => ['image' => $model->image, 'id' => $model->id]];
} else {
$files = [];
$config = [];
}
?>
<div class="feedback-form">
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
<?= $form->field($model, 'title')
->textInput([ 'maxlength' => true ]) ?>
<?php echo FileInput::widget(
[
'name' => 'file',
'options' => [
'multiple' => false,
'accept' => 'image/*',
],
'pluginOptions' => [
'maxFileCount' => 1,
'showUpload' => false,
'removeClass' => 'btn btn-danger',
'removeIcon' => '<i class="glyphicon glyphicon-trash"></i> ',
'initialPreview' => $files,
'overwriteInitial' => true,
'initialPreviewConfig' => $config
],
]
) ?>
<?php
if (!$model->isNewRecord){
echo $model->author->name.' '.$model->author->secondname;
}else{
echo $form->field($model, 'author_id')
->widget(
Select2::classname(),
[
'data' => $data,
'pluginOptions' => [
'allowClear' => true,
],
]
);
}
?>
<?= $form->field($model, 'description')
->widget(
TinyMce::className(),
[
'options' => [ 'rows' => 30 ],
'language' => 'ru',
'clientOptions' => [
'file_browser_callback' => new JsExpression(
"function(field_name, url, type, win) {
window.open('" . Url::to(
[
'imagemanager/manager',
'view-mode' => 'iframe',
'select-type' => 'tinymce',
]
) . "&tag_name='+field_name,'','width=800,height=540 ,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no');
}"
),
'plugins' => [
"advlist autolink lists link charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste image",
],
'toolbar' => "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code",
'image_advtab' => true,
],
]
); ?>
<?= $form->field($model, 'preview')
->textarea(
[
'rows' => '10',
]
) ?>
<?= $form->field($model, 'status')->widget(
Select2::classname(),
[
'data' => $model->getStatuses(),
'pluginOptions' => [
'allowClear' => true,
],
]
);
?>
<?= $form->field($model, 'price')
->textInput() ?>
<?= $form->field($model, 'on_main')
->checkbox(
[
'class' => 'switchery',
]
) ?>
<div class="form-group">
<?= Html::submitButton(
$model->isNewRecord ? Yii::t('core', 'Create') : Yii::t('core', 'Update'),
[ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]
) ?>
</div>
<?php ActiveForm::end(); ?>
</div>