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

src/Oro/Bundle/ShoppingListBundle/Resources/public/js/shoppinglist-request-quote-confirmation.js   A

Complexity

Total Complexity 10
Complexity/F 2.5

Size

Lines of Code 37
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
wmc 10
nc 10
mnd 2
bc 7
fnc 4
dl 0
loc 37
rs 10
bpm 1.75
cpm 2.5
noi 0
c 0
b 0
f 0
1
define(function(require) {
2
    'use strict';
3
4
    var _ = require('underscore');
5
    var StandartConfirmation = require('oroui/js/standart-confirmation');
6
    var mediator = require('oroui/js/mediator');
7
8
    var ShoppingListRequestQuoteConfirmation;
9
10
    ShoppingListRequestQuoteConfirmation = StandartConfirmation.extend({
11
        open: function() {
12
            var lineItems = mediator.execute('get-line-items');
13
            var lineItemsCount = lineItems.filter(function(lineItem) {
14
                if (lineItem.$el.attr('class').indexOf('--configurable') !== -1) {
15
                    var quantities = 0;
16
                    _.each(lineItem.$elements.quantity, function(quantity) {
17
                        quantities += quantity.value ? parseInt(quantity.value) : 0;
18
                    });
19
                    return quantities !== 0;
20
                } else {
21
                    return true;
22
                }
23
            }).length;
24
25
            if (
26
                (this.options.hasEmptyMatrix && lineItemsCount === 0) ||
27
                (!this.options.hasEmptyMatrix && lineItemsCount > 0)
28
            ) {
29
                this.trigger('ok');
30
                return;
31
            }
32
            ShoppingListRequestQuoteConfirmation.__super__.open.call(this);
33
        }
34
    });
35
36
    return ShoppingListRequestQuoteConfirmation;
37
});
38