DynamicFormWidget   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 146
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 2
dl 0
loc 146
ccs 0
cts 45
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B registerAssets() 0 140 1
1
<?php
2
/**
3
 * HiPanel core package
4
 *
5
 * @link      https://hipanel.com/
6
 * @package   hipanel-core
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\widgets;
12
13
use yii\web\View;
14
15
class DynamicFormWidget extends \wbraganca\dynamicform\DynamicFormWidget
16
{
17
    /**
18
     * @param View $view
19
     */
20
    public function registerAssets($view)
21
    {
22
        parent::registerAssets($view);
0 ignored issues
show
Documentation introduced by
$view is of type object<yii\web\View>, but the function expects a object<wbraganca\dynamicform\View>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
23
        // ObjectSelector fix, rebind events
24
        $view->registerJs(<<<JS
25
            $('.{$this->widgetContainer}').on('afterDelete', function(e) {
26
                var objectSelectorInputs = $(this).find('[data-object-selector-field]');
27
                objectSelectorInputs.each(function(i, elem) {
28
                    var elem = $(elem), changer = elem.prev('select');
29
                    var objectInputId = elem.attr('id');
30
                    var changerInputId = changer.attr('id');
31
                    changer.off();
32
                    initObjectSelectorChanger(changerInputId, objectInputId);
33
                });
34
            });
35
JS
36
        );
37
        // For init Destination Region Inputs
38
        $view->registerJs(<<<JS
39
            $('.{$this->widgetContainer}').on('afterInsert', function(e, item) {
40
                var destinationRegionInputs = $(item).find('[data-destination-field]');
41
                if (destinationRegionInputs.length) {
42
                    destinationRegionInputs.each(function() {
43
                        if (typeof tryToResolveDestinationRange === 'function') {
44
                            $(this).on('select2:selecting', tryToResolveDestinationRange);
45
                        }
46
                    });
47
                }
48
            });
49
JS
50
        );
51
        // For init select2
52
        $view->registerJs(<<<JS
53
            $('.{$this->widgetContainer}').on('afterInsert afterDelete', function(e, item) {
54
                var options = eval($(this).data('dynamicform'));
55
                var combos = item ? $(item).find('[data-combo-field]') : $(this).find('[data-combo-field]');
56
                if (combos.length > 0) {
57
                    combos.each(function() {
58
                        var comboItem = this;
59
                        if (e.type === 'afterDelete' && typeof $(comboItem).data('select2') === 'object') {
60
                            $(comboItem).select2('destroy');
61
                            comboItem.dataset.select2Id = this.getAttribute('id');
62
                        }
63
                        var template = $('.' + options.widgetContainer).find(options.widgetItem).first().find('[data-combo-field]').filter(function () {
64
                            return $(this).data('combo-field') == $(comboItem).data('combo-field');
65
                        });
66
67
                        if (template.length === 0) {
68
                            return true;
69
                        }
70
71
                        var tpl = $(template[0]);
72
                        if (tpl.data('field')) {
73
                            var config_id = tpl.data('field').id;
74
                            if (item) {
75
                                $(item).closest(options.widgetItem).combo().register($(this), config_id);
76
                            } else {
77
                                $(comboItem).closest('form').combo().register($(comboItem), config_id);
78
                            }
79
                        }
80
                    });
81
                }
82
            });
83
JS
84
        );
85
        // For init datetime picker
86
        $view->registerJs(<<<JS
87
            $('.{$this->widgetContainer}').on('afterInsert', function(e, item) {
88
                var options = eval($(this).data('dynamicform'));
89
                var pickers = $(item).find('[data-krajee-datetimepicker]');
90
                if (pickers.length > 0) {
91
                    pickers.each(function() {
92
                        var pickerItem = this;
93
                        var template = $('.' + options.widgetContainer).find(options.widgetItem).first().find('[data-krajee-datetimepicker]').filter(function () {
94
                            return $(this).data('krajee-datetimepicker') === $(pickerItem).data('krajee-datetimepicker');
95
                        });
96
97
                        if (template.length == 0) {
98
                            return true;
99
                        }
100
101
                        var config_id = $(template[0]).data('krajee-datetimepicker');
102
                        var configObj = window[config_id];
103
                        var elementId = $(pickerItem).attr('id');
104
                        if (configObj !== null && typeof configObj === 'object') {
105
                            $('#' + elementId + '-datetime').datetimepicker(configObj);
106
                        } else {
107
                            console.error('config_id ' + config_id + ' not found');
108
                        }
109
                    });
110
                }
111
            });
112
JS
113
        );
114
        // For init datetime picker
115
        $view->registerJs(<<<JS
116
            $('.{$this->widgetContainer}').on('afterInsert', function(e, item) {
117
                var options = eval($(this).data('dynamicform'));
118
                var pickers = $(item).find('[data-hiqdev-datetimepicker]');
119
                if (pickers.length > 0) {
120
                    pickers.each(function() {
121
                        var pickerItem = this;
122
                        var template = $('.' + options.widgetContainer).find(options.widgetItem).first().find('[data-hiqdev-datetimepicker]').filter(function () {
123
                            return $(this).data('hiqdev-datetimepicker') === $(pickerItem).data('hiqdev-datetimepicker');
124
                        });
125
126
                        if (template.length == 0) {
127
                            return true;
128
                        }
129
130
                        var config_id = $(template[0]).data('hiqdev-datetimepicker');
131
                        var configObj = window.hiqdev_datetimepicker_options[config_id];
132
                        var elementId = $(pickerItem).attr('id');
133
                        if (configObj !== null && typeof configObj === 'object') {
134
                            $('#' + elementId).parent().datetimepicker(configObj);
135
                        } else {
136
                            console.error('config_id ' + config_id + ' not found');
137
                        }
138
                    });
139
                }
140
            });
141
JS
142
        );
143
        // For PasswordInput
144
        $view->registerJs(<<<JS
145
            $('.{$this->widgetContainer}').on('afterInsert', function(e, item) {
146
                var passwordInputs = $(item).find('input[type=password]').closest('div.input-group');
147
                if (passwordInputs.length > 0) {
148
                    passwordInputs.filter(function () {
149
                        return $(this).find('.show-password').length > 0;
150
                    }).each(function() {
151
                        if ($.isFunction($.fn.passwordInput)) {
152
                            $(this).passwordInput(); 
153
                        }
154
                    });
155
                }
156
            });
157
JS
158
        );
159
    }
160
}
161