Blame view

backend/views/banner/_form.php 2.77 KB
8774e5a3   Administrator   31.03.16 finish 1
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
  <?php
  
  use common\modules\file\widgets\ImageUploader;
  use kartik\select2\Select2;
  use yii\helpers\Html;
  use yii\widgets\ActiveForm;
  
  /* @var $this yii\web\View */
  /* @var $model common\models\Banner */
  /* @var $form yii\widgets\ActiveForm */
  ?>
  
  <div class="banner-form">
  
      <?php $form = ActiveForm::begin(); ?>
  
  
      <?= $form->field($model, 'alt')->textInput(['maxlength' => true]) ?>
  
      <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
  
      <?= $form->field($model, 'url')->textInput(['maxlength' => true]) ?>
  
      <?= $form->field($model, 'status')->widget(Select2::className(),([
          'name' => 'status',
          'hideSearch' => true,
          'data' => [1 => 'Active', 2 => 'Inactive'],
          'options' => ['placeholder' => 'Select status...'],
          'pluginOptions' => [
              'allowClear' => true
          ]
      ])) ?>
  
      <?= $form->field($model, 'width')->textInput(['maxlength' => true]) ?>
  
      <?= $form->field($model, 'height')->textInput(['maxlength' => true]) ?>
  
      <p id="save_image_widget_settings" class = "btn btn-primary" >Применить настройки</p>
  
      <div id="image_widget_block">
          <?php if(!empty($model->image)){
              echo ImageUploader::widget([
                  'model'=> $model,
                  'field'=>'image',
                  'size' => [
                      [
                          'width'=>$model->width,
                          'height'=>$model->height,
                      ],
                  ],
                  'gallery' =>$model->image,
                  'name' => "Загрузить баннер"
              ]);
          }?>
      </div>
  
      <div class="form-group">
          <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
      </div>
  
      <?php ActiveForm::end(); ?>
  
  </div>
  <script>
      $('#save_image_widget_settings').click(function(){
          var width = $('#banner-width').val();
          var height = $('#banner-height').val();
          save_image_widget_settings( width, height, function(data){
              $('#image_widget_block').html = '';
              $('#image_widget_block').html(data.html);
          });
      });
      function save_image_widget_settings( width, height, callback )
      {
          $.ajax({
              url: '/admin/banner/save-image-settings',
              data        :
              {
                  'width'       : width,
                  'height'   : height
              },
              type : 'POST',
              dataType: 'json',
              success: function (data)
              {
                  if(callback)
                      callback(data);
              },
              error: function()
              {
                  console.info('error');
              }
          });
      }
  </script>