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
3 // found in the LICENSE file.
5 // Defines global variables.
6 var commands = TaskManagerCommands;
7 var taskmanager = undefined; // This will be instantiated in main.js.
10 * Invoked when a range of items has changed.
11 * @param {Integer} start The start position of tasks to be changed
12 * @param {Integer} length The length of tasks to be changed
13 * @param {Array of task} tasks The array of updated task
15 function taskChanged(start, length, tasks) {
16 var task = {type: 'change', start: start, length: length, tasks: tasks};
18 if (taskmanager) taskmanager.processTaskChange(task);
21 // Cached list of enabled columns to prevent frequent access to localStorage.
22 var cachedEnabledColumns;
25 * @return {Dictionary} the dictionary which contains the list of columns and
26 * whether each column is enabled or not.
28 function getEnabledColumns() {
29 // Use the cache after the second time since access to localStorage is slow.
30 if (cachedEnabledColumns)
31 return cachedEnabledColumns;
33 var json = window.localStorage.getItem(ENABLED_COLUMNS_KEY);
35 cachedEnabledColumns = JSON.parse(json) || {};
37 cachedEnabledColumns = {};
39 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
40 if (typeof(cachedEnabledColumns[DEFAULT_COLUMNS[i][0]]) == 'undefined')
41 cachedEnabledColumns[DEFAULT_COLUMNS[i][0]] = DEFAULT_COLUMNS[i][3];
43 return cachedEnabledColumns;
47 * @return {boolean} the given column (at |columnId|) is enabled or not.
48 * @param {string} columnId The ID of the collumn to be checked.
50 function isColumnEnabled(columnId) {
51 return (getEnabledColumns())[columnId];
55 * Sets the given column either enabled or disabled.
56 * @param {string} columnId The ID of the collumn to be set.
57 * @param {boolean} newChecked True, to set the column enable. False otherwise.
59 function setColumnEnabled(columnId, newChecked) {
60 commands.setUpdateColumn(columnId, newChecked);
61 cachedEnabledColumns[columnId] = newChecked;
62 var json = JSON.stringify(cachedEnabledColumns);
63 window.localStorage.setItem(ENABLED_COLUMNS_KEY, json);
66 // Enable the taskmanager model before the loading of scripts.
68 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
69 var columnId = DEFAULT_COLUMNS[i][0];
70 if (isColumnEnabled(columnId))
71 commands.setUpdateColumn(columnId, true);
73 commands.enableTaskManager();
74 commands.setUpdateColumn('canInspect', true);
75 commands.setUpdateColumn('canActivate', true);