<commit_before>/**
 * Developer: <NAME>
 * Date: 17.08.2015
 * Copyright: 2009-2015 Comindware®
 *       All Rights Reserved
 *
 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Comindware
 *       The copyright notice above does not evidence any
 *       actual or intended publication of such source code.
 */

/* global define, require, Marionette, _, Handlebars, shared, $ */

define(['../../list/views/GridHeaderView', 'text!../templates/header.html'],
    function (GridHeaderView, template) {
        'use strict';

        var HeaderView = GridHeaderView.extend({
            initialize: function (options) {
                GridHeaderView.prototype.initialize.apply(this, arguments);
                this.columnsFit = options.columnsFit;
                _.bindAll(this, '__draggerMouseUp', '__draggerMouseMove', '__handleResize', '__handleResizeInternal', '__handleColumnSort');
                $(window).resize(this.__handleResize);
            },

            template: Handlebars.compile(template),

            onRender: function () {
                var self = this;
                this.ui.gridHeaderColumnContent.each(function (i, el) {
                    var column = self.columns[i];
                    var view = new self.gridColumnHeaderView(_.extend(self.gridColumnHeaderViewOptions || {}, {
                        model: column.viewModel,
                        column: column,
                        gridEventAggregator: self.gridEventAggregator
                    }));
                    self.listenTo(view, 'columnSort', self.__handleColumnSort);
                    var childEl = view.render().el;
                    el.appendChild(childEl);
                });
            },

            setFitToView: function () {
                var availableWidth = this.$el.parent().width(),
                    viewWidth = this.$el.width();

                this.ui.gridHeaderColumn.each(function (i, el) {
                    var columnWidth = Math.floor($(el).width() * availableWidth / viewWidth);
                    $(el).width(columnWidth);
                    this.columns[i].width = columnWidth;
                }.bind(this));

                this.$el.width(availableWidth);
            },

            __setInitialWidth: function (fullWidth) {
                var columnsL = this.ui.gridHeaderColumn.length,
                    columnWidth = Math.floor(fullWidth / columnsL),
                    fullWidth = 0;

                this.ui.gridHeaderColumn.each(function (i, el) {
                    if (this.columns[i].width)
                        columnWidth = this.columns[i].width;

                    $(el).width(columnWidth);
                    this.columns[i].width = columnWidth;
                    fullWidth += columnWidth;
                }.bind(this));

                this.$el.width(fullWidth);
            },

            onShow: function () {
                this.headerMinWidth = this.$el.parent().width();
                this.__setInitialWidth(this.headerMinWidth);
                this.__handleResizeInternal();
            },

            __startDrag: function (e) {
                var $dragger = $(e.target);
                var $column = $dragger.parent();<commit_msg>NativeGrid: proportional fit to view with minimum column width<commit_after>/**
 * Developer: <NAME>
 * Date: 17.08.2015
 * Copyright: 2009-2015 Comindware®
 *       All Rights Reserved
 *
 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Comindware
 *       The copyright notice above does not evidence any
 *       actual or intended publication of such source code.
 */

/* global define, require, Marionette, _, Handlebars, shared, $ */

define(['../../list/views/GridHeaderView', 'text!../templates/header.html'],
    function (GridHeaderView, template) {
        'use strict';

        var HeaderView = GridHeaderView.extend({
            initialize: function (options) {
                GridHeaderView.prototype.initialize.apply(this, arguments);
                this.columnsFit = options.columnsFit;
                _.bindAll(this, '__draggerMouseUp', '__draggerMouseMove', '__handleResize', '__handleResizeInternal', '__handleColumnSort');
                $(window).resize(this.__handleResize);
            },

            template: Handlebars.compile(template),

            onRender: function () {
                var self = this;
                this.ui.gridHeaderColumnContent.each(function (i, el) {
                    var column = self.columns[i];
                    var view = new self.gridColumnHeaderView(_.extend(self.gridColumnHeaderViewOptions || {}, {
                        model: column.viewModel,
                        column: column,
                        gridEventAggregator: self.gridEventAggregator
                    }));
                    self.listenTo(view, 'columnSort', self.__handleColumnSort);
                    var childEl = view.render().el;
                    el.appendChild(childEl);
                });
            },

            setFitToView: function () {
                var availableWidth = this.$el.parent().width(),
                    viewWidth = this.$el.width(),
                    columnsL = this.ui.gridHeaderColumn.length,
                    fullWidth = 0,
                    sumDelta = 0,
                    sumGap = 0;

                this.ui.gridHeaderColumn.each(function (i, el) {
                    var columnWidth = Math.floor($(el).width() * availableWidth / viewWidth);
                    if (columnWidth < this.constants.MIN_COLUMN_WIDTH) {
                        sumDelta += this.constants.MIN_COLUMN_WIDTH - columnWidth;
                        columnWidth = this.constants.MIN_COLUMN_WIDTH;
                    } else {
                        sumGap += columnWidth - this.constants.MIN_COLUMN_WIDTH;
                    }

                    this.columns[i].width = columnWidth;
                }.bind(this));

                var usedDelta = 0;

                this.ui.gridHeaderColumn.each(function (i, el) {
                    if (this.columns[i].width > this.constants.MIN_COLUMN_WIDTH) {
                        var delta = Math.ceil((this.columns[i].width - this.constants.MIN_COLUMN_WIDTH) * sumDelta / sumGap);
                        this.columns[i].width -= delta;
                        usedDelta += delta;
                    }

                    if (i === columnsL - 1 && fullWidth + this.columns[i].width < availableWidth) {
                        this.columns[i].width = availableWidth - fullWidth;
                    }

                    $(el).width(this.columns[i].width);
                    fullWidth += this.columns[i].width;

                }.bind(this));
                this.$el.width(fullWidth);
            },

            __setInitialWidth: function (availableWidth) {
                var columnsL = this.ui.gridHeaderColumn.length,
                    columnWidth = Math.floor(availableWidth / columnsL),
                    fullWidth = 0;

                this.ui.gridHeaderColumn.each(function (i, el) {
                    if (this.columns[i].width)
                        columnWidth = this.columns[i].width;

                    if (i === columnsL - 1 && fullWidth + this.columns[i].width < availableWidth) {
                        this.columns[i].width = availableWidth - fullWidth;
                    }

                    $(el).width(columnWidth);
                    this.columns[i].width = columnWidth;
                    fullWidth += columnWidth;
                }.bind(this));

                this.$el.width(fullWidth);
            },

            onShow: function () {
                this.headerMinWidth = this.$el.parent().width();
                this.__setInitialWidth(this.headerMinWidth);
                this.__handleResizeInternal();
            },

            __startDrag: function (e) {
                var $dragger = $(e.target);
                var $column = $dragger.parent();
{'fraction_non_alphanumeric': 0.11037167252636866, 'fraction_numerical': 0.005022601707684581, 'mean_word_length': 1.5110340479192939, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6320012', 'n_tokens_mistral': 2064, 'n_tokens_neox': 1899, 'n_words': 379}