[Mapbender-commits] r1092 - trunk/mapbender/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Feb 8 09:39:05 EST 2007


Author: christoph
Date: 2007-02-08 09:39:05 -0500 (Thu, 08 Feb 2007)
New Revision: 1092

Modified:
   trunk/mapbender/http/javascripts/mod_digitize_tab.php
   trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php
Log:
* configuration in wfs_default.conf and digitize_default.conf
* datatype validation
* mandatory field validation


Modified: trunk/mapbender/http/javascripts/mod_digitize_tab.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_digitize_tab.php	2007-02-08 14:36:09 UTC (rev 1091)
+++ trunk/mapbender/http/javascripts/mod_digitize_tab.php	2007-02-08 14:39:05 UTC (rev 1092)
@@ -63,12 +63,12 @@
 
 var wfsWindow;	
 var dwin = null;
-var wfsConf = new Array();
+var wfsConf = [];
 var d = new parent.GeometryArray();
 var mod_digitize_width;
 var mod_digitize_height;
 var mod_digitizeEvent = false;
-var digi_hl;
+var nonTransactionalHighlight;
 
 var button_point = "Point";
 var button_line = "Line";
@@ -79,6 +79,8 @@
 var button_clear = "clear";
 var button_combine = "combine";
 
+const featureTypeElementFormId = "featureTypeElementForm";
+
 try {if(mod_digitize_elName){}}catch(e) {mod_digitize_elName = "digitize";}
 
 // ------------------------------------------------------------------------------------------------------------------------
@@ -125,16 +127,16 @@
 
 function mod_digitize_start(e){
 	// check if a proper geometry is selected	
-	if (d.getGeometry(-1,-1).complete == true || d.count() == 0){
+	if (d.getGeometry(-1,-1).complete || d.count() == 0){
 		
 		if (mod_digitizeEvent != false) {
-			alert("No geometry selected!");
+			alert(errorMessageNoGeometrySelected[selectedLanguage]);
 		}
 		return false;
 	}
 	
 	var realWorldPos;
-	if (s.isSnapped() == true) {
+	if (s.isSnapped()) {
 		realWorldPos = s.getSnappedPoint(d); 
 		s.clean();
 	}
@@ -162,7 +164,7 @@
 		
 		// add first point of polygon to snapping list (if three points have been inserted).
 		else if (d.get(-1).geomtype == parent.geomTypePolygon && d.getGeometry(-1,-1).count() == 3) {
-			s.add(d, 0, -1, -1)
+			s.add(d, 0, -1, -1);
 		}
 
 		// add last point of line to snapping list (if at least two points have been inserted).
@@ -170,7 +172,7 @@
 			if (mod_digitizeEvent != button_move) {
 				s.store(d);
 			}
-			s.add(d, -1, -1, -1)
+			s.add(d, -1, -1, -1);
 		}
 	}
 	executeDigitizeSubFunctions();
@@ -189,7 +191,7 @@
 var basepointDragActive = false;
 
 function handleBasepoint(obj,memberIndex,geometryIndex,pointIndex){
-	if(!(mod_digitizeEvent == button_move || mod_digitizeEvent == button_insert || mod_digitizeEvent == button_delete)){ return false; };
+	if(!(mod_digitizeEvent == button_move || mod_digitizeEvent == button_insert || mod_digitizeEvent == button_delete)){ return false; }
 	
 	basepointObject = obj;
 	basepointMemberIndex = memberIndex;
@@ -210,7 +212,7 @@
 }
 
 function convertLinepointToBasepoint(obj, memberIndex, geomIndex, pointIndex){
-	if(!(mod_digitizeEvent == button_insert)){ return false; };
+	if(!(mod_digitizeEvent == button_insert)){ return false; }
 	
 	if(mod_digitizeEvent == button_insert){
 		mod_digitize_timeout();
@@ -238,7 +240,7 @@
 }
 
 function deleteBasepoint(){
-	var i = basepointMemberIndex
+	var i = basepointMemberIndex;
 	var j = basepointGeometryIndex;
 	var k = basepointPointIndex;
 	d.delAllPointsLike(d.getPoint(i,j,k));
@@ -247,7 +249,7 @@
 }
 
 function selectBasepoint(e){
-	if(basepointDragActive == false && mod_digitizeEvent == button_move){
+	if(!basepointDragActive && mod_digitizeEvent == button_move){
 		basepointDragActive = true;
 		s.store(d, d.getPoint(basepointMemberIndex, basepointGeometryIndex, basepointPointIndex));
 		basepointObject.onmouseup = releaseBasepoint;
@@ -269,7 +271,7 @@
 			
 		if (parent.ie) {
 			// ie cannot handle backgroundColor = 'transparent'
-			basepointObject.style.background = "url(../img/button_digitize/trans.png)";
+			basepointObject.style.background = "url(../img/transparent.gif)";
 		}
 		else{
 			basepointObject.style.backgroundColor = 'transparent';
@@ -299,9 +301,9 @@
 	var p = parent.makeClickPos2RealWorldPos(mod_digitize_target, basepointDragEnd.x, basepointDragEnd.y);
 
 	var oldPoint = parent.cloneObject(d.getPoint(i,j,k));
-	if (s.isSnapped() == true) {
+	if (s.isSnapped()) {
 		var snappedPoint = parent.cloneObject(s.getSnappedPoint(d));
-		if (nonTransactionalEditable == false) {
+		if (!nonTransactionalEditable) {
 			updateAllPointsOfNonTransactionalLike(oldPoint, snappedPoint);
 		}
 		else {
@@ -311,7 +313,7 @@
 	}
 	else {
 		var newPoint = new parent.Point(p[0],p[1]);
-		if (nonTransactionalEditable == false) {
+		if (!nonTransactionalEditable) {
 			updateAllPointsOfNonTransactionalLike(oldPoint, newPoint);
 		}
 		else {
@@ -351,29 +353,33 @@
 }
 
 function registerFunctions(){
-	mod_digitizePreFunctions = new Array();
-	mod_digitizeSubFunctions = new Array();
+	mod_digitizePreFunctions = [];
+	mod_digitizeSubFunctions = [];
 	registerDigitizePreFunctions("updateExtent()");
 	registerDigitizePreFunctions("drawDashedLine()");
 	registerDigitizeSubFunctions("updateListOfGeometries()");
 	registerDigitizeSubFunctions("drawDashedLine()");
+	registerDigitizeSubFunctions("updateMeasureTag()");
 	parent.mb_registerInitFunctions("window.frames['"+ mod_digitize_elName + "'].setStyleForTargetFrame()");
 	parent.mb_registerInitFunctions("window.frames['"+ mod_digitize_elName + "'].checkDigitizeTag()");
 	parent.mb_registerInitFunctions("window.frames['"+ mod_digitize_elName + "'].initialiseSnapping()");
-	parent.mb_registerInitFunctions("window.frames['"+ mod_digitize_elName + "'].initialiseHighlight()");
+	if (!nonTransactionalEditable) {
+		parent.mb_registerInitFunctions("window.frames['"+ mod_digitize_elName + "'].initialiseHighlight()");
+	}
+	parent.mb_registerInitFunctions("window.frames['"+ mod_digitize_elName + "'].initialiseMeasure()");
 	parent.mb_registerSubFunctions("window.frames['" + mod_digitize_elName + "'].updateExtent()");
 	parent.mb_registerSubFunctions("window.frames['"+ mod_digitize_elName + "'].drawDashedLine()");
-	parent.mb_registerWfsReadSubFunctions(function(geom){parent.tab_open(mod_digitize_elName);parent.window.frames[mod_digitize_elName].appendGeometryArray(geom)});
-	parent.mb_registerWfsWriteSubFunctions(function(){parent.zoom(mod_digitize_target, true, 0.999)});
+	parent.mb_registerWfsReadSubFunctions(function(geom){parent.tab_open(mod_digitize_elName);parent.window.frames[mod_digitize_elName].appendGeometryArray(geom);});
+	parent.mb_registerWfsWriteSubFunctions(function(){parent.zoom(mod_digitize_target, true, 0.999);});
 }
 
 function checkDigitizeTag(){
-	var attributes = new Array();
-	attributes[0] = new Array();
+	var attributes = [];
+	attributes[0] = [];
 	attributes[0][0] = "style";
-	attributes[0][1] = "position:absolute; top:0px; left:0px; z-index:26; font-size:10px"; 
+	attributes[0][1] = "position:absolute; top:0px; left:0px; z-index:"+digitizeTransactionalZIndex+"; font-size:10px"; 
 	node = parent.mb_checkTag(mod_digitize_target, "div", "digitize", "body", attributes);
-	if (node == false) {
+	if (!node) {
 		alert("Fatal error: Element id 'digitize' is already taken!");
 	}
 	parent.mb_registerPanSubElement("digitize");
@@ -389,14 +395,33 @@
 }
 
 function initialiseSnapping(){
-	s = new parent.Snapping(mod_digitize_target, snappingTolerance, snappingColor, true);
+	s = new parent.Snapping(mod_digitize_target, snappingTolerance, snappingColor, snappingHighlightZIndex);
 }
 function initialiseHighlight(){
-	digi_hl = new parent.Highlight(new Array(mod_digitize_target), "digi_hl");
+	nonTransactionalHighlight = new parent.Highlight(new Array(mod_digitize_target), "nonTransactional", "position:absolute; top:0px; left:0px; z-index:"+digitizeNonTransactionalZIndex, nonTransactionalLineWidth);
 }
+function initialiseMeasure(){
+	measureDivTag = new parent.DivTag(measureTagName, measureTagTarget, measureTagStyle);
+}
 // --- registered functions (end) -----------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------------------------------------------
 
+
+function updateMeasureTag () {
+	if (d.count() > 0 ) {
+		if (d.get(-1).count() > 0) {
+			if (d.getGeometry(-1, -1).count() > 0) {
+				measureDivTag.write(measureTagLabelCurrent[selectedLanguage] + d.getGeometry(-1, -1).getCurrentDist(measureNumberOfDigits) + "<br>" +measureTagLabelTotal[selectedLanguage] + d.getGeometry(-1, -1).getTotalDist(measureNumberOfDigits));
+			}
+			else {
+				measureDivTag.clean();
+			}
+		}
+	}
+}
+
+
+
 // ------------------------------------------------------------------------------------------------------------------------
 // --- button handling (begin) --------------------------------------------------------------------------------------------
 
@@ -437,7 +462,7 @@
 	else if (obj.id == button_point || obj.id == button_line || obj.id == button_polygon || obj.id == button_clear || obj.id == button_combine){
 		mod_digitizeEvent = obj.id;
 		executeDigitizePreFunctions();
-		obj.title = obj.title_off;
+		obj.title = obj.title_on;
 		if (obj.id == button_point) {
 			d.addMember(parent.geomTypePoint);
 			d.get(-1).addGeometry();
@@ -451,8 +476,8 @@
 			d.get(-1).addGeometry();
 		}
 		else if (obj.id == button_clear) {
-			var clear = confirm('clear list of geometries?');
-			if (clear == true) {
+			var clear = confirm(messageConfirmDeleteAllGeomFromList[selectedLanguage]);
+			if (clear) {
 				d = new parent.GeometryArray();
 				parent.mb_disableThisButton(button_clear);
 			}
@@ -465,7 +490,7 @@
 //			});
 			parent.mb_disableThisButton(button_combine);
 		}
-		if (mod_digitizeEvent == button_point || mod_digitizeEvent == button_line || mod_digitizeEvent == button_polygon || mod_digitizeEvent == button_insert ) s.store(d);
+		if (mod_digitizeEvent == button_point || mod_digitizeEvent == button_line || mod_digitizeEvent == button_polygon || mod_digitizeEvent == button_insert ) {s.store(d);}
 		var el = parent.frames[mod_digitize_target].document;
 		el.onmousemove = mod_digitize_go;
 	}
@@ -473,7 +498,7 @@
 
 function digitizeDisable(obj) {
 	if (obj.id == button_point || obj.id == button_line || obj.id == button_polygon){
-		obj.title = obj.title_on;
+		obj.title = obj.title_off;
 		d.close();
 		mod_digitize_timeout();
 		executeDigitizeSubFunctions();
@@ -496,7 +521,9 @@
 }
 
 function drawDashedLine(){
-	digi_hl.clean();
+	if (!nonTransactionalEditable) {
+		nonTransactionalHighlight.clean();
+	}
 	var smP = "";
 	smP += "<div class='t_img'>";
 	smP += "<img src='"+parent.mb_trans.src+"' width='"+mod_digitize_width+"' height='0'></div>";
@@ -504,8 +531,8 @@
 	smP += "<img src='"+parent.mb_trans.src+"' width='0' height='"+mod_digitize_height+"'></div>";
 
 	for(var i=0; i<d.count(); i++){
-		if (nonTransactionalEditable == false && !isTransactional(d.get(i))) {
-			digi_hl.add(d.get(i), nonTransactionalColor);
+		if (!nonTransactionalEditable && !isTransactional(d.get(i))) {
+			nonTransactionalHighlight.add(d.get(i), nonTransactionalColor);
 		}
 		else {
 			for(var j=0; j<d.get(i).count(); j++){
@@ -514,12 +541,12 @@
 					
 					if (!d.getGeometry(i,j).isComplete() && 
 						( (k == 0 && d.get(i).geomtype == parent.geomTypePolygon) || (k == d.getGeometry(i,j).count()-1 && d.get(i).geomtype == parent.geomTypeLine))) {
-						smP += "<div class='bp' style='top:"+(pos[1]-2)+"px;left:"+(pos[0]-2)+"px;z-index:50;background-color:"+linepointColor+"'";
+						smP += "<div class='bp' style='top:"+(pos[1]-2)+"px;left:"+(pos[0]-2)+"px;z-index:"+digitizeTransactionalZIndex+";background-color:"+linepointColor+"'";
 					}
 					else {
-						smP += "<div class='bp' style='top:"+(pos[1]-2)+"px;left:"+(pos[0]-2)+"px;z-index:50;'";
+						smP += "<div class='bp' style='top:"+(pos[1]-2)+"px;left:"+(pos[0]-2)+"px;z-index:"+digitizeTransactionalZIndex+";'";
 					}
-					if(j==0 && d.get(i).geomtype == parent.geomTypePolygon && d.getGeometry(i,j).complete == false){
+					if(j==0 && d.get(i).geomtype == parent.geomTypePolygon && !d.getGeometry(i,j).complete){
 						smP += " title='"+closePolygon_title+"' ";
 					}
 					if(mod_digitizeEvent == button_move || mod_digitizeEvent == button_insert || mod_digitizeEvent == button_delete) {
@@ -554,10 +581,10 @@
 		var y = Math.round(start.y + i * step.y) - 2;
 		if(x >= 0 && x <= mod_digitize_width && y >= 0 && y <= mod_digitize_height){
 			if (memberIndex == d.count()-1 && !d.getGeometry(-1,-1).isComplete()) {
-				str_dashedLine += "<div class='lp' style='top:"+y+"px;left:"+x+"px;z-index:50;background-color:"+linepointColor+"' ";
+				str_dashedLine += "<div class='lp' style='top:"+y+"px;left:"+x+"px;z-index:"+digitizeTransactionalZIndex+";background-color:"+linepointColor+"' ";
 			}
 			else {
-				str_dashedLine += "<div class='lp' style='top:"+y+"px;left:"+x+"px;z-index:50;' ";
+				str_dashedLine += "<div class='lp' style='top:"+y+"px;left:"+x+"px;z-index:"+digitizeTransactionalZIndex+";' ";
 			}
 			if(mod_digitizeEvent == button_insert) {
 				str_dashedLine += "onmouseover='parent.window.frames[\""+mod_digitize_elName+"\"].convertLinepointToBasepoint(this,"+memberIndex+","+geomIndex+","+pointIndex+")'";
@@ -571,17 +598,23 @@
 function isTransactional(geom) {
 //	alert(typeof(geom.wfs_conf) + " " + geom.wfs_conf + " " + wfsConf.length);
 	if (typeof(geom.wfs_conf) == 'number') {
-		if (geom.wfs_conf >= 0 && geom.wfs_conf < wfsConf.length) {
-			if (!(wfsConf[geom.wfs_conf]['wfs_transaction'] == "" && wfsConf[geom.wfs_conf]['fkey_featuretype_id'] == "")) {
+		if (geom.wfs_conf >= 0 && geom.wfs_conf < wfsConf.length) {			
+			var isTransactionalGeom = (wfsConf[geom.wfs_conf]['wfs_transaction'] != "" && wfsConf[geom.wfs_conf]['fkey_featuretype_id'] != "");
+			if (isTransactionalGeom) {
 				return true;
 			}
+			else{
+				return false;
+			}
 		}
 	}
-	return false;
+	else if (typeof(geom.wfs_conf) == 'undefined') {
+		return true;
+	}
 }
 
 function isValidWfsConfIndex (wfsConf, wfsConfIndex) {
-	return typeof(wfsConfIndex) == "number" && wfsConfIndex >=0 && wfsConfIndex < wfsConf.length
+	return (typeof(wfsConfIndex) == "number" && wfsConfIndex >=0 && wfsConfIndex < wfsConf.length);
 }
 
 function getName (geom) {
@@ -600,7 +633,7 @@
 		return resultName;
 	}
 	else {
-		return "new";
+		return digitizeDefaultGeometryName[selectedLanguage];
 	}
 }
 
@@ -610,7 +643,7 @@
 		wfsConf = parent.get_complete_wfs_conf();
 		for (var i = 0 ; i < d.count(); i ++) {
 
-			if (!(nonTransactionalEditable == false && !isTransactional(d.get(i)))) {
+			if (nonTransactionalEditable || isTransactional(d.get(i))) {
 	
 				listOfGeom += "\t<tr>\n\t\t<td>\n";
 				listOfGeom += "\t\t\t<img src = '"+buttonDig_imgdir+buttonDig_wfs_src+"' title='"+buttonDig_wfs_title+"' onclick='showWfs("+i+")'>\n";
@@ -619,7 +652,7 @@
 				listOfGeom += "\t\t</td>\n\t\t<td>\n";
 	
 				if (isValidWfsConfIndex(wfsConf, d.get(i).wfs_conf)) {
-					listOfGeom += "\t\t\t<img src = '"+buttonDig_imgdir+buttonDig_removeDb_src+"' title='"+buttonDig_removeDb_title+"' onclick=\"var deltrans = confirm('Delete geometry from database?');if (deltrans) dbGeom('delete', "+i+")\">\n";
+					listOfGeom += "\t\t\t<img src = '"+buttonDig_imgdir+buttonDig_removeDb_src+"' title='"+buttonDig_removeDb_title+"' onclick=\"var deltrans = confirm('"+messageConfirmDeleteGeomFromDb[selectedLanguage]+"');if (deltrans) dbGeom('delete', "+i+")\">\n";
 				}
 				listOfGeom += "\t\t</td>\n\t\t<td style = 'color:blue;font-size:12px'>\n";
 				listOfGeom += "\t\t\t<div onmouseover='parent.mb_wfs_perform(\"over\",d.get("+i+"));' ";
@@ -644,137 +677,136 @@
 // -----------------------------------------------------------------------------------------------------------
 // --- wfs window (begin) -----------------------------------------------------------------------------------------
 
-// returns a form with the elements of a selected wfs
-// (if the original wfs is the selected wfs, the values are set too)
-function buildElementForm(wfsConfIndex, memberIndex){
-	var selMember = memberIndex;
-	
-	if (parseInt(d.get(memberIndex).wfs_conf) != parseInt(wfsConfIndex)) {memberIndex=-1;}
-	var str = "";
-	var hasGeometryColumn = false;
-	var wfs = wfsConf[wfsConfIndex];
-	var memberElements;
-	var fid = false;
+// -----------------------------------------------------------------------------------------------------------
+// --- wfs window form check (begin) -----------------------------------------------------------------------------------------
 
-	if (parseInt(memberIndex) != -1) {
-		memberElements = d.get(memberIndex).e;
-		fid = memberElements.getElementValueByName('fid');
-	}
+function formCorrect(doc, formId) {
+	var isCorrect = true;
+	var errorMessage = "";
+	var result;
+	var form = doc.getElementById(formId);
 	
-	// search attribute 'element' in wfsConfArray
-	for (attr in wfs) {
-		if (attr == "element") {
-			str += "<form id='wfs_conf'>\n\t<table>\n";
-			b = wfs[attr];
-			
-			for (var i = 0 ; i < b.length ; i ++) {
-				var c = b[i];
-				var elementLabel = c['element_name'];
-				var elementName = c['element_name'];
-				if (c['f_label'] != "") {
-					elementLabel = c['f_label']; 
-				}
-				
-//				if (parseInt(c['f_geom']) != 1 && parseInt(c['f_edit']) == 1) {
-				var isGeomColumn = (parseInt(c['f_geom']) == 1); 
-				if (!isGeomColumn) {
-					str += "\t\t<tr>\n";
-					str += "\t\t\t<td>\n\t\t\t\t<div class = '"+c['f_label_id']+"''>" + elementLabel + "</div>\n\t\t\t</td>\n";
-					str += "\t\t\t<td colspan = 2>\n";
+	result = mandatoryFieldsNotEmpty(doc, form);
+	isCorrect = isCorrect && result.isCorrect;
+	errorMessage += result.errorMessage;
 
-					var elementValue = "";
-					if (parseInt(memberIndex) != -1) {
-						for (var j = 0 ; j < memberElements.count() ; j ++) {
-							if (memberElements.getName(j) == c['element_name']) {
-								elementValue = memberElements.getValue(j);
-							}
-						}
-					}
-					if (c['f_form_element_html'] == "") {
-						str += "\t\t\t\t<input id = '" + elementName + "' name='" + elementName + "' type='text' class = '"+c['f_style_id']+"' size=20 value = '" + elementValue + "'>\n";
-					}
-					else {
-						var formElementHtml = c['f_form_element_html'];
-						while (formElementHtml.match(/\\/)) {
-							formElementHtml = formElementHtml.replace(/\\/, "");
-						} 
-//alert(formElementHtml);
-						// preselect the correct entry of the box
-						var patternString = "option value='"+elementValue+"'";
-						var pattern = new RegExp(patternString);
-						formElementHtml = formElementHtml.replace(pattern, patternString+" selected");
-//alert(formElementHtml);
-						str += formElementHtml;
+	result = validBoxEntrySelected(form);
+	isCorrect = isCorrect && result.isCorrect;
+	errorMessage += result.errorMessage;
 
-					}
-					str += "\t\t\t</td>\n";
-					str += "\t\t</tr>\n";
-				}
-				else {
-					hasGeometryColumn = true;
-				}
+	result = dataTypeIsCorrect(doc, form);
+	isCorrect = isCorrect && result.isCorrect;
+	errorMessage += result.errorMessage;
+
+	return {"isCorrect":isCorrect, "errorMessage":errorMessage};
+}
+
+function validBoxEntrySelected(form){
+	var isCorrect = true;
+	var errorMessage = "";
+	for (var i = 0; i < form.childNodes.length && isCorrect; i++) {
+		if (form.childNodes[i].nodeName.toUpperCase() == "SELECT") {
+			if (parseInt(form.childNodes[i].selectedIndex) == 0) {
+				return {"isCorrect":false, "errorMessage":errorMessage};
 			}
+		}
+		else if (form.childNodes[i].hasChildNodes()) {
+			isCorrect = validBoxEntrySelected(form.childNodes[i]).isCorrect;
+		}
+	}
+	if (!isCorrect) {
+		errorMessage = messageSelectAnOption[selectedLanguage] + "\n";
+	}
+	return {"isCorrect":isCorrect, "errorMessage":errorMessage};
+}
 
-			if (wfs['wfs_transaction']) {
-				var colspan = 0;
-				str += "\t\t<tr>\n";
-				if (hasGeometryColumn) {
-					str += "\t\t\t<td><input type='button' name='saveButton' value='Save' onclick=\"if (window.opener.formCorrect(document.getElementById('wfs_conf'))){window.opener.dbGeom('save', "+selMember+")}else{alert('Bitte treffen Sie eine Auswahl.');};\" /></td>\n";
+function mandatoryFieldsNotEmpty(doc, node){
+	var isCorrect = true;
+	var errorMessage = "";
+	
+	nodeArray = doc.getElementsByName("mandatory");
+	for (var i = 0; i < nodeArray.length && isCorrect; i++) {
+		if (nodeArray[i].nodeName.toUpperCase() == "INPUT" && nodeArray[i].type == "hidden" && nodeArray[i].id.substr(0,10) == "mandatory_") {
+			var nodeId = nodeArray[i].id.substr(10);
+			if (nodeArray[i].value == "true") {
+				if (doc.getElementById(nodeId).value == "") {
+					isCorrect = false;
+					errorMessage += "'"+ doc.getElementById(nodeId).name +"': "+ messageErrorFieldIsEmpty[selectedLanguage] +"\n";
 				}
-				else colspan++;
-				if (parseInt(memberIndex) != -1 && fid) {
-					if (hasGeometryColumn) {
-						str += "\t\t\t<td><input type='button' name='updateButton' value='Update' onclick=\"if (window.opener.formCorrect(document.getElementById('wfs_conf'))){window.opener.dbGeom('update', "+selMember+")}else{alert('Bitte treffen Sie eine Auswahl.');};\"/></td>\n";
-					}
-					else colspan++;
-//					str += "\t\t\t<td><input type='button' name='deleteButton' value='Delete' onclick=\"if (window.opener.formCorrect(document.getElementById('wfs_conf'))){window.opener.dbGeom('delete', "+selMember+")}else{alert('Bitte treffen Sie eine Auswahl.');};\"/></td>\n";
-				}
-				else colspan++;
-				
-				if (colspan > 0 && colspan < 3) {
-					str += "\t\t\t<td colspan = " + colspan + "></td>\n";
-				}
-				str += "\t\t</tr>";
 			}
-			str += "\t</table>\n";
-				str += "<input type='hidden' name='fid' value='"+fid+"'>";
-//				str += "<input type='text' name='mb_wfs_conf'>";
-			str += "</form>\n";
 		}
 	}
-	return str;
+	return {"isCorrect":isCorrect, "errorMessage":errorMessage};
 }
 
+function isInteger(str) {
+	if (str.match(/^\d+$/)) {
+		return true;
+	}
+	return false;
+}
 
-function formCorrect(form) {
-	isCorrect = true;
-	isCorrect = isCorrect && validBoxEntrySelected(form);
-	return isCorrect;
+function isFloat(str) {
+	if (isInteger(str)) {
+		return true;
+	}
+	if (str.match(/^\d+\.\d+$/)) {
+		return true;
+	}
+	return false;
 }
 
-function validBoxEntrySelected(form){
+function replaceCommaByDecimalPoint(str) {
+	var patternString = ",";
+	var pattern = new RegExp(patternString);
+	while (str.match(pattern)) {
+		str = str.replace(pattern, ".");
+	}
+	return str;
+}
+
+function dataTypeIsCorrect(doc, node){
 	var isCorrect = true;
-	for (var i = 0; i < form.childNodes.length && isCorrect == true; i++) {
-		if (form.childNodes[i].nodeName.toUpperCase() == "SELECT") {
-			if (parseInt(form.childNodes[i].selectedIndex) == 0) {
-				return false;
+	var errorMessage = "";
+	
+	nodeArray = doc.getElementsByName("datatype");
+	for (var i = 0; i < nodeArray.length ; i++) {
+		if (nodeArray[i].nodeName.toUpperCase() == "INPUT" && nodeArray[i].type == "hidden" && nodeArray[i].id.substr(0,9) == "datatype_") {
+			var nodeId = nodeArray[i].id.substr(9);
+			var nodeValue = doc.getElementById(nodeId).value;
+			
+			if (nodeArray[i].value == "int") {
+				if (!isInteger(nodeValue)) {
+					isCorrect = false;
+					errorMessage += "'"+doc.getElementById(nodeId).name+"': "+ messageErrorNotAnInteger[selectedLanguage] + "\n";
+				}
 			}
+			else if (nodeArray[i].value == "double") {
+				nodeValue = replaceCommaByDecimalPoint(nodeValue);
+				if (!isFloat(nodeValue)) {
+					isCorrect = false;
+					errorMessage += "'"+doc.getElementById(nodeId).name+"': "+ messageErrorNotAFloat[selectedLanguage] + "\n";
+				}
+				else {
+					doc.getElementById(nodeId).value = nodeValue;
+				}
+			}
 		}
-		else if (form.childNodes[i].hasChildNodes()) {
-			isCorrect = validBoxEntrySelected(form.childNodes[i]);
-		}
 	}
-	return isCorrect;
+	return {"isCorrect":isCorrect, "errorMessage":errorMessage};
 }
+// --- wfs window form check (end) -----------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------------------------------------
 
 
+
 //
 // this method opens a new window and displays the attributes in wfs_conf
 //
 function showWfs(geometryIndex) {
 	wfsConf = parent.get_complete_wfs_conf();
 
-	wfsWindow = open("", "wfsattributes", "width=400, height=300, resizable, dependent=yes, scrollbars=yes");
+	wfsWindow = open("", "wfsattributes", "width="+wfsWindowWidth+", height="+wfsWindowHeight+", resizable, dependent=yes, scrollbars=yes");
 	wfsWindow.document.open("text/html");
 
 	var str = "";
@@ -782,11 +814,24 @@
 	var defaultIndex = -1;
 
 	str += "<form id='wfs'>\n";
+
+	//
+	// 1. add select box 
+	//
+
+	var onChangeText = "document.getElementById('elementForm').innerHTML = ";
+	onChangeText += "window.opener.buildElementForm(this.value , " + geometryIndex + ");";
+	onChangeText += "window.opener.setWfsWindowStyle(this.value);";
+	
 	str += "\t<select name='wfs' size='" + wfsConf.length + "'";
-	str += " onChange='document.getElementById(\"elementForm\").innerHTML = window.opener.buildElementForm(this.value , " + geometryIndex + ")'";
+	str += " onChange=\"alert(this.value);"+ onChangeText +"\"";
 	str += ">\n\t\t";
 
 	for (var attr in wfsConf) {
+		var isTrans = (wfsConf[attr]['wfs_transaction'] != "");
+		if (!isTrans) {
+			continue;
+		}
 		if (isValidWfsConfIndex(wfsConf, parseInt(d.get(geometryIndex).wfs_conf))) {
 			
 			if (parseInt(d.get(geometryIndex).wfs_conf) == parseInt(attr)) {
@@ -820,26 +865,13 @@
 					}
 				}
 			}
-		}
+		}	
 	}
+
 	
-	
 	str += "</select>\n\t\t</form>\n\t";
 	str += "<div id='elementForm'>\n</div>";
 	
-
-/*
-	// add css link from element var 'wfsCssUrl'
-	if (wfsCssUrl != "") {
-		var cssLink = wfsWindow.document.createElement("link");
-		cssLink.setAttribute("href", wfsCssUrl); 
-		cssLink.setAttribute("type", "text/css"); 
-		cssLink.setAttribute("rel", "stylesheet"); 
-		var cssTmp = wfsWindow.document.getElementsByTagName("head")[0];
-		cssTmp.appendChild(cssLink);
-	}
-*/
-
 	if (defaultIndex != -1) {
 		wfsWindow.document.writeln("<html><head><style type='text/css'>"+wfsConf[defaultIndex]['g_style']+"</style></head><body></body></html>");
 		wfsWindow.document.write(str);
@@ -853,9 +885,129 @@
 	}
 }
 
+function setWfsWindowStyle(wfsConfIndex) {
+	wfsWindow.document.getElementsByTagName("style")[0].innerHTML = wfsConf[wfsConfIndex]['g_style'];
+}
 
-function mod_saveGeom() {
-	dwin = window.open("../php/mod_wfs_save.php","dwin","width=300,height=200");
+// returns a form with the elements of a selected wfs
+// (if the original wfs is the selected wfs, the values are set too)
+function buildElementForm(wfsConfIndex, memberIndex){
+	var featureTypeMismatch = false;
+	if (parseInt(d.get(memberIndex).wfs_conf) != parseInt(wfsConfIndex)) {featureTypeMismatch = true;}
+	var str = "";
+	var hasGeometryColumn = false;
+	var featureTypeArray = wfsConf[wfsConfIndex];
+	var memberElements;
+	var fid = false;
+
+	if (!featureTypeMismatch) {
+		memberElements = d.get(memberIndex).e;
+		fid = memberElements.getElementValueByName('fid');
+	}
+	
+	if (typeof(featureTypeArray["element"]) !== "undefined") {
+
+		str += "<form id='"+featureTypeElementFormId+"'>\n\t<table>\n";
+		featureTypeElementArray = featureTypeArray["element"];
+		
+		//
+		// 2. add rows to form 
+		//
+		for (var i = 0 ; i < featureTypeElementArray.length ; i ++) {
+			var featureTypeElement = featureTypeElementArray[i];
+
+			var elementName = featureTypeElement['element_name'];
+			var elementType = featureTypeElement['element_type'];
+			var isEditable = (parseInt(featureTypeElement['f_edit']) == 1); 
+			var isMandatory = (parseInt(featureTypeElement['f_mandatory']) == 1); 
+			var isGeomColumn = (parseInt(featureTypeElement['f_geom']) == 1); 
+
+			var elementLabelExists = (featureTypeElement['f_label'] != "");
+			var elementLabel = ""; 
+			if (elementLabelExists) {
+				elementLabel = featureTypeElement['f_label'];
+			}
+			var elementLabelStyle = featureTypeElement['f_label_id'];
+
+			if (!isGeomColumn) {
+				if (isEditable) {
+					str += "\t\t<tr>\n";
+					str += "\t\t\t<td>\n\t\t\t\t<div class = '"+elementLabelStyle+"''>" + elementLabel + "</div>\n\t\t\t</td>\n";
+					str += "\t\t\t<td>\n";
+
+					var elementValue = "";
+					if (!featureTypeMismatch) {
+						for (var j = 0 ; j < memberElements.count() ; j ++) {
+							if (memberElements.getName(j) == featureTypeElement['element_name']) {
+								elementValue = memberElements.getValue(j);
+							}
+						}
+					}
+					var formElementHtml = featureTypeElement['f_form_element_html']; 
+					if (!formElementHtml) {
+						str += "\t\t\t\t<input id = 'datatype_" + elementName + "' name='datatype' type='hidden' value = '" + elementType + "'>\n";
+						str += "\t\t\t\t<input id = 'mandatory_" + elementName + "' name='mandatory' type='hidden' value = '" + isMandatory + "'>\n";
+						str += "\t\t\t\t<input id = '" + elementName + "' name='" + elementLabel + "' type='text' class = '"+featureTypeElement['f_style_id']+"' size=20 value = '" + elementValue + "'>\n";
+						}
+						else {
+							while (formElementHtml.match(/\\/)) {
+								formElementHtml = formElementHtml.replace(/\\/, "");
+							} 
+//							alert(formElementHtml);
+							// preselect the correct entry of the box
+							var patternString = "option value='"+elementValue+"'";
+							var pattern = new RegExp(patternString);
+							formElementHtml = formElementHtml.replace(pattern, patternString+" selected");
+//							alert(formElementHtml);
+							str += formElementHtml;
+	
+						}
+						str += "\t\t\t</td>\n\t\t</tr>\n";
+				}
+			}
+			else {
+				hasGeometryColumn = true;
+			}
+		}
+
+		//
+		// 3. add buttons "save", "update", "delete"
+		//
+		var isTransactional = (featureTypeArray['wfs_transaction']); 
+		if (isTransactional) {
+			str += "\t\t<tr>\n";
+
+			var options = ["save", "update", "delete"];
+			for (var i = 0 ; i < options.length ; i++) {
+				var onClickText = "var result = window.opener.formCorrect(document, '"+featureTypeElementFormId+"');";
+				onClickText += 	"if (result.isCorrect) {";
+				onClickText += 		"window.opener.dbGeom('"+options[i]+"', "+memberIndex+")";
+				onClickText += 	"}";
+				onClickText += 	"else {";
+				onClickText += 		"alert(result.errorMessage);"
+				onClickText += 	"}";
+
+				if (options[i] == "save" && hasGeometryColumn) {
+					str += "\t\t\t<td><input type='button' name='saveButton' value='"+buttonLabelSaveGeometry[selectedLanguage]+"' onclick=\""+onClickText+"\" /></td>\n";
+				}
+				
+				if (!featureTypeMismatch && fid) {
+					if (options[i] == "update" && hasGeometryColumn) {
+						str += "\t\t\t<td><input type='button' name='updateButton' value='"+buttonLabelUpdateGeometry[selectedLanguage]+"' onclick=\""+onClickText+"\"/></td>\n";
+					}
+					if (options[i] == "delete"){ 
+						str += "\t\t\t<td><input type='button' name='deleteButton' value='"+buttonLabelDeleteGeometry[selectedLanguage]+"' onclick=\""+onClickText+"\"/></td>\n";
+					}
+				}
+			}
+			str += "\t\t</tr>\n";
+		}
+		str += "\t</table>\n";
+		str += "<input type='hidden' id='fid' value='"+fid+"'>";
+//			str += "<input type='text' name='mb_wfs_conf'>";
+		str += "</form>\n";
+	}
+	return str;
 }
 
 function dbGeom(type,m) {
@@ -871,24 +1023,24 @@
 	var mapObjInd = parent.getMapObjIndexByName(mod_digitize_target);
 
 	if (myconf['featuretype_srs'] != parent.mb_mapObj[mapObjInd].epsg) {
-		alert("fatal error: EPSG mismatch. "+ parent.mb_mapObj[mapObjInd].epsg + " / "+ myconf['featuretype_srs']);
+		alert(errorMessageEpsgMismatch[selectedLanguage] + parent.mb_mapObj[mapObjInd].epsg + " / "+ myconf['featuretype_srs']);
 	}
 	else {
 		var fid = false;
 		if (typeof(wfsWindow) != 'undefined' && !wfsWindow.closed) {
-			var myform = wfsWindow.document.forms[1];
+			var myform = wfsWindow.document.getElementById(featureTypeElementFormId);
 		
 			for (var i=0; i<myform.length; i++){
-				if (myform.elements[i].name == "fid") {
+				if (myform.elements[i].id == "fid") {
 					fid = myform.elements[i].value;
 					d.get(m).e.setElement('fid', fid);
 				}
 				else if (myform.elements[i].type == 'text' ){
-					d.get(m).e.setElement(myform.elements[i].name, myform.elements[i].value);
+					d.get(m).e.setElement(myform.elements[i].id, myform.elements[i].value);
 				}
 				// selectbox
 				else if (typeof(myform.elements[i].selectedIndex) == 'number') {
-					d.get(m).e.setElement(myform.elements[i].name, myform.elements[i].options[myform.elements[i].selectedIndex].value);
+					d.get(m).e.setElement(myform.elements[i].id, myform.elements[i].options[myform.elements[i].selectedIndex].value);
 				}
 			}
 		}
@@ -897,25 +1049,40 @@
 		}
 
 		str = parent.get_wfs_str(myconf, d, m, type, fid);
-		prompt('', str);
+//		prompt('', str);
 		parent.mb_ajax_post("../extensions/geom2wfst.php", {'filter':str,'url':myconf['wfs_transaction']}, function(xml,status){
-			wfsSubWrite(m,type,status);
-			var serializer = new XMLSerializer();
-			var xml_string = serializer.serializeToString(xml);
+//			var serializer = new XMLSerializer();
+//			var xml_string = serializer.serializeToString(xml);
+			var xml_string = "";
 //			prompt('', xml_string);
-			alert(xml_string);
+//			alert(xml_string);
+			wfsSubWrite(m, type, status, xml_string);
 		});
 	}
 }
 
-function wfsSubWrite(m,type,status) {
+// TO DO
+function wfsWriteSucceeded (xmlString) {
+	return true;
+}
+
+function wfsSubWrite(m, type, status, xml_string) {
 	parent.mb_execWfsWriteSubFunctions();
+
 	if (type == 'delete') {
 		parent.mb_disableThisButton(mod_digitizeEvent);
 		d.del(m);
 	}
 	executeDigitizeSubFunctions();
-	alert(status);
+	
+	if (status == "success" && wfsWriteSucceeded(xml_string)) {
+		var wfsWriteMessage = messageSuccessWfsWrite[selectedLanguage];
+	}
+	else {
+		var wfsWriteMessage = messageErrorWfsWrite[selectedLanguage] + "\n" + xml_string;
+	} 
+	wfsWindow.close();
+	alert(wfsWriteMessage);
 }
 // --- wfs window (begin) -----------------------------------------------------------------------------------------
 // -----------------------------------------------------------------------------------------------------------

Modified: trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php	2007-02-08 14:36:09 UTC (rev 1091)
+++ trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php	2007-02-08 14:39:05 UTC (rev 1092)
@@ -21,6 +21,7 @@
 import_request_variables("PG");
 require_once("../php/mb_validateSession.php");
 require_once("../../conf/mapbender.conf");
+require_once("../../conf/wfs_default.conf");
 $con = db_connect(DBSERVER,OWNER,PW);
 db_select_db(DB,$con);
 
@@ -29,7 +30,7 @@
 
 $wfs_conf_filename = "wfs_default.conf";
 include '../include/dyn_php.php';
-include("../../conf/" . $digitize_conf_filename);
+include("../../conf/" . $wfs_conf_filename);
 
 include '../include/dyn_js.php';
 $sql = "SELECT e_src, e_target FROM gui_element WHERE e_id = 'setSpatialRequest' AND fkey_gui_id = '".$gui_id."'";
@@ -50,15 +51,11 @@
 var wfsAreaType_extent = "extent";
 var wfsAreaType_current = "";
 
-var activeButton = null;
-var mod_wfs_spatialRequest_geometry = null;
-
 var mod_wfs_spatialRequest_frameName = "";
 var mod_wfs_spatialRequest_epsg;
 var mod_wfs_spatialRequest_width;
 var mod_wfs_spatialRequest_height;
 
-var mod_wfs_spatialRequestSubFunctions = new Array();
 var mod_wfs_spatialRequest_bg = "";
 var mod_wfs_spatialRequest_pgsql = true;
 var mod_wfs_spatialRequest_win = null;
@@ -71,13 +68,18 @@
 var button_dialogue = "dialogue";
 var mb_wfs_tolerance = 8;
 
+var activeButton = null;
+var mod_wfs_spatialRequest_geometry = null;
+var mod_wfs_spatialRequestSubFunctions = [];
+
+
 // ------------------------------------------------------------------------------------------
 // ------------ button handling -------------------------------------------------------------
 
 function displayButtons() {
 	for (var i = 0 ; i < buttonWfs_id.length ; i ++) {
 		if (parseInt(buttonWfs_on[i])==1) {
-			document.write("<div id='div_"+buttonWfs_id[i]+"' style='position:absolute; top:"+buttonWfs_y[i]+"; left:"+buttonWfs_x[i]+"'><img name=\""+buttonWfs_id[i]+"\" onmouseover=\"mb_regButton_frame('initWfsButton', null, "+i+");\" id=\""+buttonWfs_id[i]+"\" title=\""+buttonWfs_title_off[i]+"\" src=\""+buttonWfs_imgdir+buttonWfs_src[i]+"\"></div>");
+			document.write("<div id='div_"+buttonWfs_id[i]+"' style='position:absolute; top:"+buttonWfs_y[i]+"; left:"+buttonWfs_x[i]+"; z-index:"+buttonWfs_zIndex+"'><img name=\""+buttonWfs_id[i]+"\" onmouseover=\"mb_regButton_frame('initWfsButton', null, "+i+");\" id=\""+buttonWfs_id[i]+"\" title=\""+buttonWfs_title_off[i]+"\" src=\""+buttonWfs_imgdir+buttonWfs_src[i]+"\"></div>");
 		}
 	}
 }
@@ -189,7 +191,7 @@
 			mod_getAreaExt_send();
 		}
 		else{
-			alert("Ausschnitt ungültig!")
+			alert(errorMessageInvalidExtent[selectedLanguage])
 			mb_disableThisButton(activeButton.id);
 		}
 	}
@@ -364,11 +366,12 @@
 		mod_wfs_spatialRequest_win.focus();
 	}	
 }
+
 function mb_setwfsrequest(target,queryGeom){
 	//mb_wfs_reset();
 	var ind = getMapObjIndexByName(target);
-	var w = new Array();
-	w_ = new Array();
+	var w = [];
+	w_ = [];
 	wfs_config = window.frames["wfs_conf"].get_wfs_conf();
 	for (var i=0; i<mb_mapObj[ind].wms.length; i++){
 		for(var ii=0; ii<mb_mapObj[ind].wms[i].objLayer.length; ii++){
@@ -408,14 +411,8 @@
 			mb_get_geom(url, filter, i, w_[i]);
 		}
 	}
-	else if(queryGeom.geomtype==geomTypeLine || queryGeom.geomtype == geomTypePoint){
-		var rectangle = new Array();
-		if(queryGeom.geomtype == geomTypePoint){
-			var tmp = realToMap(mb_wfs_target, queryGeom.get(0));
-			var buffer = new Point(mb_wfs_tolerance/2, -mb_wfs_tolerance/2);
-			rectangle[0] = mapToReal(mb_wfs_target, tmp.minus(buffer));
-			rectangle[1] = mapToReal(mb_wfs_target, tmp.plus(buffer));
-		}
+	else if(queryGeom.geomtype==geomTypeLine){
+		var rectangle = [];
 		if(queryGeom.geomtype == geomTypeLine){
 			var rectangle = queryGeom.getBBox();
 		}
@@ -436,12 +433,34 @@
 			mb_get_geom(url, filter, i, w_[i]);
 		}
 	}
-	highlight = new Highlight(mb_wfs_targets, highlight_tag_id);
+	else if(queryGeom.geomtype == geomTypePoint){
+		var tmp = queryGeom.get(0);
+		var buffer = mb_wfs_tolerance/2;
+		for(var i=0; i<w_.length; i++){
+			var url = wfs_config[w_[i]]['wfs_getfeature'];
+			param = "service=wfs&request=getFeature&version=1.0.0&typename="+ wfs_config[w_[i]]['featuretype_name']+"&filter=";
+			var filter = "<ogc:Filter xmlns:ogc='http://ogc.org' xmlns:gml='http://www.opengis.net/gml'>";
+			filter += "<Intersects><ogc:PropertyName>";
+			for(var j=0; j<wfs_config[w_[i]]['element'].length; j++){
+				if(wfs_config[w_[i]]['element'][j]['f_geom'] == 1){
+					filter += wfs_config[w_[i]]['element'][j]['element_name'];
+				}
+			}
+			filter += "</ogc:PropertyName><gml:Polygon srsName='4326'><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>";	
+			filter += (tmp.x - buffer) + "," + (tmp.y - buffer) + " " + (tmp.x + buffer) + "," + (tmp.y - buffer) +  " ";
+			filter += (tmp.x + buffer) + "," + (tmp.y + buffer) + " " + (tmp.x - buffer) + "," + (tmp.y + buffer) + " " + (tmp.x - buffer) + "," + (tmp.y - buffer); 
+			filter += "</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></Intersects></ogc:Filter>";
+			url += param;
+			mb_get_geom(url, filter, i, w_[i]);
+		}
+	}
+	highlight = new Highlight(mb_wfs_targets, highlight_tag_id, "position:absolute; top:0px; left:0px; z-index:"+generalHighlightZIndex, generalHighlightLineWidth);
 	return true;
 }
 
 function mb_get_geom(url, filter, index, wfs_conf_id) {
-	mb_ajax_post("../php/mod_wfs_result.php",{'url':url,'filter':filter,'typename':wfs_config[wfs_conf_id]['featuretype_name'],'wfs_conf_id':wfs_conf_id},function(js_code,status){
+	
+	mb_ajax_post("../" + wfsResultModulePath + wfsResultModuleFilename,{'url':url,'filter':filter,'typename':wfs_config[wfs_conf_id]['featuretype_name'],'wfs_conf_id':wfs_conf_id},function(js_code,status){
 //		alert(js_code);
 		eval(js_code);
 		if (typeof(geom) == 'object') mb_execWfsReadSubFunctions(geom);



More information about the Mapbender_commits mailing list