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-bar', location = 'com/tempoplugin/js/tempo.worklog.v2.js' */
define('tempo/global-worklog-dialog', [
    'jquery',
    'underscore',
    'tempo/context-path',
    'tempo/ajs-meta',
    'tempo/jira-events',
    'tempo/analytics'
], function ($, _, contextPath, Meta, Events, Analytics) {

    function trackLogWorkWithShortcut() {
        // Log work by using shortcut
        Analytics.addActionTrackingInfo(Analytics.Constants.VALUES.ACTIONS.KEYBOARD_SHORTCUT);
    }

    function shortcutOpenDialog() {
        if ($('#worklogForm')[0]) {
            // do nothing if worklog form already exists in the dom
            return;
        }
        var timesheetLink = $('#timesheet-mlink'); // Timesheets is enabled and user has Tempo Time Tracking permission
        if (timesheetLink.length > 0) {
            var issueKey = jira.app.issue.getIssueKey();
            if (issueKey) {
                // We have an issue
                $.get(contextPath() + '/rest/api/2/mypermissions/?issueKey=' + issueKey, function (response) {
                    if (response.permissions.WORK_ON_ISSUES.havePermission) {
                        triggerWorklogDialog({originTaskId: issueKey});
                        trackLogWorkWithShortcut();
                    }
                });
            } else {
                triggerWorklogDialog();
                trackLogWorkWithShortcut();
            }
        }
    }

    function isTempoAppPage() {
        var appWrappers = ['#tempo-issue-app'];
        var arrayLength = appWrappers.length;
        for (var i = 0; i < arrayLength; i++) {
            if ($(appWrappers[i]).length > 0) {
                return true;
            }
        }
        return false;
    }

    function triggerGlobalWorklogDialog(data) {
        var tempoDialogDiv = document.getElementById('tempo-global-dialog-holder');
        if (!tempoDialogDiv) {
            tempoDialogDiv = document.createElement('div');
            $(tempoDialogDiv).attr('id', 'tempo-global-dialog-holder')
                .css({
                    'left': '0',
                    'height': '100%',
                    'width': '100%',
                    'position': 'absolute',
                    'top': '0',
                    'background': 'transparent',
                    'z-index': 9000
                });
            document.body.appendChild(tempoDialogDiv);
        }
        var wlDialog = $(tempoDialogDiv).tempoFrame({
            loadUrl: contextPath() + '/secure/GlobalWorklogDialog.jspa?decorator=none',
            onContentLoaded: function ($container) {
                $container.hideSpinner();
            },
            onStart: function ($container) {
                $('html').css({'overflow': 'hidden'});
                $container.css({top: window.pageYOffset});
                $container.showSpinner();
            },
            onClose: function () {
                $('html').css({'overflow': 'auto'});
            },
            initialData: data
        });
        window.document.addEventListener('tempo-worklog-created', function () {
            AJS.trigger('worklogsChanged');
        }, false);
        window.document.addEventListener('tempo-worklog-dialog-opened', function () {
            AJS.trigger('logWorkOpened');
        }, false);
        window.document.addEventListener('tempo-open-worklog-dialog-close', function () {
            wlDialog.close();
        }, false);
    }

    /*
    * PM-158: New issue view and update TUI worklog form for p2
    * The event is binded at src/io/frontend/js/utils/connect-utilities.p2.js#registerOpenWorklogDialog
    */
    function triggerWorklogDialog(customData) {
        var data = customData || {};
        if (isTempoAppPage()) {
            AJS.trigger('tempo-open-worklog-dialog-bundled', data);
        } else {
            triggerGlobalWorklogDialog(data);
        }
    }

    return {
        shortcutOpenDialog: shortcutOpenDialog,
        triggerWorklogDialog: triggerWorklogDialog,
        triggerGlobalWorklogDialog: triggerGlobalWorklogDialog
    }
});

}catch(e){WRMCB(e)};
;
try {
/* module-key = 'is.origo.jira.tempo-plugin:tempo-bar', location = 'com/tempoplugin/js/tempo.bar.js' */
require([
    'jquery', 'tempo/context-path', 'tempo/analytics', 'tempo/global-worklog-dialog',
], function ($, contextPath, Analytics, GlobalWorklogDialog) {
    window.tempo = window.tempo || {};

    var loggedInUser = function () {
        if (AJS.params.loggedInUser !== "") {
            return AJS.params.loggedInUser;
        } else if (AJS.Meta.get('tempo-user-key') !== "" || AJS.Meta.get('tempo-user-key') !== undefined) {
            return AJS.Meta.get('tempo-user-key');
        }
        return null;
    };

    var ISSUE_TEMPLATE = '<span class="issue"><span class="image"><a><img width="16" height="16" border="0" align="absmiddle"></a></span><span class="key"><a></a></span><span id="issue-tracker-summary-id" class="summary"><a></a></span></span>',
        ISSUE_REST_PATH = contextPath() + '/rest/api/2/issue/',
        SECOND = 1000,
        instance = null,
        timer = null,
        ISTRACKING = "Tempo.TRACKER_ISTRACKING_",
        PREV_DURATION = "Tempo.TRACKER_PREV_DURATION_",
        CYCLESTART = "Tempo.TRACKER_CYCLE_START_",
        INITIALSTART = "Tempo.TRACKER_INITIAL_START_",
        ISSUEID = "Tempo.TRACKER_ISSUE_ID_",
        PAUSED = "Tempo.TRACKER_PAUSED_",
        PAUSE_COUNT = "Tempo.PAUSE_COUNT_",
        SHOW_TRACKER = "Tempo.SHOW_TRACKER_",
        EXPAND_TRACKER = "Tempo.EXPAND_TRACKER_",
        ISFETCHINGISSUE = "Tempo.IS_FETCHING_ISSUE_",
        issueData;

    function cookieRead(key) {
        return  AJS.Cookie.read(key + loggedInUser());
    }

    function cookieSave(key, value) {
        return  AJS.Cookie.save(key + loggedInUser(), value);
    }

    function cookieErase(key) {
        return  AJS.Cookie.erase(key + loggedInUser());
    }

    function isTracking() {
        // check if start is set and start is valid
        return cookieRead(ISTRACKING) === "true" && Number(cookieRead(CYCLESTART)) > 0;
    }

    function isPaused() {
        return (cookieRead(PAUSED) === "true");
    }

    function showTracking() {
        return (cookieRead(SHOW_TRACKER) === "true");
    }

    function trackerExpanded() {
        return (cookieRead(EXPAND_TRACKER) === "true");
    }

    function getCurrentDuration() {
        return Number(cookieRead(PREV_DURATION)) + (new Date().getTime() - new Date(Number(cookieRead(CYCLESTART))).getTime()) / 1000;
    }

    function getDurationString(timeSpent, withSeconds) {
        if (timeSpent === null || timeSpent === undefined || timeSpent <= 0) {
            return "0m";
        }
        var minutes, durationString;
        var timeSpentSeconds = Math.round(timeSpent),
            seconds = timeSpentSeconds % 60,
            hours = Math.floor(timeSpentSeconds / 3600);

        if (withSeconds) {
            minutes = Math.floor(timeSpentSeconds / 60) % 60;
        } else {
            minutes = Math.round(timeSpentSeconds / 60) % 60;
            if (minutes === 0) {
                hours = Math.round(timeSpentSeconds / 3600);
            }
        }

        durationString = "";
        if (hours > 0) {
            durationString = durationString + hours + "h";
        }
        if (minutes >= 0) {
            if (hours > 0) {
                durationString = durationString + " ";
            }
            durationString = durationString + minutes + "m";
        }
        if (withSeconds && seconds) {
            durationString = durationString + " " + seconds + "s";
        }
        return durationString.toString();
    }

    function getTimeSpent() {
        if (isPaused()) {
            var prevDuration = Number(cookieRead(PREV_DURATION));
            if (prevDuration === null || prevDuration === undefined) {
                prevDuration = 0;
            }
            return prevDuration;
        }
        return getCurrentDuration();
    }

    function getPauseCount() {
        if (cookieRead(PAUSE_COUNT) === undefined) {
            return 0;
        } else {
            return cookieRead(PAUSE_COUNT);
        }
    }

    function update() {
        if (showTracking() && !AJS.params.printable) {
            var clock = instance.find('span.clock'),
                issueId = cookieRead(ISSUEID),
                fetchingIssue = cookieRead(ISFETCHINGISSUE);

            clock.show().text(getDurationString(getTimeSpent(), true));
            if (issueId && !issueData && (!fetchingIssue || fetchingIssue === "false")) {
                getIssueData(issueId);
            } else if (issueId && issueData && fetchingIssue === "false") {
                var issue = instance.find('span.issue'),
                    img = issue.find('img');

                img.attr('src', issueData.iconUrl);
                issue.find('span a').attr('href', issueData.href);
                issue.find('span.key a').text(issueData.key).attr('data-id', issueData.id);
                issue.find('span.summary a').text(issueData.summary);
                issue.find('span.summary a').attr('title', issueData.summary);
                issue.show();
            }
            instance.show();
        }
        if (isTracking() && !isPaused()) {
            clearTimeout(timer);
            timer = setTimeout(function () {
                update();
            }, SECOND);
        }
    }

    function getIssueData(issueId) {
        var url = ISSUE_REST_PATH + issueId + '?fields=issuetype,summary';
        cookieSave(ISFETCHINGISSUE, "true");
        $.get(url, function (issueObject) {
            issueData = {
                id: issueObject.id,
                key: issueObject.key,
                iconUrl: issueObject.fields.issuetype.iconUrl,
                href: contextPath() + '/browse/' + issueObject.key,
                summary: issueObject.fields.summary
            };
            cookieSave(ISFETCHINGISSUE, "false");
            update();
        });
    }

    function createButton(title) {
        var button = $('<a>', {
            "href": "#",
            "class": "tracker-button button aui-button aui-button-subtle",
            text: "",
            title: title
        });
        button.prepend('<span class="tempo-tracker-label"></span>');
        button.prepend('<span class="icon"></span>');
        return button;
    }

    function removeDropdownMenu() {
        $(document).click();
    }

    function saveIssueTracker(issueId) {
        if (issueId != undefined) {
            cookieSave(ISSUEID, issueId);
            getIssueData(issueId);
        }
    }

    function startTracker() {
        const bar = $('#tempo-bar');
        if (!bar.length) {
            init();
        } else {
            positionTrackersOnPage(bar);
        }
        cookieSave(SHOW_TRACKER, "true");
        $('#tempo-tracker-slider-id').removeClass('tempo-tracker-slider aui-button aui-button-subtle');
        update();
        removeDropdownMenu();
    }

    function eraseCookies() {
        cookieErase(SHOW_TRACKER);
        cookieErase(EXPAND_TRACKER);
        cookieErase(ISTRACKING);
        cookieErase(INITIALSTART);
        cookieErase(CYCLESTART);
        cookieErase(PREV_DURATION);
        cookieErase(ISSUEID);
        cookieErase(PAUSED);
        cookieErase(PAUSE_COUNT);
        cookieErase(ISFETCHINGISSUE);
    }

    function clearTracker() {
        sendAnalytics(Analytics.Constants.EVENTS.DELETED_TRACKER);
        eraseCookies();
    }

    function removeTracker() {
        $("#tempo-tracker-slider-id").die();
        $("#tempo-bar").remove();
        clearTracker();
    }

    function resetTracker() {
        $("#tempo-tracker-slider-id").die();
        $("#tempo-bar").remove();
        eraseCookies();
    }

    function toggleExpand() {
        if (trackerExpanded()) {
            $('#tempo-bar').removeClass('tempo-bar-expanded');
            $('#tempo-tracker-slider-id').removeClass('tracker-expanded');
            $('#issue-tracker-summary-id').addClass('hidden-actions');
            $('.tracker-button span.tempo-tracker-label').text("");
            cookieSave(EXPAND_TRACKER, "false");
        } else {
            $('#tempo-bar').addClass('tempo-bar-expanded');
            $('#tempo-tracker-slider-id').addClass('tracker-expanded');
            $('#issue-tracker-summary-id').removeClass('hidden-actions');
            $('.play span.tempo-tracker-label').text("\u041d\u0430\u0447\u0430\u043b\u043e");
            $('.pause span.tempo-tracker-label').text("\u041f\u0430\u0443\u0437\u0430");
            $('.stop span.tempo-tracker-label').text("\u041e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c");
            cookieSave(EXPAND_TRACKER, "true");
        }
    }

    function isIssueSelected() {
        var issueId = cookieRead(ISSUEID);
        return issueId !== undefined && issueId !== null && issueId !== "";
    }

    function sendAnalytics(event) {
        var properties = {};
        properties[Analytics.Constants.KEYS.PRESELECTED_ISSUE] = isIssueSelected();
        var payload = {
            event: event,
            properties: properties
        };
        Analytics.trackEvent(payload);
    }

    function positionTrackersOnPage(bar) {
        var myWorkSidebar = $('#tempoIssuesSidePanel');
        if (myWorkSidebar.length) {
            bar.css('right', myWorkSidebar.outerWidth());
        }
    }

    function attachIssueToTrackerIfEmpty() {
        if (AJS.Cookie.read(ISSUEID + loggedInUser()) === undefined) {
            var issueId = jira.app.issue.getIssueId();
            if (issueId !== undefined && issueId !== null) {
                saveIssueTracker(issueId);
            }
        }
    }

    function init() {
        if (loggedInUser() === null) {
            return;
        }

        var clock, closeButton, issue;
        var bar = $('<div>').attr('id', "tempo-bar"),
            sliderButton = $('<div>').attr('id', "tempo-tracker-slider-id"),
            tempoLogo = $('<a>').attr('title', "\u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u0442\u0430\u0431\u0435\u043b\u0435\u0439 \u0443\u0447\u0435\u0442\u0430 \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0443\u0440\u043d\u0430\u043b\u0430")
                .attr('href', contextPath() + "/secure/Tempo.jspa#/my-work/timesheet")
                .addClass("tempo-bar-logo")
                .text("TEMPO");

        var container = $('<div>').addClass('tempo-bar-container');
        bar.append(container);
        container.append(sliderButton).append(tempoLogo);
        bar.hide();

        if (isTracking() || isPaused()) {
            $(bar).find('#tempo-bar').addClass('tempo-bar-expanded tracker-not-started');
            $(bar).find('#tempo-tracker-slider-id').addClass('tempo-tracker-slider aui-button aui-button-subtle');
            if (trackerExpanded()) {
                $(bar).find('#tempo-tracker-slider-id').addClass('tracker-expanded');
            }
        }

        clock = $('<span id="tempo-tracker-clock-id" class="clock"></span>');
        if (!isTracking() && !trackerExpanded()) {
            clock.addClass('hide-clock');
        }
        clock.appendTo(container);
        $('#tempo-tracker-slider-id').live("click", function () {
            toggleExpand();
        });

        closeButton = $('<a>', {
            id: "tempo-bar-close",
            href: contextPath() + "/secure/TempoTrackerConfirmation!default.jspa?returnUrl=" + document.URL,
            "class": "tempoaction-open-dialog-form aui-button aui-button-subtle",
            text: "\u0417\u0430\u043a\u0440\u044b\u0442\u044c \u0441\u0447\u0435\u0442\u0447\u0438\u043a",
            title: "\u0417\u0430\u043a\u0440\u044b\u0442\u044c \u0441\u0447\u0435\u0442\u0447\u0438\u043a"
        });

        closeButton.on("click", function () {
            if (!isTracking()) {
                clearTracker();
                bar.hide();
                return false;
            }
            return true;
        });


        var actionButtons = $('<ul id="tempo-tracker-actions" class="action-buttons ops aui-buttons"></ul>'),
            playButton = createButton("\u0421\u0442\u0430\u0440\u0442 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430"),
            pauseButton = createButton("\u041f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0447\u0435\u0442\u0447\u0438\u043a"),
            stopButton = createButton("\u0421\u0442\u043e\u043f \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430");

        playButton.addClass("play first last");
        actionButtons.append(playButton);

        pauseButton.addClass("pause first");
        actionButtons.append(pauseButton);

        stopButton.addClass("stop issueaction-tempo-add-hours-on-issue last");
        actionButtons.append(stopButton);

        playButton.on("click", function (e) {
            cookieSave(SHOW_TRACKER, 'true'); // Fix bad state.
            attachIssueToTrackerIfEmpty();
            if (!isTracking()) {
                cookieSave(ISTRACKING, "true");
                cookieSave(INITIALSTART, new Date().getTime());
                cookieSave(CYCLESTART, new Date().getTime());
                cookieSave(PREV_DURATION, "0");
                cookieSave(PAUSE_COUNT, "0");
                $('#tempo-tracker-clock-id').removeClass('hide-clock');
                $('#tempo-tracker-slider-id').addClass('tempo-tracker-slider aui-button aui-button-subtle');
                update();
            } else {
                // returning from paused state, create new cycle and erase pause cookie
                cookieSave(CYCLESTART, new Date().getTime());
                cookieErase(PAUSED);
                update();
            }
            $('.play span.tempo-tracker-label').text("");
            pauseButton.show();
            playButton.hide();
            stopButton.show();
            e.preventDefault();
            sendAnalytics(Analytics.Constants.EVENTS.STARTED_TRACKER);
        });

        function resetButtonsToStartState() {
            pauseButton.hide();
            playButton.removeClass("last").show();
        }

        pauseButton.on("click", function (e) {
            resetButtonsToStartState();
            if (isTracking()) {
                cookieSave(PREV_DURATION, getCurrentDuration());
                cookieSave(PAUSED, "true");
                cookieSave(PAUSE_COUNT, String(Number(getPauseCount()) + 1));
            }
            e.preventDefault();
            sendAnalytics(Analytics.Constants.EVENTS.PAUSED_TRACKER);
        });

        stopButton.on("click", function (event) {
            if (isTracking()) {
                event.stopPropagation();
                event.preventDefault();
                // round to the nearest minute to avoid rounding off by 1 in the worklog form.
                var timeSpentSeconds = (getTimeSpent() / 60).toFixed(0) * 60;
                var startedDate = moment(new Date(Number(cookieRead(INITIALSTART)))).format('YYYY-MM-DDTHH:mm:ss.SSS');
                var customData = {
                    originTaskId: issueData ? issueData.key : "",
                    worklog: {
                        timeSpentSeconds: timeSpentSeconds,
                        originTaskId: issueData ? issueData.key : "",
                        started: startedDate,
                    },
                    fromTracker: true,
                };
                GlobalWorklogDialog.triggerGlobalWorklogDialog(customData);
                Analytics.addActionTrackingInfo(Analytics.Constants.VALUES.ACTIONS.CONVERTED_TRACKER);
            }
            return false;
        });
        actionButtons.appendTo(container);

        issue = $(ISSUE_TEMPLATE).hide();
        issue.appendTo(container);
        closeButton.appendTo(container);

        bar.appendTo('body');
        if (!trackerExpanded()) {
            $('#issue-tracker-summary-id').addClass('hidden-actions');
        }

        var TOPMENU_TRACKER_BUTTON = '#tempo-bar-mlink';
        $(TOPMENU_TRACKER_BUTTON).on('click', function () {
            startTracker();
            sendAnalytics(Analytics.Constants.EVENTS.DISPLAYED_TRACKER);
            return false;
        });

        var ISSUE_MORE_BUTTON = '#tempo-issue-tracker-start-mlink';
        $(ISSUE_MORE_BUTTON).on('click', function () {
            saveIssueTracker(jira.app.issue.getIssueId());
            startTracker();
            sendAnalytics(Analytics.Constants.EVENTS.DISPLAYED_TRACKER);
            playButton.trigger('click');
            return false;
        });

        var ISSUE_OVERFLOW_BUTTON = '.tempo-bar-start';
        $(ISSUE_OVERFLOW_BUTTON).live('click', function () {
            saveIssueTracker($(this).attr('data-issueid') || jira.app.issue.getIssueId());
            startTracker();
            sendAnalytics(Analytics.Constants.EVENTS.DISPLAYED_TRACKER);
            playButton.trigger('click');
            return false;
        });
        instance = bar;

        if (isTracking() && !isPaused()) {
            pauseButton.show();
            playButton.hide();
        } else {
            pauseButton.hide();
            playButton.removeClass("last").show();
        }
        if (!isTracking()) {
            $('.play span.tempo-tracker-label').text("\u041d\u0430\u0447\u0430\u043b\u043e");
            stopButton.hide();
            playButton.addClass("last");
        }
        update();
        positionTrackersOnPage(bar);
        var reInitializeTracker = function () {
            resetTracker();
            startTracker();
        };

        window.document.addEventListener('tempo-reset-tracker', function() {
            reInitializeTracker();
        }, false);
    }

    var tempoTracker = { init: init, clearTracker: clearTracker, stopTracker: eraseCookies, removeTracker: removeTracker };
    window.tempo.tempobar = tempoTracker;

    $(function () {
        // TMA-5733 - We were asked by Atlassian to defer this to save 7ms of loading time.
        setTimeout(tempoTracker.init, 0);
    });

    return tempoTracker;
});

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