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 ], |
11 | 11 |
12 properties: { | 12 properties: { |
13 /** @private {BookmarkNode} */ | 13 /** @private */ |
| 14 isFolder_: Boolean, |
| 15 |
| 16 /** @private */ |
| 17 isEdit_: Boolean, |
| 18 |
| 19 /** |
| 20 * Item that is being edited, or null when adding. |
| 21 * @private {?BookmarkNode} |
| 22 */ |
14 editItem_: Object, | 23 editItem_: Object, |
15 | 24 |
16 /** @private */ | 25 /** |
17 isFolder_: Boolean, | 26 * Parent node for the item being added, or null when editing. |
| 27 * @private {?string} |
| 28 */ |
| 29 parentId_: String, |
18 | 30 |
19 /** @private */ | 31 /** @private */ |
20 titleValue_: String, | 32 titleValue_: String, |
21 | 33 |
22 /** @private */ | 34 /** @private */ |
23 urlValue_: String, | 35 urlValue_: String, |
24 }, | 36 }, |
25 | 37 |
26 keyBindings: { | 38 keyBindings: { |
27 'enter': 'onSaveButtonTap_', | 39 'enter': 'onSaveButtonTap_', |
28 }, | 40 }, |
29 | 41 |
30 /** @param {BookmarkNode} editItem */ | 42 /** |
31 showEditDialog: function(editItem) { | 43 * Show the dialog to add a new folder (if |isFolder|) or item, which will be |
32 this.editItem_ = editItem; | 44 * inserted into the tree as a child of |parentId|. |
33 this.isFolder_ = !editItem.url; | 45 * @param {boolean} isFolder |
34 | 46 * @param {string} parentId |
35 this.titleValue_ = editItem.title; | 47 */ |
36 if (!this.isFolder_) { | 48 showAddDialog: function(isFolder, parentId) { |
37 this.$.url.invalid = false; | 49 this.reset_(); |
38 this.urlValue_ = assert(editItem.url); | 50 this.isEdit_ = false; |
39 } | 51 this.isFolder_ = isFolder; |
| 52 this.parentId_ = parentId; |
40 | 53 |
41 this.$.dialog.showModal(); | 54 this.$.dialog.showModal(); |
42 }, | 55 }, |
43 | 56 |
44 /** | 57 /** |
| 58 * Show the edit dialog for |editItem|. |
| 59 * @param {BookmarkNode} editItem |
| 60 */ |
| 61 showEditDialog: function(editItem) { |
| 62 this.reset_(); |
| 63 this.isEdit_ = true; |
| 64 this.isFolder_ = !editItem.url; |
| 65 this.editItem_ = editItem; |
| 66 |
| 67 this.titleValue_ = editItem.title; |
| 68 if (!this.isFolder_) |
| 69 this.urlValue_ = assert(editItem.url); |
| 70 |
| 71 this.$.dialog.showModal(); |
| 72 }, |
| 73 |
| 74 /** |
| 75 * Clear out existing values from the dialog, allowing it to be reused. |
| 76 * @private |
| 77 */ |
| 78 reset_: function() { |
| 79 this.editItem_ = null; |
| 80 this.parentId_ = null; |
| 81 this.$.url.invalid = false; |
| 82 this.titleValue_ = ''; |
| 83 this.urlValue_ = ''; |
| 84 }, |
| 85 |
| 86 /** |
45 * @param {boolean} isFolder | 87 * @param {boolean} isFolder |
| 88 * @param {boolean} isEdit |
46 * @return {string} | 89 * @return {string} |
47 * @private | 90 * @private |
48 */ | 91 */ |
49 getDialogTitle_: function(isFolder) { | 92 getDialogTitle_: function(isFolder, isEdit) { |
50 return loadTimeData.getString( | 93 var title; |
51 isFolder ? 'renameFolderTitle' : 'editBookmarkTitle'); | 94 if (isEdit) |
| 95 title = isFolder ? 'renameFolderTitle' : 'editBookmarkTitle'; |
| 96 else |
| 97 title = isFolder ? 'addFolderTitle' : 'addBookmarkTitle'; |
| 98 |
| 99 return loadTimeData.getString(title); |
52 }, | 100 }, |
53 | 101 |
54 /** | 102 /** |
55 * Validates the value of the URL field, returning true if it is a valid URL. | 103 * 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. | 104 * May modify the value by prepending 'http://' in order to make it valid. |
57 * @return {boolean} | 105 * @return {boolean} |
58 * @private | 106 * @private |
59 */ | 107 */ |
60 validateUrl_: function() { | 108 validateUrl_: function() { |
61 var urlInput = /** @type {PaperInputElement} */ (this.$.url); | 109 var urlInput = /** @type {PaperInputElement} */ (this.$.url); |
(...skipping 14 matching lines...) Expand all Loading... |
76 /** @private */ | 124 /** @private */ |
77 onSaveButtonTap_: function() { | 125 onSaveButtonTap_: function() { |
78 var edit = {'title': this.titleValue_}; | 126 var edit = {'title': this.titleValue_}; |
79 if (!this.isFolder_) { | 127 if (!this.isFolder_) { |
80 if (!this.validateUrl_()) | 128 if (!this.validateUrl_()) |
81 return; | 129 return; |
82 | 130 |
83 edit['url'] = this.urlValue_; | 131 edit['url'] = this.urlValue_; |
84 } | 132 } |
85 | 133 |
86 chrome.bookmarks.update(this.editItem_.id, edit); | 134 if (this.isEdit_) { |
| 135 chrome.bookmarks.update(this.editItem_.id, edit); |
| 136 } else { |
| 137 edit['parentId'] = this.parentId_; |
| 138 chrome.bookmarks.create(edit); |
| 139 } |
87 this.$.dialog.close(); | 140 this.$.dialog.close(); |
88 }, | 141 }, |
89 | 142 |
90 /** @private */ | 143 /** @private */ |
91 onCancelButtonTap_: function() { | 144 onCancelButtonTap_: function() { |
92 this.$.dialog.cancel(); | 145 this.$.dialog.cancel(); |
93 }, | 146 }, |
94 }); | 147 }); |
OLD | NEW |