Completed
Push — master ( ca8e7b...a410c5 )
by Klochok
04:26
created

AmountWithCurrency::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 6
ccs 0
cts 6
cp 0
crap 6
rs 9.4285
1
<?php
2
3
/*
4
 * HiPanel core package
5
 *
6
 * @link      https://hipanel.com/
7
 * @package   hipanel-core
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\widgets;
13
14
class AmountWithCurrency extends \yii\base\Widget
15
{
16
    static public $widgetClass = 'amount-with-currency-widget';
17
18
    public $currencyAttributeName;
19
    public $currencyAttributeOptions;
20
    public $model;
21
    public $form;
22
    public $attribute;
23
24
    public function run()
25
    {
26
        $this->initClientScript();
27
28
        return $this->render((new \ReflectionClass($this))->getShortName(), [
29
            'form' => $this->form,
30
            'model' => $this->model,
31
            'currencyAttributeName' => $this->currencyAttributeName,
32
            'currencyAttributeOptions' => $this->currencyAttributeOptions,
33
            'attribute' => $this->attribute,
34
            'containerClass' => self::$widgetClass,
35
        ]);
36
    }
37
38
    public function initClientScript()
39
    {
40
        $widgetClass = self::$widgetClass;
41
        $this->getView()->registerJs(<<<"JS"
42
        $(document).on('click', '.{$widgetClass} a', function(e) {
43
            var item = $(this);
44
            item.parents('.amount-with-currency-widget').find('.iwd-label').text(item.data('label'));
45
            item.parents('.amount-with-currency-widget').find(':hidden').val(item.data('value')).trigger('change');
46
        });
47
JS
48
        );
49
    }
50
}
51