EditButtonBase.js
Summary
No overview generated for 'EditButtonBase.js'
mapbuilder.loadScript(baseDir+"/widget/ButtonBase.js");
function EditButtonBase(widgetNode, model) {
ButtonBase.apply(this, new Array(widgetNode, model));
this.cursor = "crosshair";
this.trm=this.getProperty("mb:transactionResponseModel");
this.defaultModelUrl=this.getProperty("mb:defaultModelUrl");
this.featureXpath=this.getProperty("mb:featureXpath");
this.appendOnEdit = Mapbuilder.parseBoolean(this.getProperty("mb:appendOnEdit", true));
this.createControl = function(objRef) {
return OpenLayers.Control.DrawFeature;
}
this.doSelect = function(objRef, selected) {
if (objRef.control.active) {
if (objRef.trm && !objRef.transactionResponseModel){
objRef.transactionResponseModel=window.config.objects[objRef.trm];
}
if(!selected && objRef.transactionResponseModel){
objRef.transactionResponseModel.setModel(objRef.transactionResponseModel,null);
}
config.loadModel(objRef.targetModel.id, objRef.defaultModelUrl);
}
}
this.newSession = function(objRef) {
objRef.modified = false;
}
this.handleFeatureInsert = function(feature) {
var objRef = feature.layer.mbButton;
objRef.feature = OpenLayers.Util.extend({}, feature);
objRef.geometry = OpenLayers.Util.extend({}, feature.geometry);
var previousFeatureNode = objRef.targetModel.doc.selectSingleNode("/*/*").cloneNode(true);
if (objRef.modified && objRef.appendOnEdit) {
objRef.targetModel.doc.selectSingleNode("/*").appendChild(previousFeatureNode);
}
objRef.setFeature(objRef);
objRef.modified = true;
feature.mbSelectStyle = null;
feature.destroy();
}
this.setEditingLayer = function(objRef) {
if (!objRef.targetContext.featureLayers[objRef.id]) {
objRef.featureLayer = new OpenLayers.Layer.Vector(objRef.id);
objRef.featureLayer.calculateInRange = function() {return true;};
objRef.featureLayer.mbButton = objRef;
objRef.targetContext.featureLayers[objRef.id] = objRef.featureLayer;
objRef.featureLayer.onFeatureInsert = objRef.handleFeatureInsert;
}
}
this.setFeature = function(objRef) {
if (!objRef.enabled) {
return;
}
var gml = new OpenLayers.Format.GML().write([objRef.feature]);
var gmlDoc = Sarissa.getDomDocument();
gmlDoc = (new DOMParser()).parseFromString(gml, "text/xml");
if (objRef.targetModel.namespace) {
Sarissa.setXpathNamespaces(gmlDoc, objRef.targetModel.namespace);
}
var insertPoint = objRef.featureXpath.lastIndexOf("/")+1;
var insertXpath = objRef.featureXpath.substring(insertPoint);
var insertNode = gmlDoc.selectSingleNode("//"+insertXpath);
if (!insertNode) {
insertNode = gmlDoc.selectSingleNode("//gml:featureMember/*/*");
}
var targetNode = objRef.targetModel.doc.selectSingleNode(objRef.featureXpath);
if (targetNode.childNodes.length > 0) {
targetNode.removeChild(targetNode.firstChild);
}
try {
Sarissa.copyChildNodes(insertNode, targetNode);
} catch(e) {
alert(mbGetMessage("invalidFeatureXpathEditLine", objRef.featureXpath));
}
objRef.targetModel.setParam("refresh");
}
this.initButton = function(objRef) {
if (!objRef.targetContext.featureLayers) {
objRef.targetContext.featureLayers = new Array();
}
objRef.targetContext.addFirstListener("refresh",objRef.setEditingLayer, objRef);
objRef.targetModel.addListener("loadModel", objRef.newSession, objRef);
}
this.model.addListener("init",this.initButton, this);
}
Documentation generated by
JSDoc on Sun Apr 27 20:30:54 2008