| 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 /** | 5 /** |
| 6 * @fileoverview This is a table column model | 6 * @fileoverview This is a table column model |
| 7 */ | 7 */ |
| 8 cr.define('cr.ui.table', function() { | 8 cr.define('cr.ui.table', function() { |
| 9 /** @const */ var EventTarget = cr.EventTarget; | 9 /** @const */ var EventTarget = cr.EventTarget; |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 var MIMIMAL_WIDTH = 10; | 26 var MIMIMAL_WIDTH = 10; |
| 27 | 27 |
| 28 TableColumnModel.prototype = { | 28 TableColumnModel.prototype = { |
| 29 __proto__: EventTarget.prototype, | 29 __proto__: EventTarget.prototype, |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * The number of the columns. | 32 * The number of the columns. |
| 33 * @type {number} | 33 * @type {number} |
| 34 */ | 34 */ |
| 35 get size() { | 35 get size() { return this.columns_.length; }, |
| 36 return this.columns_.length; | |
| 37 }, | |
| 38 | 36 |
| 39 /** | 37 /** |
| 40 * Returns id of column at the given index. | 38 * Returns id of column at the given index. |
| 41 * @param {number} index The index of the column. | 39 * @param {number} index The index of the column. |
| 42 * @return {string} Column id. | 40 * @return {string} Column id. |
| 43 */ | 41 */ |
| 44 getId: function(index) { | 42 getId: function(index) { return this.columns_[index].id; }, |
| 45 return this.columns_[index].id; | |
| 46 }, | |
| 47 | 43 |
| 48 /** | 44 /** |
| 49 * Returns name of column at the given index. Name is used as column header | 45 * Returns name of column at the given index. Name is used as column header |
| 50 * label. | 46 * label. |
| 51 * @param {number} index The index of the column. | 47 * @param {number} index The index of the column. |
| 52 * @return {string} Column name. | 48 * @return {string} Column name. |
| 53 */ | 49 */ |
| 54 getName: function(index) { | 50 getName: function(index) { return this.columns_[index].name; }, |
| 55 return this.columns_[index].name; | |
| 56 }, | |
| 57 | 51 |
| 58 /** | 52 /** |
| 59 * Sets name of column at the given index. | 53 * Sets name of column at the given index. |
| 60 * @param {number} index The index of the column. | 54 * @param {number} index The index of the column. |
| 61 * @param {string} name Column name. | 55 * @param {string} name Column name. |
| 62 */ | 56 */ |
| 63 setName: function(index, name) { | 57 setName: function(index, name) { |
| 64 if (index < 0 || index >= this.columns_.size - 1) | 58 if (index < 0 || index >= this.columns_.size - 1) |
| 65 return; | 59 return; |
| 66 if (name != this.columns_[index].name) | 60 if (name != this.columns_[index].name) |
| 67 return; | 61 return; |
| 68 | 62 |
| 69 this.columns_[index].name = name; | 63 this.columns_[index].name = name; |
| 70 cr.dispatchSimpleEvent(this, 'change'); | 64 cr.dispatchSimpleEvent(this, 'change'); |
| 71 }, | 65 }, |
| 72 | 66 |
| 73 /** | 67 /** |
| 74 * Returns width (in percent) of column at the given index. | 68 * Returns width (in percent) of column at the given index. |
| 75 * @param {number} index The index of the column. | 69 * @param {number} index The index of the column. |
| 76 * @return {string} Column width in pixels. | 70 * @return {string} Column width in pixels. |
| 77 */ | 71 */ |
| 78 getWidth: function(index) { | 72 getWidth: function(index) { return this.columns_[index].width; }, |
| 79 return this.columns_[index].width; | |
| 80 }, | |
| 81 | 73 |
| 82 /** | 74 /** |
| 83 * Check if the column at the given index should align to the end. | 75 * Check if the column at the given index should align to the end. |
| 84 * @param {number} index The index of the column. | 76 * @param {number} index The index of the column. |
| 85 * @return {boolean} True if the column is aligned to end. | 77 * @return {boolean} True if the column is aligned to end. |
| 86 */ | 78 */ |
| 87 isEndAlign: function(index) { | 79 isEndAlign: function(index) { return this.columns_[index].endAlign; }, |
| 88 return this.columns_[index].endAlign; | |
| 89 }, | |
| 90 | 80 |
| 91 /** | 81 /** |
| 92 * Sets width of column at the given index. | 82 * Sets width of column at the given index. |
| 93 * @param {number} index The index of the column. | 83 * @param {number} index The index of the column. |
| 94 * @param {number} width Column width. | 84 * @param {number} width Column width. |
| 95 */ | 85 */ |
| 96 setWidth: function(index, width) { | 86 setWidth: function(index, width) { |
| 97 if (index < 0 || index >= this.columns_.size - 1) | 87 if (index < 0 || index >= this.columns_.size - 1) |
| 98 return; | 88 return; |
| 99 | 89 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 var contentWidth = this.totalWidth; | 196 var contentWidth = this.totalWidth; |
| 207 column.visible = visible; | 197 column.visible = visible; |
| 208 this.normalizeWidths(contentWidth); | 198 this.normalizeWidths(contentWidth); |
| 209 }, | 199 }, |
| 210 | 200 |
| 211 /** | 201 /** |
| 212 * Returns a column's visibility. | 202 * Returns a column's visibility. |
| 213 * @param {number} index The column index. | 203 * @param {number} index The column index. |
| 214 * @return {boolean} Whether the column is visible. | 204 * @return {boolean} Whether the column is visible. |
| 215 */ | 205 */ |
| 216 isVisible: function(index) { | 206 isVisible: function(index) { return this.columns_[index].visible; } |
| 217 return this.columns_[index].visible; | |
| 218 } | |
| 219 }; | 207 }; |
| 220 | 208 |
| 221 return { | 209 return {TableColumnModel: TableColumnModel}; |
| 222 TableColumnModel: TableColumnModel | |
| 223 }; | |
| 224 }); | 210 }); |
| OLD | NEW |