Index: chrome/browser/resources/md_bookmarks/edit_dialog.js |
diff --git a/chrome/browser/resources/md_bookmarks/edit_dialog.js b/chrome/browser/resources/md_bookmarks/edit_dialog.js |
index 6c3d635af1ee0bbb2139454b722a24d07b2eaf9e..576097323ea14cc721f76401eef3d04b09bd8dcd 100644 |
--- a/chrome/browser/resources/md_bookmarks/edit_dialog.js |
+++ b/chrome/browser/resources/md_bookmarks/edit_dialog.js |
@@ -10,13 +10,25 @@ Polymer({ |
], |
properties: { |
- /** @private {BookmarkNode} */ |
- editItem_: Object, |
- |
/** @private */ |
isFolder_: Boolean, |
/** @private */ |
+ isEdit_: Boolean, |
+ |
+ /** |
+ * Item that is being edited, or null when adding. |
+ * @private {?BookmarkNode} |
+ */ |
+ editItem_: Object, |
+ |
+ /** |
+ * Parent node for the item being added, or null when editing. |
+ * @private {?string} |
+ */ |
+ parentId_: String, |
+ |
+ /** @private */ |
titleValue_: String, |
/** @private */ |
@@ -27,28 +39,63 @@ Polymer({ |
'enter': 'onSaveButtonTap_', |
}, |
- /** @param {BookmarkNode} editItem */ |
+ /** |
+ * Show the dialog to add a new folder (if |isFolder|) or item, which will be |
+ * inserted into the tree as a child of |parentId|. |
+ * @param {boolean} isFolder |
+ * @param {string} parentId |
+ */ |
+ showAddDialog: function(isFolder, parentId) { |
+ this.reset_(); |
+ this.isEdit_ = false; |
+ this.isFolder_ = isFolder; |
+ this.parentId_ = parentId; |
+ |
+ this.$.dialog.showModal(); |
+ }, |
+ |
+ /** |
+ * Show the edit dialog for |editItem|. |
+ * @param {BookmarkNode} editItem |
+ */ |
showEditDialog: function(editItem) { |
- this.editItem_ = editItem; |
+ this.reset_(); |
+ this.isEdit_ = true; |
this.isFolder_ = !editItem.url; |
+ this.editItem_ = editItem; |
this.titleValue_ = editItem.title; |
- if (!this.isFolder_) { |
- this.$.url.invalid = false; |
+ if (!this.isFolder_) |
this.urlValue_ = assert(editItem.url); |
- } |
this.$.dialog.showModal(); |
}, |
/** |
+ * Clear out existing values from the dialog, allowing it to be reused. |
+ * @private |
+ */ |
+ reset_: function() { |
+ this.editItem_ = null; |
+ this.parentId_ = null; |
+ this.$.url.invalid = false; |
+ this.titleValue_ = ''; |
+ this.urlValue_ = ''; |
+ }, |
+ |
+ /** |
* @param {boolean} isFolder |
+ * @param {boolean} isEdit |
* @return {string} |
* @private |
*/ |
- getDialogTitle_: function(isFolder) { |
- return loadTimeData.getString( |
- isFolder ? 'renameFolderTitle' : 'editBookmarkTitle'); |
+ getDialogTitle_: function(isFolder, isEdit) { |
+ var title; |
+ if (isEdit) |
+ title = isFolder ? 'renameFolderTitle' : 'editBookmarkTitle'; |
+ else |
+ title = isFolder ? 'addFolderTitle' : 'addBookmarkTitle'; |
calamity
2017/04/03 07:20:48
nit: blank line after this.
tsergeant
2017/04/04 01:21:07
Done.
|
+ return loadTimeData.getString(title); |
}, |
/** |
@@ -83,7 +130,12 @@ Polymer({ |
edit['url'] = this.urlValue_; |
} |
- chrome.bookmarks.update(this.editItem_.id, edit); |
+ if (this.isEdit_) { |
+ chrome.bookmarks.update(this.editItem_.id, edit); |
+ } else { |
+ edit['parentId'] = this.parentId_; |
+ chrome.bookmarks.create(edit); |
+ } |
this.$.dialog.close(); |
}, |