ButtonBase.js
Summary
No overview generated for 'ButtonBase.js'
mapbuilder.loadScript(baseDir+"/util/Util.js");
mapbuilder.loadScript(baseDir+"/widget/WidgetBase.js");
function ButtonBase(widgetNode, model) {
WidgetBase.apply(this, new Array(widgetNode, model));
this.htmlTagId = this.getProperty("mb:buttonBar");
if (!this.htmlTagId) {
this.htmlTagId = this.getProperty("mb:htmlTagId");
}
if (!this.htmlTagId) {
alert(mbGetMessage("buttonBarRequired", widgetNode.nodeName));
}
if (config.widgetText) {
var textNodeXpath = "/mb:WidgetText/mb:widgets/mb:" + widgetNode.nodeName;
var textParams = config.widgetText.selectNodes(textNodeXpath+"/*");
for (var j=0;j<textParams.length;j++) {
this[textParams[j].nodeName]=getNodeValue(textParams[j]);
}
}
this.panelHtmlTagId = this.htmlTagId+'_panel';
loadCss('controlPanel.css');
this.buttonType = this.getProperty("mb:class")
this.buttonType = this.buttonType ? this.buttonType.toUpperCase() : null;
if (this.buttonType == "RADIOBUTTON") this.enabled = false;
this.olButtonType = {
"RADIOBUTTON" : OpenLayers.Control.TYPE_TOOL,
"TOOL" : OpenLayers.Control.TYPE_TOOL,
"BUTTON" : OpenLayers.Control.TYPE_BUTTON,
"TOGGLE" : OpenLayers.Control.TYPE_TOGGLE
}
this.action = this.getProperty("mb:action");
var tooltip = this.getProperty("mb:tooltip");
if (tooltip) {
this.tooltip = tooltip;
}
var disabledImage = this.getProperty("mb:disabledSrc");
if (disabledImage) {
this.disabledImage = config.skinDir + disabledImage;
}
var enabledImage = this.getProperty("mb:enabledSrc");
if (enabledImage) {
this.enabledImage = config.skinDir + enabledImage;
}
this.cursor = 'default';
this.cursor = this.getProperty("mb:cursor");
this.selected = Mapbuilder.parseBoolean(this.getProperty("mb:selected", false));
this.getButtonClass = function(objRef, state) {
var cssName;
if (objRef.control.displayClass) {
cssName = objRef.control.displayClass;
} else {
cssName = objRef.control.CLASS_NAME;
cssName = cssName.replace(/OpenLayers/, 'ol').replace(/\./g, '');
}
cssName += 'Item';
return '.' + cssName + state;
}
this.control = null;
this.doAction = function() {}
this.select = function() {
if (this.control.type == OpenLayers.Control.TYPE_BUTTON) {
this.control.trigger();
} else {
this.panel.activateControl(this.control);
}
}
this.doSelect = function(objRef, selected) {
}
this.attachToOL = function(objRef,refreshId) {
if (objRef.control) {
return;
}
if (refreshId && (refreshId!=objRef.id)) return;
if (!objRef.createControl) return;
var SubclassControl = objRef.createControl(objRef);
var type = objRef.olButtonType[objRef.buttonType] ||
SubclassControl.prototype.type;
var Control = OpenLayers.Class( SubclassControl, {
objRef: objRef,
type: type,
superclass: SubclassControl.prototype,
trigger: function() {
if(this.superclass.trigger) {
this.superclass.trigger.call(this);
}
objRef.doSelect(objRef, true);
},
activate: function() {
if (this.superclass.activate.call(this)) {
this.panel_div.style.backgroundImage = "url(\""+objRef.enabledImage+"\")";
this.map.div.style.cursor = objRef.cursor;
this.map.mbCursor = objRef.cursor;
objRef.enabled = true;
this.active = true;
objRef.doSelect(objRef, true);
}
},
deactivate: function() {
if (this.superclass.deactivate.call(this)) {
this.panel_div.style.backgroundImage = "url(\""+objRef.disabledImage+"\")";
objRef.enabled = false;
this.active = false;
if (map.getControlsBy("active", true).length == 0) {
this.map.div.style.cursor = "";
this.map.mbCursor = "";
}
objRef.doSelect(objRef, false)
}
},
destroy: function() {
try {
this.superclass.destroy.apply(this, arguments);
} catch(e) {
OpenLayers.Control.prototype.destroy.apply(this, arguments);
}
this.superclass = null;
OpenLayers.Event.stopObservingElement(this.panel_div);
this.objRef.panel.div.removeChild(this.panel_div);
this.objRef.control = null;
this.objRef = null;
this.panel_div = null;
this.div = null;
}
});
if (!objRef.control) {
objRef.control = objRef.instantiateControl ? objRef.instantiateControl(objRef, Control) : new Control();
}
var map = objRef.targetContext.map;
objRef.panel = objRef.targetContext.buttonBars[objRef.htmlTagId];
if (!objRef.panel || objRef.panel.map == null) {
if (!document.getElementById(objRef.panelHtmlTagId)) {
var olPanelNode = document.createElement('div');
olPanelNode.setAttribute('id', objRef.panelHtmlTagId);
olPanelNode.setAttribute('class', 'olControlPanel');
var parentNode = objRef.getNode();
parentNode.appendChild(olPanelNode);
parentNode.innerHTML += " ";
}
var Panel = OpenLayers.Class( OpenLayers.Control.Panel, {
div: document.getElementById(objRef.panelHtmlTagId),
defaultControl: null,
destroy: function() {
parentNode.removeChild(this.div);
OpenLayers.Control.prototype.destroy.apply(this, arguments);
this.div = null;
objRef.panel = null;
}
});
objRef.panel = new Panel();
objRef.targetContext.buttonBars[objRef.htmlTagId] = objRef.panel;
map.addControl(objRef.panel);
}
if (OpenLayers.Util.indexOf(objRef.control, objRef.panel.controls) == -1) {
var originalStop = OpenLayers.Event.stop;
OpenLayers.Event.stop = function(){};
objRef.panel.addControls(objRef.control);
OpenLayers.Event.stop = originalStop;
}
if (objRef.tooltip) {
objRef.control.panel_div.title=objRef.tooltip;
}
objRef.control.panel_div.style.backgroundImage = "url(\""+objRef.disabledImage+"\")";
if(objRef.selected == true) {
objRef.control.activate();
}
}
this.buttonInit = function(objRef) {
var targetContext = objRef.widgetNode.selectSingleNode("mb:targetContext");
if (targetContext) {
objRef.targetContext = window.config.objects[getNodeValue(targetContext)];
if ( !objRef.targetModel ) {
alert(mbGetMessage("noTargetContext", getNodeValue(targetContext), objRef.id));
}
} else {
objRef.targetContext = objRef.targetModel;
}
if (!objRef.targetContext.buttonBars) {
objRef.targetContext.buttonBars = new Array();
}
objRef.targetContext.addListener("refresh", objRef.attachToOL, objRef);
}
this.model.addListener("init",this.buttonInit,this);
this.model.removeListener("newNodel", this.clearWidget, this);
}
Documentation generated by
JSDoc on Sun Apr 27 20:30:54 2008