[Mapbender-commits] r8331 - trunk/mapbender/http/plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Apr 26 11:37:03 EDT 2012


Author: armin11
Date: 2012-04-26 08:37:03 -0700 (Thu, 26 Apr 2012)
New Revision: 8331

Added:
   trunk/mapbender/http/plugins/mb_metadata_showMetadataAddonWfs.js
Modified:
   trunk/mapbender/http/plugins/mb_metadata_wfs_edit.js
   trunk/mapbender/http/plugins/mb_metadata_wfs_submit.js
Log:
Initial things to add service - data - metadata coupling to wfs to support inspire download services.

Added: trunk/mapbender/http/plugins/mb_metadata_showMetadataAddonWfs.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_showMetadataAddonWfs.js	                        (rev 0)
+++ trunk/mapbender/http/plugins/mb_metadata_showMetadataAddonWfs.js	2012-04-26 15:37:03 UTC (rev 8331)
@@ -0,0 +1,300 @@
+var $showMetadataAddonDiv = $(this);
+var $metadataAddonForm = $("<form></form>").appendTo($showMetadataAddonDiv);
+//var $metadataUploadForm = $("<form></form>").appendTo($showMetadataAddonDiv);
+
+var $metadataAddonPopup = $("<div></div>");
+var $metadataUploadPopup = $("<div></div>");
+
+var ShowMetadataAddonApi = function() {
+	var that = this;
+	var featuretypeId;
+	var metadataId;
+        //var wfsId;
+	//Function, which pulls the metadata out off the mapbender registry and give a possibility to edit the record or link
+	this.valid = function () {
+		if (validator && validator.numberOfInvalids() > 0) {
+			$metadataAddonForm.valid();
+			return false;
+		}
+		return true;
+	};
+	this.getInitialFeaturetypeMetadata = function(metadataId, featuretypeId){
+		// get metadata from server
+		var req = new Mapbender.Ajax.Request({
+			url: "../plugins/mb_metadata_server.php",
+			method: "getInitialFeaturetypeMetadata",
+			parameters: {
+				"featuretypeId": featuretypeId,
+				"metadataId": metadataId
+			},
+			callback: function (obj, result, message) {
+				if (!result) {
+					return;
+				}
+				$metadataAddonForm.easyform("reset");
+				$metadataAddonForm.easyform("fill", obj);
+				
+				
+				//that.showForm(metadataId, featuretypeId);
+				/*
+				//enable link element to edit link!
+				$("#link").removeAttr("disabled");
+
+				switch (obj.origin) {
+					case "external":
+						$("#metadataUrlEditor").css("display","block");
+						$("#link_editor").css("display","block");
+    						break;
+  					case "metador":
+						$("#metadataUrlEditor").css("display","block");
+						$("#simple_metadata_editor").css("display","block");
+    						break;
+  					case "capabilities":
+						$("#metadataUrlEditor").css("display","block");
+    						$("#simple_metadata_editor").css("display","block");
+    						break;			
+					default:
+    						break;
+				}
+				*/
+			}
+		});
+		req.send();	
+	}
+	this.getAddedMetadata = function(metadataId, featuretypeId){
+		// get metadata from server
+		var req = new Mapbender.Ajax.Request({
+			url: "../plugins/mb_metadata_server.php",
+			method: "getFeaturetypeMetadataAddon",
+			parameters: {
+				"featuretypeId": featuretypeId,
+				"metadataId": metadataId
+			},
+			callback: function (obj, result, message) {
+				if (!result) {
+					return;
+				}
+				$metadataAddonForm.easyform("reset");
+				$metadataAddonForm.easyform("fill", obj);
+				
+				//enable link element to edit link!
+				$("#link").removeAttr("disabled");
+
+				switch (obj.origin) {
+					case "external":
+						$("#metadataUrlEditor").css("display","block");
+						$("#link_editor").css("display","block");
+    						break;
+  					case "metador":
+						$("#metadataUrlEditor").css("display","block");
+						$("#simple_metadata_editor").css("display","block");
+    						break;
+  					case "capabilities":
+						$("#metadataUrlEditor").css("display","block");
+    						$("#simple_metadata_editor").css("display","block");
+    						break;			
+					default:
+    						break;
+				}
+				//select the right list entries:
+				$(".format_selectbox").val(obj.format); 				
+				$(".charset_selectbox").val(obj.inspire_charset);
+				$(".ref_system_selectbox").val(obj.ref_system);
+				$(".cyclic_selectbox").val(obj.update_frequency);
+				$(".radioRes").filter('[value='+obj.spatial_res_type+']').attr('checked', true);
+
+			}
+		});
+		req.send();	
+	}		
+	this.insertAddedMetadata = function(featuretypeId, data){
+		// push metadata from server
+		var req = new Mapbender.Ajax.Request({
+			url: "../plugins/mb_metadata_server.php",
+			method: "insertFeaturetypeMetadataAddon",
+			parameters: {
+				"featuretypeId": featuretypeId,
+				"data": data
+			},
+			callback: function (obj, result, message) {
+				$("<div></div>").text(message).dialog({
+					modal: true
+				});
+				//update featuretype form to show edited data
+				that.fillFeaturetypeForm(featuretypeId);
+			}
+		});
+		req.send();	
+	}
+
+
+	this.updateAddedMetadata = function(metadataId, featuretypeId, data){
+		// push metadata from server
+		var req = new Mapbender.Ajax.Request({
+			url: "../plugins/mb_metadata_server.php",
+			method: "updateFeaturetypeMetadataAddon",
+			parameters: {
+				"featuretypeId": featuretypeId,
+				"metadataId": metadataId,
+				"data": data
+			},
+			callback: function (obj, result, message) {
+				if (!result) {
+					return;
+				}
+				$("<div></div>").text(message).dialog({
+					modal: true
+				});
+				//update featuretype form to show edited data
+				that.fillFeaturetypeForm(featuretypeId);
+			}
+		});
+		req.send();	
+	}	
+	//function to fill featuretype form with changed metadata entries TODO: this function is defined in mb_metadata_featuretype.js before but it cannot be called - maybe s.th. have to be changed
+	this.fillFeaturetypeForm = function (featuretypeId) {
+		// get metadata from server
+		var req = new Mapbender.Ajax.Request({
+			url: "../plugins/mb_metadata_server.php",
+			method: "getFeaturetypeMetadata",
+			parameters: {
+				"id": featuretypeId
+			},
+			callback: function (obj, result, message) {
+				if (!result) {
+					return;
+				}
+				//this.wfsId = obj.wfs_id;
+				//delete metadataURL entries
+				$('.metadataEntry').remove();
+				//fill MetadataURLs into metadata_selectbox_id - notice: the name of the module is fix!
+				Mapbender.modules.mb_md_featuretype.fillMetadataURLs(obj);
+				//reload featuretype tree for showing symbols
+				Mapbender.modules.mb_md_featuretype_tree.init(Mapbender.modules.mb_md_featuretype.getWfsId());
+			}
+		});
+		req.send();		
+	};
+	
+	deleteAddedMetadata = function(metadataId, featuretypeId){
+		// push metadata from server
+		var req = new Mapbender.Ajax.Request({
+			url: "../plugins/mb_metadata_server.php",
+			method: "deleteFeaturetypeMetadataAddon",
+			parameters: {
+				"metadataId": metadataId
+			},
+			callback: function (obj, result, message) {
+				if (!result) {
+					return;
+				}	
+				//delete metadataURL entries
+				$('.metadataEntry').remove();
+				//fill MetadataURLs into metadata_selectbox_id
+				//update featuretype form to show edited data
+				that.fillFeaturetypeForm(featuretypeId);
+				//alert(wfsId);
+				$("<div></div>").text(message).dialog({
+					modal: true
+				});
+			}
+		});
+		req.send();
+	
+		
+	}		
+
+	this.showForm = function (metadataId, featuretypeId, isNew) {
+		$metadataAddonPopup.append($metadataAddonForm);
+		$metadataAddonPopup.dialog({
+			title : "Metadata Addon Editor", 
+			autoOpen : false, 
+			draggable : true,
+			modal : true,
+			width : 600,
+			position : [600, 75],
+			buttons: {
+				"close": function() {
+					$(this).dialog('close');
+				},
+				"save": function() {
+					//get data from form
+					//supress validation for the link only way
+					//example $("#myform").validate().element( "#myselect" );
+					//$("#myform").validate({
+					// ignore: ".ignore"
+					//})
+					if ($("#addonChooser").css("display") == "block") {
+						//don't allow saving but do something else
+						return;
+						
+					}
+					if ($("#simple_metadata_editor").css("display") == "block") {
+						//validate form before send it!
+						if ($metadataAddonForm.valid() != true) {
+							alert("Form not valid - please check your input!"); //TODO use translations and make a php file from this
+							return;
+						}
+					}
+					var formData = $metadataAddonForm.easyform("serialize");
+					if (!isNew) {
+						that.updateAddedMetadata(metadataId, featuretypeId, formData);
+					} else {
+						that.insertAddedMetadata(featuretypeId, formData);
+						
+					}
+					//$('#mb_md_featuretype_tree').refresh;
+					$(this).dialog('close');
+				}
+			},
+			close: function() {
+				//what to do when the dialog is closed
+				
+			}
+		});
+		$metadataAddonPopup.dialog("open");
+	};
+	
+	initUploadForm = function (featuretypeId) {
+		$metadataAddonPopup.dialog("close");
+		initXmlImport(featuretypeId);
+		that.fillFeaturetypeForm(featuretypeId);
+	}
+
+
+	this.init = function (metadataId, featuretypeId, isNew) {
+		$metadataAddonPopup.dialog("close");
+		$metadataAddonForm.load("../plugins/mb_metadata_addon.php", function () {
+			//push infos to help dialogs
+			$metadataAddonForm.find(".help-dialog").helpDialog();
+			//initialize datepicker
+			$('.hasdatepicker').datepicker({dateFormat:'yy-mm-dd', yearRange: '1900:2050', buttonImageOnly: true, changeYear: true,
+constraintInput: true});
+			//first get json
+			if (!isNew) {
+				that.getAddedMetadata(metadataId, featuretypeId);
+			
+			} else {
+				//show chooser
+				$("#metadataUrlEditor").css("display","block"); 
+				$("#addonChooser").css("display","block");
+				//get initial values (title/abstract)
+				that.getInitialFeaturetypeMetadata(metadataId, featuretypeId);
+			}
+			that.showForm(metadataId, featuretypeId, isNew);
+			$("#uploadImage").click(function () {
+				initUploadForm(featuretypeId);
+			});
+			//alert($("#uploadImage").attr('onclick')); //there has been a bigger problem when setting an onclick attribut with jquery :-(
+			//TODO: make the fields resizable 
+			//$( "#abstract" ).resizable({ minWidth: 75 });
+		});
+	}
+	initMetadataAddon = function(metadataId, featuretypeId, isNew) {
+		//close old window and load form
+		that.init(metadataId, featuretypeId, isNew);	
+		//fill form
+	}
+};
+
+$showMetadataAddonDiv.mapbender(new ShowMetadataAddonApi());

Modified: trunk/mapbender/http/plugins/mb_metadata_wfs_edit.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_wfs_edit.js	2012-04-26 14:48:16 UTC (rev 8330)
+++ trunk/mapbender/http/plugins/mb_metadata_wfs_edit.js	2012-04-26 15:37:03 UTC (rev 8331)
@@ -122,7 +122,11 @@
 	
 	this.init = function (obj) {
 		wfsId = obj;
-		
+
+		if (!wfsId) {
+			return;
+		}
+
 		var formData = arguments.length >= 2 ? arguments[1] : undefined;
 		
 		if (!formReady) {

Modified: trunk/mapbender/http/plugins/mb_metadata_wfs_submit.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_wfs_submit.js	2012-04-26 14:48:16 UTC (rev 8330)
+++ trunk/mapbender/http/plugins/mb_metadata_wfs_submit.js	2012-04-26 15:37:03 UTC (rev 8331)
@@ -10,7 +10,15 @@
 			return;
 		}
 		if (formData !== null) {
-			formData = $.extend(formData, data);
+			if (formData.wfs && data.wfs) {
+				formDatawfs = $.extend(formData.wfs, data.wfs);
+			}
+			else if (formData.featuretype && data.featuretype) {
+				formData.featuretype = $.extend(formData.featuretype, data.featuretype);
+			}
+			else {
+				formData = $.extend(formData, data);
+			}
 		}
 	};
 	
@@ -25,6 +33,7 @@
 		});
 
 		if (formData === null) {
+			alert("Please complete or correct the data in the form.");
 			return;
 		}
 



More information about the Mapbender_commits mailing list