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

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

Issue 8438037: Change 'Add Page' to show a simple input dialog with --use-more-webui. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years, 1 month 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
OLDNEW
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('inputWindowDialog', function() { 5 cr.define('inputWindowDialog', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * Disables the controls while the dialog is busy. 9 * Disables the controls while the dialog is busy.
10 */ 10 */
11 function disableControls() { 11 function disableControls() {
12 $('cancel').disabled = true; 12 $('cancel').disabled = true;
13 $('ok').disabled = true; 13 $('ok').disabled = true;
14 } 14 }
15 15
16 /** 16 /**
17 * Close the dialog and pass a result value to the dialog close handler. 17 * Close the dialog and pass a result value to the dialog close handler.
18 * @param {boolean} result The value to pass to the dialog close handler. 18 * @param {boolean} result The value to pass to the dialog close handler.
19 */ 19 */
20 function closeWithResult(result) { 20 function closeWithResult(result) {
21 disableControls(); 21 disableControls();
22 var value = [result]; 22 var values = [result];
23 if (result) { 23 if (result) {
24 value.push($('name').value); 24 values.push($('name').value);
25 if ($('url-area').style.display != 'none') {
flackr 2011/11/02 15:38:18 Use class to determine whether a URL is being edit
mazda 2011/11/07 09:59:23 Done. I added a function to check if a URL field i
26 values.push($('url').value);
27 }
25 } 28 }
26 var json = JSON.stringify(value); 29 var json = JSON.stringify(values);
27 chrome.send('DialogClose', [json]); 30 chrome.send('DialogClose', [json]);
28 } 31 }
29 32
30 /** 33 /**
31 * Inserts translated strings on loading. 34 * Inserts translated strings on loading.
32 */ 35 */
33 function initialize() { 36 function initialize() {
34 i18nTemplate.process(document, templateData); 37 i18nTemplate.process(document, templateData);
35 38
36 var args = JSON.parse(chrome.dialogArguments); 39 var args = JSON.parse(chrome.dialogArguments);
37 $('name-label').textContent = args.label; 40 $('name-label').textContent = args.nameLabel;
38 $('name').value = args.contents; 41 $('name').value = args.name;
42
43 if (args.urlLabel && args.url) {
44 $('url-label').textContent = args.urlLabel;
45 $('url').value = args.url;
46 $('url-area').style.display = '-webkit-box';
flackr 2011/11/02 15:38:18 Use class to toggle CSS properties.
mazda 2011/11/07 09:59:23 Done.
47 } else {
48 $('url-area').style.display = 'none';
49 }
39 50
40 $('cancel').onclick = function() { 51 $('cancel').onclick = function() {
41 closeWithResult(false); 52 closeWithResult(false);
42 } 53 }
43 54
44 $('ok').onclick = function() { 55 $('ok').onclick = function() {
45 if (!$('ok').disabled) { 56 if (!$('ok').disabled) {
46 closeWithResult(true); 57 closeWithResult(true);
47 } 58 }
48 } 59 }
49 60
50 $('name').oninput = function() { 61 function validate() {
51 var name = $('name').value; 62 var values = [$('name').value]
52 chrome.send('validate', [name]); 63 if ($('url-area').style.display != 'none') {
flackr 2011/11/02 15:38:18 Same as above, check class instead of style.
mazda 2011/11/07 09:59:23 Done.
64 values.push($('url').value);
65 }
66 chrome.send('validate', values);
53 } 67 }
54 68
69 $('name').oninput = validate;
70 $('url').oninput = $('url-area').style.display != 'none' ? validate : null;
71
55 document.body.onkeydown = function(evt) { 72 document.body.onkeydown = function(evt) {
56 if (evt.keyCode == 13) { // Enter key 73 if (evt.keyCode == 13) { // Enter key
57 $('ok').onclick(); 74 $('ok').onclick();
58 } else if (evt.keyCode == 27) { // Escape key 75 } else if (evt.keyCode == 27) { // Escape key
59 $('cancel').onclick(); 76 $('cancel').onclick();
60 } 77 }
61 } 78 }
62 } 79 }
63 80
64 /** 81 /**
65 * Called in response to validate request. 82 * Called in response to validate request.
66 * @param {boolean} valid The result of validate request. 83 * @param {boolean} valid The result of validate request.
67 */ 84 */
68 function ackValidation(valid) { 85 function ackValidation(valid) {
69 $('ok').disabled = !valid; 86 $('ok').disabled = !valid;
70 } 87 }
71 88
72 return { 89 return {
73 initialize: initialize, 90 initialize: initialize,
74 ackValidation: ackValidation, 91 ackValidation: ackValidation,
75 }; 92 };
76 }); 93 });
77 94
78 document.addEventListener('DOMContentLoaded', inputWindowDialog.initialize); 95 document.addEventListener('DOMContentLoaded', inputWindowDialog.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698