<commit_before>var Backbone = require('backbone');


var NicsRowView = require('./nics-row');
var JobProgress = require('./job-progress');

var NicsView = Backbone.Marionette.CompositeView.extend({
    template: require('../tpl/nics.hbs'),
    itemView: NicsRowView,
    itemViewContainer: 'tbody',
    events: {
        'click button.add-nic': 'onClickAddNic',
        'click button.remove-nics': 'onClickRemoveNics'
    },

    initialize: function(options)  {
        this.model = options.vm;
        this.selectedNics = new Backbone.Collection();
        this.collection = new Backbone.Collection(this.model.get('nics'));

        this.listenTo(this.selectedNics, 'add remove', this.onChangeSelectedNics, this);
        this.listenTo(this.model, 'change:nics', this.resetNics, this);
    },

    resetNics: function(vm) {
        this.collection.reset(vm.get('nics'));
    },

    onClickRemoveNics: function() {
        var self = this;
        var macs = this.selectedNics.pluck('mac');
        this.model.removeNics(macs, function(job) {
            var jobView = new JobProgress({model: job});
            jobView.show();
            self.listenTo(jobView, 'execution', function(st) {
                console.log(st);
                if (st === 'succeeded') {
                    self.selectedNics.each(function(n) {
                        self.collection.remove(n);
                    });
                }
            });
        });
    },

    onClickAddNic: function() {
        var AddNicView = require('./vm-add-nic');
        var view = new AddNicView({vm: this.model});
        view.render();<commit_msg>ADMINUI-1170 Destructive operations should require confirmation<commit_after>var Backbone = require('backbone');


var NicsRowView = require('./nics-row');
var JobProgress = require('./job-progress');

var NicsView = Backbone.Marionette.CompositeView.extend({
    template: require('../tpl/nics.hbs'),
    itemView: NicsRowView,
    itemViewContainer: 'tbody',
    events: {
        'click button.add-nic': 'onClickAddNic',
        'click button.remove-nics': 'onClickRemoveNics'
    },

    initialize: function(options)  {
        this.model = options.vm;
        this.selectedNics = new Backbone.Collection();
        this.collection = new Backbone.Collection(this.model.get('nics'));

        this.listenTo(this.selectedNics, 'add remove', this.onChangeSelectedNics, this);
        this.listenTo(this.model, 'change:nics', this.resetNics, this);
    },

    resetNics: function(vm) {
        this.collection.reset(vm.get('nics'));
    },

    onClickRemoveNics: function() {
        var confirm = window.confirm('Are you sure you want to remove selected nics?');
        if (! confirm) {
            return;
        }

        var self = this;
        var macs = this.selectedNics.pluck('mac');
        this.model.removeNics(macs, function(job) {
            var jobView = new JobProgress({model: job});
            jobView.show();
            self.listenTo(jobView, 'execution', function(st) {
                console.log(st);
                if (st === 'succeeded') {
                    self.selectedNics.each(function(n) {
                        self.collection.remove(n);
                    });
                }
            });
        });
    },

    onClickAddNic: function() {
        var AddNicView = require('./vm-add-nic');
        var view = new AddNicView({vm: this.model});
        view.render();
{'fraction_non_alphanumeric': 0.1427325581395349, 'fraction_numerical': 0.0011627906976744186, 'mean_word_length': 2.230985915492958, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3272065', 'n_tokens_mistral': 1037, 'n_tokens_neox': 1001, 'n_words': 184}