/* License: LGPL as per: http://www.gnu.org/copyleft/lesser.html $Id$ */ /** * Base Class for widgets. Associates a node on the page with a stylesheet and * model. All widgets must extend this base class. * Defines the default paint() method for all widgets which is where the * stylesheet is applied to the model XML document. * To override widget.paint(), define it before calling this constructor. * The stylesheet URL defaults to "widget/.xsl" if it is not defined * in config file. Set a stylesheet property containing an XSL URL in config * to customize the stylesheet used. * All stylesheets will have "modelId" and "widgetId" parameters set when called. * * @constructor * @author Mike Adair * @param widget Pointer to the widget instance being created * @param widgetNode The widget's XML object node from the configuration document. * @param model The model object that this widget belongs to. */ function WidgetBase(widget,widgetNode,model) { widget.model = model; widget.widgetNode = widgetNode; /** Method used for painting. * xsl2html (default) => output of XSL will be HTML. * xsl2js => output of XSL will be javascript to execute. * image2html => where the model doc has content type image/* */ widget.paintMethod="xsl2html"; /** Widget's Id defined in the Config (required) */ if (widgetNode.attributes.getNamedItem("id")) { widget.id = widgetNode.attributes.getNamedItem("id").nodeValue; } else { alert("id required for object:" + widgetNode.nodeName ); } //allow the widget output to be replaced on each paint call var outputNode = widgetNode.selectSingleNode("mb:outputNodeId"); if ( outputNode ) { widget.outputNodeId = outputNode.firstChild.nodeValue; } else { widget.outputNodeId = "MbWidget_" + mbIds.getId(); } //until htmlTagNode becomes required allow setting of it by widget id if (!widget.htmlTagId) { var htmlTagNode = widgetNode.selectSingleNode("mb:htmlTagId"); if (htmlTagNode) { widget.htmlTagId = htmlTagNode.firstChild.nodeValue; } else { widget.htmlTagId = widget.id; } } // Node in main HTML to attach widget to. widget.node = document.getElementById(widget.htmlTagId); if(!widget.node) { //alert("htmlTagId: "+widget.htmlTagId+" for widget "+widgetNode.nodeName+" not found in config"); } //set an empty debug property in config to see inputs and outputs of stylehseet if ( widgetNode.selectSingleNode("mb:debug") ) widget.debug=true; /** Transient var used to store model XML before and then after XSL transform. * It can be modified by prePaint() . */ widget.resultDoc = null; // Set this.stylesheet // Defaults to "widget/.xsl" if not defined in config file. if ( !widget.stylesheet ) { var styleNode = widgetNode.selectSingleNode("mb:stylesheet"); if (styleNode ) { widget.stylesheet = new XslProcessor(styleNode.firstChild.nodeValue,model.namespace); } else { widget.stylesheet = new XslProcessor(baseDir+"/widget/"+widgetNode.nodeName+".xsl",model.namespace); } } /** * Initialize dynamic properties.set the target model * @param toolRef Pointer to this object. */ this.initTargetModel = function(objRef) { //set the target model var targetModel = objRef.widgetNode.selectSingleNode("mb:targetModel"); if (targetModel) { objRef.targetModel = eval("config.objects."+targetModel.firstChild.nodeValue); if ( !objRef.targetModel ) { alert("error finding targetModel:" + targetModel.firstChild.nodeValue + " for:" + objRef.id); } } else { objRef.targetModel = objRef.model; } objRef.stylesheet.setParameter("targetModelId", objRef.targetModel.id ); } // Set stylesheet parameters for all the child nodes from the config file for (var j=0;j