| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 if (thumbnailDivs.length == 0) { | |
| 26 $(divId).style.display = 'none'; | |
| 27 return; | |
| 28 } | |
| 29 for (var i = 0; i < thumbnailDivs.length; i++) { | |
| 30 // If the the current div matches the thumbnail id provided, | |
| 31 // or there is no thumbnail id given, and we're at the first thumbnail. | |
| 32 if ((thumbnailDivs[i].id == thumbnailId) || (!thumbnailId && !i)) { | |
| 33 thumbnailDivs[i].className = 'image-thumbnail-container-selected'; | |
| 34 selectedThumbnailId = thumbnailId; | |
| 35 savedThumbnailIds[divId] = thumbnailId; | |
| 36 } else { | |
| 37 thumbnailDivs[i].className = 'image-thumbnail-container'; | |
| 38 } | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 /** | |
| 43 * Adds an image thumbnail to the specified div. | |
| 44 */ | |
| 45 function addScreenshot(divId, screenshot) { | |
| 46 var thumbnailDiv = document.createElement('div'); | |
| 47 thumbnailDiv.className = 'image-thumbnail-container'; | |
| 48 | |
| 49 thumbnailDiv.id = divId + '-thumbnailDiv-' + $(divId).children.length; | |
| 50 thumbnailDiv.onclick = function() { | |
| 51 selectImage(divId, thumbnailDiv.id); | |
| 52 }; | |
| 53 | |
| 54 var innerDiv = document.createElement('div'); | |
| 55 if (divId == 'current-screenshots') | |
| 56 innerDiv.className = 'image-thumbnail-current'; | |
| 57 else | |
| 58 innerDiv.className = 'image-thumbnail'; | |
| 59 | |
| 60 var thumbnail = document.createElement('img'); | |
| 61 thumbnail.id = thumbnailDiv.id + '-image'; | |
| 62 // We add the ?+timestamp to make sure the image URLs are unique | |
| 63 // and Chrome does not load the image from cache. | |
| 64 thumbnail.src = screenshot + '?' + Date.now(); | |
| 65 innerDiv.appendChild(thumbnail); | |
| 66 | |
| 67 thumbnailDiv.appendChild(innerDiv); | |
| 68 $(divId).appendChild(thumbnailDiv); | |
| 69 | |
| 70 if (!selectedThumbnailId) | |
| 71 selectImage(divId, thumbnailDiv.id); | |
| 72 } | |
| 73 | |
| 74 /** | |
| 75 * Send's the report; after the report is sent, we need to be redirected to | |
| 76 * the landing page, but we shouldn't be able to navigate back, hence | |
| 77 * we open the landing page in a new tab and sendReport closes this tab. | |
| 78 */ | |
| 79 function sendReport() { | |
| 80 if (!$('issue-with-combo').selectedIndex) { | |
| 81 alert(localStrings.getString('no-issue-selected')); | |
| 82 return false; | |
| 83 } else if ($('description-text').value.length == 0) { | |
| 84 alert(localStrings.getString('no-description')); | |
| 85 return false; | |
| 86 } | |
| 87 | |
| 88 var imagePath = ''; | |
| 89 if ($('screenshot-checkbox').checked && selectedThumbnailId) | |
| 90 imagePath = $(selectedThumbnailId + '-image').src; | |
| 91 var pageUrl = $('page-url-text').value; | |
| 92 if (!$('page-url-checkbox').checked) | |
| 93 pageUrl = ''; | |
| 94 | |
| 95 // Note, categories are based from 1 in our protocol buffers, so no | |
| 96 // adjustment is needed on selectedIndex. | |
| 97 var reportArray = [String($('issue-with-combo').selectedIndex), | |
| 98 pageUrl, | |
| 99 $('description-text').value, | |
| 100 imagePath]; | |
| 101 | |
| 102 // Add chromeos data if it exists. | |
| 103 if ($('user-email-text') && $('sys-info-checkbox')) { | |
| 104 var userEmail= $('user-email-text').textContent; | |
| 105 if (!$('user-email-checkbox').checked) | |
| 106 userEmail = ''; | |
| 107 reportArray = reportArray.concat([userEmail, | |
| 108 String($('sys-info-checkbox').checked)]); | |
| 109 } | |
| 110 | |
| 111 // open the landing page in a new tab, sendReport will close this one. | |
| 112 window.open(FEEDBACK_LANDING_PAGE, '_blank'); | |
| 113 chrome.send('sendReport', reportArray); | |
| 114 return true; | |
| 115 } | |
| 116 | |
| 117 function cancel() { | |
| 118 chrome.send('cancel', []); | |
| 119 return true; | |
| 120 } | |
| 121 | |
| 122 /** | |
| 123 * Select the current screenshots div, restoring the image that was | |
| 124 * selected when we had this div open previously. | |
| 125 */ | |
| 126 function currentSelected() { | |
| 127 // TODO(rkc): Change this to use a class instead. | |
| 128 $('current-screenshots').style.display = 'block'; | |
| 129 if ($('saved-screenshots')) | |
| 130 $('saved-screenshots').style.display = 'none'; | |
| 131 | |
| 132 if (selectedThumbnailDivId != 'current-screenshots') | |
| 133 selectImage('current-screenshots', | |
| 134 savedThumbnailIds['current-screenshots']); | |
| 135 | |
| 136 return true; | |
| 137 } | |
| 138 | |
| 139 /** | |
| 140 * Select the saved screenshots div, restoring the image that was | |
| 141 * selected when we had this div open previously. | |
| 142 */ | |
| 143 function savedSelected() { | |
| 144 $('current-screenshots').style.display = 'none'; | |
| 145 | |
| 146 if ($('saved-screenshots').childElementCount == 0) { | |
| 147 // setupSavedScreenshots will take care of changing visibility | |
| 148 chrome.send('refreshSavedScreenshots', []); | |
| 149 } else { | |
| 150 $('saved-screenshots').style.display = 'block'; | |
| 151 if (selectedThumbnailDivId != 'saved-screenshots') | |
| 152 selectImage('saved-screenshots', savedThumbnailIds['saved-screenshots']); | |
| 153 } | |
| 154 | |
| 155 return true; | |
| 156 } | |
| 157 | |
| 158 | |
| 159 /** | |
| 160 * Change the type of screenshot we're showing to the user from | |
| 161 * the current screenshot to saved screenshots | |
| 162 */ | |
| 163 function changeToSaved() { | |
| 164 $('screenshot-label-current').style.display = 'none'; | |
| 165 $('screenshot-label-saved').style.display = 'inline'; | |
| 166 | |
| 167 // Change the link to say "go to original" | |
| 168 $('screenshot-link-tosaved').style.display = 'none'; | |
| 169 $('screenshot-link-tocurrent').style.display = 'inline'; | |
| 170 | |
| 171 savedSelected(); | |
| 172 } | |
| 173 | |
| 174 /** | |
| 175 * Change the type of screenshot we're showing to the user from | |
| 176 * the saved screenshots to the current screenshots | |
| 177 */ | |
| 178 function changeToCurrent() { | |
| 179 $('screenshot-label-current').style.display = 'inline'; | |
| 180 $('screenshot-label-saved').style.display = 'none'; | |
| 181 | |
| 182 // Change the link to say "go to original" | |
| 183 $('screenshot-link-tosaved').style.display = 'inline'; | |
| 184 $('screenshot-link-tocurrent').style.display = 'none'; | |
| 185 | |
| 186 currentSelected(); | |
| 187 } | |
| 188 | |
| 189 /////////////////////////////////////////////////////////////////////////////// | |
| 190 // Document Functions: | |
| 191 /** | |
| 192 * Window onload handler, sets up the page. | |
| 193 */ | |
| 194 function load() { | |
| 195 if ($('sysinfo-url')) { | |
| 196 $('sysinfo-url').onclick = function(event) { | |
| 197 chrome.send('openSystemTab'); | |
| 198 }; | |
| 199 } | |
| 200 | |
| 201 <if expr="pp_ifdef('chromeos')"> | |
| 202 $('screenshot-link-tosaved').onclick = changeToSaved; | |
| 203 $('screenshot-link-tocurrent').onclick = changeToCurrent; | |
| 204 </if> | |
| 205 $('send-report-button').onclick = sendReport; | |
| 206 $('cancel-button').onclick = cancel; | |
| 207 | |
| 208 var menuOffPattern = /(^\?|&)menu=off($|&)/; | |
| 209 var menuDisabled = menuOffPattern.test(window.location.search); | |
| 210 document.documentElement.setAttribute('hide-menu', menuDisabled); | |
| 211 | |
| 212 // Set default values for the possible parameters, and then parse the actual | |
| 213 // values from the URL hash. | |
| 214 var parameters = { | |
| 215 'description': '', | |
| 216 'issueType': 0, | |
| 217 }; | |
| 218 var queryPos = window.location.hash.indexOf('?'); | |
| 219 if (queryPos !== -1) { | |
| 220 // Get an array of parameters in 'name=value' form. | |
| 221 var query = window.location.hash.substring(queryPos + 1).split('&'); | |
| 222 for (var i = 0; i < query.length; i++) { | |
| 223 // Decode and store each parameter value. | |
| 224 parameter = query[i].split('='); | |
| 225 parameters[parameter[0]] = decodeURIComponent(parameter[1]); | |
| 226 } | |
| 227 | |
| 228 // For a clean URL, trim the parameters from the hash. | |
| 229 window.location.hash = window.location.hash.substring(0, queryPos); | |
| 230 } | |
| 231 | |
| 232 // Set the initial description text. | |
| 233 $('description-text').textContent = parameters['description']; | |
| 234 | |
| 235 // Get a list of issues that we allow the user to select from. | |
| 236 // Note, the order and the issues types themselves are different | |
| 237 // between Chromium and Chromium OS, so this code needs to be | |
| 238 // maintained individually between in these two sections. | |
| 239 var issueTypeText = []; | |
| 240 issueTypeText[0] = localStrings.getString('issue-choose'); | |
| 241 <if expr="not pp_ifdef('chromeos')"> | |
| 242 issueTypeText[1] = localStrings.getString('issue-page-formatting'); | |
| 243 issueTypeText[2] = localStrings.getString('issue-page-load'); | |
| 244 issueTypeText[3] = localStrings.getString('issue-plugins'); | |
| 245 issueTypeText[4] = localStrings.getString('issue-tabs'); | |
| 246 issueTypeText[5] = localStrings.getString('issue-sync'); | |
| 247 issueTypeText[6] = localStrings.getString('issue-crashes'); | |
| 248 issueTypeText[7] = localStrings.getString('issue-extensions'); | |
| 249 issueTypeText[8] = localStrings.getString('issue-phishing'); | |
| 250 issueTypeText[9] = localStrings.getString('issue-other'); | |
| 251 var numDefaultIssues = issueTypeText.length; | |
| 252 issueTypeText[10] = localStrings.getString('issue-autofill'); | |
| 253 </if> | |
| 254 <if expr="pp_ifdef('chromeos')"> | |
| 255 issueTypeText[1] = localStrings.getString('issue-connectivity'); | |
| 256 issueTypeText[2] = localStrings.getString('issue-sync'); | |
| 257 issueTypeText[3] = localStrings.getString('issue-crashes'); | |
| 258 issueTypeText[4] = localStrings.getString('issue-page-formatting'); | |
| 259 issueTypeText[5] = localStrings.getString('issue-extensions'); | |
| 260 issueTypeText[6] = localStrings.getString('issue-standby'); | |
| 261 issueTypeText[7] = localStrings.getString('issue-phishing'); | |
| 262 issueTypeText[8] = localStrings.getString('issue-other'); | |
| 263 var numDefaultIssues = issueTypeText.length; | |
| 264 issueTypeText[9] = localStrings.getString('issue-autofill'); | |
| 265 </if> | |
| 266 // Add all the issues to the selection box. | |
| 267 for (var i = 0; i < issueTypeText.length; i++) { | |
| 268 var option = document.createElement('option'); | |
| 269 option.className = 'bug-report-text'; | |
| 270 option.textContent = issueTypeText[i]; | |
| 271 if (('' + i) === parameters['issueType']) | |
| 272 option.selected = true; | |
| 273 | |
| 274 if (i < numDefaultIssues || option.selected) | |
| 275 $('issue-with-combo').add(option); | |
| 276 } | |
| 277 | |
| 278 chrome.send('getDialogDefaults', []); | |
| 279 chrome.send('refreshCurrentScreenshot', []); | |
| 280 }; | |
| 281 | |
| 282 function setupCurrentScreenshot(screenshot) { | |
| 283 addScreenshot('current-screenshots', screenshot); | |
| 284 } | |
| 285 | |
| 286 function setupSavedScreenshots(screenshots) { | |
| 287 if (screenshots.length == 0) { | |
| 288 $('saved-screenshots').textContent = | |
| 289 localStrings.getString('no-saved-screenshots'); | |
| 290 | |
| 291 // Make sure we make the display the message. | |
| 292 $('saved-screenshots').style.display = 'block'; | |
| 293 | |
| 294 // In case the user tries to send now; fail safe, do not send a screenshot | |
| 295 // at all versus sending the current screenshot. | |
| 296 selectedThumbnailDivId = ''; | |
| 297 selectedThumbnailId = ''; | |
| 298 } else { | |
| 299 for (i = 0; i < screenshots.length; ++i) | |
| 300 addScreenshot('saved-screenshots', screenshots[i]); | |
| 301 | |
| 302 // Now that we have our screenshots, try selecting the saved screenshots | |
| 303 // again. | |
| 304 savedSelected(); | |
| 305 } | |
| 306 } | |
| 307 | |
| 308 function setupDialogDefaults(defaults) { | |
| 309 if (defaults.length > 0) { | |
| 310 $('page-url-text').value = defaults[0]; | |
| 311 if (defaults[0] == '') | |
| 312 $('page-url-checkbox').checked = false; | |
| 313 | |
| 314 if (defaults.length > 2) { | |
| 315 // We're in Chromium OS. | |
| 316 $('user-email-text').textContent = defaults[2]; | |
| 317 if (defaults[2] == '') { | |
| 318 // if we didn't get an e-mail address from cros, | |
| 319 // disable the user email display totally. | |
| 320 $('user-email-table').style.display = 'none'; | |
| 321 | |
| 322 // this also means we are in privacy mode, so no saved screenshots. | |
| 323 $('screenshot-link-tosaved').style.display = 'none'; | |
| 324 } | |
| 325 } | |
| 326 } | |
| 327 } | |
| 328 | |
| 329 window.addEventListener('DOMContentLoaded', load); | |
| OLD | NEW |