Hopkins-Plugin-HMI
view release on metacpan or search on metacpan
share/root/static/yui/build/datatable/datatable.js view on Meta::CPAN
* Formats text strings.
*
* @method DataTable.formatText
* @param el {HTMLElement} The element to format with markup.
* @param oRecord {YAHOO.widget.Record} Record instance.
* @param oColumn {YAHOO.widget.Column} Column instance.
* @param oData {Object} (Optional) Data value for the cell.
* @static
*/
formatText : function(el, oRecord, oColumn, oData) {
var value = (lang.isValue(oData)) ? oData : "";
//TODO: move to util function
el.innerHTML = value.toString().replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
},
/**
* Formats TEXTAREA elements.
*
* @method DataTable.formatTextarea
* @param el {HTMLElement} The element to format with markup.
* @param oRecord {YAHOO.widget.Record} Record instance.
* @param oColumn {YAHOO.widget.Column} Column instance.
* @param oData {Object} (Optional) Data value for the cell.
* @static
*/
formatTextarea : function(el, oRecord, oColumn, oData) {
var value = (lang.isValue(oData)) ? oData : "",
markup = "<textarea>" + value + "</textarea>";
el.innerHTML = markup;
},
/**
* Formats INPUT TYPE=TEXT elements.
*
* @method DataTable.formatTextbox
* @param el {HTMLElement} The element to format with markup.
* @param oRecord {YAHOO.widget.Record} Record instance.
* @param oColumn {YAHOO.widget.Column} Column instance.
* @param oData {Object} (Optional) Data value for the cell.
* @static
*/
formatTextbox : function(el, oRecord, oColumn, oData) {
var value = (lang.isValue(oData)) ? oData : "",
markup = "<input type=\"text\" value=\"" + value + "\" />";
el.innerHTML = markup;
},
/**
* Default cell formatter
*
* @method DataTable.formatDefault
* @param el {HTMLElement} The element to format with markup.
* @param oRecord {YAHOO.widget.Record} Record instance.
* @param oColumn {YAHOO.widget.Column} Column instance.
* @param oData {Object} (Optional) Data value for the cell.
* @static
*/
formatDefault : function(el, oRecord, oColumn, oData) {
el.innerHTML = oData === undefined ||
oData === null ||
(typeof oData === 'number' && isNaN(oData)) ?
" " : oData.toString();
},
/**
* Validates data value to type Number, doing type conversion as
* necessary. A valid Number value is return, else null is returned
* if input value does not validate.
*
*
* @method DataTable.validateNumber
* @param oData {Object} Data to validate.
* @static
*/
validateNumber : function(oData) {
//Convert to number
var number = oData * 1;
// Validate
if(lang.isNumber(number)) {
return number;
}
else {
return undefined;
}
}
});
// Done in separate step so referenced functions are defined.
/**
* Cell formatting functions.
* @property DataTable.Formatter
* @type Object
* @static
*/
DT.Formatter = {
button : DT.formatButton,
checkbox : DT.formatCheckbox,
currency : DT.formatCurrency,
"date" : DT.formatDate,
dropdown : DT.formatDropdown,
email : DT.formatEmail,
link : DT.formatLink,
"number" : DT.formatNumber,
radio : DT.formatRadio,
text : DT.formatText,
textarea : DT.formatTextarea,
textbox : DT.formatTextbox,
defaultFormatter : DT.formatDefault
};
lang.extend(DT, util.Element, {
/////////////////////////////////////////////////////////////////////////////
//
// Superclass methods
//
/////////////////////////////////////////////////////////////////////////////
/**
share/root/static/yui/build/datatable/datatable.js view on Meta::CPAN
// Get a particular CellEditor
elCell = this.getTdEl(elCell);
if(elCell) {
oColumn = this.getColumn(elCell);
if(oColumn && oColumn.editor) {
var oCellEditor = this._oCellEditor;
// Clean up active CellEditor
if(oCellEditor) {
if(this._oCellEditor.cancel) {
this._oCellEditor.cancel();
}
else if(oCellEditor.isActive) {
this.cancelCellEditor();
}
}
if(oColumn.editor instanceof YAHOO.widget.BaseCellEditor) {
// Get CellEditor
oCellEditor = oColumn.editor;
var ok = oCellEditor.attach(this, elCell);
if(ok) {
oCellEditor.move();
ok = this.doBeforeShowCellEditor(oCellEditor);
if(ok) {
oCellEditor.show();
this._oCellEditor = oCellEditor;
}
}
}
// Backward compatibility
else {
if(!oRecord || !(oRecord instanceof YAHOO.widget.Record)) {
oRecord = this.getRecord(elCell);
}
if(!oColumn || !(oColumn instanceof YAHOO.widget.Column)) {
oColumn = this.getColumn(elCell);
}
if(oRecord && oColumn) {
if(!this._oCellEditor || this._oCellEditor.container) {
this._initCellEditorEl();
}
// Update Editor values
oCellEditor = this._oCellEditor;
oCellEditor.cell = elCell;
oCellEditor.record = oRecord;
oCellEditor.column = oColumn;
oCellEditor.validator = (oColumn.editorOptions &&
lang.isFunction(oColumn.editorOptions.validator)) ?
oColumn.editorOptions.validator : null;
oCellEditor.value = oRecord.getData(oColumn.key);
oCellEditor.defaultValue = null;
// Move Editor
var elContainer = oCellEditor.container;
var x = Dom.getX(elCell);
var y = Dom.getY(elCell);
// SF doesn't get xy for cells in scrolling table
// when tbody display is set to block
if(isNaN(x) || isNaN(y)) {
x = elCell.offsetLeft + // cell pos relative to table
Dom.getX(this._elTbody.parentNode) - // plus table pos relative to document
this._elTbody.scrollLeft; // minus tbody scroll
y = elCell.offsetTop + // cell pos relative to table
Dom.getY(this._elTbody.parentNode) - // plus table pos relative to document
this._elTbody.scrollTop + // minus tbody scroll
this._elThead.offsetHeight; // account for fixed THEAD cells
}
elContainer.style.left = x + "px";
elContainer.style.top = y + "px";
// Hook to customize the UI
this.doBeforeShowCellEditor(this._oCellEditor);
//TODO: This is temporarily up here due so elements can be focused
// Show Editor
elContainer.style.display = "";
// Handle ESC key
Ev.addListener(elContainer, "keydown", function(e, oSelf) {
// ESC hides Cell Editor
if((e.keyCode == 27)) {
oSelf.cancelCellEditor();
oSelf.focusTbodyEl();
}
else {
oSelf.fireEvent("editorKeydownEvent", {editor:oSelf._oCellEditor, event:e});
}
}, this);
// Render Editor markup
var fnEditor;
if(lang.isString(oColumn.editor)) {
switch(oColumn.editor) {
case "checkbox":
fnEditor = DT.editCheckbox;
break;
case "date":
fnEditor = DT.editDate;
break;
case "dropdown":
fnEditor = DT.editDropdown;
break;
case "radio":
fnEditor = DT.editRadio;
break;
case "textarea":
fnEditor = DT.editTextarea;
break;
case "textbox":
fnEditor = DT.editTextbox;
break;
default:
fnEditor = null;
}
}
else if(lang.isFunction(oColumn.editor)) {
fnEditor = oColumn.editor;
}
share/root/static/yui/build/datatable/datatable.js view on Meta::CPAN
// Cancel button
var elCancelBtn = elBtnsDiv.appendChild(document.createElement("button"));
elCancelBtn.innerHTML = this.LABEL_CANCEL;
Ev.addListener(elCancelBtn, "click", function(oArgs) {
this.cancel();
}, this, true);
this._elCancelBtn = elCancelBtn;
},
/**
* Attach CellEditor for a new interaction.
*
* @method attach
* @param oDataTable {YAHOO.widget.DataTable} Associated DataTable instance.
* @param elCell {HTMLElement} Cell to edit.
*/
attach : function(oDataTable, elCell) {
// Validate
if(oDataTable instanceof YAHOO.widget.DataTable) {
this._oDataTable = oDataTable;
// Validate cell
elCell = oDataTable.getTdEl(elCell);
if(elCell) {
this._elTd = elCell;
// Validate Column
var oColumn = oDataTable.getColumn(elCell);
if(oColumn) {
this._oColumn = oColumn;
// Validate Record
var oRecord = oDataTable.getRecord(elCell);
if(oRecord) {
this._oRecord = oRecord;
var value = oRecord.getData(this.getColumn().getKey());
this.value = (value !== undefined) ? value : this.defaultValue;
return true;
}
}
}
}
return false;
},
/**
* Moves container into position for display.
*
* @method move
*/
move : function() {
// Move Editor
var elContainer = this.getContainerEl(),
elTd = this.getTdEl(),
x = Dom.getX(elTd),
y = Dom.getY(elTd);
//TODO: remove scrolling logic
// SF doesn't get xy for cells in scrolling table
// when tbody display is set to block
if(isNaN(x) || isNaN(y)) {
var elTbody = this.getDataTable().getTbodyEl();
x = elTd.offsetLeft + // cell pos relative to table
Dom.getX(elTbody.parentNode) - // plus table pos relative to document
elTbody.scrollLeft; // minus tbody scroll
y = elTd.offsetTop + // cell pos relative to table
Dom.getY(elTbody.parentNode) - // plus table pos relative to document
elTbody.scrollTop + // minus tbody scroll
this.getDataTable().getTheadEl().offsetHeight; // account for fixed THEAD cells
}
elContainer.style.left = x + "px";
elContainer.style.top = y + "px";
},
/**
* Displays CellEditor UI in the correct position.
*
* @method show
*/
show : function() {
this.resetForm();
this.isActive = true;
this.getContainerEl().style.display = "";
this.focus();
this.fireEvent("showEvent", {editor:this});
},
/**
* Fires blockEvent
*
* @method block
*/
block : function() {
this.fireEvent("blockEvent", {editor:this});
},
/**
* Fires unblockEvent
*
* @method unblock
*/
unblock : function() {
this.fireEvent("unblockEvent", {editor:this});
},
/**
* Saves value of CellEditor and hides UI.
*
* @method save
*/
save : function() {
// Get new value
var inputValue = this.getInputValue();
var validValue = inputValue;
// Validate new value
if(this.validator) {
validValue = this.validator.call(this.getDataTable(), inputValue, this.value, this);
if(validValue === undefined ) {
if(this.resetInvalidData) {
( run in 0.675 second using v1.01-cache-2.11-cpan-39bf76dae61 )