1 | View Code Duplication | define(function(require) { |
|
0 ignored issues
–
show
Duplication
introduced
by
![]() |
|||
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 |