| 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..ec03ec6d96a45fb891558156c026efcc81b668a3 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,64 @@ 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';
|
| +
|
| + return loadTimeData.getString(title);
|
| },
|
|
|
| /**
|
| @@ -83,7 +131,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();
|
| },
|
|
|
|
|