weekly release 2.4dev
[moodle.git] / lib / yuilib / 3.7.1 / build / datatable-core / datatable-core-coverage.js
blob4e9e7379d90e08d823600d810d4d7d1fb8ea3e70
1 /*
2 YUI 3.7.1 (build 5627)
3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
7 if (typeof _yuitest_coverage == "undefined"){
8     _yuitest_coverage = {};
9     _yuitest_coverline = function(src, line){
10         var coverage = _yuitest_coverage[src];
11         if (!coverage.lines[line]){
12             coverage.calledLines++;
13         }
14         coverage.lines[line]++;
15     };
16     _yuitest_coverfunc = function(src, name, line){
17         var coverage = _yuitest_coverage[src],
18             funcId = name + ":" + line;
19         if (!coverage.functions[funcId]){
20             coverage.calledFunctions++;
21         }
22         coverage.functions[funcId]++;
23     };
25 _yuitest_coverage["build/datatable-core/datatable-core.js"] = {
26     lines: {},
27     functions: {},
28     coveredLines: 0,
29     calledLines: 0,
30     coveredFunctions: 0,
31     calledFunctions: 0,
32     path: "build/datatable-core/datatable-core.js",
33     code: []
35 _yuitest_coverage["build/datatable-core/datatable-core.js"].code=["YUI.add('datatable-core', function (Y, NAME) {","","/**","The core implementation of the `DataTable` and `DataTable.Base` Widgets.","","@module datatable","@submodule datatable-core","@since 3.5.0","**/","","var INVALID = Y.Attribute.INVALID_VALUE,","","    Lang         = Y.Lang,","    isFunction   = Lang.isFunction,","    isObject     = Lang.isObject,","    isArray      = Lang.isArray,","    isString     = Lang.isString,","    isNumber     = Lang.isNumber,","","    toArray = Y.Array,","","    keys = Y.Object.keys,","","    Table;","    ","/**","_API docs for this extension are included in the DataTable class._","","Class extension providing the core API and structure for the DataTable Widget.","","Use this class extension with Widget or another Base-based superclass to create","the basic DataTable model API and composing class structure.","","@class DataTable.Core","@for DataTable","@since 3.5.0","**/","Table = Y.namespace('DataTable').Core = function () {};","","Table.ATTRS = {","    /**","    Columns to include in the rendered table.","    ","    If omitted, the attributes on the configured `recordType` or the first item","    in the `data` collection will be used as a source.","","    This attribute takes an array of strings or objects (mixing the two is","    fine).  Each string or object is considered a column to be rendered.","    Strings are converted to objects, so `columns: ['first', 'last']` becomes","    `columns: [{ key: 'first' }, { key: 'last' }]`.","","    DataTable.Core only concerns itself with a few properties of columns.","    These properties are:","","    * `key` - Used to identify the record field/attribute containing content for","      this column.  Also used to create a default Model if no `recordType` or","      `data` are provided during construction.  If `name` is not specified, this","      is assigned to the `_id` property (with added incrementer if the key is","      used by multiple columns).","    * `children` - Traversed to initialize nested column objects","    * `name` - Used in place of, or in addition to, the `key`.  Useful for","      columns that aren't bound to a field/attribute in the record data.  This","      is assigned to the `_id` property.","    * `id` - For backward compatibility.  Implementers can specify the id of","      the header cell.  This should be avoided, if possible, to avoid the","      potential for creating DOM elements with duplicate IDs.","    * `field` - For backward compatibility.  Implementers should use `name`.","    * `_id` - Assigned unique-within-this-instance id for a column.  By order","      of preference, assumes the value of `name`, `key`, `id`, or `_yuid`.","      This is used by the rendering views as well as feature module","      as a means to identify a specific column without ambiguity (such as","      multiple columns using the same `key`.","    * `_yuid` - Guid stamp assigned to the column object.","    * `_parent` - Assigned to all child columns, referencing their parent","      column.","","    @attribute columns","    @type {Object[]|String[]}","    @default (from `recordType` ATTRS or first item in the `data`)","    @since 3.5.0","    **/","    columns: {","        // TODO: change to setter to clone input array/objects","        validator: isArray,","        setter: '_setColumns',","        getter: '_getColumns'","    },","","    /**","    Model subclass to use as the `model` for the ModelList stored in the `data`","    attribute.","","    If not provided, it will try really hard to figure out what to use.  The","    following attempts will be made to set a default value:","    ","    1. If the `data` attribute is set with a ModelList instance and its `model`","       property is set, that will be used.","    2. If the `data` attribute is set with a ModelList instance, and its","       `model` property is unset, but it is populated, the `ATTRS` of the","       `constructor of the first item will be used.","    3. If the `data` attribute is set with a non-empty array, a Model subclass","       will be generated using the keys of the first item as its `ATTRS` (see","       the `_createRecordClass` method).","    4. If the `columns` attribute is set, a Model subclass will be generated","       using the columns defined with a `key`. This is least desirable because","       columns can be duplicated or nested in a way that's not parsable.","    5. If neither `data` nor `columns` is set or populated, a change event","       subscriber will listen for the first to be changed and try all over","       again.","","    @attribute recordType","    @type {Function}","    @default (see description)","    @since 3.5.0","    **/","    recordType: {","        getter: '_getRecordType',","        setter: '_setRecordType'","    },","","    /**","    The collection of data records to display.  This attribute is a pass","    through to a `data` property, which is a ModelList instance.","","    If this attribute is passed a ModelList or subclass, it will be assigned to","    the property directly.  If an array of objects is passed, a new ModelList","    will be created using the configured `recordType` as its `model` property","    and seeded with the array.","","    Retrieving this attribute will return the ModelList stored in the `data`","    property.","","    @attribute data","    @type {ModelList|Object[]}","    @default `new ModelList()`","    @since 3.5.0","    **/","    data: {","        valueFn: '_initData',","        setter : '_setData',","        lazyAdd: false","    },","","    /**","    Content for the `<table summary=\"ATTRIBUTE VALUE HERE\">`.  Values assigned","    to this attribute will be HTML escaped for security.","","    @attribute summary","    @type {String}","    @default '' (empty string)","    @since 3.5.0","    **/","    //summary: {},","","    /**","    HTML content of an optional `<caption>` element to appear above the table.","    Leave this config unset or set to a falsy value to remove the caption.","","    @attribute caption","    @type HTML","    @default '' (empty string)","    @since 3.5.0","    **/","    //caption: {},","","    /**","    Deprecated as of 3.5.0. Passes through to the `data` attribute.","","    WARNING: `get('recordset')` will NOT return a Recordset instance as of","    3.5.0.  This is a break in backward compatibility.","","    @attribute recordset","    @type {Object[]|Recordset}","    @deprecated Use the `data` attribute","    @since 3.5.0","    **/","    recordset: {","        setter: '_setRecordset',","        getter: '_getRecordset',","        lazyAdd: false","    },","","    /**","    Deprecated as of 3.5.0. Passes through to the `columns` attribute.","","    WARNING: `get('columnset')` will NOT return a Columnset instance as of","    3.5.0.  This is a break in backward compatibility.","","    @attribute columnset","    @type {Object[]}","    @deprecated Use the `columns` attribute","    @since 3.5.0","    **/","    columnset: {","        setter: '_setColumnset',","        getter: '_getColumnset',","        lazyAdd: false","    }","};","","Y.mix(Table.prototype, {","    // -- Instance properties -------------------------------------------------","    /**","    The ModelList that manages the table's data.","","    @property data","    @type {ModelList}","    @default undefined (initially unset)","    @since 3.5.0","    **/","    //data: null,","","    // -- Public methods ------------------------------------------------------","","    /**","    Gets the column configuration object for the given key, name, or index.  For","    nested columns, `name` can be an array of indexes, each identifying the index","    of that column in the respective parent's \"children\" array.","","    If you pass a column object, it will be returned.","","    For columns with keys, you can also fetch the column with","    `instance.get('columns.foo')`.","","    @method getColumn","    @param {String|Number|Number[]} name Key, \"name\", index, or index array to","                identify the column","    @return {Object} the column configuration object","    @since 3.5.0","    **/","    getColumn: function (name) {","        var col, columns, i, len, cols;","","        if (isObject(name) && !isArray(name)) {","            // TODO: support getting a column from a DOM node - this will cross","            // the line into the View logic, so it should be relayed","","            // Assume an object passed in is already a column def","            col = name;","        } else {","            col = this.get('columns.' + name);","        }","","        if (col) {","            return col;","        }","","        columns = this.get('columns');","","        if (isNumber(name) || isArray(name)) {","            name = toArray(name);","            cols = columns;","","            for (i = 0, len = name.length - 1; cols && i < len; ++i) {","                cols = cols[name[i]] && cols[name[i]].children;","            }","","            return (cols && cols[name[i]]) || null;","        }","","        return null;","    },","","    /**","    Returns the Model associated to the record `id`, `clientId`, or index (not","    row index).  If none of those yield a Model from the `data` ModelList, the","    arguments will be passed to the `view` instance's `getRecord` method","    if it has one.","","    If no Model can be found, `null` is returned.","","    @method getRecord","    @param {Number|String|Node} seed Record `id`, `clientId`, index, Node, or","        identifier for a row or child element","    @return {Model}","    @since 3.5.0","    **/","    getRecord: function (seed) {","        var record = this.data.getById(seed) || this.data.getByClientId(seed);","","        if (!record) {","            if (isNumber(seed)) {","                record = this.data.item(seed);","            }","            ","            // TODO: this should be split out to base somehow","            if (!record && this.view && this.view.getRecord) {","                record = this.view.getRecord.apply(this.view, arguments);","            }","        }","","        return record || null;","    },","","    // -- Protected and private properties and methods ------------------------","","    /**","    This tells `Y.Base` that it should create ad-hoc attributes for config","    properties passed to DataTable's constructor. This is useful for setting","    configurations on the DataTable that are intended for the rendering View(s).","","    @property _allowAdHocAttrs","    @type Boolean","    @default true","    @protected","    @since 3.6.0","    **/","    _allowAdHocAttrs: true,","","    /**","    A map of column key to column configuration objects parsed from the","    `columns` attribute.","","    @property _columnMap","    @type {Object}","    @default undefined (initially unset)","    @protected","    @since 3.5.0","    **/","    //_columnMap: null,","","    /**","    The Node instance of the table containing the data rows.  This is set when","    the table is rendered.  It may also be set by progressive enhancement,","    though this extension does not provide the logic to parse from source.","","    @property _tableNode","    @type {Node}","    @default undefined (initially unset)","    @protected","    @since 3.5.0","    **/","    //_tableNode: null,","","    /**","    Updates the `_columnMap` property in response to changes in the `columns`","    attribute.","","    @method _afterColumnsChange","    @param {EventFacade} e The `columnsChange` event object","    @protected","    @since 3.5.0","    **/","    _afterColumnsChange: function (e) {","        this._setColumnMap(e.newVal);","    },","","    /**","    Updates the `modelList` attributes of the rendered views in response to the","    `data` attribute being assigned a new ModelList.","","    @method _afterDataChange","    @param {EventFacade} e the `dataChange` event","    @protected","    @since 3.5.0","    **/","    _afterDataChange: function (e) {","        var modelList = e.newVal;","","        this.data = e.newVal;","","        if (!this.get('columns') && modelList.size()) {","            // TODO: this will cause a re-render twice because the Views are","            // subscribed to columnsChange","            this._initColumns();","        }","    },","","    /**","    Assigns to the new recordType as the model for the data ModelList","","    @method _afterRecordTypeChange","    @param {EventFacade} e recordTypeChange event","    @protected","    @since 3.6.0","    **/","    _afterRecordTypeChange: function (e) {","        var data = this.data.toJSON();","","        this.data.model = e.newVal;","","        this.data.reset(data);","","        if (!this.get('columns') && data) {","            if (data.length) {","                this._initColumns();","            } else {","                this.set('columns', keys(e.newVal.ATTRS));","            }","        }","    },","","    /**","    Creates a Model subclass from an array of attribute names or an object of","    attribute definitions.  This is used to generate a class suitable to","    represent the data passed to the `data` attribute if no `recordType` is","    set.","","    @method _createRecordClass","    @param {String[]|Object} attrs Names assigned to the Model subclass's","                `ATTRS` or its entire `ATTRS` definition object","    @return {Model}","    @protected","    @since 3.5.0","    **/","    _createRecordClass: function (attrs) {","        var ATTRS, i, len;","","        if (isArray(attrs)) {","            ATTRS = {};","","            for (i = 0, len = attrs.length; i < len; ++i) {","                ATTRS[attrs[i]] = {};","            }","        } else if (isObject(attrs)) {","            ATTRS = attrs;","        }","","        return Y.Base.create('record', Y.Model, [], null, { ATTRS: ATTRS });","    },","","    /**","    Tears down the instance.","","    @method destructor","    @protected","    @since 3.6.0","    **/","    destructor: function () {","        new Y.EventHandle(Y.Object.values(this._eventHandles)).detach();","    },","","    /**","    The getter for the `columns` attribute.  Returns the array of column","    configuration objects if `instance.get('columns')` is called, or the","    specific column object if `instance.get('columns.columnKey')` is called.","","    @method _getColumns","    @param {Object[]} columns The full array of column objects","    @param {String} name The attribute name requested","                         (e.g. 'columns' or 'columns.foo');","    @protected","    @since 3.5.0","    **/","    _getColumns: function (columns, name) {","        // Workaround for an attribute oddity (ticket #2529254)","        // getter is expected to return an object if get('columns.foo') is called.","        // Note 'columns.' is 8 characters","        return name.length > 8 ? this._columnMap : columns;","    },","","    /**","    Relays the `get()` request for the deprecated `columnset` attribute to the","    `columns` attribute.","","    THIS BREAKS BACKWARD COMPATIBILITY.  3.4.1 and prior implementations will","    expect a Columnset instance returned from `get('columnset')`.","","    @method _getColumnset","    @param {Object} ignored The current value stored in the `columnset` state","    @param {String} name The attribute name requested","                         (e.g. 'columnset' or 'columnset.foo');","    @deprecated This will be removed with the `columnset` attribute in a future","                version.","    @protected","    @since 3.5.0","    **/","    _getColumnset: function (_, name) {","        return this.get(name.replace(/^columnset/, 'columns'));","    },","","    /**","    Returns the Model class of the instance's `data` attribute ModelList.  If","    not set, returns the explicitly configured value.","","    @method _getRecordType","    @param {Model} val The currently configured value","    @return {Model}","    **/","    _getRecordType: function (val) {","        // Prefer the value stored in the attribute because the attribute","        // change event defaultFn sets e.newVal = this.get('recordType')","        // before notifying the after() subs.  But if this getter returns","        // this.data.model, then after() subs would get e.newVal === previous","        // model before _afterRecordTypeChange can set","        // this.data.model = e.newVal","        return val || (this.data && this.data.model);","    },","","    /**","    Initializes the `_columnMap` property from the configured `columns`","    attribute.  If `columns` is not set, but there are records in the `data`","    ModelList, use","    `ATTRS` of that class.","","    @method _initColumns","    @protected","    @since 3.5.0","    **/","    _initColumns: function () {","        var columns = this.get('columns') || [],","            item;","        ","        // Default column definition from the configured recordType","        if (!columns.length && this.data.size()) {","            // TODO: merge superclass attributes up to Model?","            item = this.data.item(0);","","            if (item.toJSON) {","                item = item.toJSON();","            }","","            this.set('columns', keys(item));","        }","","        this._setColumnMap(columns);","    },","","    /**","    Sets up the change event subscriptions to maintain internal state.","","    @method _initCoreEvents","    @protected","    @since 3.6.0","    **/","    _initCoreEvents: function () {","        this._eventHandles.coreAttrChanges = this.after({","            columnsChange   : Y.bind('_afterColumnsChange', this),","            recordTypeChange: Y.bind('_afterRecordTypeChange', this),","            dataChange      : Y.bind('_afterDataChange', this)","        });","    },","","    /**","    Defaults the `data` attribute to an empty ModelList if not set during","    construction.  Uses the configured `recordType` for the ModelList's `model`","    proeprty if set.","","    @method _initData","    @protected","    @return {ModelList}","    @since 3.6.0","    **/","    _initData: function () {","        var recordType = this.get('recordType'),","            // TODO: LazyModelList if recordType doesn't have complex ATTRS","            modelList = new Y.ModelList();","","        if (recordType) {","            modelList.model = recordType;","        }","","        return modelList;","    },","","    /**","    Initializes the instance's `data` property from the value of the `data`","    attribute.  If the attribute value is a ModelList, it is assigned directly","    to `this.data`.  If it is an array, a ModelList is created, its `model`","    property is set to the configured `recordType` class, and it is seeded with","    the array data.  This ModelList is then assigned to `this.data`.","","    @method _initDataProperty","    @param {Array|ModelList|ArrayList} data Collection of data to populate the","            DataTable","    @protected","    @since 3.6.0","    **/","    _initDataProperty: function (data) {","        var recordType;","","        if (!this.data) {","            recordType = this.get('recordType');","","            if (data && data.each && data.toJSON) {","                this.data = data;","","                if (recordType) {","                    this.data.model = recordType;","                }","            } else {","                // TODO: customize the ModelList or read the ModelList class","                // from a configuration option?","                this.data = new Y.ModelList();","                ","                if (recordType) {","                    this.data.model = recordType;","                }","            }","","            // TODO: Replace this with an event relay for specific events.","            // Using bubbling causes subscription conflicts with the models'","            // aggregated change event and 'change' events from DOM elements","            // inside the table (via Widget UI event).","            this.data.addTarget(this);","        }","    },","","    /**","    Initializes the columns, `recordType` and data ModelList.","","    @method initializer","    @param {Object} config Configuration object passed to constructor","    @protected","    @since 3.5.0","    **/","    initializer: function (config) {","        var data       = config.data,","            columns    = config.columns,","            recordType;","","        // Referencing config.data to allow _setData to be more stringent","        // about its behavior","        this._initDataProperty(data);","","        // Default columns from recordType ATTRS if recordType is supplied at","        // construction.  If no recordType is supplied, but the data is","        // supplied as a non-empty array, use the keys of the first item","        // as the columns.","        if (!columns) {","            recordType = (config.recordType || config.data === this.data) &&","                            this.get('recordType');","","            if (recordType) {","                columns = keys(recordType.ATTRS);","            } else if (isArray(data) && data.length) {","                columns = keys(data[0]);","            }","","            if (columns) {","                this.set('columns', columns);","            }","        }","","        this._initColumns();","","        this._eventHandles = {};","","        this._initCoreEvents();","    },","","    /**","    Iterates the array of column configurations to capture all columns with a","    `key` property.  An map is built with column keys as the property name and","    the corresponding column object as the associated value.  This map is then","    assigned to the instance's `_columnMap` property.","","    @method _setColumnMap","    @param {Object[]|String[]} columns The array of column config objects","    @protected","    @since 3.6.0","    **/","    _setColumnMap: function (columns) {","        var map = {};","        ","        function process(cols) {","            var i, len, col, key;","","            for (i = 0, len = cols.length; i < len; ++i) {","                col = cols[i];","                key = col.key;","","                // First in wins for multiple columns with the same key","                // because the first call to genId (in _setColumns) will","                // return the same key, which will then be overwritten by the","                // subsequent same-keyed column.  So table.getColumn(key) would","                // return the last same-keyed column.","                if (key && !map[key]) {","                    map[key] = col;","                }","","                //TODO: named columns can conflict with keyed columns","                map[col._id] = col;","","                if (col.children) {","                    process(col.children);","                }","            }","        }","","        process(columns);","","        this._columnMap = map;","    },","","    /**","    Translates string columns into objects with that string as the value of its","    `key` property.","","    All columns are assigned a `_yuid` stamp and `_id` property corresponding","    to the column's configured `name` or `key` property with any spaces","    replaced with dashes.  If the same `name` or `key` appears in multiple","    columns, subsequent appearances will have their `_id` appended with an","    incrementing number (e.g. if column \"foo\" is included in the `columns`","    attribute twice, the first will get `_id` of \"foo\", and the second an `_id`","    of \"foo1\").  Columns that are children of other columns will have the","    `_parent` property added, assigned the column object to which they belong.","","    @method _setColumns","    @param {null|Object[]|String[]} val Array of config objects or strings","    @return {null|Object[]}","    @protected","    **/","    _setColumns: function (val) {","        var keys = {},","            known = [],","            knownCopies = [],","            arrayIndex = Y.Array.indexOf;","        ","        function copyObj(o) {","            var copy = {},","                key, val, i;","","            known.push(o);","            knownCopies.push(copy);","","            for (key in o) {","                if (o.hasOwnProperty(key)) {","                    val = o[key];","","                    if (isArray(val)) {","                        copy[key] = val.slice();","                    } else if (isObject(val, true)) {","                        i = arrayIndex(val, known);","","                        copy[key] = i === -1 ? copyObj(val) : knownCopies[i];","                    } else {","                        copy[key] = o[key];","                    }","                }","            }","","            return copy;","        }","","        function genId(name) {","            // Sanitize the name for use in generated CSS classes.","            // TODO: is there more to do for other uses of _id?","            name = name.replace(/\\s+/, '-');","","            if (keys[name]) {","                name += (keys[name]++);","            } else {","                keys[name] = 1;","            }","","            return name;","        }","","        function process(cols, parent) {","            var columns = [],","                i, len, col, yuid;","","            for (i = 0, len = cols.length; i < len; ++i) {","                columns[i] = // chained assignment","                col = isString(cols[i]) ? { key: cols[i] } : copyObj(cols[i]);","","                yuid = Y.stamp(col);","","                // For backward compatibility","                if (!col.id) {","                    // Implementers can shoot themselves in the foot by setting","                    // this config property to a non-unique value","                    col.id = yuid;","                }","                if (col.field) {","                    // Field is now known as \"name\" to avoid confusion with data","                    // fields or schema.resultFields","                    col.name = col.field;","                }","","                if (parent) {","                    col._parent = parent;","                } else {","                    delete col._parent;","                }","","                // Unique id based on the column's configured name or key,","                // falling back to the yuid.  Duplicates will have a counter","                // added to the end.","                col._id = genId(col.name || col.key || col.id);","","                if (isArray(col.children)) {","                    col.children = process(col.children, col);","                }","            }","","            return columns;","        }","","        return val && process(val);","    },","","    /**","    Relays attribute assignments of the deprecated `columnset` attribute to the","    `columns` attribute.  If a Columnset is object is passed, its basic object","    structure is mined.","","    @method _setColumnset","    @param {Array|Columnset} val The columnset value to relay","    @deprecated This will be removed with the deprecated `columnset` attribute","                in a later version.","    @protected","    @since 3.5.0","    **/","    _setColumnset: function (val) {","        this.set('columns', val);","","        return isArray(val) ? val : INVALID;","    },","","    /**","    Accepts an object with `each` and `getAttrs` (preferably a ModelList or","    subclass) or an array of data objects.  If an array is passes, it will","    create a ModelList to wrap the data.  In doing so, it will set the created","    ModelList's `model` property to the class in the `recordType` attribute,","    which will be defaulted if not yet set.","","    If the `data` property is already set with a ModelList, passing an array as","    the value will call the ModelList's `reset()` method with that array rather","    than replacing the stored ModelList wholesale.","","    Any non-ModelList-ish and non-array value is invalid.","","    @method _setData","    @protected","    @since 3.5.0","    **/","    _setData: function (val) {","        if (val === null) {","            val = [];","        }","","        if (isArray(val)) {","            this._initDataProperty();","","            // silent to prevent subscribers to both reset and dataChange","            // from reacting to the change twice.","            // TODO: would it be better to return INVALID to silence the","            // dataChange event, or even allow both events?","            this.data.reset(val, { silent: true });","","            // Return the instance ModelList to avoid storing unprocessed","            // data in the state and their vivified Model representations in","            // the instance's data property.  Decreases memory consumption.","            val = this.data;","        } else if (!val || !val.each || !val.toJSON) {","            // ModelList/ArrayList duck typing","            val = INVALID;","        }","","        return val;","    },","","    /**","    Relays the value assigned to the deprecated `recordset` attribute to the","    `data` attribute.  If a Recordset instance is passed, the raw object data","    will be culled from it.","","    @method _setRecordset","    @param {Object[]|Recordset} val The recordset value to relay","    @deprecated This will be removed with the deprecated `recordset` attribute","                in a later version.","    @protected","    @since 3.5.0","    **/","    _setRecordset: function (val) {","        var data;","","        if (val && Y.Recordset && val instanceof Y.Recordset) {","            data = [];","            val.each(function (record) {","                data.push(record.get('data'));","            });","            val = data;","        }","","        this.set('data', val);","","        return val;","    },","","    /**","    Accepts a Base subclass (preferably a Model subclass). Alternately, it will","    generate a custom Model subclass from an array of attribute names or an","    object defining attributes and their respective configurations (it is","    assigned as the `ATTRS` of the new class).","","    Any other value is invalid.","","    @method _setRecordType","    @param {Function|String[]|Object} val The Model subclass, array of","            attribute names, or the `ATTRS` definition for a custom model","            subclass","    @return {Function} A Base/Model subclass","    @protected","    @since 3.5.0","    **/","    _setRecordType: function (val) {","        var modelClass;","","        // Duck type based on known/likely consumed APIs","        if (isFunction(val) && val.prototype.toJSON && val.prototype.setAttrs) {","            modelClass = val;","        } else if (isObject(val)) {","            modelClass = this._createRecordClass(val);","        }","","        return modelClass || INVALID;","    }","","});","","","}, '3.7.1', {\"requires\": [\"escape\", \"model-list\", \"node-event-delegate\"]});"];
36 _yuitest_coverage["build/datatable-core/datatable-core.js"].lines = {"1":0,"11":0,"38":0,"40":0,"201":0,"232":0,"234":0,"239":0,"241":0,"244":0,"245":0,"248":0,"250":0,"251":0,"252":0,"254":0,"255":0,"258":0,"261":0,"279":0,"281":0,"282":0,"283":0,"287":0,"288":0,"292":0,"345":0,"358":0,"360":0,"362":0,"365":0,"378":0,"380":0,"382":0,"384":0,"385":0,"386":0,"388":0,"407":0,"409":0,"410":0,"412":0,"413":0,"415":0,"416":0,"419":0,"430":0,"449":0,"469":0,"487":0,"501":0,"505":0,"507":0,"509":0,"510":0,"513":0,"516":0,"527":0,"545":0,"549":0,"550":0,"553":0,"570":0,"572":0,"573":0,"575":0,"576":0,"578":0,"579":0,"584":0,"586":0,"587":0,"595":0,"608":0,"614":0,"620":0,"621":0,"624":0,"625":0,"626":0,"627":0,"630":0,"631":0,"635":0,"637":0,"639":0,"654":0,"656":0,"657":0,"659":0,"660":0,"661":0,"668":0,"669":0,"673":0,"675":0,"676":0,"681":0,"683":0,"705":0,"710":0,"711":0,"714":0,"715":0,"717":0,"718":0,"719":0,"721":0,"722":0,"723":0,"724":0,"726":0,"728":0,"733":0,"736":0,"739":0,"741":0,"742":0,"744":0,"747":0,"750":0,"751":0,"754":0,"755":0,"758":0,"761":0,"764":0,"766":0,"769":0,"772":0,"773":0,"775":0,"781":0,"783":0,"784":0,"788":0,"791":0,"807":0,"809":0,"830":0,"831":0,"834":0,"835":0,"841":0,"846":0,"847":0,"849":0,"852":0,"868":0,"870":0,"871":0,"872":0,"873":0,"875":0,"878":0,"880":0,"900":0,"903":0,"904":0,"905":0,"906":0,"909":0};
37 _yuitest_coverage["build/datatable-core/datatable-core.js"].functions = {"getColumn:231":0,"getRecord:278":0,"_afterColumnsChange:344":0,"_afterDataChange:357":0,"_afterRecordTypeChange:377":0,"_createRecordClass:406":0,"destructor:429":0,"_getColumns:445":0,"_getColumnset:468":0,"_getRecordType:480":0,"_initColumns:500":0,"_initCoreEvents:526":0,"_initData:544":0,"_initDataProperty:569":0,"initializer:607":0,"process:656":0,"_setColumnMap:653":0,"copyObj:710":0,"genId:736":0,"process:750":0,"_setColumns:704":0,"_setColumnset:806":0,"_setData:829":0,"(anonymous 2):872":0,"_setRecordset:867":0,"_setRecordType:899":0,"(anonymous 1):1":0};
38 _yuitest_coverage["build/datatable-core/datatable-core.js"].coveredLines = 162;
39 _yuitest_coverage["build/datatable-core/datatable-core.js"].coveredFunctions = 27;
40 _yuitest_coverline("build/datatable-core/datatable-core.js", 1);
41 YUI.add('datatable-core', function (Y, NAME) {
43 /**
44 The core implementation of the `DataTable` and `DataTable.Base` Widgets.
46 @module datatable
47 @submodule datatable-core
48 @since 3.5.0
49 **/
51 _yuitest_coverfunc("build/datatable-core/datatable-core.js", "(anonymous 1)", 1);
52 _yuitest_coverline("build/datatable-core/datatable-core.js", 11);
53 var INVALID = Y.Attribute.INVALID_VALUE,
55     Lang         = Y.Lang,
56     isFunction   = Lang.isFunction,
57     isObject     = Lang.isObject,
58     isArray      = Lang.isArray,
59     isString     = Lang.isString,
60     isNumber     = Lang.isNumber,
62     toArray = Y.Array,
64     keys = Y.Object.keys,
66     Table;
67     
68 /**
69 _API docs for this extension are included in the DataTable class._
71 Class extension providing the core API and structure for the DataTable Widget.
73 Use this class extension with Widget or another Base-based superclass to create
74 the basic DataTable model API and composing class structure.
76 @class DataTable.Core
77 @for DataTable
78 @since 3.5.0
79 **/
80 _yuitest_coverline("build/datatable-core/datatable-core.js", 38);
81 Table = Y.namespace('DataTable').Core = function () {};
83 _yuitest_coverline("build/datatable-core/datatable-core.js", 40);
84 Table.ATTRS = {
85     /**
86     Columns to include in the rendered table.
87     
88     If omitted, the attributes on the configured `recordType` or the first item
89     in the `data` collection will be used as a source.
91     This attribute takes an array of strings or objects (mixing the two is
92     fine).  Each string or object is considered a column to be rendered.
93     Strings are converted to objects, so `columns: ['first', 'last']` becomes
94     `columns: [{ key: 'first' }, { key: 'last' }]`.
96     DataTable.Core only concerns itself with a few properties of columns.
97     These properties are:
99     * `key` - Used to identify the record field/attribute containing content for
100       this column.  Also used to create a default Model if no `recordType` or
101       `data` are provided during construction.  If `name` is not specified, this
102       is assigned to the `_id` property (with added incrementer if the key is
103       used by multiple columns).
104     * `children` - Traversed to initialize nested column objects
105     * `name` - Used in place of, or in addition to, the `key`.  Useful for
106       columns that aren't bound to a field/attribute in the record data.  This
107       is assigned to the `_id` property.
108     * `id` - For backward compatibility.  Implementers can specify the id of
109       the header cell.  This should be avoided, if possible, to avoid the
110       potential for creating DOM elements with duplicate IDs.
111     * `field` - For backward compatibility.  Implementers should use `name`.
112     * `_id` - Assigned unique-within-this-instance id for a column.  By order
113       of preference, assumes the value of `name`, `key`, `id`, or `_yuid`.
114       This is used by the rendering views as well as feature module
115       as a means to identify a specific column without ambiguity (such as
116       multiple columns using the same `key`.
117     * `_yuid` - Guid stamp assigned to the column object.
118     * `_parent` - Assigned to all child columns, referencing their parent
119       column.
121     @attribute columns
122     @type {Object[]|String[]}
123     @default (from `recordType` ATTRS or first item in the `data`)
124     @since 3.5.0
125     **/
126     columns: {
127         // TODO: change to setter to clone input array/objects
128         validator: isArray,
129         setter: '_setColumns',
130         getter: '_getColumns'
131     },
133     /**
134     Model subclass to use as the `model` for the ModelList stored in the `data`
135     attribute.
137     If not provided, it will try really hard to figure out what to use.  The
138     following attempts will be made to set a default value:
139     
140     1. If the `data` attribute is set with a ModelList instance and its `model`
141        property is set, that will be used.
142     2. If the `data` attribute is set with a ModelList instance, and its
143        `model` property is unset, but it is populated, the `ATTRS` of the
144        `constructor of the first item will be used.
145     3. If the `data` attribute is set with a non-empty array, a Model subclass
146        will be generated using the keys of the first item as its `ATTRS` (see
147        the `_createRecordClass` method).
148     4. If the `columns` attribute is set, a Model subclass will be generated
149        using the columns defined with a `key`. This is least desirable because
150        columns can be duplicated or nested in a way that's not parsable.
151     5. If neither `data` nor `columns` is set or populated, a change event
152        subscriber will listen for the first to be changed and try all over
153        again.
155     @attribute recordType
156     @type {Function}
157     @default (see description)
158     @since 3.5.0
159     **/
160     recordType: {
161         getter: '_getRecordType',
162         setter: '_setRecordType'
163     },
165     /**
166     The collection of data records to display.  This attribute is a pass
167     through to a `data` property, which is a ModelList instance.
169     If this attribute is passed a ModelList or subclass, it will be assigned to
170     the property directly.  If an array of objects is passed, a new ModelList
171     will be created using the configured `recordType` as its `model` property
172     and seeded with the array.
174     Retrieving this attribute will return the ModelList stored in the `data`
175     property.
177     @attribute data
178     @type {ModelList|Object[]}
179     @default `new ModelList()`
180     @since 3.5.0
181     **/
182     data: {
183         valueFn: '_initData',
184         setter : '_setData',
185         lazyAdd: false
186     },
188     /**
189     Content for the `<table summary="ATTRIBUTE VALUE HERE">`.  Values assigned
190     to this attribute will be HTML escaped for security.
192     @attribute summary
193     @type {String}
194     @default '' (empty string)
195     @since 3.5.0
196     **/
197     //summary: {},
199     /**
200     HTML content of an optional `<caption>` element to appear above the table.
201     Leave this config unset or set to a falsy value to remove the caption.
203     @attribute caption
204     @type HTML
205     @default '' (empty string)
206     @since 3.5.0
207     **/
208     //caption: {},
210     /**
211     Deprecated as of 3.5.0. Passes through to the `data` attribute.
213     WARNING: `get('recordset')` will NOT return a Recordset instance as of
214     3.5.0.  This is a break in backward compatibility.
216     @attribute recordset
217     @type {Object[]|Recordset}
218     @deprecated Use the `data` attribute
219     @since 3.5.0
220     **/
221     recordset: {
222         setter: '_setRecordset',
223         getter: '_getRecordset',
224         lazyAdd: false
225     },
227     /**
228     Deprecated as of 3.5.0. Passes through to the `columns` attribute.
230     WARNING: `get('columnset')` will NOT return a Columnset instance as of
231     3.5.0.  This is a break in backward compatibility.
233     @attribute columnset
234     @type {Object[]}
235     @deprecated Use the `columns` attribute
236     @since 3.5.0
237     **/
238     columnset: {
239         setter: '_setColumnset',
240         getter: '_getColumnset',
241         lazyAdd: false
242     }
245 _yuitest_coverline("build/datatable-core/datatable-core.js", 201);
246 Y.mix(Table.prototype, {
247     // -- Instance properties -------------------------------------------------
248     /**
249     The ModelList that manages the table's data.
251     @property data
252     @type {ModelList}
253     @default undefined (initially unset)
254     @since 3.5.0
255     **/
256     //data: null,
258     // -- Public methods ------------------------------------------------------
260     /**
261     Gets the column configuration object for the given key, name, or index.  For
262     nested columns, `name` can be an array of indexes, each identifying the index
263     of that column in the respective parent's "children" array.
265     If you pass a column object, it will be returned.
267     For columns with keys, you can also fetch the column with
268     `instance.get('columns.foo')`.
270     @method getColumn
271     @param {String|Number|Number[]} name Key, "name", index, or index array to
272                 identify the column
273     @return {Object} the column configuration object
274     @since 3.5.0
275     **/
276     getColumn: function (name) {
277         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "getColumn", 231);
278 _yuitest_coverline("build/datatable-core/datatable-core.js", 232);
279 var col, columns, i, len, cols;
281         _yuitest_coverline("build/datatable-core/datatable-core.js", 234);
282 if (isObject(name) && !isArray(name)) {
283             // TODO: support getting a column from a DOM node - this will cross
284             // the line into the View logic, so it should be relayed
286             // Assume an object passed in is already a column def
287             _yuitest_coverline("build/datatable-core/datatable-core.js", 239);
288 col = name;
289         } else {
290             _yuitest_coverline("build/datatable-core/datatable-core.js", 241);
291 col = this.get('columns.' + name);
292         }
294         _yuitest_coverline("build/datatable-core/datatable-core.js", 244);
295 if (col) {
296             _yuitest_coverline("build/datatable-core/datatable-core.js", 245);
297 return col;
298         }
300         _yuitest_coverline("build/datatable-core/datatable-core.js", 248);
301 columns = this.get('columns');
303         _yuitest_coverline("build/datatable-core/datatable-core.js", 250);
304 if (isNumber(name) || isArray(name)) {
305             _yuitest_coverline("build/datatable-core/datatable-core.js", 251);
306 name = toArray(name);
307             _yuitest_coverline("build/datatable-core/datatable-core.js", 252);
308 cols = columns;
310             _yuitest_coverline("build/datatable-core/datatable-core.js", 254);
311 for (i = 0, len = name.length - 1; cols && i < len; ++i) {
312                 _yuitest_coverline("build/datatable-core/datatable-core.js", 255);
313 cols = cols[name[i]] && cols[name[i]].children;
314             }
316             _yuitest_coverline("build/datatable-core/datatable-core.js", 258);
317 return (cols && cols[name[i]]) || null;
318         }
320         _yuitest_coverline("build/datatable-core/datatable-core.js", 261);
321 return null;
322     },
324     /**
325     Returns the Model associated to the record `id`, `clientId`, or index (not
326     row index).  If none of those yield a Model from the `data` ModelList, the
327     arguments will be passed to the `view` instance's `getRecord` method
328     if it has one.
330     If no Model can be found, `null` is returned.
332     @method getRecord
333     @param {Number|String|Node} seed Record `id`, `clientId`, index, Node, or
334         identifier for a row or child element
335     @return {Model}
336     @since 3.5.0
337     **/
338     getRecord: function (seed) {
339         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "getRecord", 278);
340 _yuitest_coverline("build/datatable-core/datatable-core.js", 279);
341 var record = this.data.getById(seed) || this.data.getByClientId(seed);
343         _yuitest_coverline("build/datatable-core/datatable-core.js", 281);
344 if (!record) {
345             _yuitest_coverline("build/datatable-core/datatable-core.js", 282);
346 if (isNumber(seed)) {
347                 _yuitest_coverline("build/datatable-core/datatable-core.js", 283);
348 record = this.data.item(seed);
349             }
350             
351             // TODO: this should be split out to base somehow
352             _yuitest_coverline("build/datatable-core/datatable-core.js", 287);
353 if (!record && this.view && this.view.getRecord) {
354                 _yuitest_coverline("build/datatable-core/datatable-core.js", 288);
355 record = this.view.getRecord.apply(this.view, arguments);
356             }
357         }
359         _yuitest_coverline("build/datatable-core/datatable-core.js", 292);
360 return record || null;
361     },
363     // -- Protected and private properties and methods ------------------------
365     /**
366     This tells `Y.Base` that it should create ad-hoc attributes for config
367     properties passed to DataTable's constructor. This is useful for setting
368     configurations on the DataTable that are intended for the rendering View(s).
370     @property _allowAdHocAttrs
371     @type Boolean
372     @default true
373     @protected
374     @since 3.6.0
375     **/
376     _allowAdHocAttrs: true,
378     /**
379     A map of column key to column configuration objects parsed from the
380     `columns` attribute.
382     @property _columnMap
383     @type {Object}
384     @default undefined (initially unset)
385     @protected
386     @since 3.5.0
387     **/
388     //_columnMap: null,
390     /**
391     The Node instance of the table containing the data rows.  This is set when
392     the table is rendered.  It may also be set by progressive enhancement,
393     though this extension does not provide the logic to parse from source.
395     @property _tableNode
396     @type {Node}
397     @default undefined (initially unset)
398     @protected
399     @since 3.5.0
400     **/
401     //_tableNode: null,
403     /**
404     Updates the `_columnMap` property in response to changes in the `columns`
405     attribute.
407     @method _afterColumnsChange
408     @param {EventFacade} e The `columnsChange` event object
409     @protected
410     @since 3.5.0
411     **/
412     _afterColumnsChange: function (e) {
413         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_afterColumnsChange", 344);
414 _yuitest_coverline("build/datatable-core/datatable-core.js", 345);
415 this._setColumnMap(e.newVal);
416     },
418     /**
419     Updates the `modelList` attributes of the rendered views in response to the
420     `data` attribute being assigned a new ModelList.
422     @method _afterDataChange
423     @param {EventFacade} e the `dataChange` event
424     @protected
425     @since 3.5.0
426     **/
427     _afterDataChange: function (e) {
428         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_afterDataChange", 357);
429 _yuitest_coverline("build/datatable-core/datatable-core.js", 358);
430 var modelList = e.newVal;
432         _yuitest_coverline("build/datatable-core/datatable-core.js", 360);
433 this.data = e.newVal;
435         _yuitest_coverline("build/datatable-core/datatable-core.js", 362);
436 if (!this.get('columns') && modelList.size()) {
437             // TODO: this will cause a re-render twice because the Views are
438             // subscribed to columnsChange
439             _yuitest_coverline("build/datatable-core/datatable-core.js", 365);
440 this._initColumns();
441         }
442     },
444     /**
445     Assigns to the new recordType as the model for the data ModelList
447     @method _afterRecordTypeChange
448     @param {EventFacade} e recordTypeChange event
449     @protected
450     @since 3.6.0
451     **/
452     _afterRecordTypeChange: function (e) {
453         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_afterRecordTypeChange", 377);
454 _yuitest_coverline("build/datatable-core/datatable-core.js", 378);
455 var data = this.data.toJSON();
457         _yuitest_coverline("build/datatable-core/datatable-core.js", 380);
458 this.data.model = e.newVal;
460         _yuitest_coverline("build/datatable-core/datatable-core.js", 382);
461 this.data.reset(data);
463         _yuitest_coverline("build/datatable-core/datatable-core.js", 384);
464 if (!this.get('columns') && data) {
465             _yuitest_coverline("build/datatable-core/datatable-core.js", 385);
466 if (data.length) {
467                 _yuitest_coverline("build/datatable-core/datatable-core.js", 386);
468 this._initColumns();
469             } else {
470                 _yuitest_coverline("build/datatable-core/datatable-core.js", 388);
471 this.set('columns', keys(e.newVal.ATTRS));
472             }
473         }
474     },
476     /**
477     Creates a Model subclass from an array of attribute names or an object of
478     attribute definitions.  This is used to generate a class suitable to
479     represent the data passed to the `data` attribute if no `recordType` is
480     set.
482     @method _createRecordClass
483     @param {String[]|Object} attrs Names assigned to the Model subclass's
484                 `ATTRS` or its entire `ATTRS` definition object
485     @return {Model}
486     @protected
487     @since 3.5.0
488     **/
489     _createRecordClass: function (attrs) {
490         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_createRecordClass", 406);
491 _yuitest_coverline("build/datatable-core/datatable-core.js", 407);
492 var ATTRS, i, len;
494         _yuitest_coverline("build/datatable-core/datatable-core.js", 409);
495 if (isArray(attrs)) {
496             _yuitest_coverline("build/datatable-core/datatable-core.js", 410);
497 ATTRS = {};
499             _yuitest_coverline("build/datatable-core/datatable-core.js", 412);
500 for (i = 0, len = attrs.length; i < len; ++i) {
501                 _yuitest_coverline("build/datatable-core/datatable-core.js", 413);
502 ATTRS[attrs[i]] = {};
503             }
504         } else {_yuitest_coverline("build/datatable-core/datatable-core.js", 415);
505 if (isObject(attrs)) {
506             _yuitest_coverline("build/datatable-core/datatable-core.js", 416);
507 ATTRS = attrs;
508         }}
510         _yuitest_coverline("build/datatable-core/datatable-core.js", 419);
511 return Y.Base.create('record', Y.Model, [], null, { ATTRS: ATTRS });
512     },
514     /**
515     Tears down the instance.
517     @method destructor
518     @protected
519     @since 3.6.0
520     **/
521     destructor: function () {
522         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "destructor", 429);
523 _yuitest_coverline("build/datatable-core/datatable-core.js", 430);
524 new Y.EventHandle(Y.Object.values(this._eventHandles)).detach();
525     },
527     /**
528     The getter for the `columns` attribute.  Returns the array of column
529     configuration objects if `instance.get('columns')` is called, or the
530     specific column object if `instance.get('columns.columnKey')` is called.
532     @method _getColumns
533     @param {Object[]} columns The full array of column objects
534     @param {String} name The attribute name requested
535                          (e.g. 'columns' or 'columns.foo');
536     @protected
537     @since 3.5.0
538     **/
539     _getColumns: function (columns, name) {
540         // Workaround for an attribute oddity (ticket #2529254)
541         // getter is expected to return an object if get('columns.foo') is called.
542         // Note 'columns.' is 8 characters
543         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_getColumns", 445);
544 _yuitest_coverline("build/datatable-core/datatable-core.js", 449);
545 return name.length > 8 ? this._columnMap : columns;
546     },
548     /**
549     Relays the `get()` request for the deprecated `columnset` attribute to the
550     `columns` attribute.
552     THIS BREAKS BACKWARD COMPATIBILITY.  3.4.1 and prior implementations will
553     expect a Columnset instance returned from `get('columnset')`.
555     @method _getColumnset
556     @param {Object} ignored The current value stored in the `columnset` state
557     @param {String} name The attribute name requested
558                          (e.g. 'columnset' or 'columnset.foo');
559     @deprecated This will be removed with the `columnset` attribute in a future
560                 version.
561     @protected
562     @since 3.5.0
563     **/
564     _getColumnset: function (_, name) {
565         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_getColumnset", 468);
566 _yuitest_coverline("build/datatable-core/datatable-core.js", 469);
567 return this.get(name.replace(/^columnset/, 'columns'));
568     },
570     /**
571     Returns the Model class of the instance's `data` attribute ModelList.  If
572     not set, returns the explicitly configured value.
574     @method _getRecordType
575     @param {Model} val The currently configured value
576     @return {Model}
577     **/
578     _getRecordType: function (val) {
579         // Prefer the value stored in the attribute because the attribute
580         // change event defaultFn sets e.newVal = this.get('recordType')
581         // before notifying the after() subs.  But if this getter returns
582         // this.data.model, then after() subs would get e.newVal === previous
583         // model before _afterRecordTypeChange can set
584         // this.data.model = e.newVal
585         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_getRecordType", 480);
586 _yuitest_coverline("build/datatable-core/datatable-core.js", 487);
587 return val || (this.data && this.data.model);
588     },
590     /**
591     Initializes the `_columnMap` property from the configured `columns`
592     attribute.  If `columns` is not set, but there are records in the `data`
593     ModelList, use
594     `ATTRS` of that class.
596     @method _initColumns
597     @protected
598     @since 3.5.0
599     **/
600     _initColumns: function () {
601         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_initColumns", 500);
602 _yuitest_coverline("build/datatable-core/datatable-core.js", 501);
603 var columns = this.get('columns') || [],
604             item;
605         
606         // Default column definition from the configured recordType
607         _yuitest_coverline("build/datatable-core/datatable-core.js", 505);
608 if (!columns.length && this.data.size()) {
609             // TODO: merge superclass attributes up to Model?
610             _yuitest_coverline("build/datatable-core/datatable-core.js", 507);
611 item = this.data.item(0);
613             _yuitest_coverline("build/datatable-core/datatable-core.js", 509);
614 if (item.toJSON) {
615                 _yuitest_coverline("build/datatable-core/datatable-core.js", 510);
616 item = item.toJSON();
617             }
619             _yuitest_coverline("build/datatable-core/datatable-core.js", 513);
620 this.set('columns', keys(item));
621         }
623         _yuitest_coverline("build/datatable-core/datatable-core.js", 516);
624 this._setColumnMap(columns);
625     },
627     /**
628     Sets up the change event subscriptions to maintain internal state.
630     @method _initCoreEvents
631     @protected
632     @since 3.6.0
633     **/
634     _initCoreEvents: function () {
635         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_initCoreEvents", 526);
636 _yuitest_coverline("build/datatable-core/datatable-core.js", 527);
637 this._eventHandles.coreAttrChanges = this.after({
638             columnsChange   : Y.bind('_afterColumnsChange', this),
639             recordTypeChange: Y.bind('_afterRecordTypeChange', this),
640             dataChange      : Y.bind('_afterDataChange', this)
641         });
642     },
644     /**
645     Defaults the `data` attribute to an empty ModelList if not set during
646     construction.  Uses the configured `recordType` for the ModelList's `model`
647     proeprty if set.
649     @method _initData
650     @protected
651     @return {ModelList}
652     @since 3.6.0
653     **/
654     _initData: function () {
655         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_initData", 544);
656 _yuitest_coverline("build/datatable-core/datatable-core.js", 545);
657 var recordType = this.get('recordType'),
658             // TODO: LazyModelList if recordType doesn't have complex ATTRS
659             modelList = new Y.ModelList();
661         _yuitest_coverline("build/datatable-core/datatable-core.js", 549);
662 if (recordType) {
663             _yuitest_coverline("build/datatable-core/datatable-core.js", 550);
664 modelList.model = recordType;
665         }
667         _yuitest_coverline("build/datatable-core/datatable-core.js", 553);
668 return modelList;
669     },
671     /**
672     Initializes the instance's `data` property from the value of the `data`
673     attribute.  If the attribute value is a ModelList, it is assigned directly
674     to `this.data`.  If it is an array, a ModelList is created, its `model`
675     property is set to the configured `recordType` class, and it is seeded with
676     the array data.  This ModelList is then assigned to `this.data`.
678     @method _initDataProperty
679     @param {Array|ModelList|ArrayList} data Collection of data to populate the
680             DataTable
681     @protected
682     @since 3.6.0
683     **/
684     _initDataProperty: function (data) {
685         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_initDataProperty", 569);
686 _yuitest_coverline("build/datatable-core/datatable-core.js", 570);
687 var recordType;
689         _yuitest_coverline("build/datatable-core/datatable-core.js", 572);
690 if (!this.data) {
691             _yuitest_coverline("build/datatable-core/datatable-core.js", 573);
692 recordType = this.get('recordType');
694             _yuitest_coverline("build/datatable-core/datatable-core.js", 575);
695 if (data && data.each && data.toJSON) {
696                 _yuitest_coverline("build/datatable-core/datatable-core.js", 576);
697 this.data = data;
699                 _yuitest_coverline("build/datatable-core/datatable-core.js", 578);
700 if (recordType) {
701                     _yuitest_coverline("build/datatable-core/datatable-core.js", 579);
702 this.data.model = recordType;
703                 }
704             } else {
705                 // TODO: customize the ModelList or read the ModelList class
706                 // from a configuration option?
707                 _yuitest_coverline("build/datatable-core/datatable-core.js", 584);
708 this.data = new Y.ModelList();
709                 
710                 _yuitest_coverline("build/datatable-core/datatable-core.js", 586);
711 if (recordType) {
712                     _yuitest_coverline("build/datatable-core/datatable-core.js", 587);
713 this.data.model = recordType;
714                 }
715             }
717             // TODO: Replace this with an event relay for specific events.
718             // Using bubbling causes subscription conflicts with the models'
719             // aggregated change event and 'change' events from DOM elements
720             // inside the table (via Widget UI event).
721             _yuitest_coverline("build/datatable-core/datatable-core.js", 595);
722 this.data.addTarget(this);
723         }
724     },
726     /**
727     Initializes the columns, `recordType` and data ModelList.
729     @method initializer
730     @param {Object} config Configuration object passed to constructor
731     @protected
732     @since 3.5.0
733     **/
734     initializer: function (config) {
735         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "initializer", 607);
736 _yuitest_coverline("build/datatable-core/datatable-core.js", 608);
737 var data       = config.data,
738             columns    = config.columns,
739             recordType;
741         // Referencing config.data to allow _setData to be more stringent
742         // about its behavior
743         _yuitest_coverline("build/datatable-core/datatable-core.js", 614);
744 this._initDataProperty(data);
746         // Default columns from recordType ATTRS if recordType is supplied at
747         // construction.  If no recordType is supplied, but the data is
748         // supplied as a non-empty array, use the keys of the first item
749         // as the columns.
750         _yuitest_coverline("build/datatable-core/datatable-core.js", 620);
751 if (!columns) {
752             _yuitest_coverline("build/datatable-core/datatable-core.js", 621);
753 recordType = (config.recordType || config.data === this.data) &&
754                             this.get('recordType');
756             _yuitest_coverline("build/datatable-core/datatable-core.js", 624);
757 if (recordType) {
758                 _yuitest_coverline("build/datatable-core/datatable-core.js", 625);
759 columns = keys(recordType.ATTRS);
760             } else {_yuitest_coverline("build/datatable-core/datatable-core.js", 626);
761 if (isArray(data) && data.length) {
762                 _yuitest_coverline("build/datatable-core/datatable-core.js", 627);
763 columns = keys(data[0]);
764             }}
766             _yuitest_coverline("build/datatable-core/datatable-core.js", 630);
767 if (columns) {
768                 _yuitest_coverline("build/datatable-core/datatable-core.js", 631);
769 this.set('columns', columns);
770             }
771         }
773         _yuitest_coverline("build/datatable-core/datatable-core.js", 635);
774 this._initColumns();
776         _yuitest_coverline("build/datatable-core/datatable-core.js", 637);
777 this._eventHandles = {};
779         _yuitest_coverline("build/datatable-core/datatable-core.js", 639);
780 this._initCoreEvents();
781     },
783     /**
784     Iterates the array of column configurations to capture all columns with a
785     `key` property.  An map is built with column keys as the property name and
786     the corresponding column object as the associated value.  This map is then
787     assigned to the instance's `_columnMap` property.
789     @method _setColumnMap
790     @param {Object[]|String[]} columns The array of column config objects
791     @protected
792     @since 3.6.0
793     **/
794     _setColumnMap: function (columns) {
795         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_setColumnMap", 653);
796 _yuitest_coverline("build/datatable-core/datatable-core.js", 654);
797 var map = {};
798         
799         _yuitest_coverline("build/datatable-core/datatable-core.js", 656);
800 function process(cols) {
801             _yuitest_coverfunc("build/datatable-core/datatable-core.js", "process", 656);
802 _yuitest_coverline("build/datatable-core/datatable-core.js", 657);
803 var i, len, col, key;
805             _yuitest_coverline("build/datatable-core/datatable-core.js", 659);
806 for (i = 0, len = cols.length; i < len; ++i) {
807                 _yuitest_coverline("build/datatable-core/datatable-core.js", 660);
808 col = cols[i];
809                 _yuitest_coverline("build/datatable-core/datatable-core.js", 661);
810 key = col.key;
812                 // First in wins for multiple columns with the same key
813                 // because the first call to genId (in _setColumns) will
814                 // return the same key, which will then be overwritten by the
815                 // subsequent same-keyed column.  So table.getColumn(key) would
816                 // return the last same-keyed column.
817                 _yuitest_coverline("build/datatable-core/datatable-core.js", 668);
818 if (key && !map[key]) {
819                     _yuitest_coverline("build/datatable-core/datatable-core.js", 669);
820 map[key] = col;
821                 }
823                 //TODO: named columns can conflict with keyed columns
824                 _yuitest_coverline("build/datatable-core/datatable-core.js", 673);
825 map[col._id] = col;
827                 _yuitest_coverline("build/datatable-core/datatable-core.js", 675);
828 if (col.children) {
829                     _yuitest_coverline("build/datatable-core/datatable-core.js", 676);
830 process(col.children);
831                 }
832             }
833         }
835         _yuitest_coverline("build/datatable-core/datatable-core.js", 681);
836 process(columns);
838         _yuitest_coverline("build/datatable-core/datatable-core.js", 683);
839 this._columnMap = map;
840     },
842     /**
843     Translates string columns into objects with that string as the value of its
844     `key` property.
846     All columns are assigned a `_yuid` stamp and `_id` property corresponding
847     to the column's configured `name` or `key` property with any spaces
848     replaced with dashes.  If the same `name` or `key` appears in multiple
849     columns, subsequent appearances will have their `_id` appended with an
850     incrementing number (e.g. if column "foo" is included in the `columns`
851     attribute twice, the first will get `_id` of "foo", and the second an `_id`
852     of "foo1").  Columns that are children of other columns will have the
853     `_parent` property added, assigned the column object to which they belong.
855     @method _setColumns
856     @param {null|Object[]|String[]} val Array of config objects or strings
857     @return {null|Object[]}
858     @protected
859     **/
860     _setColumns: function (val) {
861         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_setColumns", 704);
862 _yuitest_coverline("build/datatable-core/datatable-core.js", 705);
863 var keys = {},
864             known = [],
865             knownCopies = [],
866             arrayIndex = Y.Array.indexOf;
867         
868         _yuitest_coverline("build/datatable-core/datatable-core.js", 710);
869 function copyObj(o) {
870             _yuitest_coverfunc("build/datatable-core/datatable-core.js", "copyObj", 710);
871 _yuitest_coverline("build/datatable-core/datatable-core.js", 711);
872 var copy = {},
873                 key, val, i;
875             _yuitest_coverline("build/datatable-core/datatable-core.js", 714);
876 known.push(o);
877             _yuitest_coverline("build/datatable-core/datatable-core.js", 715);
878 knownCopies.push(copy);
880             _yuitest_coverline("build/datatable-core/datatable-core.js", 717);
881 for (key in o) {
882                 _yuitest_coverline("build/datatable-core/datatable-core.js", 718);
883 if (o.hasOwnProperty(key)) {
884                     _yuitest_coverline("build/datatable-core/datatable-core.js", 719);
885 val = o[key];
887                     _yuitest_coverline("build/datatable-core/datatable-core.js", 721);
888 if (isArray(val)) {
889                         _yuitest_coverline("build/datatable-core/datatable-core.js", 722);
890 copy[key] = val.slice();
891                     } else {_yuitest_coverline("build/datatable-core/datatable-core.js", 723);
892 if (isObject(val, true)) {
893                         _yuitest_coverline("build/datatable-core/datatable-core.js", 724);
894 i = arrayIndex(val, known);
896                         _yuitest_coverline("build/datatable-core/datatable-core.js", 726);
897 copy[key] = i === -1 ? copyObj(val) : knownCopies[i];
898                     } else {
899                         _yuitest_coverline("build/datatable-core/datatable-core.js", 728);
900 copy[key] = o[key];
901                     }}
902                 }
903             }
905             _yuitest_coverline("build/datatable-core/datatable-core.js", 733);
906 return copy;
907         }
909         _yuitest_coverline("build/datatable-core/datatable-core.js", 736);
910 function genId(name) {
911             // Sanitize the name for use in generated CSS classes.
912             // TODO: is there more to do for other uses of _id?
913             _yuitest_coverfunc("build/datatable-core/datatable-core.js", "genId", 736);
914 _yuitest_coverline("build/datatable-core/datatable-core.js", 739);
915 name = name.replace(/\s+/, '-');
917             _yuitest_coverline("build/datatable-core/datatable-core.js", 741);
918 if (keys[name]) {
919                 _yuitest_coverline("build/datatable-core/datatable-core.js", 742);
920 name += (keys[name]++);
921             } else {
922                 _yuitest_coverline("build/datatable-core/datatable-core.js", 744);
923 keys[name] = 1;
924             }
926             _yuitest_coverline("build/datatable-core/datatable-core.js", 747);
927 return name;
928         }
930         _yuitest_coverline("build/datatable-core/datatable-core.js", 750);
931 function process(cols, parent) {
932             _yuitest_coverfunc("build/datatable-core/datatable-core.js", "process", 750);
933 _yuitest_coverline("build/datatable-core/datatable-core.js", 751);
934 var columns = [],
935                 i, len, col, yuid;
937             _yuitest_coverline("build/datatable-core/datatable-core.js", 754);
938 for (i = 0, len = cols.length; i < len; ++i) {
939                 _yuitest_coverline("build/datatable-core/datatable-core.js", 755);
940 columns[i] = // chained assignment
941                 col = isString(cols[i]) ? { key: cols[i] } : copyObj(cols[i]);
943                 _yuitest_coverline("build/datatable-core/datatable-core.js", 758);
944 yuid = Y.stamp(col);
946                 // For backward compatibility
947                 _yuitest_coverline("build/datatable-core/datatable-core.js", 761);
948 if (!col.id) {
949                     // Implementers can shoot themselves in the foot by setting
950                     // this config property to a non-unique value
951                     _yuitest_coverline("build/datatable-core/datatable-core.js", 764);
952 col.id = yuid;
953                 }
954                 _yuitest_coverline("build/datatable-core/datatable-core.js", 766);
955 if (col.field) {
956                     // Field is now known as "name" to avoid confusion with data
957                     // fields or schema.resultFields
958                     _yuitest_coverline("build/datatable-core/datatable-core.js", 769);
959 col.name = col.field;
960                 }
962                 _yuitest_coverline("build/datatable-core/datatable-core.js", 772);
963 if (parent) {
964                     _yuitest_coverline("build/datatable-core/datatable-core.js", 773);
965 col._parent = parent;
966                 } else {
967                     _yuitest_coverline("build/datatable-core/datatable-core.js", 775);
968 delete col._parent;
969                 }
971                 // Unique id based on the column's configured name or key,
972                 // falling back to the yuid.  Duplicates will have a counter
973                 // added to the end.
974                 _yuitest_coverline("build/datatable-core/datatable-core.js", 781);
975 col._id = genId(col.name || col.key || col.id);
977                 _yuitest_coverline("build/datatable-core/datatable-core.js", 783);
978 if (isArray(col.children)) {
979                     _yuitest_coverline("build/datatable-core/datatable-core.js", 784);
980 col.children = process(col.children, col);
981                 }
982             }
984             _yuitest_coverline("build/datatable-core/datatable-core.js", 788);
985 return columns;
986         }
988         _yuitest_coverline("build/datatable-core/datatable-core.js", 791);
989 return val && process(val);
990     },
992     /**
993     Relays attribute assignments of the deprecated `columnset` attribute to the
994     `columns` attribute.  If a Columnset is object is passed, its basic object
995     structure is mined.
997     @method _setColumnset
998     @param {Array|Columnset} val The columnset value to relay
999     @deprecated This will be removed with the deprecated `columnset` attribute
1000                 in a later version.
1001     @protected
1002     @since 3.5.0
1003     **/
1004     _setColumnset: function (val) {
1005         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_setColumnset", 806);
1006 _yuitest_coverline("build/datatable-core/datatable-core.js", 807);
1007 this.set('columns', val);
1009         _yuitest_coverline("build/datatable-core/datatable-core.js", 809);
1010 return isArray(val) ? val : INVALID;
1011     },
1013     /**
1014     Accepts an object with `each` and `getAttrs` (preferably a ModelList or
1015     subclass) or an array of data objects.  If an array is passes, it will
1016     create a ModelList to wrap the data.  In doing so, it will set the created
1017     ModelList's `model` property to the class in the `recordType` attribute,
1018     which will be defaulted if not yet set.
1020     If the `data` property is already set with a ModelList, passing an array as
1021     the value will call the ModelList's `reset()` method with that array rather
1022     than replacing the stored ModelList wholesale.
1024     Any non-ModelList-ish and non-array value is invalid.
1026     @method _setData
1027     @protected
1028     @since 3.5.0
1029     **/
1030     _setData: function (val) {
1031         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_setData", 829);
1032 _yuitest_coverline("build/datatable-core/datatable-core.js", 830);
1033 if (val === null) {
1034             _yuitest_coverline("build/datatable-core/datatable-core.js", 831);
1035 val = [];
1036         }
1038         _yuitest_coverline("build/datatable-core/datatable-core.js", 834);
1039 if (isArray(val)) {
1040             _yuitest_coverline("build/datatable-core/datatable-core.js", 835);
1041 this._initDataProperty();
1043             // silent to prevent subscribers to both reset and dataChange
1044             // from reacting to the change twice.
1045             // TODO: would it be better to return INVALID to silence the
1046             // dataChange event, or even allow both events?
1047             _yuitest_coverline("build/datatable-core/datatable-core.js", 841);
1048 this.data.reset(val, { silent: true });
1050             // Return the instance ModelList to avoid storing unprocessed
1051             // data in the state and their vivified Model representations in
1052             // the instance's data property.  Decreases memory consumption.
1053             _yuitest_coverline("build/datatable-core/datatable-core.js", 846);
1054 val = this.data;
1055         } else {_yuitest_coverline("build/datatable-core/datatable-core.js", 847);
1056 if (!val || !val.each || !val.toJSON) {
1057             // ModelList/ArrayList duck typing
1058             _yuitest_coverline("build/datatable-core/datatable-core.js", 849);
1059 val = INVALID;
1060         }}
1062         _yuitest_coverline("build/datatable-core/datatable-core.js", 852);
1063 return val;
1064     },
1066     /**
1067     Relays the value assigned to the deprecated `recordset` attribute to the
1068     `data` attribute.  If a Recordset instance is passed, the raw object data
1069     will be culled from it.
1071     @method _setRecordset
1072     @param {Object[]|Recordset} val The recordset value to relay
1073     @deprecated This will be removed with the deprecated `recordset` attribute
1074                 in a later version.
1075     @protected
1076     @since 3.5.0
1077     **/
1078     _setRecordset: function (val) {
1079         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_setRecordset", 867);
1080 _yuitest_coverline("build/datatable-core/datatable-core.js", 868);
1081 var data;
1083         _yuitest_coverline("build/datatable-core/datatable-core.js", 870);
1084 if (val && Y.Recordset && val instanceof Y.Recordset) {
1085             _yuitest_coverline("build/datatable-core/datatable-core.js", 871);
1086 data = [];
1087             _yuitest_coverline("build/datatable-core/datatable-core.js", 872);
1088 val.each(function (record) {
1089                 _yuitest_coverfunc("build/datatable-core/datatable-core.js", "(anonymous 2)", 872);
1090 _yuitest_coverline("build/datatable-core/datatable-core.js", 873);
1091 data.push(record.get('data'));
1092             });
1093             _yuitest_coverline("build/datatable-core/datatable-core.js", 875);
1094 val = data;
1095         }
1097         _yuitest_coverline("build/datatable-core/datatable-core.js", 878);
1098 this.set('data', val);
1100         _yuitest_coverline("build/datatable-core/datatable-core.js", 880);
1101 return val;
1102     },
1104     /**
1105     Accepts a Base subclass (preferably a Model subclass). Alternately, it will
1106     generate a custom Model subclass from an array of attribute names or an
1107     object defining attributes and their respective configurations (it is
1108     assigned as the `ATTRS` of the new class).
1110     Any other value is invalid.
1112     @method _setRecordType
1113     @param {Function|String[]|Object} val The Model subclass, array of
1114             attribute names, or the `ATTRS` definition for a custom model
1115             subclass
1116     @return {Function} A Base/Model subclass
1117     @protected
1118     @since 3.5.0
1119     **/
1120     _setRecordType: function (val) {
1121         _yuitest_coverfunc("build/datatable-core/datatable-core.js", "_setRecordType", 899);
1122 _yuitest_coverline("build/datatable-core/datatable-core.js", 900);
1123 var modelClass;
1125         // Duck type based on known/likely consumed APIs
1126         _yuitest_coverline("build/datatable-core/datatable-core.js", 903);
1127 if (isFunction(val) && val.prototype.toJSON && val.prototype.setAttrs) {
1128             _yuitest_coverline("build/datatable-core/datatable-core.js", 904);
1129 modelClass = val;
1130         } else {_yuitest_coverline("build/datatable-core/datatable-core.js", 905);
1131 if (isObject(val)) {
1132             _yuitest_coverline("build/datatable-core/datatable-core.js", 906);
1133 modelClass = this._createRecordClass(val);
1134         }}
1136         _yuitest_coverline("build/datatable-core/datatable-core.js", 909);
1137 return modelClass || INVALID;
1138     }
1143 }, '3.7.1', {"requires": ["escape", "model-list", "node-event-delegate"]});