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 cr.define('editSearchEngineDialog', function() { |
| 6 'use strict'; |
| 7 |
| 8 /** |
| 9 * Disables the controls while the dialog is busy. |
| 10 */ |
| 11 function disableControls() { |
| 12 $('cancel').disabled = true; |
| 13 $('save').disabled = true; |
| 14 } |
| 15 |
| 16 /** |
| 17 * Close the dialog and pass a result value to the dialog close handler. |
| 18 * @param {{description: string, details: string, url: string}=} opt_result |
| 19 * The value to pass to the dialog close handler. |
| 20 */ |
| 21 function closeWithResult(opt_result) { |
| 22 disableControls(); |
| 23 var json = JSON.stringify(opt_result ? [opt_result] : []); |
| 24 chrome.send('DialogClose', [json]); |
| 25 } |
| 26 |
| 27 /** |
| 28 * Sets the text of the dialog's editable text boxes. |
| 29 * @param {{description: string, details: string, url: string}} details Values |
| 30 * for corresponding text fields. |
| 31 */ |
| 32 function setDetails(details) { |
| 33 $('description-text').value = details.description; |
| 34 $('keyword-text').value = details.keyword; |
| 35 $('url-text').value = details.url; |
| 36 } |
| 37 |
| 38 /** |
| 39 * Inserts translated strings on loading. |
| 40 */ |
| 41 function initialize() { |
| 42 i18nTemplate.process(document, templateData); |
| 43 |
| 44 document.title = chrome.dialogArguments == 'add' ? templateData.titleNew : |
| 45 templateData.titleEdit; |
| 46 |
| 47 $('cancel').onclick = function() { |
| 48 closeWithResult(); |
| 49 } |
| 50 |
| 51 $('save').onclick = function() { |
| 52 closeWithResult({description: $('description-text').value, |
| 53 keyword: $('keyword-text').value, |
| 54 url: $('url-text').value}); |
| 55 } |
| 56 |
| 57 chrome.send('requestDetails') |
| 58 } |
| 59 |
| 60 return { |
| 61 initialize: initialize, |
| 62 setDetails: setDetails, |
| 63 }; |
| 64 }); |
| 65 |
| 66 document.addEventListener('DOMContentLoaded', |
| 67 editSearchEngineDialog.initialize); |
OLD | NEW |