| 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 representation | 6 * @fileoverview This is a table column representation |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 cr.define('cr.ui.table', function() { | 9 cr.define('cr.ui.table', function() { |
| 10 /** @const */ var EventTarget = cr.EventTarget; | 10 /** @const */ var EventTarget = cr.EventTarget; |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * A table column that wraps column ids and settings. | 13 * A table column that wraps column ids and settings. |
| 14 * @param {string} id | 14 * @param {string} id |
| 15 * @param {string} name | 15 * @param {string} name |
| 16 * @param {number} width | 16 * @param {number} width |
| 17 * @param {boolean=} opt_endAlign | 17 * @param {boolean=} opt_endAlign |
| 18 * @constructor | 18 * @constructor |
| 19 * @extends {cr.EventTarget} | 19 * @extends {cr.EventTarget} |
| 20 */ | 20 */ |
| 21 function TableColumn(id, name, width, opt_endAlign) { | 21 function TableColumn(id, name, width, opt_endAlign) { |
| 22 this.id_ = id; | 22 this.id_ = id; |
| 23 this.name_ = name; | 23 this.name_ = name; |
| 24 this.width_ = width; | 24 this.width_ = width; |
| 25 this.endAlign_ = !!opt_endAlign; | 25 this.endAlign_ = !!opt_endAlign; |
| 26 this.visible_ = true; |
| 26 } | 27 } |
| 27 | 28 |
| 28 TableColumn.prototype = { | 29 TableColumn.prototype = { |
| 29 __proto__: EventTarget.prototype, | 30 __proto__: EventTarget.prototype, |
| 30 | 31 |
| 31 defaultOrder_: 'asc', | 32 defaultOrder_: 'asc', |
| 32 | 33 |
| 33 /** | 34 /** |
| 34 * Clones column. | 35 * Clones column. |
| 35 * @return {cr.ui.table.TableColumn} Clone of the given column. | 36 * @return {cr.ui.table.TableColumn} Clone of the given column. |
| 36 */ | 37 */ |
| 37 clone: function() { | 38 clone: function() { |
| 38 var tableColumn = new TableColumn(this.id_, this.name_, this.width_, | 39 var tableColumn = new TableColumn(this.id_, this.name_, this.width_, |
| 39 this.endAlign_); | 40 this.endAlign_); |
| 40 tableColumn.renderFunction = this.renderFunction_; | 41 tableColumn.renderFunction = this.renderFunction_; |
| 41 tableColumn.headerRenderFunction = this.headerRenderFunction_; | 42 tableColumn.headerRenderFunction = this.headerRenderFunction_; |
| 42 tableColumn.defaultOrder = this.defaultOrder_; | 43 tableColumn.defaultOrder = this.defaultOrder_; |
| 44 |
| 45 tableColumn.visible_ = this.visible_; |
| 46 |
| 43 return tableColumn; | 47 return tableColumn; |
| 44 }, | 48 }, |
| 45 | 49 |
| 46 /** | 50 /** |
| 47 * Renders table cell. This is the default render function. | 51 * Renders table cell. This is the default render function. |
| 48 * @param {*} dataItem The data item to be rendered. | 52 * @param {*} dataItem The data item to be rendered. |
| 49 * @param {string} columnId The column id. | 53 * @param {string} columnId The column id. |
| 50 * @param {cr.ui.Table} table The table. | 54 * @param {cr.ui.Table} table The table. |
| 51 * @return {HTMLElement} Rendered element. | 55 * @return {HTMLElement} Rendered element. |
| 52 */ | 56 */ |
| 53 renderFunction_: function(dataItem, columnId, table) { | 57 renderFunction_: function(dataItem, columnId, table) { |
| 54 var div = /** @type {HTMLElement} */ | 58 var div = /** @type {HTMLElement} */ |
| 55 (table.ownerDocument.createElement('div')); | 59 (table.ownerDocument.createElement('div')); |
| 56 div.textContent = dataItem[columnId]; | 60 div.textContent = dataItem[columnId]; |
| 61 div.hidden = !this.visible; |
| 57 return div; | 62 return div; |
| 58 }, | 63 }, |
| 59 | 64 |
| 60 /** | 65 /** |
| 61 * Renders table header. This is the default render function. | 66 * Renders table header. This is the default render function. |
| 62 * @param {cr.ui.Table} table The table. | 67 * @param {cr.ui.Table} table The table. |
| 63 * @return {Text} Rendered text node. | 68 * @return {Text} Rendered text node. |
| 64 */ | 69 */ |
| 65 headerRenderFunction_: function(table) { | 70 headerRenderFunction_: function(table) { |
| 66 return table.ownerDocument.createTextNode(this.name); | 71 return table.ownerDocument.createTextNode(this.name); |
| 67 }, | 72 }, |
| 73 |
| 74 /** |
| 75 * The width of the column. Hidden columns have zero width. |
| 76 * @type {number} |
| 77 */ |
| 78 get width() { |
| 79 return this.visible_ ? this.width_ : 0; |
| 80 }, |
| 81 |
| 82 /** |
| 83 * The width of the column, disregarding visibility. For hidden columns, |
| 84 * this would be the width of the column if it were to be made visible. |
| 85 * @type {number} |
| 86 */ |
| 87 get absoluteWidth() { |
| 88 return this.width_; |
| 89 }, |
| 68 }; | 90 }; |
| 69 | 91 |
| 70 /** | 92 /** |
| 71 * The column id. | 93 * The column id. |
| 72 * @type {string} | 94 * @type {string} |
| 73 */ | 95 */ |
| 74 cr.defineProperty(TableColumn, 'id'); | 96 cr.defineProperty(TableColumn, 'id'); |
| 75 | 97 |
| 76 /** | 98 /** |
| 77 * The column name | 99 * The column name |
| 78 * @type {string} | 100 * @type {string} |
| 79 */ | 101 */ |
| 80 cr.defineProperty(TableColumn, 'name'); | 102 cr.defineProperty(TableColumn, 'name'); |
| 81 | 103 |
| 82 /** | 104 /** |
| 83 * The column width. | 105 * The column width. |
| 84 * @type {number} | 106 * @type {number} |
| 85 */ | 107 */ |
| 86 cr.defineProperty(TableColumn, 'width'); | 108 cr.defineProperty(TableColumn, 'width'); |
| 87 | 109 |
| 88 /** | 110 /** |
| 111 * The column visibility. |
| 112 * @type {boolean} |
| 113 */ |
| 114 cr.defineProperty(TableColumn, 'visible'); |
| 115 |
| 116 /** |
| 89 * True if the column is aligned to end. | 117 * True if the column is aligned to end. |
| 90 * @type {boolean} | 118 * @type {boolean} |
| 91 */ | 119 */ |
| 92 cr.defineProperty(TableColumn, 'endAlign'); | 120 cr.defineProperty(TableColumn, 'endAlign'); |
| 93 | 121 |
| 94 /** | 122 /** |
| 95 * The column render function. | 123 * The column render function. |
| 96 * @type {function(*, string, cr.ui.Table): HTMLElement} | 124 * @type {function(*, string, cr.ui.Table): HTMLElement} |
| 97 */ | 125 */ |
| 98 cr.defineProperty(TableColumn, 'renderFunction'); | 126 cr.defineProperty(TableColumn, 'renderFunction'); |
| 99 | 127 |
| 100 /** | 128 /** |
| 101 * The column header render function. | 129 * The column header render function. |
| 102 * @type {function(cr.ui.Table): Text} | 130 * @type {function(cr.ui.Table): Text} |
| 103 */ | 131 */ |
| 104 cr.defineProperty(TableColumn, 'headerRenderFunction'); | 132 cr.defineProperty(TableColumn, 'headerRenderFunction'); |
| 105 | 133 |
| 106 /** | 134 /** |
| 107 * Default sorting order for the column ('asc' or 'desc'). | 135 * Default sorting order for the column ('asc' or 'desc'). |
| 108 * @type {string} | 136 * @type {string} |
| 109 */ | 137 */ |
| 110 cr.defineProperty(TableColumn, 'defaultOrder'); | 138 cr.defineProperty(TableColumn, 'defaultOrder'); |
| 111 | 139 |
| 112 return { | 140 return { |
| 113 TableColumn: TableColumn | 141 TableColumn: TableColumn |
| 114 }; | 142 }; |
| 115 }); | 143 }); |
| OLD | NEW |