Blame view

backend/widgets/Gallery/views/GalleryWidgetView.php 3.38 KB
d1f8bd40   Alexey Boroda   first commit
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
  <?php
  use yii\helpers\Url;
  use common\components\GalleryManager;
  
  if (method_exists($model, 'getGalleryLink') && $model->getGalleryLink()) : ?>
      <div class="table-responsive">
          <table class="table table-bordered table-stripped" id="galleryTable">
              <thead>
              <tr>
                  <th>
                      <?= Yii::t('app', 'Image') ?>
                  </th>
                  <th>
                      <?= Yii::t('app', 'Image title') ?>
                  </th>
                  <th>
                      <?= Yii::t('app', 'Position') ?>
                  </th>
                  <th>
                      <?= Yii::t('app', 'Actions') ?>
                  </th>
              </tr>
              </thead>
              <tbody>
              <?php foreach ($model->getGalleryItems() as $imageParam) : ?>
                  <tr>
                      <td>
                          <img src="<?= $imageParam[GalleryManager::NAME_IMAGE_PATH] ?>" width="250">
                          <input type="hidden" name="GalleryManager[<?= GalleryManager::NAME_IMAGE ?>][]"
                                 class="form-control" value="<?= $imageParam[GalleryManager::NAME_IMAGE] ?>">
                      </td>
                      <td>
                          <input type="text" name="GalleryManager[<?= GalleryManager::NAME_IMAGE_TITLE ?>][]"
                                 class="form-control" value="<?= $imageParam[GalleryManager::NAME_IMAGE_TITLE] ?>">
                      </td>
                      <td>
                          <input type="text" name="GalleryManager[<?= GalleryManager::NAME_SORT ?>][]"
                                 class="form-control" value="<?= $imageParam[GalleryManager::NAME_SORT] ?>">
                      </td>
                      <td>
                          <button type="button"
                                  class="gallery-file-remove btn btn-xs btn-default"
                                  title="Удалить файл"
                                  data-url="<?= Url::to(['filedelete', 'id' => Yii::$app->getRequest()->get('id', null)]) ?>"
                                  data-key="<?= $imageParam[GalleryManager::NAME_IMAGE] ?>">
                              <i class="glyphicon glyphicon-trash text-danger"></i></button>
                          <!--                    <button class="btn btn-white"><i class="fa fa-trash"></i> </button>-->
                      </td>
                  </tr>
              <?php endforeach; ?>
              </tbody>
          </table>
      </div>
  
  <?php endif; ?>
  
  <?php
  $this->registerJs('
  
     $(function() {
         
         $(document).on(\'click\', \'.gallery-file-remove\', function() {
             var th = $(this);
             console.log(th);
             
             $.ajax({
                 method: \'post\',
                 url: th.data(\'url\'),
                 data : {
                      key: th.data(\'key\'),
                      ' . Yii::$app->getRequest()->csrfParam . ': \'' . Yii::$app->getRequest()->getCsrfToken() . '\',
                 },
                 success: function(data) {
                      if (data.error == \'file deleted\') {
                        removeRow(th.closest(\'tr\'));  
                      }
                  
                 }
         });
         
         
         function removeRow(tr)
         {
              tr.remove();
              if ($(\'#galleryTable tr\').length === 0) {
                  $(\'#galleryTable\').remove();
              }
         }
         
      })
     })
  
  ');