| @@ 1-83 (lines=83) @@ | ||
| 1 | define(function(require) { |
|
| 2 | 'use strict'; |
|
| 3 | ||
| 4 | var ConfigHideFieldsComponent; |
|
| 5 | var _ = require('underscore'); |
|
| 6 | var $ = require('jquery'); |
|
| 7 | var BaseComponent = require('oroui/js/app/components/base/component'); |
|
| 8 | ||
| 9 | ConfigHideFieldsComponent = BaseComponent.extend({ |
|
| 10 | /** |
|
| 11 | * @property {Object} |
|
| 12 | */ |
|
| 13 | options: { |
|
| 14 | selectors: { |
|
| 15 | row_container: '.control-group', |
|
| 16 | dependend_checkbox: '[data-depends-on-field="single_unit_mode"]' |
|
| 17 | } |
|
| 18 | }, |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @property {jQuery} |
|
| 22 | */ |
|
| 23 | $form: null, |
|
| 24 | ||
| 25 | /** |
|
| 26 | * @property {jQuery} |
|
| 27 | */ |
|
| 28 | $el: null, |
|
| 29 | ||
| 30 | /** |
|
| 31 | * @property {jQuery} |
|
| 32 | */ |
|
| 33 | $dependedEl: null, |
|
| 34 | ||
| 35 | /** |
|
| 36 | * @inheritDoc |
|
| 37 | */ |
|
| 38 | constructor: function ConfigHideFieldsComponent() { |
|
| 39 | ConfigHideFieldsComponent.__super__.constructor.apply(this, arguments); |
|
| 40 | }, |
|
| 41 | ||
| 42 | /** |
|
| 43 | * @inheritDoc |
|
| 44 | */ |
|
| 45 | initialize: function(options) { |
|
| 46 | this.options = _.defaults(options || {}, this.options); |
|
| 47 | ||
| 48 | this.$el = this.options._sourceElement; |
|
| 49 | this.$form = this.$el.closest('form'); |
|
| 50 | var id = this.$el.data('dependency-id'); |
|
| 51 | ||
| 52 | this.$dependedEl = this.$form.find('[data-depends-on-field="' + id + '"]'); |
|
| 53 | ||
| 54 | this.updateDependentFields(); |
|
| 55 | this.$el.on('change', $.proxy(this.updateDependentFields, this)); |
|
| 56 | }, |
|
| 57 | ||
| 58 | /** |
|
| 59 | * @inheritDoc |
|
| 60 | */ |
|
| 61 | dispose: function() { |
|
| 62 | if (this.disposed) { |
|
| 63 | return; |
|
| 64 | } |
|
| 65 | ||
| 66 | this.$el.off('change', $.proxy(this.updateDependentFields, this)); |
|
| 67 | ||
| 68 | ConfigHideFieldsComponent.__super__.dispose.call(this); |
|
| 69 | }, |
|
| 70 | ||
| 71 | updateDependentFields: function() { |
|
| 72 | var isChecked = this.$el.prop('checked'); |
|
| 73 | ||
| 74 | if (isChecked) { |
|
| 75 | this.$dependedEl.closest(this.options.selectors.row_container).show(); |
|
| 76 | } else { |
|
| 77 | this.$dependedEl.closest(this.options.selectors.row_container).hide(); |
|
| 78 | } |
|
| 79 | } |
|
| 80 | }); |
|
| 81 | ||
| 82 | return ConfigHideFieldsComponent; |
|
| 83 | }); |
|
| 84 | ||
| @@ 1-81 (lines=81) @@ | ||
| 1 | define(function(require) { |
|
| 2 | 'use strict'; |
|
| 3 | ||
| 4 | var ConfigHideFieldsComponent; |
|
| 5 | var _ = require('underscore'); |
|
| 6 | var $ = require('jquery'); |
|
| 7 | var BaseComponent = require('oroui/js/app/components/base/component'); |
|
| 8 | ||
| 9 | ConfigHideFieldsComponent = BaseComponent.extend({ |
|
| 10 | /** |
|
| 11 | * @property {Object} |
|
| 12 | */ |
|
| 13 | options: { |
|
| 14 | selectors: { |
|
| 15 | row_container: '.control-group' |
|
| 16 | } |
|
| 17 | }, |
|
| 18 | ||
| 19 | /** |
|
| 20 | * @property {jQuery} |
|
| 21 | */ |
|
| 22 | $form: null, |
|
| 23 | ||
| 24 | /** |
|
| 25 | * @property {jQuery} |
|
| 26 | */ |
|
| 27 | $el: null, |
|
| 28 | ||
| 29 | /** |
|
| 30 | * @inheritDoc |
|
| 31 | */ |
|
| 32 | constructor: function ConfigHideFieldsComponent() { |
|
| 33 | ConfigHideFieldsComponent.__super__.constructor.apply(this, arguments); |
|
| 34 | }, |
|
| 35 | ||
| 36 | /** |
|
| 37 | * @inheritDoc |
|
| 38 | */ |
|
| 39 | initialize: function(options) { |
|
| 40 | this.options = _.defaults(options || {}, this.options); |
|
| 41 | ||
| 42 | this.$el = this.options._sourceElement; |
|
| 43 | this.$form = this.$el.closest('form'); |
|
| 44 | ||
| 45 | this.updateDependentFields(); |
|
| 46 | this.$el.on('change', $.proxy(this.updateDependentFields, this)); |
|
| 47 | }, |
|
| 48 | ||
| 49 | /** |
|
| 50 | * @inheritDoc |
|
| 51 | */ |
|
| 52 | dispose: function() { |
|
| 53 | if (this.disposed) { |
|
| 54 | return; |
|
| 55 | } |
|
| 56 | ||
| 57 | this.$el.off('change', $.proxy(this.updateDependentFields, this)); |
|
| 58 | ||
| 59 | ConfigHideFieldsComponent.__super__.dispose.call(this); |
|
| 60 | }, |
|
| 61 | ||
| 62 | updateDependentFields: function() { |
|
| 63 | var id = this.$el.data('dependency-id'); |
|
| 64 | var value = this.$el.val(); |
|
| 65 | _.each( |
|
| 66 | this.$form.find('[data-depends-on-field="' + id + '"]'), |
|
| 67 | function(item) { |
|
| 68 | var $item = $(item); |
|
| 69 | if ($item.data('depends-on-field-value') === value) { |
|
| 70 | $item.closest(this.options.selectors.row_container).show(); |
|
| 71 | } else { |
|
| 72 | $item.closest(this.options.selectors.row_container).hide(); |
|
| 73 | } |
|
| 74 | }, |
|
| 75 | this |
|
| 76 | ); |
|
| 77 | } |
|
| 78 | }); |
|
| 79 | ||
| 80 | return ConfigHideFieldsComponent; |
|
| 81 | }); |
|
| 82 | ||