<commit_before>define(
[
    'models',
    'views/common',
    'views/dialogs',
    'text!templates/cluster/network_tab.html',
    'text!templates/cluster/verify_network_control.html'
],
function(models, commonViews, dialogViews, networkTabTemplate, networkTabVerificationControlTemplate) {
    'use strict';
    var NetworkTab, NetworkTabVerificationControl;

    NetworkTab = commonViews.Tab.extend({
        template: _.template(networkTabTemplate),
        updateInterval: 3000,
        hasChanges: false,
        events: {
            'keyup input[type=text]': 'changeNetworks',
            'change select': 'changeNetworks',
            'click .net-manager input:not([checked])': 'changeManager',
            'click .verify-networks-btn:not([disabled])': 'verifyNetworks',
            'click .btn-revert-changes:not([disabled])': 'revertChanges',
            'click .apply-btn:not([disabled])': 'applyChanges'
        },
        defaultButtonsState: function(buttonState) {
            this.$('.btn:not(.verify-networks-btn)').attr('disabled', buttonState);
        },
        disableControls: function() {
            this.$('.btn, input, select').attr('disabled', true);
        },
        changeNetworks: function(e) {
            var row = e ? this.$(e.currentTarget).parents('.control-group') : this.$('.control-group.fixed-network');
            row.removeClass('error').find('.help-inline').text('');
            row.find('.error').removeClass('error');
            if (e) {
                // display vlan ids range
                if (this.$(e.currentTarget).hasClass('range')) {
                    if (parseInt(this.$('input[name=fixed-amount]').val(), 10) > 1 && parseInt(this.$('input[name=fixed-vlan_start]').val(), 10)) {
                        this.$('.fixed-header .vlan').text('VLAN ID range');
                        this.$('input[name=fixed-vlan_start]').addClass('range');
                        var vlanEnd =  parseInt(this.$('input[name=fixed-vlan_start]').val(), 10) + parseInt(this.$('input[name=fixed-amount]').val(), 10) - 1;
                        vlanEnd = vlanEnd > 4094 ? 4094 : vlanEnd;
                        this.$('input[name=fixed-vlan-end]').val(vlanEnd);
                        this.$('.vlan-end').removeClass('hide').show();
                    } else {
                        this.$('.fixed-header .vlan').text('VLAN ID');
                        this.$('.vlan-end').hide();
                    }
                }
                // set fixedAmount
                if (this.$(e.currentTarget).attr('name') == 'fixed-amount' && parseInt(this.$(e.currentTarget).val(), 10)) {
                    this.fixedAmount = parseInt(this.$(e.currentTarget).val(), 10);
                }
            }
            // validate data per each change
            this.networks.get(row.data('network-id')).set({
                cidr: $('.cidr input', row).val(),
                vlan_start: parseInt($('.vlan_start input:first', row).val(), 10),
                amount: this.manager == 'FlatDHCPManager' || this.networks.get(row.data('network-id')).get('name') != 'fixed' ? 1: parseInt(this.$('input[name=fixed-amount]').val(), 10),
                network_size: e && this.$(e.currentTarget).parent().hasClass('cidr') && this.$(e.currentTarget).attr('name') != 'fixed-cidr' ? Math.pow(2, 32 - parseInt(_.last($('.cidr input', row).val().split('/')), 10)) : parseInt($('.network_size select', row).val(), 10)
            }, {validate: true});
            // check for changes
            var noChanges = (_.isEqual(this.model.get('networks').toJSON(), this.networks.toJSON()) && this.model.get('net_manager') == this.manager) || _.some(this.networks.models, 'validationError');
            this.defaultButtonsState(noChanges);
            this.hasChanges = !noChanges;
            this.page.removeVerificationTask();
        },
        changeManager: function(e) {
            this.manager = this.$(e.currentTarget).val();
            this.changeNetworks();
            this.render();
            this.$('input[name=fixed-amount]').val(this.fixedAmount);
        },
        startVerification: function() {
            var task = new models.Task();
            var options = {
                method: 'PUT',
                url: _.result(this.model, 'url') + '/verify/networks',
                data: JSON.stringify(this.networks)
            };
            task.save({}, options)
                .fail(_.bind(function() {
                        var dialog = new dialogViews.SimpleMessage({error: true, title: 'Network verification'});
                        app.page.registerSubView(dialog);
                        dialog.render();
                    }, this))<commit_msg>PRD-702 fix<commit_after>define(
[
    'models',
    'views/common',
    'views/dialogs',
    'text!templates/cluster/network_tab.html',
    'text!templates/cluster/verify_network_control.html'
],
function(models, commonViews, dialogViews, networkTabTemplate, networkTabVerificationControlTemplate) {
    'use strict';
    var NetworkTab, NetworkTabVerificationControl;

    NetworkTab = commonViews.Tab.extend({
        template: _.template(networkTabTemplate),
        updateInterval: 3000,
        hasChanges: false,
        events: {
            'keyup input[type=text]': 'changeNetworks',
            'change select': 'changeNetworks',
            'click .net-manager input:not([checked])': 'changeManager',
            'click .verify-networks-btn:not([disabled])': 'verifyNetworks',
            'click .btn-revert-changes:not([disabled])': 'revertChanges',
            'click .apply-btn:not([disabled])': 'applyChanges'
        },
        defaultButtonsState: function(buttonState) {
            this.$('.btn:not(.verify-networks-btn)').attr('disabled', buttonState);
        },
        disableControls: function() {
            this.$('.btn, input, select').attr('disabled', true);
        },
        changeNetworks: function(e) {
            var row = e ? this.$(e.currentTarget).parents('.control-group') : this.$('.control-group.fixed-network');
            row.removeClass('error').find('.help-inline').text('');
            row.find('.error').removeClass('error');
            if (e) {
                // display vlan ids range
                if (this.$(e.currentTarget).hasClass('range')) {
                    if (parseInt(this.$('input[name=fixed-amount]').val(), 10) > 1 && parseInt(this.$('input[name=fixed-vlan_start]').val(), 10)) {
                        this.$('.fixed-header .vlan').text('VLAN ID range');
                        this.$('input[name=fixed-vlan_start]').addClass('range');
                        var vlanEnd =  parseInt(this.$('input[name=fixed-vlan_start]').val(), 10) + parseInt(this.$('input[name=fixed-amount]').val(), 10) - 1;
                        vlanEnd = vlanEnd > 4094 ? 4094 : vlanEnd;
                        this.$('input[name=fixed-vlan-end]').val(vlanEnd);
                        this.$('.vlan-end').removeClass('hide').show();
                    } else {
                        this.$('.fixed-header .vlan').text('VLAN ID');
                        this.$('.vlan-end').hide();
                    }
                }
                // set fixedAmount
                if (this.$(e.currentTarget).attr('name') == 'fixed-amount' && parseInt(this.$(e.currentTarget).val(), 10)) {
                    this.fixedAmount = parseInt(this.$(e.currentTarget).val(), 10);
                }
            }
            // validate data per each change
            this.networks.get(row.data('network-id')).set({
                cidr: $('.cidr input', row).val(),
                vlan_start: Number($('.vlan_start input:first', row).val()),
                amount: this.manager == 'FlatDHCPManager' || this.networks.get(row.data('network-id')).get('name') != 'fixed' ? 1: Number(this.$('input[name=fixed-amount]').val()),
                network_size: e && this.$(e.currentTarget).parent().hasClass('cidr') && this.$(e.currentTarget).attr('name') != 'fixed-cidr' ? Math.pow(2, 32 - parseInt(_.last($('.cidr input', row).val().split('/')), 10)) : parseInt($('.network_size select', row).val(), 10)
            }, {validate: true});
            // check for changes
            var noChanges = (_.isEqual(this.model.get('networks').toJSON(), this.networks.toJSON()) && this.model.get('net_manager') == this.manager) || _.some(this.networks.models, 'validationError');
            this.defaultButtonsState(noChanges);
            this.hasChanges = !noChanges;
            this.page.removeVerificationTask();
        },
        changeManager: function(e) {
            this.manager = this.$(e.currentTarget).val();
            this.changeNetworks();
            this.render();
            this.$('input[name=fixed-amount]').val(this.fixedAmount);
        },
        startVerification: function() {
            var task = new models.Task();
            var options = {
                method: 'PUT',
                url: _.result(this.model, 'url') + '/verify/networks',
                data: JSON.stringify(this.networks)
            };
            task.save({}, options)
                .fail(_.bind(function() {
                        var dialog = new dialogViews.SimpleMessage({error: true, title: 'Network verification'});
                        app.page.registerSubView(dialog);
                        dialog.render();
                    }, this))
{'fraction_non_alphanumeric': 0.17438894792773646, 'fraction_numerical': 0.007970244420828906, 'mean_word_length': 2.060487804878049, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6033814', 'n_tokens_mistral': 2673, 'n_tokens_neox': 2578, 'n_words': 404}