| 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 * Create item nodes from the metadata. |
| 82 * @constructor |
| 83 */ |
| 84 function ItemsList(itemsTabNode, items) { |
| 85 this.items_ = items; |
| 86 this.itemsTabNode_ = itemsTabNode; |
| 87 assert(this.itemsTabNode_); |
| 88 } |
| 89 |
| 89 ItemsList.prototype = { | 90 ItemsList.prototype = { |
| 90 __proto__: HTMLDivElement.prototype, | |
| 91 | 91 |
| 92 /** | 92 /** |
| 93 * |data_| holds the metadata of all the apps and extensions. | 93 * |items_| holds the metadata of all apps / extensions. |
| 94 * @type {!Array.<!Object>} | 94 * @type {!Array.<!Object>} |
| 95 * @private | 95 * @private |
| 96 */ | 96 */ |
| 97 data_: [], | 97 items_: [], |
| 98 | 98 |
| 99 /** | 99 /** |
| 100 * @override | 100 * |itemsTabNode_| html element holding the items tab. |
| 101 * @type {!HTMLElement} |
| 102 * @private |
| 101 */ | 103 */ |
| 102 decorate: function() { | 104 itemsTabNode_: null, |
| 103 this.textContent = ''; | 105 |
| 104 this.showItemNodes_(); | 106 /** |
| 107 * Creates all items from scratch. |
| 108 */ |
| 109 showItemNodes: function() { |
| 110 this.itemsTabNode_.textContent = ''; |
| 111 // Iterate over the items and add each item to the list. |
| 112 this.itemsTabNode_.classList.toggle('empty-item-list', |
| 113 this.items_.length == 0); |
| 114 for (var i = 0; i < this.items_.length; ++i) { |
| 115 this.createNode_(this.items_[i]); |
| 116 } |
| 105 }, | 117 }, |
| 106 | 118 |
| 107 /** | 119 /** |
| 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 | 120 * Synthesizes and initializes an HTML element for the item metadata |
| 119 * given in |item|. | 121 * given in |item|. |
| 120 * @param {!Object} item A dictionary of item metadata. | 122 * @param {!Object} item A dictionary of item metadata. |
| 121 * @private | 123 * @private |
| 122 */ | 124 */ |
| 123 createNode_: function(item) { | 125 createNode_: function(item) { |
| 124 var template = $('template-collection').querySelector( | 126 var template = $('template-collection').querySelector( |
| 125 '.extension-list-item-wrapper'); | 127 '.extension-list-item-wrapper'); |
| 126 var node = template.cloneNode(true); | 128 var node = template.cloneNode(true); |
| 127 node.id = item.id; | 129 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 = | 214 loadPath.querySelector('span:nth-of-type(2)').textContent = |
| 213 ' ' + item.path; | 215 ' ' + item.path; |
| 214 } | 216 } |
| 215 | 217 |
| 216 // Then the 'managed, cannot uninstall/disable' message. | 218 // Then the 'managed, cannot uninstall/disable' message. |
| 217 if (!item.may_disable) | 219 if (!item.may_disable) |
| 218 node.querySelector('.managed-message').hidden = false; | 220 node.querySelector('.managed-message').hidden = false; |
| 219 | 221 |
| 220 this.setActiveViews_(item, node); | 222 this.setActiveViews_(item, node); |
| 221 | 223 |
| 222 this.appendChild(node); | 224 this.itemsTabNode_.appendChild(node); |
| 223 }, | 225 }, |
| 224 | 226 |
| 225 /** | 227 /** |
| 226 * Sets the webstore link. | 228 * Sets the webstore link. |
| 227 * @param {!Object} item A dictionary of item metadata. | 229 * @param {!Object} item A dictionary of item metadata. |
| 228 * @param {HTMLElement} el HTML element containing all items. | 230 * @param {HTMLElement} el HTML element containing all items. |
| 229 * @private | 231 * @private |
| 230 */ | 232 */ |
| 231 setWebstoreLink_: function(item, el) { | 233 setWebstoreLink_: function(item, el) { |
| 232 var siteLink = el.querySelector('.site-link'); | 234 var siteLink = el.querySelector('.site-link'); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 ItemsList.launchApp = function(id) { | 422 ItemsList.launchApp = function(id) { |
| 421 chrome.management.launchApp(id, function() { | 423 chrome.management.launchApp(id, function() { |
| 422 ItemsList.loadItemsInfo(); | 424 ItemsList.loadItemsInfo(); |
| 423 }); | 425 }); |
| 424 }; | 426 }; |
| 425 | 427 |
| 426 return { | 428 return { |
| 427 ItemsList: ItemsList, | 429 ItemsList: ItemsList, |
| 428 }; | 430 }; |
| 429 }); | 431 }); |
| OLD | NEW |