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

src/Oro/Bundle/CheckoutBundle/Resources/public/js/app/views/late-checkout-registration-view.js   A

Complexity

Total Complexity 6
Complexity/F 1.2

Size

Lines of Code 58
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 1
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 6
mnd 1
bc 7
fnc 5
bpm 1.4
cpm 1.2
noi 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