<commit_before>/*jslint nomen:true*/
/*global define*/
define([
    'backbone',
    'underscore',
    'orotranslation/js/translator',
    './collection',
    './model',
    './view-name-modal',
    'oroui/js/mediator',
    'oroui/js/delete-confirmation'
], function (Backbone, _, __, GridViewsCollection, GridViewModel, ViewNameModal, mediator, DeleteConfirmation) {
    'use strict';
    var $, GridViewsView;
    $ = Backbone.$;

    /**
     * Datagrid views widget
     *
     * @export  orodatagrid/js/datagrid/grid-views/view
     * @class   orodatagrid.datagrid.GridViewsView
     * @extends Backbone.View
     */
    GridViewsView = Backbone.View.extend({
        className: 'grid-views',

        /** @property */
        events: {
            "click .views-group a": "onChange",
            "click a.save": "onSave",
            "click a.save_as": "onSaveAs",
            "click a.share": "onShare",
            "click a.unshare": "onUnshare",
            "click a.delete": "onDelete",
            "click a.rename": "onRename",
            "click a.discard_changes": "onDiscardChanges"
        },

        /** @property */
        template: _.template(
            '<div class="btn-toolbar">' +
                '<% if (choices.length) { %>' +
                    '<div class="btn-group views-group">' +
                        '<button data-toggle="dropdown" class="btn btn-link dropdown-toggle <% if (disabled) { %>disabled<% } %>">' +
                            '<%= title %>' +
                        '</button>' +
                        '<ul class="dropdown-menu">' +
                            '<% _.each(choices, function (choice) { %>' +
                                '<li><a href="#" data-value="' + '<%= choice.value %>' + '">' + '<%= choice.label %>' + '</a></li>' +
                            '<% }); %>' +
                        '</ul>' +
                    '</div>' +
                '<% } %>' +
                '<% if (showActions) { %>' +
                    '<div class="btn-group actions-group">' +
                        '<button class="btn btn-link dropdown-toggle" data-toggle="dropdown" href="#">' +
                            '<%= actionsLabel %>' +
                        '</button>' +
                        '<ul class="dropdown-menu">' +
                            '<% _.each(actions, function(action) { %>' +
                                '<% if (action.enabled) { %>' +
                                    '<li><a href="#" class="<%= action.name %>"><%= action.label %></a></li>' +
                                '<% } %>' +
                            '<% }); %>' +
                        '</ul>' +
                    '</div>' +
                    '<% if (dirty) { %>' +
                        '<div class="edited-label">&nbsp;-&nbsp;<%= editedLabel %></div>' +
                    '<% } %>' +
                '<% } %>' +
            '</div>'
        ),

        /** @property */
        titleTemplate: _.template(
            '<% if (navbar) { %>' +
                '<h1 class="oro-subtitle"><%= title %><span class="caret"></span></h1>' +
            '<% } else { %>' +
                '<%= title %><span class="caret"></span>' +
            '<% } %>'
        ),

        /** @property */
        title: null,

        /** @property */
        enabled: true,

        /** @property */
        choices: [],

        /** @property */
        permissions: {
            CREATE: false,
            EDIT: false,
            DELETE: false,
            SHARE: false,
            EDIT_SHARED: false
        },

        /** @property */
        prevState: {},

        /** @property */
        gridName: {},

        /** @property */
        viewsCollection: GridViewsCollection,

        /** @property */
        originalTitle: null,

        /**
         * Initializer.
         *
         * @param {Object} options
         * @param {Backbone.Collection} options.collection
         * @param {Boolean} [options.enable]
         * @param {Array}   [options.choices]
         * @param {Array}   [options.views]
         */
        initialize: function (options) {
            options = options || {};

            if (!options.collection) {
                throw new TypeError("'collection' is required");
            }

            if (options.choices) {
                this.choices = _.union(this.choices, options.choices);
                this._getView('__all__').label = __('oro.datagrid.gridView.all') + (options.title || '');
            }

            if (options.permissions) {
                this.permissions = _.extend(this.permissions, options.permissions);
            }

            if (options.title) {
                this.title = options.title;
            }

            this.originalTitle = $(document).prop('title');

            this.gridName = options.gridName;
            this.collection = options.collection;
            this.enabled = options.enable != false;

            this.listenTo(this.collection, "updateState", this.render);
            this.listenTo(this.collection, "beforeFetch", this.render);
            this.listenTo(this.collection, "reset", this._onCollectionReset);
            this.listenTo(this.collection, "reset", this.render);

            options.views = options.views || [];
            _.each(options.views, function(view) {
                view.grid_name = this.gridName;
                view.label = _.first(_.filter(this.choices, function (item) {
                    return view.name == item.value;
                }, this)).label;
            }, this);

            this.viewsCollection = new this.viewsCollection(options.views);
            if (!this.collection.state.gridView) {
                this.collection.state.gridView = '__all__';
            }

            this.viewDirty = !this._isCurrentStateSynchronized();
            this.prevState = this._getCurrentState();

            this.listenTo(this.viewsCollection, 'add', this._onModelAdd);
            this.listenTo(this.viewsCollection, 'remove', this._onModelRemove);
            this.listenTo(this.viewsCollection, 'change', this._onModelChange, this);

            this.listenTo(mediator, 'datagrid:' + this.gridName + ':views:add', function(model) {<commit_msg>BAP-8020: Wrong View name after Reset<commit_after>/*jslint nomen:true*/
/*global define*/
define([
    'backbone',
    'underscore',
    'orotranslation/js/translator',
    './collection',
    './model',
    './view-name-modal',
    'oroui/js/mediator',
    'oroui/js/delete-confirmation'
], function (Backbone, _, __, GridViewsCollection, GridViewModel, ViewNameModal, mediator, DeleteConfirmation) {
    'use strict';
    var $, GridViewsView;
    $ = Backbone.$;

    /**
     * Datagrid views widget
     *
     * @export  orodatagrid/js/datagrid/grid-views/view
     * @class   orodatagrid.datagrid.GridViewsView
     * @extends Backbone.View
     */
    GridViewsView = Backbone.View.extend({
        className: 'grid-views',

        /** @property */
        events: {
            "click .views-group a": "onChange",
            "click a.save": "onSave",
            "click a.save_as": "onSaveAs",
            "click a.share": "onShare",
            "click a.unshare": "onUnshare",
            "click a.delete": "onDelete",
            "click a.rename": "onRename",
            "click a.discard_changes": "onDiscardChanges"
        },

        /** @property */
        template: _.template(
            '<div class="btn-toolbar">' +
                '<% if (choices.length) { %>' +
                    '<div class="btn-group views-group">' +
                        '<button data-toggle="dropdown" class="btn btn-link dropdown-toggle <% if (disabled) { %>disabled<% } %>">' +
                            '<%= title %>' +
                        '</button>' +
                        '<ul class="dropdown-menu">' +
                            '<% _.each(choices, function (choice) { %>' +
                                '<li><a href="#" data-value="' + '<%= choice.value %>' + '">' + '<%= choice.label %>' + '</a></li>' +
                            '<% }); %>' +
                        '</ul>' +
                    '</div>' +
                '<% } %>' +
                '<% if (showActions) { %>' +
                    '<div class="btn-group actions-group">' +
                        '<button class="btn btn-link dropdown-toggle" data-toggle="dropdown" href="#">' +
                            '<%= actionsLabel %>' +
                        '</button>' +
                        '<ul class="dropdown-menu">' +
                            '<% _.each(actions, function(action) { %>' +
                                '<% if (action.enabled) { %>' +
                                    '<li><a href="#" class="<%= action.name %>"><%= action.label %></a></li>' +
                                '<% } %>' +
                            '<% }); %>' +
                        '</ul>' +
                    '</div>' +
                    '<% if (dirty) { %>' +
                        '<div class="edited-label">&nbsp;-&nbsp;<%= editedLabel %></div>' +
                    '<% } %>' +
                '<% } %>' +
            '</div>'
        ),

        /** @property */
        titleTemplate: _.template(
            '<% if (navbar) { %>' +
                '<h1 class="oro-subtitle"><%= title %><span class="caret"></span></h1>' +
            '<% } else { %>' +
                '<%= title %><span class="caret"></span>' +
            '<% } %>'
        ),

        /** @property */
        title: null,

        /** @property */
        enabled: true,

        /** @property */
        choices: [],

        /** @property */
        permissions: {
            CREATE: false,
            EDIT: false,
            DELETE: false,
            SHARE: false,
            EDIT_SHARED: false
        },

        /** @property */
        prevState: {},

        /** @property */
        gridName: {},

        /** @property */
        viewsCollection: GridViewsCollection,

        /** @property */
        originalTitle: null,

        /**
         * Initializer.
         *
         * @param {Object} options
         * @param {Backbone.Collection} options.collection
         * @param {Boolean} [options.enable]
         * @param {Array}   [options.choices]
         * @param {Array}   [options.views]
         */
        initialize: function (options) {
            options = options || {};

            if (!options.collection) {
                throw new TypeError("'collection' is required");
            }

            if (options.choices) {
                this.choices = _.union(this.choices, options.choices);
                this._getView('__all__').label = __('oro.datagrid.gridView.all') + (options.title || '');
            }

            if (options.permissions) {
                this.permissions = _.extend(this.permissions, options.permissions);
            }

            if (options.title) {
                this.title = options.title;
            }

            this.originalTitle = $(document).prop('title');

            this.gridName = options.gridName;
            this.collection = options.collection;
            this.enabled = options.enable != false;

            this.listenTo(this.collection, "updateState", function (collection) {
                if (!collection.state.gridView) {
                    collection.state.gridView = '__all__';
                }
            });
            this.listenTo(this.collection, "updateState", this.render);
            this.listenTo(this.collection, "beforeFetch", this.render);
            this.listenTo(this.collection, "reset", this._onCollectionReset);
            this.listenTo(this.collection, "reset", this.render);

            options.views = options.views || [];
            _.each(options.views, function(view) {
                view.grid_name = this.gridName;
                view.label = _.first(_.filter(this.choices, function (item) {
                    return view.name == item.value;
                }, this)).label;
            }, this);

            this.viewsCollection = new this.viewsCollection(options.views);
            if (!this.collection.state.gridView) {
                this.collection.state.gridView = '__all__';
            }

            this.viewDirty = !this._isCurrentStateSynchronized();
            this.prevState = this._getCurrentState();

            this.listenTo(this.viewsCollection, 'add', this._onModelAdd);
            this.listenTo(this.viewsCollection, 'remove', this._onModelRemove);
            this.listenTo(this.viewsCollection, 'change', this._onModelChange, this);

            this.listenTo(mediator, 'datagrid:' + this.gridName + ':views:add', function(model) {
{'fraction_non_alphanumeric': 0.1631690639000236, 'fraction_numerical': 0.0006287825198459483, 'mean_word_length': 1.4478645632935745, 'pattern_counts': {'":': 16, '<': 115, '<?xml version=': 0, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3231167', 'n_tokens_mistral': 3541, 'n_tokens_neox': 3412, 'n_words': 579}