<commit_before>/*global define*/
define(['jquery', 'underscore', 'backbone', 'routing', 'orotranslation/js/translator', 'oroui/js/mediator',
    'oroui/js/widget-manager', 'orodashboard/js/widget/dashboard-item', 'jquery-ui'
    ], function ($, _, Backbone, routing, __, mediator, widgetManager, DashboardItemWidget) {
    'use strict';

    /**
     * @export orodashboard/js/dashboard-container
     * @class  orodashboard.DashboardContainer
     */
    var dashboardContainer = {
        /**
         * @property {Object}
         */
        widgets: {},

        /**
         * @property {Object}
         */
        options: {
            widgetIds: [],
            handle: ".dashboard-widget > .title",
            columnsSelector: '.dashboard-column',
            urls: {
                savePositions: routing.generate('oro_api_positions_dashboard_widget')
            },
            placeholder: {
                element: function(currentItem) {
                    var height = $(currentItem).height();
                    return $(
                        '<div><div class="widget-placeholder" style="height: ' + height + 'px;">' +
                            __('oro.dashboard.drop_placeholder_label') +
                        '</div></div>'
                    )[0];
                },
                update: function(container, p) {
                    return;
                }
            }
        },

        /**
         * Initialize dashboard
         *
         * @param {Object} options
         */
        initialize: function(options) {
            var self = this;
            this.options = _.extend({}, this.options, options);

            _.each(this.options.widgetIds, function (wid) {
                widgetManager.getWidgetInstance(
                    wid,
                    function (widget) {
                        self.add(widget);
                    }
                );
            });


            $(this.options.columnsSelector)
                .sortable({
                    handle: this.options.handle,
                    placeholder: this.options.placeholder,
                    connectWith: this.options.columnsSelector,
                    stop: function(event, ui) {
                        self.saveLayoutPosition();
                    }
                });
        },

        /**
         * Save layout position
         */
        saveLayoutPosition: function() {
            var self = this;
            var data = {
                layoutPositions: {}
            };
            $(this.options.columnsSelector).each(function(index, columnElement) {
                var columnIndex = $(columnElement).data('column');
                $('> div', columnElement).each(function (widgetIndex, widgetContainer) {
                    var wid = $('.widget-content', widgetContainer).data('wid');
                    if (self.widgets[wid]) {
                        var id = self.widgets[wid].state.id;
                        data.layoutPositions[id] = [columnIndex, widgetIndex];
                    }
                });
            });

            $.ajax({
                url: this.options.urls.savePositions,
                type: 'PUT',
                data: $.param(data)
            });
        },

        /**
         * Add dashboard widget
         *
         * @param {DashboardItemWidget} widget
         */
        add: function(widget) {
            this.widgets[widget.getWid()] = widget;
            this.getWidgetDraggableElement(widget).draggable();
        },

        /**
         *
         * @param {DashboardItemWidget} widget
         * @param {function} callback
         * @returns {HTMLElement}
         */
        getWidgetDraggableElement: function(widget, callback) {
            return widget.widget.parent();
        }
    };

    return dashboardContainer;
});<commit_msg>BAP-3906: Add JS module for dashboard widget in dashboard bundle - remove not used code<commit_after>/*global define*/
define(['jquery', 'underscore', 'backbone', 'routing', 'orotranslation/js/translator', 'oroui/js/mediator',
    'oroui/js/widget-manager', 'orodashboard/js/widget/dashboard-item', 'jquery-ui'
    ], function ($, _, Backbone, routing, __, mediator, widgetManager, DashboardItemWidget) {
    'use strict';

    /**
     * @export orodashboard/js/dashboard-container
     * @class  orodashboard.DashboardContainer
     */
    var dashboardContainer = {
        /**
         * @property {Object}
         */
        widgets: {},

        /**
         * @property {Object}
         */
        options: {
            widgetIds: [],
            handle: ".dashboard-widget > .title",
            columnsSelector: '.dashboard-column',
            urls: {
                savePositions: routing.generate('oro_api_positions_dashboard_widget')
            },
            placeholder: {
                element: function(currentItem) {
                    var height = $(currentItem).height();
                    return $(
                        '<div><div class="widget-placeholder" style="height: ' + height + 'px;">' +
                            __('oro.dashboard.drop_placeholder_label') +
                        '</div></div>'
                    )[0];
                },
                update: function(container, p) {
                    return;
                }
            }
        },

        /**
         * Initialize dashboard
         *
         * @param {Object} options
         */
        initialize: function(options) {
            var self = this;
            this.options = _.extend({}, this.options, options);

            _.each(this.options.widgetIds, function (wid) {
                widgetManager.getWidgetInstance(
                    wid,
                    function (widget) {
                        self.add(widget);
                    }
                );
            });


            $(this.options.columnsSelector)
                .sortable({
                    handle: this.options.handle,
                    placeholder: this.options.placeholder,
                    connectWith: this.options.columnsSelector,
                    stop: function(event, ui) {
                        self.saveLayoutPosition();
                    }
                });
        },

        /**
         * Save layout position
         */
        saveLayoutPosition: function() {
            var self = this;
            var data = {
                layoutPositions: {}
            };
            $(this.options.columnsSelector).each(function(index, columnElement) {
                var columnIndex = $(columnElement).data('column');
                $('> div', columnElement).each(function (widgetIndex, widgetContainer) {
                    var wid = $('.widget-content', widgetContainer).data('wid');
                    if (self.widgets[wid]) {
                        var id = self.widgets[wid].state.id;
                        data.layoutPositions[id] = [columnIndex, widgetIndex];
                    }
                });
            });

            $.ajax({
                url: this.options.urls.savePositions,
                type: 'PUT',
                data: $.param(data)
            });
        },

        /**
         * Add dashboard widget
         *
         * @param {DashboardItemWidget} widget
         */
        add: function(widget) {
            this.widgets[widget.getWid()] = widget;
        }
    };

    return dashboardContainer;
});
{'fraction_non_alphanumeric': 0.12146400321758949, 'fraction_numerical': 0.0008043973723019171, 'mean_word_length': 1.2764723832773879, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '7662158', 'n_tokens_mistral': 1870, 'n_tokens_neox': 1768, 'n_words': 315}