OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 Polymer({ | 5 Polymer({ |
6 is: 'bookmarks-edit-dialog', | 6 is: 'bookmarks-edit-dialog', |
7 | 7 |
8 behaviors: [ | 8 behaviors: [ |
9 Polymer.IronA11yKeysBehavior, | 9 Polymer.IronA11yKeysBehavior, |
10 ], | 10 ], |
(...skipping 15 matching lines...) Expand all Loading... |
26 keyBindings: { | 26 keyBindings: { |
27 'enter': 'onSaveButtonTap_', | 27 'enter': 'onSaveButtonTap_', |
28 }, | 28 }, |
29 | 29 |
30 /** @param {BookmarkNode} editItem */ | 30 /** @param {BookmarkNode} editItem */ |
31 showEditDialog: function(editItem) { | 31 showEditDialog: function(editItem) { |
32 this.editItem_ = editItem; | 32 this.editItem_ = editItem; |
33 this.isFolder_ = !editItem.url; | 33 this.isFolder_ = !editItem.url; |
34 | 34 |
35 this.titleValue_ = editItem.title; | 35 this.titleValue_ = editItem.title; |
36 if (!this.isFolder_) | 36 if (!this.isFolder_) { |
| 37 this.$.url.invalid = false; |
37 this.urlValue_ = assert(editItem.url); | 38 this.urlValue_ = assert(editItem.url); |
| 39 } |
38 | 40 |
39 this.$.dialog.showModal(); | 41 this.$.dialog.showModal(); |
40 }, | 42 }, |
41 | 43 |
42 /** | 44 /** |
43 * @param {boolean} isFolder | 45 * @param {boolean} isFolder |
44 * @return {string} | 46 * @return {string} |
45 * @private | 47 * @private |
46 */ | 48 */ |
47 getDialogTitle_: function(isFolder) { | 49 getDialogTitle_: function(isFolder) { |
48 return loadTimeData.getString( | 50 return loadTimeData.getString( |
49 isFolder ? 'renameFolderTitle' : 'editBookmarkTitle'); | 51 isFolder ? 'renameFolderTitle' : 'editBookmarkTitle'); |
50 }, | 52 }, |
51 | 53 |
| 54 /** |
| 55 * Validates the value of the URL field, returning true if it is a valid URL. |
| 56 * May modify the value by prepending 'http://' in order to make it valid. |
| 57 * @return {boolean} |
| 58 * @private |
| 59 */ |
| 60 validateUrl_: function() { |
| 61 var urlInput = /** @type {PaperInputElement} */ (this.$.url); |
| 62 var originalValue = this.urlValue_; |
| 63 |
| 64 if (urlInput.validate()) |
| 65 return true; |
| 66 |
| 67 this.urlValue_ = 'http://' + originalValue; |
| 68 |
| 69 if (urlInput.validate()) |
| 70 return true; |
| 71 |
| 72 this.urlValue_ = originalValue; |
| 73 return false; |
| 74 }, |
| 75 |
52 /** @private */ | 76 /** @private */ |
53 onSaveButtonTap_: function() { | 77 onSaveButtonTap_: function() { |
54 // TODO(tsergeant): Verify values. | |
55 var edit = {'title': this.titleValue_}; | 78 var edit = {'title': this.titleValue_}; |
56 if (!this.isFolder_) | 79 if (!this.isFolder_) { |
| 80 if (!this.validateUrl_()) |
| 81 return; |
| 82 |
57 edit['url'] = this.urlValue_; | 83 edit['url'] = this.urlValue_; |
| 84 } |
58 | 85 |
59 chrome.bookmarks.update(this.editItem_.id, edit); | 86 chrome.bookmarks.update(this.editItem_.id, edit); |
60 this.$.dialog.close(); | 87 this.$.dialog.close(); |
61 }, | 88 }, |
62 | 89 |
63 /** @private */ | 90 /** @private */ |
64 onCancelButtonTap_: function() { | 91 onCancelButtonTap_: function() { |
65 this.$.dialog.cancel(); | 92 this.$.dialog.cancel(); |
66 }, | 93 }, |
67 }); | 94 }); |
OLD | NEW |