recordset.js revision 52104662d2bf71db0aa6dba39f7e6b3d1982f60b
}
/**
* TODO: make recordsetChangedEvent fire through bubbling of other events
* TODO: figure out what object to send through recordsetChangedEvent when recordset is emptied
* TODO: finish updateRecord to make it work with indices, specific records, arrays
* TODO: update getRecord to return array of records
* TODO: Implement methods: hasRecord(), reverseRecords(), sortRecords(), toString(), getLength()
*/
/**
* Class name.
*
* @property NAME
* @type String
* @static
* @final
* @value "recordset"
*/
/////////////////////////////////////////////////////////////////////////////
//
// Recordset Attributes
//
/////////////////////////////////////////////////////////////////////////////
records: {
value: null,
setter: "_setRecords"
},
length: {
value: 0,
readOnly:true
}
};
/* Recordset extends Base */
_setRecords: function(allData) {
var records = [];
function initRecord(oneData){
}
return records;
},
initializer: function() {
},
destructor: function() {
},
/**
* Utility method called upon by addRecord() - it is used to create a new record(s) in the recordset
*
* @method _addRecord
* @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;
},
//---------------------------------------------
// Event Firing
//---------------------------------------------
/**
* 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
* @param i {Number} (optional) Index at which the modifications to the recordset were made
* @private
*/
_recordsetChanged: function(i) {
Y.log('recordsetChangedEvent fired');
this.fire('recordsetChangedEvent', i);
},
/**
* 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 {Y.Record || Array of Y.Record} The record that was added, or an array of records added
* @param i {Number} (optional) 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 deleted from the recordset. Multiple simultaneous changes still fires this event once.
*
* @method _recordDeleted
* @param oRecord {Y.Record || Array of Y.Record} The record that was deleted or an array of records deleted
* @param i {Number} (optional) Index at which the modifications to the recordset were made
* @private
*/
_recordDeleted: function(oRecord, i) {
Y.log('recordsetDeleted 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');
},
Y.log('recordsetUpdated Event Fired');
},
//---------------------------------------------
// 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
*/
},
var i=0, returnedRecords = [];
//Range cannot take on negative values
return returnedRecords;
},
/**
* Returns a string of values for a specified key in the recordset
*
* @method getRecord
* @param index {Number} (optional) Index at which the required record resides
* @return {Y.Record} An Y.Record instance
* @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 addRecord
* @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 = [];
delete oRecord;
idx++;
}
}
//If it is an object literal of data
}
//it is an instance of Y.Record - checking explicitly here so nothing weird gets through
}
this._recordsetChanged(index);
//return an object literal, containing array of new Y.Record instances
},
/**
* Deletes one or more Records to the RecordSet at the given index. If index is null,
* then deletes a single Record from the end of the RecordSet.
*
* @method deleteRecord
* @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 i=0, delRecords=[];
//Default is remove only the last record
for ( ; i < range; i++) {
//Deep clone the records that are going to be deleted, and populate the delRecords array with them
}
//Remove the cloned records
//If there is only 1 Record object in the array, return the object. Else, return entire array
}
else {
}
this._recordsetChanged(index);
return null;
},
/**
* Deletes one or more Records to the RecordSet at the given index. If index is null,
* then deletes a single Record from the end of the RecordSet.
*
* @method deleteRecord
* @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
*/
empty: function() {
this._recordsetEmptied();
//TODO: What index should be sent to recordSetUpdatedEvent when the recordset is emptied?
this._recordsetChanged(0);
},
return null;
}
});