<commit_before>/* globals moment */

/**
 * This widget provides a text input field to specify a date/time. The user
 * chooses the date/time using a popup picker.
 */
girder.views.DateTimeWidget = girder.View.extend({

    /**
     * @param [settings.defaultDate=false] The default date/time when not set
     * explicitly. Set to false to have no default.
     * @param [settings.showIcon=true] Whether to show a calendar icon beside
     * the input field. When true, clicking the icon shows the popup. Otherwise,
     * focusing the input field shows the popup.
     */
    initialize: function (settings) {
        this.defaultDate = settings.defaultDate || false;
        this.showIcon = _.has(settings, 'showIcon') ? settings.showIcon : true;
    },

    render: function () {
        this.$el.html(girder.templates.dateTimeWidget({
            showIcon: this.showIcon
        }));

        this.$('.g-datetime-widget').datetimepicker({
            showClear: true,
            showTodayButton: true,
            useCurrent: 'day',
            icons: {
                time: 'icon-clock',
                date: 'icon-calendar',
                up: 'icon-up-open',
                down: 'icon-down-open',
                previous: 'icon-left-open',
                next: 'icon-right-open',
                clear: 'icon-trash',
                close: 'icon-cancel',
                today: 'icon-target'
            },
            defaultDate: this.defaultDate
        });

        return this;
    },

    /**
     * Set date/time. Argument can be an ISO 8601-formatted date string, a
     * moment object, or a Date object. Call with null or the empty string to
     * clear. When called with a string, the widget displays in local time.
     *
     * @param date Date/time to display.
     */
    setDate: function (date) {
        var picker = this._picker();
        if (_.isEmpty(date)) {
            picker.clear();
        } else if (_.isString(date)) {
            var localDate = moment.utc(date).local();
            picker.date(localDate);
        } else {
            picker.date(date);
        }
    },

    /**
     * Get the date/time as a moment object in UTC. Returns null if no date is
     * set.
     */
    date: function () {
        var picker = this._picker();
        var date = picker.date();
        if (date !== null) {
            date = moment(date);
            date.utc();
        }
        return date;
    },

    /**
     * Convenience function to return the date/time as a string in UTC. Returns
     * the empty string if no date is set.
     */
    dateString: function () {
        var date = this.date();
        if (date === null) {
            return '';
        }
        return date.format();
    },

    /**
     * Convenience function to access the datetimepicker on an element.
     */
    _picker: function () {
        var picker = this.$('.g-datetime-widget').data('DateTimePicker');
        return picker;
    }
});

/**
 * This widget provides text input fields to specify a range of dates/times.
 * That is, the first field specifies "from" and the second field specifies
 * "to." The user chooses each date/time using a popup picker.
 */
girder.views.DateTimeRangeWidget = girder.View.extend({

    /**
     * @param [settings.defaultFromDate=false] The default "from" date/time when
     * not set explicitly. Set to false to have no default.
     * @param [settings.defaultToDate=false] The default "to" date/time when not
     * set explicitly. Set to false to have no default.
     * @param [settings.showIcon=true] Whether to show calendar icons beside
     * the input fields. When true, clicking the icon shows the popup. Otherwise,
     * focusing the input field shows the popup.
     */
    initialize: function (settings) {
        this.defaultFromDate = settings.defaultFromDate || false;
        this.defaultToDate = settings.defaultToDate || false;
        this.showIcon = _.has(settings, 'showIcon') ? settings.showIcon : true;
        this.fromLabel = settings.fromLabel || 'From';
        this.toLabel = settings.toLabel || 'To';
    },

    render: function () {
        this.$el.html(girder.templates.dateTimeRangeWidget({
            showIcon: this.showIcon,
            fromLabel: this.fromLabel,
            toLabel: this.toLabel
        }));

        // Link datetimepickers to disallow choosing range where "from" date is
        // after "to" date

        var options = {
            showClear: true,
            showTodayButton: true,
            icons: {
                time: 'icon-clock',
                date: 'icon-calendar',
                up: 'icon-up-open',
                down: 'icon-down-open',
                previous: 'icon-left-open',
                next: 'icon-right-open',
                clear: 'icon-trash',
                close: 'icon-cancel',
                today: 'icon-target'
            }
        };
        options.useCurrent = 'day';<commit_msg>DateTimeRangeWidget: change default labels, document label options<commit_after>/* globals moment */

/**
 * This widget provides a text input field to specify a date/time. The user
 * chooses the date/time using a popup picker.
 */
girder.views.DateTimeWidget = girder.View.extend({

    /**
     * @param [settings.defaultDate=false] The default date/time when not set
     * explicitly. Set to false to have no default.
     * @param [settings.showIcon=true] Whether to show a calendar icon beside
     * the input field. When true, clicking the icon shows the popup. Otherwise,
     * focusing the input field shows the popup.
     */
    initialize: function (settings) {
        this.defaultDate = settings.defaultDate || false;
        this.showIcon = _.has(settings, 'showIcon') ? settings.showIcon : true;
    },

    render: function () {
        this.$el.html(girder.templates.dateTimeWidget({
            showIcon: this.showIcon
        }));

        this.$('.g-datetime-widget').datetimepicker({
            showClear: true,
            showTodayButton: true,
            useCurrent: 'day',
            icons: {
                time: 'icon-clock',
                date: 'icon-calendar',
                up: 'icon-up-open',
                down: 'icon-down-open',
                previous: 'icon-left-open',
                next: 'icon-right-open',
                clear: 'icon-trash',
                close: 'icon-cancel',
                today: 'icon-target'
            },
            defaultDate: this.defaultDate
        });

        return this;
    },

    /**
     * Set date/time. Argument can be an ISO 8601-formatted date string, a
     * moment object, or a Date object. Call with null or the empty string to
     * clear. When called with a string, the widget displays in local time.
     *
     * @param date Date/time to display.
     */
    setDate: function (date) {
        var picker = this._picker();
        if (_.isEmpty(date)) {
            picker.clear();
        } else if (_.isString(date)) {
            var localDate = moment.utc(date).local();
            picker.date(localDate);
        } else {
            picker.date(date);
        }
    },

    /**
     * Get the date/time as a moment object in UTC. Returns null if no date is
     * set.
     */
    date: function () {
        var picker = this._picker();
        var date = picker.date();
        if (date !== null) {
            date = moment(date);
            date.utc();
        }
        return date;
    },

    /**
     * Convenience function to return the date/time as a string in UTC. Returns
     * the empty string if no date is set.
     */
    dateString: function () {
        var date = this.date();
        if (date === null) {
            return '';
        }
        return date.format();
    },

    /**
     * Convenience function to access the datetimepicker on an element.
     */
    _picker: function () {
        var picker = this.$('.g-datetime-widget').data('DateTimePicker');
        return picker;
    }
});

/**
 * This widget provides text input fields to specify a range of dates/times.
 * That is, the first field specifies "from" and the second field specifies
 * "to." The user chooses each date/time using a popup picker.
 */
girder.views.DateTimeRangeWidget = girder.View.extend({

    /**
     * @param [settings.defaultFromDate=false] The default "from" date/time when
     * not set explicitly. Set to false to have no default.
     * @param [settings.defaultToDate=false] The default "to" date/time when not
     * set explicitly. Set to false to have no default.
     * @param [settings.showIcon=true] Whether to show calendar icons beside
     * the input fields. When true, clicking the icon shows the popup. Otherwise,
     * focusing the input field shows the popup.
     * @param [settings.fromLabel='Start date'] The label text for the "from"
     * input field.
     * @param [settings.toLabel='End date'] The label text for the "to" input
     * field.
     */
    initialize: function (settings) {
        this.defaultFromDate = settings.defaultFromDate || false;
        this.defaultToDate = settings.defaultToDate || false;
        this.showIcon = _.has(settings, 'showIcon') ? settings.showIcon : true;
        this.fromLabel = settings.fromLabel || 'Start date';
        this.toLabel = settings.toLabel || 'End date';
    },

    render: function () {
        this.$el.html(girder.templates.dateTimeRangeWidget({
            showIcon: this.showIcon,
            fromLabel: this.fromLabel,
            toLabel: this.toLabel
        }));

        // Link datetimepickers to disallow choosing range where "from" date is
        // after "to" date

        var options = {
            showClear: true,
            showTodayButton: true,
            icons: {
                time: 'icon-clock',
                date: 'icon-calendar',
                up: 'icon-up-open',
                down: 'icon-down-open',
                previous: 'icon-left-open',
                next: 'icon-right-open',
                clear: 'icon-trash',
                close: 'icon-cancel',
                today: 'icon-target'
            }
        };
        options.useCurrent = 'day';
{'fraction_non_alphanumeric': 0.11297769918459574, 'fraction_numerical': 0.0007859318204145791, 'mean_word_length': 1.8555399719495091, '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': '5823200', 'n_tokens_mistral': 2819, 'n_tokens_neox': 2724, 'n_words': 869}