recordset-base.js revision 8f31ee83a62db697e7f623307f2d3412d374a9ef
initializer: function() {
//set up event listener to fire events when recordset is modified in anyway
this._recordsetChanged();
},
destructor: function() {
},
/**
* Helper method called upon by add() - it is used to create a new record(s) in the recordset
*
* @method _add
* @param aRecord {Y.Record} A Y.Record instance
* @param index {Number} (optional) Index at which to add the record(s)
* @return {Y.Record} A Record instance.
* @private
*/
return aRecord;
},
/**
* Helper method called upon by update() - it updates the recordset when an array is passed in
*
* @method _updateGivenArray
* @param arr {Array} An array of object literals or Y.Record instances
* @param index {Number} The index at which to update the records.
* @param overwriteFlag {boolean} (optional) A boolean to represent whether or not you wish to over-write the existing records with records from your recordset. Default is false. The first record is always overwritten.
* @private
*/
var i = 0,
overwrittenRecords = [],
newRecords = [];
//store everything being added into newRecords
//Arrays at the first index will always overwrite the one they are updating.
if (i===0) {
//splice returns an array with 1 object, so just get the object - otherwise this will become a nested array
//console.log(overwrittenRecords[i]);
}
else {
overwrittenRecords[i] = this._updateGivenObject(newRecords[i], index+i, overwriteFlag).overwritten[0];
if (overwrittenRecords[i] === undefined) {
}
}
}
},
/**
* Helper method called upon by update() and _updateGivenArray() - it updates the recordset when an array is passed in
*
* @method _updateGivenObject
* @param obj {Object || Y.Record} Any objet literal or Y.Record instance
* @param index {Number} The index at which to update the records.
* @param overwriteFlag {boolean} (optional) A boolean to represent whether or not you wish to over-write the existing records with records from your recordset. Default is false. The first record is always overwritten.
* @return {Y.Record || null} The overwritten Record instance, if it exists.
* @private
*/
var oRecs = [],
overwrittenRecords = [];
//If overwrite is set to true, splice and remove the record at current entry, otherwise just add it
if (overwriteFlag) {
}
else {
}
//Always returning the object in an array so it can be iterated through
},
/**
* Helper method - it takes an object bag and converts it to a Y.Record
*
* @method _changeToRecord
* @param obj {Object || Y.Record} Any objet literal or Y.Record instance
* @return {Y.Record} A Record instance.
* @private
*/
_changeToRecord: function(obj) {
var oRec;
}
else {
}
return oRec;
},
//---------------------------------------------
// Events
//---------------------------------------------
/**
* Event that is fired whenever the recordset is changed. Note that multiple simultaneous changes still fires this event once.
* (ie: Adding multiple records via an array will only fire this event once at the completion of all the additions)
*
* @method _recordSetUpdated
* @private
*/
_recordsetChanged: function() {
this.on(['recordsetUpdatedEvent', 'recordsetAddedEvent', 'recordsetRemovedEvent', 'recordsetEmptiedEvent'], function() {
Y.log('recordsetChangedEvent fire');
this.fire('recordsetChangedEvent', {});
});
},
/**
* Event that is fired whenever the a record is added to the recordset. Multiple simultaneous changes still fires this event once.
*
* @method _recordAdded
* @param oRecord {Array} The record that was added, or an array of records added
* @param i {Number} Index at which the modifications to the recordset were made
* @private
*/
_recordAdded: function(oRecord, i) {
Y.log('recordsetAdded Event Fired');
},
/**
* Event that is fired whenever the a record is removed from the recordset. Multiple simultaneous changes still fires this event once.
*
* @method _recordDeleted
* @param oRecord {Array} An array of Y.Records that were deleted
* @param idx {Number} Index at which the modifications to the recordset were made
* @private
*/
Y.log('recordsetRemoved Event Fired');
},
/**
* Event that is fired when the record set is emptied
*
* @method _recordsetEmptied
* @private
*/
_recordsetEmptied: function() {
//TODO: What configuration object should be sent here?
this.fire('recordsetEmptiedEvent', {});
Y.log('recordsetEmptied Event Fired');
},
var e = {
data:
{
},
};
this.fire('recordsetUpdatedEvent', e);
},
//---------------------------------------------
// Public Methods
//---------------------------------------------
/**
* Returns the record at a particular index
*
* @method getRecord
* @param index {Number} Index at which the required record resides
* @return {Y.Record} An Y.Record instance
* @public
*/
},
/**
* Returns a range of records beginning at particular index
*
* @method getRecord
* @param index {Number} Index at which the required record resides
* @param range {Number} (Optional) Number of records to retrieve. The default is 1
* @return {Array} An array of Y.Record instances
* @public
*/
var i=0, returnedRecords = [];
//Range cannot take on negative values
for(; i<range; i++) {
}
return returnedRecords;
},
getLength: function() {
return this.size();
},
/**
* Returns an array of values for a specified key in the recordset
*
* @method getRecord
* @param index {Number} (optional) Index at which the required record resides
* @return {Array} An array of values for the given key
* @public
*/
getValuesByKey: function(key) {
for( ; i < len; i++) {
}
return retVals;
},
/**
* Adds one or more Records to the RecordSet at the given index. If index is null,
* then adds the Records to the end of the RecordSet.
*
* @method add
* @param oData {Y.Record, Object Literal, Array} A Y.Record instance, An object literal of data or an array of object literals
* @param index {Number} (optional) Index at which to add the record(s)
* @return {object} An object literal with two properties: "data" which contains array of Y.Record(s) and "index" which contains the index where the Y.Record(s) were added
* @public
*/
//Passing in array of object literals for oData
newRecords = [];
idx++;
}
}
//If it is an object literal of data
}
//it is an instance of Y.Record - checking explicitly here so nothing weird gets through
}
//return an object literal, containing array of new Y.Record instances
},
/**
* Removes one or more Records to the RecordSet at the given index. If index is null,
* then removes a single Record from the end of the RecordSet.
*
* @method remove
* @param index {Number} (optional) Index at which to remove the record(s) from
* @param range {Number} (optional) Number of records to remove (including the one at the index)
* @return {object} An object literal with two properties: "data" which contains the removed set {Y.Record or Y.Recordset} and "index" which contains the index where the Y.Record(s) were removed from
* @public
*/
var remRecords=[];
//Default is to only remove the last record - the length is always 1 greater than the last index
//Remove records and store them in remRecords
//Fire event
},
/**
* Empties the recordset
*
* @method empty
* @public
*/
empty: function() {
this._items = [];
this._recordsetEmptied();
return null;
},
/**
* Updates one or more records in the recordset with new records. New records can overwrite existing records or be appended at an index.
*
* @method update
* @param oData {Object || Array || Y.Record} This represents the data you want to update the record with. Can be an object literal, an array of object literals, a Y.Record instance or an array of Y.Record instances.
* @param index {Number} The index at which to update the records.
* @param overwriteFlag {boolean} (optional) Represents whether or not you wish to over-write the existing records with records from your recordset. Default is false. The first record is always overwritten.
* @public
*/
var data;
}
//If its just an object, it will overwrite the existing one, so passing in true
}
//fire event
return null;
}
},
{
ATTRS: {
records: {
getter: function () {
// give them a copy, not the internal object
return Y.Array(this._items);
},
var records = [];
function initRecord(oneData) {
}
else {
}
}
// ...unless we don't care about live object references
},
//for performance reasons, getters and setters aren't active until they are accessed. Set this to false, since
//they are needed to be active in order for the constructor to create the necessary records
lazyAdd: false
}
}
});