From 362fc8a9b89f79b3c774386c8326b91ef9c5359d Mon Sep 17 00:00:00 2001
From: Bengt Brodersen
"); + + jQuery("head", printDocument).append(newPrintPanelPageCSS()); + jQuery("head", printDocument).append(newPrintPanelCardCSS()); + + console.logInfo("load " + issueKeyList.length + " issues..."); + jQuery("#card-print-dialog-title").text("Card Print - Loading " + issueKeyList.length + " issues..."); + var deferredList = []; + + issueKeyList.each(function(position, issueKey) { + var card = newCardHTML(issueKey); + card.hide(); + jQuery("body", printDocument).append(card); + var deferred = addDeferred(deferredList); + loadCardDataJSON(issueKey, function(responseData) { + fillCardWithJSONData(card, responseData); + card.show(); + resizeIframe(printFrame); + deferred.resolve(); }); + }); + console.logInfo("wait for issues loaded..."); - jQuery("head").append(newPrintOverlayStyle); - jQuery("body").append(newPrintOverlayHTML); - - var printFrame = jQuery("#card-print-dialog-content-iframe"); - var printWindow = printFrame[0].contentWindow; - var printDocument = printWindow.document; - - printDocument.open(); - printDocument.write("
"); - - jQuery("head", printDocument).append(newPrintPanelPageCSS()); - jQuery("head", printDocument).append(newPrintPanelCardCSS()); - - console.logInfo("load " + issueKeyList.length + " issues..."); - jQuery("#card-print-dialog-title").text("Card Print - Loading... " + 0 + " / " + issueKeyList.length); - var deferredList = []; - issueKeyList.each(function(position, issueKey) { - var card = newCardHTML(issueKey); - card.hide(); - jQuery("body", printDocument).append(card); - var deferred = new jQuery.Deferred() - deferredList.push(deferred); - loadCardDataJSON(issueKey, function(responseData) { - fillCardWithJSONData(card, responseData); - card.show(); - resizeIframe(printFrame); - jQuery("#card-print-dialog-title").text("Card Print - Loading... " + (position + 1) + " / " + issueKeyList.length); - deferred.resolve(); - }); - }); - console.logInfo("wait for issues loaded..."); - - jQuery.when.apply(jQuery, deferredList).done(function() { - jQuery(printWindow).load(function(){ - jQuery("#card-print-dialog-title").text("Card Print"); - console.logInfo("everything loaded!"); - printWindow.print(); - }) - printDocument.close(); - console.logInfo("wait for resources loaded..."); - }); + applyDeferred(deferredList,function() { + jQuery(printWindow).load(function(){ + jQuery("#card-print-dialog-title").text("Card Print"); + console.logInfo("everything loaded!"); + printWindow.print(); + }) + printDocument.close(); + console.logInfo("wait for resources loaded..."); + }); } -function close(){ - console.logInfo("close overlay"); - jQuery("#card-print-overlay").remove(); - jQuery("#card-print-overlay-style").remove(); +function closePrintPreview(){ + console.logInfo("close overlay"); + jQuery("#card-print-overlay").remove(); + jQuery("#card-print-overlay-style").remove(); } function getSelectedIssueKeyList() { - //JIRA - if (jQuery("meta[name='application-name'][ content='JIRA']").length > 0) { - //Browse - if (/.*\/browse\/.*/g.test(document.URL)) { - return jQuery("a[data-issue-key][id='key-val']").map(function() { - return jQuery(this).attr('data-issue-key'); - }); - } - - // RapidBoard - if (/.*\/secure\/RapidBoard.jspa.*/g.test(document.URL)) { - return jQuery('div[data-issue-key].ghx-selected').map(function() { - return jQuery(this).attr('data-issue-key'); - }); - } + //JIRA + if (jQuery("meta[name='application-name'][ content='JIRA']").length > 0) { + //Browse + if (/.*\/browse\/.*/g.test(document.URL)) { + return jQuery("a[data-issue-key][id='key-val']").map(function() { + return jQuery(this).attr('data-issue-key'); + }); } - return []; + // RapidBoard + if (/.*\/secure\/RapidBoard.jspa.*/g.test(document.URL)) { + return jQuery('div[data-issue-key].ghx-selected').map(function() { + return jQuery(this).attr('data-issue-key'); + }); + } + } + + return []; } function fillCardWithJSONData(card, data) { - //Key - var key = data.key; - console.logInfo("key: " + key); - card.find('.key').text(key); + //Key + var key = data.key; + console.logInfo("key: " + key); + card.find('.key').text(key); - //Type - var type = data.fields.issuetype.name.toLowerCase(); - console.logInfo("type: " + type); - card.find(".card").attr("type", type); - - //Summary - var summary = data.fields.summary; - console.logInfo("summary: " + summary); - card.find('.summary').text(summary); + //Type + var type = data.fields.issuetype.name.toLowerCase(); + console.logInfo("type: " + type); + card.find(".card").attr("type", type); - //Description - var description = data.renderedFields.description; - console.logInfo("description: " + description); - card.find('.description').html(description); + //Summary + var summary = data.fields.summary; + console.logInfo("summary: " + summary); + card.find('.summary').text(summary); - //Assignee - var assignee = data.fields.assignee; - console.logInfo("assignee: " + assignee); - if ( assignee ) { - var avatarUrl = assignee.avatarUrls['48x48']; - if(avatarUrl.indexOf("ownerId=") < 0){ - var displayName = assignee.displayName; - //card.find(".assignee").css("background", stringToColor(displayName)); - card.find(".assignee").text(displayName[0]); - } - else { - card.find(".assignee").css("background-image", "url('" + avatarUrl + "')"); - } - } else { - card.find(".assignee").addClass("hidden"); + //Description + var description = data.renderedFields.description; + console.logInfo("description: " + description); + card.find('.description').html(description); + + //Assignee + var assignee = data.fields.assignee; + console.logInfo("assignee: " + assignee); + if ( assignee ) { + var avatarUrl = assignee.avatarUrls['48x48']; + if(avatarUrl.indexOf("ownerId=") < 0){ + var displayName = assignee.displayName; + card.find(".assignee").text(displayName[0]); + } + else { + card.find(".assignee").css("background-image", "url('" + avatarUrl + "')"); + } + } else { + card.find(".assignee").addClass("hidden"); + } + + //Due-Date + var duedate = data.fields.duedate; + console.logInfo("duedate: " + duedate); + if ( duedate ) { + var renderedDuedate = new Date(duedate).format('D d.m.'); + card.find(".due-date").text(renderedDuedate); + } else { + card.find(".due").addClass("hidden"); + } + + //Attachment + var hasAttachment = false; + var indexOfPrintScopeDeviderToken = description.indexOf(printScopeDeviderToken); + if (indexOfPrintScopeDeviderToken >= 0) { + var descriptionWithoutAttachment = description.substring(0, indexOfPrintScopeDeviderToken); + card.find('.description').html(descriptionWithoutAttachment); + hasAttachment = true; + } else if (data.fields.attachment.length > 0) { + hasAttachment = true; + } + console.logInfo("hasAttachment: " + hasAttachment); + if ( hasAttachment ) { + } else{ + card.find('.attachment').addClass('hidden'); + } + + //Story Points + var storyPoints = data.fields.storyPoints; + console.logInfo("storyPoints: " + storyPoints); + if (storyPoints) { + card.find(".estimate").text(storyPoints); + } else { + card.find(".estimate").addClass("hidden"); + } + + //Epic + var epicKey = data.fields.epicLink; + console.logInfo("epicKey: " + epicKey); + if ( epicKey ) { + card.find(".epic-key").text(epicKey); + loadCardDataJSON(epicKey, function(responseData) { + var epicName = responseData.fields.epicName; + console.logTrace("epicName: " + epicName); + card.find(".epic-name").text(epicName); + }, false); + } else { + card.find(".epic").addClass("hidden"); + } + + //QR-Code + var qrCodeImageUrl = 'https://chart.googleapis.com/chart?cht=qr&chs=256x256&chld=L|1&chl=' + window.location.origin + "/browse/" + key; + console.logTrace("qrCodeImageUrl: " + qrCodeImageUrl); + card.find(".qr-code").css("background-image", "url('" + qrCodeImageUrl + "')"); + + //handle Site specifics + switch (window.location.hostname) { + case "lrs-support.com": fillCardWithJSONDataLRS(card, data); + break; + default: } - //Due-Date - var duedate = data.fields.duedate; - console.logInfo("duedate: " + duedate); - if ( duedate ) { - var renderedDuedate = new Date(duedate).format('D d.m.'); - card.find(".due-date").text(renderedDuedate); - } else { - card.find(".due").addClass("hidden"); - } + } - //Attachment - var hasAttachment = false; - var indexOfPrintScopeDeviderToken = ((description.indexOf(printScopeDeviderToken2) + 1) || (description.indexOf(printScopeDeviderToken1) + 1)) - 1; - if (indexOfPrintScopeDeviderToken >= 0) { - var descriptionWithoutAttachment = description.substring(0, indexOfPrintScopeDeviderToken); - card.find('.description').html(descriptionWithoutAttachment); - hasAttachment = true; - } else if (data.fields.attachment.length > 0) { - hasAttachment = true; - } - console.logInfo("hasAttachment: " + hasAttachment); - if ( hasAttachment ) { - } else{ - card.find('.attachment').addClass('hidden'); - } - - //Story Points - var storyPoints = data.fields.storyPoints; - console.logInfo("storyPoints: " + storyPoints); - if (storyPoints) { - card.find(".estimate").text(storyPoints); - } else { - card.find(".estimate").addClass("hidden"); - } - - //Epic - var epicKey = data.fields.epicLink; - console.logInfo("epicKey: " + epicKey); - if ( epicKey ) { - card.find(".epic-key").text(epicKey); - loadCardDataJSON(epicKey, function(responseData) { - var epicName = responseData.fields.epicName; - console.logTrace("epicName: " + epicName); - card.find(".epic-name").text(epicName); - }, false); - } else { - card.find(".epic").addClass("hidden"); - } - - //QR-Code - var qrCodeImageUrl = 'https://chart.googleapis.com/chart?cht=qr&chs=256x256&chld=L|1&chl=' + window.location.origin + "/browse/" + key; - console.logTrace("qrCodeImageUrl: " + qrCodeImageUrl); - card.find(".qr-code").css("background-image", "url('" + qrCodeImageUrl + "')"); - - //handle Site specifics - switch (window.location.hostname) { - case "lrs-support.com": fillCardWithJSONDataLRS(card, data); - break; - default: - } - -} - -function fillCardWithJSONDataLRS(card, data) { + function fillCardWithJSONDataLRS(card, data) { console.logInfo("Apply LRS Specifics"); - //Desired-Date + //Desired-Date var desiredDate = data.fields.desiredDate; console.logInfo("desiredDate: " + desiredDate); if ( desiredDate ) { - var renderedDesiredDate = new Date(desiredDate).format('D d.m.'); - card.find(".due-date").text(renderedDesiredDate); - card.find(".due").removeClass("hidden"); + var renderedDesiredDate = new Date(desiredDate).format('D d.m.'); + card.find(".due-date").text(renderedDesiredDate); + card.find(".due").removeClass("hidden"); } else { - card.find(".due").addClass("hidden"); + card.find(".due").addClass("hidden"); } -} + } -function loadCardDataJSON(issueKey, callback, async) { - async = firstNotNull(async, true); + function loadCardDataJSON(issueKey, callback) { //https://docs.atlassian.com/jira/REST/latest/ var url = '/rest/api/2/issue/' + issueKey + '?expand=renderedFields,names'; console.logInfo("IssueUrl: " + window.location.hostname + url); console.logDebug("Issue: " + issueKey + " Loading..."); return jQuery.ajax({ - type: 'GET', - url: url, - dataType: 'json', - success: function(responseData){ - fields = responseData.fields; - // add custom fields with field names - jQuery.each(responseData.names, function(key, value) { - if(key.startsWith("customfield_")){ - var newFieldId = value.toCamelCase(); - console.logTrace("add new field: " + newFieldId +" with value from "+ key); - fields[value.toCamelCase()] = fields[key]; - } - }); - console.logDebug("Issue: " + issueKey + " Loaded!"); - callback(responseData); - }, - data: {}, - async: async + type: 'GET', + url: url, + dataType: 'json', + success: function(responseData){ + fields = responseData.fields; + // add custom fields with field names + jQuery.each(responseData.names, function(key, value) { + if(key.startsWith("customfield_")){ + var newFieldId = value.toCamelCase(); + console.logTrace("add new field: " + newFieldId +" with value from "+ key); + fields[value.toCamelCase()] = fields[key]; + } + }); + console.logDebug("Issue: " + issueKey + " Loaded!"); + callback(responseData); + }, + data: {}, }); -} + } @@ -272,59 +273,71 @@ function loadCardDataJSON(issueKey, callback, async) { // http://www.cssdesk.com/T9hXg function newPrintOverlayHTML(){ - var result = jQuery(document.createElement('div')) - .attr("id","card-print-overlay") - .html(multilineString(function() { - /*! + var result = jQuery(document.createElement('div')) + .attr("id","card-print-overlay") + .html(multilineString(function() { +/*!