| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // require: cr.js | 5 // require: cr.js |
| 6 // require: cr/ui.js | 6 // require: cr/ui.js |
| 7 // require: cr/ui/tree.js | 7 // require: cr/ui/tree.js |
| 8 | 8 |
| 9 (function() { | 9 (function() { |
| 10 /** | 10 /** |
| 11 * A helper function to determine if a node is the root of its type. | 11 * A helper function to determine if a node is the root of its type. |
| 12 * | 12 * |
| 13 * @param {!Object} node The node to check. | 13 * @param {!Object} node The node to check. |
| 14 */ | 14 */ |
| 15 var isTypeRootNode = function(node) { | 15 var isTypeRootNode = function(node) { |
| 16 return node.PARENT_ID == 'r' && node.UNIQUE_SERVER_TAG != ''; | 16 return node.PARENT_ID == 'r' && node.UNIQUE_SERVER_TAG != ''; |
| 17 } | 17 }; |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * A helper function to determine if a node is a child of the given parent. | 20 * A helper function to determine if a node is a child of the given parent. |
| 21 * | 21 * |
| 22 * @param {string} parentId The ID of the parent. | 22 * @param {!Object} parent node. |
| 23 * @param {!Object} node The node to check. | 23 * @param {!Object} node The node to check. |
| 24 */ | 24 */ |
| 25 var isChildOf = function(parentId, node) { | 25 var isChildOf = function(parentNode, node) { |
| 26 return node.PARENT_ID == parentId; | 26 if (node.PARENT_ID != '') { |
| 27 } | 27 return node.PARENT_ID == parentNode.ID; |
| 28 } |
| 29 else { |
| 30 return node.modelType == parentNode.modelType; |
| 31 } |
| 32 }; |
| 28 | 33 |
| 29 /** | 34 /** |
| 30 * A helper function to sort sync nodes. | 35 * A helper function to sort sync nodes. |
| 31 * | 36 * |
| 32 * Sorts by position index if possible, falls back to sorting by name, and | 37 * Sorts by position index if possible, falls back to sorting by name, and |
| 33 * finally sorting by METAHANDLE. | 38 * finally sorting by METAHANDLE. |
| 34 * | 39 * |
| 35 * If this proves to be slow and expensive, we should experiment with moving | 40 * If this proves to be slow and expensive, we should experiment with moving |
| 36 * this functionality to C++ instead. | 41 * this functionality to C++ instead. |
| 37 */ | 42 */ |
| 38 var nodeComparator = function(nodeA, nodeB) { | 43 var nodeComparator = function(nodeA, nodeB) { |
| 39 if (nodeA.hasOwnProperty('positionIndex') && | 44 if (nodeA.hasOwnProperty('positionIndex') && |
| 40 nodeB.hasOwnProperty('positionIndex')) { | 45 nodeB.hasOwnProperty('positionIndex')) { |
| 41 return nodeA.positionIndex - nodeB.positionIndex; | 46 return nodeA.positionIndex - nodeB.positionIndex; |
| 42 } else if (nodeA.NON_UNIQUE_NAME != nodeB.NON_UNIQUE_NAME) { | 47 } else if (nodeA.NON_UNIQUE_NAME != nodeB.NON_UNIQUE_NAME) { |
| 43 return nodeA.NON_UNIQUE_NAME.localeCompare(nodeB.NON_UNIQUE_NAME); | 48 return nodeA.NON_UNIQUE_NAME.localeCompare(nodeB.NON_UNIQUE_NAME); |
| 44 } else { | 49 } else { |
| 45 return nodeA.METAHANDLE - nodeB.METAHANDLE; | 50 return nodeA.METAHANDLE - nodeB.METAHANDLE; |
| 46 } | 51 } |
| 47 } | 52 }; |
| 48 | 53 |
| 49 /** | 54 /** |
| 50 * Updates the node detail view with the details for the given node. | 55 * Updates the node detail view with the details for the given node. |
| 51 * @param {!Object} node The struct representing the node we want to display. | 56 * @param {!Object} node The struct representing the node we want to display. |
| 52 */ | 57 */ |
| 53 function updateNodeDetailView(node) { | 58 function updateNodeDetailView(node) { |
| 54 var nodeDetailsView = $('node-details'); | 59 var nodeDetailsView = $('node-details'); |
| 55 nodeDetailsView.hidden = false; | 60 nodeDetailsView.hidden = false; |
| 56 jstProcess(new JsEvalContext(node.entry_), nodeDetailsView); | 61 jstProcess(new JsEvalContext(node.entry_), nodeDetailsView); |
| 57 } | 62 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 */ | 104 */ |
| 100 handleExpand_: function(event) { | 105 handleExpand_: function(event) { |
| 101 var treeItem = this; | 106 var treeItem = this; |
| 102 | 107 |
| 103 if (treeItem.expanded_) { | 108 if (treeItem.expanded_) { |
| 104 return; | 109 return; |
| 105 } | 110 } |
| 106 treeItem.expanded_ = true; | 111 treeItem.expanded_ = true; |
| 107 | 112 |
| 108 var children = treeItem.tree.allNodes.filter( | 113 var children = treeItem.tree.allNodes.filter( |
| 109 isChildOf.bind(undefined, treeItem.entry_.ID)); | 114 isChildOf.bind(undefined, treeItem.entry_)); |
| 110 children.sort(nodeComparator); | 115 children.sort(nodeComparator); |
| 111 | 116 |
| 112 children.forEach(function(node) { | 117 children.forEach(function(node) { |
| 113 treeItem.add(new SyncNodeTreeItem(node)); | 118 treeItem.add(new SyncNodeTreeItem(node)); |
| 114 }); | 119 }); |
| 115 }, | 120 }, |
| 116 }; | 121 }; |
| 117 | 122 |
| 118 /** | 123 /** |
| 119 * Creates a new sync node tree. Technically, it's a forest since it each | 124 * Creates a new sync node tree. Technically, it's a forest since it each |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 // Automatically trigger a refresh the first time this tab is selected. | 210 // Automatically trigger a refresh the first time this tab is selected. |
| 206 $('sync-browser-tab').addEventListener('selectedChange', function f(e) { | 211 $('sync-browser-tab').addEventListener('selectedChange', function f(e) { |
| 207 if (this.selected) { | 212 if (this.selected) { |
| 208 $('sync-browser-tab').removeEventListener('selectedChange', f); | 213 $('sync-browser-tab').removeEventListener('selectedChange', f); |
| 209 refresh(); | 214 refresh(); |
| 210 } | 215 } |
| 211 }); | 216 }); |
| 212 }); | 217 }); |
| 213 | 218 |
| 214 })(); | 219 })(); |
| OLD | NEW |