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

Side by Side Diff: chrome/browser/resources/md_bookmarks/util.js

Issue 2912893002: MD Bookmarks: Support policies for disabling bookmark editing (Closed)
Patch Set: Review comments Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview Utility functions for the Bookmarks page. 6 * @fileoverview Utility functions for the Bookmarks page.
7 */ 7 */
8 8
9 cr.define('bookmarks.util', function() { 9 cr.define('bookmarks.util', function() {
10 /** 10 /**
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 return nodeMap; 64 return nodeMap;
65 } 65 }
66 66
67 /** @return {!BookmarksPageState} */ 67 /** @return {!BookmarksPageState} */
68 function createEmptyState() { 68 function createEmptyState() {
69 return { 69 return {
70 nodes: {}, 70 nodes: {},
71 selectedFolder: '0', 71 selectedFolder: '0',
72 closedFolders: new Set(), 72 closedFolders: new Set(),
73 prefs: { 73 prefs: {
74 canEdit: true,
74 incognitoAvailability: IncognitoAvailability.ENABLED, 75 incognitoAvailability: IncognitoAvailability.ENABLED,
75 }, 76 },
76 search: { 77 search: {
77 term: '', 78 term: '',
78 inProgress: false, 79 inProgress: false,
79 results: [], 80 results: [],
80 }, 81 },
81 selection: { 82 selection: {
82 items: new Set(), 83 items: new Set(),
83 anchor: null, 84 anchor: null,
84 }, 85 },
85 }; 86 };
86 } 87 }
87 88
88 /** 89 /**
89 * @param {BookmarksPageState} state 90 * @param {BookmarksPageState} state
90 * @return {boolean} 91 * @return {boolean}
91 */ 92 */
92 function isShowingSearch(state) { 93 function isShowingSearch(state) {
93 return !!state.search.term && !state.search.inProgress; 94 return !!state.search.term && !state.search.inProgress;
94 } 95 }
95 96
96 /** 97 /**
98 * Returns true if the node with ID |itemId| is modifiable, allowing
99 * the node to be renamed, moved or deleted. Note that if a node is
100 * uneditable, it may still have editable children (for example, the top-level
101 * folders).
calamity 2017/06/13 05:13:53 Might also be worth mentioning that the unmodifiab
tsergeant 2017/06/13 05:32:16 I think that comment will probably just end up res
102 * @param {BookmarksPageState} state
103 * @param {string} itemId
104 * @return {boolean}
105 */
106 function canEditNode(state, itemId) {
107 return itemId != ROOT_NODE_ID &&
108 state.nodes[itemId].parentId != ROOT_NODE_ID &&
109 !state.nodes[itemId].unmodifiable && state.prefs.canEdit;
110 }
111
112 /**
113 * Returns true if it is possible to modify the children list of the node with
114 * ID |itemId|. This includes rearranging the children or adding new ones.
115 * @param {BookmarksPageState} state
116 * @param {string} itemId
117 * @return {boolean}
118 */
119 function canReorderChildren(state, itemId) {
120 return itemId != ROOT_NODE_ID && !state.nodes[itemId].unmodifiable &&
121 state.prefs.canEdit;
122 }
123
124 /**
97 * @param {string} id 125 * @param {string} id
98 * @param {NodeMap} nodes 126 * @param {NodeMap} nodes
99 * @return {boolean} 127 * @return {boolean}
100 */ 128 */
101 function hasChildFolders(id, nodes) { 129 function hasChildFolders(id, nodes) {
102 var children = nodes[id].children; 130 var children = nodes[id].children;
103 for (var i = 0; i < children.length; i++) { 131 for (var i = 0; i < children.length; i++) {
104 if (nodes[children[i]].children) 132 if (nodes[children[i]].children)
105 return true; 133 return true;
106 } 134 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 */ 187 */
160 function removeIdsFromSet(set, ids) { 188 function removeIdsFromSet(set, ids) {
161 var difference = new Set(set); 189 var difference = new Set(set);
162 ids.forEach(function(id) { 190 ids.forEach(function(id) {
163 difference.delete(id); 191 difference.delete(id);
164 }); 192 });
165 return difference; 193 return difference;
166 } 194 }
167 195
168 return { 196 return {
197 canEditNode: canEditNode,
198 canReorderChildren: canReorderChildren,
169 createEmptyState: createEmptyState, 199 createEmptyState: createEmptyState,
170 getDescendants: getDescendants, 200 getDescendants: getDescendants,
171 getDisplayedList: getDisplayedList, 201 getDisplayedList: getDisplayedList,
172 hasChildFolders: hasChildFolders, 202 hasChildFolders: hasChildFolders,
173 isShowingSearch: isShowingSearch, 203 isShowingSearch: isShowingSearch,
174 normalizeNode: normalizeNode, 204 normalizeNode: normalizeNode,
175 normalizeNodes: normalizeNodes, 205 normalizeNodes: normalizeNodes,
176 removeIdsFromMap: removeIdsFromMap, 206 removeIdsFromMap: removeIdsFromMap,
177 removeIdsFromSet: removeIdsFromSet, 207 removeIdsFromSet: removeIdsFromSet,
178 }; 208 };
179 }); 209 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698