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