(function () { var version = "3.1.21"; console.log("Version: " + version); var isDev = typeof isDev !== 'undefined' && isDev ; var isTest = typeof isTest !== 'undefined' && isTest ; var hostOrigin = "https://qoomon.github.io/Jira-Issue-Card-Printer/"; if(isDev){ console.log("DEVELOPMENT"); hostOrigin = "https://rawgit.com/qoomon/Jira-Issue-Card-Printer/develop/"; } if(isTest){ console.log("TEST"); } //cors = "https://cors-anywhere.herokuapp.com/"; //$("#card").load("https://cors-anywhere.herokuapp.com/"+"https://qoomon.github.io/Jira-Issue-Card-Printer/card.html"); // (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-50840116-3', {'alwaysSendReferrer': true}); if(isTest || isDev){ ga('set', 'page', '/dev/cardprinter'); } else { ga('set', 'page', '/cardprinter'); } //ga('set', 'referrer', window.location.hostname); //ga('set', 'location', window.location.protocol + '//' + window.location.host + window.location.pathname); //ga('set', 'hostname', window.location.hostname); //ga('set', 'title', document.title); //ga('set', 'campaignSource', '(direct)'); //ga('set', 'campaignMedium', '(none)'); // try { // load jQuery if (window.jQuery === undefined) { appendScript('//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'); } // wait untill all scripts loaded appendScript('https://qoomon.github.io/void', function(){ init(); main(); }); function init(){ addJQueryFunctions(); addConsoleFunctions(); addStringFunctions(); addDateFunctions(); printScopeDeviderToken = "Attachment"; console.logLevel = console.INFO; resourceOrigin = hostOrigin+ "resources/"; } function main(){ //preconditions if(jQuery("#card-print-overlay").length > 0){ alert("Print Card already opened!"); return; } var issueKeyList = getSelectedIssueKeyList(); if(issueKeyList.length <= 0){ alert("Please select at least one issue."); return; } // open print preview jQuery("body").append(printOverlayHTML); jQuery("#card-print-overlay").prepend(printOverlayStyle); ga('send', 'pageview'); jQuery("#card-print-dialog-title").text("Card Print - Loading " + issueKeyList.length + " issues..."); renderCards(issueKeyList, function(){ jQuery("#card-print-dialog-title").text("Card Print"); //print(); }); } function print(){ var printFrame = jQuery("#card-print-dialog-content-iframe"); var printWindow = printFrame[0].contentWindow; var printDocument = printWindow.document; ga('send', 'event', 'button', 'click', 'print', jQuery(".card", printDocument).length ); printWindow.print(); } function renderCards(issueKeyList, callback) { 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(printPanelPageCSS()); jQuery("head", printDocument).append(printPanelCardCSS()); console.logInfo("load " + issueKeyList.length + " issues..."); var deferredList = []; issueKeyList.each(function(position, issueKey) { var page = newPage(issueKey); page.hide(); page.find('.key').text(issueKey); jQuery("body", printDocument).append(page); var deferred = addDeferred(deferredList); loadCardDataJSON(issueKey, function(responseData) { fillCardWithJSONData(page, responseData); page.show(); resizeIframe(printFrame); deferred.resolve(); }); }); console.logInfo("wait for issues loaded..."); applyDeferred(deferredList,function() { console.logInfo("...all issues loaded."); jQuery(printWindow).load(function(){ console.logInfo("...all resources loaded."); callback(); }) printDocument.close(); console.logInfo("wait for resources loaded..."); }); } function closePrintPreview(){ 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'); }); } } return []; } function fillCardWithJSONData(card, data) { //Key var key = data.key; console.logDebug("key: " + key); card.find('.key').text(key); //Type var type = data.fields.issuetype.name.toLowerCase(); console.logDebug("type: " + type); card.find(".card").attr("type", type); ga('send', 'event', 'task', 'generate', 'card', type ); //Summary var summary = data.fields.summary; console.logDebug("summary: " + summary); card.find('.summary').text(summary); //Description var description = data.renderedFields.description; console.logDebug("description: " + description); card.find('.description').html(description); //Assignee var assignee = data.fields.assignee; console.logDebug("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.logDebug("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"); } <<<<<<< HEAD } function loadCardDataJSON(issueKey, callback) { //https://docs.atlassian.com/jira/REST/latest/ var url = '/rest/api/2/issue/' + issueKey + '?expand=renderedFields,names'; console.logDebug("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: {}, }); } //############################################################################################################################ //############################################################################################################################ //############################################################################################################################ // http://www.cssdesk.com/T9hXg function printOverlayHTML(){ var result = jQuery(document.createElement('div')) .attr("id","card-print-overlay") .html(multilineString(function() { /*!
Card Print
*/ })); // info result.find("#report-issue") .click(function(event){ window.open('https://github.com/qoomon/Jira-Issue-Card-Printer/issues'); return false; }); ======= //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.logDebug("hasAttachment: " + hasAttachment); if ( hasAttachment ) { } else{ card.find('.attachment').addClass('hidden'); } //Story Points var storyPoints = data.fields.storyPoints; console.logDebug("storyPoints: " + storyPoints); if (storyPoints) { card.find(".estimate").text(storyPoints); } else { card.find(".estimate").addClass("hidden"); } //Epic var epicKey = data.fields.epicLink; console.logDebug("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) { console.logInfo("Apply LRS Specifics"); //Desired-Date var desiredDate = data.fields.desiredDate; console.logDebug("desiredDate: " + desiredDate); if ( desiredDate ) { 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"); } } function loadCardDataJSON(issueKey, callback) { //https://docs.atlassian.com/jira/REST/latest/ var url = '/rest/api/2/issue/' + issueKey + '?expand=renderedFields,names'; console.logDebug("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: {}, }); } //############################################################################################################################ //############################################################################################################################ //############################################################################################################################ // http://www.cssdesk.com/T9hXg function printOverlayHTML(){ var result = jQuery(document.createElement('div')) .attr("id","card-print-overlay") .html(multilineString(function() { /*!
Card Print
*/ })); // info >>>>>>> gh-pages result.find("#report-issue") .click(function(event){ window.open('https://github.com/qoomon/Jira-Issue-Card-Printer/issues'); return false; }); result.find("#about") .click(function(event){ window.open('http://qoomon.blogspot.de/2014/01/jira-issue-card-printer-bookmarklet.html'); return false; }); // print result.find("#card-print-dialog-print") .click(function(event){ print(); return false; }); // closePrintPreview result.find("#card-print-dialog-cancel") .click(function(event){ closePrintPreview(); return false; }); result.click(function(event) { if( event.target == this ){ closePrintPreview(); } return false; }); jQuery(document).keyup(function(e) { if (e.keyCode == 27) { // esc closePrintPreview(); } }); // prevent background scrolling result.scroll(function(event) { return false; }); return result; } function printOverlayStyle(){ var result = jQuery(document.createElement('style')) .attr("id", "card-print-overlay-style") .attr("type", "text/css") .html(multilineString(function() { /*! #card-print-overlay { position: fixed; height: 100%; width: 100%; top: 0; left: 0; background:rgba(0, 0, 0, 0.5); box-sizing: border-box; word-wrap:break-word; z-index: 99999; } #card-print-dialog { position: relative; top: 60px; right:0px; left:0px; height: calc(100% - 120px); width: 1000px; margin: auto; border-style: solid; border-color: #cccccc; border-width: 1px; -moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px; overflow: hidden; } #card-print-dialog-header { position: relative; background: #f0f0f0; height: 25px; border-bottom: 1px solid #cccccc; padding: 15px 20px 15px 20px; } #card-print-dialog-content { position: relative; background: white; height: calc(100% - 106px); + height: 100px; width: 100%; overflow-y: scroll; } #card-print-dialog-content-iframe { position: relative; height: 100%; width: 100%; border:none; } #card-print-dialog-footer { position: relative; background: #f0f0f0; border-top: 1px solid #cccccc; height: 30px; padding: 10px; text-align: right; } #buttons { position: relative; float: right; display: inline-block; height 30px; } #info { position: absolute; right: 400px; float: left; display: inline-block; height 30px; } #card-print-dialog-title{ position: relative; float: left; color: rgb(51, 51, 51); display: block; font-family: Arial, sans-serif; font-size: 20px; font-weight: normal; height: 30px; line-height: 30px; } */ })); return result; } function printPanelPageCSS(){ var result = jQuery(document.createElement('style')) .attr("id", "printPanelPageStyle") .attr("type", "text/css") .html(multilineString(function() { /*! .page { position: relative; overflow: auto; margin-left: auto; margin-right: auto; width: auto; max-width: 29.7cm; min-width: 21cm; height: auto; page-break-after: always; background:rgba(256, 256, 256, 0.85); -webkit-box-shadow: 0px 0px 7px 3px rgba(31,31,31,0.4); -moz-box-shadow: 0px 0px 7px 3px rgba(31,31,31,0.4); box-shadow: 0px 0px 7px 3px rgba(31,31,31,0.4); border-style: solid; border-color: #bfbfbf; border-width: 0.05cm; -moz-border-radius: 0.1cm; -webkit-border-radius: 0.1cm; border-radius: 0.1cm; padding: 1.0cm; margin: 1.0cm; } @media print { .page { <<<<<<< HEAD border:none; } #card-print-dialog-footer { position: relative; background: #f0f0f0; border-top: 1px solid #cccccc; height: 30px; padding: 10px; text-align: right; } #buttons { position: relative; float: right; display: inline-block; height 30px; } #card-print-dialog-title{ position: relative; float: left; color: rgb(51, 51, 51); display: block; font-family: Arial, sans-serif; font-size: 20px; font-weight: normal; height: 30px; line-height: 30px; } */ })); return result; } function printPanelPageCSS(){ var result = jQuery(document.createElement('style')) .attr("id", "printPanelPageStyle") .attr("type", "text/css") .html(multilineString(function() { /*! .page { position: relative; overflow: auto; margin-left: auto; margin-right: auto; width: auto; max-width: 29.7cm; min-width: 21cm; height: auto; ======= >>>>>>> gh-pages page-break-after: always; background:rgba(256, 256, 256, 0.0); border-style: none; padding: 0.0cm; margin: 0.0cm; -webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none; -webkit-print-color-adjust:exact; print-color-adjust: exact; -webkit-filter:opacity(1.0); filter:opacity(1.0); } <<<<<<< HEAD @media print { .page { page-break-after: always; background:rgba(256, 256, 256, 0.0); border-style: none; padding: 0.0cm; margin: 0.0cm; -webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none; -webkit-print-color-adjust:exact; print-color-adjust: exact; -webkit-filter:opacity(1.0); filter:opacity(1.0); } .page:last-of-type { page-break-after: auto; } } */ })); return result; } // http://www.cssdesk.com/scHcP function newPage(issueKey){ var page = jQuery(document.createElement('div')) .attr("id",issueKey) .addClass("page") .html(multilineString(function() { /*!
Bengt Brodersen - qoomon.com