Test Setup Failed
Push — master ( 30c942...1927eb )
by
unknown
04:05
created

BaseComponent.extend.initialize   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
/** @lends LateRegistrationView */
2
define(function(require) {
3
    'use strict';
4
5
    var LateRegistrationView;
6
    var $ = require('jquery');
7
    var _ = require('underscore');
8
    var BaseComponent = require('oroui/js/app/views/base/view');
9
10
    LateRegistrationView = BaseComponent.extend({
11
12
        /**
13
         * @property {jQuery}
14
         */
15
        $el: null,
16
17
        options: {
18
            selectors: {
19
                switcher: null,
20
                fieldsContainer: null
21
            }
22
        },
23
24
        /**
25
         * @inheritDoc
26
         */
27
        constructor: function LateRegistrationView() {
28
            LateRegistrationView.__super__.constructor.apply(this, arguments);
29
        },
30
31
        /**
32
         * @inheritDoc
33
         */
34
        initialize: function(options) {
35
            this.options = $.extend(true, {}, this.options, options);
36
37
            this.$switcher = this.$el.find(this.options.selectors.switcher);
38
            this.$fieldsContainer = this.$el.find(this.options.selectors.fieldsContainer);
39
            this.$switcher.on('change', _.bind(this.onOptionChange, this));
40
            this.onOptionChange();
41
        },
42
43
        onOptionChange: function() {
44
            var inputs = this.$fieldsContainer.find('input');
45
            var validationDisabled = false;
46
            if ($(this.$switcher).is(':checked')) {
47
                $(this.$fieldsContainer).show();
48
            } else {
49
                $(this.$fieldsContainer).hide();
50
                validationDisabled = true;
51
            }
52
            _.each(inputs, function(input) {
53
                $(input).prop('disabled', validationDisabled).inputWidget('refresh');
54
            });
55
        }
56
    });
57
58
    return LateRegistrationView;
59
});
60