[Mapbender-commits] r4483 - branches/print_dev/http/print

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Aug 5 04:57:58 EDT 2009


Author: mschulz
Date: 2009-08-05 04:57:58 -0400 (Wed, 05 Aug 2009)
New Revision: 4483

Modified:
   branches/print_dev/http/print/mod_printPDF_div.js
Log:
added NaturalDocs documentation

Modified: branches/print_dev/http/print/mod_printPDF_div.js
===================================================================
--- branches/print_dev/http/print/mod_printPDF_div.js	2009-08-05 08:48:21 UTC (rev 4482)
+++ branches/print_dev/http/print/mod_printPDF_div.js	2009-08-05 08:57:58 UTC (rev 4483)
@@ -75,266 +75,322 @@
 
 
 /* ------------- printbox addition ------------- */
-var printBox;
 
 var PrintPDF = function (options) {
 
-var that = this;
-var actualConfig;
+	var that = this;
+	
+	/**
+ 	 * Property: actualConfig
+	 * 
+	 * object, holds the actual configuration after loading the json file
+	 */
+	var actualConfig;
 
-eventInit.register(function () {
-	mod_printPDF_init();
-});
-
-this.createPrintBox = function () {
-	size = "A4";
-	//document.form1.size.value = size;
-	format = "portrait";
-	var w, h;
-	//validate();
-	var map = Mapbender.modules[myTarget];
-	var map_el = map.getDomElement();
-	var jqForm = $("#"+myId+"_form");
-	printBox = createBox({
-		target : myTarget,
-		printWidth : getPDFMapSize("width")/10,
-		printHeight : getPDFMapSize("height")/10,
-		scale : Math.pow(10, Math.floor(Math.log(map.getScale())/Math.LN10)),
-		afterChangeAngle : function (obj) {
-			if (typeof(obj) == "object") {
-				if (typeof(obj.angle) == "number") {
-					jqForm[0].angle.value = obj.angle;
+	/**
+ 	 * constructor
+	 */
+	eventInit.register(function () {
+		mod_printPDF_init();
+	});
+	
+	/**
+ 	 * Property: printBox
+	 * 
+	 * the movable printframe
+	 */	
+	var printBox;
+	
+	/**
+ 	 * Method: createPrintBox
+	 * 
+	 * creates a printBox in the current view, calculates the scale 
+	 * (tbd. if not set from the config) so that the printbox fits in the mapframe.
+	 * Width and height are taken from the configuration.
+	 */
+	this.createPrintBox = function () {
+		size = "A4";
+		//document.form1.size.value = size;
+		format = "portrait";
+		var w, h;
+		//validate();
+		var map = Mapbender.modules[myTarget];
+		var map_el = map.getDomElement();
+		var jqForm = $("#"+myId+"_form");
+		printBox = createBox({
+			target : myTarget,
+			printWidth : getPDFMapSize("width")/10,
+			printHeight : getPDFMapSize("height")/10,
+			scale : Math.pow(10, Math.floor(Math.log(map.getScale())/Math.LN10)),
+			afterChangeAngle : function (obj) {
+				if (typeof(obj) == "object") {
+					if (typeof(obj.angle) == "number") {
+						jqForm[0].angle.value = obj.angle;
+					}
+					if (obj.coordinates) {
+						jqForm[0].coordinates.value = String(obj.coordinates);
+					}
 				}
-				if (obj.coordinates) {
-					jqForm[0].coordinates.value = String(obj.coordinates);
+			},
+			afterChangeSize : function (obj) {
+				if (typeof(obj) == "object") {
+					if (obj.scale) {
+						jqForm[0].scale.value = obj.scale;
+					}
+					if (obj.coordinates) {
+						jqForm[0].coordinates.value = String(obj.coordinates);
+					}
 				}
 			}
-		},
-		afterChangeSize : function (obj) {
-			if (typeof(obj) == "object") {
-				if (obj.scale) {
-					jqForm[0].scale.value = obj.scale;
+		});
+		
+		eventAfterMapRequest.register(function () {
+			if (typeof(printBox) !== "undefined") {
+				printBox.repaint();
+			}
+		});
+	};
+
+	/**
+ 	 * Method: getPDFMapSize
+	 * 
+	 * checks the actual config for the size w/h values.
+	 *
+	 * Parameters:
+	 * key      - string, the key which value to retrieve (currently width or height)
+	 */	
+	var getPDFMapSize = function (key) {
+		for (var page in actualConfig.pages) {
+			for (var pageElement in actualConfig.pages[page].elements) {
+				if (actualConfig.pages[page].elements[pageElement].type == "map") {
+					return actualConfig.pages[page].elements[pageElement][key];
+					break;
 				}
-				if (obj.coordinates) {
-					jqForm[0].coordinates.value = String(obj.coordinates);
-				}
 			}
+		} 
+	};
+
+	/**
+ 	 * Method: destroyPrintBox
+	 * 
+	 * removes an existing printBox.
+	 */	
+	var destroyPrintBox = function () {
+		if (printBox) {
+			printBox.destroy();
 		}
-	});
+	};
 	
-	eventAfterMapRequest.register(function () {
-		if (typeof(printBox) !== "undefined") {
-			printBox.repaint();
-		}
-	});
-};
+	/**
+ 	 * Method: mod_printPDF_init
+	 * 
+	 * initializes the print modules, generates template chooser and loads first configuration.
+	 */	
+	var mod_printPDF_init = function () {
+		/* first we'd need to build the configuration selection */
+		buildConfigSelector();	
+		/* second we'd need to read the json configuration */
+		that.loadConfig(mbPrintConfigFilenames[0]);
+	};
 
-var getPDFMapSize = function (key) {
-	for (var page in actualConfig.pages) {
-		for (var pageElement in actualConfig.pages[page].elements) {
-			if (actualConfig.pages[page].elements[pageElement].type == "map") {
-				return actualConfig.pages[page].elements[pageElement][key];
+	/**
+ 	 * Method: loadConfig
+	 * 
+	 * GETs the config, build corresponding form, remove an existing printBox
+	 */		
+	this.loadConfig = function (configFilename) {
+		$.get(mbPrintConfigPath + configFilename, function(json, status){
+		    actualConfig = eval('(' + json + ')');
+		    buildForm(); 
+		    hookForm();
+		});
+		destroyPrintBox();
+	};
+
+	/**
+ 	 * Method: hookForm
+	 * 
+	 * utility method to connect the form plugin to the print form.
+	 */	
+	var hookForm = function () {
+		var options = { 
+	   		url:			'../print/printFactory.php', 
+	   		type:			'post',
+	   		dataType:		'json',
+	   		beforeSubmit: 	validate,
+	   		success:    	showResult
+		};
+		$("#"+myId+"_form").ajaxForm(options);	
+	};
+	
+	/**
+	 * Change status of the working elements. These should begin with "$myId_working" 
+	 *
+	 * @param {String} newStatus either "hide or "show"
+	 */
+	var showHideWorking = function (newStatus) {
+		if (newStatus=="hide")
+	    	$("[id^='"+myId+"_working']").hide();
+	    else
+	    	$("[id^='"+myId+"_working']").show();	
+	};
+	
+	/**
+	 * update form values helper function
+	 *
+	 */
+	var updateFormField = function (formData, key, value) {
+		for(var j=0; j < formData.length; j++){
+			if (formData[j].name == key) {
+				formData[j].value = value;
 				break;
 			}
+		}	
+	};
+	
+	
+	/**
+	 * Validates and updates form data values.
+	 * Adds the elements before the submit button.
+	 *
+	 * @see jquery.forms#beforeSubmitHandler
+	 */
+	var validate = function (formData, jqForm, options) {
+		showHideWorking("show");
+		
+		// map urls
+		var ind = getMapObjIndexByName(myTarget);
+		var f = jqForm[0];
+		f.map_url.value = '';
+		f.overview_url.value = '';
+		for(var i=0; i < mb_mapObj[ind].wms.length; i++){
+			if(mb_mapObj[ind].wms[i].gui_wms_visible > 0){
+				if(mb_mapObj[ind].wms[i].mapURL != false && mb_mapObj[ind].wms[i].mapURL != 'false' && mb_mapObj[ind].wms[i].mapURL != ''){   
+					if(f.map_url.value != ""){
+						f.map_url.value += '___';
+					}      
+					f.map_url.value += mb_mapObj[ind].wms[i].mapURL;
+				}
+			}
 		}
-	} 
-};
-
-var destroyPrintBox = function () {
-	if (printBox) {
-		printBox.destroy();
-	}
-};
-/* ------------- printbox addition -------------*/
-
-
-var mod_printPDF_init = function () {
-	/* first we'd need to build the configuration selection */
-	buildConfigSelector();	
-	/* second we'd need to read the json configuration */
-	that.loadConfig(mbPrintConfigFilenames[0]);
-};
-
-this.loadConfig = function (configFilename) {
-	$.get(mbPrintConfigPath + configFilename, function(json, status){
-	    actualConfig = eval('(' + json + ')');
-	    buildForm(); 
-	    hookForm();
-	});
-	destroyPrintBox();
-};
-
-var hookForm = function () {
-	var options = { 
-   		url:			'../print/printFactory.php', 
-   		type:			'post',
-   		dataType:		'json',
-   		beforeSubmit: 	validate,
-   		success:    	showResult
+		updateFormField(formData, "map_url", f.map_url.value);
+		
+		//overview_url
+		var ind_overview = getMapObjIndexByName('overview');
+		if(mb_mapObj[ind_overview].mapURL != false ){
+		    f.overview_url.value = mb_mapObj[ind_overview].mapURL;
+			updateFormField(formData, "overview_url", f.overview_url.value);
+		}
+		
+		updateFormField(formData, "map_scale", mb_getScale(myTarget));
+		// write the measured coordinates
+		if (typeof(mod_measure_RX) !== "undefined") {
+			var tmp_x = '';
+			var tmp_y = '';
+			for(i = 0; i < mod_measure_RX.length; i++) {
+				if(tmp_x != '') {
+					tmp_x += ','
+				}
+				tmp_x += mod_measure_RX[i];
+			}
+			for(i = 0; i < mod_measure_RY.length; i++) {
+				if(tmp_y != '') {
+					tmp_y += ','
+				}
+				tmp_y += mod_measure_RY[i];
+			}
+			updateFormField(formData, "measured_x_values", tmp_x);
+			updateFormField(formData, "measured_y_values", tmp_y);
+		}	
+		
+		
+		if (f.map_url.value!="") {
+			//return true;
+		} else {
+		    showHideWorking("hide");
+			return false;
+		}
+			
 	};
-	$("#"+myId+"_form").ajaxForm(options);	
-};
 
-/**
- * Change status of the working elements. These should begin with "$myId_working" 
- *
- * @param {String} newStatus either "hide or "show"
- */
-var showHideWorking = function (newStatus) {
-	if (newStatus=="hide")
-    	$("[id^='"+myId+"_working']").hide();
-    else
-    	$("[id^='"+myId+"_working']").show();	
-};
-
-/**
- * update form values helper function
- *
- */
-var updateFormField = function (formData, key, value) {
-	for(var j=0; j < formData.length; j++){
-		if (formData[j].name == key) {
-			formData[j].value = value;
-			break;
+	/**
+ 	 * Method: showResult
+	 * 
+	 * load the generated PDF from the returned URL as an attachment, 
+	 * that triggers a download popup or is displayed in PDF plugin.
+	 */		
+	var showResult = function (res, text) {
+		if (text == 'success') {
+			window.location = stripslashes(res.outputFileName);
+			showHideWorking("hide");	
 		}
-	}	
-};
-
-
-/**
- * Validates and updates form data values.
- * Adds the elements before the submit button.
- *
- * @see jquery.forms#beforeSubmitHandler
- */
-var validate = function (formData, jqForm, options) {
-	showHideWorking("show");
-	var ind = getMapObjIndexByName(myTarget);
-	var f = jqForm[0];
-	f.map_url.value = '';
-	f.overview_url.value = '';
-	for(var i=0; i < mb_mapObj[ind].wms.length; i++){
-		if(mb_mapObj[ind].wms[i].gui_wms_visible > 0){
-			if(mb_mapObj[ind].wms[i].mapURL != false && mb_mapObj[ind].wms[i].mapURL != 'false' && mb_mapObj[ind].wms[i].mapURL != ''){   
-				if(f.map_url.value != ""){
-					f.map_url.value += '___';
-				}      
-				f.map_url.value += mb_mapObj[ind].wms[i].mapURL;
-			}
+		else {
+			/* something went wrong */
+			$("#"+myId+"_result").html(text);
 		}
-	}
-	updateFormField(formData, "map_url", f.map_url.value);
+	};
 	
-	//overview_url
-	var ind_overview = getMapObjIndexByName('overview');
-	if(mb_mapObj[ind_overview].mapURL != false ){
-	    f.overview_url.value = mb_mapObj[ind_overview].mapURL;
-		updateFormField(formData, "overview_url", f.overview_url.value);
-	}
-	
-	updateFormField(formData, "map_scale", mb_getScale(myTarget));
-	// write the measured coordinates
-	if (typeof(mod_measure_RX) !== "undefined") {
-		var tmp_x = '';
-		var tmp_y = '';
-		for(i = 0; i < mod_measure_RX.length; i++) {
-			if(tmp_x != '') {
-				tmp_x += ','
+	/**
+	 * Generates form elements as specified in the config controls object.
+	 * Adds the elements before the submit button.
+	 * 
+	 * @param {Object} json the config object in json
+	 */
+	var buildForm = function () {
+		$(".print_option_dyn").remove();
+		var str = "";
+		for (var item in actualConfig.controls) {
+			var element = actualConfig.controls[item];
+			var element_id = myId + "_" + element.id;
+			if (element.type != "hidden") {
+				str += '<div class="print_option_dyn">\n';	
+				str += '<label class="print_label" for="'+element.id+'">'+element.label+'</label>\n';
+			} else {
+				str += '<div class="print_option_dyn" style="display:none;">\n';	
 			}
-			tmp_x += mod_measure_RX[i];
-		}
-		for(i = 0; i < mod_measure_RY.length; i++) {
-			if(tmp_y != '') {
-				tmp_y += ','
+			switch (element.type) {
+				case "text":
+					str += '<input type="'+element.type+'" name="'+element.id+'" id="'+element.id+'" size="'+element.size+'"><br>\n';
+					break;
+				case "hidden":
+					str += '<input type="'+element.type+'" name="'+element.id+'" id="'+element.id+'">\n';
+					break;				
+				case "textarea":
+					str += '<textarea id="'+element.id+'" name="'+element.id+'" size="'+element.size+'"></textarea><br>\n';
+					break;				
+				case "select":
+					str += '<select id="'+element.id+'" name="'+element.id+'" size="1">\n';
+					for (var option_index in element.options) {
+						option = element.options[option_index];
+						str += '<option value="'+option.value+'">'+option.label+'</option>\n';
+					}
+					str += '</select><br>\n';
+					break;
 			}
-			tmp_y += mod_measure_RY[i];
+			str += '</div>\n';
 		}
-		updateFormField(formData, "measured_x_values", tmp_x);
-		updateFormField(formData, "measured_y_values", tmp_y);
-	}	
+		if (str) $("#"+myId+"_formsubmit").before(str);
+	};
 	
+	/**
+	 * Generates the configuration select element from the gui element vars
+	 * mbPrintConfigFilenames and mbPrintConfigTitles
+	 */
+	var buildConfigSelector = function () {
+		var str = "";
+		str += '<label class="print_label" for="printPDF_template">Vorlage</label>\n';
+		str += '<select id="printPDF_template" name="printPDF_template" size="1" onchange="Mapbender.modules[\''+myId+'\'].loadConfig(mbPrintConfigFilenames[this.selectedIndex]);">\n';
+		for (var i = 0; i < mbPrintConfigFilenames.length; i++) {
+			str += '<option value="'+mbPrintConfigFilenames[i]+'">'+mbPrintConfigTitles[i]+'</option>\n';
+		}
+		str += '</select><img src="../print/img/shape_handles.png" onclick="Mapbender.modules[\''+myId+'\'].createPrintBox();" title="Use printbox">\n';
+		if (str) $("#printPDF_selector").append(str);
+	};
 	
-	if (f.map_url.value!="") {
-		//return true;
-	} else {
-	    showHideWorking("hide");
-		return false;
-	}
-		
-};
+	var stripslashes = function ( str ) {
+	    return (str+'').replace(/\0/g, '0').replace(/\\([\\'"])/g, '$1');
+	};
 
-var showResult = function (res, text) {
-	if (text == 'success') {
-		window.location = stripslashes(res.outputFileName);
-		showHideWorking("hide");	
-	}
-	else {
-		/* something went wrong */
-		$("#"+myId+"_result").html(text);
-	}
-};
-
-/**
- * Generates form elements as specified in the config controls object.
- * Adds the elements before the submit button.
- * 
- * @param {Object} json the config object in json
- */
-var buildForm = function () {
-	$(".print_option_dyn").remove();
-	var str = "";
-	for (var item in actualConfig.controls) {
-		var element = actualConfig.controls[item];
-		var element_id = myId + "_" + element.id;
-		if (element.type != "hidden") {
-			str += '<div class="print_option_dyn">\n';	
-			str += '<label class="print_label" for="'+element.id+'">'+element.label+'</label>\n';
-		} else {
-			str += '<div class="print_option_dyn" style="display:none;">\n';	
-		}
-		switch (element.type) {
-			case "text":
-				str += '<input type="'+element.type+'" name="'+element.id+'" id="'+element.id+'" size="'+element.size+'"><br>\n';
-				break;
-			case "hidden":
-				str += '<input type="'+element.type+'" name="'+element.id+'" id="'+element.id+'">\n';
-				break;				
-			case "textarea":
-				str += '<textarea id="'+element.id+'" name="'+element.id+'" size="'+element.size+'"></textarea><br>\n';
-				break;				
-			case "select":
-				str += '<select id="'+element.id+'" name="'+element.id+'" size="1">\n';
-				for (var option_index in element.options) {
-					option = element.options[option_index];
-					str += '<option value="'+option.value+'">'+option.label+'</option>\n';
-				}
-				str += '</select><br>\n';
-				break;
-		}
-		str += '</div>\n';
-	}
-	if (str) $("#"+myId+"_formsubmit").before(str);
-};
-
-/**
- * Generates the configuration select element from the gui element vars
- * mbPrintConfigFilenames and mbPrintConfigTitles
- */
-var buildConfigSelector = function () {
-	var str = "";
-	str += '<label class="print_label" for="printPDF_template">Vorlage</label>\n';
-	str += '<select id="printPDF_template" name="printPDF_template" size="1" onchange="Mapbender.modules[\''+myId+'\'].loadConfig(mbPrintConfigFilenames[this.selectedIndex]);">\n';
-	for (var i = 0; i < mbPrintConfigFilenames.length; i++) {
-		str += '<option value="'+mbPrintConfigFilenames[i]+'">'+mbPrintConfigTitles[i]+'</option>\n';
-	}
-	str += '</select><img src="../print/img/shape_handles.png" onclick="Mapbender.modules[\''+myId+'\'].createPrintBox();" title="Use printbox">\n';
-	if (str) $("#printPDF_selector").append(str);
-};
-
-var stripslashes = function ( str ) {
-    return (str+'').replace(/\0/g, '0').replace(/\\([\\'"])/g, '$1');
-};
-
 }
 
 $.extend(Mapbender.modules[options.id], new PrintPDF(options));
\ No newline at end of file



More information about the Mapbender_commits mailing list