| @@ 1-67 (lines=67) @@ | ||
| 1 | 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 | ||
| @@ 1-62 (lines=62) @@ | ||
| 1 | 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 | ||