net/sf/jsm/widgets/+jsmSelectField.js
Summary
No overview generated for 'net/sf/jsm/widgets/+jsmSelectField.js'
function JsmSelectField(options, selectedValueOrLabel, multi, size) {
this.id=new Date().getTime() + "" + Math.random();
logger.info("Created JsmSelectField with id: " + this.id);
this.selected = selectedValueOrLabel;
this._options=jsm.noud(options)?new Array():options;
this._multi=jsm.noud(multi)?false:multi;
this._size=jsm.noud(size)?1:size;
this._delimiter=",";
}
JsmSelectField.extendClass(JsmWidget);
JsmSelectField.prototype.className="JsmSelectField";
JsmSelectField.prototype.toString = function() {
return "[JsmSelectField object]\n";
}
JsmSelectField.prototype.getSelected = function() {
return this.selected;
}
JsmSelectField.prototype.setSelected = function(selectedValueOrLabel) {
this.selected = selected;
return this;
}
JsmSelectField.prototype.setMulti = function(multi) {
this._multi = multi;
return this;
}
JsmSelectField.prototype.isMulti = function() {
return this._multi;
}
JsmSelectField.prototype.setSize = function(size) {
this._size = size;
return this;
}
JsmSelectField.prototype.getSize = function() {
return this._size;
}
JsmSelectField.prototype.getOptions = function() {
return this._options;
}
JsmSelectField.prototype.setOptions = function(options) {
this._options = options;
return this;
}
JsmSelectField.prototype.addOption = function(value, label) {
this._options.push({'value': value, 'label': label});
return this;
}
JsmSelectField.prototype.init = function(theTd) {
var value = theTd.getValue();
logger.debug("JsmSelectField: init(): " + theTd.getValue());
this.selected = theTd.getValue().split(this._delimiter);
return this;
}
JsmSelectField.prototype.updateModel = function(table, rowIdx, columnIdx, theViewComponent) {
if (jsm.noud(theViewComponent)) {return;}
if (!this.validate(table, rowIdx, columnIdx, theViewComponent)) {
return;
}
var currentLabel="";
var currentSelectedLabels=new Array();
var currentValue="";
if (this.isMulti()) currentValue="[";
var options = theViewComponent.options;
for (var i=0;i<options.length;i++) {
var option = options[i];
logger.trace("JsmSelectField: option: " + option + option.text + option.value);
if (option.selected) {
currentSelectedLabels.push(option.text);
currentLabel+=option.text + this._delimiter + " ";
if (this.isMulti()) {
currentValue+= "'" + option.value + "', ";
} else {
currentValue+= option.value;
}
}
}
currentLabel = currentLabel.substr(0, currentLabel.length-2);
if (this.isMulti() && currentValue.length>2) currentValue = currentValue.substr(0, currentValue.length-2);
if (this.isMulti()) currentValue+="]";
logger.debug("JsmSelectField: currentLabel: " + currentLabel);
logger.debug("JsmSelectField: currentValue: " + currentValue);
td = table.getTd(rowIdx, columnIdx);
if (!jsm.arrayOfSameValues(this.selected, currentSelectedLabels)) {
logger.debug("JsmSelectField: Set the td to dirty");
td.setDirty(true);
}
td.setValue(currentLabel);
td.setMetaData(this.META_DATA_NAME_VALUE, currentValue);
}
JsmSelectField.prototype.getNode = function() {
var selectField = document.createElement("select");
selectField.model=this;
selectField.setAttribute("id", this.id);
selectField.setAttribute("name", this.id);
if (this.isMulti()) {
selectField.multiple=true;
selectField.size=this.getSize();
}
this.addAttributesToViewComponent(selectField);
for (var optionIdx=0;optionIdx<this.getOptions().length;optionIdx++) {
var optionObject = document.createElement("option");
option = this.getOptions()[optionIdx];
optionObject.text = option.label;
optionObject.value = option.value;
selectField.options[selectField.length] = optionObject;
if (!jsm.noud(this.selected) && (jsm.arrayContains(this.selected, option.value) || jsm.arrayContains(this.selected, option.label))) {
logger.debug("JsmSelectField: Option is selected: " + option.label);
optionObject.selected = true;
jsmHangOntoSelectedWidgetNodes(optionObject);
}
}
return selectField;
}
JsmSelectField.prototype.clone = function() {
var clonedWidget = new JsmSelectField();
clonedWidget._attributes = this._attributes;
clonedWidget._metaData = this._metaData;
clonedWidget._options = this._options;
clonedWidget._multi = this._multi;
clonedWidget._size = this._size;
clonedWidget._delimiter = this._delimiter;
return clonedWidget;
}
Documentation generated by
JSDoc on Tue Sep 26 08:42:57 2006