Hopkins-Plugin-HMI
view release on metacpan or search on metacpan
share/root/static/yui/build/datatable/datatable-debug.js view on Meta::CPAN
/*
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.7.0
*/
/**
* Mechanism to execute a series of callbacks in a non-blocking queue. Each callback is executed via setTimout unless configured with a negative timeout, in which case it is run in blocking mode in the same execution thread as the previous callback....
* <ul>
* <li><code>method</code> - {Function} REQUIRED the callback function.</li>
* <li><code>scope</code> - {Object} the scope from which to execute the callback. Default is the global window scope.</li>
* <li><code>argument</code> - {Array} parameters to be passed to method as individual arguments.</li>
* <li><code>timeout</code> - {number} millisecond delay to wait after previous callback completion before executing this callback. Negative values cause immediate blocking execution. Default 0.</li>
* <li><code>until</code> - {Function} boolean function executed before each iteration. Return true to indicate completion and proceed to the next callback.</li>
* <li><code>iterations</code> - {Number} number of times to execute the callback before proceeding to the next callback in the chain. Incompatible with <code>until</code>.</li>
* </ul>
*
* @namespace YAHOO.util
* @class Chain
* @constructor
* @param callback* {Function|Object} Any number of callbacks to initialize the queue
*/
YAHOO.util.Chain = function () {
/**
* The callback queue
* @property q
* @type {Array}
* @private
*/
this.q = [].slice.call(arguments);
/**
* Event fired when the callback queue is emptied via execution (not via
* a call to chain.stop().
* @event end
*/
this.createEvent('end');
};
YAHOO.util.Chain.prototype = {
/**
* Timeout id used to pause or stop execution and indicate the execution state of the Chain. 0 indicates paused or stopped, -1 indicates blocking execution, and any positive number indicates non-blocking execution.
* @property id
* @type {number}
* @private
*/
id : 0,
/**
* Begin executing the chain, or resume execution from the last paused position.
* @method run
* @return {Chain} the Chain instance
*/
run : function () {
// Grab the first callback in the queue
var c = this.q[0],
fn;
// If there is no callback in the queue or the Chain is currently
// in an execution mode, return
if (!c) {
this.fireEvent('end');
return this;
} else if (this.id) {
return this;
}
fn = c.method || c;
if (typeof fn === 'function') {
var o = c.scope || {},
args = c.argument || [],
ms = c.timeout || 0,
me = this;
if (!(args instanceof Array)) {
args = [args];
}
// Execute immediately if the callback timeout is negative.
if (ms < 0) {
this.id = ms;
if (c.until) {
for (;!c.until();) {
// Execute the callback from scope, with argument
fn.apply(o,args);
}
} else if (c.iterations) {
for (;c.iterations-- > 0;) {
fn.apply(o,args);
}
} else {
fn.apply(o,args);
}
this.q.shift();
this.id = 0;
return this.run();
} else {
// If the until condition is set, check if we're done
if (c.until) {
if (c.until()) {
// Shift this callback from the queue and execute the next
// callback
this.q.shift();
return this.run();
}
// Otherwise if either iterations is not set or we're
// executing the last iteration, shift callback from the queue
} else if (!c.iterations || !--c.iterations) {
this.q.shift();
}
// Otherwise set to execute after the configured timeout
this.id = setTimeout(function () {
// Execute the callback from scope, with argument
fn.apply(o,args);
// Check if the Chain was not paused from inside the callback
if (me.id) {
// Indicate ready to run state
me.id = 0;
// Start the fun all over again
me.run();
}
},ms);
}
}
return this;
},
/**
* Add a callback to the end of the queue
* @method add
* @param c {Function|Object} the callback function ref or object literal
* @return {Chain} the Chain instance
*/
add : function (c) {
this.q.push(c);
return this;
},
/**
* Pause the execution of the Chain after the current execution of the
* current callback completes. If called interstitially, clears the
* timeout for the pending callback. Paused Chains can be restarted with
* chain.run()
* @method pause
* @return {Chain} the Chain instance
*/
pause: function () {
clearTimeout(this.id);
this.id = 0;
return this;
},
/**
* Stop and clear the Chain's queue after the current execution of the
* current callback completes.
* @method stop
* @return {Chain} the Chain instance
*/
stop : function () {
this.pause();
this.q = [];
return this;
}
};
YAHOO.lang.augmentProto(YAHOO.util.Chain,YAHOO.util.EventProvider);
share/root/static/yui/build/datatable/datatable-debug.js view on Meta::CPAN
*
* @method render
*/
render : function() {
//YAHOO.example.Performance.trialStart = new Date();
this._oChainRender.stop();
YAHOO.log("DataTable rendering...", "info", this.toString());
var i, j, k, len, allRecords;
var oPaginator = this.get('paginator');
// Paginator is enabled, show a subset of Records and update Paginator UI
if(oPaginator) {
allRecords = this._oRecordSet.getRecords(
oPaginator.getStartIndex(),
oPaginator.getRowsPerPage());
}
// Not paginated, show all records
else {
allRecords = this._oRecordSet.getRecords();
}
// From the top, update in-place existing rows, so as to reuse DOM elements
var elTbody = this._elTbody,
loopN = this.get("renderLoopSize"),
nRecordsLength = allRecords.length;
// Table has rows
if(nRecordsLength > 0) {
elTbody.style.display = "none";
while(elTbody.lastChild) {
elTbody.removeChild(elTbody.lastChild);
}
elTbody.style.display = "";
// Set up the loop Chain to render rows
this._oChainRender.add({
method: function(oArg) {
if((this instanceof DT) && this._sId) {
var i = oArg.nCurrentRecord,
endRecordIndex = ((oArg.nCurrentRecord+oArg.nLoopLength) > nRecordsLength) ?
nRecordsLength : (oArg.nCurrentRecord+oArg.nLoopLength),
elRow, nextSibling;
elTbody.style.display = "none";
for(; i<endRecordIndex; i++) {
elRow = Dom.get(allRecords[i].getId());
elRow = elRow || this._addTrEl(allRecords[i]);
nextSibling = elTbody.childNodes[i] || null;
elTbody.insertBefore(elRow, nextSibling);
}
elTbody.style.display = "";
// Set up for the next loop
oArg.nCurrentRecord = i;
}
},
scope: this,
iterations: (loopN > 0) ? Math.ceil(nRecordsLength/loopN) : 1,
argument: {
nCurrentRecord: 0,//nRecordsLength-1, // Start at first Record
nLoopLength: (loopN > 0) ? loopN : nRecordsLength
},
timeout: (loopN > 0) ? 0 : -1
});
// Post-render tasks
this._oChainRender.add({
method: function(oArg) {
if((this instanceof DT) && this._sId) {
while(elTbody.rows.length > nRecordsLength) {
elTbody.removeChild(elTbody.lastChild);
}
this._setFirstRow();
this._setLastRow();
this._setRowStripes();
this._setSelections();
}
},
scope: this,
timeout: (loopN > 0) ? 0 : -1
});
}
// Table has no rows
else {
// Set up the loop Chain to delete rows
var nTotal = elTbody.rows.length;
if(nTotal > 0) {
this._oChainRender.add({
method: function(oArg) {
if((this instanceof DT) && this._sId) {
var i = oArg.nCurrent,
loopN = oArg.nLoopLength,
nIterEnd = (i - loopN < 0) ? -1 : i - loopN;
elTbody.style.display = "none";
for(; i>nIterEnd; i--) {
elTbody.deleteRow(-1);
}
elTbody.style.display = "";
// Set up for the next loop
oArg.nCurrent = i;
}
},
scope: this,
iterations: (loopN > 0) ? Math.ceil(nTotal/loopN) : 1,
argument: {
nCurrent: nTotal,
nLoopLength: (loopN > 0) ? loopN : nTotal
},
timeout: (loopN > 0) ? 0 : -1
});
}
}
this._runRenderChain();
},
/**
* Disables DataTable UI.
*
* @method disable
*/
disable : function() {
var elTable = this._elTable;
var elMask = this._elMask;
elMask.style.width = elTable.offsetWidth + "px";
elMask.style.height = elTable.offsetHeight + "px";
elMask.style.display = "";
this.fireEvent("disableEvent");
},
/**
* Undisables DataTable UI.
*
* @method undisable
*/
undisable : function() {
this._elMask.style.display = "none";
this.fireEvent("undisableEvent");
},
/**
* Nulls out the entire DataTable instance and related objects, removes attached
* event listeners, and clears out DOM elements inside the container. After
* calling this method, the instance reference should be expliclitly nulled by
* implementer, as in myDataTable = null. Use with caution!
*
* @method destroy
*/
destroy : function() {
// Store for later
var instanceName = this.toString();
this._oChainRender.stop();
// Destroy static resizer proxy and column proxy
DT._destroyColumnDragTargetEl();
DT._destroyColumnResizerProxyEl();
// Destroy ColumnDD and ColumnResizers
this._destroyColumnHelpers();
// Destroy all CellEditors
var oCellEditor;
for(var i=0, len=this._oColumnSet.flat.length; i<len; i++) {
oCellEditor = this._oColumnSet.flat[i].editor;
share/root/static/yui/build/datatable/datatable-debug.js view on Meta::CPAN
var i, len,
aKeyIndexes = oColumn.getKeyIndex();
// Must be a parent Column
if(aKeyIndexes === null) {
var descKeyIndexes = [];
var allDescendants = this._oColumnSet.getDescendants(oColumn);
for(i=0, len=allDescendants.length; i<len; i++) {
// Is this descendant a key Column?
var thisKey = allDescendants[i].getKeyIndex();
if(thisKey !== null) {
descKeyIndexes[descKeyIndexes.length] = thisKey;
}
}
if(descKeyIndexes.length > 0) {
aKeyIndexes = descKeyIndexes;
}
}
// Must be a key Column
else {
aKeyIndexes = [aKeyIndexes];
}
if(aKeyIndexes !== null) {
// Sort the indexes so we can remove from the right
aKeyIndexes.sort(function(a, b) {return YAHOO.util.Sort.compare(a, b);});
// Destroy previous THEAD
this._destroyTheadEl();
// Create new THEAD
var aOrigColumnDefs = this._oColumnSet.getDefinitions();
oColumn = aOrigColumnDefs.splice(nColTreeIndex,1)[0];
this._initColumnSet(aOrigColumnDefs);
this._initTheadEl();
// Remove COL
for(i=aKeyIndexes.length-1; i>-1; i--) {
this._removeColgroupColEl(aKeyIndexes[i]);
}
// Remove TD
var allRows = this._elTbody.rows;
if(allRows.length > 0) {
var loopN = this.get("renderLoopSize"),
loopEnd = allRows.length;
this._oChainRender.add({
method: function(oArg) {
if((this instanceof DT) && this._sId) {
var i = oArg.nCurrentRow,
len = loopN > 0 ? Math.min(i + loopN,allRows.length) : allRows.length,
aIndexes = oArg.aIndexes,
j;
for(; i < len; ++i) {
for(j = aIndexes.length-1; j>-1; j--) {
allRows[i].removeChild(allRows[i].childNodes[aIndexes[j]]);
}
}
oArg.nCurrentRow = i;
}
},
iterations: (loopN > 0) ? Math.ceil(loopEnd/loopN) : 1,
argument: {nCurrentRow:0, aIndexes:aKeyIndexes},
scope: this,
timeout: (loopN > 0) ? 0 : -1
});
this._runRenderChain();
}
this.fireEvent("columnRemoveEvent",{column:oColumn});
YAHOO.log("Column \"" + oColumn.key + "\" removed", "info", this.toString());
return oColumn;
}
}
}
YAHOO.log("Could not remove Column \"" + oColumn.key + "\". Only non-nested Columns can be removed", "warn", this.toString());
},
/**
* Inserts given Column at the index if given, otherwise at the end. NOTE: You
* can only add non-nested Columns and top-level parent Columns. You cannot add
* a nested Column to an existing parent.
*
* @method insertColumn
* @param oColumn {Object | YAHOO.widget.Column} Object literal Column
* definition or a Column instance.
* @param index {Number} (optional) New tree index.
* @return oColumn {YAHOO.widget.Column} Inserted Column instance.
*/
insertColumn : function(oColumn, index) {
// Validate Column
if(oColumn instanceof YAHOO.widget.Column) {
oColumn = oColumn.getDefinition();
}
else if(oColumn.constructor !== Object) {
YAHOO.log("Could not insert Column \"" + oColumn + "\" due to invalid argument", "warn", this.toString());
return;
}
// Validate index or append new Column to the end of the ColumnSet
var oColumnSet = this._oColumnSet;
if(!lang.isValue(index) || !lang.isNumber(index)) {
index = oColumnSet.tree[0].length;
}
// Destroy previous THEAD
this._destroyTheadEl();
// Create new THEAD
var aNewColumnDefs = this._oColumnSet.getDefinitions();
aNewColumnDefs.splice(index, 0, oColumn);
this._initColumnSet(aNewColumnDefs);
this._initTheadEl();
// Need to refresh the reference
oColumnSet = this._oColumnSet;
var oNewColumn = oColumnSet.tree[0][index];
// Get key index(es) for new Column
var i, len,
descKeyIndexes = [];
var allDescendants = oColumnSet.getDescendants(oNewColumn);
for(i=0, len=allDescendants.length; i<len; i++) {
// Is this descendant a key Column?
var thisKey = allDescendants[i].getKeyIndex();
if(thisKey !== null) {
descKeyIndexes[descKeyIndexes.length] = thisKey;
}
}
if(descKeyIndexes.length > 0) {
// Sort the indexes
var newIndex = descKeyIndexes.sort(function(a, b) {return YAHOO.util.Sort.compare(a, b);})[0];
// Add COL
for(i=descKeyIndexes.length-1; i>-1; i--) {
this._insertColgroupColEl(descKeyIndexes[i]);
}
// Add TD
var allRows = this._elTbody.rows;
if(allRows.length > 0) {
var loopN = this.get("renderLoopSize"),
loopEnd = allRows.length;
// Get templates for each new TD
var aTdTemplates = [],
elTdTemplate;
for(i=0, len=descKeyIndexes.length; i<len; i++) {
var thisKeyIndex = descKeyIndexes[i];
elTdTemplate = this._getTrTemplateEl().childNodes[i].cloneNode(true);
elTdTemplate = this._formatTdEl(this._oColumnSet.keys[thisKeyIndex], elTdTemplate, thisKeyIndex, (thisKeyIndex===this._oColumnSet.keys.length-1));
aTdTemplates[thisKeyIndex] = elTdTemplate;
}
this._oChainRender.add({
method: function(oArg) {
if((this instanceof DT) && this._sId) {
var i = oArg.nCurrentRow, j,
descKeyIndexes = oArg.descKeyIndexes,
len = loopN > 0 ? Math.min(i + loopN,allRows.length) : allRows.length,
nextSibling;
for(; i < len; ++i) {
nextSibling = allRows[i].childNodes[newIndex] || null;
for(j=descKeyIndexes.length-1; j>-1; j--) {
allRows[i].insertBefore(oArg.aTdTemplates[descKeyIndexes[j]].cloneNode(true), nextSibling);
}
}
oArg.nCurrentRow = i;
}
},
iterations: (loopN > 0) ? Math.ceil(loopEnd/loopN) : 1,
argument: {nCurrentRow:0,aTdTemplates:aTdTemplates,descKeyIndexes:descKeyIndexes},
scope: this,
timeout: (loopN > 0) ? 0 : -1
});
this._runRenderChain();
}
this.fireEvent("columnInsertEvent",{column:oColumn,index:index});
YAHOO.log("Column \"" + oColumn.key + "\" inserted into index " + index, "info", this.toString());
return oNewColumn;
}
},
/**
* Removes given Column and inserts into given tree index. NOTE: You
* can only reorder non-nested Columns and top-level parent Columns. You cannot
* reorder a nested Column to an existing parent.
*
* @method reorderColumn
* @param oColumn {YAHOO.widget.Column} Column instance.
* @param index {Number} New tree index.
* @return oColumn {YAHOO.widget.Column} Reordered Column instance.
*/
reorderColumn : function(oColumn, index) {
// Validate Column and new index
if(!(oColumn instanceof YAHOO.widget.Column)) {
oColumn = this.getColumn(oColumn);
}
if(oColumn && YAHOO.lang.isNumber(index)) {
var nOrigTreeIndex = oColumn.getTreeIndex();
if((nOrigTreeIndex !== null) && (nOrigTreeIndex !== index)) {
// Which key index(es)
var i, len,
aOrigKeyIndexes = oColumn.getKeyIndex(),
allDescendants,
descKeyIndexes = [],
thisKey;
// Must be a parent Column...
if(aOrigKeyIndexes === null) {
allDescendants = this._oColumnSet.getDescendants(oColumn);
for(i=0, len=allDescendants.length; i<len; i++) {
// Is this descendant a key Column?
thisKey = allDescendants[i].getKeyIndex();
if(thisKey !== null) {
descKeyIndexes[descKeyIndexes.length] = thisKey;
}
}
if(descKeyIndexes.length > 0) {
aOrigKeyIndexes = descKeyIndexes;
}
}
// ...or else must be a key Column
else {
aOrigKeyIndexes = [aOrigKeyIndexes];
}
if(aOrigKeyIndexes !== null) {
// Sort the indexes
aOrigKeyIndexes.sort(function(a, b) {return YAHOO.util.Sort.compare(a, b);});
share/root/static/yui/build/datatable/datatable-debug.js view on Meta::CPAN
var oNewColumn = this._oColumnSet.tree[0][index];
// What are new key index(es)
var aNewKeyIndexes = oNewColumn.getKeyIndex();
// Must be a parent Column
if(aNewKeyIndexes === null) {
descKeyIndexes = [];
allDescendants = this._oColumnSet.getDescendants(oNewColumn);
for(i=0, len=allDescendants.length; i<len; i++) {
// Is this descendant a key Column?
thisKey = allDescendants[i].getKeyIndex();
if(thisKey !== null) {
descKeyIndexes[descKeyIndexes.length] = thisKey;
}
}
if(descKeyIndexes.length > 0) {
aNewKeyIndexes = descKeyIndexes;
}
}
// Must be a key Column
else {
aNewKeyIndexes = [aNewKeyIndexes];
}
// Sort the new indexes and grab the first one for the new location
var newIndex = aNewKeyIndexes.sort(function(a, b) {return YAHOO.util.Sort.compare(a, b);})[0];
// Reorder COL
this._reorderColgroupColEl(aOrigKeyIndexes, newIndex);
// Reorder TD
var allRows = this._elTbody.rows;
if(allRows.length > 0) {
var loopN = this.get("renderLoopSize"),
loopEnd = allRows.length;
this._oChainRender.add({
method: function(oArg) {
if((this instanceof DT) && this._sId) {
var i = oArg.nCurrentRow, j, tmpTds, nextSibling,
len = loopN > 0 ? Math.min(i + loopN,allRows.length) : allRows.length,
aIndexes = oArg.aIndexes, thisTr;
// For each row
for(; i < len; ++i) {
tmpTds = [];
thisTr = allRows[i];
// Remove each TD
for(j=aIndexes.length-1; j>-1; j--) {
tmpTds.push(thisTr.removeChild(thisTr.childNodes[aIndexes[j]]));
}
// Insert each TD
nextSibling = thisTr.childNodes[newIndex] || null;
for(j=tmpTds.length-1; j>-1; j--) {
thisTr.insertBefore(tmpTds[j], nextSibling);
}
}
oArg.nCurrentRow = i;
}
},
iterations: (loopN > 0) ? Math.ceil(loopEnd/loopN) : 1,
argument: {nCurrentRow:0, aIndexes:aOrigKeyIndexes},
scope: this,
timeout: (loopN > 0) ? 0 : -1
});
this._runRenderChain();
}
this.fireEvent("columnReorderEvent",{column:oNewColumn});
YAHOO.log("Column \"" + oNewColumn.key + "\" reordered", "info", this.toString());
return oNewColumn;
}
}
}
YAHOO.log("Could not reorder Column \"" + oColumn.key + "\". Only non-nested Columns can be reordered", "warn", this.toString());
},
/**
* Selects given Column. NOTE: You cannot select/unselect nested Columns. You can only
* select/unselect non-nested Columns, and bottom-level key Columns.
*
* @method selectColumn
* @param column {HTMLElement | String | Number} DOM reference or ID string to a
* TH/TD element (or child of a TH/TD element), a Column key, or a ColumnSet key index.
*/
selectColumn : function(oColumn) {
oColumn = this.getColumn(oColumn);
if(oColumn && !oColumn.selected) {
// Only bottom-level Columns can get hidden
if(oColumn.getKeyIndex() !== null) {
oColumn.selected = true;
// Update head cell
var elTh = oColumn.getThEl();
Dom.addClass(elTh,DT.CLASS_SELECTED);
// Update body cells
var allRows = this.getTbodyEl().rows;
var oChainRender = this._oChainRender;
oChainRender.add({
method: function(oArg) {
if((this instanceof DT) && this._sId && allRows[oArg.rowIndex] && allRows[oArg.rowIndex].cells[oArg.cellIndex]) {
Dom.addClass(allRows[oArg.rowIndex].cells[oArg.cellIndex],DT.CLASS_SELECTED);
}
oArg.rowIndex++;
},
scope: this,
iterations: allRows.length,
argument: {rowIndex:0,cellIndex:oColumn.getKeyIndex()}
});
this._clearTrTemplateEl();
this._elTbody.style.display = "none";
this._runRenderChain();
this._elTbody.style.display = "";
this.fireEvent("columnSelectEvent",{column:oColumn});
YAHOO.log("Column \"" + oColumn.key + "\" selected", "info", this.toString());
}
else {
YAHOO.log("Could not select Column \"" + oColumn.key + "\". Only non-nested Columns can be selected", "warn", this.toString());
}
}
},
/**
* Unselects given Column. NOTE: You cannot select/unselect nested Columns. You can only
* select/unselect non-nested Columns, and bottom-level key Columns.
*
* @method unselectColumn
* @param column {HTMLElement | String | Number} DOM reference or ID string to a
* TH/TD element (or child of a TH/TD element), a Column key, or a ColumnSet key index.
*/
unselectColumn : function(oColumn) {
oColumn = this.getColumn(oColumn);
if(oColumn && oColumn.selected) {
// Only bottom-level Columns can get hidden
if(oColumn.getKeyIndex() !== null) {
oColumn.selected = false;
// Update head cell
var elTh = oColumn.getThEl();
Dom.removeClass(elTh,DT.CLASS_SELECTED);
// Update body cells
var allRows = this.getTbodyEl().rows;
var oChainRender = this._oChainRender;
oChainRender.add({
method: function(oArg) {
if((this instanceof DT) && this._sId && allRows[oArg.rowIndex] && allRows[oArg.rowIndex].cells[oArg.cellIndex]) {
Dom.removeClass(allRows[oArg.rowIndex].cells[oArg.cellIndex],DT.CLASS_SELECTED);
}
oArg.rowIndex++;
},
scope: this,
iterations:allRows.length,
argument: {rowIndex:0,cellIndex:oColumn.getKeyIndex()}
});
this._clearTrTemplateEl();
this._elTbody.style.display = "none";
this._runRenderChain();
this._elTbody.style.display = "";
this.fireEvent("columnUnselectEvent",{column:oColumn});
YAHOO.log("Column \"" + oColumn.key + "\" unselected", "info", this.toString());
}
else {
YAHOO.log("Could not unselect Column \"" + oColumn.key + "\". Only non-nested Columns can be unselected", "warn", this.toString());
}
}
},
/**
* Returns an array selected Column instances.
*
* @method getSelectedColumns
* @return {YAHOO.widget.Column[]} Array of Column instances.
*/
getSelectedColumns : function(oColumn) {
var selectedColumns = [];
var aKeys = this._oColumnSet.keys;
for(var i=0,len=aKeys.length; i<len; i++) {
if(aKeys[i].selected) {
selectedColumns[selectedColumns.length] = aKeys[i];
}
}
return selectedColumns;
},
/**
* Assigns the class YAHOO.widget.DataTable.CLASS_HIGHLIGHTED to cells of the given Column.
* NOTE: You cannot highlight/unhighlight nested Columns. You can only
* highlight/unhighlight non-nested Columns, and bottom-level key Columns.
*
* @method highlightColumn
* @param column {HTMLElement | String | Number} DOM reference or ID string to a
* TH/TD element (or child of a TH/TD element), a Column key, or a ColumnSet key index.
*/
highlightColumn : function(column) {
var oColumn = this.getColumn(column);
// Only bottom-level Columns can get highlighted
if(oColumn && (oColumn.getKeyIndex() !== null)) {
// Update head cell
var elTh = oColumn.getThEl();
Dom.addClass(elTh,DT.CLASS_HIGHLIGHTED);
// Update body cells
var allRows = this.getTbodyEl().rows;
var oChainRender = this._oChainRender;
oChainRender.add({
method: function(oArg) {
if((this instanceof DT) && this._sId && allRows[oArg.rowIndex] && allRows[oArg.rowIndex].cells[oArg.cellIndex]) {
Dom.addClass(allRows[oArg.rowIndex].cells[oArg.cellIndex],DT.CLASS_HIGHLIGHTED);
}
oArg.rowIndex++;
},
scope: this,
iterations:allRows.length,
argument: {rowIndex:0,cellIndex:oColumn.getKeyIndex()},
timeout: -1
});
this._elTbody.style.display = "none";
this._runRenderChain();
this._elTbody.style.display = "";
this.fireEvent("columnHighlightEvent",{column:oColumn});
YAHOO.log("Column \"" + oColumn.key + "\" highlighed", "info", this.toString());
}
else {
YAHOO.log("Could not highlight Column \"" + oColumn.key + "\". Only non-nested Columns can be highlighted", "warn", this.toString());
}
},
/**
* Removes the class YAHOO.widget.DataTable.CLASS_HIGHLIGHTED to cells of the given Column.
* NOTE: You cannot highlight/unhighlight nested Columns. You can only
* highlight/unhighlight non-nested Columns, and bottom-level key Columns.
*
* @method unhighlightColumn
* @param column {HTMLElement | String | Number} DOM reference or ID string to a
* TH/TD element (or child of a TH/TD element), a Column key, or a ColumnSet key index.
*/
unhighlightColumn : function(column) {
var oColumn = this.getColumn(column);
// Only bottom-level Columns can get highlighted
if(oColumn && (oColumn.getKeyIndex() !== null)) {
// Update head cell
var elTh = oColumn.getThEl();
Dom.removeClass(elTh,DT.CLASS_HIGHLIGHTED);
// Update body cells
var allRows = this.getTbodyEl().rows;
var oChainRender = this._oChainRender;
oChainRender.add({
method: function(oArg) {
if((this instanceof DT) && this._sId && allRows[oArg.rowIndex] && allRows[oArg.rowIndex].cells[oArg.cellIndex]) {
Dom.removeClass(allRows[oArg.rowIndex].cells[oArg.cellIndex],DT.CLASS_HIGHLIGHTED);
}
oArg.rowIndex++;
},
scope: this,
iterations:allRows.length,
argument: {rowIndex:0,cellIndex:oColumn.getKeyIndex()},
timeout: -1
});
this._elTbody.style.display = "none";
this._runRenderChain();
this._elTbody.style.display = "";
this.fireEvent("columnUnhighlightEvent",{column:oColumn});
YAHOO.log("Column \"" + oColumn.key + "\" unhighlighted", "info", this.toString());
}
else {
YAHOO.log("Could not unhighlight Column \"" + oColumn.key + "\". Only non-nested Columns can be unhighlighted", "warn", this.toString());
}
},
// ROW FUNCTIONS
share/root/static/yui/build/datatable/datatable-debug.js view on Meta::CPAN
* @param aData {Object[]} Array of object literal data for the rows.
* @param index {Number} (optional) RecordSet position index at which to add data.
*/
addRows : function(aData, index) {
if(lang.isNumber(index) && (index < 0 || index > this._oRecordSet.getLength())) {
YAHOO.log("Could not add rows at index " + index + " with " + lang.dump(aData), "warn", this.toString());
return;
}
if(lang.isArray(aData)) {
var aRecords = this._oRecordSet.addRecords(aData, index);
if(aRecords) {
var recIndex = this.getRecordIndex(aRecords[0]);
// Paginated
var oPaginator = this.get('paginator');
if (oPaginator) {
// Update the paginator's totalRecords
var totalRecords = oPaginator.get('totalRecords');
if (totalRecords !== widget.Paginator.VALUE_UNLIMITED) {
oPaginator.set('totalRecords',totalRecords + aRecords.length);
}
var endRecIndex = (oPaginator.getPageRecords())[1];
// At least one of the new records affects the view
if (recIndex <= endRecIndex) {
this.render();
}
this.fireEvent("rowsAddEvent", {records:aRecords});
YAHOO.log("Added " + aRecords.length +
" rows at index " + this._oRecordSet.getRecordIndex(aRecords[0]) +
" with data " + lang.dump(aData), "info", this.toString());
return;
}
// Not paginated
else {
// Add the TR elements
var loopN = this.get("renderLoopSize");
var loopEnd = recIndex + aData.length;
var nRowsNeeded = (loopEnd - recIndex); // how many needed
var isLast = (recIndex >= this._elTbody.rows.length);
this._oChainRender.add({
method: function(oArg) {
if((this instanceof DT) && this._sId) {
var aRecords = oArg.aRecords,
i = oArg.nCurrentRow,
j = oArg.nCurrentRecord,
len = loopN > 0 ? Math.min(i + loopN,loopEnd) : loopEnd,
df = document.createDocumentFragment(),
elNext = (this._elTbody.rows[i]) ? this._elTbody.rows[i] : null;
for(; i < len; i++, j++) {
df.appendChild(this._addTrEl(aRecords[j]));
}
this._elTbody.insertBefore(df, elNext);
oArg.nCurrentRow = i;
oArg.nCurrentRecord = j;
}
},
iterations: (loopN > 0) ? Math.ceil(loopEnd/loopN) : 1,
argument: {nCurrentRow:recIndex,nCurrentRecord:0,aRecords:aRecords},
scope: this,
timeout: (loopN > 0) ? 0 : -1
});
this._oChainRender.add({
method: function(oArg) {
var recIndex = oArg.recIndex;
// Set FIRST/LAST
if(recIndex === 0) {
this._setFirstRow();
}
if(oArg.isLast) {
this._setLastRow();
}
// Set EVEN/ODD
this._setRowStripes();
this.fireEvent("rowsAddEvent", {records:aRecords});
YAHOO.log("Added " + aRecords.length +
" rows at index " + this._oRecordSet.getRecordIndex(aRecords[0]) +
" with data " + lang.dump(aData), "info", this.toString());
},
argument: {recIndex: recIndex, isLast: isLast},
scope: this,
timeout: -1 // Needs to run immediately after the DOM insertions above
});
this._runRenderChain();
this.hideTableMessage();
return;
}
}
}
YAHOO.log("Could not add rows at index " + index + " with " + lang.dump(aData), "warn", this.toString());
},
/**
* For the given row, updates the associated Record with the given data. If the
* row is on current page, the corresponding DOM elements are also updated.
*
* @method updateRow
* @param row {YAHOO.widget.Record | Number | HTMLElement | String}
* Which row to update: By Record instance, by Record's RecordSet
* position index, by HTMLElement reference to the TR element, or by ID string
* of the TR element.
* @param oData {Object} Object literal of data for the row.
*/
updateRow : function(row, oData) {
var index = row;
if (!lang.isNumber(index)) {
index = this.getRecordIndex(row);
}
// Update the Record
if(lang.isNumber(index) && (index >= 0)) {
var oRecordSet = this._oRecordSet,
oldRecord = oRecordSet.getRecord(index);
if(oldRecord) {
var updatedRecord = this._oRecordSet.setRecord(oData, index),
share/root/static/yui/build/datatable/datatable-debug.js view on Meta::CPAN
var tracker = this._aSelections || [],
i=0, j, newId, oldId;
for(; i<tracker.length; i++) {
for(j=0; j<aOldRecords.length; j++) {
oldId = aOldRecords[j].getId();
if((tracker[i] === oldId)) {
tracker[i] = aNewRecords[j].getId();
}
else if(tracker[i].recordId === oldId) {
tracker[i].recordId = aNewRecords[j].getId();
}
}
}
// Paginated
var oPaginator = this.get('paginator');
if (oPaginator) {
var pageStartIndex = (oPaginator.getPageRecords())[0],
pageLastIndex = (oPaginator.getPageRecords())[1];
// At least one of the new records affects the view
if ((startIndex >= pageStartIndex) || (lastIndex <= pageLastIndex)) {
this.render();
}
this.fireEvent("rowsAddEvent", {newRecords:aNewRecords, oldRecords:aOldRecords});
YAHOO.log("Added " + aNewRecords.length +
" rows starting at index " + startIndex +
" with data " + lang.dump(aData), "info", this.toString());
return;
}
// Not paginated
else {
// Update the TR elements
var loopN = this.get("renderLoopSize"),
rowCount = aData.length, // how many needed
lastRowIndex = this._elTbody.rows.length,
isLast = (lastIndex >= lastRowIndex),
isAdding = (lastIndex > lastRowIndex);
this._oChainRender.add({
method: function(oArg) {
if((this instanceof DT) && this._sId) {
var aRecords = oArg.aRecords,
i = oArg.nCurrentRow,
j = oArg.nDataPointer,
len = loopN > 0 ? Math.min(i+loopN, startIndex+aRecords.length) : startIndex+aRecords.length;
for(; i < len; i++,j++) {
if(isAdding && (i>=lastRowIndex)) {
this._elTbody.appendChild(this._addTrEl(aRecords[j]));
}
else {
this._updateTrEl(this._elTbody.rows[i], aRecords[j]);
}
}
oArg.nCurrentRow = i;
oArg.nDataPointer = j;
}
},
iterations: (loopN > 0) ? Math.ceil(rowCount/loopN) : 1,
argument: {nCurrentRow:startIndex,aRecords:aNewRecords,nDataPointer:0,isAdding:isAdding},
scope: this,
timeout: (loopN > 0) ? 0 : -1
});
this._oChainRender.add({
method: function(oArg) {
var recIndex = oArg.recIndex;
// Set FIRST/LAST
if(recIndex === 0) {
this._setFirstRow();
}
if(oArg.isLast) {
this._setLastRow();
}
// Set EVEN/ODD
this._setRowStripes();
this.fireEvent("rowsAddEvent", {newRecords:aNewRecords, oldRecords:aOldRecords});
YAHOO.log("Added " + aNewRecords.length +
" rows starting at index " + startIndex +
" with data " + lang.dump(aData), "info", this.toString());
},
argument: {recIndex: startIndex, isLast: isLast},
scope: this,
timeout: -1 // Needs to run immediately after the DOM insertions above
});
this._runRenderChain();
this.hideTableMessage();
return;
}
}
}
}
YAHOO.log("Could not update rows at " + startrow + " with " + lang.dump(aData), "warn", this.toString());
},
/**
* Deletes the given row's Record from the RecordSet. If the row is on current page,
* the corresponding DOM elements are also deleted.
*
* @method deleteRow
* @param row {HTMLElement | String | Number} DOM element reference or ID string
* to DataTable page element or RecordSet index.
*/
deleteRow : function(row) {
var nRecordIndex = (lang.isNumber(row)) ? row : this.getRecordIndex(row);
if(lang.isNumber(nRecordIndex)) {
var oRecord = this.getRecord(nRecordIndex);
if(oRecord) {
var nTrIndex = this.getTrIndex(nRecordIndex);
// Remove from selection tracker if there
var sRecordId = oRecord.getId();
var tracker = this._aSelections || [];
for(var j=tracker.length-1; j>-1; j--) {
if((lang.isString(tracker[j]) && (tracker[j] === sRecordId)) ||
(lang.isObject(tracker[j]) && (tracker[j].recordId === sRecordId))) {
tracker.splice(j,1);
}
}
share/root/static/yui/build/datatable/datatable-debug.js view on Meta::CPAN
}
}
else {
count = 1;
}
var aData = this._oRecordSet.deleteRecords(lowIndex, count);
// Update the UI
if(aData) {
var oPaginator = this.get('paginator'),
loopN = this.get("renderLoopSize");
// If paginated and the deleted row was on this or a prior page, just
// re-render
if (oPaginator) {
// Update the paginator's totalRecords
var totalRecords = oPaginator.get('totalRecords'),
// must capture before the totalRecords change because
// Paginator shifts to previous page automatically
rng = oPaginator.getPageRecords();
if (totalRecords !== widget.Paginator.VALUE_UNLIMITED) {
oPaginator.set('totalRecords',totalRecords - aData.length);
}
// The records were on this or a prior page, re-render
if (!rng || lowIndex <= rng[1]) {
this.render();
}
this._oChainRender.add({
method: function(oArg) {
if((this instanceof DT) && this._sId) {
this.fireEvent("rowsDeleteEvent", {recordIndex:lowIndex, oldData:aData, count:count});
YAHOO.log("DataTable " + count + " rows deleted starting at index " + lowIndex, "info", this.toString());
}
},
scope: this,
timeout: (loopN > 0) ? 0 : -1
});
this._runRenderChain();
return;
}
// Not paginated
else {
if(lang.isNumber(nTrIndex)) {
// Delete the TR elements starting with highest index
var loopEnd = lowIndex;
var nRowsNeeded = count; // how many needed
this._oChainRender.add({
method: function(oArg) {
if((this instanceof DT) && this._sId) {
var i = oArg.nCurrentRow,
len = (loopN > 0) ? (Math.max(i - loopN,loopEnd)-1) : loopEnd-1;
for(; i>len; --i) {
this._deleteTrEl(i);
}
oArg.nCurrentRow = i;
}
},
iterations: (loopN > 0) ? Math.ceil(count/loopN) : 1,
argument: {nCurrentRow:highIndex},
scope: this,
timeout: (loopN > 0) ? 0 : -1
});
this._oChainRender.add({
method: function() {
// Post-delete tasks
if(this._elTbody.rows.length > 0) {
this._setFirstRow();
this._setLastRow();
this._setRowStripes();
}
this.fireEvent("rowsDeleteEvent", {recordIndex:lowIndex, oldData:aData, count:count});
YAHOO.log("DataTable " + count + " rows deleted starting at index " + lowIndex, "info", this.toString());
},
scope: this,
timeout: -1 // Needs to run immediately after the DOM deletions above
});
this._runRenderChain();
return;
}
}
}
}
}
YAHOO.log("Could not delete " + count + " rows at row " + row, "warn", this.toString());
return null;
},
( run in 1.598 second using v1.01-cache-2.11-cpan-71847e10f99 )