WRMCB=function(e){var c=console;if(c&&c.log&&c.error){c.log('Error running batched script.');c.error(e);}}
;
try {
/* module-key = 'is.origo.jira.tempo-plugin:tempo-analytics', location = 'com/tempoplugin/tempo-analytics-constants.js' */
/**
 * Created by thoreyr on 7/14/16.
 * 'tempo/analytics-constants'
 */
define('tempo/analytics-constants', [], function () {
window.TEMPO = window.TEMPO || {};

TEMPO.Analytics = _.extend(TEMPO.Analytics || {}, {
    constants: {
        ANALYTICS_BEAN_FIELDS: {
            EVENT: 'event',
            TYPE: 'type',
            PROPERTIES: 'properties',
            TRAITS: 'traits'
        },
        EVENT_TYPES: {
            SCREEN: 'screen',
            TRACK: 'track'
        },
        EVENTS: {
            CHANGED_MAX_HOURS_USERS_CAN_LOG_WORK_PER_DAY: 'Changed Max Hours Users Can Log Work per Day',
            CHANGED_MAX_DAYS_USERS_CAN_LOG_FUTURE_WORK: 'Changed Max Days Users Can Log Future Work',
            CHANGED_PERIOD_VIEW: 'Changed Period View',
            DELETED_TRACKER: 'Deleted Tracker',
            DISPLAYED_TRACKER: 'Displayed Tracker',
            EXPORT_TIME_AND_EXPENSES: 'Export Time and Expenses',
            MADE_REMAINING_ESTIMATE_OPTIONAL: 'Made Remaining Estimate Optional',
            MADE_REMAINING_ESTIMATE_REQUIRED: 'Made Remaining Estimate Required',
            MADE_WORKLOG_DESCRIPTION_OPTIONAL: 'Made Worklog Description Optional',
            MADE_WORKLOG_DESCRIPTION_REQUIRED: 'Made Worklog Description Required',
            MOVED_WORKLOG: 'Moved Worklog',
            PAUSED_TRACKER: 'Paused Tracker',
            SPLIT_WORKLOG: 'Split Worklog',
            STARTED_TRACKER: 'Started Tracker',
            TRIED_TO_LOG_WORK: 'Tried to Log Work',
            TRIED_TO_PLAN_TIME: 'Tried to Plan Time'
        },
        FORM_FIELDS: {
            ANALYTICS_ORIGIN_ACTION: 'analytics-origin-action',
            ANALYTICS_ORIGIN_PAGE: 'analytics-origin-page',
            ANALYTICS_ORIGIN_VIEW: 'analytics-origin-view',
            ANALYTICS_PAGE_CATEGORY: 'analytics-page-category'
        },
        KEYS: {
            EXPORT_FORMAT: 'Export Format',
            LOAD_TIME_UI: 'Load Time of UI',
            MAX_HOURS_USERS_CAN_LOG_WORK_PER_DAY: 'Max Hours Users Can Log Work per Day',
            MAX_DAYS_USERS_CAN_LOG_FUTURE_WORK: 'Max Days Users Can Log Future Work',
            NUMBER_OF_APPROVALS: 'Number of Approvals',
            ORIGIN_ACTION: 'Origin Action',
            ORIGIN_PAGE: 'Origin Page',
            ORIGIN_VIEW: 'Origin View',
            PAGE_CATEGORY: 'Page Category',
            PRESELECTED_ISSUE: 'Preselected Issue'
        },
        VALUES: {
            PAGES: {
                GLOBAL_CONFIGURATION: 'Global Configuration',
                INTERNAL_ISSUES: 'Internal Issues',
                JIRA_AGILE_VIEW: 'Agile View',
                JIRA_DASHBOARD: 'JIRA Dashboard',

                JIRA_ISSUE_SEARCH: 'Issue Search',
                JIRA_ISSUE_SEARCH_OR_VIEW: 'Issue Search or Issue View',
                JIRA_ISSUE_VIEW: 'Issue View',

                JIRA_PROJECT_ISSUES: 'Project Issues',
                JIRA_PROJECT_SINGLE: 'Project Single Issue',

                JIRA_SERVICE_QUEUES: 'Service Desk Queues',

                TEMPO_TRACKER: 'Tracker',

                TEMPO_USER_BOARD: 'User Board',
                TEMPO_USER_WORKLOG_CALENDAR: 'Worklog Calendar',

                TEMPO_TEAM_APPROVALS: 'Team Approvals',
                TEMPO_TEAM_BOARD: 'Team Board',
                TEMPO_TEAM_UTILIZATION: 'Team Utilization',

                TEMPO_ACCOUNT_BOARD: 'Account Board',
                TEMPO_ACCOUNT_REVENUE_REPORT: 'Account Revenue Report',
                TEMPO_ACCOUNT_TIME_AND_EXPENSES: 'Account Time and Expenses',

                TEMPO_ISSUE_BOARD: 'Issue Board',
                TEMPO_PROJECT_BOARD: 'Project Board',
                TEMPO_ADVANCED_BOARD: 'Advanced Board',
            },
            PAGE_CATEGORIES: {
                JIRA: 'JIRA',
                TEMPO: 'Tempo'
            },
            VIEWS: {
                CALENDAR: 'Calendar',
                COLLABORATORS_PANE: 'Collaborators Pane',
                ISSUE_LIST: 'Issue List',
                ISSUE_OPERATIONS: 'Issue Operations',
                LIST: 'List',
                REPORT: 'Report',
                TEMPO_ISSUE_PANEL: 'Tempo Issue Panel',
                TIME: 'Time',
                TIMETRACKING_PANE: 'Time Tracking Pane',
                TIMESHEET: 'Timesheet'
            },
            ACTIONS: {
                CLICK_ON_CANVAS: 'Clicked',
                CLICK_CALENDAR_CELL: 'Clicked Calendar Cell',
                CLICK_CELL: 'Clicked Cell',
                CLICK_DROPDOWN_BUTTON: 'Clicked Dropdown Button',
                CLICK_LOG_WORK_BUTTON: 'Clicked Log Work Button',
                CLICK_LOG_WORK_LINK: 'Clicked Log Work Link',
                CLICK_PLAN_TIME_LINK: 'Clicked Plan Time Link',
                CLICK_PLUS_BUTTON: 'Clicked Plus Button',
                CLICK_SUGGESTION: 'Clicked Suggestion',
                CONVERTED_TRACKER: 'Converted Tracker',

                COPY: 'Copied',
                DRAG_FROM_SIDEBAR: 'Dragged from Sidebar',
                HIGHLIGHT_CELLS: 'Highlighted Cells',
                KEYBOARD_SHORTCUT: 'Pressed Keyboard Shortcut',
            },
            EXPORT_TYPES: {
                EXCEL: 'Excel',
                PRINT: 'Print'
            },
            UNKNOWN: 'Unknown'
        }
    }
});
return TEMPO.Analytics.constants;
});

}catch(e){WRMCB(e)};
;
try {
/* module-key = 'is.origo.jira.tempo-plugin:tempo-analytics', location = 'com/tempoplugin/js/analytics/tempo.analytics.js' */
define('tempo/analytics', ['jquery', 'tempo/context-path', 'tempo/analytics-constants'],
    function ($, contextPath, AnalyticsConstants) {

    var Analytics = {
        ORIGIN: {
            page: '',
            view: '',
            action: '',
            page_category: ''
        },

        Constants: AnalyticsConstants,

        stringContains: function (str, subStr) {
            return str.indexOf(subStr) !== -1;
        },

        getTempoBoardOriginPage: function () {

            const urlPart = window.location.pathname;

            var originPage = null;
            if (Analytics.stringContains(urlPart, '/TempoUserBoard')) {
                originPage = AnalyticsConstants.VALUES.PAGES.TEMPO_USER_BOARD;
            } else if (Analytics.stringContains(urlPart, '/TempoTeamBoard')) {
                originPage = AnalyticsConstants.VALUES.PAGES.TEMPO_TEAM_BOARD;
            } else if (Analytics.stringContains(urlPart, '/TempoAccountBoard')) {
                originPage = AnalyticsConstants.VALUES.PAGES.TEMPO_ACCOUNT_BOARD;
            } else if (Analytics.stringContains(urlPart, '/TempoProjectBoard')) {
                originPage = AnalyticsConstants.VALUES.PAGES.TEMPO_PROJECT_BOARD;
            } else if (Analytics.stringContains(urlPart, '/TempoIssueBoard')) {
                originPage = AnalyticsConstants.VALUES.PAGES.TEMPO_ISSUE_BOARD;
            }  else if (Analytics.stringContains(urlPart, '/TempoSearchBoard')) {
                originPage = AnalyticsConstants.VALUES.PAGES.TEMPO_ADVANCED_BOARD;
            }

            return originPage;
        },

        getTempoBoardOriginView: function () {

            const urlPart = window.location.pathname;

            var originView = null;
            if (Analytics.stringContains(urlPart, '!timesheet')) {
                originView = AnalyticsConstants.VALUES.VIEWS.TIMESHEET;
            } else if (Analytics.stringContains(urlPart, '!report')) {
                originView = AnalyticsConstants.VALUES.VIEWS.REPORT;
            } else if (Analytics.stringContains(urlPart, '!worklogs')) {
                originView = AnalyticsConstants.VALUES.VIEWS.LIST;
            } else if (Analytics.stringContains(urlPart, '!calendar')) {
                originView = AnalyticsConstants.VALUES.VIEWS.CALENDAR;
            }

            return originView;
        },


        trackChangedPeriodViewWithArrows: function (action, start, end) {
            Analytics.trackEvent({
                event: AnalyticsConstants.EVENTS.CHANGED_PERIOD_VIEW,
                properties: {
                    'Origin Page': Analytics.getTempoBoardOriginPage(),
                    'Origin View':  Analytics.getTempoBoardOriginView(),
                    'Origin Action': action,
                    'Period Length in Days': moment(end).diff(start, 'days') + 1
                },
            });
        },

        trackMoveWorklog: function () {
            const payload = {
                event: AnalyticsConstants.EVENTS.MOVED_WORKLOG,
                type: AnalyticsConstants.EVENT_TYPES.TRACK
            };
            Analytics.trackEvent(payload);
        },

        trackSplitWorklog: function () {
            const payload = {
                event: AnalyticsConstants.EVENTS.SPLIT_WORKLOG,
                type: AnalyticsConstants.EVENT_TYPES.TRACK
            };
            Analytics.trackEvent(payload);
        },

        trackTriedToLogWork: function () {
            const payload = {
                event: AnalyticsConstants.EVENTS.TRIED_TO_LOG_WORK,
                type: AnalyticsConstants.EVENT_TYPES.TRACK
            };
            Analytics.trackEvent(payload);
        },

        trackTriedToPlanTime: function (originPage) {
            const properties = {};
            properties[AnalyticsConstants.KEYS.ORIGIN_PAGE] = originPage;
            const payload = {
                event: AnalyticsConstants.EVENTS.TRIED_TO_PLAN_TIME,
                type: AnalyticsConstants.EVENT_TYPES.TRACK,
                properties: properties
            };
            Analytics.trackEvent(payload);
        },

        addAnalyticsToForm: function ($form) {

            function getTempoLocation(ref) {
                var idx = ref.indexOf('/Tempo');
                var idx2 = ref.indexOf('.jspa');
                if (idx > 0 && idx2 > idx) {
                    return ref.substring(idx + 1, idx2).split('!');
                }
                return undefined;
            }

            var loggedWithTracker = $('[name=tracker]', $form).val() === 'true';

            var tempoLocation = getTempoLocation(window.location.href);

            if (loggedWithTracker) {
                this.addPageTrackingInfo(AnalyticsConstants.VALUES.PAGES.TEMPO_TRACKER);
                this.addPageCategoryTrackingInfo(AnalyticsConstants.VALUES.PAGE_CATEGORIES.TEMPO);
            } else if (tempoLocation) {
                if (tempoLocation[0]) {
                    this.addPageTrackingInfo(tempoLocation[0]);
                }
                if (tempoLocation[1]) {
                    this.addViewTrackingInfo(tempoLocation[1]);
                }
            } else if (Analytics.stringContains(window.location.href, '/projects/')) {
                if (Analytics.stringContains(window.location.href, '/issue/')) {
                    this.addPageTrackingInfo(AnalyticsConstants.VALUES.PAGES.JIRA_PROJECT_SINGLE);
                    this.addPageCategoryTrackingInfo(AnalyticsConstants.VALUES.PAGE_CATEGORIES.JIRA);
                } else if (Analytics.stringContains(window.location.href, '/issues/')) {
                    this.addPageTrackingInfo(AnalyticsConstants.VALUES.PAGES.JIRA_PROJECT_ISSUES);
                    this.addPageCategoryTrackingInfo(AnalyticsConstants.VALUES.PAGE_CATEGORIES.JIRA);
                }
            } else if (Analytics.stringContains(window.location.href, '/queues/')) {
                this.addPageTrackingInfo(AnalyticsConstants.VALUES.PAGES.JIRA_SERVICE_QUEUES);
                this.addPageCategoryTrackingInfo(AnalyticsConstants.VALUES.PAGE_CATEGORIES.JIRA);
            } else if (Analytics.stringContains(window.location.href, '/browse/')) {
                this.addPageTrackingInfo(AnalyticsConstants.VALUES.PAGES.JIRA_ISSUE_SEARCH_OR_VIEW);
                this.addPageCategoryTrackingInfo(AnalyticsConstants.VALUES.PAGE_CATEGORIES.JIRA);
            } else if (Analytics.stringContains(window.location.href, '/issues/')) {
                this.addPageTrackingInfo(AnalyticsConstants.VALUES.PAGES.JIRA_ISSUE_SEARCH);
                this.addPageCategoryTrackingInfo(AnalyticsConstants.VALUES.PAGE_CATEGORIES.JIRA);
                this.addViewTrackingInfo(AnalyticsConstants.VALUES.VIEWS.ISSUE_LIST);

                var planningDialogOpen = $('[name=planning]', $form).val() === 'true';
                var action = planningDialogOpen ? AnalyticsConstants.VALUES.ACTIONS.CLICK_PLAN_TIME_LINK : AnalyticsConstants.VALUES.ACTIONS.CLICK_LOG_WORK_LINK;
                this.addActionTrackingInfo(action);

            } else if (Analytics.stringContains(window.location.href, 'RapidBoard.jspa')) {
                this.addPageTrackingInfo(AnalyticsConstants.VALUES.PAGES.JIRA_AGILE_VIEW);
                this.addPageCategoryTrackingInfo(AnalyticsConstants.VALUES.PAGE_CATEGORIES.JIRA);
            } else if (Analytics.stringContains(window.location.href, 'Dashboard.jspa')) {
                this.addPageTrackingInfo(AnalyticsConstants.VALUES.PAGES.JIRA_DASHBOARD);
                this.addPageCategoryTrackingInfo(AnalyticsConstants.VALUES.PAGE_CATEGORIES.JIRA);
            }

            if (!this.ORIGIN.page) {
                this.addPageTrackingInfo(AnalyticsConstants.VALUES.UNKNOWN);
            }

            $form.find('input[name=' + AnalyticsConstants.FORM_FIELDS.ANALYTICS_ORIGIN_PAGE + ']').val(this.ORIGIN.page);
            $form.find('input[name=' + AnalyticsConstants.FORM_FIELDS.ANALYTICS_ORIGIN_VIEW + ']').val(this.ORIGIN.view);
            $form.find('input[name=' + AnalyticsConstants.FORM_FIELDS.ANALYTICS_ORIGIN_ACTION + ']').val(this.ORIGIN.action);
            $form.find('input[name=' + AnalyticsConstants.FORM_FIELDS.ANALYTICS_PAGE_CATEGORY + ']').val(this.ORIGIN.page_category);
        },

        addTrackingInfo: function (page, view, action, category) {
            this.ORIGIN.page = page || this.ORIGIN.page;
            this.ORIGIN.view = view || this.ORIGIN.view;
            this.ORIGIN.action = action || this.ORIGIN.action;
            this.ORIGIN.page_category = category || this.ORIGIN.page_category;
        },

        addPageTrackingInfo: function (page) {
            this.addTrackingInfo(page, null, null, null);
        },

        addViewTrackingInfo: function (view) {
            this.addTrackingInfo(null, view, null, null);
        },

        addActionTrackingInfo: function (action) {
            this.addTrackingInfo(null, null, action, null);
        },

        addPageCategoryTrackingInfo: function (category) {
            this.addTrackingInfo(null, null, null, category);
        },
        
        trackPageLoad: function (page) {
            const payload = {};
            payload[AnalyticsConstants.ANALYTICS_BEAN_FIELDS.EVENT] = page;
            payload[AnalyticsConstants.ANALYTICS_BEAN_FIELDS.TYPE] = AnalyticsConstants.EVENT_TYPES.SCREEN;
            this.trackEvent(payload);
        },

        trackEvent: function (request) {
            request.context = {
                locale: window.navigator.language,
                userAgent: window.navigator.userAgent
            };

            $.ajax({
                type: 'POST',
                url: contextPath() + '/rest/tempo-timesheets/3/analytics/track',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify(request)
            });
        }
    };

    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
        $(context).find("a#log-work-link").bind('click', function (event) {
            // Log work by clicking JIRA log work (plus-button)
            Analytics.addViewTrackingInfo(AnalyticsConstants.VALUES.VIEWS.TIMETRACKING_PANE);
            Analytics.addActionTrackingInfo(AnalyticsConstants.VALUES.ACTIONS.CLICK_PLUS_BUTTON);
        });
        $(context).find("#plan-time-on-issue-btn").bind('click', function (event) {
            // Log work by clicking JIRA plan time (plus-button)
            Analytics.addViewTrackingInfo(AnalyticsConstants.VALUES.VIEWS.COLLABORATORS_PANE);
            Analytics.addActionTrackingInfo(AnalyticsConstants.VALUES.ACTIONS.CLICK_PLUS_BUTTON);
        });
        addTrackingEventsToElements();
    });

    function addTrackingEventsToElements() {
        $('.issueaction-tempo-add-hours-on-issue#add-hours-on-issue').off().on('click', function () {
            // Log work by clicking link in issue operations drop-down
            Analytics.addViewTrackingInfo(AnalyticsConstants.VALUES.VIEWS.ISSUE_OPERATIONS);
            Analytics.addActionTrackingInfo(AnalyticsConstants.VALUES.ACTIONS.CLICK_LOG_WORK_LINK);
        });

        $('.issueaction-tempo-add-hours-on-issue.issueaction-tempo-log-work').off().on('click', function () {
            // Log work by clicking link in issue operations drop-down
            Analytics.addViewTrackingInfo(AnalyticsConstants.VALUES.VIEWS.ISSUE_OPERATIONS);
            Analytics.addActionTrackingInfo(AnalyticsConstants.VALUES.ACTIONS.CLICK_LOG_WORK_LINK);
        });

        $('.issueaction-tempo-plan-time#plan-time-on-issue').off().on('click', function () {
            // Plan time by clicking link in issue operations drop-down
            Analytics.addViewTrackingInfo(AnalyticsConstants.VALUES.VIEWS.ISSUE_OPERATIONS);
            Analytics.addActionTrackingInfo(AnalyticsConstants.VALUES.ACTIONS.CLICK_PLAN_TIME_LINK);
        });

        $('a.issueaction-tempo-add-hours-on-issue#issue-view-tempo-panel-log-work').off().on('click', function (e, triggeredBySelf) {
            if (triggeredBySelf !== false) { // This check needs to be in since the log-work-link triggers this event to get a log work dialog
                // Log work by clicking log-work on Tempo Issue Panel
                Analytics.addActionTrackingInfo(AnalyticsConstants.VALUES.ACTIONS.CLICK_LOG_WORK_BUTTON);
                Analytics.addViewTrackingInfo(AnalyticsConstants.VALUES.VIEWS.TEMPO_ISSUE_PANEL);
            }
        });
    }

    window.tempo = window.tempo || {};
    window.tempo.ANALYTICS = Analytics;
    return Analytics;

});

}catch(e){WRMCB(e)};