1
|
|
View Code Duplication |
define(function(require) { |
|
|
|
|
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) { |
|
|
|
|
49
|
|
|
shouldChangeProbability = false; |
50
|
|
|
}); |
51
|
|
|
|
52
|
|
|
status.on('change', function(e) { |
|
|
|
|
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
|
|
|
|