OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Constants. |
| 6 var FEEDBACK_LANDING_PAGE = |
| 7 'http://www.google.com/support/chrome/go/feedback_confirmation' |
| 8 |
| 9 var selectedThumbnailDivId = ''; |
| 10 var selectedThumbnailId = ''; |
| 11 var selectedImageUrl; |
| 12 |
| 13 var savedThumbnailIds = []; |
| 14 savedThumbnailIds['current-screenshots'] = ''; |
| 15 savedThumbnailIds['saved-screenshots'] = ''; |
| 16 |
| 17 var localStrings = new LocalStrings(); |
| 18 |
| 19 /** |
| 20 * Selects an image thumbnail in the specified div. |
| 21 */ |
| 22 function selectImage(divId, thumbnailId) { |
| 23 var thumbnailDivs = $(divId).children; |
| 24 selectedThumbnailDivId = divId; |
| 25 for (var i = 0; i < thumbnailDivs.length; i++) { |
| 26 // If the the current div matches the thumbnail id provided, |
| 27 // or there is no thumbnail id given, and we're at the first thumbnail. |
| 28 if ((thumbnailDivs[i].id == thumbnailId) || (!thumbnailId && !i)) { |
| 29 thumbnailDivs[i].className = 'image-thumbnail-container-selected'; |
| 30 selectedThumbnailId = thumbnailId; |
| 31 savedThumbnailIds[divId] = thumbnailId; |
| 32 } else { |
| 33 thumbnailDivs[i].className = 'image-thumbnail-container'; |
| 34 } |
| 35 } |
| 36 } |
| 37 |
| 38 /** |
| 39 * Adds an image thumbnail to the specified div. |
| 40 */ |
| 41 function addScreenshot(divId, screenshot) { |
| 42 var thumbnailDiv = document.createElement('div'); |
| 43 thumbnailDiv.className = 'image-thumbnail-container'; |
| 44 |
| 45 thumbnailDiv.id = divId + '-thumbnailDiv-' + $(divId).children.length; |
| 46 thumbnailDiv.onclick = function() { |
| 47 selectImage(divId, thumbnailDiv.id); |
| 48 }; |
| 49 |
| 50 var innerDiv = document.createElement('div'); |
| 51 innerDiv.className = 'image-thumbnail'; |
| 52 |
| 53 var thumbnail = document.createElement('img'); |
| 54 thumbnail.id = thumbnailDiv.id + '-image'; |
| 55 thumbnail.src = screenshot; |
| 56 innerDiv.appendChild(thumbnail); |
| 57 |
| 58 var largeImage = document.createElement('img'); |
| 59 largeImage.src = screenshot; |
| 60 |
| 61 var popupDiv = document.createElement('div'); |
| 62 popupDiv.appendChild(largeImage); |
| 63 innerDiv.appendChild(popupDiv); |
| 64 |
| 65 thumbnailDiv.appendChild(innerDiv); |
| 66 $(divId).appendChild(thumbnailDiv); |
| 67 |
| 68 if (!selectedThumbnailId) |
| 69 selectImage(divId, thumbnailDiv.id); |
| 70 } |
| 71 |
| 72 /** |
| 73 * Send's the report; after the report is sent, we need to be redirected to |
| 74 * the landing page, but we shouldn't be able to navigate back, hence |
| 75 * we open the landing page in a new tab and sendReport closes this tab. |
| 76 */ |
| 77 function sendReport() { |
| 78 if (!$('issue-with-combo').selectedIndex) { |
| 79 alert(localStrings.getString('no-issue-selected')); |
| 80 return false; |
| 81 } |
| 82 |
| 83 var imagePath = ''; |
| 84 if (selectedThumbnailId) |
| 85 imagePath = $(selectedThumbnailId + '-image').src; |
| 86 |
| 87 // Note, categories are based from 1 in our protocol buffers, so no |
| 88 // adjustment is needed on selectedIndex. |
| 89 var reportArray = [String($('issue-with-combo').selectedIndex), |
| 90 $('page-url-text').value, |
| 91 $('description-text').value, |
| 92 imagePath]; |
| 93 |
| 94 // Add chromeos data if it exists. |
| 95 if ($('user-email-text') && $('sys-info-checkbox')) { |
| 96 reportArray = reportArray.concat([$('user-email-text').value, |
| 97 String($('sys-info-checkbox').checked)]); |
| 98 } |
| 99 |
| 100 // open the landing page in a new tab, sendReport will close this one. |
| 101 window.open(FEEDBACK_LANDING_PAGE, '_blank'); |
| 102 chrome.send('sendReport', reportArray); |
| 103 return true; |
| 104 } |
| 105 |
| 106 function cancel() { |
| 107 chrome.send('cancel', []); |
| 108 return true; |
| 109 } |
| 110 |
| 111 /** |
| 112 * Select the current screenshots div, restoring the image that was |
| 113 * selected when we had this div open previously. |
| 114 */ |
| 115 function currentSelected() { |
| 116 $('current-screenshots').style.display = 'block'; |
| 117 if ($('saved-screenshots')) |
| 118 $('saved-screenshots').style.display = 'none'; |
| 119 |
| 120 if (selectedThumbnailDivId != 'current-screenshots') |
| 121 selectImage('current-screenshots', |
| 122 savedThumbnailIds['current-screenshots']); |
| 123 |
| 124 return true; |
| 125 } |
| 126 |
| 127 /** |
| 128 * Select the saved screenshots div, restoring the image that was |
| 129 * selected when we had this div open previously. |
| 130 */ |
| 131 function savedSelected() { |
| 132 $('current-screenshots').style.display = 'none'; |
| 133 $('saved-screenshots').style.display = 'block'; |
| 134 |
| 135 if (selectedThumbnailDivId != 'saved-screenshots') |
| 136 selectImage('saved-screenshots', savedThumbnailIds['saved-screenshots']); |
| 137 |
| 138 return true; |
| 139 } |
| 140 |
| 141 /** |
| 142 * Unselect all screenshots divs. |
| 143 */ |
| 144 function noneSelected() { |
| 145 $('current-screenshots').style.display = 'none'; |
| 146 if ($('saved-screenshots')) |
| 147 $('saved-screenshots').style.display = 'none'; |
| 148 |
| 149 selectedThumbnailDivId = ''; |
| 150 selectedThumbnailId = ''; |
| 151 return true; |
| 152 } |
OLD | NEW |