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

line-item-view.js ➔ define   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 55
rs 9.7692
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A line-item-view.js ➔ ... ➔ BaseProductView.extend.onQuantityUnitChange 0 9 1
A line-item-view.js ➔ ... ➔ LineItemView 0 3 1
A line-item-view.js ➔ ... ➔ BaseProductView.extend.initialize 0 14 2

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 LineItemView;
5
    var BaseProductView = require('oroproduct/js/app/views/base-product-view');
6
    var ProductQuantityView = require('oroproduct/js/app/views/product-quantity-editable-view');
7
    var mediator = require('oroui/js/mediator');
8
    var _ = require('underscore');
9
10
    LineItemView = BaseProductView.extend({
11
        elements: _.extend({}, BaseProductView.prototype.elements, {
12
            quantity: '[data-name="field__quantity"]',
13
            unit: '[data-name="field__unit"]'
14
        }),
15
16
        lineItemId: null,
17
18
        /**
19
         * @inheritDoc
20
         */
21
        constructor: function LineItemView() {
22
            LineItemView.__super__.constructor.apply(this, arguments);
23
        },
24
25
        /**
26
         * @inheritDoc
27
         */
28
        initialize: function(options) {
29
            LineItemView.__super__.initialize.apply(this, arguments);
30
            this.lineItemId = options.lineItemId;
31
32
            if (this.getElement('quantity').length) {
33
                var productQuantityView = new ProductQuantityView(_.extend({
34
                    el: this.$el.get(0),
35
                    model: this.model
36
                }, options.quantityComponentOptions));
37
38
                this.subview('productQuantityView', productQuantityView);
39
                this.listenTo(productQuantityView, 'product:quantity-unit:update', this.onQuantityUnitChange);
40
            }
41
        },
42
43
        onQuantityUnitChange: function(data) {
44
            mediator.trigger('frontend:shopping-list-item-quantity:update', data);
45
46
            this.trigger('unit-changed', {
47
                lineItemId: this.lineItemId,
48
                product: this.model.get('id'),
49
                unit: data.value.unit
50
            });
51
        }
52
    });
53
54
    return LineItemView;
55
});
56