/*
Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
Available via Academic Free License >= 2.1 OR the modified BSD license.
see: http://dojotoolkit.org/license for details
*/
if(!dojo._hasResource["dojox.grid.cells._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.grid.cells._base"] = true;
dojo.provide("dojox.grid.cells._base");
dojo.require("dojox.grid.util");
dojo.require("dijit._Widget");
dojo.declare("dojox.grid._DeferredTextWidget", dijit._Widget, {
deferred: null,
_destroyOnRemove: true,
postCreate: function(){
if(this.deferred){
this.deferred.addBoth(dojo.hitch(this, function(text){
if(this.domNode){
this.domNode.innerHTML = text;
}
}));
}
}
});
(function(){
var focusSelectNode = function(inNode){
try{
dojox.grid.util.fire(inNode, "focus");
dojox.grid.util.fire(inNode, "select");
}catch(e){// IE sux bad
}
};
var whenIdle = function(/*inContext, inMethod, args ...*/){
setTimeout(dojo.hitch.apply(dojo, arguments), 0);
};
var dgc = dojox.grid.cells;
dojo.declare("dojox.grid.cells._Base", null, {
// summary:
// Respresents a grid cell and contains information about column options and methods
// for retrieving cell related information.
// Each column in a grid layout has a cell object and most events and many methods
// provide access to these objects.
styles: '',
classes: '',
editable: false,
alwaysEditing: false,
formatter: null,
defaultValue: '...',
value: null,
hidden: false,
noresize: false,
draggable: true,
//private
_valueProp: "value",
_formatPending: false,
constructor: function(inProps){
this._props = inProps || {};
dojo.mixin(this, inProps);
if(this.draggable === undefined){
this.draggable = true;
}
},
_defaultFormat: function(inValue, callArgs){
var s = this.grid.formatterScope || this;
var f = this.formatter;
if(f && s && typeof f == "string"){
f = this.formatter = s[f];
}
var v = (inValue != this.defaultValue && f) ? f.apply(s, callArgs) : inValue;
if(typeof v == "undefined"){
return this.defaultValue;
}
if(v && v.addBoth){
// Check if it's a deferred
v = new dojox.grid._DeferredTextWidget({deferred: v},
dojo.create("span", {innerHTML: this.defaultValue}));
}
if(v && v.declaredClass && v.startup){
return "
" +
this.defaultValue +
"
";
}
return v;
},
// data source
format: function(inRowIndex, inItem){
// summary:
// provides the html for a given grid cell.
// inRowIndex: int
// grid row index
// returns: html for a given grid cell
var i = this.grid.edit.info;
var d = this.get ? this.get(inRowIndex, inItem) : (this.value || this.defaultValue);
if (d && d.replace && this.grid.escapeHTMLInData) {
d = d.replace(/&/g, '&').replace(/';
},
formatNode: function(inNode, inDatum, inRowIndex){
this.inherited(arguments);
// FIXME: feels too specific for this interface
this.registerOnBlur(inNode, inRowIndex);
},
doKey: function(e){
if(this.keyFilter){
var key = String.fromCharCode(e.charCode);
if(key.search(this.keyFilter) == -1){
dojo.stopEvent(e);
}
}
},
_finish: function(inRowIndex){
this.inherited(arguments);
var n = this.getEditNode(inRowIndex);
try{
dojox.grid.util.fire(n, "blur");
}catch(e){}
}
});
dgc.Cell.markupFactory = function(node, cellDef){
dgc._Base.markupFactory(node, cellDef);
var d = dojo;
var keyFilter = d.trim(d.attr(node, "keyFilter")||"");
if(keyFilter){
cellDef.keyFilter = new RegExp(keyFilter);
}
};
dojo.declare("dojox.grid.cells.RowIndex", dgc.Cell, {
name: 'Row',
postscript: function(){
this.editable = false;
},
get: function(inRowIndex){
return inRowIndex + 1;
}
});
dgc.RowIndex.markupFactory = function(node, cellDef){
dgc.Cell.markupFactory(node, cellDef);
};
dojo.declare("dojox.grid.cells.Select", dgc.Cell, {
// summary:
// grid cell that provides a standard select for editing
// options: Array
// text of each item
options: null,
// values: Array
// value for each item
values: null,
// returnIndex: Integer
// editor returns only the index of the selected option and not the value
returnIndex: -1,
constructor: function(inCell){
this.values = this.values || this.options;
},
formatEditing: function(inDatum, inRowIndex){
this.needFormatNode(inDatum, inRowIndex);
var h = [ '');
return h.join('');
},
getValue: function(inRowIndex){
var n = this.getEditNode(inRowIndex);
if(n){
var i = n.selectedIndex, o = n.options[i];
return this.returnIndex > -1 ? i : o.value || o.innerHTML;
}
}
});
dgc.Select.markupFactory = function(node, cell){
dgc.Cell.markupFactory(node, cell);
var d=dojo;
var options = d.trim(d.attr(node, "options")||"");
if(options){
var o = options.split(',');
if(o[0] != options){
cell.options = o;
}
}
var values = d.trim(d.attr(node, "values")||"");
if(values){
var v = values.split(',');
if(v[0] != values){
cell.values = v;
}
}
};
dojo.declare("dojox.grid.cells.AlwaysEdit", dgc.Cell, {
// summary:
// grid cell that is always in an editable state, regardless of grid editing state
alwaysEditing: true,
_formatNode: function(inDatum, inRowIndex){
this.formatNode(this.getEditNode(inRowIndex), inDatum, inRowIndex);
},
applyStaticValue: function(inRowIndex){
var e = this.grid.edit;
e.applyCellEdit(this.getValue(inRowIndex), this, inRowIndex);
e.start(this, inRowIndex, true);
}
});
dgc.AlwaysEdit.markupFactory = function(node, cell){
dgc.Cell.markupFactory(node, cell);
};
dojo.declare("dojox.grid.cells.Bool", dgc.AlwaysEdit, {
// summary:
// grid cell that provides a standard checkbox that is always on for editing
_valueProp: "checked",
formatEditing: function(inDatum, inRowIndex){
return '';
},
doclick: function(e){
if(e.target.tagName == 'INPUT'){
this.applyStaticValue(e.rowIndex);
}
}
});
dgc.Bool.markupFactory = function(node, cell){
dgc.AlwaysEdit.markupFactory(node, cell);
};
})();
}