net/sf/jsm/widgets/jsmDoubleSelectField.js
Summary
No overview generated for 'net/sf/jsm/widgets/jsmDoubleSelectField.js'
function JsmDoubleSelectField(options, selectedValueOrLabel, size) {
this.id=new Date().getTime() + "" + Math.random();
logger.info("Created JsmDoubleSelectField with id: " + this.id);
this._multi=true;
this.selected = selectedValueOrLabel;
this._options=jsm.noud(options)?new Array():options;
this._size=jsm.noud(size)?1:size;
this._delimiter=",";
}
JsmDoubleSelectField.extendClass(JsmSelectField);
JsmDoubleSelectField.prototype.className="JsmDoubleSelectField";
JsmDoubleSelectField.prototype.toString = function() {
return "[JsmDoubleSelectField object]\n";
}
JsmDoubleSelectField.prototype.updateModel = function(table, rowIdx, columnIdx, theViewComponent) {
if (jsm.noud(theViewComponent)) {return;}
if (!this.validate(table, rowIdx, columnIdx, theViewComponent)) {
return;
}
var currentLabel=theViewComponent.innerHTML;
var currentValue=theViewComponent.selectFieldValue;
logger.debug("JsmDoubleSelectField: updateModel: currentLabel: " + currentLabel);
logger.debug("JsmDoubleSelectField: updateModel: currentValue: " + currentValue);
if (currentLabel == jsmTextClickToEdit) {
logger.debug("JsmDoubleSelectField: updateModel: Nothing is selectd - the anchor holds the default text");
var currentSelectedLabels = "".split(this._delimiter);
} else {
var currentSelectedLabels=theViewComponent.innerHTML.split(this._delimiter);
}
td = table.getTd(rowIdx, columnIdx);
if (!jsm.arrayOfSameValues(this.selected, currentSelectedLabels)) {
logger.debug("JsmDoubleSelectField: Set the td to dirty");
td.setDirty(true);
}
td.setValue(currentLabel == jsmTextClickToEdit?'':currentLabel);
td.setMetaData(this.META_DATA_NAME_VALUE, currentValue);
}
JsmDoubleSelectField.prototype.getNode = function() {
var anchor = document.createElement("a");
anchor.model = this;
this.setAttribute('onclick', "if (!e) e=window.event; this.model.showDiv(e.clientX, e.clientY);");
anchor.setAttribute("id", this.id);
anchor.setAttribute("name", this.id);
anchor.className='jsmHand';
var linkText = "";
for (var i=0;i<this.selected.length;i++) {
linkText+=this.selected[i];
if (i<this.selected.length-1) linkText+=this._delimiter + " ";
}
if (linkText.length == 0){linkText = jsmTextClickToEdit;}
var anchorText = document.createTextNode(linkText);
anchor.appendChild(anchorText);
this.addAttributesToViewComponent(anchor);
return anchor;
}
JsmDoubleSelectField.prototype.showDiv = function(x, y) {
this.selected = $(this.getId()).innerHTML.split(this._delimiter);
var theDiv = $('JsmDoubleSelectFieldDiv');
if (!jsm.noud(theDiv)) {
theDiv.parentNode.removeChild(theDiv);
}
var availableOptions = [];
var assignedOptions = [];
for (var idx in this.getOptions()) {
var option = this.getOptions()[idx];
if (jsm.arrayContains(this.selected, option.label) || jsm.arrayContains(this.selected, option.value)) {
assignedOptions.push(option);
} else {
availableOptions.push(option);
}
}
var divTable = new JsmTable("JsmDoubleSelectFieldDiv");
var tr2 = new JsmTr();
tr2.addCell(new JsmTd("<img src='" + jsmHideImage + "' border='0'></img>").setTitle('Close').setAttribute('colspan', '3').setAttribute('align', 'right').setAttribute('onclick', "var theAnchor = $('" + this.getId() + "'); var linkText = jsmGetLabels($('assignedOptions@" + this.getId() + "'), '" + this._delimiter + "'); theAnchor.innerHTML = linkText.length>0?linkText:jsmTextClickToEdit; theAnchor.selectFieldValue = jsmGetValues($('assignedOptions@" + this.getId() + "')); var theDiv = $('JsmDoubleSelectFieldDiv');theDiv.parentNode.removeChild(theDiv);"));
divTable.addRow(tr2);
var tr = new JsmTr();
tr.addCell(new JsmTd(new JsmSelectField(availableOptions, null, true, this.getSize()).setId('availableOptions@' + this.getId())).setAttribute("align", "center"));
tr.addCell(new JsmTd("<span onclick=\"jsmCopySelectedOptions($('availableOptions@" + this.getId() + "'), $('assignedOptions@" + this.getId() + "'));\">></span><br><span onclick=\"jsmCopySelectedOptions($('assignedOptions@" + this.getId() + "'), $('availableOptions@" + this.getId() + "'));\"><</span>").setTitle(' '));
tr.addCell(new JsmTd(new JsmSelectField(assignedOptions, null, true, this.getSize()).setId('assignedOptions@' + this.getId())).setAttribute("align", "center"));
divTable.addRow(tr);
var div = document.createElement("div");
div.setAttribute("id", 'JsmDoubleSelectFieldDiv');
div.appendChild(divTable.getNode());
div.style.zIndex="500";
div.style.backgroundColor="black";
div.style.padding = "2px"
div.style.position='absolute';
div.style.top= y + 'px';
div.style.left= x + 'px';
document.getElementsByTagName("body")[0].appendChild(div);
}
JsmDoubleSelectField.prototype.clone = function() {
var clonedWidget = new JsmDoubleSelectField();
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