[Mapbender-commits] r7517 - in trunk/mapbender/http: classes javascripts php plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Feb 2 13:28:18 EST 2011


Author: kmq
Date: 2011-02-02 10:28:18 -0800 (Wed, 02 Feb 2011)
New Revision: 7517

Modified:
   trunk/mapbender/http/classes/class_elementVar.php
   trunk/mapbender/http/classes/class_wfs_conf.php
   trunk/mapbender/http/classes/class_wmc.php
   trunk/mapbender/http/javascripts/initWmcObj.php
   trunk/mapbender/http/javascripts/mod_wfsGazetteerEditor_client.php
   trunk/mapbender/http/php/mod_wfs_conf_server.php
   trunk/mapbender/http/plugins/wfsConfTree.js
Log:
wfsconftree now persists in the sessionwmc

Modified: trunk/mapbender/http/classes/class_elementVar.php
===================================================================
--- trunk/mapbender/http/classes/class_elementVar.php	2011-02-02 16:52:38 UTC (rev 7516)
+++ trunk/mapbender/http/classes/class_elementVar.php	2011-02-02 18:28:18 UTC (rev 7517)
@@ -37,7 +37,7 @@
 				$this->load();
 			}
 			catch (Exception $e) {
-				throw new Exception ("Could not initialize element var.");
+				throw new Exception ("Could not initialize element var, because: " . $e);
 			}
 		}
 	}	

Modified: trunk/mapbender/http/classes/class_wfs_conf.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_conf.php	2011-02-02 16:52:38 UTC (rev 7516)
+++ trunk/mapbender/http/classes/class_wfs_conf.php	2011-02-02 18:28:18 UTC (rev 7517)
@@ -153,7 +153,8 @@
 									"f_auth_varname" => $row["f_auth_varname"],
 									"f_detailpos" => $row["f_detailpos"],
 									"f_operator" => $row["f_operator"],
-									"f_show_detail" => $row["f_show_detail"]
+									"f_show_detail" => $row["f_show_detail"],
+									"f_helptext" => $row["f_helptext"] == null? "":$row["f_helptext"]
 									);
 			array_push($elementArray, $currentElement);
 		}
@@ -187,7 +188,7 @@
 	/**
 	 * get WFS conf data from database
 	 */
-	private function getWfsConfFromDB ($idArray) {
+	public function getWfsConfFromDB ($idArray) {
 		
 		// if a user has access to some WFS confs...
 		if (count($idArray) > 0) {

Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2011-02-02 16:52:38 UTC (rev 7516)
+++ trunk/mapbender/http/classes/class_wmc.php	2011-02-02 18:28:18 UTC (rev 7517)
@@ -18,7 +18,7 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 require_once(dirname(__FILE__) . "/../classes/class_wms.php");
-require_once(dirname(__FILE__) . "/../classes/class_wfs_configuration.php");
+require_once(dirname(__FILE__) . "/../classes/class_wfs_conf.php");
 require_once(dirname(__FILE__) . "/../classes/class_layer_monitor.php");
 require_once(dirname(__FILE__) . "/../classes/class_point.php");
 require_once(dirname(__FILE__) . "/../classes/class_bbox.php");
@@ -183,6 +183,18 @@
 	// get the map objects "overview" and "mapframe1"
 		$this->mainMap = map::selectMainMapByApplication($appId);
 		$this->overviewMap = map::selectOverviewMapByApplication($appId);
+
+		// a  wWFS is basically just a vectorlayer, and a WFSconf is just a configured WFS,
+		// so it makes sense to attach the WFSCONFIDstring to to the mapobject
+		// this clearly needs a better solution though...
+		try{
+			$ev = new ElementVar($appId,"mapframe1","wfsConfIdString");
+			$this->generalExtensionArray['WFSCONFIDSTRING'] = $ev->value;
+		}catch(Exception $E){
+			// ... exceprtions are a terribkle way to do this, but I am not going to rewrite the ElementVar class
+			$this->generalExtensionArray['WFSCONFIDSTRING'] = "";
+		}
+
 		$this->createXml();
 		$this->saveAsFile();
 	}
@@ -1021,11 +1033,12 @@
 
 	public function featuretypeConfToJavaScript() {
 		$wfsConfIds = $this->generalExtensionArray['WFSCONFIDSTRING'];
+		new mb_exception("app AAAA idstr $wfsConfIds");
 		$featuretypeConfs = array();
 		$featuretypeConfArray = is_string($wfsConfIds) ?
 			explode(",", $wfsConfIds) : array();
 		for ($i = 0; $i < count($featuretypeConfArray); $i++) {
-			$featuretypeConf = WfsConfiguration::createFromDb($featuretypeConfArray[$i]);
+			$featuretypeConf = WfsConf::getWfsConfFromDb($featuretypeConfArray[$i]);
 			array_push($featuretypeConfs,$featuretypeConf);
 		}
 		$featuretypeConfObj = new Mapbender_JSON();

Modified: trunk/mapbender/http/javascripts/initWmcObj.php
===================================================================
--- trunk/mapbender/http/javascripts/initWmcObj.php	2011-02-02 16:52:38 UTC (rev 7516)
+++ trunk/mapbender/http/javascripts/initWmcObj.php	2011-02-02 18:28:18 UTC (rev 7517)
@@ -492,10 +492,13 @@
 }
 
 $wmcFeaturetypeJson = $wmc->featuretypeConfToJavaScript();
+$wfsConfIdString = $wmcGetApi->generalExtensionArray['WFSCONFIDSTRING'];
 $wmcFeaturetypeStr = <<<JS
 	Mapbender.events.afterInit.register(function () {
+		console.log("triggering the thing");
 		$('#body').trigger('addFeaturetypeConfs', [
-			{featuretypeConfObj : $wmcFeaturetypeJson}
+			{ featuretypeConfObj : $wmcFeaturetypeJson,
+				wfsConfIdString: "$wfsConfIdString"}
 		]);
 	});
 JS;

Modified: trunk/mapbender/http/javascripts/mod_wfsGazetteerEditor_client.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_wfsGazetteerEditor_client.php	2011-02-02 16:52:38 UTC (rev 7516)
+++ trunk/mapbender/http/javascripts/mod_wfsGazetteerEditor_client.php	2011-02-02 18:28:18 UTC (rev 7517)
@@ -159,7 +159,36 @@
 var geomArray = null;
 
 var frameIsReady = function () {
+	var req = parent.Mapbender.Ajax.Request({
+		url: 	"../php/mod_wfs_conf_server.php",
+		method:	"getWfsConfsFromId",
+		parameters: {
+			wfsConfIdString: global_selectedWfsConfId 
+		},
+		callback: function(result,success,message){
+		console.debug("b");
+		console.debug(result);
 
+			// the rest of the script doesn't expect an array, but an object, so the result must be converted
+			global_wfsConfObj = {};
+			for(var i in result){
+				if(!result.hasOwnProperty(i)){ continue;}
+				global_wfsConfObj[result[i].id] = result[i];
+
+			}
+			init_wfsSpatialRequest();
+			appendWfsForm();
+			appendStyles();
+		
+			setWfsInfo();
+			
+			// creates a Highlight object for the request geometry
+			var styleProperties = {"position":"absolute", "top":"0px", "left":"0px", "z-index":100};
+			requestGeometryHighlight = new parent.Highlight(targetArray, "requestGeometryHighlight", styleProperties, 2);
+			parent.mb_registerSubFunctions("window.frames['" + frameName +"'].requestGeometryHighlight.paint()");
+		}
+	});
+//	req.send();
 	parent.mb_ajax_json("../php/mod_wfs_gazetteer_server.php", {command:"getWfsConf",wfsConfIdString: global_selectedWfsConfId }, function(json,status){
 		global_wfsConfObj = json;
 		init_wfsSpatialRequest();
@@ -556,8 +585,8 @@
 				
 				form.appendChild(spanNode);
 				form.appendChild(inputNode);
-				//if(wfsConfElementArray[i].f_helptext.length > 0) { form.appendChild(helptextNode); }
-				//if(wfsConfElementArray[i].f_helptext.length > 0) { form.appendChild(helptextDisplay); }
+				if(wfsConfElementArray[i].f_helptext.length > 0) { form.appendChild(helptextNode); }
+				if(wfsConfElementArray[i].f_helptext.length > 0) { form.appendChild(helptextDisplay); }
 				form.appendChild(document.createElement("br"));
 			}
 		}
@@ -1061,7 +1090,10 @@
 			title: searchPopupTitle,
 			width:searchPopupWidth,
 			height: searchPopupHeight,
-			position: [ searchPopupX,searchPopupY]
+			position: [ searchPopupX,searchPopupY],
+			onclose: function(){
+				resultList.hide();
+			}
 		}); 
 	}
 	else {

Modified: trunk/mapbender/http/php/mod_wfs_conf_server.php
===================================================================
--- trunk/mapbender/http/php/mod_wfs_conf_server.php	2011-02-02 16:52:38 UTC (rev 7516)
+++ trunk/mapbender/http/php/mod_wfs_conf_server.php	2011-02-02 18:28:18 UTC (rev 7517)
@@ -27,6 +27,32 @@
 $command = $ajaxResponse->getMethod();
 
 switch ($command) {
+
+
+	case "getWfsConfsFromId":
+		$wfsConfIdString = $ajaxResponse->getParameter("wfsConfIdString");
+
+		if(!$wfsConfIdString){ 
+			$ajaxResponse->setSuccess($false);
+			$ajaxResponse->setMessage("missing wfsConfIdString");
+			$ajaxResponse->send();
+			break;
+		}
+		$wfsConfIdString = trim($wfsConfIdString,',');
+		$wfsConfIds = explode(',',$wfsConfIdString);
+		$result = array();
+		foreach($wfsConfIds as $wfsId){
+			new mb_exception("AAAAAAAAAA  '$wfsId' of $wfsConfIdString ");
+			$currentWfsConf = WfsConfiguration::createFromDb($wfsId);
+			if ($currentWfsConf !== null) {
+				$result[]= $currentWfsConf;
+			}else{
+				$result[] = "OMG";
+			}
+		}
+		$ajaxResponse->setResult($result);
+		$ajaxResponse->send();
+	break;
 	case "getWfsConfs" : 
 		$currentUser = new User(Mapbender::session()->get("mb_user_id"));
 		$wfsConfIds = $currentUser->getWfsConfByWfsOwner();
@@ -130,4 +156,4 @@
 $ajaxResponse->setMessage("Invalid command.");
 $ajaxResponse->setSuccess(false);
 $ajaxResponse->send();
-?>
\ No newline at end of file
+?>

Modified: trunk/mapbender/http/plugins/wfsConfTree.js
===================================================================
--- trunk/mapbender/http/plugins/wfsConfTree.js	2011-02-02 16:52:38 UTC (rev 7516)
+++ trunk/mapbender/http/plugins/wfsConfTree.js	2011-02-02 18:28:18 UTC (rev 7517)
@@ -1,22 +1,40 @@
+/*
+ *  default wfsConfIdString is taken from the elementVar "wfsConfIdString" to the mapframe1 element
+ *
+ *  */
 var $confTree = $(this);
 var ConfTree = function(o){
 
-
-	wfsConfIdString = o.wfsConfIdString || "";
-
-
+	var that = this;
+	var wfsConfIdString = o.wfsConfIdString || "";
+	var wfsconfs = wfsConfIdString.split(',');
 	// getParams is a global variable that contains the Querystring as a json object
 	var getwfsConfIdString = getParams['FEATURETYPE'] || "";
+	if(getwfsConfIdString !== ""){
+		wfsconfs = wfsconfs.concat(getwfsConfIdString.split(','));
+	}
+	wfsConfIdString = wfsconfs.join(',');
+	var currentWFSConf = {};
 
-	wfsConfIdString = wfsConfIdString  + "," + getwfsConfIdString;
 
+	if(parent.Mapbender.modules.loadwmc){
+		parent.Mapbender.modules.loadwmc.events.loaded.register(function (obj) {
+			if (obj.extensionData && obj.extensionData.WFSCONFIDSTRING) {
+				var req = Mapbender.Ajax.Request({
+					url: 	"../php/mod_wfs_conf_server.php",
+					method:	"getWfsConfsFromId",
+					parameters: {
+						wfsConfIdString: obj.extensionData.WFSCONFIDSTRING
+					},
+					callback: function(result,success,message){
+						reset(result);
+					}
+				});
+				req.send();
+			}
+		});
+	}
 
-	$confTree.children().remove();
-	$confTree.addClass('conftree');
-
-	var $WFSConffolder = $('<li class="open wfsconf"><ul></ul></li>');
-	$confTree.append($WFSConffolder);
-
 	var $wfsConfDialog = $("<div></div>").dialog({
 		width: 500,
 		height: 600,
@@ -27,50 +45,70 @@
 				}
 			}
 	});
-	mb_ajax_json("../php/mod_wfs_gazetteer_server.php", {command:"getWfsConf",wfsConfIdString: wfsConfIdString }, function(json,status){
-		aWFSConf = json;
+	$("button.toggle",$confTree).live('click', function(){
+		if($(this).parent().hasClass("open")){
+			$(this).parent().removeClass("open");
+			$(this).parent().addClass("closed");
+		}else{
+			$(this).parent().removeClass("closed");
+			$(this).parent().addClass("open");
+
+		}
+	});
+
+	var reset = function(aWFSConf){
+		wfsconfs = [];
+		$confTree.children().remove();
+		$confTree.append("<li class='emptymessage'>Keine WFSConf verfügbar</li>");
+		$confTree.addClass('conftree');
+
+		var $WFSConffolder = $('<li class="open wfsconf"><ul></ul></li>');
+		$confTree.append($WFSConffolder);
 		for(var i in  aWFSConf){
-
+			// remove default "no wfs conf"message
+			if(i == 0){ $confTree.find(".emptymessage").remove();}
 			// group by featyretype
-			$featuretypeFolder = $WFSConffolder.find("li.featuregroup_"+aWFSConf[i].featuretype_id);
+			$featuretypeFolder = $WFSConffolder.find("li.featuregroup_"+aWFSConf[i].featureTypeId);
+			wfsconfs.push(aWFSConf[i].id);
 			if($featuretypeFolder.size() == 0){
-				$featuretypeFolder = $('<li class="open featuregroup_'+ aWFSConf[i].featuretype_id + '"><button class="toggle"></button>'+ aWFSConf[i].wfs_conf_abstract + '<ul></ul></li>');
+				$featuretypeFolder = $('<li class="open featuregroup_'+ aWFSConf[i].featureTypeId + '"><button class="toggle"></button>'+ aWFSConf[i].abstr + '<ul></ul></li>');
 				$WFSConffolder.find(" > ul").append($featuretypeFolder);
 				$featuretypeList = $featuretypeFolder.find("ul");
 			}else{
 				$featuretypeList = $featuretypeFolder.find("ul");
 			};
 
-			switch(aWFSConf[i].wfs_conf_type){
+			//parseInt because one version of wfsConf creates this as a string, the other as an int 
+			switch(parseInt(aWFSConf[i].type,10)){
 					/* search */
-					case "0": 
-						$wfsconfEntry = $('<li class="search" ><img src="../img/gnome/icn_suchmodul.png" /><a href="#" class="meta">metadata</a><button class="remove">remove</button><a href="#" class="dialogopen">'+ aWFSConf[i].g_label +'</a></li>');
-						//$wfsconfEntry = $('<li class="search" ><a href="#" class="meta">metadata</a><button class="remove">remove</button><a href="#" class="dialogopen">'+ aWFSConf[i].g_label +'</a></li>');
+					case 0: 
+						$wfsconfEntry = $('<li class="search" ><img src="../img/gnome/icn_suchmodul.png" /><a href="#" class="meta">metadata</a><button class="remove">remove</button><a href="#" class="dialogopen">'+ aWFSConf[i].label +'</a></li>');
 					break;
 					
 					/* digitize */
-					case "1":
-						$wfsconfEntry = $('<li class="digitize" ><img src="../img/gnome/document-save.png" /><a href="#" class="meta">medadata</a><button class="remove">remove</button><a href="#" class="dialogopen">'+ aWFSConf[i].g_label +'</a></li>');
+					case 1:
+						$wfsconfEntry = $('<li class="digitize" ><img src="../img/gnome/document-save.png" /><a href="#" class="meta">medadata</a><button class="remove">remove</button><a href="#" class="dialogopen">'+ aWFSConf[i].label +'</a></li>');
 					break;
 
 					/* download */
-					case "2": 
-						$wfsconfEntry = $('<li class="download" ><img src="../img/gnome/accessories-text-editor.png" /><a href="#" class="meta">metadata</a><button class="remove">remove</button><a href="#" class="dialogopen">'+ aWFSConf[i].g_label +'</a></li>');
+					case 2: 
+						$wfsconfEntry = $('<li class="download" ><img src="../img/gnome/accessories-text-editor.png" /><a href="#" class="meta">metadata</a><button class="remove">remove</button><a href="#" class="dialogopen">'+ aWFSConf[i].label +'</a></li>');
 					break;
 
 			}
+			$wfsconfEntry.data("wfsconfId",aWFSConf[i].id);
 			$featuretypeList.append($wfsconfEntry);
 
 			$wfsconfEntry.find("a.dialogopen").click((function(wfsConf){ 
 				return function(){
 
-				var querystring = 'wfsConfId='+wfsConf.wfs_conf_id+'&e_id_css='+o.id+'&e_target='+o.target;
-				switch(wfsConf.wfs_conf_type){
+				var querystring = 'wfsConfId='+wfsConf.id+'&e_id_css='+o.id+'&e_target='+o.target;
+				switch(parseInt(wfsConf.type,10)){
 
 					/* search */
-					case "0": 
+					case 0: 
 					/* download */
-					case "2": 
+					case 2: 
 						var $iframe = $('<iframe name="'+o.id+'_" style="width: 100%; height: 100%;" src="../javascripts/mod_wfsGazetteerEditor_client.php?'+querystring+'"></iframe>');
 						$wfsConfDialog.empty();
 						$wfsConfDialog.append($iframe);	
@@ -78,7 +116,7 @@
 					break;
 
 					/* digitize */
-					case "1":
+					case 1:
 					break;
 				}
 
@@ -86,30 +124,66 @@
 			})(aWFSConf[i]));
 			$wfsconfEntry.find("button.remove").click(function(){
 			
+				
+				var wfsconfId = $(this).parent().data("wfsconfId");
 				// if this was the last entry in the featuregroup, remove it completely	...
-				if($(this).parent().siblings().size() == 0){
-					$(this).parent().parent().parent().remove();
-				}else{
-					//.. otherwise just rmeove the entry
-					$(this).parent().remove();
+//				if($(this).parent().siblings().size() == 0){
+//					$(this).parent().parent().parent().remove();
+//				}else{
+//					$(this).parent().remove();
+//				}
+				
+				var newWFSConf = [];
+				for (var i in currentWFSConf){
+					if(currentWFSConf[i].id != wfsconfId){
+						newWFSConf.push(currentWFSConf[i]);
+					}
 				}
-			
+				reset(newWFSConf);
 					
 			});
 		}
-	}); 
-
+		if(parent.Mapbender.modules.savewmc){
+			parent.Mapbender.modules.savewmc.setExtensionData({ WFSCONFIDSTRING: wfsconfs.join(',') });
+			parent.Mapbender.modules.savewmc.save({session: true});
+		}
 	
-	$("button.toggle",$confTree).live('click', function(){
-		if($(this).parent().hasClass("open")){
-			$(this).parent().removeClass("open");
-			$(this).parent().addClass("closed");
-		}else{
-			$(this).parent().removeClass("closed");
-			$(this).parent().addClass("open");
+		// need this so we have a reference to the currently active wfsConfs
+		currentWFSConf = aWFSConf;
+	};
 
+
+	var req = Mapbender.Ajax.Request({
+		url: 	"../php/mod_wfs_conf_server.php",
+		method:	"getWfsConfsFromId",
+		parameters: {
+			wfsConfIdString: wfsConfIdString
+		},
+		callback: function(result,success,message){
+			console.debug("FROM GUI");
+			reset(result);
 		}
 	});
+	req.send();
+
+
+	// addFeaturetypeConf should take precedence
+	$('#body').bind('addFeaturetypeConfs',function(evt,obj){
+		var req = Mapbender.Ajax.Request({
+			url: 	"../php/mod_wfs_conf_server.php",
+			method:	"getWfsConfsFromId",
+			parameters: {
+				wfsConfIdString: obj.wfsConfIdString
+			},
+			callback: function(result,success,message){
+				console.debug("FROM WMS");
+				reset(result);
+			}
+		});
+		req.send();
+	});
+
+
 };
 
 Mapbender.events.init.register(function(){



More information about the Mapbender_commits mailing list