| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @fileoverview Module for functions which produce action objects. These are |
| 7 * listed in one place to document available actions and their parameters. |
| 8 */ |
| 9 |
| 10 cr.define('bookmarks.actions', function() { |
| 11 |
| 12 /** |
| 13 * @param {string} id |
| 14 * @param {{title: string, url: (string|undefined)}} changeInfo |
| 15 * @return {!Action} |
| 16 */ |
| 17 function editBookmark(id, changeInfo) { |
| 18 return { |
| 19 name: 'edit-bookmark', |
| 20 id: id, |
| 21 changeInfo: changeInfo, |
| 22 }; |
| 23 } |
| 24 |
| 25 /** |
| 26 * @param {string} id |
| 27 * @param {string} parentId |
| 28 * @param {number} index |
| 29 * @return {!Action} |
| 30 */ |
| 31 function removeBookmark(id, parentId, index) { |
| 32 return { |
| 33 name: 'remove-bookmark', |
| 34 id: id, |
| 35 parentId: parentId, |
| 36 index: index, |
| 37 }; |
| 38 } |
| 39 |
| 40 /** |
| 41 * @param {NodeList} nodeMap |
| 42 * @return {!Action} |
| 43 */ |
| 44 function refreshNodes(nodeMap) { |
| 45 return { |
| 46 name: 'refresh-nodes', |
| 47 nodes: nodeMap, |
| 48 }; |
| 49 }; |
| 50 |
| 51 /** |
| 52 * @param {string} id |
| 53 * @return {!Action} |
| 54 */ |
| 55 function selectFolder(id) { |
| 56 return { |
| 57 name: 'select-folder', |
| 58 id: id, |
| 59 }; |
| 60 } |
| 61 |
| 62 /** |
| 63 * @param {string} id |
| 64 * @param {boolean} open |
| 65 * @return {!Action} |
| 66 */ |
| 67 function changeFolderOpen(id, open) { |
| 68 return { |
| 69 name: 'change-folder-open', |
| 70 id: id, |
| 71 open: open, |
| 72 }; |
| 73 } |
| 74 |
| 75 /** |
| 76 * @param {string} id |
| 77 * @param {boolean} add |
| 78 * @param {boolean} range |
| 79 * @param {BookmarksPageState} state |
| 80 * @return {!Action} |
| 81 */ |
| 82 function selectItem(id, add, range, state) { |
| 83 var anchor = state.selection.anchor; |
| 84 var toSelect = []; |
| 85 |
| 86 if (range && anchor) { |
| 87 var displayedList = bookmarks.util.getDisplayedList(state); |
| 88 var selectedIndex = displayedList.indexOf(id); |
| 89 assert(selectedIndex != -1); |
| 90 var anchorIndex = displayedList.indexOf(anchor); |
| 91 assert(anchorIndex != -1); |
| 92 |
| 93 var startIndex = Math.min(anchorIndex, selectedIndex); |
| 94 var endIndex = Math.max(anchorIndex, selectedIndex); |
| 95 |
| 96 for (var i = startIndex; i <= endIndex; i++) |
| 97 toSelect.push(displayedList[i]); |
| 98 } else { |
| 99 toSelect.push(id); |
| 100 } |
| 101 |
| 102 return { |
| 103 name: 'select-items', |
| 104 add: add, |
| 105 anchor: id, |
| 106 items: toSelect, |
| 107 }; |
| 108 } |
| 109 |
| 110 /** |
| 111 * @param {string} term |
| 112 * @return {!Action} |
| 113 */ |
| 114 function setSearchTerm(term) { |
| 115 if (!term) { |
| 116 return {name: 'clear-search'}; |
| 117 } |
| 118 |
| 119 return { |
| 120 name: 'start-search', |
| 121 term: term, |
| 122 }; |
| 123 } |
| 124 |
| 125 /** |
| 126 * @param {!Array<!BookmarkTreeNode>} nodeList |
| 127 * @return {!Action} |
| 128 */ |
| 129 function setSearchResults(nodeList) { |
| 130 return { |
| 131 name: 'finish-search', |
| 132 results: nodeList.map(function(node) { |
| 133 return node.id; |
| 134 }), |
| 135 }; |
| 136 } |
| 137 |
| 138 return { |
| 139 editBookmark: editBookmark, |
| 140 removeBookmark: removeBookmark, |
| 141 refreshNodes: refreshNodes, |
| 142 selectFolder: selectFolder, |
| 143 changeFolderOpen: changeFolderOpen, |
| 144 selectItem: selectItem, |
| 145 setSearchTerm: setSearchTerm, |
| 146 setSearchResults: setSearchResults, |
| 147 }; |
| 148 }); |
| OLD | NEW |