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

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

Issue 2704983002: MD Bookmarks: Proof-of-concept reimplementation of data storage/binding layer (Closed)
Patch Set: Add doc comments 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/actions.js
diff --git a/chrome/browser/resources/md_bookmarks/actions.js b/chrome/browser/resources/md_bookmarks/actions.js
new file mode 100644
index 0000000000000000000000000000000000000000..34c509f51d50e87299f10567aacde5ad051e74e8
--- /dev/null
+++ b/chrome/browser/resources/md_bookmarks/actions.js
@@ -0,0 +1,148 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview Module for functions which produce action objects. These are
+ * listed in one place to document available actions and their parameters.
+ */
+
+cr.define('bookmarks.actions', function() {
+
+ /**
+ * @param {string} id
+ * @param {{title: string, url: (string|undefined)}} changeInfo
+ * @return {!Action}
+ */
+ function editBookmark(id, changeInfo) {
+ return {
+ name: 'edit-bookmark',
+ id: id,
+ changeInfo: changeInfo,
+ };
+ }
+
+ /**
+ * @param {string} id
+ * @param {string} parentId
+ * @param {number} index
+ * @return {!Action}
+ */
+ function removeBookmark(id, parentId, index) {
+ return {
+ name: 'remove-bookmark',
+ id: id,
+ parentId: parentId,
+ index: index,
+ };
+ }
+
+ /**
+ * @param {NodeList} nodeMap
+ * @return {!Action}
+ */
+ function refreshNodes(nodeMap) {
+ return {
+ name: 'refresh-nodes',
+ nodes: nodeMap,
+ };
+ };
+
+ /**
+ * @param {string} id
+ * @return {!Action}
+ */
+ function selectFolder(id) {
+ return {
+ name: 'select-folder',
+ id: id,
+ };
+ }
+
+ /**
+ * @param {string} id
+ * @param {boolean} open
+ * @return {!Action}
+ */
+ function changeFolderOpen(id, open) {
+ return {
+ name: 'change-folder-open',
+ id: id,
+ open: open,
+ };
+ }
+
+ /**
+ * @param {string} id
+ * @param {boolean} add
+ * @param {boolean} range
+ * @param {BookmarksPageState} state
+ * @return {!Action}
+ */
+ function selectItem(id, add, range, state) {
+ var anchor = state.selection.anchor;
+ var toSelect = [];
+
+ if (range && anchor) {
+ var displayedList = bookmarks.util.getDisplayedList(state);
+ var selectedIndex = displayedList.indexOf(id);
+ assert(selectedIndex != -1);
+ var anchorIndex = displayedList.indexOf(anchor);
+ assert(anchorIndex != -1);
+
+ var startIndex = Math.min(anchorIndex, selectedIndex);
+ var endIndex = Math.max(anchorIndex, selectedIndex);
+
+ for (var i = startIndex; i <= endIndex; i++)
+ toSelect.push(displayedList[i]);
+ } else {
+ toSelect.push(id);
+ }
+
+ return {
+ name: 'select-items',
+ add: add,
+ anchor: id,
+ items: toSelect,
+ };
+ }
+
+ /**
+ * @param {string} term
+ * @return {!Action}
+ */
+ function setSearchTerm(term) {
+ if (!term) {
+ return {name: 'clear-search'};
+ }
+
+ return {
+ name: 'start-search',
+ term: term,
+ };
+ }
+
+ /**
+ * @param {!Array<!BookmarkTreeNode>} nodeList
+ * @return {!Action}
+ */
+ function setSearchResults(nodeList) {
+ return {
+ name: 'finish-search',
+ results: nodeList.map(function(node) {
+ return node.id;
+ }),
+ };
+ }
+
+ return {
+ editBookmark: editBookmark,
+ removeBookmark: removeBookmark,
+ refreshNodes: refreshNodes,
+ selectFolder: selectFolder,
+ changeFolderOpen: changeFolderOpen,
+ selectItem: selectItem,
+ setSearchTerm: setSearchTerm,
+ setSearchResults: setSearchResults,
+ };
+});
« no previous file with comments | « chrome/browser/resources/md_bookmarks/actions.html ('k') | chrome/browser/resources/md_bookmarks/api_listener.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698