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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Apr 7 10:56:15 EDT 2010


Author: verenadiewald
Date: 2010-04-07 10:56:14 -0400 (Wed, 07 Apr 2010)
New Revision: 5872

Modified:
   trunk/mapbender/http/javascripts/mod_digitize_tab.php
Log:
image upload functionality with link for uploaded image and delete button

Modified: trunk/mapbender/http/javascripts/mod_digitize_tab.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_digitize_tab.php	2010-04-07 11:56:57 UTC (rev 5871)
+++ trunk/mapbender/http/javascripts/mod_digitize_tab.php	2010-04-07 14:56:14 UTC (rev 5872)
@@ -2110,8 +2110,37 @@
 		"});";
 	
 	onChangeText += datePickerText;
-	onChangeText += "$('.uploader').upload({callback: function(result,stat,msg){if(stat !== true){alert(msg);}}});";
+
 	
+	var uploaderText = 
+		"deleteUploadedFile = function (domNode) {" + 
+			"$(domNode).siblings('input').val('');" + 
+			"$(domNode).siblings('a').remove();" + 
+			"$(domNode).remove();" + 
+		"};" + 
+		"var linkAndDeleteButtonHtml = '<a target=\\\'_blank\\\' title=\\\'show uploaded file\\\' " + 
+			"href=\\\'#\\\'>Show file</a>" + 
+			"<img src=\\\'../img/button_digitize/geomRemove.png\\\' " + 
+			"title=\\\'Delete uploaded file\\\' alt=\\\'Delete uploaded file\\\' " +  
+			"onclick=\\\'deleteUploadedFile(this);\\\' " + 
+			"style=\\\'cursor:pointer\\\'/>';" + 
+		"$('.upload').each(function () { " + 
+		"var $this = $(this).upload({ "+
+			"callback: function(result,stat,msg){"+
+				"if(stat !== true){alert(msg);}"+
+				"else{" + 
+					"$this.prev().val(result.filename);" +
+					"if ($this.siblings('a').size() === 0) {" + 
+						"$this.parent().prepend(linkAndDeleteButtonHtml);" + 
+					"}\n" +
+					"$this.siblings('a').attr('href', result.filename);" + 
+				"}" + 
+			"}" + 
+		"});" + 
+	"});";
+	
+	onChangeText += uploaderText;
+	
 	str += "\t<select name='wfs' size='" + wfsConf.length + "'";
 	str += " onChange=\""+ onChangeText +"\"";
 	str += ">\n\t\t";
@@ -2149,7 +2178,7 @@
 		headStr += 'a img { vertical-align: middle;border: 0; }';
 		headStr += '.mandatory { border:1px solid red; }';
 		headStr += '</style>';
-		headStr += '</head><body onload="window.opener.toggleTabs(\''+initialTab+'\'); ' + datePickerText + var $uploader = $(\'.uploader\');$uploader.upload({callback: function(result,stat,msg){if(stat !== true){alert(msg);}}});">';
+		headStr += '</head><body onload="window.opener.toggleTabs(\''+initialTab+'\'); ' + datePickerText + uploaderText + '">';
 		wfsWindow.document.write(headStr);
 	}
 	else {
@@ -2282,7 +2311,33 @@
 	return formElementHtml;
 }
 
+function prepareUploadField (formElementHtml, categoryName, isMandatory, elementLabel, elementValue, styleId) {
+	//var elementValue = "../tmp/1-14bbb3d6987e16.png";
+	var classString = (styleId == '0') ? "" : styleId;
+	var patternString = "<div";
+	var pattern = new RegExp(patternString);
+		
+	// set category
+	if (categoryName) {
+		formElementHtml = formElementHtml.replace(pattern, patternString + " category='" + categoryName + "' ");
+	}
 
+	classString = (classString !== "") ? " class='"+classString+"' " : " ";
+	formElementHtml = formElementHtml.replace(pattern, patternString + classString);
+	
+	// preselect the correct entry of the box
+	if(elementValue !== "") {
+		formElementHtml = "<a title='show uploaded file' target='_blank' href='" + 
+			elementValue + "'>Show file</a><img title='Delete uploaded file' " +
+			"alt='Delete uploaded file' style='cursor:pointer;' " +
+			"onclick='$(this).siblings(\"input\").val(\"\");" + 
+			"$(this).siblings(\"a\").remove();$(this).remove();' " + 
+			"src='../img/button_digitize/geomRemove.png'/>" + 
+			formElementHtml;
+	}
+	
+	return formElementHtml;
+}
 
 // Returns a form with the elements of a selected WFS grouped in tabs
 // (if the original WFS is the selected WFS, the values are set too)
@@ -2429,6 +2484,11 @@
 							if (pattern.test(formElementHtml)) {
 								formElementHtml = prepareTextArea(formElementHtml, "", isMandatory, elementLabel, elementValue, styleId);
 							}
+							var patternString = "upload";
+							pattern = new RegExp(patternString);
+							if (pattern.test(formElementHtml)) {
+								formElementHtml = prepareUploadField(formElementHtml, "", isMandatory, elementLabel, elementValue, styleId);
+							}
 							str += formElementHtml;
 						}
 						
@@ -2554,8 +2614,11 @@
 						d.get(m).e.setElement('fid', fid);
 					}
 				}
+				
 				//else if (myform.elements[i].type == 'text' { //merging geoportal.rlp
-				else if (myform.elements[i].type == 'text'  || myform.elements[i].tagName.toUpperCase() == "TEXTAREA"){
+				else if (myform.elements[i].type == "text" || 
+						myform.elements[i].tagName.toUpperCase() == "TEXTAREA" ||
+						myform.elements[i].className == "hiddenUploadField"){
 					if (myform.elements[i].id) {
 						var elementId = String(myform.elements[i].id).replace(/mb_digitize_form_/, "");
 						d.get(m).e.setElement(elementId, myform.elements[i].value);



More information about the Mapbender_commits mailing list