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

shoppinglist-title-inline-editable-view-component.js ➔ define   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 77

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 77
rs 8.9342
c 0
b 0
f 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A shoppinglist-title-inline-editable-view-component.js ➔ ... ➔ InlineEditableViewComponent.extend.dispose 0 11 2
A shoppinglist-title-inline-editable-view-component.js ➔ ... ➔ InlineEditableViewComponent.extend.initialize 0 14 1
A shoppinglist-title-inline-editable-view-component.js ➔ ... ➔ InlineEditableViewComponent.extend.getViewOptions 0 9 2
A shoppinglist-title-inline-editable-view-component.js ➔ ... ➔ ShoppingListTitleInlineEditableViewComponent 0 3 1
A shoppinglist-title-inline-editable-view-component.js ➔ ... ➔ InlineEditableViewComponent.extend.repackageEvent 0 8 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 InlineEditableViewComponent = require('oroform/js/app/components/inline-editable-view-component');
5
    var ShoppingListCollectionService = require('oroshoppinglist/js/shoppinglist-collection-service');
6
    var mediator = require('oroui/js/mediator');
7
    var ShoppingListTitleInlineEditableViewComponent;
8
9
    ShoppingListTitleInlineEditableViewComponent = InlineEditableViewComponent.extend({
10
11
        eventChannelId: null,
12
13
        shoppingListCollection: null,
14
15
        /**
16
         * @inheritDoc
17
         */
18
        constructor: function ShoppingListTitleInlineEditableViewComponent() {
19
            ShoppingListTitleInlineEditableViewComponent.__super__.constructor.apply(this, arguments);
20
        },
21
22
        /**
23
         * @param {Object} options
24
         */
25
        initialize: function(options) {
26
            this.$el = options._sourceElement;
27
            this.shoppingListId = options.metadata.broadcast_parameters.id;
28
            this.eventChannelId = options.eventChannelId;
29
            ShoppingListTitleInlineEditableViewComponent.__super__.initialize.apply(this, arguments);
30
31
            // listening to generic inline editor's events and repackaging them
32
            // into specific shopping list events
33
            mediator.on('inlineEditor:' + this.eventChannelId + ':update', this.repackageEvent, this);
34
35
            ShoppingListCollectionService.shoppingListCollection.done((function(collection) {
36
                this.shoppingListCollection = collection;
37
            }).bind(this));
38
        },
39
40
        getViewOptions: function() {
41
            var options = ShoppingListTitleInlineEditableViewComponent.__super__.getViewOptions.apply(this);
42
43
            if (!this.inlineEditingOptions.enable) {
44
                options.autoRender = false;
45
            }
46
47
            return options;
48
        },
49
50
        /**
51
         *
52
         * @param data
53
         */
54
        repackageEvent: function(data) {
55
            var shoppingListId = this.shoppingListId;
56
            this.shoppingListCollection.each(function(model) {
57
                if (model.get('id') === shoppingListId) {
58
                    model.set('label', data.label);
59
                }
60
            });
61
        },
62
63
        dispose: function() {
64
            if (this.disposed) {
65
                return;
66
            }
67
68
            delete this.shoppingListCollection;
69
            this.$el.off();
70
            mediator.off('inlineEditor:' + this.eventChannelId + ':update', this.repackageEvent, this);
71
72
            ShoppingListTitleInlineEditableViewComponent.__super__.dispose.call(this);
73
        }
74
    });
75
76
    return ShoppingListTitleInlineEditableViewComponent;
77
});
78