src/widgets/formInputs/componentSettings/assets/component-settings.js   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 87

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 87
rs 8.6296
c 0
b 0
f 0

8 Functions

Rating   Name   Duplication   Size   Complexity  
A sx.classes.Component.extend.goEdit 0 11 1
A sx.classes.Component.extend.getjComponentSelect 0 4 1
A sx.classes.Component.extend.getjWrapper 0 4 1
A sx.classes.Component.extend._onDomReady 0 19 1
A sx.classes.Component.extend.save 0 12 2
A sx.classes.Component.extend.getjBtnEdit 0 4 1
A sx.classes.Component.extend.update 0 13 2
A sx.classes.Component.extend.getjComponentSettings 0 4 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
/*!
2
 * @author Semenov Alexander <[email protected]>
3
 * @link http://skeeks.com/
4
 * @copyright 2010 SkeekS (СкикС)
5
 * @date 09.06.2015
6
 */
7
(function(sx, $, _)
0 ignored issues
show
Unused Code introduced by
The parameter _ is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
8
{
9
    sx.classes.ComponentSettingsWidget = sx.classes.Component.extend({
10
11
        getjWrapper: function()
12
        {
13
            return $("#" + this.get('id'));
14
        },
15
16
        getjBtnEdit: function()
17
        {
18
            return $(".sx-btn-edit", this.getjWrapper());
19
        },
20
21
        getjComponentSelect: function()
22
        {
23
            return $("#" + this.get('componentSelectId'));
24
        },
25
        getjComponentSettings: function()
26
        {
27
            return $("#" + this.get('componentSettingsId'));
28
        },
29
30
        _onDomReady: function()
31
        {
32
            var self = this;
33
34
            this.getjComponentSelect().on("change", function()
35
            {
36
                self.currentComponent = $(this).val();
37
                self.update();
38
            });
39
40
            this.getjBtnEdit().on('click', function()
41
            {
42
                self.goEdit();
43
                return false;
44
            });
45
46
            this.currentComponent = this.getjComponentSelect().val();
47
            self.update();
48
        },
49
50
        /**
51
         * Обновление текущего состояния
52
         * @returns {sx.classes.ComponentSettingsWidget}
53
         */
54
        update: function()
55
        {
56
            var self = this;
57
58
            if (!self.currentComponent)
59
            {
60
                this.getjBtnEdit().hide();
61
            } else
62
            {
63
                this.getjBtnEdit().show();
64
            }
65
            return this;
66
        },
67
68
        save: function(dataStringB64)
69
        {
70
            var old = this.getjComponentSettings().val();
71
            this.getjComponentSettings().val(dataStringB64);
72
            var newVal = this.getjComponentSettings().val();
73
74
            if (newVal != old)
75
            {
76
                console.log('changed');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
77
            }
78
            this.windowObject.close();
79
        },
80
81
        goEdit: function()
82
        {
83
            var url = this.get('backend');
84
                url = url + '?';
85
                url = url + "&component=" + this.currentComponent;
86
                url = url + "&settings="  + this.getjComponentSettings().val();
87
                url = url + "&callbackComonentId="  + this.get('id');
88
89
            this.windowObject = new sx.classes.Window(url);
90
            this.windowObject.open();
91
        },
92
    });
93
})(sx, sx.$, sx._);
0 ignored issues
show
Bug introduced by
The variable sx seems to be never declared. If this is a global, consider adding a /** global: sx */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...