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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Nov 13 08:00:36 EST 2009


Author: christoph
Date: 2009-11-13 08:00:35 -0500 (Fri, 13 Nov 2009)
New Revision: 4982

Modified:
   trunk/mapbender/http/javascripts/mod_loadwmc.js
Log:


Modified: trunk/mapbender/http/javascripts/mod_loadwmc.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_loadwmc.js	2009-11-13 12:59:30 UTC (rev 4981)
+++ trunk/mapbender/http/javascripts/mod_loadwmc.js	2009-11-13 13:00:35 UTC (rev 4982)
@@ -20,68 +20,115 @@
 	
 var checkLayerAvailability = typeof options.checkLayerAvailability !== "undefined" 
 	&& options.checkLayerAvailability === 1 ? true : false;
+
+options.loadWmc = typeof options.loadWmc === "number" ? options.loadWmc : 1;
+options.mergeWmc = typeof options.mergeWmc === "number" ? options.mergeWmc : 1;
+options.appendWmc = typeof options.appendWmc === "number" ? options.appendWmc : 1;
+options.publishWmc = typeof options.publishWmc === "number" ? options.publishWmc : 0;
+options.showWmc = typeof options.showWmc === "number" ? options.showWmc : 1;
+options.openLayers = typeof options.openLayers === "number" ? options.openLayers : 1;
+options.deleteWmc = typeof options.deleteWmc === "number" ? options.deleteWmc : 1;
+options.uploadWmc = typeof options.uploadWmc === "number" ? options.uploadWmc : 1;
+options.listWmc = typeof options.listWmc === "number" ? options.listWmc : 1;
 	
-$(this).click(function () {
-	if (wmcPopup === null || !wmcPopup.isVisible()) {
-		mod_loadwmc();
-	}
-}).mouseover(function () {
-	if (options.src) {
-		this.src = options.src.replace(/_off/, "_over");
-	}
-}).mouseout(function () {
-	if (options.src) {
-		this.src = options.src;
-	}
-});
+var tagName = this.tagName.toUpperCase();
 
+if (tagName === "IMG") {
+
+	$(this).click(function () {
+		if (wmcPopup === null || !wmcPopup.isVisible()) {
+			mod_loadwmc();
+		}
+	}).mouseover(function () {
+		if (options.src) {
+			this.src = options.src.replace(/_off/, "_over");
+		}
+	}).mouseout(function () {
+		if (options.src) {
+			this.src = options.src;
+		}
+	});
+}
+else {
+	mod_loadwmc();
+}	
+
 /**
  * is called when the load WMC button is pressed
  */
 function mod_loadwmc(){
 
-	var initialHtml = "<div style='display:none' id='" + options.id + "_tabs'>" + 
-				"<ul>" + 
-					"<li><a href='#" + options.id + "_wmclist'>List</a></li>" + 
-					"<li><a href='#" + options.id + "_wmcUpload'>Upload</a></li>" + 
-				"</ul>" + 
-				"<div id='" + options.id + "_wmclist' >" +
-					"<table width='100%' id='" + options.id + "_wmclist_table'>" +
-						"<thead><tr>" +
-							"<th>WMC name</td>" +
-							"<th>last update</td>" +
-							"<th>load</td>" +
-							"<th>merge</td>" +
-							"<th>append</td>" +
-							"<th>public</td>" +
-							"<th>show</td>" +
-							"<th>OpenLayers</td>" +
-							"<th>delete</td>" +
-						"</thead></tr>" +
-					"</table>" +
-				"</div>" +
-				"<div id='" + options.id + "_wmcUpload' >" +
-				"</div>" +
+	var initialHtml = "<div style='display:none' id='" + options.id + "_tabs'>";
+
+	//
+	// add tabs if both modules are available
+	//
+	if (options.listWmc && options.uploadWmc) {
+		initialHtml += "<ul>" + 
+						"<li><a href='#" + options.id + "_wmclist'>List</a></li>" + 
+						"<li><a href='#" + options.id + "_wmcUpload'>Upload</a></li>" + 
+					"</ul>";
+	}
+	if (options.listWmc || options.uploadWmc) {
+		//
+		// add listWMC if available
+		//
+		if (options.listWmc) {
+			initialHtml += "<div id='" + options.id + "_wmclist' >" +
+							"<table width='100%' id='" + options.id + "_wmclist_table'>" +
+								"<thead><tr>" +
+									"<th>WMC name</td>" +
+									"<th>last update</td>" + 
+									"<th>created</td>";
+			initialHtml += options.loadWmc ? "<th>load</td>" : "";
+			initialHtml += options.mergeWmc ? "<th>merge</td>" : "";
+			initialHtml += options.appendWmc ? "<th>append</td>" : "";
+			initialHtml += options.publishWmc ? "<th>public</td>" : "";
+			initialHtml += options.showWmc ? "<th>show</td>" : "";
+			initialHtml += options.openLayers ? "<th>OpenLayers</td>" : "";
+			initialHtml += options.deleteWmc ? "<th>delete</td>" : "";
+		
+			initialHtml += 		"</thead></tr>" +
+							"</table>" +
+						"</div>";
+		}
+		//
+		// add uploadWMC if available
+		//
+		if (options.uploadWmc) {
+			initialHtml += "<div id='" + options.id + "_wmcUpload' >" +
 			"</div>";
+		}
+	}
+	else {
+		return;
+	}
 
+	initialHtml += "</div>";
+
 	// creates a new pop up (if it doesn't already exist)
 	// the pop up allows you to load, append, merge, 
 	// display and delete WMC documents
-	if (wmcPopup === null) {
-		wmcPopup = new mb_popup({
-			title:options.currentTitle,
-			width:750,
-			height:500,
-			top:50,
-			left:100,
-			html:initialHtml
-		});
+	if (tagName === "IMG") {
+		if (wmcPopup === null) {
+			wmcPopup = new mb_popup({
+				title: options.currentTitle,
+				width: 750,
+				height: 500,
+				top: 50,
+				left: 100,
+				html: initialHtml
+			});
+		}
+		
+		// display the pop up
+		if (!wmcPopup.isVisible()) {
+			wmcPopup.setHtml(initialHtml);
+			wmcPopup.show();
+		}
 	}
-
-	// display the pop up
-	if (!wmcPopup.isVisible()) {
-		wmcPopup.setHtml(initialHtml);
-		wmcPopup.show();
+	else {
+		$("#" + options.id).html(initialHtml);
 	}
 
 	// get WMC data from server
@@ -116,186 +163,211 @@
 			var $td;
 			$tr.append($("<td>" + wmcObj.wmc[i].title + "</td>"));
 			$tr.append($("<td>" + wmcObj.wmc[i].timestamp + "</td>"));
+			$tr.append($("<td>" + wmcObj.wmc[i].timestamp_create + "</td>"));
 
-			// Load WMC
-			var $loadTd = appendTableCell({
-				src: "../img/button_gray/wmc_load.png",
-				title: "load this WMC",
-				method: "loadWmc",
-				message: "WMC has been loaded successfully.",
-				parameters: {
-					id:currentId
-				},
-				callback: function (args) {
-					if (constraintCheckRequired()) {
-						checkConstraints(args, function (args) {
-							executeJavaScript(args);
-						});
-						return;	
+			if (options.loadWmc) {
+			
+				// Load WMC
+				var $loadTd = appendTableCell({
+					src: "../img/button_gray/wmc_load.png",
+					title: "load this WMC",
+					method: "loadWmc",
+					message: "WMC has been loaded successfully.",
+					parameters: {
+						id: currentId
+					},
+					callback: function(args){
+						if (constraintCheckRequired()) {
+							checkConstraints(args, function(args){
+								executeJavaScript(args);
+							});
+							return;
+						}
+						executeJavaScript(args);
 					}
-					executeJavaScript(args);
-				}
-			});
-			$tr.append($loadTd);				
+				});
+				$tr.append($loadTd);
+			}
 
-			// Merge WMC
-			var $mergeTd = appendTableCell({
-				src: "../img/button_gray/wmc_merge.png",
-				title: "merge WMC",
-				method: "mergeWmc",
-				message: "WMC has been merged successfully.",
-				parameters:{
-					id:currentId, 
-					extensionData:currentWmcExtensionData !== null ?
-						currentWmcExtensionData : null, 
-					mapObject:mb_mapObj,
-					generalTitle:"currentState"
-				},
-				callback: function (args) {
-					if (constraintCheckRequired()) {
-						checkConstraints(args, function (args) {
-							executeJavaScript(args);
-						});
-						return;	
+			if (options.mergeWmc) {
+				// Merge WMC
+				var $mergeTd = appendTableCell({
+					src: "../img/button_gray/wmc_merge.png",
+					title: "merge WMC",
+					method: "mergeWmc",
+					message: "WMC has been merged successfully.",
+					parameters: {
+						id: currentId,
+						extensionData: currentWmcExtensionData !== null ? currentWmcExtensionData : null,
+						mapObject: mb_mapObj,
+						generalTitle: "currentState"
+					},
+					callback: function(args){
+						if (constraintCheckRequired()) {
+							checkConstraints(args, function(args){
+								executeJavaScript(args);
+							});
+							return;
+						}
+						executeJavaScript(args);
 					}
-					executeJavaScript(args);
-				}
-			});
-			$tr.append($mergeTd);				
+				});
+				$tr.append($mergeTd);
+			}
 
-			// Append WMC
-			var $appendTd = appendTableCell({
-				src: "../img/button_gray/wmc_append.png",
-				title: "append WMC",
-				method: "appendWmc",
-				message: "WMC has been appended successfully.",
-				parameters:{
-					id:currentId, 
-					extensionData:currentWmcExtensionData !== null ?
-						currentWmcExtensionData : null,
-					mapObject:mb_mapObj,
-					generalTitle:"currentState"
-				},
-				callback: function (args) {
-					if (constraintCheckRequired()) {
-						checkConstraints(args, function (args) {
-							executeJavaScript(args);
-						});
-						return;	
+			if (options.appendWmc) {
+				// Append WMC
+				var $appendTd = appendTableCell({
+					src: "../img/button_gray/wmc_append.png",
+					title: "append WMC",
+					method: "appendWmc",
+					message: "WMC has been appended successfully.",
+					parameters: {
+						id: currentId,
+						extensionData: currentWmcExtensionData !== null ? currentWmcExtensionData : null,
+						mapObject: mb_mapObj,
+						generalTitle: "currentState"
+					},
+					callback: function(args){
+						if (constraintCheckRequired()) {
+							checkConstraints(args, function(args){
+								executeJavaScript(args);
+							});
+							return;
+						}
+						executeJavaScript(args);
 					}
-					executeJavaScript(args);
-				}
-			});
-			$tr.append($appendTd);				
+				});
+				$tr.append($appendTd);
+			}
 
-            //WMC is Public
-			var $publicTd = appendBoolTableCell({
-                isPublic:  isPublic,
-                disabled:  isDisabled,
-				method: "setWMCPublic",
-				parameters:{
-					id:currentId
-				},
-				callback: executeJavaScript
-			});
-			$tr.append($publicTd);				
+			if (options.publishWmc) {
+				//WMC is Public
+				var $publicTd = appendBoolTableCell({
+					isPublic: isPublic,
+					disabled: isDisabled,
+					method: "setWMCPublic",
+					parameters: {
+						id: currentId
+					},
+					callback: executeJavaScript
+				});
+				$tr.append($publicTd);
+			}
 
 			// Display WMC
-			var $displayTd = appendTableCell({
-				src: "../img/button_gray/wmc_xml.png",
-				title: "display WMC XML",
-				callback: function() {
-					// create Popup
-					if (wmcDisplayPopup === null) {
-						wmcDisplayPopup = new mb_popup({
-							title: "WMC Document",
-							width:600,
-							height:500,
-							top:50,
-							left:700,
-							url:"../javascripts/mod_displayWmc.php?wmc_id=" + currentId
-						});
+			if (options.showWmc) {
+				var $displayTd = appendTableCell({
+					src: "../img/button_gray/wmc_xml.png",
+					title: "display WMC XML",
+					callback: function(){
+						// create Popup
+						if (wmcDisplayPopup === null) {
+							wmcDisplayPopup = new mb_popup({
+								title: "WMC Document",
+								width: 600,
+								height: 500,
+								top: 50,
+								left: 700,
+								url: "../javascripts/mod_displayWmc.php?wmc_id=" + currentId
+							});
+						}
+						else {
+							wmcDisplayPopup.setUrl("../javascripts/mod_displayWmc.php?wmc_id=" + currentId + "&" + mb_session_name + "=" + mb_nr);
+						}
+						// display the pop up
+						wmcDisplayPopup.show();
 					}
-					else {
-						wmcDisplayPopup.setUrl("../javascripts/mod_displayWmc.php?wmc_id=" + currentId + "&" + mb_session_name + "=" + mb_nr);
+				});
+				$tr.append($displayTd);
+			}
+						
+			if (options.openLayers) {
+				// OpenLayers Export
+				var $openLayersTd = appendTableCell({
+					src: "../img/OpenLayers.trac.png",
+					title: "export to OpenLayers",
+					callback: function(){
+						// create Popup
+						if (wmcOpenlayersPopup === null) {
+							wmcOpenlayersPopup = new mb_popup({
+								title: "OpenLayers",
+								width: 600,
+								height: 500,
+								top: 40,
+								left: 600,
+								url: "../php/mod_wmc2ol.php?wmc_id=" + currentId +
+								"&" +
+								mb_session_name +
+								"=" +
+								mb_nr
+							});
+						}
+						else {
+							// set correct URL
+							wmcOpenlayersPopup.setUrl("../php/mod_wmc2ol.php?wmc_id=" + currentId + "&" + mb_session_name + "=" + mb_nr);
+						}
+						// display the pop up
+						wmcOpenlayersPopup.show();
 					}
-					// display the pop up
-					wmcDisplayPopup.show();
-				}
-			});
-			$tr.append($displayTd);	
-			
-			// OpenLayers Export
-			var $openLayersTd = appendTableCell({
-				src: "../img/OpenLayers.trac.png",
-				title: "export to OpenLayers",
-				callback: function () {
-					// create Popup
-					if (wmcOpenlayersPopup === null) {
-						wmcOpenlayersPopup = new mb_popup({
-							title: "OpenLayers",
-							width: 600,
-							height: 500,
-							top: 40,
-							left: 600,
-							url: "../php/mod_wmc2ol.php?wmc_id=" + currentId + 
-								"&" + mb_session_name + "=" + mb_nr
-						});
-					}
-					else {
-						// set correct URL
-						wmcOpenlayersPopup.setUrl("../php/mod_wmc2ol.php?wmc_id=" + currentId + "&" + mb_session_name + "=" + mb_nr);
-					}
-					// display the pop up
-					wmcOpenlayersPopup.show();
-				}
-			});
-			$tr.append($openLayersTd);	
+				});
+				$tr.append($openLayersTd);
+			}
 
-			// delete WMC
-			(function () {
-				var $deleteTd = appendTableCell({
-					src: isDisabled ? "../img/button_gray/del_disabled.png" : "../img/button_gray/del.png",
-					title: "delete this WMC",
-					method: "deleteWmc",
-					callback: function (args) {
-						if (!isDisabled && confirm("Do you really want to delete WMC '" + currentName + "'?")) {
-							executeJavaScript(args);
-							var aPos = wmcTable.fnGetPosition($deleteTd.get(0));
-							wmcTable.fnDeleteRow(aPos[0]);
+			if (options.deleteWmc) {
+				// delete WMC
+				(function(){
+					var $deleteTd = appendTableCell({
+						src: isDisabled ? "../img/button_gray/del_disabled.png" : "../img/button_gray/del.png",
+						title: "delete this WMC",
+						method: "deleteWmc",
+						callback: function(args){
+							if (!isDisabled && confirm("Do you really want to delete WMC '" + currentName + "'?")) {
+								executeJavaScript(args);
+								var aPos = wmcTable.fnGetPosition($deleteTd.get(0));
+								wmcTable.fnDeleteRow(aPos[0]);
+							}
+						},
+						parameters: {
+							id: currentId
 						}
-					},
-					parameters:{
-						id:currentId
-					}
-				});
-				$tr.append($deleteTd);	
-			})();
+					});
+					$tr.append($deleteTd);
+				})();
+			}
 		})();
 	}
 
-	$("#" + options.id + "_tabs").tabs();
+
+	if (options.listWmc && options.uploadWmc) {
+		$("#" + options.id + "_tabs").tabs();
+	}
 	
-	$("#" + options.id + "_wmcUpload").upload({
-		callback: function (filename, success, message) {
-			if (!success) {
-				new Mb_exception(message);
-				alert(message);
+	if (options.uploadWmc) {
+		$("#" + options.id + "_wmcUpload").upload({
+			callback: function(filename, success, message){
+				if (!success) {
+					new Mb_exception(message);
+					alert(message);
+				}
+				executeJavaScript({
+					method: "loadWmcFromFile",
+					parameters: {
+						filename: filename
+					},
+					message: "WMC has been loaded successfully."
+				});
 			}
-			executeJavaScript({
-				method: "loadWmcFromFile",
-				parameters: {
-					filename: filename
-				},
-				message: "WMC has been loaded successfully."
-			});
-		}
-	});
-	wmcTable = $("#" + options.id + "_wmclist_table").dataTable({
-		"bPaginate": true,
-		"bJQueryUI": true
-	});
+		});
+	}
+	if (options.listWmc) {
 	
+		wmcTable = $("#" + options.id + "_wmclist_table").dataTable({
+			"bPaginate": true,
+			"bJQueryUI": true
+		});
+	}
+	
 	$("#" + options.id + "_tabs").css("display", "block");
 	
 }
@@ -319,9 +391,66 @@
 			checkLayerAvailability: checkLayerAvailability
 		},
 		callback: function (obj, result, message) {
-			if (typeof callback === "function") {
-				callback(args);
+			
+			var html = "";
+			var constraintTypeArray = [];
+			for (var constraintType in obj) {
+				var caseObj = obj[constraintType];
+
+				if (caseObj.wms.length === 0) {
+					continue;
+				}
+
+				html += "<fieldset>" + caseObj.message + " Dienste trotzdem laden?<br><br>";
+				
+				for (var index in caseObj.wms) {
+					var wms = caseObj.wms[index];
+					html += "<label for='" + constraintType + "_" + wms.index + "'>" + 
+						"<input id='" + options.id + "_" + constraintType + "_" + wms.index + "' " + 
+						"type='checkbox' />" + wms.title  + "</label><br>";
+				}
+				html += "</fieldset><br>";
+				constraintTypeArray.push(constraintType);
 			}
+
+			$("<div id='" + options.id + "_constraint_form' title='Warning'>" + 
+				"<style> fieldset label { display: block; }</style>" + 
+				"<form>" + html + "</form></div>").dialog(
+				{
+					bgiframe: true,
+					autoOpen: false,
+					height: 400,
+					width: 500,
+					modal: true,
+					buttons: {
+						"Continue": function(){
+							var skipWmsArray = [];
+							for (var i in constraintTypeArray) {
+								var currentConstraint = constraintTypeArray[i];
+								var selector = options.id + "_" + currentConstraint + "_";
+								var context = $("#" + options.id + "_constraint_form").get(0);
+								$("input[id^='" + selector + "']", context).each(function () {
+									if (!this.checked) {
+										var regexp = new RegExp(selector);
+										var id = parseInt(this.id.replace(regexp, ""), 10);
+										skipWmsArray.push(id);
+									}
+								});
+							}
+							args.parameters.skipWms = skipWmsArray;
+							if (typeof callback === "function") {
+								callback(args);
+							}
+							$(this).dialog('close').remove();
+						},
+						"Cancel": function(){
+							$(this).dialog('close').remove();
+						}
+					}
+				}
+			);
+
+			$("#" + options.id + "_constraint_form").dialog('open');
 		}
 	});
 	req.send();



More information about the Mapbender_commits mailing list