Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.define('apps_dev_tool', function() { | 5 cr.define('apps_dev_tool', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | |
| 9 * Creates a new list of items. | |
| 10 * @param {Object=} opt_propertyBag Optional properties. | |
| 11 * @constructor | |
| 12 */ | |
| 13 var ItemsList = cr.ui.define('div'); | |
| 14 | |
| 15 // The list of all apps & extensions. | 8 // The list of all apps & extensions. |
| 16 var completeList = []; | 9 var completeList = []; |
| 17 | 10 |
| 18 // The list of all apps. | 11 // The list of all apps. |
| 19 var appList = []; | 12 var appList = []; |
| 20 | 13 |
| 14 // The list of all extensions. | |
| 15 var extensionList = []; | |
| 16 | |
| 21 /** const*/ var AppsDevTool = apps_dev_tool.AppsDevTool; | 17 /** const*/ var AppsDevTool = apps_dev_tool.AppsDevTool; |
| 22 | 18 |
| 23 /** | 19 /** |
| 24 * @param {string} a first string. | 20 * @param {string} a first string. |
| 25 * @param {string} b second string. | 21 * @param {string} b second string. |
| 26 * @return {number} 1, 0, -1 if |a| is lexicographically greater, equal or | 22 * @return {number} 1, 0, -1 if |a| is lexicographically greater, equal or |
| 27 * lesser than |b| respectively. | 23 * lesser than |b| respectively. |
| 28 */ | 24 */ |
| 29 function compare(a, b) { | 25 function compare(a, b) { |
| 30 return a > b ? 1 : (a == b ? 0 : -1); | 26 return a > b ? 1 : (a == b ? 0 : -1); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 49 * @param {string} app2 second app_name. | 45 * @param {string} app2 second app_name. |
| 50 */ | 46 */ |
| 51 function compareByName(app1, app2) { | 47 function compareByName(app1, app2) { |
| 52 return compare(app1.name.toLowerCase(), app2.name.toLowerCase()); | 48 return compare(app1.name.toLowerCase(), app2.name.toLowerCase()); |
| 53 } | 49 } |
| 54 | 50 |
| 55 /** | 51 /** |
| 56 * Refreshes the app. | 52 * Refreshes the app. |
| 57 */ | 53 */ |
| 58 function reloadAppDisplay() { | 54 function reloadAppDisplay() { |
| 59 var itemsDiv = $('items'); | 55 var extensions = new ItemsList($('extension-settings-list'), extensionList); |
| 60 | 56 var apps = new ItemsList($('app-settings-list'), appList); |
| 61 // Empty the current content. | 57 extensions.showItemNodes(); |
| 62 itemsDiv.textContent = ''; | 58 apps.showItemNodes(); |
| 63 | |
| 64 ItemsList.prototype.data_ = appList; | |
| 65 var itemsList = $('extension-settings-list'); | |
| 66 ItemsList.decorate(itemsList); | |
| 67 } | 59 } |
| 68 | 60 |
| 69 /** | 61 /** |
| 70 * Applies the given |filter| to the items list. | 62 * Applies the given |filter| to the items list. |
| 71 * @param {string} filter Curent string in the search box. | 63 * @param {string} filter Curent string in the search box. |
| 72 */ | 64 */ |
| 73 function rebuildAppList(filter) { | 65 function rebuildAppList(filter) { |
| 74 if (!filter) { | 66 appList = []; |
| 75 appList = completeList; | 67 extensionList = []; |
| 76 return; | |
| 77 } | |
| 78 | 68 |
| 79 appList = []; | |
| 80 for (var i = 0; i < completeList.length; i++) { | 69 for (var i = 0; i < completeList.length; i++) { |
| 81 var item = completeList[i]; | 70 var item = completeList[i]; |
| 82 if (item.name.toLowerCase().search(filter) < 0) | 71 if (filter && item.name.toLowerCase().search(filter) < 0) |
| 83 continue; | 72 continue; |
| 84 | 73 if (item.isApp) |
| 85 appList.push(item); | 74 appList.push(item); |
| 75 else | |
| 76 extensionList.push(item); | |
| 86 } | 77 } |
| 87 } | 78 } |
| 88 | 79 |
| 80 /** | |
| 81 * ItemsList constructor. | |
|
Dan Beam
2013/04/03 22:56:24
^ this comment isn't useful (it's easily derivable
Gaurav
2013/04/04 17:50:59
Used a class to group the functionality of creatin
| |
| 82 * @constructor | |
| 83 */ | |
| 84 function ItemsList(itemsTabNode, items) { | |
| 85 this.items_ = items; | |
| 86 this.itemsTabNode_ = itemsTabNode; | |
|
Dan Beam
2013/04/03 22:56:24
assert(this.itemsTabNode_);
Gaurav
2013/04/04 17:50:59
Done.
| |
| 87 } | |
| 88 | |
| 89 ItemsList.prototype = { | 89 ItemsList.prototype = { |
| 90 __proto__: HTMLDivElement.prototype, | |
| 91 | 90 |
| 92 /** | 91 /** |
| 93 * |data_| holds the metadata of all the apps and extensions. | 92 * |items_| holds the metadata of all apps / extensions. |
| 94 * @type {!Array.<!Object>} | 93 * @type {!Array.<!Object>} |
| 95 * @private | 94 * @private |
| 96 */ | 95 */ |
| 97 data_: [], | 96 items_: [], |
| 98 | 97 |
| 99 /** | 98 /** |
| 100 * @override | 99 * |itemsTabNode_| html element holding the items tab. |
| 100 * @type {!Object} | |
|
Dan Beam
2013/04/03 22:56:24
@type {!HTMLElement}
Gaurav
2013/04/04 17:50:59
Done.
| |
| 101 *@private | |
|
Dan Beam
2013/04/03 22:56:24
* @private
Gaurav
2013/04/04 17:50:59
Done.
| |
| 101 */ | 102 */ |
| 102 decorate: function() { | 103 itemsTabNode_: Object, |
| 103 this.textContent = ''; | 104 |
| 104 this.showItemNodes_(); | 105 /** |
| 106 * Creates all items from scratch. | |
| 107 */ | |
| 108 showItemNodes: function() { | |
| 109 this.itemsTabNode_.textContent = ''; | |
| 110 // Iterate over the items and add each item to the list. | |
| 111 this.itemsTabNode_.classList.toggle('empty-item-list', | |
| 112 this.items_.length == 0); | |
| 113 for (var i = 0; i < this.items_.length; ++i) { | |
| 114 this.createNode_(this.items_[i]); | |
| 115 } | |
| 105 }, | 116 }, |
| 106 | 117 |
| 107 /** | 118 /** |
| 108 * Creates all items from scratch. | |
| 109 * @private | |
| 110 */ | |
| 111 showItemNodes_: function() { | |
| 112 // Iterate over the item data and add each item to the list. | |
| 113 this.classList.toggle('empty-extension-list', this.data_.length == 0); | |
| 114 this.data_.forEach(this.createNode_, this); | |
| 115 }, | |
| 116 | |
| 117 /** | |
| 118 * Synthesizes and initializes an HTML element for the item metadata | 119 * Synthesizes and initializes an HTML element for the item metadata |
| 119 * given in |item|. | 120 * given in |item|. |
| 120 * @param {!Object} item A dictionary of item metadata. | 121 * @param {!Object} item A dictionary of item metadata. |
| 121 * @private | 122 * @private |
| 122 */ | 123 */ |
| 123 createNode_: function(item) { | 124 createNode_: function(item) { |
| 124 var template = $('template-collection').querySelector( | 125 var template = $('template-collection').querySelector( |
| 125 '.extension-list-item-wrapper'); | 126 '.extension-list-item-wrapper'); |
| 126 var node = template.cloneNode(true); | 127 var node = template.cloneNode(true); |
| 127 node.id = item.id; | 128 node.id = item.id; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 loadPath.querySelector('span:nth-of-type(2)').textContent = | 213 loadPath.querySelector('span:nth-of-type(2)').textContent = |
| 213 ' ' + item.path; | 214 ' ' + item.path; |
| 214 } | 215 } |
| 215 | 216 |
| 216 // Then the 'managed, cannot uninstall/disable' message. | 217 // Then the 'managed, cannot uninstall/disable' message. |
| 217 if (!item.may_disable) | 218 if (!item.may_disable) |
| 218 node.querySelector('.managed-message').hidden = false; | 219 node.querySelector('.managed-message').hidden = false; |
| 219 | 220 |
| 220 this.setActiveViews_(item, node); | 221 this.setActiveViews_(item, node); |
| 221 | 222 |
| 222 this.appendChild(node); | 223 this.itemsTabNode_.appendChild(node); |
| 223 }, | 224 }, |
| 224 | 225 |
| 225 /** | 226 /** |
| 226 * Sets the webstore link. | 227 * Sets the webstore link. |
| 227 * @param {!Object} item A dictionary of item metadata. | 228 * @param {!Object} item A dictionary of item metadata. |
| 228 * @param {HTMLElement} el HTML element containing all items. | 229 * @param {HTMLElement} el HTML element containing all items. |
| 229 * @private | 230 * @private |
| 230 */ | 231 */ |
| 231 setWebstoreLink_: function(item, el) { | 232 setWebstoreLink_: function(item, el) { |
| 232 var siteLink = el.querySelector('.site-link'); | 233 var siteLink = el.querySelector('.site-link'); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 ItemsList.launchApp = function(id) { | 421 ItemsList.launchApp = function(id) { |
| 421 chrome.management.launchApp(id, function() { | 422 chrome.management.launchApp(id, function() { |
| 422 ItemsList.loadItemsInfo(); | 423 ItemsList.loadItemsInfo(); |
| 423 }); | 424 }); |
| 424 }; | 425 }; |
| 425 | 426 |
| 426 return { | 427 return { |
| 427 ItemsList: ItemsList, | 428 ItemsList: ItemsList, |
| 428 }; | 429 }; |
| 429 }); | 430 }); |
| OLD | NEW |