Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: chrome/browser/resources/edit_search_engine_dialog.js

Issue 8118012: WebUI Edit Search Engine Dialog (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: validation images and button-strip fixups Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 validate();
37 }
38
39 /**
40 * Updates the validity icon element by changing its style.
41 * @param {element} element The element to change.
42 * @param {boolean} valid True if the data is valid.
43 */
44 function setValidImage(element, valid) {
45 element.className = valid ? 'valid' : 'invalid';
46 }
47
48 /**
49 * Sends all strings to Chrome for validation. Chrome is expected to respond
50 * by calling setValidation.
51 */
52 function validate() {
53 chrome.send('requestValidation', [$('description-text').value,
54 $('keyword-text').value, $('url-text').value]);
55 }
56
57 /**
58 * Sets dialog state given the results of the validation of input by Chrome.
59 * @param {{description: boolean, details: boolean, url: boolean, ok:boolean}}
60 * details A dictionary of booleans indicating the validation results of
61 * various parts of the UI. |description|, |details| and |url| indicate
62 * the validity of the respective text fields, and |ok| indicates whether
63 * the OK/Save button can be pressed.
64 */
65 function setValidation(details) {
66 setValidImage($('description-icon'), details.description);
67 setValidImage($('keyword-icon'), details.keyword);
68 setValidImage($('url-icon'), details.url);
69 $('save').disabled = !details.ok;
70 }
71
72 /**
73 * Inserts translated strings on loading.
74 */
75 function initialize() {
76 i18nTemplate.process(document, templateData);
77
78 document.title = chrome.dialogArguments == 'add' ? templateData.titleNew :
79 templateData.titleEdit;
80
81 $('cancel').onclick = function() {
82 closeWithResult();
83 }
84
85 $('save').onclick = function() {
86 closeWithResult({description: $('description-text').value,
87 keyword: $('keyword-text').value,
88 url: $('url-text').value});
89 }
90
91 $('description-text').oninput = validate;
92 $('keyword-text').oninput = validate;
93 $('url-text').oninput = validate;
94
95 setValidation({description: false, keyword: false, url: false});
96
97 chrome.send('requestDetails')
98 }
99
100 return {
101 initialize: initialize,
102 setDetails: setDetails,
103 setValidation: setValidation,
104 };
105 });
106
107 document.addEventListener('DOMContentLoaded',
arv (Not doing code reviews) 2011/10/11 17:56:08 I would keep this inside the closure above, then y
108 editSearchEngineDialog.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698