40731a101f30570a8fe653d123035c7e836f92d1Luke SmithAdds support for a message container to appear in the table. This can be used
40731a101f30570a8fe653d123035c7e836f92d1Luke Smithto indicate loading progress, lack of records, or any other communication
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith@module datatable
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith@submodule datatable-message
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith_API docs for this extension are included in the DataTable class._
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke SmithAdds support for a message container to appear in the table. This can be used
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smithto indicate loading progress, lack of records, or any other communication
40731a101f30570a8fe653d123035c7e836f92d1Luke SmithFeatures added to `Y.DataTable`, and made available for custom classes at
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith`Y.DataTable.Message`.
9536cae43ae4c1480743450028cf2fb4a7cdbb91Luke Smith@class DataTable.Message
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith@for DataTable
40731a101f30570a8fe653d123035c7e836f92d1Luke SmithY.namespace('DataTable').Message = Message = function () {};
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith Enables the display of messages in the table. Setting this to false will
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith prevent the message Node from being created and `showMessage` from doing
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @attribute showMessages
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @type {Boolean}
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @default true
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith @since 3.5.0
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith Template used to generate the node that will be used to report messages.
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @property MESSAGE_TEMPLATE
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @type {HTML}
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @default <tbody class="{className}"><td class="{contentClass}" colspan="{colspan}"></td></tbody>
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith @since 3.5.0
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith MESSAGE_TEMPLATE: '<tbody class="{className}"><tr><td class="{contentClass}" colspan="{colspan}"></td></tr></tbody>',
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith Hides the message node.
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @method hideMessage
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @return {DataTable}
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith @since 3.5.0
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith hideMessage: function () {
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith return this;
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith Display the message node and set its content to `message`. If there is a
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith localized `strings` entry for the value of `message`, that string will be
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @method showMessage
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @param {String} message The message name or message itself to display
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @return {DataTable}
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith @since 3.5.0
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith var content = this.getString(message) || message;
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith // TODO: is this right?
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith // If no message provided, remove the message node.
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith return this;
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith //--------------------------------------------------------------------------
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith // Protected methods
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith //--------------------------------------------------------------------------
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith Updates the colspan of the `<td>` used to display the messages.
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @method _afterMessageColumnsChange
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @param {EventFacade} e The columnsChange event
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith @since 3.5.0
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith contentNode.set('colSpan', this._displayColumns.length);
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith Relays to `_uiSetMessage` to hide or show the message node.
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @method _afterMessageDataChange
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @param {EventFacade} e The dataChange event
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith @since 3.5.0
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith Removes the message node if `showMessages` is `false`, or relays to
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith `_uiSetMessage` if `true`.
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @method _afterShowMessagesChange
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @param {EventFacade} e The showMessagesChange event
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith @since 3.5.0
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith } else if (this._messageNode) {
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith Binds the events necessary to keep the message node in sync with the current
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith table and configuration state.
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @method _bindMessageUI
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith @since 3.5.0
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith _bindMessageUI: function () {
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith this.after(['dataChange', '*:add', '*:remove', '*:reset'],
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith this.after('columnsChange', Y.bind('_afterMessageColumnsChange', this));
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith Merges in the message related strings and hooks into the rendering cycle to
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith also render and bind the message node.
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @method initializer
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith @since 3.5.0
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith initializer: function () {
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith this.after('renderBody', Y.bind('_initMessageNode', this));
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith this.after(Y.bind('_bindMessageUI', this), this, 'bindUI');
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith this.after(Y.bind('_syncMessageUI', this), this, 'syncUI');
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith Creates the `_messageNode` property from the configured `MESSAGE_TEMPLATE`
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith and inserts it before the `<table>`'s `<tbody>` node.
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @method _initMessageNode
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith @since 3.5.0
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith contentClass: this.getClassName('message', 'content'),
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith this._tableNode.insertBefore(this._messageNode, this._tbodyNode);
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith Add the messaging related strings to the `strings` map.
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @method _initMessageStrings
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith @since 3.5.0
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith // Not a valueFn because other class extensions will want to add to it
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith this.set('strings', Y.mix((this.get('strings') || {}),
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith Node used to display messages from `showMessage`.
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @property _messageNode
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @type {Node}
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @value `undefined` (not initially set)
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith @since 3.5.0
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith //_messageNode: null,
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith Synchronizes the message UI with the table state.
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @method _syncMessageUI
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith @since 3.5.0
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith _syncMessageUI: function () {
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith Calls `hideMessage` or `showMessage` as appropriate based on the presence of
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith records in the `data` ModelList.
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith This is called when `data` is reset or records are added or removed. Also,
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith if the `showMessages` attribute is updated. In either case, if the
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith triggering event has a `message` property on the EventFacade, it will be
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith passed to `showMessage` (if appropriate). If no such property is on the
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith facade, the `emptyMessage` will be used (see the strings).
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @method _uiSetMessage
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith @param {EventFacade} e The columnsChange event
83abb4e792c64ccc94916233f9dedbd9fa638d50Luke Smith @since 3.5.0
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith _uiSetMessage: function (e) {
40731a101f30570a8fe653d123035c7e836f92d1Luke Smith this.showMessage((e && e.message) || 'emptyMessage');
2f1d3d787984c366443b37599e743b58caaeb259Luke Smith}, '@VERSION@' ,{requires:['datatable-base'], skinnable:true, lang:['en']});