Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Blue Ant plugin custom fields functionalities on fields:
  3.  * Assign to Blue Ant, Blue Ant projects, Blue Ant activities.
  4.  * Mainly used at on create/edit Issue, Assign to BA Bulk Operation.
  5.  */
  6. AJS.$(function() {
  7.     "use strict";
  8.  
  9.     var url = AJS.contextPath() + "/plugins/servlet/blueant/fields";
  10.     var bulkEditInterval;
  11.     var bulkDetailsOperation = "BulkAssignBADetails";
  12.    
  13.     AJS.$(window).load(function() {
  14.         if (AJS.$("#BulkAssignBAAction").length || AJS.$("#bulkedit_confirmation").length  || AJS.$("#bulkedit").length) {
  15.             onStartup();
  16.         }
  17.     });
  18.    
  19.     /**
  20.      * Enable assign functionality on create/edit issue.
  21.      */
  22.     function onStartup() {
  23.         var bulkEditCheck = true; //on bulk action listener.
  24.         getCustomFields(function(customFieldsMap) {
  25.             delete customFieldsMap["epicLink"]; //at bulk action it's need only BA custom fields, epic link must be removed.
  26.             if(AJS.$("#BulkAssignBAAction").length) { //check if Bulk Assign to Blue Ant action else it's Bulk Edit.
  27.                 removeUnusedFields(customFieldsMap);
  28.             } else {
  29.                 removeUnusedFields(customFieldsMap, true)// Remove from Bulk Edit action all assign to BA custom fields.
  30.             }
  31.            
  32.             bulkEditInterval = setInterval(function() {
  33.                 if (AJS.$("#bulkedit #availableActionsTable").length && bulkEditCheck && AJS.$("#BulkAssignBAAction").length) { //on open bulk edit page
  34.                     bulkEditCheck = false;
  35.                     removeNoneAssingBAFields(customFieldsMap);
  36.                     onBulkEditStartup(customFieldsMap);
  37.                     AJS.$("#projectBAForIssue, #activityBAForIssue").parent().show();
  38.                     AJS.$("#cb" + customFieldsMap["project"]).prop("checked", true).trigger("change");
  39.                     var projectRow = AJS.$("#projectBAForIssue").parent().parent();
  40.                     projectRow.insertBefore(projectRow.prev()); //move project row before activity, because there is alphabetic order.
  41.                     addAssignWarning("#bulkedit");
  42.                 } else if (AJS.$("#bulkedit_confirmation").length && bulkEditCheck && AJS.$("." + customFieldsMap["project"]).length) {
  43.                     bulkEditCheck = false;
  44.                     confirmationPageHooks(customFieldsMap);
  45.                     addAssignWarning("#bulkedit_confirmation");
  46.                 } else if (!AJS.$("#bulkedit").length && !AJS.$("#bulkedit_confirmation").length && !bulkEditCheck) { //on close bulk edit page
  47.                     bulkEditCheck = true;
  48.                     logout(url);
  49.                 }
  50.                 console.log("OnProjectChangeFunction");
  51.                 onProjectChangeBulkEdit();
  52.                 onActivityChangeBulkEdit();
  53.             }, 1000);
  54.         });
  55.     }
  56.     function onProjectChangeBulkEdit() {
  57.         var prevVal;
  58.         var activityPrevVal;
  59.         AJS.$("#projectBAForIssue").on('focusin', function(){
  60.             if (prevVal == undefined  || prevVal == null || prevVal =='') {
  61.                 console.log("Inside");
  62.                 prevVal = AJS.$(this).val();
  63.                 console.log("previous value of Project: " + prevVal);
  64.                 activityPrevVal = AJS.$("#activityBAForIssue").val();
  65.  
  66.                 AJS.$("#projectBAForIssue").on('change', function() {
  67.                     console.log("Changing");
  68.                     if(prevVal != undefined || prevVal != '') {
  69.                         addAssignWarningBulkEdit("#projectBAForIssue", prevVal, "#activityBAForIssue", activityPrevVal);
  70.                     }
  71.                 });
  72.             }
  73.         });
  74.     }
  75.  
  76.     /**
  77.      * alert User if changed Activity issueType==epic while editing
  78.      */
  79.     function onActivityChangeBulkEdit() {
  80.         var prevVal;
  81.         AJS.$("#activityBAForIssue").on('focusin', function(){
  82.  
  83.             if (prevVal == undefined  || prevVal == null || prevVal =='-') {
  84.                 prevVal = AJS.$(this).val();
  85.                 console.log("previous value of Activity: " + prevVal);
  86.                 AJS.$("#activityBAForIssue").on('change', function() {
  87.                     if(prevVal != undefined || prevVal != '' || prevVal != '-') {
  88.                         addAssignWarningBulkEdit("#activityBAForIssue", prevVal);
  89.                     }
  90.                 });
  91.             }
  92.         });
  93.     }
  94.  
  95.     /**
  96.      * Add Blue Ant assign warning that will be edited only Epic and main issues, not any sub-issues.
  97.      */
  98.     function addAssignWarningBulkEdit(containerId, prevVal, activityId, activityPrevVal) {
  99.         console.log("AddingAssignMessage");
  100.         //if( (AJS.$("#bulkAssignMessage").length<1) || !(AJS.$("#bulkAssignMessage").is(":visible")) ){
  101.             AJS.$(containerId).parent().prepend(AJS.$("<div>").attr("id", "bulkAssignMessage").attr("class", "style-for-message"));
  102.             var content = AJS.I18n.getText("blueant.worktime.customfield.save.project.change.on.issutype.epic")+'<br>'+
  103.                                             '<a id="assignWarningYes">'+AJS.I18n.getText("blueant.worktime.customfield.save.project.change.on.issutype.epic.yes")+
  104.                                             '</a> <a id="assignWarningNo">'+AJS.I18n.getText("blueant.worktime.customfield.save.project.change.on.issutype.epic.no")+'</a>';
  105.  
  106.             displayMessage("warning", content, "bulkAssignMessage");
  107.  
  108.             AJS.$("#assignWarningYes").on('click', function(){
  109.                 AJS.$("#bulkAssignMessage").remove();
  110.             });
  111.  
  112.             AJS.$("#assignWarningNo").on('click', function(){
  113.                 AJS.$(containerId).val(prevVal);
  114.                 AJS.$(containerId).parent().find('input').val(prevVal);
  115.  
  116.                 if (activityId != undefined) {
  117.                     activitiesGet(function() {
  118.                         AJS.$(activityId).val(activityPrevVal);
  119.                         AJS.$(activityId).parent().find('input').val(activityPrevVal);
  120.                     });
  121.                 }
  122.                 AJS.$("#bulkAssignMessage").remove();
  123.             });
  124.         //}
  125.         AJS.$("#bulkAssignMessage div span").removeClass("aui-icon"); // Force user to decide
  126.     }
  127.  
  128.     /**
  129.      * Remove from Bulk Assign BA action all fields expose BA custom fields.
  130.      */
  131.     function removeNoneAssingBAFields(customFieldsMap) {
  132.         var isCustomBAToRemove = false;
  133.         AJS.$(".availableActionRowMultiSelect").remove(); //remove all Multi select - unused to assign BA.
  134.         AJS.$("#unavailableActionsTable").remove(); //remove unavailable actions.
  135.         removeUnusedFields(customFieldsMap, isCustomBAToRemove);
  136.     }
  137.    
  138.     /**
  139.      * Remove from Bulk Edit action all assign to BA custom fields.
  140.      */
  141.     function removeUnusedFields(customFieldsMap, isCustomBAToRemove) {
  142.         AJS.$.each(AJS.$(".availableActionRow"), function(id, row) {
  143.             var input = AJS.$(row).find("input");
  144.             var isCustomBA = false;
  145.             AJS.$.map(customFieldsMap, function(cfVal, key) {
  146.                 if (AJS.$(input).attr("id") == "cb" + cfVal) {
  147.                     isCustomBA = true;
  148.                     return;
  149.                 }
  150.             });
  151.             if(isCustomBA == isCustomBAToRemove) {
  152.                 AJS.$(input).parent().parent(".availableActionRow").remove();
  153.             }
  154.         });
  155.     }
  156.    
  157.     /**
  158.      * On bulk edit action enable to edit assign, project, activity and epic link fields together.
  159.      */
  160.     function onBulkEditStartup(customFieldsMap) {
  161.         AJS.$.map(customFieldsMap, function(field, key) {
  162.             AJS.$("#cb" + field).on("change", function() {
  163.                 var value = AJS.$(this).is(':checked');
  164.                 AJS.$.each(customFieldsMap, function(key, fieldToCheck) {
  165.                     AJS.$("#cb" + fieldToCheck).prop("checked", value);
  166.                 }) 
  167.             });
  168.         });
  169.     }
  170.  
  171.     /**
  172.      * Replace operation third step link to Assign bulk operation (default it is bulk edit).
  173.      * Hide assign to Blue Ant fields row - not necessary for user because it's assign operation.
  174.      */
  175.     function confirmationPageHooks(customFieldsMap) {
  176.         AJS.$(".steps li:nth-child(3) a").attr('href', bulkDetailsOperation + '.jspa');
  177.     }
  178.    
  179.     /**
  180.      * Add Blue Ant assign warning that will be edited only Epic and main issues, not any sub-issues.
  181.      */
  182.     function addAssignWarning(containerId) {
  183.         AJS.$(containerId).prepend(AJS.$("<div>").attr("id", "bulkAssignMessage"));
  184.         displayMessage("warning", AJS.I18n.getText("blueant.worktime.bulk.assign.what.edited.warning"), "bulkAssignMessage");
  185.     }
  186.    
  187. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement