<commit_before>/*
 * Copyright (c) 1997-2013, SalesLogix, NA., LLC. All rights reserved.
 */
define('Mobile/SalesLogix/Recurrence', [
    'dojo/_base/declare',
    'dojo/_base/lang',
    'dojo/string',
    'dijit/_Widget',
    'Sage/Platform/Mobile/_ActionMixin',
    'Sage/Platform/Mobile/_CustomizationMixin',
    'Sage/Platform/Mobile/_Templated',
    'moment'
], function(
    declare,
    lang,
    string,
    _Widget,
    _ActionMixin,
    _CustomizationMixin,
    _Templated,
    moment
) {
    return lang.setObject('Mobile.SalesLogix.Recurrence', {
        // Localization
        neverText: 'Never',
        daysText: 'days',
        dailyText: 'Daily',
        weeksText: 'weeks',
        weeklyText: 'Weekly',
        weeklyOnText: 'Weekly on ${3}', // eg. {weekly} on {friday}
        monthsText: 'months',
        monthlyText: 'Monthly',
        monthlyOnDayText: 'Monthly on day ${1}', // eg. {monthly} on day {15}
        monthlyOnText: 'Monthly on ${5} ${3}', // eg. {monthly} on {second} {Monday}
        yearsText: 'years',
        yearlyText: 'Yearly',
        yearlyOnText: 'Yearly on ${2}', // eg. {yearly} on {short_date}
        yearlyOnWeekdayText: 'Yearly on ${5} ${3} in ${4}', // eg. {yearly} on {first} {Thursday} in {April}
        everyText: 'every ${0} ${1}', // eg. every {2} {weeks}
        afterCompletionText: 'after completion',
        untilEndDateText: '${0} until ${1}', // eg. {daily} until {31/10/2012}
        ordText: [
            'day',
            'first',
            'second',
            'third',
            'fourth',
            'last'
        ],

        interval: 1, // repeat every interval days/weeks/months/years
        defaultIterations: [// by RecurPeriod, -1 for After Completed. Configurable.
            7, // days
            -1,
            8, // weeks
            -1,
            12, // months
            12,
            -1,
            5, // years
            5,
            -1
        ],
        _weekDayValues: [
            131072, // sun
            262144, // mon
            524288, // tue
            1048576, // wed
            2097152, // thu
            4194304, // fri
            8388608  // sat
        ],
        simplifiedOptions: [
            {
                label: 'neverText',
                Recurring: false,
                RecurPeriod: -1, // not recurring
                basePeriodSpec: 0,
                RecurPeriodSpec: 0,
                RecurIterations: 0,
                RecurrenceState: 'rsNotRecurring'
            },
            {
                label: 'dailyText',
                Recurring: true,
                RecurPeriod: 0,
                basePeriodSpec: 0,
                RecurPeriodSpec: 0,
                RecurIterations: 7, // override from this.defaultIterations
                RecurrenceState: 'rstMaster'
            },
            {
                label: 'weeklyOnText',
                Recurring: true,
                RecurPeriod: 2,
                basePeriodSpec: 0,
                weekdays: [0, 0, 0, 0, 0, 0, 0], // none selected by default
                RecurPeriodSpec: 0,
                RecurIterations: 8,
                RecurrenceState: 'rstMaster',
                calc: true
            },
            {
                label: 'monthlyOnDayText',
                Recurring: true,
                RecurPeriod: 4,
                basePeriodSpec: 1048576,
                RecurPeriodSpec: 0,
                RecurIterations: 12,
                RecurrenceState: 'rstMaster'
            },
            {
                label: 'monthlyOnText',
                Recurring: true,
                RecurPeriod: 5,
                basePeriodSpec: 0,
                RecurPeriodSpec: 0,
                RecurIterations: 12,
                RecurrenceState: 'rstMaster',
                calc: true
            },
            {
                label: 'yearlyOnText',
                Recurring: true,
                RecurPeriod: 7,
                basePeriodSpec: 38797312,
                RecurPeriodSpec: 0,
                RecurIterations: 5,
                RecurrenceState: 'rstMaster'
            },
            {
                // Need one more for Yearly on #ord #weekday of month
                label: 'yearlyOnWeekdayText',
                Recurring: true,
                RecurPeriod: 8,
                basePeriodSpec: 0,
                RecurPeriodSpec: 0,
                weekdays: [0, 0, 0, 0, 0, 0, 0],
                RecurIterations: 5,
                RecurrenceState: 'rstMaster'
            }
        ],

        createSimplifiedOptions: function(startDate) {

            this.recalculateSimplifiedPeriodSpec(startDate);

            var list = [],
                currentDate = startDate || new Date(),
                wrapped = moment(currentDate),
                day = currentDate.getDate(),
                ord = this.ordText[parseInt((day - 1) / 7, 10) + 1],
                textOptions = [
                    null, // scale, replaced in loop
                    day,
                    wrapped.format('DD'),
                    wrapped.lang().weekdays(wrapped),
                    wrapped.lang().monthsShort(wrapped),
                    ord
                ];

            for (var recurOption in this.simplifiedOptions) {
                textOptions[0] = this.getPanel(this.simplifiedOptions[recurOption].RecurPeriod);
                this.simplifiedOptions[recurOption].RecurIterations = this.defaultIterations[this.simplifiedOptions[recurOption].RecurPeriod];
                list.push({
                    '$key': recurOption, // this.simplifiedOptions[recurOption].RecurPeriod,
                    '$descriptor': string.substitute(this[this.simplifiedOptions[recurOption].label], textOptions),
                    'recurrence': this.simplifiedOptions[recurOption]
                });
            }

            return {'$resources': list};
        },
        getPanel: function(recurPeriod, plural) {
            switch (recurPeriod) {
                case 0:
                case 1:
                    return plural ? this.daysText : this.dailyText;
                case 2:
                case 3:
                    return plural ? this.weeksText : this.weeklyText;
                case 4:
                case 5:
                case 6:
                    return plural ? this.monthsText : this.monthlyText;
                case 7:
                case 8:<commit_msg>Added null ref check. #MBL-10207 Fixed<commit_after>/*
 * Copyright (c) 1997-2013, SalesLogix, NA., LLC. All rights reserved.
 */
define('Mobile/SalesLogix/Recurrence', [
    'dojo/_base/declare',
    'dojo/_base/lang',
    'dojo/string',
    'dijit/_Widget',
    'Sage/Platform/Mobile/_ActionMixin',
    'Sage/Platform/Mobile/_CustomizationMixin',
    'Sage/Platform/Mobile/_Templated',
    'moment'
], function(
    declare,
    lang,
    string,
    _Widget,
    _ActionMixin,
    _CustomizationMixin,
    _Templated,
    moment
) {
    return lang.setObject('Mobile.SalesLogix.Recurrence', {
        // Localization
        neverText: 'Never',
        daysText: 'days',
        dailyText: 'Daily',
        weeksText: 'weeks',
        weeklyText: 'Weekly',
        weeklyOnText: 'Weekly on ${3}', // eg. {weekly} on {friday}
        monthsText: 'months',
        monthlyText: 'Monthly',
        monthlyOnDayText: 'Monthly on day ${1}', // eg. {monthly} on day {15}
        monthlyOnText: 'Monthly on ${5} ${3}', // eg. {monthly} on {second} {Monday}
        yearsText: 'years',
        yearlyText: 'Yearly',
        yearlyOnText: 'Yearly on ${2}', // eg. {yearly} on {short_date}
        yearlyOnWeekdayText: 'Yearly on ${5} ${3} in ${4}', // eg. {yearly} on {first} {Thursday} in {April}
        everyText: 'every ${0} ${1}', // eg. every {2} {weeks}
        afterCompletionText: 'after completion',
        untilEndDateText: '${0} until ${1}', // eg. {daily} until {31/10/2012}
        ordText: [
            'day',
            'first',
            'second',
            'third',
            'fourth',
            'last'
        ],

        interval: 1, // repeat every interval days/weeks/months/years
        defaultIterations: [// by RecurPeriod, -1 for After Completed. Configurable.
            7, // days
            -1,
            8, // weeks
            -1,
            12, // months
            12,
            -1,
            5, // years
            5,
            -1
        ],
        _weekDayValues: [
            131072, // sun
            262144, // mon
            524288, // tue
            1048576, // wed
            2097152, // thu
            4194304, // fri
            8388608  // sat
        ],
        simplifiedOptions: [
            {
                label: 'neverText',
                Recurring: false,
                RecurPeriod: -1, // not recurring
                basePeriodSpec: 0,
                RecurPeriodSpec: 0,
                RecurIterations: 0,
                RecurrenceState: 'rsNotRecurring'
            },
            {
                label: 'dailyText',
                Recurring: true,
                RecurPeriod: 0,
                basePeriodSpec: 0,
                RecurPeriodSpec: 0,
                RecurIterations: 7, // override from this.defaultIterations
                RecurrenceState: 'rstMaster'
            },
            {
                label: 'weeklyOnText',
                Recurring: true,
                RecurPeriod: 2,
                basePeriodSpec: 0,
                weekdays: [0, 0, 0, 0, 0, 0, 0], // none selected by default
                RecurPeriodSpec: 0,
                RecurIterations: 8,
                RecurrenceState: 'rstMaster',
                calc: true
            },
            {
                label: 'monthlyOnDayText',
                Recurring: true,
                RecurPeriod: 4,
                basePeriodSpec: 1048576,
                RecurPeriodSpec: 0,
                RecurIterations: 12,
                RecurrenceState: 'rstMaster'
            },
            {
                label: 'monthlyOnText',
                Recurring: true,
                RecurPeriod: 5,
                basePeriodSpec: 0,
                RecurPeriodSpec: 0,
                RecurIterations: 12,
                RecurrenceState: 'rstMaster',
                calc: true
            },
            {
                label: 'yearlyOnText',
                Recurring: true,
                RecurPeriod: 7,
                basePeriodSpec: 38797312,
                RecurPeriodSpec: 0,
                RecurIterations: 5,
                RecurrenceState: 'rstMaster'
            },
            {
                // Need one more for Yearly on #ord #weekday of month
                label: 'yearlyOnWeekdayText',
                Recurring: true,
                RecurPeriod: 8,
                basePeriodSpec: 0,
                RecurPeriodSpec: 0,
                weekdays: [0, 0, 0, 0, 0, 0, 0],
                RecurIterations: 5,
                RecurrenceState: 'rstMaster'
            }
        ],

        createSimplifiedOptions: function(startDate) {

            this.recalculateSimplifiedPeriodSpec(startDate);

            var list = [],
                currentDate = startDate || new Date(),
                wrapped = moment(currentDate),
                day = currentDate.getDate(),
                ord = this.ordText[parseInt((day - 1) / 7, 10) + 1],
                textOptions = [
                    null, // scale, replaced in loop
                    day,
                    wrapped.format('DD'),
                    wrapped.lang().weekdays(wrapped),
                    wrapped.lang().monthsShort(wrapped),
                    ord
                ];

            for (var recurOption in this.simplifiedOptions) {
                textOptions[0] = this.getPanel(this.simplifiedOptions[recurOption].RecurPeriod);
                this.simplifiedOptions[recurOption].RecurIterations = this.defaultIterations[this.simplifiedOptions[recurOption].RecurPeriod];

                if (this[this.simplifiedOptions[recurOption].label]) {
                    list.push({
                        '$key': recurOption, // this.simplifiedOptions[recurOption].RecurPeriod,
                        '$descriptor': string.substitute(this[this.simplifiedOptions[recurOption].label], textOptions),
                        'recurrence': this.simplifiedOptions[recurOption]
                    });
                }
            }

            return {'$resources': list};
        },
        getPanel: function(recurPeriod, plural) {
            switch (recurPeriod) {
                case 0:
                case 1:
                    return plural ? this.daysText : this.dailyText;
                case 2:
                case 3:
                    return plural ? this.weeksText : this.weeklyText;
                case 4:
                case 5:
                case 6:
                    return plural ? this.monthsText : this.monthlyText;
                case 7:
                case 8:
{'fraction_non_alphanumeric': 0.10616412067244953, 'fraction_numerical': 0.025408766408229064, 'mean_word_length': 1.260628145063335, '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': '7175062', 'n_tokens_mistral': 3930, 'n_tokens_neox': 3487, 'n_words': 790}