<commit_before>/*global define*/

define(['jquery', 'underscore', 'backbone', 'templates', 'bootstrap-switch'], function($, _, Backbone, JST) {
    'use strict';

    var FilterLabelView = Backbone.Marionette.ItemView.extend({
        tagName: 'div',
        ui: {
            'toggle': '.make-switch'
        },
        getSwitch: function() {
            return this.$('.make-switch');
        },
        initialize: function() {
            this.listenTo(this.model, 'change:enabled', this.enabled);
            this.listenTo(this.model, 'change:visible', this.visible);
            this.listenTo(this.model, 'change:count', this.updateCount);
            this.listenTo(this, 'render', this.postRender);
            this.listenTo(this.options.vent, 'disable', this.switchDisabled);
            this.listenTo(this.options.vent, 'enable', this.switchEnabled);
            _.bindAll(this, 'switchDisabled', 'switchEnabled');
        },
        updateCount: function(model) {
            this.getSwitch().find('label').text(model.get('count'));
        },
        isEnabled: function(model) {
            return model.get('enabled');
        },
        isVisible: function(model) {
            return model.get('visible');
        },
        enabled: function() {
            if (this.isEnabled(this.model)) {
                
            }
        },
        visible: function() {
            if (!this.isVisible(this.model)) {
                this.$el.hide();
            }
        },
        switchDisabled: function() {
            this.getSwitch().bootstrapSwitch('setActive', false);
        },
        switchEnabled: function() {
            this.getSwitch().bootstrapSwitch('setActive', true);
        },
        postRender: function() {
            var $switch = this.getSwitch().attr({
                'data-on': 'success',
                'data-off': 'danger'
            });
            var self = this;
            $switch.bootstrapSwitch('destroy');
            $switch.bootstrapSwitch().on('switch-change', function() {
                var d = $.Deferred();
                self.options.vent.trigger('disable');
                self.model.set('enabled', !self.model.get('enabled'));
                self.options.vent.trigger('filter', d);
                d.done(function() {
                    self.options.vent.trigger('enable');
                });
            }).on('click', function(evt) {
                evt.stopPropagation();
                evt.preventDefault();
            });
            this.visible();
        },
        template: JST['app/scripts/templates/filter-label.ejs']
    });

    return FilterLabelView;
});<commit_msg>Restore state when rendering state toggle<commit_after>/*global define*/

define(['jquery', 'underscore', 'backbone', 'templates', 'bootstrap-switch'], function($, _, Backbone, JST) {
    'use strict';

    var FilterLabelView = Backbone.Marionette.ItemView.extend({
        tagName: 'div',
        ui: {
            'toggle': '.make-switch'
        },
        getSwitch: function() {
            return this.$('.make-switch');
        },
        initialize: function() {
            this.listenTo(this.model, 'change:enabled', this.enabled);
            this.listenTo(this.model, 'change:visible', this.visible);
            this.listenTo(this.model, 'change:count', this.updateCount);
            this.listenTo(this, 'render', this.postRender);
            this.listenTo(this.options.vent, 'disable', this.switchDisabled);
            this.listenTo(this.options.vent, 'enable', this.switchEnabled);
            _.bindAll(this, 'switchDisabled', 'switchEnabled');
        },
        updateCount: function(model) {
            this.getSwitch().find('label').text(model.get('count'));
        },
        isEnabled: function(model) {
            return model.get('enabled');
        },
        isVisible: function(model) {
            return model.get('visible');
        },
        enabled: function() {
            var enabled = this.isEnabled(this.model);
            this.getSwitch().bootstrapSwitch('setState', enabled, true /* skip emit change event */);
        },
        visible: function() {
            if (!this.isVisible(this.model)) {
                this.$el.hide();
            }
        },
        switchDisabled: function() {
            this.getSwitch().bootstrapSwitch('setActive', false);
        },
        switchEnabled: function() {
            this.getSwitch().bootstrapSwitch('setActive', true);
        },
        postRender: function() {
            var $switch = this.getSwitch().attr({
                'data-on': 'success',
                'data-off': 'danger'
            });
            var self = this;
            $switch.bootstrapSwitch('destroy');
            $switch.bootstrapSwitch().on('switch-change', function() {
                var d = $.Deferred();
                self.options.vent.trigger('disable');
                self.model.set('enabled', !self.model.get('enabled'));
                self.options.vent.trigger('filter', d);
                d.done(function() {
                    self.options.vent.trigger('enable');
                });
            }).on('click', function(evt) {
                evt.stopPropagation();
                evt.preventDefault();
            });
            this.visible();
            this.enabled();
        },
        template: JST['app/scripts/templates/filter-label.ejs']
    });

    return FilterLabelView;
});
{'fraction_non_alphanumeric': 0.15507432556432374, 'fraction_numerical': 0.0, 'mean_word_length': 1.8063851699279094, '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': '4256785', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1402, 'n_words': 232}