Test Setup Failed
Push — master ( cd1dab...2a689d )
by
unknown
03:51
created

base-product-variants-view.js ➔ define   B

Complexity

Conditions 1
Paths 2

Size

Total Lines 79

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 2
nop 1
dl 0
loc 79
rs 8.8701
c 0
b 0
f 0

7 Functions

Rating   Name   Duplication   Size   Complexity  
A base-product-variants-view.js ➔ ... ➔ _.extend.dispose 0 4 1
A base-product-variants-view.js ➔ ... ➔ _.extend.initModel 0 5 2
A base-product-variants-view.js ➔ ... ➔ _.extend.initialize 0 7 1
A base-product-variants-view.js ➔ ... ➔ _.extend.hideLoading 0 6 2
A base-product-variants-view.js ➔ ... ➔ BaseProductVariantsView 0 3 1
A base-product-variants-view.js ➔ ... ➔ _.extend.updateProductInfo 0 3 2
A base-product-variants-view.js ➔ ... ➔ _.extend.showLoading 0 13 3

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
define(function(require) {
2
    'use strict';
3
4
    var BaseProductVariantsView;
5
    var BaseView = require('oroui/js/app/views/base/view');
6
    var ElementsHelper = require('orofrontend/js/app/elements-helper');
7
    var LoadingMaskView = require('oroui/js/app/views/loading-mask-view');
8
    var $ = require('jquery');
9
    var _ = require('underscore');
10
11
    BaseProductVariantsView = BaseView.extend(_.extend({}, ElementsHelper, {
12
        options: {
13
            showLoading: true
14
        },
15
16
        elements: {
17
            variantForm: '[data-name="form__oro-product-product-variant-frontend-variant-field"]',
18
            variantFields: ['variantForm', ':input[data-name]']
19
        },
20
21
        elementsEvents: {},
22
23
        /**
24
         * @inheritDoc
25
         */
26
        constructor: function BaseProductVariantsView() {
27
            BaseProductVariantsView.__super__.constructor.apply(this, arguments);
28
        },
29
30
        /**
31
         * @inheritDoc
32
         */
33
        initialize: function(options) {
34
            this.options = $.extend(true, {}, this.options, _.pick(options, _.keys(this.options)));
35
            BaseProductVariantsView.__super__.initialize.apply(this, arguments);
36
37
            this.initModel(options);
38
            this.initializeElements(options);
39
        },
40
41
        initModel: function(options) {
42
            if (options.productModel) {
43
                this.model = options.productModel;
44
            }
45
        },
46
47
        updateProductInfo: function(id) {
48
            this.model.set('id', id ? parseInt(id, 10) : 0);
49
        },
50
51
        showLoading: function() {
52
            if (!this.options.showLoading) {
53
                return;
54
            }
55
            var $container = this.$el.closest('[data-role="layout-subtree-loading-container"]');
56
            if (!$container.length) {
57
                $container = this.$el;
58
            }
59
            this.subview('loadingMask', new LoadingMaskView({
60
                container: $container
61
            }));
62
            this.subview('loadingMask').show();
63
        },
64
65
        hideLoading: function() {
66
            if (!this.options.showLoading) {
67
                return;
68
            }
69
            this.removeSubview('loadingMask');
70
        },
71
72
        dispose: function() {
73
            this.disposeElements();
74
            BaseProductVariantsView.__super__.dispose.apply(this, arguments);
75
        }
76
    }));
77
78
    return BaseProductVariantsView;
79
});
80