datatable.js revision 7f1404a89e4ee3cfaa1bba7cfea0b746434c5bc8
}
/**
* Class name.
*
* @property NAME
* @type String
* @static
* @final
* @value "column"
*/
/////////////////////////////////////////////////////////////////////////////
//
// Column Attributes
//
/////////////////////////////////////////////////////////////////////////////
id: {
valueFn: "_defaultId",
writeOnce: true
},
key: {
valueFn: "_defaultKey"
},
field: {
valueFn: "_defaultField"
},
label: {
valueFn: "_defaultLabel"
},
keyIndex: {
readOnly: true
},
parent: {
readOnly: true
},
children: {
},
colspan: {
readOnly: true
},
rowspan: {
readOnly: true
},
thNode: {
readOnly: true
},
thLinerNode: {
readOnly: true
},
thLabelNode: {
readOnly: true
},
abbr: {
value: null
},
className: {},
editor: {},
formatter: {},
// requires datatable-colresize
resizeable: {},
//requires datatable-sort
sortable: {},
hidden: {},
width: {},
minWidth: {},
maxAutoWidth: {}
};
/* Column extends Widget */
_defaultId: function() {
return Y.guid();
},
_defaultKey: function(key) {
},
_defaultField: function(field) {
},
_defaultLabel: function(label) {
},
initializer: function() {
},
destructor: function() {
},
syncUI: function() {
},
_afterAbbrChange: function (e) {
this._uiSetAbbr(e.newVal);
},
_uiSetAbbr: function(val) {
}
});
}
/**
* Class name.
*
* @property NAME
* @type String
* @static
* @final
* @value "columnset"
*/
/////////////////////////////////////////////////////////////////////////////
//
// Columnset Attributes
//
/////////////////////////////////////////////////////////////////////////////
columns: {
setter: "_setColumns"
},
// DOM tree representation of all Columns
tree: {
readOnly: true,
value: []
},
//TODO: is this necessary?
// Flat representation of all Columns
flat: {
readOnly: true,
value: []
},
// Hash of all Columns by ID
hash: {
readOnly: true,
value: {}
},
// Flat representation of only Columns that are meant to display data
keys: {
readOnly: true,
value: []
}
};
/* Columnset extends Base */
_setColumns: function(columns) {
},
initializer: function() {
// DOM tree representation of all Columns
var tree = [],
// Flat representation of all Columns
flat = [],
// Hash of all Columns by ID
hash = {},
// Flat representation of only Columns that are meant to display data
keys = [],
// Original definitions
self = this;
// Internal recursive function to define Column instances
var i=0,
// One level down
depth++;
// Create corresponding dom node if not already there for this depth
}
// Parse each node at this depth for attributes and any children
for(; i<len; ++i) {
currentNode = nodeList[i];
// Instantiate a new Column for each node
// Cross-reference Column ID back to the original object literal definition
// Add the new Column to the flat list
// Add the new Column to the hash
// Assign its parent as an attribute, if applicable
if(parent) {
}
// The Column has descendants
// The children themselves must also be parsed for Column instances
}
}
// This Column does not have any children
else {
}
// Add the Column to the top-down dom tree
}
depth--;
}
// Parse out Column instances from the array of object literals
// Save to the Columnset instance
this._setRowSpans();
this._setHeaders();
},
destructor: function() {
},
var i = 0,
// Cascade certain properties to children if not defined on their own
for(; i<len; ++i) {
child = currentChildren[i];
}
}
}
}
}
}
}
}
}
}
},
// Determine COLSPAN value for this Column
var terminalChildNodes = 0;
function countTerminalChildNodes(ancestor) {
i = 0,
// Drill down each branch and count terminal nodes
for(; i<len; ++i) {
// Keep drilling down
}
// Reached branch terminus
else {
}
}
}
},
_setRowSpans: function() {
// Determine ROWSPAN value for each Column in the dom tree
function parseDomTreeForRowspan(tree) {
var maxRowDepth = 1,
m,p;
// Calculate the max depth of descendants for this row
var i = 0,
col;
for(; i<len; ++i) {
// Column has children, so keep counting
tmpRowDepth++;
tmpRowDepth--;
}
// Column has children, so keep counting
tmpRowDepth++;
tmpRowDepth--;
}
// No children, is it the max depth?
else {
if(tmpRowDepth > maxRowDepth) {
}
}
}
}
// Count max row depth for each row
currentRow = tree[m];
// Assign the right ROWSPAN values to each Column in the row
currentColumn = currentRow[p];
}
else {
}
}
// Reset counter for next row
maxRowDepth = 1;
}
}
},
_setHeaders: function() {
//headers[i].push(oColumn.getSanitizedKey());
}
}
for(; i<len; ++i) {
headers = [];
}
},
getColumn: function() {
}
});
DATATABLE = "datatable",
FOCUS = "focus",
KEYDOWN = "keydown",
MOUSEOVER = "mouseover",
MOUSEOUT = "mouseout",
MOUSEUP = "mouseup",
MOUSEDOWN = "mousedown",
CLICK = "click",
DOUBLECLICK = "doubleclick",
TEMPLATE_TH = '<th id="{id}" rowspan="{rowspan}" colspan="{colspan}"><div class="'+CLASS_LINER+'">{value}</div></th>',
TEMPLATE_TR = '<tr id="{id}"></tr>',
TEMPLATE_VALUE = '{value}';
}
/*
* Required NAME static field, to identify the Widget class and
* used as an event prefix, to generate class names etc. (set to the
* class name in camel case).
*/
/*
* The attribute configuration for the widget. This defines the core user facing state of the widget
*/
columnset: {
setter: "_setColumnset"
},
//@type Recordset or Array
recordset: {
setter: "_setRecordset"
},
state: {
readOnly: true
},
strings: {
valueFn: function() {
}
},
},
},
trTemplate: {
}
};
/*
* The HTML_PARSER static constant is used if the Widget supports progressive enhancement, and is
* used to populate the configuration for the DTBase instance from markup already on the page.
*/
DTBase.HTML_PARSER = {
// If progressive enhancement is to be supported, return the value of "attrA" based on the contents of the srcNode
}
};
/* DTBase extends the base Widget class */
// Properties
_theadNode: null,
_tbodyNode: null,
_msgNode: null,
// Attributes
_setColumnset: function(columns) {
},
_setRecordset: function(recordset) {
}
return recordset;
},
// Initialization
initializer: function() {
// Custom events that broadcast DOM updates
// Custom events that broadcast DOM interactions
// Simply pass through DOM event facades
//TODO: do we need queuable=true?
},
// Destruction
destructor: function() {
},
// UI
renderUI: function() {
// TABLE and CAPTION
var ok = this._createTableNode();
// COLGROUP
// THEAD
// Primary TBODY
// Message TBODY
// CAPTION
return ok;
},
_createTableNode: function() {
if (!this._tableNode) {
}
return this._tableNode;
},
_createColgroupNode: function(tableNode) {
// Add COLs to DOCUMENT FRAGMENT
i = 0,
allCols = ["<colgroup>"];
for(; i<len; ++i) {
}
// Create COLGROUP
this._colgroupNode = tableNode.insertBefore(NODE.create(allCols.join("")), tableNode.get("firstChild"));
return this._colgroupNode;
},
_createTheadNode: function(tableNode) {
if(tableNode) {
this._theadNode = tableNode.insertBefore(NODE.create("<thead class='"+CLASS_COLUMNS+"'></thead>"), this._colgroupNode.next());
return this._theadNode;
}
},
_createTbodyNode: function(tableNode) {
return this._tbodyNode;
},
_createMessageNode: function(tableNode) {
this._msgNode = tableNode.insertBefore(NODE.create("<tbody class='"+CLASS_MSG+"'></tbody>"), this._tbodyNode);
return this._msgNode;
},
_createCaptionNode: function(tableNode) {
return this._captionNode;
},
// Events
bindUI: function() {
var tableNode = this._tableNode,
// DOM event delegation for THEAD
// Since we can't listen for click and dblclick on the same element...
// DOM event delegation for TBODY
// Since we can't listen for click and dblclick on the same element...
// DOM event delegation for MSG TBODY
// Since we can't listen for click and dblclick on the same element...
},
_onTheadFocus: function() {
},
_onTheadKeydown: function() {
},
_onTheadMouseover: function() {
},
_onTheadMouseout: function() {
},
_onTheadMouseup: function() {
},
_onTheadMousedown: function() {
},
// e.currentTarget holds the clicked element
_onTheadClick: function(e) {
this.fire("theadCellClick", e);
this.fire("theadRowClick", e);
this.fire("theadClick", e);
},
_onTheadDoubleclick: function() {
},
_onTbodyFocus: function() {
},
_onTbodyKeydown: function() {
},
_onTbodyMouseover: function() {
},
_onTbodyMouseout: function() {
},
_onTbodyMouseup: function() {
},
_onTbodyMousedown: function() {
},
_onTbodyClick: function(e) {
},
_onTbodyDoubleclick: function() {
},
_onMsgFocus: function() {
},
_onMsgKeydown: function() {
},
_onMsgMouseover: function() {
},
_onMsgMouseout: function() {
},
_onMsgMouseup: function() {
},
_onMsgMousedown: function() {
},
_onMsgClick: function(e) {
},
_onMsgDoubleclick: function() {
},
syncUI: function() {
/*
* syncUI is intended to be used by the Widget subclass to
* update the UI to reflect the initial state of the widget,
* after renderUI. From there, the event listeners we bound above
* will take over.
*/
// STRINGS
// THEAD ROWS
// DATA ROWS
},
/* Listeners, UI update methods */
/**
* Updates the UI if changes are made to any of the strings in the strings
* attribute.
*
* @method _afterStringsChange
* @param e {Event} Custom event for the attribute change
* @protected
*/
_afterStringsChange: function (e) {
this._uiSetStrings(e.newVal);
},
_uiSetStrings: function (strings) {
},
_uiSetSummary: function(val) {
},
_uiSetCaption: function(val) {
},
////////////////////////////////////////////////////////////////////////////
//
// THEAD FUNCTIONALITY
//
////////////////////////////////////////////////////////////////////////////
_afterColumnsetChange: function (e) {
this._uiSetColumnset(e.newVal);
},
_uiSetColumnset: function(cs) {
theadNode = this._theadNode,
i = 0,
tr,
}
//TODO: move thead off dom
// Iterate tree to add rows
for(; i<len; ++i) {
if(i === 0) {
}
if(i === len-1) {
}
}
// Column helpers needs _theadNode to exist
//this._createColumnHelpers();
//TODO: move thead on dom
},
_defAddTheadTrFn: function(e) {
i = 0,
th;
for(; i<len; ++i) {
}
},
_getTheadTrMarkup: function(record) {
},
_defAddTheadThFn: function(e) {
//column._set("thNode", thNode);
},
_getTheadThMarkup: function(o, column) {
//TODO o.classnames
//TODO o.abbr = column.get("abbr");
/*TODO
// Clear minWidth on hidden Columns
if(column.get("hidden")) {
//this._clearMinWidth(column);
}
*/
return Y.substitute(this.thTemplate, o);
},
_afterRecordsetChange: function (e) {
this._uiSetRecordset(e.newVal);
},
_uiSetRecordset: function(rs) {
var i = 0,//TODOthis.get("state.offsetIndex"),
// Iterate recordset to use existing or add new tr
for(; i<len; ++i) {
}
},
_defAddTrFn: function(e) {
tbodyNode = this._tbodyNode,
return tr;
},
_createBodyTr: function(record) {
return tr;
},
_getDataTrMarkup: function(record) {
},
var i = 0,
tds = [];
for(; i<len; ++i) {
}
},
var o = {};
return Y.substitute(this.tdTemplate, o);
},
var o = {};
}
});
//TODO: break out into own component
var //getClassName = Y.ClassNameManager.getClassName,
//DATATABLE = "datatable",
ASC = "asc",
DESC = "desc",
//CLASS_ASC = getClassName(DATATABLE, "asc"),
//CLASS_DESC = getClassName(DATATABLE, "desc"),
TEMPLATE_TH_LINK = '<a class="{link_class}" title="{link_title}" href="{link_href}">{value}</a>';
/*function RecordsetSort(field, desc, sorter) {
RecordsetSort.superclass.constructor.apply(this, arguments);
}
Y.mix(RecordsetSort, {
NS: "sort",
NAME: "recordsetSort",
ATTRS: {
dt: {
},
defaultSorter: {
value: function(recA, recB, field, desc) {
var sorted = COMPARE(recA.getValue(field), recB.getValue(field), desc);
if(sorted === 0) {
return COMPARE(recA.get("id"), recB.get("id"), desc);
}
else {
return sorted;
}
}
}
}
});
Y.extend(RecordsetSort, Y.Plugin.Base, {
initializer: function(config) {
this.addTarget(this.get("dt"));
this.publish("sort", {defaultFn: Y.bind("_defSortFn", this)});
},
destructor: function(config) {
},
_defSortFn: function(e) {
this.get("host").get("records").sort(function(a, b) {return (e.sorter)(a, b, e.field, e.desc);});
},
sort: function(field, desc, sorter) {
this.fire("sort", {field:field, desc: desc, sorter: sorter|| this.get("defaultSorter")});
},
custom: function() {
alert("sort custom");
},
// force asc
asc: function() {
alert("sort asc");
},
// force desc
desc: function() {
alert("sort desc");
},
// force reverse
reverse: function() {
alert("sort reverse");
}
});
Y.namespace("Plugin").RecordsetSort = RecordsetSort;*/
function DataTableSort() {
}
Y.mix(DataTableSort, {
NS: "sort",
NAME: "dataTableSort",
ATTRS: {
sortedBy: {
value: null
}
}
});
initializer: function(config) {
// Wrap link around TH value
// Add class
});
// Attach click handlers
// Attach UI hooks
});
alert('ok');
});
//TODO
//dt.after("recordset:mutation", function() {//reset sortedBy});
//TODO
//add Column sortFn ATTR
// Update UI after the fact (plug-then-render case)
}
},
_beforeGetTheadThMarkup: function(o, column) {
link_class: "foo",
link_title: "bar",
link_href: "bat",
});
}
},
_onEventSortColumn: function(e) {
e.halt();
//TODO: normalize e.currentTarget to TH
dir = (prevSortedBy &&
}
}
});
DATATABLE = "datatable",
//CLASS_RESIZEABLE = GETCLASSNAME(DATATABLE, "resizeable"),
function DataTableColResize() {
}
Y.mix(DataTableColResize, {
NS: "colresize",
NAME: "dataTableColResize",
ATTRS: {
}
});
initializer: function(config) {
this.get("host").thTemplate = Y.substitute(this.get("host").thTemplate, {value: this.thLinerTemplate});
this.get("host").tdTemplate = Y.substitute(this.get("host").tdTemplate, {value: this.tdLinerTemplate});
//TODO Set Column width...
/*if(oColumn.width) {
// Validate minWidth
var nWidth = (oColumn.minWidth && (oColumn.width < oColumn.minWidth)) ?
oColumn.minWidth : oColumn.width;
// ...for fallback cases
if(DT._bDynStylesFallback) {
elTh.firstChild.style.overflow = 'hidden';
elTh.firstChild.style.width = nWidth + 'px';
}
// ...for non fallback cases
else {
this._setColumnWidthDynStyles(oColumn, nWidth + 'px', 'hidden');
}
}*/
}
});
YUI.add('datatable', function(Y){}, '@VERSION@' ,{use:['datatable-base','datatable-sort','datatable-colresize']});