define("dojox/grid/cells/_base", [
"dojo/_base/kernel",
"dojo/_base/declare",
"dojo/_base/lang",
"dojo/_base/event",
"dojo/_base/connect",
"dojo/_base/array",
"dojo/_base/sniff",
"dojo/dom",
"dojo/dom-attr",
"dojo/dom-construct",
"dijit/_Widget",
"../util"
], function(dojo, declare, lang, event, connect, array, has, dom, domAttr, domConstruct, _Widget, util){
var _DeferredTextWidget = declare("dojox.grid._DeferredTextWidget", _Widget, {
deferred: null,
_destroyOnRemove: true,
postCreate: function(){
if(this.deferred){
this.deferred.addBoth(lang.hitch(this, function(text){
if(this.domNode){
this.domNode.innerHTML = text;
}
}));
}
}
});
var focusSelectNode = function(inNode){
try{
util.fire(inNode, "focus");
util.fire(inNode, "select");
}catch(e){// IE sux bad
}
};
var whenIdle = function(/*inContext, inMethod, args ...*/){
setTimeout(lang.hitch.apply(dojo, arguments), 0);
};
var BaseCell = declare("dojox.grid.cells._Base", null, {
// summary:
// Represents 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 || {};
lang.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 _DeferredTextWidget({deferred: v},
domConstruct.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 f, i=this.grid.edit.info, d=this.get ? this.get(inRowIndex, inItem) : (this.value || this.defaultValue);
d = (d && d.replace && this.grid.escapeHTMLInData) ? 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){
event.stop(e);
}
}
},
_finish: function(inRowIndex){
this.inherited(arguments);
var n = this.getEditNode(inRowIndex);
try{
util.fire(n, "blur");
}catch(e){}
}
});
Cell.markupFactory = function(node, cellDef){
BaseCell.markupFactory(node, cellDef);
var keyFilter = lang.trim(domAttr.get(node, "keyFilter")||"");
if(keyFilter){
cellDef.keyFilter = new RegExp(keyFilter);
}
};
var RowIndex = declare("dojox.grid.cells.RowIndex", Cell, {
name: 'Row',
postscript: function(){
this.editable = false;
},
get: function(inRowIndex){
return inRowIndex + 1;
}
});
RowIndex.markupFactory = function(node, cellDef){
Cell.markupFactory(node, cellDef);
};
var Select = declare("dojox.grid.cells.Select", 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('');
},
_defaultFormat: function(inValue, callArgs){
var v = this.inherited(arguments);
// when 'values' and 'options' both provided and there is no cutomized formatter,
// then we use 'options' as label in order to be consistent
if(!this.formatter && this.values && this.options){
var i = array.indexOf(this.values, v);
if(i >= 0){
v = this.options[i];
}
}
return v;
},
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;
}
}
});
Select.markupFactory = function(node, cell){
Cell.markupFactory(node, cell);
var options = lang.trim(domAttr.get(node, "options")||"");
if(options){
var o = options.split(',');
if(o[0] != options){
cell.options = o;
}
}
var values = lang.trim(domAttr.get(node, "values")||"");
if(values){
var v = values.split(',');
if(v[0] != values){
cell.values = v;
}
}
};
var AlwaysEdit = declare("dojox.grid.cells.AlwaysEdit", 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);
}
});
AlwaysEdit.markupFactory = function(node, cell){
Cell.markupFactory(node, cell);
};
var Bool = declare("dojox.grid.cells.Bool", 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);
}
}
});
Bool.markupFactory = function(node, cell){
AlwaysEdit.markupFactory(node, cell);
};
return BaseCell;
});