2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('datatable-message', function (Y, NAME) {
11 Adds support for a message container to appear in the table. This can be used
12 to indicate loading progress, lack of records, or any other communication
16 @submodule datatable-message
22 _API docs for this extension are included in the DataTable class._
24 Adds support for a message container to appear in the table. This can be used
25 to indicate loading progress, lack of records, or any other communication
28 Features added to `Y.DataTable`, and made available for custom classes at
29 `Y.DataTable.Message`.
31 @class DataTable.Message
35 Y.namespace('DataTable').Message = Message = function () {};
39 Enables the display of messages in the table. Setting this to false will
40 prevent the message Node from being created and `showMessage` from doing
43 @attribute showMessages
50 validator: Y.Lang.isBoolean
54 Y.mix(Message.prototype, {
56 Template used to generate the node that will be used to report messages.
58 @property MESSAGE_TEMPLATE
60 @default <tbody class="{className}"><td class="{contentClass}" colspan="{colspan}"></td></tbody>
63 MESSAGE_TEMPLATE: '<tbody class="{className}"><tr><td class="{contentClass}" colspan="{colspan}"></td></tr></tbody>',
66 Hides the message node.
73 hideMessage: function () {
74 this.get('boundingBox').removeClass(
75 this.getClassName('message', 'visible'));
81 Display the message node and set its content to `message`. If there is a
82 localized `strings` entry for the value of `message`, that string will be
86 @param {String} message The message name or message itself to display
91 showMessage: function (message) {
92 var content = this.getString(message) || message;
94 if (!this._messageNode) {
95 this._initMessageNode();
98 if (this.get('showMessages')) {
100 this._messageNode.one(
101 '.' + this.getClassName('message', 'content'))
104 this.get('boundingBox').addClass(
105 this.getClassName('message','visible'));
107 // TODO: is this right?
108 // If no message provided, remove the message node.
116 //--------------------------------------------------------------------------
118 //--------------------------------------------------------------------------
120 Updates the colspan of the `<td>` used to display the messages.
122 @method _afterMessageColumnsChange
123 @param {EventFacade} e The columnsChange event
127 _afterMessageColumnsChange: function () {
130 if (this._messageNode) {
131 contentNode = this._messageNode.one(
132 '.' + this.getClassName('message', 'content'));
135 // FIXME: This needs to become a class extension plus a view or
136 // plugin for the table view.
137 contentNode.set('colSpan', this._displayColumns.length);
143 Relays to `_uiSetMessage` to hide or show the message node.
145 @method _afterMessageDataChange
146 @param {EventFacade} e The dataChange event
150 _afterMessageDataChange: function () {
151 this._uiSetMessage();
155 Removes the message node if `showMessages` is `false`, or relays to
156 `_uiSetMessage` if `true`.
158 @method _afterShowMessagesChange
159 @param {EventFacade} e The showMessagesChange event
163 _afterShowMessagesChange: function (e) {
165 this._uiSetMessage(e);
166 } else if (this._messageNode) {
167 this.get('boundingBox').removeClass(
168 this.getClassName('message', 'visible'));
170 this._messageNode.remove().destroy(true);
171 this._messageNode = null;
176 Binds the events necessary to keep the message node in sync with the current
177 table and configuration state.
179 @method _bindMessageUI
183 _bindMessageUI: function () {
184 this.after(['dataChange', '*:add', '*:remove', '*:reset'],
185 Y.bind('_afterMessageDataChange', this));
187 this.after('columnsChange', Y.bind('_afterMessageColumnsChange', this));
189 this.after('showMessagesChange',
190 Y.bind('_afterShowMessagesChange', this));
194 Merges in the message related strings and hooks into the rendering cycle to
195 also render and bind the message node.
201 initializer: function () {
202 this._initMessageStrings();
204 if (this.get('showMessages')) {
205 this.after('table:renderBody', Y.bind('_initMessageNode', this));
208 this.after(Y.bind('_bindMessageUI', this), this, 'bindUI');
209 this.after(Y.bind('_syncMessageUI', this), this, 'syncUI');
213 Creates the `_messageNode` property from the configured `MESSAGE_TEMPLATE`
214 and inserts it before the `<table>`'s `<tbody>` node.
216 @method _initMessageNode
220 _initMessageNode: function () {
221 if (!this._messageNode) {
222 this._messageNode = Y.Node.create(
223 Y.Lang.sub(this.MESSAGE_TEMPLATE, {
224 className: this.getClassName('message'),
225 contentClass: this.getClassName('message', 'content'),
226 colspan: this._displayColumns.length || 1
229 this._tableNode.insertBefore(this._messageNode, this._tbodyNode);
234 Add the messaging related strings to the `strings` map.
236 @method _initMessageStrings
240 _initMessageStrings: function () {
241 // Not a valueFn because other class extensions will want to add to it
242 this.set('strings', Y.mix((this.get('strings') || {}),
243 Y.Intl.get('datatable-message')));
247 Node used to display messages from `showMessage`.
249 @property _messageNode
251 @value `undefined` (not initially set)
254 //_messageNode: null,
257 Synchronizes the message UI with the table state.
259 @method _syncMessageUI
263 _syncMessageUI: function () {
264 this._uiSetMessage();
268 Calls `hideMessage` or `showMessage` as appropriate based on the presence of
269 records in the `data` ModelList.
271 This is called when `data` is reset or records are added or removed. Also,
272 if the `showMessages` attribute is updated. In either case, if the
273 triggering event has a `message` property on the EventFacade, it will be
274 passed to `showMessage` (if appropriate). If no such property is on the
275 facade, the `emptyMessage` will be used (see the strings).
277 @method _uiSetMessage
278 @param {EventFacade} e The columnsChange event
282 _uiSetMessage: function (e) {
283 if (!this.data.size()) {
284 this.showMessage((e && e.message) || 'emptyMessage');
292 if (Y.Lang.isFunction(Y.DataTable)) {
293 Y.Base.mix(Y.DataTable, [ Message ]);
297 }, '3.13.0', {"requires": ["datatable-base"], "lang": ["en", "fr", "es", "hu", "it"], "skinnable": true});