Completed
Push — master ( 107529...d42328 )
by Dmitry
05:58
created

CreatePricesButton::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 0
cts 12
cp 0
rs 9.584
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace hipanel\modules\finance\widgets;
4
5
use hipanel\widgets\AjaxModal;
6
use Yii;
7
use yii\base\Widget;
8
use yii\bootstrap\Dropdown;
9
use yii\bootstrap\Html;
10
use yii\bootstrap\Modal;
11
use yii\web\View;
12
13
class CreatePricesButton extends Widget
14
{
15
    public $model;
16
17
    public function init()
18
    {
19
        $this->view->on(View::EVENT_END_BODY, function () {
20
            echo AjaxModal::widget([
21
                'id' => 'create-prices-modal',
22
                'header' => Html::tag('h4', Yii::t('hipanel.finance.price', 'Create prices'), ['class' => 'modal-title']),
23
                'scenario' => 'create-prices',
24
                'actionUrl' => ['@plan/suggest-prices-modal', 'id' => $this->model->id],
25
                'size' => Modal::SIZE_SMALL,
26
                'toggleButton' => false,
27
            ]);
28
            echo AjaxModal::widget([
29
                'id' => 'create-common-prices-modal',
30
                'header' => Html::tag('h4', Yii::t('hipanel.finance.price', 'Create common prices'), ['class' => 'modal-title']),
31
                'scenario' => 'create-prices',
32
                'actionUrl' => ['@plan/suggest-common-prices-modal', 'id' => $this->model->id],
33
                'size' => Modal::SIZE_SMALL,
34
                'toggleButton' => false,
35
            ]);
36
        });
37
    }
38
39
    public function run()
40
    {
41
        return Html::tag('div', Html::a(Yii::t('hipanel.finance.price', 'Create prices') .
42
                '&nbsp;&nbsp;' .
43
                Html::tag('span', null, ['class' => 'caret']), '#', [
44
                'data-toggle' => 'dropdown', 'class' => 'dropdown-toggle btn btn-success',
45
            ]) . Dropdown::widget([
46
                'options' => ['class' => 'pull-right'],
47
                'items' => [
48
                    [
49
                        'encode' => false,
50
                        'url' => '#',
51
                        'label' => Yii::t('hipanel.finance.price', 'Create prices'),
52
                        'linkOptions' => [
53
                            'data' => [
54
                                'toggle' => 'modal',
55
                                'target' => '#create-prices-modal',
56
                            ],
57
                        ],
58
                    ],
59
                    [
60
                        'encode' => false,
61
                        'url' => '#',
62
                        'label' => Yii::t('hipanel.finance.price', 'Create common prices'),
63
                        'linkOptions' => [
64
                            'data' => [
65
                                'toggle' => 'modal',
66
                                'target' => '#create-common-prices-modal',
67
                            ],
68
                        ],
69
                    ],
70
                ],
71
            ]), ['class' => 'dropdown']);
72
    }
73
}
74