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

OpportunityStatusSelectView   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 3
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 3
loc 3
rs 10
c 0
b 0
f 0
1 View Code Duplication
define(function(require) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
    'use strict';
3
4
    var OpportunityStatusSelectView;
5
    var _ = require('underscore');
6
    var BaseView = require('oroui/js/app/views/base/view');
7
8
    OpportunityStatusSelectView = BaseView.extend({
9
        /**
10
         * @inheritDoc
11
         */
12
        constructor: function OpportunityStatusSelectView() {
13
            OpportunityStatusSelectView.__super__.constructor.apply(this, arguments);
14
        },
15
16
        /**
17
         * @inheritDoc
18
         */
19
        initialize: function(options) {
20
            OpportunityStatusSelectView.__super__.initialize.apply(this, arguments);
21
22
            this.options = _.defaults(options || {}, this.options);
23
24
            this.render();
25
        },
26
27
        render: function() {
28
            this.initLayout().then(_.bind(this.afterLayoutInit, this));
29
        },
30
31
        afterLayoutInit: function() {
32
            var status = this.$('select[data-name="field__status"]');
33
            var probability = this.$('input[data-name="field__probability"]');
34
            var defaultProbabilities = status.data('probabilities');
35
            var shouldChangeProbability = false;
36
37
            if (defaultProbabilities.hasOwnProperty(status.val())) {
38
                if (parseFloat(defaultProbabilities[status.val()]) === parseFloat(probability.val())) {
39
                    shouldChangeProbability = true;
40
                }
41
            }
42
43
            probability.on('change', function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e 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...
44
                shouldChangeProbability = false;
45
            });
46
47
            status.on('change', function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e 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...
48
                var val = status.val();
49
50
                if (!shouldChangeProbability) {
51
                    return;
52
                }
53
54
                if (defaultProbabilities.hasOwnProperty(val)) {
55
                    probability.val(defaultProbabilities[val]);
56
                }
57
            });
58
        }
59
    });
60
61
    return OpportunityStatusSelectView;
62
});
63