Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5786)

Unified Diff: chrome/browser/resources/md_bookmarks/store.js

Issue 2670473002: [MD Bookmarks] Implement adding folders and bookmarks from toolbar menu. (Closed)
Patch Set: Add node menu and tests. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/md_bookmarks/store.js
diff --git a/chrome/browser/resources/md_bookmarks/store.js b/chrome/browser/resources/md_bookmarks/store.js
index 8f0ef849e334c115d6178bff4e4628950a34fcd8..34d3aa1d743d20d8de4d48c9f9273e863c1adc09 100644
--- a/chrome/browser/resources/md_bookmarks/store.js
+++ b/chrome/browser/resources/md_bookmarks/store.js
@@ -53,6 +53,7 @@ var BookmarksStore = Polymer({
/** @override */
attached: function() {
this.documentListeners_ = {
+ 'add-node-saved': this.onAddNodeSaved_.bind(this),
'folder-open-changed': this.onFolderOpenChanged_.bind(this),
'search-term-changed': this.onSearchTermChanged_.bind(this),
'select-item': this.onItemSelected_.bind(this),
@@ -79,6 +80,7 @@ var BookmarksStore = Polymer({
// Attach bookmarks API listeners.
chrome.bookmarks.onRemoved.addListener(this.onBookmarkRemoved_.bind(this));
chrome.bookmarks.onChanged.addListener(this.onBookmarkChanged_.bind(this));
+ chrome.bookmarks.onCreated.addListener(this.onBookmarkCreated_.bind(this));
},
//////////////////////////////////////////////////////////////////////////////
@@ -326,6 +328,21 @@ var BookmarksStore = Polymer({
this.updateSearchDisplay_();
},
+ /**
+ * Called when after a node is created.
+ * @param {string} id The id of the newly added bookmark node.
+ * @param {!BookmarkTreeNode} bookmarkNode
+ */
+ onBookmarkCreated_: function(id, bookmarkNode) {
+ var parent = this.idToNodeMap_[bookmarkNode.parentId || null];
angelayang 2017/02/08 07:34:03 Closure complains that bookmarkNode.parentId can b
jiaxi 2017/02/09 01:13:09 I used /** @type {?string} */ in onSelectedFolderC
angelayang 2017/02/09 03:12:24 I'll to do the same for consistency sake for now a
+ this.push(parent.path + '.children', bookmarkNode);
jiaxi 2017/02/09 01:13:09 According to my understanding, this adds the new B
jiaxi 2017/02/09 01:20:24 Take a second thought, Polymer's splice could prob
angelayang 2017/02/09 03:12:24 I think what you suggested is good, thanks
+ BookmarksStore.generatePaths(parent, parent.children.length - 1);
+ BookmarksStore.initNodes(bookmarkNode, this.idToNodeMap_);
+
+ if (this.searchTerm)
+ this.updateSearchDisplay_();
+ },
+
//////////////////////////////////////////////////////////////////////////////
// bookmarks-store, bookmarks app event listeners:
@@ -375,6 +392,18 @@ var BookmarksStore = Polymer({
},
/**
+ * Appends a node to the children the selected folder.
+ * @param {CustomEvent} e
+ * @private
+ */
+ onAddNodeSaved_: function(e) {
+ var info = /** @type {!Object} */ (e.detail);
+ info.parentId = this.selectedId;
+ // TODO (angelayang): handle invalid urls.
+ chrome.bookmarks.create(info);
+ },
+
+ /**
* Selects items according to keyboard behaviours.
* @param {CustomEvent} e
* @private
@@ -426,6 +455,9 @@ BookmarksStore.initNodes = function(bookmarkNode, idToNodeMap) {
bookmarkNode.isSelectedFolder = false;
bookmarkNode.isOpen = true;
+ if (!bookmarkNode.children)
+ bookmarkNode.children = [];
+
for (var i = 0; i < bookmarkNode.children.length; i++)
BookmarksStore.initNodes(bookmarkNode.children[i], idToNodeMap);
};
« no previous file with comments | « chrome/browser/resources/md_bookmarks/folder_node.js ('k') | chrome/browser/resources/md_bookmarks/toolbar.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698