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 /** | 8 /** |
| 9 * Creates a new list of items. | 9 * Creates a new list of items. |
| 10 * @param {Object=} opt_propertyBag Optional properties. | 10 * @param {Object=} opt_propertyBag Optional properties. |
| 11 * @constructor | 11 * @constructor |
| 12 */ | 12 */ |
| 13 var ItemsList = cr.ui.define('div'); | 13 var ItemsList = cr.ui.define('div'); |
| 14 | 14 |
| 15 // The list of all apps & extensions. | 15 // The list of all apps & extensions. |
| 16 var completeList = []; | 16 var completeList = []; |
| 17 | 17 |
| 18 // The list of all apps. | 18 // The list of all apps. |
| 19 var appList = []; | 19 var appList = []; |
| 20 | 20 |
| 21 // The list of all extensions. | |
| 22 var extensionList = []; | |
| 23 | |
| 21 /** const*/ var AppsDevTool = apps_dev_tool.AppsDevTool; | 24 /** const*/ var AppsDevTool = apps_dev_tool.AppsDevTool; |
| 22 | 25 |
| 23 /** | 26 /** |
| 24 * @param {string} a first string. | 27 * @param {string} a first string. |
| 25 * @param {string} b second string. | 28 * @param {string} b second string. |
| 26 * @return {number} 1, 0, -1 if |a| is lexicographically greater, equal or | 29 * @return {number} 1, 0, -1 if |a| is lexicographically greater, equal or |
| 27 * lesser than |b| respectively. | 30 * lesser than |b| respectively. |
| 28 */ | 31 */ |
| 29 function compare(a, b) { | 32 function compare(a, b) { |
| 30 return a > b ? 1 : (a == b ? 0 : -1); | 33 return a > b ? 1 : (a == b ? 0 : -1); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 49 * @param {string} app2 second app_name. | 52 * @param {string} app2 second app_name. |
| 50 */ | 53 */ |
| 51 function compareByName(app1, app2) { | 54 function compareByName(app1, app2) { |
| 52 return compare(app1.name.toLowerCase(), app2.name.toLowerCase()); | 55 return compare(app1.name.toLowerCase(), app2.name.toLowerCase()); |
| 53 } | 56 } |
| 54 | 57 |
| 55 /** | 58 /** |
| 56 * Refreshes the app. | 59 * Refreshes the app. |
| 57 */ | 60 */ |
| 58 function reloadAppDisplay() { | 61 function reloadAppDisplay() { |
| 59 var itemsDiv = $('items'); | 62 ItemsList.prototype.data_ = extensionList; |
|
Dan Beam
2013/03/20 19:05:30
^ I'm confused as to what this is doing?
Gaurav
2013/03/29 21:14:26
It initializes the data in ItemsList fow which the
Dan Beam
2013/03/29 21:48:13
This should be setting this on an instance, not on
| |
| 60 | 63 |
| 61 // Empty the current content. | 64 var extensions = $('extension-settings-list'); |
| 62 itemsDiv.textContent = ''; | 65 ItemsList.decorate(extensions); |
| 63 | 66 |
| 64 ItemsList.prototype.data_ = appList; | 67 ItemsList.prototype.data_ = appList; |
| 65 var itemsList = $('extension-settings-list'); | 68 var apps = $('app-settings-list'); |
| 66 ItemsList.decorate(itemsList); | 69 ItemsList.decorate(apps); |
| 67 } | 70 } |
| 68 | 71 |
| 69 /** | 72 /** |
| 70 * Applies the given |filter| to the items list. | 73 * Applies the given |filter| to the items list. |
| 71 * @param {string} filter Curent string in the search box. | 74 * @param {string} filter Curent string in the search box. |
| 72 */ | 75 */ |
| 73 function rebuildAppList(filter) { | 76 function rebuildAppList(filter) { |
| 74 if (!filter) { | 77 appList = []; |
| 75 appList = completeList; | 78 extensionList = []; |
| 76 return; | |
| 77 } | |
| 78 | 79 |
| 79 appList = []; | |
| 80 for (var i = 0; i < completeList.length; i++) { | 80 for (var i = 0; i < completeList.length; i++) { |
| 81 var item = completeList[i]; | 81 var item = completeList[i]; |
| 82 if (item.name.toLowerCase().search(filter) < 0) | 82 if (item.name.toLowerCase().search(filter) < 0) |
|
Dan Beam
2013/03/20 19:05:30
nit: if (filter && item.name.toLowerCase().search(
Gaurav
2013/03/29 21:14:26
Done.
| |
| 83 continue; | 83 continue; |
| 84 | 84 if (item.isApp) |
| 85 appList.push(item); | 85 appList.push(item); |
| 86 else | |
| 87 extensionList.push(item); | |
| 86 } | 88 } |
| 87 } | 89 } |
| 88 | 90 |
| 89 ItemsList.prototype = { | 91 ItemsList.prototype = { |
| 90 __proto__: HTMLDivElement.prototype, | 92 __proto__: HTMLDivElement.prototype, |
| 91 | 93 |
| 92 /** | 94 /** |
| 93 * |data_| holds the metadata of all the apps and extensions. | 95 * |data_| holds the metadata of all the apps and extensions. |
| 94 * @type {!Array.<!Object>} | 96 * @type {!Array.<!Object>} |
| 95 * @private | 97 * @private |
| 96 */ | 98 */ |
| 97 data_: [], | 99 data_: [], |
| 98 | 100 |
| 99 /** | 101 /** |
| 100 * @override | 102 * @override |
| 101 */ | 103 */ |
| 102 decorate: function() { | 104 decorate: function() { |
| 103 this.textContent = ''; | 105 this.textContent = ''; |
| 104 this.showItemNodes_(); | 106 this.showItemNodes_(); |
| 105 }, | 107 }, |
| 106 | 108 |
| 107 /** | 109 /** |
| 108 * Creates all items from scratch. | 110 * Creates all items from scratch. |
| 109 * @private | 111 * @private |
| 110 */ | 112 */ |
| 111 showItemNodes_: function() { | 113 showItemNodes_: function() { |
| 112 // Iterate over the item data and add each item to the list. | 114 // Iterate over the item data and add each item to the list. |
| 113 this.classList.toggle('empty-extension-list', this.data_.length == 0); | 115 this.classList.toggle('empty-item-list', this.data_.length == 0); |
| 114 this.data_.forEach(this.createNode_, this); | 116 this.data_.forEach(this.createNode_, this); |
| 115 }, | 117 }, |
| 116 | 118 |
| 117 /** | 119 /** |
| 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) { |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 chrome.management.launchApp(id, function() { | 439 chrome.management.launchApp(id, function() { |
| 438 // There is a delay in generation of background page for the app. | 440 // There is a delay in generation of background page for the app. |
| 439 setTimeout(ItemsList.loadItemsInfo, 1000); | 441 setTimeout(ItemsList.loadItemsInfo, 1000); |
| 440 }); | 442 }); |
| 441 }; | 443 }; |
| 442 | 444 |
| 443 return { | 445 return { |
| 444 ItemsList: ItemsList, | 446 ItemsList: ItemsList, |
| 445 }; | 447 }; |
| 446 }); | 448 }); |
| OLD | NEW |