Blame view

views/odoo/orders.php 5.62 KB
714f42c5   Yarik   Odoo completed
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
150
151
152
153
154
155
  <?php
      /**
       * @var \yii\data\ActiveDataProvider $dataProvider
       * @var \yii\web\View                $this
       */
      
      use yii\grid\ActionColumn;
      use yii\grid\CheckboxColumn;
      use yii\grid\Column;
      use yii\grid\GridView;
      use yii\helpers\Html;
      use yii\helpers\Json;
      use yii\helpers\Url;
      use yiister\gentelella\widgets\Panel;
      
      $this->title = \Yii::t('odoo', 'Orders');
      $this->params[ 'breadcrumbs' ][] = [
          'label' => \Yii::t('odoo', 'Odoo'),
          'url'   => [ 'index' ],
      ];
      $this->params[ 'breadcrumbs' ][] = $this->title;
  ?>
  <div class="odoo-index">
      <?php
          $xPanel = Panel::begin(
              [
                  'header' => $this->title,
              ]
          );
          echo Html::button(
              \Yii::t('odoo', 'Send'),
              [
                  'class' => 'btn btn-primary pull-right odoo-order-send',
                  'data'  => [
                      'conf' => \Yii::t('odoo', 'Are you sure to send checked orders to Odoo?'),
                      'url'  => Url::to([ 'send-orders' ]),
                  ],
              ]
          );
          echo GridView::widget(
              [
                  'id'           => 'odoo-order-grid',
                  'dataProvider' => $dataProvider,
                  'columns'      => [
                      [
                          'class' => CheckboxColumn::className(),
                      ],
                      [
                          'attribute' => 'id',
                          'value'     => function ($model) {
                              /**
                               * @var \artbox\odoo\models\Order $model
                               */
                              return Html::a(
                                  $model->id,
                                  [
                                      '/order/view',
                                      'id' => $model->id,
                                  ]
                              );
                          },
                          'format'    => 'html',
                      ],
                      [
                          'class'   => Column::className(),
                          'content' => function ($model) {
                              /**
                               * @var \artbox\odoo\models\Order $model
                               */
                              return Html::tag(
                                  'i',
                                  '',
                                  [
                                      'class' => $model->odooToOrder ? 'glyphicon glyphicon-ok' : 'glyphicon glyphicon-remove',
                                  ]
                              );
                          },
                          'header'  => \Yii::t('odoo', 'Status'),
                      ],
                      [
                          'class'    => ActionColumn::className(),
                          'template' => '{send-order}',
                          'buttons'  => [
                              'send-order' => function ($url, $model) {
                                  /**
                                   * @var \artbox\odoo\models\Order $model
                                   */
                                  return Html::a(
                                      Html::tag(
                                          'i',
                                          '',
                                          [
                                              'class' => 'glyphicon glyphicon-upload',
                                          ]
                                      ),
                                      [
                                          'send-orders',
                                          'ids' => Json::encode([ $model->id ]),
                                      ],
                                      [
                                          'class' => 'odoo-order-send-one',
                                          'data'  => [
                                              'conf' => \Yii::t('odoo', 'Are you sure to send order to Odoo?'),
                                          ],
                                      ]
                                  );
                              },
                          ],
                      ],
                  ],
              ]
          );
          $xPanel::end();
      ?>
  </div>
  <?php
      $js = <<<JS
      $('.odoo-order-send')
          .on('click', function() {
              if (confirm($(this)
                      .data('conf'))) {
                  var selector = '#odoo-order-grid';
                  var selected = $(selector)
                      .yiiGridView('getSelectedRows');
                  $(selector)
                      .prepend('<div class="loader-wrapper"></div>');
                  if(selected.length) {
                      $.post($(this).data('url') + '?ids=' + JSON.stringify(selected), function(data) {
                          console.log(data);
                          $.pjax.reload(selector, {
                            timeout: 5000,
                            fragment: selector
                        });
                      });
                  }
              }
          });
      $('.odoo-order-send-one').on('click', function(e) {
          e.preventDefault();
          if(confirm($(this).data('conf'))) {
              var selector = '#odoo-order-grid';
              $(selector)
                      .prepend('<div class="loader-wrapper"></div>');
              $.post($(this).attr('href'), function(data) {
                          console.log(data);
                          $.pjax.reload(selector, {
                            timeout: 5000,
                            fragment: selector
                        });
                      });
          }
      });
  JS;
      $this->registerJs($js);
  ?>