Test Setup Failed
Push — master ( e98e25...a896f1 )
by
unknown
03:45
created

shoppinglist-create-order-button-component.js ➔ define   B

Complexity

Conditions 1
Paths 3

Size

Total Lines 85

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 3
dl 0
loc 85
rs 8.6875
c 0
b 0
f 0
nop 1

5 Functions

Rating   Name   Duplication   Size   Complexity  
A shoppinglist-create-order-button-component.js ➔ ... ➔ ButtonComponent.extend._onClickButtonExecutor 0 4 1
A shoppinglist-create-order-button-component.js ➔ ... ➔ ButtonComponent.extend._onClickButtonRedirect 0 5 1
A shoppinglist-create-order-button-component.js ➔ ... ➔ ButtonComponent.extend._onLineItemsInit 0 5 1
A shoppinglist-create-order-button-component.js ➔ ... ➔ ButtonComponent.extend.initialize 0 4 1
A shoppinglist-create-order-button-component.js ➔ ... ➔ ButtonComponent.extend.showConfirmation 0 15 4

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 ButtonComponent = require('oroworkflow/js/app/components/button-component');
5
    var StandardConfirmation = require('oroui/js/standart-confirmation');
6
    var __ = require('orotranslation/js/translator');
7
    var ShoppingListCreateOrderButtonComponent;
8
9
    ShoppingListCreateOrderButtonComponent = ButtonComponent.extend({
10
        hasEmptyMatrix: null,
11
12
        shoppingListCollection: null,
13
14
        lineItemsCount: null,
15
16
        /**
17
         * @type {Object}
18
         */
19
        messages: {
20
            content: __('oro.shoppinglist.create_order_confirmation.message'),
21
            title: __('oro.shoppinglist.create_order_confirmation.title'),
22
            okText: __('oro.shoppinglist.create_order_confirmation.accept_button_title'),
23
            cancelText: __('oro.shoppinglist.create_order_confirmation.cancel_button_title')
24
        },
25
26
        listen: {
27
            'line-items-init mediator': '_onLineItemsInit'
28
        },
29
30
        /**
31
         * @inheritDoc
32
         */
33
        initialize: function(options) {
34
            this.hasEmptyMatrix = options.hasEmptyMatrix;
35
            return ShoppingListCreateOrderButtonComponent.__super__.initialize.apply(this, arguments);
36
        },
37
38
        /**
39
         * Listen line items init process
40
         *
41
         * @param {Array} lineItems
42
         * @private
43
         */
44
        _onLineItemsInit: function(lineItems) {
45
            this.lineItemsCount = lineItems.filter(function(lineItem) {
46
                return lineItem.$el.attr('class').indexOf('--configurable') === -1;
47
            }).length;
48
        },
49
50
        /**
51
         * @inheritDoc
52
         */
53
        _onClickButtonExecutor: function(clickedButton) {
0 ignored issues
show
Unused Code introduced by
The parameter clickedButton 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...
54
            this.showConfirmation(ShoppingListCreateOrderButtonComponent.__super__
55
                ._onClickButtonExecutor.bind(this, arguments));
56
        },
57
58
        /**
59
         * @inheritDoc
60
         */
61
        _onClickButtonRedirect: function(clickedButton) {
0 ignored issues
show
Unused Code introduced by
The parameter clickedButton 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...
62
            this.showConfirmation(ShoppingListCreateOrderButtonComponent.__super__
63
                ._onClickButtonRedirect
64
                .bind(this, arguments));
65
        },
66
67
        showConfirmation: function(callback) {
68
            if (
69
                (this.hasEmptyMatrix && this.lineItemsCount === 0) || // empty matrix only
70
                (!this.hasEmptyMatrix) // not empty matrix or it doesn't exist in SL
71
            ) {
72
                callback();
73
                return;
74
            }
75
76
            var confirmModal = new StandardConfirmation(this.messages);
77
            confirmModal
78
                .off('ok')
79
                .on('ok')
80
                .open(callback);
81
        }
82
    });
83
84
    return ShoppingListCreateOrderButtonComponent;
85
});
86