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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Jan 29 07:55:27 EST 2007


Author: christoph
Date: 2007-01-29 07:55:27 -0500 (Mon, 29 Jan 2007)
New Revision: 1083

Modified:
   trunk/mapbender/http/javascripts/mod_digitize_tab.php
Log:
- new columns f_form_element, f_edit and f_mandatory
- refactoring wfs_conf to wfsConf
- updated wfs pop-up window

Modified: trunk/mapbender/http/javascripts/mod_digitize_tab.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_digitize_tab.php	2007-01-29 12:52:37 UTC (rev 1082)
+++ trunk/mapbender/http/javascripts/mod_digitize_tab.php	2007-01-29 12:55:27 UTC (rev 1083)
@@ -63,7 +63,7 @@
 
 var wfsWindow;	
 var dwin = null;
-var wfs_conf = new Array();
+var wfsConf = new Array();
 var d = new parent.GeometryArray();
 var mod_digitize_width;
 var mod_digitize_height;
@@ -365,7 +365,6 @@
 	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)});
-	
 }
 
 function checkDigitizeTag(){
@@ -570,10 +569,10 @@
 }
 
 function isTransactional(geom) {
-//	alert(typeof(geom.wfs_conf) + " " + geom.wfs_conf + " " + wfs_conf.length);
+//	alert(typeof(geom.wfs_conf) + " " + geom.wfs_conf + " " + wfsConf.length);
 	if (typeof(geom.wfs_conf) == 'number') {
-		if (geom.wfs_conf >= 0 && geom.wfs_conf < wfs_conf.length) {
-			if (!(wfs_conf[geom.wfs_conf]['wfs_transaction'] == "" && wfs_conf[geom.wfs_conf]['fkey_featuretype_id'] == "")) {
+		if (geom.wfs_conf >= 0 && geom.wfs_conf < wfsConf.length) {
+			if (!(wfsConf[geom.wfs_conf]['wfs_transaction'] == "" && wfsConf[geom.wfs_conf]['fkey_featuretype_id'] == "")) {
 				return true;
 			}
 		}
@@ -586,17 +585,17 @@
 }
 
 function getName (geom) {
-	wfs_conf_id = geom.wfs_conf;
-	wfs_conf = parent.get_complete_wfs_conf();
-	if (isValidWfsConfIndex(wfs_conf, wfs_conf_id)) {
+	wfsConfId = geom.wfs_conf;
+	wfsConf = parent.get_complete_wfs_conf();
+	if (isValidWfsConfIndex(wfsConf, wfsConfId)) {
 		var resultName = "";
-		for (var i = 0 ; i < wfs_conf[wfs_conf_id]['element'].length ; i++) {
-			if (wfs_conf[wfs_conf_id]['element'][i]['f_show'] == 1) {
-				resultName += geom.e.getElementValueByName(wfs_conf[wfs_conf_id]['element'][i]['element_name']) + " ";
+		for (var i = 0 ; i < wfsConf[wfsConfId]['element'].length ; i++) {
+			if (wfsConf[wfsConfId]['element'][i]['f_show'] == 1) {
+				resultName += geom.e.getElementValueByName(wfsConf[wfsConfId]['element'][i]['element_name']) + " ";
 			}
 		}
 		if (resultName == "") {
-			resultName = wfs_conf[wfs_conf_id]['g_label'];
+			resultName = wfsConf[wfsConfId]['g_label'];
 		}
 		return resultName;
 	}
@@ -608,7 +607,7 @@
 function updateListOfGeometries(){
 	var listOfGeom = "<table style='position:absolute; top:"+geomList_y+"px; left:"+geomList_x+"px;'>\n";
 	if (d.count() > 0) {
-		wfs_conf = parent.get_complete_wfs_conf();
+		wfsConf = parent.get_complete_wfs_conf();
 		for (var i = 0 ; i < d.count(); i ++) {
 
 			if (!(nonTransactionalEditable == false && !isTransactional(d.get(i)))) {
@@ -619,7 +618,7 @@
 				listOfGeom += "\t\t\t<img src = '"+buttonDig_imgdir+buttonDig_remove_src+"' title='"+buttonDig_remove_title+"' onclick='parent.mb_disableThisButton(mod_digitizeEvent);d.del("+i+");executeDigitizeSubFunctions();'>\n";
 				listOfGeom += "\t\t</td>\n\t\t<td>\n";
 	
-				if (isValidWfsConfIndex(wfs_conf, d.get(i).wfs_conf)) {
+				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</td>\n\t\t<td style = 'color:blue;font-size:12px'>\n";
@@ -641,22 +640,25 @@
 // --- display (end) -----------------------------------------------------------------------------------------
 // -----------------------------------------------------------------------------------------------------------
 
+
+// -----------------------------------------------------------------------------------------------------------
+// --- 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 geom = false;
-	var wfs = wfs_conf[wfsConfIndex];
-	var memEl;
+	var hasGeometryColumn = false;
+	var wfs = wfsConf[wfsConfIndex];
+	var memberElements;
 	var fid = false;
 
 	if (parseInt(memberIndex) != -1) {
-		memEl = d.get(memberIndex).e;
-		fid = memEl.getElementValueByName('fid');
+		memberElements = d.get(memberIndex).e;
+		fid = memberElements.getElementValueByName('fid');
 	}
 	
 	// search attribute 'element' in wfsConfArray
@@ -667,56 +669,61 @@
 			
 			for (var i = 0 ; i < b.length ; i ++) {
 				var c = b[i];
-				var wfsElementName = c['element_name'];
+				var elementLabel = c['element_name'];
+				var elementName = c['element_name'];
 				if (c['f_label'] != "") {
-					wfsElementName = c['f_label']; 
+					elementLabel = c['f_label']; 
 				}
 				
 //				if (parseInt(c['f_geom']) != 1 && parseInt(c['f_edit']) == 1) {
-				if (parseInt(c['f_geom']) != 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" + wfsElementName + "\n\t\t\t</td>\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";
 
 					var elementValue = "";
 					if (parseInt(memberIndex) != -1) {
-						for (var j = 0 ; j < memEl.count() ; j ++) {
-							if (memEl.getName(j) == c['element_name']) {
-								elementValue = memEl.getValue(j);
+						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 name='" + wfsElementName + "' type='text' size=20 value = '" + elementValue + "'>\n";
+						str += "\t\t\t\t<input id = '" + elementName + "' name='" + elementName + "' type='text' class = '"+c['f_style_id']+"' size=20 value = '" + elementValue + "'>\n";
 					}
 					else {
-/*
-//						alert(elementValue);
-						var formElementHtml = c['f_form_element_html']; 
-//						alert(formElementHtml);
+						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 patternString = "option value='"+elementValue+"'";
 						var pattern = new RegExp(patternString);
 						formElementHtml = formElementHtml.replace(pattern, patternString+" selected");
-//						alert(formElementHtml);
+//alert(formElementHtml);
 						str += formElementHtml;
-*/
+
 					}
 					str += "\t\t\t</td>\n";
 					str += "\t\t</tr>\n";
 				}
-				else geom = wfsElementName;
+				else {
+					hasGeometryColumn = true;
+				}
 			}
 
 			if (wfs['wfs_transaction']) {
 				var colspan = 0;
 				str += "\t\t<tr>\n";
-				if (geom) {
+				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";
 				}
 				else colspan++;
 				if (parseInt(memberIndex) != -1 && fid) {
-					if (geom) {
+					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++;
@@ -764,57 +771,89 @@
 //
 // this method opens a new window and displays the attributes in wfs_conf
 //
-function showWfs(index) {
+function showWfs(geometryIndex) {
+	wfsConf = parent.get_complete_wfs_conf();
+
 	wfsWindow = open("", "wfsattributes", "width=400, height=300, resizable, dependent=yes, scrollbars=yes");
 	wfsWindow.document.open("text/html");
-	wfsWindow.document.writeln("<html><head></head><body></body></html>");
-	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);
-				
-	wfs_conf = parent.get_complete_wfs_conf();
+
 	var str = "";
+	var strStyle = "";
 	var defaultIndex = -1;
 
-	str += "<form id='wfs'>\n\t<select name='wfs' size='" + wfs_conf.length + "'";
-	str += " onChange='document.getElementById(\"elementForm\").innerHTML = window.opener.buildElementForm(this.value , " + index + ")'";
+	str += "<form id='wfs'>\n";
+	str += "\t<select name='wfs' size='" + wfsConf.length + "'";
+	str += " onChange='document.getElementById(\"elementForm\").innerHTML = window.opener.buildElementForm(this.value , " + geometryIndex + ")'";
 	str += ">\n\t\t";
 
-	for (var attr in wfs_conf) {
-		if (isValidWfsConfIndex(wfs_conf, parseInt(d.get(index).wfs_conf))) {
-			if (parseInt(d.get(index).wfs_conf) == parseInt(attr)) {
+	for (var attr in wfsConf) {
+		if (isValidWfsConfIndex(wfsConf, parseInt(d.get(geometryIndex).wfs_conf))) {
+			
+			if (parseInt(d.get(geometryIndex).wfs_conf) == parseInt(attr)) {
 				str += "<option value='" + attr + "'";
 				str += " selected";
 				defaultIndex = parseInt(attr);
-				str += ">" + wfs_conf[attr]['wfs_conf_abstract'];
+				str += ">" + wfsConf[attr]['wfs_conf_abstract'];
 				str += "</option>\n\t\t";
 			}
 		}
 		else {
-			str += "<option value='" + attr + "'";
-			str += ">" + wfs_conf[attr]['wfs_conf_abstract'];
-			str += "</option>\n\t\t";
+			var selected = false;
+			for (var elementIndex = 0; elementIndex < wfsConf[attr]['element'].length ; elementIndex++) {
+				var isGeomColumn = (parseInt(wfsConf[attr]['element'][elementIndex]['f_geom']) == 1); 
+				if (isGeomColumn) {
+					var isMultiPolygon = (d.get(geometryIndex).geomtype == parent.geomTypePolygon && wfsConf[attr]['element'][elementIndex]['element_type'] == 'MultiPolygonPropertyType');
+					var isPolygon = (d.get(geometryIndex).geomtype == parent.geomTypePolygon && d.get(geometryIndex).count() == 1 && wfsConf[attr]['element'][elementIndex]['element_type'] == 'PolygonPropertyType');
+					var isMultiLine = (d.get(geometryIndex).geomtype == parent.geomTypeLine && wfsConf[attr]['element'][elementIndex]['element_type'] == 'MultiLineStringPropertyType');
+					var isLine = (d.get(geometryIndex).geomtype == parent.geomTypeLine && d.get(geometryIndex).count() == 1 && wfsConf[attr]['element'][elementIndex]['element_type'] == 'LineStringPropertyType');
+					var isPoint = (d.get(geometryIndex).geomtype == parent.geomTypePoint && wfsConf[attr]['element'][elementIndex]['element_type'] == 'PointPropertyType');
+//					alert(isMultiPolygon + " " + isPolygon + " " + isMultiLine + " " + isLine + " " + isPoint);
+					if (isMultiPolygon || isPolygon || isMultiLine || isLine || isPoint || wfsConf[attr]['element'][elementIndex]['element_type'] == 'GeometryAssociationType') {
+						str += "<option value='" + attr + "'";
+						if (!selected) {
+							str += " selected";
+							selected = true;
+							defaultIndex = parseInt(attr);
+						}
+						str += ">" + wfsConf[attr]['wfs_conf_abstract'];
+						str += "</option>\n\t\t";
+					}
+				}
+			}
 		}
+	}
 	
-	}
+	
 	str += "</select>\n\t\t</form>\n\t";
-	str += "<div id='elementForm'>\n";
-	if (wfs_conf.length == 1) {
-		str += buildElementForm(0 , index);
-	}
-	str += "\n</div>";
+	str += "<div id='elementForm'>\n</div>";
 	
-	wfsWindow.document.write(str);
-	wfsWindow.document.close();
 
+/*
+	// 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.getElementById("elementForm").innerHTML = buildElementForm(defaultIndex, index);
+		wfsWindow.document.writeln("<html><head><style type='text/css'>"+wfsConf[defaultIndex]['g_style']+"</style></head><body></body></html>");
+		wfsWindow.document.write(str);
+		wfsWindow.document.close();
+		wfsWindow.document.getElementById("elementForm").innerHTML = buildElementForm(defaultIndex, geometryIndex);
 	}
+	else {
+		wfsWindow.document.writeln("<html><head><style type='text/css'></style></head><body></body></html>");
+		wfsWindow.document.write(str);
+		wfsWindow.document.close();
+	}
 }
-	
+
+
 function mod_saveGeom() {
 	dwin = window.open("../php/mod_wfs_save.php","dwin","width=300,height=200");
 }
@@ -825,9 +864,9 @@
 		d.get(m).e = new parent.Wfs_element();
 	}
 	else {
-		wfs_conf = parent.get_complete_wfs_conf();
+		wfsConf = parent.get_complete_wfs_conf();
 	}
-	var myconf = wfs_conf[d.get(m).wfs_conf];
+	var myconf = wfsConf[d.get(m).wfs_conf];
 	
 	var mapObjInd = parent.getMapObjIndexByName(mod_digitize_target);
 
@@ -858,11 +897,13 @@
 		}
 
 		str = parent.get_wfs_str(myconf, d, m, type, fid);
+		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);
 //			prompt('', xml_string);
+			alert(xml_string);
 		});
 	}
 }
@@ -876,6 +917,8 @@
 	executeDigitizeSubFunctions();
 	alert(status);
 }
+// --- wfs window (begin) -----------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------------------------------------
 
 	</script>
 	</head>



More information about the Mapbender_commits mailing list