| OLD | NEW |
| 1 <!-- | 1 <!-- |
| 2 * Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 2 * Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 3 * source code is governed by a BSD-style license that can be found in the | 3 * source code is governed by a BSD-style license that can be found in the |
| 4 * LICENSE file. | 4 * LICENSE file. |
| 5 --> | 5 --> |
| 6 <html> | 6 <html> |
| 7 <head> | 7 <head> |
| 8 <title></title> | 8 <title></title> |
| 9 <link rel="stylesheet" href="style.css" type="text/css" /> | 9 <link rel="stylesheet" href="style.css" type="text/css" /> |
| 10 <style> | 10 <style> |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 .urlAssist { | 103 .urlAssist { |
| 104 padding-left: 30px; | 104 padding-left: 30px; |
| 105 } | 105 } |
| 106 | 106 |
| 107 .status { | 107 .status { |
| 108 background-color: #FFF18A; | 108 background-color: #FFF18A; |
| 109 } | 109 } |
| 110 | 110 |
| 111 </style> | 111 </style> |
| 112 <script type="text/javascript" src="common.js"></script> | 112 <script type="text/javascript" src="common.js"></script> |
| 113 <script> | 113 <script type="text/javascript" src="options.js"></script> |
| 114 | |
| 115 // Various text messages within the edit dialog. | |
| 116 var assistText = chrome.i18n.getMessage("rss_subscription_feed_url_assist"); | |
| 117 | |
| 118 // Specifies the index of the item we are editing or -1 if adding new. | |
| 119 var editingIndex = -1; | |
| 120 // Whether we are currently editing the default item. | |
| 121 var editingDefault = false; | |
| 122 | |
| 123 function main() { | |
| 124 document.title = | |
| 125 chrome.i18n.getMessage("rss_subscription_edit_dialog_title"); | |
| 126 | |
| 127 // Make sure the dialog is not visible. | |
| 128 document.getElementById('dialogBackground').style.display = "none"; | |
| 129 | |
| 130 // Make sure the buttons are disabled to begin with. | |
| 131 document.getElementById('editReader').disabled = true; | |
| 132 document.getElementById('removeReader').disabled = true; | |
| 133 document.getElementById('setDefault').disabled = true; | |
| 134 | |
| 135 if (!storageEnabled) { | |
| 136 document.getElementById('addReader').disabled = true; | |
| 137 document.getElementById('readerListbox').disabled = true; | |
| 138 document.getElementById('alwaysUseDefault').disabled = true; | |
| 139 document.getElementById('resetList').disabled = true; | |
| 140 | |
| 141 alert(chrome.i18n.getMessage("rss_subscription_no_localstorage")); | |
| 142 return; | |
| 143 } | |
| 144 | |
| 145 var feedReaderList; | |
| 146 if (window.localStorage.readerList) { | |
| 147 feedReaderList = JSON.parse(window.localStorage.readerList); | |
| 148 } else { | |
| 149 feedReaderList = defaultReaderList(); | |
| 150 window.localStorage.readerList = JSON.stringify(feedReaderList); | |
| 151 } | |
| 152 | |
| 153 // If there is no default, set the first item as default. | |
| 154 if (isDefaultReader("") && feedReaderList.length > 0) | |
| 155 window.localStorage.defaultReader = feedReaderList[0].url; | |
| 156 | |
| 157 // Populate the list of readers. | |
| 158 var readerListbox = document.getElementById('readerListbox'); | |
| 159 while (readerListbox.options.length > 0) | |
| 160 readerListbox.remove(0); | |
| 161 for (i = 0; i < feedReaderList.length; ++i) { | |
| 162 var description = feedReaderList[i].description; | |
| 163 if (isDefaultReader(feedReaderList[i].url)) | |
| 164 description += " " + chrome.i18n.getMessage("rss_subscription_default"); | |
| 165 readerListbox.add(new Option(description, feedReaderList[i].url)); | |
| 166 } | |
| 167 | |
| 168 // Set up the 'show preview?' checkbox. | |
| 169 var skipPreview = document.getElementById('alwaysUseDefault'); | |
| 170 skipPreview.checked = window.localStorage.showPreviewPage == "No"; | |
| 171 } | |
| 172 | |
| 173 function toggleFeedPreview() { | |
| 174 var alwaysUseDefault = document.getElementById('alwaysUseDefault'); | |
| 175 if (alwaysUseDefault.checked) | |
| 176 window.localStorage.showPreviewPage = "No"; | |
| 177 else | |
| 178 delete window.localStorage.showPreviewPage; | |
| 179 } | |
| 180 | |
| 181 function setDefault() { | |
| 182 var readerListbox = document.getElementById('readerListbox'); | |
| 183 var selection = readerListbox.options[readerListbox.selectedIndex]; | |
| 184 window.localStorage.defaultReader = selection.value; | |
| 185 | |
| 186 // Reinititalize the page. | |
| 187 main(); | |
| 188 } | |
| 189 | |
| 190 function resetList() { | |
| 191 if (!confirm(chrome.i18n.getMessage( | |
| 192 "rss_subscription_reset_list_confirm"))) { | |
| 193 return; | |
| 194 } | |
| 195 | |
| 196 delete window.localStorage.readerList; | |
| 197 delete window.localStorage.defaultReader; | |
| 198 delete window.localStorage.showPreviewPage; | |
| 199 | |
| 200 // Reinititalize the page. | |
| 201 main(); | |
| 202 } | |
| 203 | |
| 204 function onSelectionChanged() { | |
| 205 var selected = readerListbox.selectedIndex > -1; | |
| 206 // To edit a reader something must be selected. | |
| 207 document.getElementById('editReader').disabled = !selected; | |
| 208 // To set default, the current selection cannot already be default. | |
| 209 document.getElementById('setDefault').disabled = !selected || | |
| 210 isDefaultReader(readerListbox[readerListbox.selectedIndex].value); | |
| 211 // To remove the selected reader it must not be the last item. | |
| 212 document.getElementById('removeReader').disabled = | |
| 213 !selected || readerListbox.options.length < 2; | |
| 214 } | |
| 215 | |
| 216 function editReader(index) { | |
| 217 var readerListbox = document.getElementById('readerListbox'); | |
| 218 | |
| 219 if (index == -1) { | |
| 220 // Adding a new item, make sure the text boxes are empty. | |
| 221 document.getElementById('urlText').value = ""; | |
| 222 document.getElementById('descriptionText').value = ""; | |
| 223 editingIndex = -1; // New item. | |
| 224 editingDefault = true; // New items become default items. | |
| 225 } else if (index == 0) { | |
| 226 // Editing some item, find the current item index and store it. | |
| 227 editingIndex = readerListbox.selectedIndex; | |
| 228 var oldOption = readerListbox.options[editingIndex]; | |
| 229 document.getElementById('urlText').value = oldOption.value; | |
| 230 document.getElementById('descriptionText').value = | |
| 231 oldOption.text.replace( | |
| 232 ' ' + chrome.i18n.getMessage("rss_subscription_default"), ''); | |
| 233 editingDefault = isDefaultReader(oldOption.value); | |
| 234 } | |
| 235 | |
| 236 showDialog(); | |
| 237 } | |
| 238 | |
| 239 function removeReader() { | |
| 240 var index = readerListbox.selectedIndex; | |
| 241 var feedReaderList = JSON.parse(window.localStorage.readerList); | |
| 242 var reply = | |
| 243 confirm(chrome.i18n.getMessage("rss_subscription_remove_confirm", | |
| 244 feedReaderList[index].description)); | |
| 245 if (reply) { | |
| 246 var wasDefault = isDefaultReader(feedReaderList[index].url); | |
| 247 // Remove the item from the list. | |
| 248 feedReaderList.splice(index, 1); | |
| 249 window.localStorage.readerList = JSON.stringify(feedReaderList); | |
| 250 | |
| 251 if (wasDefault) | |
| 252 window.localStorage.defaultReader = feedReaderList[0].url; | |
| 253 } | |
| 254 | |
| 255 main(); | |
| 256 } | |
| 257 | |
| 258 /** | |
| 259 * Shows the Edit Feed Reader dialog. | |
| 260 */ | |
| 261 function showDialog() { | |
| 262 document.getElementById('urlAssist').innerText = assistText; | |
| 263 document.getElementById('save').disabled = true; | |
| 264 | |
| 265 // Show the dialog box. | |
| 266 document.getElementById('dialogBackground').style.display = "-webkit-box"; | |
| 267 } | |
| 268 | |
| 269 /** | |
| 270 * Hides the Edit Feed Reader dialog. | |
| 271 */ | |
| 272 function hideDialog() { | |
| 273 document.getElementById('dialogBackground').style.display = "none"; | |
| 274 } | |
| 275 | |
| 276 /** | |
| 277 * Validates the input in the form (making sure something is entered in both | |
| 278 * fields and that %s is not missing from the url field. | |
| 279 */ | |
| 280 function validateInput() { | |
| 281 document.getElementById('statusMsg').innerText = ""; | |
| 282 | |
| 283 var description = document.getElementById('descriptionText'); | |
| 284 var url = document.getElementById('urlText'); | |
| 285 | |
| 286 var valid = description.value.length > 0 && | |
| 287 url.value.length > 0 && | |
| 288 url.value.indexOf("%s") > -1; | |
| 289 | |
| 290 document.getElementById('save').disabled = !valid; | |
| 291 } | |
| 292 | |
| 293 /** | |
| 294 * Handler for saving the values. | |
| 295 */ | |
| 296 function save() { | |
| 297 // Get the old list. | |
| 298 var feedReaderList = JSON.parse(window.localStorage.readerList); | |
| 299 | |
| 300 var url = document.getElementById('urlText').value; | |
| 301 var description = document.getElementById('descriptionText').value; | |
| 302 | |
| 303 if (editingIndex == -1) { | |
| 304 // Construct a new list. | |
| 305 var newFeedList = []; | |
| 306 | |
| 307 // Add the new item. | |
| 308 newFeedList.push({ 'url': url, 'description': description }); | |
| 309 | |
| 310 for (i = 0; i < feedReaderList.length; ++i) | |
| 311 newFeedList.push(feedReaderList[i]); | |
| 312 | |
| 313 feedReaderList = newFeedList; | |
| 314 } else { | |
| 315 feedReaderList[editingIndex].url = url; | |
| 316 feedReaderList[editingIndex].description = description; | |
| 317 } | |
| 318 | |
| 319 window.localStorage.readerList = JSON.stringify(feedReaderList); | |
| 320 | |
| 321 // Retain item default status, in case the url changed while editing item. | |
| 322 if (editingDefault) | |
| 323 window.localStorage.defaultReader = url; | |
| 324 | |
| 325 hideDialog(); | |
| 326 | |
| 327 // Reload the values from scratch. | |
| 328 main(); | |
| 329 } | |
| 330 | |
| 331 function init() { | |
| 332 i18nReplace('rss_subscription_options'); | |
| 333 i18nReplaceImpl('addReader', 'rss_subscription_add_reader'); | |
| 334 i18nReplaceImpl('editReader', 'rss_subscription_edit_reader'); | |
| 335 i18nReplaceImpl('removeReader', 'rss_subscription_remove_reader'); | |
| 336 i18nReplaceImpl('setDefault', 'rss_subscription_make_default_reader'); | |
| 337 i18nReplaceImpl('resetList', 'rss_subscription_reset_list'); | |
| 338 i18nReplace('rss_subscription_always_use_default'); | |
| 339 i18nReplaceImpl('dialogHeader', 'rss_subscription_edit_dialog_title'); | |
| 340 i18nReplace('rss_subscription_feed_description'); | |
| 341 i18nReplace('rss_subscription_feed_url'); | |
| 342 i18nReplaceImpl('save', 'rss_subscription_save_button', 'value'); | |
| 343 i18nReplaceImpl('rss_subscription_close_button', | |
| 344 'rss_subscription_close_button', 'value'); | |
| 345 main(); | |
| 346 } | |
| 347 </script> | |
| 348 </head> | 114 </head> |
| 349 <body onload="init()"> | 115 <body> |
| 350 <table border="0"> | 116 <table border="0"> |
| 351 <tr> | 117 <tr> |
| 352 <td valign="top" width="16"> | 118 <td valign="top" width="16"> |
| 353 <img src="feed-icon-16x16.png" /> | 119 <img src="feed-icon-16x16.png" /> |
| 354 </td> | 120 </td> |
| 355 <td valign="middle"> | 121 <td valign="middle"> |
| 356 <strong id="rss_subscription_options"></strong> | 122 <strong id="rss_subscription_options"></strong> |
| 357 </td> | 123 </td> |
| 358 <td colspan="2"> | 124 <td colspan="2"> |
| 359 </td> | 125 </td> |
| 360 </tr> | 126 </tr> |
| 361 <tr> | 127 <tr> |
| 362 <td colspan="2"> | 128 <td colspan="2"> |
| 363 <select id="readerListbox" size="8" style="width:300;" | 129 <select id="readerListbox" size="8" style="width:300;"></select> |
| 364 onchange="onSelectionChanged()"></select> | |
| 365 </td> | 130 </td> |
| 366 <td valign="top"> | 131 <td valign="top"> |
| 367 <button style="width:100%;" id="addReader" onclick="editReader(-1)" | 132 <button style="width:100%;" id="addReader"></button><br /> |
| 368 ></button><br /> | 133 <button style="width:100%;" id="editReader"></button><br /> |
| 369 <button style="width:100%;" id="editReader" onclick="editReader(0)" | 134 <button style="width:100%;" id="removeReader"></button><br /> |
| 370 ></button><br /> | 135 <button style="width:100%;" id="setDefault"></button><br /> |
| 371 <button style="width:100%;" id="removeReader" onclick="removeReader()" | 136 <button style="width:100%;" id="resetList"></button><br /> |
| 372 ></button><br /> | |
| 373 <button style="width:100%;" id="setDefault" onclick="setDefault()" | |
| 374 ></button><br /> | |
| 375 <button style="width:100%;" id="resetList" onclick="resetList()" | |
| 376 ></button><br /> | |
| 377 </td> | 137 </td> |
| 378 <td style="width: 200px;"> | 138 <td style="width: 200px;"> |
| 379 </td> | 139 </td> |
| 380 </tr> | 140 </tr> |
| 381 <tr> | 141 <tr> |
| 382 <td colspan="4"> | 142 <td colspan="4"> |
| 383 <input type="checkbox" id="alwaysUseDefault" | 143 <input type="checkbox" id="alwaysUseDefault" |
| 384 value="alwaysUseDefault" onchange="toggleFeedPreview()" | 144 value="alwaysUseDefault" |
| 385 ><span id="rss_subscription_always_use_default"></span> | 145 ><span id="rss_subscription_always_use_default"></span> |
| 386 </td> | 146 </td> |
| 387 </tr> | 147 </tr> |
| 388 </table> | 148 </table> |
| 389 | 149 |
| 390 <div id="dialogBackground"> | 150 <div id="dialogBackground"> |
| 391 <div id="dialogHBackground"> | 151 <div id="dialogHBackground"> |
| 392 <div id="dialog"> | 152 <div id="dialog"> |
| 393 | 153 |
| 394 <div id="dialogHeader"></div> | 154 <div id="dialogHeader"></div> |
| 395 | 155 |
| 396 <div id="dialogBody"> | 156 <div id="dialogBody"> |
| 397 | 157 |
| 398 <div class="dialogRow"> | 158 <div class="dialogRow"> |
| 399 <div class="status" id="statusMsg"></div> | 159 <div class="status" id="statusMsg"></div> |
| 400 </div> | 160 </div> |
| 401 | 161 |
| 402 <div class="dialogRow"> | 162 <div class="dialogRow"> |
| 403 <div id="rss_subscription_feed_description"></div> | 163 <div id="rss_subscription_feed_description"></div> |
| 404 <div> | 164 <div> |
| 405 <input type="text" id="descriptionText" onkeyup="validateInput()"> | 165 <input type="text" id="descriptionText"> |
| 406 </div> | 166 </div> |
| 407 </div> | 167 </div> |
| 408 | 168 |
| 409 <div class="dialogRow"> | 169 <div class="dialogRow"> |
| 410 <div id="rss_subscription_feed_url"></div> | 170 <div id="rss_subscription_feed_url"></div> |
| 411 <div> | 171 <div> |
| 412 <input type="text" id="urlText" onkeyup="validateInput()"> | 172 <input type="text" id="urlText"> |
| 413 </div> | 173 </div> |
| 414 </div> | 174 </div> |
| 415 | 175 |
| 416 <div class="dialogRow"> | 176 <div class="dialogRow"> |
| 417 <div id="urlAssist" class="urlAssist"></div> | 177 <div id="urlAssist" class="urlAssist"></div> |
| 418 </div> | 178 </div> |
| 419 | 179 |
| 420 <div class="dialogRow" id="dialogContentFooter"> | 180 <div class="dialogRow" id="dialogContentFooter"> |
| 421 <div> | 181 <div> |
| 422 <input type="button" id="save" | 182 <input type="button" id="save"> |
| 423 onclick="save()"> | |
| 424 </div> | 183 </div> |
| 425 <div> | 184 <div> |
| 426 <input type="button" | 185 <input type="button" |
| 427 id="rss_subscription_close_button" | 186 id="rss_subscription_close_button" > |
| 428 onclick="hideDialog()"> | |
| 429 </div> | 187 </div> |
| 430 </div> | 188 </div> |
| 431 | 189 |
| 432 </div> <!-- /dialogBody --> | 190 </div> <!-- /dialogBody --> |
| 433 | 191 |
| 434 </div> | 192 </div> |
| 435 </div> | 193 </div> |
| 436 </div> | 194 </div> |
| 437 | 195 |
| 438 </body> | 196 </body> |
| 439 </html> | 197 </html> |
| OLD | NEW |