if (!window.My) My=[];
if (!My.Templates) My.Templates=[];
My.Templates.Select = Active.System.Template.subclass();
My.Templates.Select.create = function(){
/****************************************************************
Select Cell template.
*****************************************************************/
var obj = this.prototype;
var _super = this.superclass.prototype;
// ------------------------------------------------------------
obj.setTag("select");
obj.setClass("templates", "input");
obj.setClass("input","select");
obj.setClass("select", function(){return this.getColumnProperty("index")});
obj.getName = function() {
var r = this.getRowProperty("index");
var c = this.getColumnProperty("index");
if (!r) r = 0;
if (!c) c = 0;
return "item_"+r+"_"+o;
}
// ------------------------------------------------------------
obj.setAttribute("name", function(){ return this.getName(); } );
obj.setStyle("font-size","75%");
// ------------------------------------------------------------
// This Array contains the list of Options is the select dropdown list
// ------------------------------------------------------------
var _options = new Array();
// ------------------------------------------------------------
// Add the text value pair to the select dropdown list
// ------------------------------------------------------------
obj.addOption = function( text, value ) {
_options.push( new Array( value ? value : text, text) );
}
obj.clearOptions = function() {
_options = new Array();
}
obj.getOptions = function() {
return _options;
}
obj.setContent( "options", function() {
var optionsHTML = new Array();
var textVal = this.getItemProperty("text");
var foundMe = false;
for( i=0; i< _options.length; i++ ) {
var oTag = new Active.System.HTML();
var val = _options[i][0];
oTag.setTag("option");
oTag.setAttribute( "value", val );
oTag.setContent("text",_options[i][1]);
if ( val==textVal ) {
oTag.setAttribute( "selected","true" );
foundMe = true;
}
optionsHTML.push( oTag );
}
if (!foundMe) {
optionsHTML.push("<option value=\""+textVal+"\" selected=\"true\">"+textVal+"</option>");
}
return optionsHTML.join("");
});
obj.setEvent( "onchange", function(event) { this.onChange( event ); } );
obj.onChange = function( event ) {
var select = event.srcElement;
var optArray = select.options;
var index = select.selectedIndex;
var sOption = optArray[index];
var sVal = sOption.value ? sOption.value : sOption.innerHTML;
var name = select.name;
var row = this.getRowProperty("index");
var col = this.getColumnProperty("index");
var originalVal = this.getItemProperty("text");
if (sVal!=originalVal) {
this.onChangeAction( sVal, name, row, col );
}
}
obj.onChangeAction = function( newVal, name, row, col ) {
if (this.__debug) alert("Changed "+name+" ("+row+":"+col+") to "+newVal );
}
};
My.Templates.Select.create();
var grid = ...
var tmpl = new SDI.Templates.Select();
tmpl.addOption( "foo","true" );
tmpl.addOption( "bar","false" );
tmpl.__debug=true;
grid.setColumnTemplate( tmpl, 0 );
var tmpl = new My.Templates.Select();
obj.myList = new Array();
obj._optionsList = null;
obj.addOption = function( value, display ) {
if (!display) display = value;
var options = this._optionList;
if (!options) {
options = new Array();
this._optionsList = options;
}
options.push( new Array( value, display ) );
}
obj.setContent( "options", function() {
var i, optionList = this.getOptionList();
if (!optionList) optionList = new Array();
...
}
var obj = this.prototype;
var _super = this.superclass.prototype;
obj.init = function(){
// do your stuff
_super.init.call(this);
};
This topic is archived.