Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Page Tree
expandCollapseAlltrue
root@self
searchBoxtrue

Check if Tempo Account is filled in the issue

Work attributes

Image Removed

Script

Code Block
languagejs
collapsetrue
var ACCOUNT_CUSTOM_FIELD_NAME = "com.tempoplugin.tempo-accounts:accounts.customfield";

function extractCustomFieldId(fieldData, customfieldName) {
    var fields = AJS.$.grep(fieldData, function (field) {
        return (field.custom && field.schema.custom === customfieldName);
    });
    return fields[0].id;
}

function getIssueKey() {
    'use strict';

    function isNullOrEmpty(value) {
        return value === undefined || typeof(value) === 'undefined' || value === null || value === '';
    }

    var funs = [
        function() {
            return AJS.$('#tempo-report-issue').val();
        },
        function() {
            return AJS.$('#tempo-issue-picker-popup').val();
        },
        function() {
            return AJS.$('.tempoIssueKey').val();
        },
        function() {
            return AJS.$('.dialog-panel-body:not(:hidden) [id^="tempo-issue-picker"]').val();
        },
        function() {
            return AJS.$('.dialog-panel-body:not(:hidden) [id^="tempo-issue-picker"] option[selected="selected"]').val();
        },
        function() {
            return AJS.$("select[name='issueKey']").val();
        },
        function() {
            try {
                return JIRA.Issue.getIssueKey();
            } catch(error) {
                console.debug("Could not call JIRA.Issue.getIssueKey, we're probably not in the context of an issue.");
            }
        }
    ]

    for (var i = 0; i < funs.length; i++) {
        var issueKey = funs[i]();

        if(!isNullOrEmpty(issueKey))
            return issueKey;
    }
}


function performBillingKeyCheck() {
    hideWorkLogBillingKeyField()
    var issueKey = getIssueKey();
    var baseUrl = AJS.params.baseURL;
    var url = baseUrl + "/rest/api/2/field";

    AJS.$.getJSON(url, function (data) {
        accountCustomFieldId = extractCustomFieldId(data, ACCOUNT_CUSTOM_FIELD_NAME);
        url = baseUrl + "/rest/api/2/issue/" + issueKey;
        AJS.$.getJSON(url, function (data) {
            account = data.fields[accountCustomFieldId];
            validAccount = (account !== undefined && account !== null);
            AJS.$("[name='_BillingKey_']").prop('checked', validAccount);
            AJS.$("#issue-add-button").removeAttr("disabled")
        });
    });
}

AJS.$(document).ready(function () {
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context, reason) {
        if (reason === JIRA.CONTENT_ADDED_REASON.dialogReady) {

            //log another resets all elements with class resetable
            AJS.$(".field-group.custom_checkboxes.resetable").removeClass("resetable");

            AJS.$("#issue-add-button").attr("disabled", true)

            performBillingKeyCheck();

            AJS.$('[id^="tempo-issue-picker"]:not([id$="-field"])').change(performBillingKeyCheck);
        }
    });

    AJS.$('[id^="tempo-issue-picker"][id$="-field"]').live('blur', performBillingKeyCheck)
});

function hideWorkLogBillingKeyField() {
    AJS.$("#popup_BillingKey_").parent().hide();
    AJS.$("[name='_BillingKey_']").parent().hide();
}

setTimeout(hideWorkLogBillingKeyField, 50);

Demo

Image Removed

Dependent drop downs

This script will enable you to imitate the dependent dynamic dropdowns as were known in Tempo 8.1 and earlier.

Given three static lists in the Tempo Worklog Attributes:

  • Main (required)
  • Sub1 (optional)
  • Sub2 (optional)

The Sub1 list will only be displayed when the value 'One' is selected in the Main list, Sub2 list only when the value is 'Two'.

Script

Code Block
languagejs
collapsetrue
var tempoList = '.tempoStaticList';
var mainList = 'popup_Main_';
var subListOne = 'popup_Sub1_';
var subListTwo = 'popup_Sub2_';
var selectedOptionForSubListOne = 'One';
var selectedOptionForSubListTwo = 'Two';

AJS.$(document).ready(function() {
  AJS.$('#time-popup').live('focus', function() {
    AJS.$('.tempoStaticList').each( function(index, item) {
      if (AJS.$(item).attr('id') != mainList) {
         AJS.$(this).parent().hide();
      }
    });
  AJS.$(tempoList + '[id$="' + mainList + '"').live('change', function() {
    if (AJS.$(this).val() == selectedOptionForSubListOne) {
      AJS.$('.tempoStaticList').each( function(index, item) {
        if (AJS.$(item).attr('id') == mainList || AJS.$(item).attr('id') == subListOne) {
	      AJS.$(item).parent().show();
        } else {
          AJS.$(item).parent().hide();
        }
      });
    } else if (AJS.$(this).val() == selectedOptionForSubListTwo) {
      AJS.$('.tempoStaticList').each( function(index, item) {
        if (AJS.$(item).attr('id') == mainList || AJS.$(item).attr('id') == subListTwo) {
	      AJS.$(item).parent().show();
        } else {
          AJS.$(item).parent().hide();
        }
      });
    } else {
      AJS.$('.tempoStaticList').each( function(index, item) {
        if (AJS.$(item).attr('id') == mainList) {
	      AJS.$(item).parent().show();
        } else {
          AJS.$(item).parent().hide();
        }
      });
    }
  });
  });
});

Demo

Image Removed

Child pages (Children Display)
alltrue