|
1 | 1 | var refreshButton_Placed = false;
|
2 | 2 | var enableToggle = true;
|
3 |
| -function allIncluded() { |
| 3 | +function allIncluded(outputTarget = 'email') { |
4 | 4 | /* global $*/
|
5 | 5 | var scrumBody = null;
|
6 | 6 | var scrumSubject = null;
|
@@ -69,9 +69,19 @@ function allIncluded() {
|
69 | 69 | if (items.githubUsername) {
|
70 | 70 | githubUsername = items.githubUsername;
|
71 | 71 | fetchGithubData();
|
72 |
| - } else { |
73 |
| - console.warn('No GitHub username found in storage'); |
74 |
| - } |
| 72 | + } else { |
| 73 | + if (outputTarget === 'popup') { |
| 74 | + // Show error in popup |
| 75 | + const generateBtn = document.getElementById('generateReport'); |
| 76 | + if (generateBtn) { |
| 77 | + generateBtn.innerHTML = '<i class="fa fa-refresh"></i> Generate Report'; |
| 78 | + generateBtn.disabled = false; |
| 79 | + } |
| 80 | + Materialize.toast('Please enter your GitHub username', 3000); |
| 81 | + } else { |
| 82 | + console.warn('No GitHub username found in storage'); |
| 83 | + } |
| 84 | + } |
75 | 85 | if (items.projectName) {
|
76 | 86 | projectName = items.projectName;
|
77 | 87 | }
|
@@ -230,14 +240,37 @@ function allIncluded() {
|
230 | 240 | <p> ${userReason}</p>`;
|
231 | 241 | }
|
232 | 242 |
|
233 |
| - // Use the adapter to inject content |
234 |
| - const elements = window.emailClientAdapter.getEditorElements(); |
235 |
| - if (!elements || !elements.body) { |
236 |
| - console.error('Email client editor not found'); |
237 |
| - return; |
238 |
| - } |
| 243 | + if (outputTarget === 'popup') { |
| 244 | + // Update popup textarea |
| 245 | + const scrumReport = document.getElementById('scrumReport'); |
| 246 | + if (scrumReport) { |
| 247 | + // Convert HTML to plain text for textarea |
| 248 | + const plainContent = content |
| 249 | + .replace(/<br>/g, '\n') |
| 250 | + .replace(/<\/?[^>]+(>|$)/g, '') |
| 251 | + .replace(/ /g, ' '); |
| 252 | + |
| 253 | + scrumReport.value = plainContent; |
| 254 | + Materialize.textareaAutoResize(scrumReport); |
239 | 255 |
|
240 |
| - window.emailClientAdapter.injectContent(elements.body, content, elements.eventTypes.contentChange); |
| 256 | + // Reset generate button |
| 257 | + const generateBtn = document.getElementById('generateReport'); |
| 258 | + if (generateBtn) { |
| 259 | + generateBtn.innerHTML = '<i class="fa fa-refresh"></i> Generate Report'; |
| 260 | + generateBtn.disabled = false; |
| 261 | + } |
| 262 | + |
| 263 | + Materialize.toast('Report generated successfully!', 3000); |
| 264 | + } |
| 265 | + } else { |
| 266 | + // Use the adapter to inject content |
| 267 | + const elements = window.emailClientAdapter.getEditorElements(); |
| 268 | + if (!elements || !elements.body) { |
| 269 | + console.error('Email client editor not found'); |
| 270 | + return; |
| 271 | + } |
| 272 | + window.emailClientAdapter.injectContent(elements.body, content, elements.eventTypes.contentChange); |
| 273 | + } |
241 | 274 | });
|
242 | 275 | }
|
243 | 276 |
|
@@ -547,13 +580,21 @@ function allIncluded() {
|
547 | 580 | }, 1000);
|
548 | 581 | }
|
549 | 582 | function handleRefresh() {
|
550 |
| - allIncluded(); |
| 583 | + allIncluded('email'); |
551 | 584 | }
|
552 | 585 | }
|
553 |
| -allIncluded(); |
| 586 | +allIncluded('email'); // Auto-trigger on page load |
| 587 | +$('button>span:contains(New conversation)').parent('button').click(() => { |
| 588 | + allIncluded('email'); // Auto-trigger on new conversation |
| 589 | +}); |
554 | 590 |
|
555 | 591 | $('button>span:contains(New conversation)')
|
556 | 592 | .parent('button')
|
557 | 593 | .click(() => {
|
558 |
| - allIncluded(); |
| 594 | + allIncluded('email'); |
559 | 595 | });
|
| 596 | + |
| 597 | +// Export for use in popup |
| 598 | +window.generateScrumReport = function() { |
| 599 | + allIncluded('popup'); |
| 600 | +}; |
0 commit comments