| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('editSearchEngineDialog', function() { | 5 cr.define('editSearchEngineDialog', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Flag inidicating if we are in the process of validating input. While |
| 10 * validating, the validity of the inputs is indeterminate. |
| 11 * @type {boolean} |
| 12 * @private |
| 13 */ |
| 14 var isValidating_ = false; |
| 15 |
| 16 /** |
| 9 * Disables the controls while the dialog is busy. | 17 * Disables the controls while the dialog is busy. |
| 10 */ | 18 */ |
| 11 function disableControls() { | 19 function disableControls() { |
| 12 $('cancel').disabled = true; | 20 $('cancel').disabled = true; |
| 13 $('save').disabled = true; | 21 $('save').disabled = true; |
| 14 } | 22 } |
| 15 | 23 |
| 16 /** | 24 /** |
| 17 * Close the dialog and pass a result value to the dialog close handler. | 25 * Close the dialog and pass a result value to the dialog close handler. |
| 18 * @param {{description: string, details: string, url: string}=} opt_result | 26 * @param {{description: string, details: string, url: string}=} opt_result |
| (...skipping 24 matching lines...) Expand all Loading... |
| 43 */ | 51 */ |
| 44 function setValidImage(element, valid) { | 52 function setValidImage(element, valid) { |
| 45 element.className = valid ? 'valid' : 'invalid'; | 53 element.className = valid ? 'valid' : 'invalid'; |
| 46 } | 54 } |
| 47 | 55 |
| 48 /** | 56 /** |
| 49 * Sends all strings to Chrome for validation. Chrome is expected to respond | 57 * Sends all strings to Chrome for validation. Chrome is expected to respond |
| 50 * by calling setValidation. | 58 * by calling setValidation. |
| 51 */ | 59 */ |
| 52 function validate() { | 60 function validate() { |
| 61 isValidating_ = true; |
| 53 chrome.send('requestValidation', [$('description-text').value, | 62 chrome.send('requestValidation', [$('description-text').value, |
| 54 $('keyword-text').value, $('url-text').value]); | 63 $('keyword-text').value, $('url-text').value]); |
| 55 } | 64 } |
| 56 | 65 |
| 57 /** | 66 /** |
| 58 * Sets dialog state given the results of the validation of input by Chrome. | 67 * Sets dialog state given the results of the validation of input by Chrome. |
| 59 * @param {{description: boolean, details: boolean, url: boolean, ok:boolean}} | 68 * @param {{description: boolean, |
| 60 * details A dictionary of booleans indicating the validation results of | 69 keyword: boolean, |
| 61 * various parts of the UI. |description|, |details| and |url| indicate | 70 url: boolean, |
| 62 * the validity of the respective text fields, and |ok| indicates whether | 71 ok: boolean}} details |
| 72 * A dictionary of booleans indicating the validation results of various |
| 73 * parts of the UI. |description|, |keyword| and |url| indicate the |
| 74 * validity of the respective text fields, and |ok| indicates whether |
| 63 * the OK/Save button can be pressed. | 75 * the OK/Save button can be pressed. |
| 64 */ | 76 */ |
| 65 function setValidation(details) { | 77 function setValidation(details) { |
| 66 setValidImage($('description-icon'), details.description); | 78 setValidImage($('description-icon'), details.description); |
| 67 setValidImage($('keyword-icon'), details.keyword); | 79 setValidImage($('keyword-icon'), details.keyword); |
| 68 setValidImage($('url-icon'), details.url); | 80 setValidImage($('url-icon'), details.url); |
| 69 $('save').disabled = !details.ok; | 81 $('save').disabled = !details.ok; |
| 82 isValidating_ = false; |
| 70 } | 83 } |
| 71 | 84 |
| 72 /** | 85 /** |
| 73 * Reverses the order of child nodes. | 86 * Reverses the order of child nodes. |
| 74 * @param {HTMLElement} parent The parent node whose children are to be | 87 * @param {HTMLElement} parent The parent node whose children are to be |
| 75 * reversed. | 88 * reversed. |
| 76 */ | 89 */ |
| 77 function reverseChildren(parent) { | 90 function reverseChildren(parent) { |
| 78 var childNodes = parent.childNodes; | 91 var childNodes = parent.childNodes; |
| 79 for (var i = childNodes.length - 1; i >= 0; i--) | 92 for (var i = childNodes.length - 1; i >= 0; i--) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 101 url: $('url-text').value}); | 114 url: $('url-text').value}); |
| 102 } | 115 } |
| 103 | 116 |
| 104 $('description-text').oninput = validate; | 117 $('description-text').oninput = validate; |
| 105 $('keyword-text').oninput = validate; | 118 $('keyword-text').oninput = validate; |
| 106 $('url-text').oninput = validate; | 119 $('url-text').oninput = validate; |
| 107 | 120 |
| 108 setValidation({description: false, keyword: false, url: false}); | 121 setValidation({description: false, keyword: false, url: false}); |
| 109 if (cr.isViews) | 122 if (cr.isViews) |
| 110 forEach(document.querySelectorAll('.button-strip'), reverseChildren); | 123 forEach(document.querySelectorAll('.button-strip'), reverseChildren); |
| 111 chrome.send('requestDetails') | 124 // Mark that we are in the process of validating, since the 'send' call |
| 125 // is asynchronous. Until the next call to 'setValidation' complete, the |
| 126 // validity of the inputs is in an indeterminate state. |
| 127 isValidating_ = true; |
| 128 chrome.send('requestDetails'); |
| 129 } |
| 130 |
| 131 /** |
| 132 * Indicates if we are in the process of validating input. |
| 133 * @return {boolean} True if validation is in progress. |
| 134 */ |
| 135 function isValidating() { |
| 136 return isValidating_; |
| 112 } | 137 } |
| 113 | 138 |
| 114 document.addEventListener('DOMContentLoaded', initialize); | 139 document.addEventListener('DOMContentLoaded', initialize); |
| 115 | 140 |
| 116 return { | 141 return { |
| 142 isValidating: isValidating, |
| 117 setDetails: setDetails, | 143 setDetails: setDetails, |
| 118 setValidation: setValidation, | 144 setValidation: setValidation, |
| 119 }; | 145 }; |
| 120 }); | 146 }); |
| 121 | 147 |
| 122 | 148 |
| OLD | NEW |