1
|
|
View Code Duplication |
define(function(require) { |
|
|
|
|
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) { |
|
|
|
|
44
|
|
|
shouldChangeProbability = false; |
45
|
|
|
}); |
46
|
|
|
|
47
|
|
|
status.on('change', function(e) { |
|
|
|
|
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
|
|
|
|