simpledefaultlist.lzx
<library>
<class name="simpledefaultlist" extends="list">
<method name="rollback">
if (this.changed) {
// Replace the data with our archived copy
// this will effectively reset our datapath
this.datapath.p.parentNode.replaceChild(
this.rollbackvalue,
this.datapath.p );
this.setAttribute('changed', false);
}
</method>
<attribute name="defaultitem" value="null
"/>
<attribute name="autoselectdefault" value="true
"/>
<handler name="ondata" args="d">
//Debug.write( "ondata event", d);
this.handleDataChange();
</handler>
<method name="handleDataChange">
this.rollbackvalue = this.datapath.p.cloneNode(true);
// Find the default node in the data
this.setAttribute("defaultitem", this.findDefault());
if (this.autoselectdefault) this.selectDefault();
this.setChanged(false);
</method>
<method name="findDefault">
//Debug.write("finding default", this.data);
if (this.datapath.p == null) return null;
if (!this.datapath.p.hasChildNodes()) return null;
var nodes = this.datapath.p.childNodes;
var curnode;
// search the data for default="true"
for (var i = 0; i < nodes.length; i++) {
curnode = nodes[i];
if (curnode.attributes["default"] == "true") {
//Debug.write("Found default! ", curnode);
return curnode;
}
}
// Didn't find it, return null
return null;
</method>
<method name="selectDefault">
this.selectByData(this.defaultitem)
</method>
<method name="selectByData" args="data">
var view;
if(data) {
view = this._selector.getItemByData(data);
select(view);
}
return view;
</method>
<method name="toXML">
if (this.datapath.p == null) return "undefined";
return this.datapath.serialize();
</method>
<method name="setDefault" args="item">
// Move this to selection manager???
this.setDefaultByData(item.data);
</method>
<method name="setDefaultByData" args="item">
if (item == this.defaultitem) return;
// Set the dataflags
if (this.defaultitem) {
this.defaultitem.removeAttr("default");
}
this.setAttribute("defaultitem", item);
//Debug.write("set default item to ", this.defaultitem);
if (this.defaultitem) {
this.defaultitem.setAttr("default", "true");
}
this.setAttribute("changed", true);
</method>
<method name="modify" args="node">
this.setAttribute("changed", true);
</method>
</class>
</library>