Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Blue Ant plugin custom fields functionalities on fields:
- * Assign to Blue Ant, Blue Ant projects, Blue Ant activities.
- * Mainly used at on create/edit Issue, Assign to BA Bulk Operation.
- */
- AJS.$(function() {
- "use strict";
- var url = AJS.contextPath() + "/plugins/servlet/blueant/fields";
- var bulkEditInterval;
- var bulkDetailsOperation = "BulkAssignBADetails";
- AJS.$(window).load(function() {
- if (AJS.$("#BulkAssignBAAction").length || AJS.$("#bulkedit_confirmation").length || AJS.$("#bulkedit").length) {
- onStartup();
- }
- });
- /**
- * Enable assign functionality on create/edit issue.
- */
- function onStartup() {
- var bulkEditCheck = true; //on bulk action listener.
- getCustomFields(function(customFieldsMap) {
- delete customFieldsMap["epicLink"]; //at bulk action it's need only BA custom fields, epic link must be removed.
- if(AJS.$("#BulkAssignBAAction").length) { //check if Bulk Assign to Blue Ant action else it's Bulk Edit.
- removeUnusedFields(customFieldsMap);
- } else {
- removeUnusedFields(customFieldsMap, true)// Remove from Bulk Edit action all assign to BA custom fields.
- }
- bulkEditInterval = setInterval(function() {
- if (AJS.$("#bulkedit #availableActionsTable").length && bulkEditCheck && AJS.$("#BulkAssignBAAction").length) { //on open bulk edit page
- bulkEditCheck = false;
- removeNoneAssingBAFields(customFieldsMap);
- onBulkEditStartup(customFieldsMap);
- AJS.$("#projectBAForIssue, #activityBAForIssue").parent().show();
- AJS.$("#cb" + customFieldsMap["project"]).prop("checked", true).trigger("change");
- var projectRow = AJS.$("#projectBAForIssue").parent().parent();
- projectRow.insertBefore(projectRow.prev()); //move project row before activity, because there is alphabetic order.
- addAssignWarning("#bulkedit");
- } else if (AJS.$("#bulkedit_confirmation").length && bulkEditCheck && AJS.$("." + customFieldsMap["project"]).length) {
- bulkEditCheck = false;
- confirmationPageHooks(customFieldsMap);
- addAssignWarning("#bulkedit_confirmation");
- } else if (!AJS.$("#bulkedit").length && !AJS.$("#bulkedit_confirmation").length && !bulkEditCheck) { //on close bulk edit page
- bulkEditCheck = true;
- logout(url);
- }
- console.log("OnProjectChangeFunction");
- onProjectChangeBulkEdit();
- onActivityChangeBulkEdit();
- }, 1000);
- });
- }
- function onProjectChangeBulkEdit() {
- var prevVal;
- var activityPrevVal;
- AJS.$("#projectBAForIssue").on('focusin', function(){
- if (prevVal == undefined || prevVal == null || prevVal =='') {
- console.log("Inside");
- prevVal = AJS.$(this).val();
- console.log("previous value of Project: " + prevVal);
- activityPrevVal = AJS.$("#activityBAForIssue").val();
- AJS.$("#projectBAForIssue").on('change', function() {
- console.log("Changing");
- if(prevVal != undefined || prevVal != '') {
- addAssignWarningBulkEdit("#projectBAForIssue", prevVal, "#activityBAForIssue", activityPrevVal);
- }
- });
- }
- });
- }
- /**
- * alert User if changed Activity issueType==epic while editing
- */
- function onActivityChangeBulkEdit() {
- var prevVal;
- AJS.$("#activityBAForIssue").on('focusin', function(){
- if (prevVal == undefined || prevVal == null || prevVal =='-') {
- prevVal = AJS.$(this).val();
- console.log("previous value of Activity: " + prevVal);
- AJS.$("#activityBAForIssue").on('change', function() {
- if(prevVal != undefined || prevVal != '' || prevVal != '-') {
- addAssignWarningBulkEdit("#activityBAForIssue", prevVal);
- }
- });
- }
- });
- }
- /**
- * Add Blue Ant assign warning that will be edited only Epic and main issues, not any sub-issues.
- */
- function addAssignWarningBulkEdit(containerId, prevVal, activityId, activityPrevVal) {
- console.log("AddingAssignMessage");
- //if( (AJS.$("#bulkAssignMessage").length<1) || !(AJS.$("#bulkAssignMessage").is(":visible")) ){
- AJS.$(containerId).parent().prepend(AJS.$("<div>").attr("id", "bulkAssignMessage").attr("class", "style-for-message"));
- var content = AJS.I18n.getText("blueant.worktime.customfield.save.project.change.on.issutype.epic")+'<br>'+
- '<a id="assignWarningYes">'+AJS.I18n.getText("blueant.worktime.customfield.save.project.change.on.issutype.epic.yes")+
- '</a> <a id="assignWarningNo">'+AJS.I18n.getText("blueant.worktime.customfield.save.project.change.on.issutype.epic.no")+'</a>';
- displayMessage("warning", content, "bulkAssignMessage");
- AJS.$("#assignWarningYes").on('click', function(){
- AJS.$("#bulkAssignMessage").remove();
- });
- AJS.$("#assignWarningNo").on('click', function(){
- AJS.$(containerId).val(prevVal);
- AJS.$(containerId).parent().find('input').val(prevVal);
- if (activityId != undefined) {
- activitiesGet(function() {
- AJS.$(activityId).val(activityPrevVal);
- AJS.$(activityId).parent().find('input').val(activityPrevVal);
- });
- }
- AJS.$("#bulkAssignMessage").remove();
- });
- //}
- AJS.$("#bulkAssignMessage div span").removeClass("aui-icon"); // Force user to decide
- }
- /**
- * Remove from Bulk Assign BA action all fields expose BA custom fields.
- */
- function removeNoneAssingBAFields(customFieldsMap) {
- var isCustomBAToRemove = false;
- AJS.$(".availableActionRowMultiSelect").remove(); //remove all Multi select - unused to assign BA.
- AJS.$("#unavailableActionsTable").remove(); //remove unavailable actions.
- removeUnusedFields(customFieldsMap, isCustomBAToRemove);
- }
- /**
- * Remove from Bulk Edit action all assign to BA custom fields.
- */
- function removeUnusedFields(customFieldsMap, isCustomBAToRemove) {
- AJS.$.each(AJS.$(".availableActionRow"), function(id, row) {
- var input = AJS.$(row).find("input");
- var isCustomBA = false;
- AJS.$.map(customFieldsMap, function(cfVal, key) {
- if (AJS.$(input).attr("id") == "cb" + cfVal) {
- isCustomBA = true;
- return;
- }
- });
- if(isCustomBA == isCustomBAToRemove) {
- AJS.$(input).parent().parent(".availableActionRow").remove();
- }
- });
- }
- /**
- * On bulk edit action enable to edit assign, project, activity and epic link fields together.
- */
- function onBulkEditStartup(customFieldsMap) {
- AJS.$.map(customFieldsMap, function(field, key) {
- AJS.$("#cb" + field).on("change", function() {
- var value = AJS.$(this).is(':checked');
- AJS.$.each(customFieldsMap, function(key, fieldToCheck) {
- AJS.$("#cb" + fieldToCheck).prop("checked", value);
- })
- });
- });
- }
- /**
- * Replace operation third step link to Assign bulk operation (default it is bulk edit).
- * Hide assign to Blue Ant fields row - not necessary for user because it's assign operation.
- */
- function confirmationPageHooks(customFieldsMap) {
- AJS.$(".steps li:nth-child(3) a").attr('href', bulkDetailsOperation + '.jspa');
- }
- /**
- * Add Blue Ant assign warning that will be edited only Epic and main issues, not any sub-issues.
- */
- function addAssignWarning(containerId) {
- AJS.$(containerId).prepend(AJS.$("<div>").attr("id", "bulkAssignMessage"));
- displayMessage("warning", AJS.I18n.getText("blueant.worktime.bulk.assign.what.edited.warning"), "bulkAssignMessage");
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement