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

update-page-view.js ➔ ... ➔ UpdatePageView   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 3
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 1
nop 0
dl 3
loc 3
rs 10
c 1
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 UpdatePageView;
5
    var _ = require('underscore');
6
    var BaseView = require('oroui/js/app/views/base/view');
7
8
    UpdatePageView = BaseView.extend({
9
        /**
10
         * @inheritDoc
11
         */
12
        constructor: function UpdatePageView() {
13
            UpdatePageView.__super__.constructor.apply(this, arguments);
14
        },
15
16
        /**
17
         * @inheritDoc
18
         */
19
        initialize: function(options) {
20
            UpdatePageView.__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.pageComponent('oro_sales_opportunity_form_status').view.$el;
33
            var probability = this.$('input[data-name="field__probability"]:enabled');
34
            var probabilities = status.data('probabilities');
35
            var shouldChangeProbability = false;
36
37
            // probability field might be missing or disabled
38
            if (0 === probability.length) {
39
                return;
40
            }
41
42
            if (probabilities.hasOwnProperty(status.val())) {
43
                if (parseFloat(probabilities[status.val()]) === parseFloat(probability.val())) {
44
                    shouldChangeProbability = true;
45
                }
46
            }
47
48
            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...
49
                shouldChangeProbability = false;
50
            });
51
52
            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...
53
                var val = status.val();
54
55
                if (!shouldChangeProbability) {
56
                    return;
57
                }
58
59
                if (probabilities.hasOwnProperty(val)) {
60
                    probability.val(probabilities[val]);
61
                }
62
            });
63
        }
64
    });
65
66
    return UpdatePageView;
67
});
68