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

  A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
nop 1
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