Test Setup Failed
Push — master ( 982d9a...a2862f )
by
unknown
03:40
created

configure-integration-view.js ➔ define   A

Complexity

Conditions 1
Paths 2

Size

Total Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 2
nop 1
dl 0
loc 51
rs 9.4109
c 1
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A configure-integration-view.js ➔ ... ➔ ConfigureIntegrationView 0 3 1
A configure-integration-view.js ➔ ... ➔ BaseView.extend.onWidgetLoad 0 19 1
A configure-integration-view.js ➔ ... ➔ BaseView.extend.initialize 0 5 1

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 ConfigureIntegrationView;
5
    var BaseView = require('oroui/js/app/views/base/view');
6
    var $ = require('jquery');
7
    var mediator = require('oroui/js/mediator');
8
    var widgetManager = require('oroui/js/widget-manager');
9
10
    ConfigureIntegrationView = BaseView.extend({
11
        optionNames: BaseView.prototype.optionNames.concat(['wid', 'dataFieldSelector', 'apiKeyFieldSelector']),
12
13
        /**
14
         * @inheritDoc
15
         */
16
        constructor: function ConfigureIntegrationView() {
17
            ConfigureIntegrationView.__super__.constructor.apply(this, arguments);
18
        },
19
20
        /**
21
         * @inheritDoc
22
         */
23
        initialize: function(options) {
24
            ConfigureIntegrationView.__super__.initialize.call(this, options);
25
26
            widgetManager.getWidgetInstance(this.wid, this.onWidgetLoad.bind(this));
27
        },
28
29
        onWidgetLoad: function(widget) {
30
            mediator.on('integrationFormReload:before', function(event) {
31
                event.reloadManually = false;
32
                widget.loadContent($.param(event.data), event.formEl.attr('method'));
33
            });
34
35
            widget.on('contentLoad', function() {
36
                var $dataField = this.$(this.dataFieldSelector);
37
                var $apiKeyField = this.$(this.apiKeyFieldSelector);
38
39
                if ($dataField.val() && !$apiKeyField.val()) {
40
                    var data = JSON.parse($dataField.val());
41
42
                    if (data.transport.apiKey) {
43
                        $apiKeyField.val(data.transport.apiKey);
44
                    }
45
                }
46
            }.bind(this));
47
        }
48
    });
49
50
    return ConfigureIntegrationView;
51
});
52
53