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 properties: { | 8 properties: { |
9 /** @private {BookmarkNode} */ | 9 /** @private {BookmarkNode} */ |
10 editItem_: Object, | 10 editItem_: Object, |
11 | 11 |
12 /** @private */ | 12 /** @private */ |
13 isFolder_: Boolean, | 13 isFolder_: Boolean, |
14 | 14 |
15 /** @private */ | 15 /** @private */ |
16 titleValue_: String, | 16 titleValue_: String, |
17 | 17 |
18 /** @private */ | 18 /** @private */ |
19 urlValue_: String, | 19 urlValue_: String, |
20 }, | 20 }, |
21 | 21 |
22 /** @param {BookmarkNode} editItem */ | 22 /** @param {BookmarkNode} editItem */ |
23 showEditDialog: function(editItem) { | 23 showEditDialog: function(editItem) { |
24 this.editItem_ = editItem; | 24 this.editItem_ = editItem; |
25 this.isFolder_ = !editItem.url; | 25 this.isFolder_ = !editItem.url; |
26 | 26 |
27 this.titleValue_ = editItem.title; | 27 this.titleValue_ = editItem.title; |
28 if (!this.isFolder_) | 28 if (!this.isFolder_) { |
29 this.$.url.invalid = false; | |
29 this.urlValue_ = assert(editItem.url); | 30 this.urlValue_ = assert(editItem.url); |
31 } | |
30 | 32 |
31 this.$.dialog.showModal(); | 33 this.$.dialog.showModal(); |
32 }, | 34 }, |
33 | 35 |
34 /** | 36 /** |
35 * @param {boolean} isFolder | 37 * @param {boolean} isFolder |
36 * @return {string} | 38 * @return {string} |
37 * @private | 39 * @private |
38 */ | 40 */ |
39 getDialogTitle_: function(isFolder) { | 41 getDialogTitle_: function(isFolder) { |
40 return loadTimeData.getString( | 42 return loadTimeData.getString( |
41 isFolder ? 'renameFolderTitle' : 'editBookmarkTitle'); | 43 isFolder ? 'renameFolderTitle' : 'editBookmarkTitle'); |
42 }, | 44 }, |
43 | 45 |
46 /** | |
47 * Validates the value of the URL field, returning true if it is a valid URL. | |
48 * May modify the value by prepending 'http://' in order to make it valid. | |
49 * @return {boolean} | |
50 * @private | |
51 */ | |
52 validateUrl_: function() { | |
53 var urlInput = /** @type {PaperInputElement} */ (this.$.url); | |
54 var originalValue = this.urlValue_; | |
55 | |
56 if (urlInput.validate()) | |
57 return true; | |
58 | |
59 this.urlValue_ = 'http://' + originalValue; | |
60 | |
61 if (urlInput.validate()) | |
62 return true; | |
63 | |
64 this.urlValue_ = originalValue; | |
calamity
2017/03/24 04:57:44
Urgh. This is a bit unfortunate. It's a shame you
tsergeant
2017/03/27 05:31:44
Yeah, it's a pity, but at least the URL field vali
| |
65 return false; | |
66 }, | |
67 | |
44 /** @private */ | 68 /** @private */ |
45 onSaveButtonTap_: function() { | 69 onSaveButtonTap_: function() { |
46 // TODO(tsergeant): Save changes when enter is pressed. | 70 // TODO(tsergeant): Save changes when enter is pressed. |
47 // TODO(tsergeant): Verify values. | |
48 var edit = {'title': this.titleValue_}; | 71 var edit = {'title': this.titleValue_}; |
49 if (!this.isFolder_) | 72 if (!this.isFolder_) { |
73 if (!this.validateUrl_()) | |
74 return; | |
75 | |
50 edit['url'] = this.urlValue_; | 76 edit['url'] = this.urlValue_; |
77 } | |
51 | 78 |
52 chrome.bookmarks.update(this.editItem_.id, edit); | 79 chrome.bookmarks.update(this.editItem_.id, edit); |
53 this.$.dialog.close(); | 80 this.$.dialog.close(); |
54 }, | 81 }, |
55 | 82 |
56 /** @private */ | 83 /** @private */ |
57 onCancelButtonTap_: function() { | 84 onCancelButtonTap_: function() { |
58 this.$.dialog.cancel(); | 85 this.$.dialog.cancel(); |
59 }, | 86 }, |
60 }); | 87 }); |
OLD | NEW |