Blame view

backend/views/book/_form.php 4.9 KB
8f340aa7   Anastasia   - main page
1
2
3
  <?php
      
      use artbox\core\admin\assets\Switchery;
8f340aa7   Anastasia   - main page
4
      use dosamigos\tinymce\TinyMce;
d7245f5e   Anastasia   - create book
5
      use kartik\file\FileInput;
8f340aa7   Anastasia   - main page
6
7
8
9
10
11
12
13
14
15
      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 */
d7245f5e   Anastasia   - create book
16
      /* @var array $data*/
8f340aa7   Anastasia   - main page
17
18
19
20
21
22
23
24
25
26
27
28
29
30
      
      Switchery::register($this);
      $js = <<< JS
  $('.switchery').each(function(idx, elem) {
    new Switchery(elem, {
      color:'#46b749',
      secondaryColor:'#e2e2e2'
    });
  });
  
  JS;
      
      
      $this->registerJs($js, View::POS_READY);
d7245f5e   Anastasia   - create book
31
32
33
34
35
36
37
38
      
      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 = [];
      }
8f340aa7   Anastasia   - main page
39
40
41
42
  ?>
  
  <div class="feedback-form">
      
d7245f5e   Anastasia   - create book
43
      <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
8f340aa7   Anastasia   - main page
44
45
46
      
      <?= $form->field($model, 'title')
               ->textInput([ 'maxlength' => true ]) ?>
d7245f5e   Anastasia   - create book
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
      <?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,
                              ],
                          ]
                      );
        }
        ?>
8f340aa7   Anastasia   - main page
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
      
      <?= $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,
              ],
          ]
      );
              ?>
ad2187ad   Anastasia   - book, author in...
131
132
      <?= $form->field($model, 'price')
               ->textInput() ?>
8f340aa7   Anastasia   - main page
133
134
135
136
137
138
      <?= $form->field($model, 'on_main')
               ->checkbox(
                   [
                       'class' => 'switchery',
                   ]
               ) ?>
ad2187ad   Anastasia   - book, author in...
139
      
8f340aa7   Anastasia   - main page
140
141
142
143
144
145
146
147
148
149
      <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>