/**
* Copyright (c) 2014, Oracle and/or its affiliates.
* All rights reserved.
*/
/**
* @preserve Copyright 2013 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*/
/*jslint browser: true,devel:true*/
/**
* @export
* @class oj.TableDataSource
* @classdesc Abstract object representing data used by table component
* @param {Object} data data supported by the components
* @param {Object=} options Options for the TableDataSource
* @constructor
*/
oj.TableDataSource = function(data, options)
{
if (this.constructor == oj.TableDataSource)
{
// This should only be called by the constructors of the subclasses. If you need
// to initialize a new TableDataSource then call the constructors of the subclasses such
// as oj.ArrayTableDataSource or oj.CollectionTableDataSource.
var errSummary = oj.TableDataSource._LOGGER_MSG._ERR_TABLE_DATASOURCE_INSTANTIATED_SUMMARY;
var errDetail = oj.TableDataSource._LOGGER_MSG._ERR_TABLE_DATASOURCE_INSTANTIATED_DETAIL;
throw new Error(errSummary + '\n' + errDetail);
}
// Initialize
this.data = data;
this.options = options;
this.isFetching = false;
this._startIndex = 0;
this.Init();
};
// Subclass from oj.DataSource
oj.Object.createSubclass(oj.TableDataSource, oj.DataSource, "oj.TableDataSource");
/**
* Initializes the instance.
* @export
* @expose
* @memberof! oj.TableDataSource
* @instance
*/
oj.TableDataSource.prototype.Init = function()
{
oj.TableDataSource.superclass.Init.call(this);
};
/**
* Return the row data found at the given index.
*
* @param {number} index Index for which to return the row data.
* @param {Object=} options Options to control the at.
* @param {number} options.fetchSize fetch size to use if the call needs to fetch more records from the server, if virtualized. Overrides the overall fetchSize setting <p>
* @return {Promise} Promise resolves to a compound object which has the structure below. If the index is out of range, Promise resolves to null.<p>
* <table>
* <tbody>
* <tr><td><b>data</b></td><td>The raw row data</td></tr>
* <tr><td><b>index</b></td><td>The index for the row</td></tr>
* <tr><td><b>key</b></td><td>The key value for the row</td></tr>
* </tbody>
* </table>
* @export
* @expose
* @memberof! oj.TableDataSource
* @instance
*/
oj.TableDataSource.prototype.at = function(index, options)
{
oj.Assert.failedInAbstractFunction();
return Promise.reject();
};
/**
* Fetch the row data.
* @param {Object=} options Options to control fetch
* @param {number} options.startIndex The index at which to start fetching records.
* @param {boolean} options.silent If set, do not fire a sync event.
* @return {Promise} Promise object resolves to a compound object which contains an array of row data objects, an array of ids, and the startIndex triggering done when complete.<p>
* The structure of the resolved compound object is:<p>
* <table>
* <tbody>
* <tr><td><b>data</b></td><td>An array of raw row data</td></tr>
* <tr><td><b>keys</b></td><td>An array of key values for the rows</td></tr>
* <tr><td><b>startIndex</b></td><td>The startIndex for the returned set of rows</td></tr>
* </tbody>
* </table>
* @export
* @expose
* @memberof! oj.TableDataSource
* @instance
*/
oj.TableDataSource.prototype.fetch = function(options)
{
oj.Assert.failedInAbstractFunction();
return Promise.reject();
};
/**
* Return the first row data whose id value is the given id
* @param {string} id ID for which to return the row data, if found.
* @param {Object=} options Options to control the get.
* @param {number} options.fetchSize fetch size to use if the call needs to fetch more records from the server, if virtualized. Overrides the overall fetchSize setting <p>
* @return {Promise} Promise which resolves to a compound object which has the structure below where the id matches the given id. If none are found, resolves to null.<p>
* <table>
* <tbody>
* <tr><td><b>data</b></td><td>The raw row data</td></tr>
* <tr><td><b>index</b></td><td>The index for the row</td></tr>
* <tr><td><b>key</b></td><td>The key value for the row</td></tr>
* </tbody>
* </table>
* @export
* @expose
* @memberof! oj.TableDataSource
* @instance
*/
oj.TableDataSource.prototype.get = function(id, options)
{
oj.Assert.failedInAbstractFunction();
return Promise.reject();
};
/**
* Determines whether this TableDataSource supports certain feature.
* @param {string} feature the feature in which its capabilities is inquired. Currently the only valid feature is "sort".
* @return {string|null} the name of the feature. For "sort", the valid return values are: "full", "none".
* Returns null if the feature is not recognized.
* @export
* @expose
* @memberof! oj.TableDataSource
* @instance
*/
oj.TableDataSource.prototype.getCapability = function(feature)
{
return null;
};
/**
* Performs a sort on the data source. Null criteria clears the existing sort.
* @param {Object} criteria the sort criteria.
* @param {Object} criteria.key The key that identifies which field to sort
* @param {string} criteria.direction the sort direction, valid values are "ascending", "descending", "none" (default)
* @return {Promise} promise object triggering done when complete.
* @export
* @expose
* @memberof! oj.TableDataSource
* @instance
*/
oj.TableDataSource.prototype.sort = function(criteria)
{
oj.Assert.failedInAbstractFunction();
return Promise.reject();
};
/**
* Return the total size of data available, including server side if not local.
* @returns {number} total size of data
* @export
* @expose
* @memberof! oj.TableDataSource
* @instance
*/
oj.TableDataSource.prototype.totalSize = function()
{
oj.Assert.failedInAbstractFunction();
return 0;
};
/**
* @export
* Event types
* @enum {string}
*/
oj.TableDataSource.EventType =
{
/** Triggered when a Row is added to a TableDataSource<p>
* The event payload contains:<p>
* <table cellspacing="0" style="border-collapse: collapse;">
* <tbody>
* <tr><td><b>data</b></td><td>An array of raw row data</td></tr>
* <tr><td><b>keys</b></td><td>An array of key values for the rows</td></tr>
* <tr><td><b>indexes</b></td><td>An array of index values for the rows in post-insert sorted order</td></tr>
* </tbody>
* </table>
*/
'ADD': "add",
/** Triggered when a Row is removed from a TableDataSource<p>
* The event payload contains:<p>
* <table cellspacing="0" style="border-collapse: collapse;">
* <tbody>
* <tr><td><b>data</b></td><td>An array of raw row data</td></tr>
* <tr><td><b>keys</b></td><td>An array of key values for the rows</td></tr>
* <tr><td><b>indexes</b></td><td>An array of index values for the rows in pre-remove sorted order</td></tr>
* </tbody>
* </table>
*/
'REMOVE': "remove",
/** Triggered when a TableDataSource is reset */
'RESET': "reset",
/** Triggered when a TableDataSource is refreshed */
'REFRESH': "refresh",
/** Triggered when a TableDataSource is sorted<p>
* The event payload contains:<p>
* <table cellspacing="0" style="border-collapse: collapse;">
* <tbody>
* <tr><td><b>header</b></td><td>the key of the header which was sorted on</td></tr>
* <tr><td><b>direction</b></td><td>the direction of the sort ascending/descending</td></tr>
* </tbody>
* </table>
*/
'SORT': "sort",
/** Triggered when a Row's attributes are changed<p>
* The event payload contains:<p>
* <table cellspacing="0" style="border-collapse: collapse;">
* <tbody>
* <tr><td><b>data</b></td><td>An array of raw row data</td></tr>
* <tr><td><b>keys</b></td><td>An array of key values for the rows</td></tr>
* <tr><td><b>indexes</b></td><td>An array of index values for the rows</td></tr>
* </tbody>
* </table>
*/
'CHANGE': "change",
/** Triggered when a TableDataSource has sent a fetch request
* The event payload contains:<p>
* <table cellspacing="0" style="border-collapse: collapse;">
* <tbody>
* <tr><td><b>startIndex</b></td><td>The start index at which the fetch was invoked</td></tr>
* </tbody>
* </table>
*/
'REQUEST': "request",
/** Triggered when a TableDataSource has been updated by a fetch<p>
* The event payload contains:<p>
* <table cellspacing="0" style="border-collapse: collapse;">
* <tbody>
* <tr><td><b>data</b></td><td>An array of raw row data</td></tr>
* <tr><td><b>keys</b></td><td>An array of key values for the rows</td></tr>
* <tr><td><b>startIndex</b></td><td>The start index at which the fetch occurred</td></tr>
* </tbody>
* </table>
*/
'SYNC': "sync",
/** Triggered when an error occurred on the TableDataSource */
'ERROR': "error"
};
oj.TableDataSource._LOGGER_MSG =
{
'_ERR_TABLE_DATASOURCE_INSTANTIATED_SUMMARY': 'oj.TableDataSource constructor called.',
'_ERR_TABLE_DATASOURCE_INSTANTIATED_DETAIL': 'Please do not instantiate oj.TableDataSource. Please use one of the subclasses instead such as oj.ArrayTableDataSource or oj.CollectionTableDataSource.',
'_ERR_DATA_INVALID_TYPE_SUMMARY': 'Invalid data type.',
'_ERR_DATA_INVALID_TYPE_DETAIL': 'Please specify the appropriate data type.'
};
Source: src/main/javascript/oracle/oj/ojdatacollection-common/TableDataSource.js
Oracle® JavaScript Extension Toolkit (JET)
1.1.2
E65298-01