[Mapbender-commits] r4256 - in trunk/mapbender: core
http/javascripts http/php lib
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Jun 26 10:58:28 EDT 2009
Author: christoph
Date: 2009-06-26 10:58:28 -0400 (Fri, 26 Jun 2009)
New Revision: 4256
Modified:
trunk/mapbender/core/system.php
trunk/mapbender/http/javascripts/core.php
trunk/mapbender/http/javascripts/map.js
trunk/mapbender/http/javascripts/map.php
trunk/mapbender/http/javascripts/map_obj.js
trunk/mapbender/http/javascripts/mod_addWMSfromfilteredList.php
trunk/mapbender/http/javascripts/mod_changeEPSG.php
trunk/mapbender/http/javascripts/mod_log.php
trunk/mapbender/http/php/mod_log.php
trunk/mapbender/http/php/mod_wfs_conf_interface.js
trunk/mapbender/lib/ajax.js
trunk/mapbender/lib/ajax.php
trunk/mapbender/lib/basic.js
trunk/mapbender/lib/exception.js
Log:
Modified: trunk/mapbender/core/system.php
===================================================================
--- trunk/mapbender/core/system.php 2009-06-26 14:34:50 UTC (rev 4255)
+++ trunk/mapbender/core/system.php 2009-06-26 14:58:28 UTC (rev 4256)
@@ -40,5 +40,6 @@
"mapframe1,featureInfo1,gazetteerWFS,back,forward,zoomCoords,zoomFull,zoomIn1," .
"zoomOut1,selArea1,pan1,copyright,dependentDiv,dragMapSize," .
"dynamicOverview,FeatureInfoRedirect,highlightPOI,navFrame,sandclock," .
- "scaleBar,scaleSelect,setBBOX,setPOI2Scale,reload,overview,addWMS,repaint"
+ "scaleBar,scaleSelect,setBBOX,setPOI2Scale,reload,overview,addWMS," .
+ "repaint,changeEPSG"
);
Modified: trunk/mapbender/http/javascripts/core.php
===================================================================
--- trunk/mapbender/http/javascripts/core.php 2009-06-26 14:34:50 UTC (rev 4255)
+++ trunk/mapbender/http/javascripts/core.php 2009-06-26 14:58:28 UTC (rev 4256)
@@ -28,9 +28,15 @@
*/
var Mapbender = {
events: {
-
},
- modules: {}
+ modules: {
+ },
+ getTimestamp: function () {
+ var d = new Date();
+ var ts = Math.round(Date.parse(d)/1000);
+ return ts;
+ }
+
};
<?php
ob_start();
Modified: trunk/mapbender/http/javascripts/map.js
===================================================================
--- trunk/mapbender/http/javascripts/map.js 2009-06-26 14:34:50 UTC (rev 4255)
+++ trunk/mapbender/http/javascripts/map.js 2009-06-26 14:58:28 UTC (rev 4256)
@@ -170,8 +170,8 @@
var vendorSpecificString = eval(mb_vendorSpecific[v]);
requestParams += "&" + vendorSpecificString;
}
- if(mb_log && validation){
- var tmp = eval(mb_log + "('" + newfeatureInfoRequest + requestParams + "','" + ts + "')");
+ if(Mapbender.log && validation){
+ var tmp = eval(Mapbender.log + "('" + newfeatureInfoRequest + requestParams + "','" + ts + "')");
}
if(document.getElementById("FeatureInfoRedirect") && validation){
newfeatureInfoRequest += requestParams;
Modified: trunk/mapbender/http/javascripts/map.php
===================================================================
--- trunk/mapbender/http/javascripts/map.php 2009-06-26 14:34:50 UTC (rev 4255)
+++ trunk/mapbender/http/javascripts/map.php 2009-06-26 14:58:28 UTC (rev 4256)
@@ -94,6 +94,7 @@
}
?>
+// this replaces the old init function
$(function () {
initModules();
@@ -120,7 +121,9 @@
"list.js",
"point.js",
"style.js",
- "button.js");
+ "button.js",
+ "backwards_compatibility_to_2.6.js"
+);
for ($i = 0; $i < count($libFileArray); $i++) {
$currentFile = $libPath . $libFileArray[$i];
Modified: trunk/mapbender/http/javascripts/map_obj.js
===================================================================
--- trunk/mapbender/http/javascripts/map_obj.js 2009-06-26 14:34:50 UTC (rev 4255)
+++ trunk/mapbender/http/javascripts/map_obj.js 2009-06-26 14:58:28 UTC (rev 4256)
@@ -787,8 +787,9 @@
}
var newMapRequest = getLayerHtmlCode(ii);
- if (mb_log) {
- var tmp = eval(mb_log + "('" + newMapURL + "','" + ts + "')");
+ if (Mapbender.log) {
+ var tmp = eval(Mapbender.log + "('" +
+ newMapURL + "','" + ts + "')");
}
var myDivId = this.elementName + "_div_" + ii;
writeTag(this.frameName, myDivId, newMapRequest);
@@ -905,8 +906,9 @@
that.mapURL[ii]= newMapURL;
currentWms.mapURL = newMapURL;
- if (mb_log && currentWms.mapURL) {
- var tmp = eval(mb_log + "('" +newMapURL + "','" + ts + "')");
+ if (Mapbender.log && currentWms.mapURL) {
+ var tmp = eval(Mapbender.log + "('" +
+ newMapURL + "','" + ts + "')");
}
return newMapRequest;
Modified: trunk/mapbender/http/javascripts/mod_addWMSfromfilteredList.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_addWMSfromfilteredList.php 2009-06-26 14:34:50 UTC (rev 4255)
+++ trunk/mapbender/http/javascripts/mod_addWMSfromfilteredList.php 2009-06-26 14:58:28 UTC (rev 4256)
@@ -199,11 +199,11 @@
$logged_user_id=Mapbender::session()->get("mb_user_id");
$logged_gui_id=Mapbender::session()->get("mb_user_gui");
-###### SQL #####################################################################################
+# SQL
-/*get infos from gui_element ********************************************************/
+//get infos from gui_element
-/*get group from logged user *******************************************************/
+//get group from logged user
$sql_user_group = "SELECT * FROM mb_user_mb_group WHERE fkey_mb_user_id= $1 ";
$array_values = array($logged_user_id);
$array_types = array('s');
@@ -284,9 +284,9 @@
$fkey_wms_id[$cnt_gui_wms] = $row["fkey_wms_id"];
$cnt_gui_wms++;
}
-/*get allocated wms from allocated gui ********************************************************************************************/
+//get allocated wms from allocated gui
-/*get allocated wms-Abstract and wms-Capabilities from allocated gui ********************************************************************************************/
+//get allocated wms-Abstract and wms-Capabilities from allocated gui
$sql_wms = "SELECT DISTINCT wms_title, wms_abstract, wms_getcapabilities, wms_version FROM wms WHERE wms_id IN (";
$v = $fkey_wms_id;
$t = array();
@@ -307,7 +307,7 @@
$wms_version[$cnt_wms] = $row["wms_version"];
$cnt_wms++;
}
-/*get allocated wms-Abstract and wms-Capabilities from allocated gui ********************************************************************************************/
+//get allocated wms-Abstract and wms-Capabilities from allocated gui
/*INSERT HTML*/
@@ -369,9 +369,9 @@
$cnt_fkey_group_gui_wms++;
}
- /*get group gui WMS ********************************************************************************************/
+ //get group gui WMS
- /*group: get allocated wms-Abstract and wms-Capabilities from allocated gui ********************************************************************************************/
+ //group - get allocated wms-Abstract and wms-Capabilities from allocated gui
if(count($fkey_group_gui_wms_id)>0){
$sql_group_gui_wms = "SELECT DISTINCT wms_title, wms_abstract, wms_getcapabilities, wms_version FROM wms WHERE wms_id IN (";
$v = $fkey_group_gui_wms_id;
@@ -397,9 +397,9 @@
}
}
- /*group: get allocated wms-Abstract and wms-Capabilities from allocated gui ********************************************************************************************/
+ //group - get allocated wms-Abstract and wms-Capabilities from allocated gui
- /*table with allocated wms-Abstract and wms-Capabilities from allocated gui ********************************************************************************************/
+ //table with allocated wms-Abstract and wms-Capabilities from allocated gui
#if ($show_group_wms > 0)
if ($cnt_group_gui_wms > 0){
/*get goup name for showing in the table ********************************************************************************************/
@@ -462,7 +462,7 @@
}
/*get group gui WMS ********************************************************************************************/
- /*gui: get allocated wms-Abstract and wms-Capabilities from allocated gui ********************************************************************************************/
+ //gui - get allocated wms-Abstract and wms-Capabilities from allocated gui
if(count($fkey_show_gui_wms_id)>0){
$sql_show_gui_wms = "SELECT DISTINCT wms_title, wms_abstract, wms_getcapabilities, wms_id, wms_version FROM wms WHERE wms_id IN (";
$v = $fkey_show_gui_wms_id;
@@ -486,7 +486,7 @@
#echo"$gui_wms_title[$cnt_show_gui_wms]";
$cnt_show_gui_wms++;
}
- /*gui: get allocated wms-Abstract and wms-Capabilities from allocated gui ********************************************************************************************/
+ //gui - get allocated wms-Abstract and wms-Capabilities from allocated gui
/*table with allocated wms-Abstract and wms-Capabilities from allocated gui ********************************************************************************************/
#if (isset($cnt_show_gui_wms > 0))
@@ -556,7 +556,7 @@
}
/*get group gui WMS ********************************************************************************************/
- /*gui: get allocated wms-Abstract and wms-Capabilities from allocated gui ********************************************************************************************/
+ //gui - get allocated wms-Abstract and wms-Capabilities from allocated gui
if(count($fkey_show_gui_wms_id)>0){
$sql_show_gui_wms = "SELECT DISTINCT wms_title, wms_abstract, wms_getcapabilities, wms_id, wms_version FROM wms WHERE wms_id IN (";
$v = $fkey_show_gui_wms_id;
@@ -580,14 +580,14 @@
#echo"$gui_wms_title[$cnt_show_gui_wms]";
$cnt_show_gui_wms++;
}
- /*gui: get allocated wms-Abstract and wms-Capabilities from allocated gui ********************************************************************************************/
+ //gui - get allocated wms-Abstract and wms-Capabilities from allocated gui
- /*table with allocated wms-Abstract and wms-Capabilities from allocated gui ********************************************************************************************/
+ //table with allocated wms-Abstract and wms-Capabilities from allocated gui
#if (isset($cnt_show_gui_wms > 0))
}
if ($cnt_show_gui_wms > 0){
- /*get selected gui name for table caption ********************************************************************************************/
+ //get selected gui name for table caption
$sql_gui_table = "SELECT * FROM gui WHERE gui_id = $1";
$v = array($show_gui_configured_wms);
$t = array("s");
Modified: trunk/mapbender/http/javascripts/mod_changeEPSG.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_changeEPSG.php 2009-06-26 14:34:50 UTC (rev 4255)
+++ trunk/mapbender/http/javascripts/mod_changeEPSG.php 2009-06-26 14:58:28 UTC (rev 4256)
@@ -16,26 +16,16 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-require(dirname(__FILE__)."/../php/mb_validateSession.php");
-
-include(dirname(__FILE__)."/../include/dyn_js.php");
-
-echo "var myTarget = '".$e_target[0]."';";
-echo "var myId = '".$e_id."';";
?>
+var that = this;
var exists = false;
eventAfterMapRequest.register(function () {
mod_changeEPSG_setBox();
});
-eventInit.register(function () {
-// mod_changeEPSG_init();
-});
-
function mod_changeEPSG_setBox(){
- $("#"+myId+" option").each(function () {
+ $("#"+options.id+" option").each(function () {
if (this.value == mb_mapObj[0].epsg) {
isEPSG = true;
$(this).attr("selected", "selected");
@@ -43,7 +33,7 @@
});
}
-$("#"+myId).change(function () {
+$(this).change(function () {
var srsArray = [];
for (var i = 0; i < mb_mapObj.length; i++) {
var currentSrs = {
@@ -57,53 +47,53 @@
}
var req = new Mapbender.Ajax.Request({
- "method":"changeEpsg",
- "parameters":{
- "srs":srsArray,
- "newSrs": $("#"+myId).get(0).value
- }
- });
- req.send("../php/mod_changeEPSG_server.php", function (obj, success, message) {
- if (!success) {
- new Mb_exception("!!!!!!"+message);
- return;
- }
-
- var newExtent = obj;
-
- for(var i = 0; i < newExtent.length; i++) {
- if(newExtent[i].frameName == myTarget){
-
- var ind = getMapObjIndexByName(myTarget);
-
- for(var ii = 0; ii < mb_mapObj[ind].mb_MapHistoryObj.length; ii++) {
- if (mb_mapObj[ind].mb_MapHistoryObj[ii].epsg == newExtent[i].newSrs) {
- exists = ii;
- var goback = true;
+ url: "../php/mod_changeEPSG_server.php",
+ method: "changeEpsg",
+ parameters: {
+ srs: srsArray,
+ newSrs: $("#"+options.id).get(0).value
+ },
+ callback: function (obj, success, message) {
+ if (!success) {
+ new Mapbender.Exception(message);
+ return;
+ }
+
+ var newExtent = obj;
+
+ for (var i = 0; i < newExtent.length; i++) {
+ if(newExtent[i].frameName == options.target){
+
+ var map = Mapbender.modules[options.target];
+
+ for (var ii = 0; ii < map.mb_MapHistoryObj.length; ii++) {
+ if (map.mb_MapHistoryObj[ii].epsg == newExtent[i].newSrs) {
+ exists = ii;
+ var goback = true;
+ }
}
+
+ if (goback) {
+ map.epsg = newExtent[i].newSrs;
+ map.extent = map.mb_MapHistoryObj[exists].extent;
+ map.setMapRequest();
+ }
+ else{
+ map.epsg = newExtent[i].newSrs;
+ map.extent = parseFloat(newExtent[i].minx) + "," + parseFloat(newExtent[i].miny) + "," +
+ parseFloat(newExtent[i].maxx) + "," + parseFloat(newExtent[i].maxy);
+ map.setMapRequest();
+ }
}
-
- if (goback) {
- mb_mapObj[ind].epsg = newExtent[i].newSrs;
- mb_mapObj[ind].extent = mb_mapObj[ind].mb_MapHistoryObj[exists].extent;
- setMapRequest(newExtent[i].frameName);
- }
- else{
- mb_mapObj[ind].epsg = newExtent[i].newSrs;
- mb_mapObj[ind].extent = parseFloat(newExtent[i].minx) + "," + parseFloat(newExtent[i].miny) + "," +
+ else {
+ var map = Mapbender.modules[newExtent[i].frameName];
+ map.epsg = newExtent[i].newSrs;
+ map.extent = parseFloat(newExtent[i].minx) + "," + parseFloat(newExtent[i].miny) + "," +
parseFloat(newExtent[i].maxx) + "," + parseFloat(newExtent[i].maxy);
- setMapRequest(newExtent[i].frameName);
+ map.setMapRequest();
}
}
- else {
- var ind = getMapObjIndexByName(newExtent[i].frameName);
- mb_mapObj[ind].epsg = newExtent[i].newSrs;
- mb_mapObj[ind].extent = parseFloat(newExtent[i].minx) + "," + parseFloat(newExtent[i].miny) + "," +
- parseFloat(newExtent[i].maxx) + "," + parseFloat(newExtent[i].maxy);
- setMapRequest(newExtent[i].frameName);
- }
- }
-
-
+ }
});
+ req.send();
});
\ No newline at end of file
Modified: trunk/mapbender/http/javascripts/mod_log.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_log.php 2009-06-26 14:34:50 UTC (rev 4255)
+++ trunk/mapbender/http/javascripts/mod_log.php 2009-06-26 14:58:28 UTC (rev 4256)
@@ -1,13 +1,13 @@
-<?php
-require(dirname(__FILE__)."/../php/mb_validatePermission.php");
-?>
-mb_registerInitFunctions("mb_log_init()");
-function mb_log_init(){
- mb_log = "mb_log_set";
-}
-try{if(logtype){}}catch(e){logtype="";}
-function mb_log_set(req, time_client){
- var url = "../php/mod_log.php?<?php echo $urlParameters;?>&req=" + escape(req) + "&time_client=" + time_client;
- mb_ajax_post(url, {req:req, time:time_client});
- return true;
-}
\ No newline at end of file
+Mapbender.events.init.register(function () {
+ eventAfterMapRequest.register(function (options) {
+ var parameters = {
+ req : options.url,
+ time_client : Mapbender.getTimestamp()
+ };
+ var notification = new Mapbender.Ajax.Notification({
+ url: "../php/mod_log.php",
+ parameters: parameters
+ });
+ notification.send();
+ });
+});
Modified: trunk/mapbender/http/php/mod_log.php
===================================================================
--- trunk/mapbender/http/php/mod_log.php 2009-06-26 14:34:50 UTC (rev 4255)
+++ trunk/mapbender/http/php/mod_log.php 2009-06-26 14:58:28 UTC (rev 4256)
@@ -17,7 +17,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
+$ajaxResponse = new AjaxResponse($_REQUEST);
+
require(dirname(__FILE__)."/../include/dyn_php.php");
if($_REQUEST['req']){
Modified: trunk/mapbender/http/php/mod_wfs_conf_interface.js
===================================================================
--- trunk/mapbender/http/php/mod_wfs_conf_interface.js 2009-06-26 14:34:50 UTC (rev 4255)
+++ trunk/mapbender/http/php/mod_wfs_conf_interface.js 2009-06-26 14:58:28 UTC (rev 4256)
@@ -168,81 +168,88 @@
// get available WFS ("new" mode)
var getWfsFromDb = function (options) {
var req = new Mapbender.Ajax.Request({
- "method" : "getWfs",
- "parameters" : {}
+ method : "getWfs",
+ parameters : {},
+ url: "../php/mod_wfs_conf_server.php",
+ callback: function(result, success, message) {
+ if (result !== null) {
+ wfsArray = result;
+ }
+ if (typeof options !== "object") {
+ return;
+ }
+ if (typeof options.callback === "function") {
+ options.callback(wfsArray);
+ }
+ }
});
- req.send("../php/mod_wfs_conf_server.php", function(result, success, message) {
- if (result !== null) {
- wfsArray = result;
- }
- if (typeof options !== "object") {
- return;
- }
- if (typeof options.callback === "function") {
- options.callback(wfsArray);
- }
- });
-
+ req.send();
};
// get available WFS configurations ("edit" mode)
var getWfsConfsFromDb = function (options) {
var req = new Mapbender.Ajax.Request({
- "method" : "getWfsConfs",
- "parameters" : {}
+ method : "getWfsConfs",
+ parameters : {},
+ url: "../php/mod_wfs_conf_server.php",
+ callback: function (result, success, message) {
+ if (result !== null) {
+ wfsConfArray = result;
+ }
+ if (typeof options !== "object") {
+ return;
+ }
+ if (typeof options.callback === "function") {
+ options.callback(wfsConfArray);
+ }
+ }
});
- req.send("../php/mod_wfs_conf_server.php", function (result, success, message) {
- if (result !== null) {
- wfsConfArray = result;
- }
- if (typeof options !== "object") {
- return;
- }
- if (typeof options.callback === "function") {
- options.callback(wfsConfArray);
- }
- });
+ req.send();
};
var updateWfsConfInDb = function (wfsConf) {
var req = new Mapbender.Ajax.Request({
- "method" : "updateWfsConf",
- "parameters": {
+ method : "updateWfsConf",
+ parameters: {
"wfsConf": wfsConf
+ },
+ url: "../php/mod_wfs_conf_server.php",
+ callback: function(result, success, message) {
+ isNotBusy.trigger();
+ alert(message);
}
});
isBusy.trigger();
- req.send("../php/mod_wfs_conf_server.php", function(result, success, message) {
- isNotBusy.trigger();
- alert(message);
- });
+ req.send();
};
var insertWfsConfIntoDb = function (wfsConf) {
var req = new Mapbender.Ajax.Request({
- "method" : "insertWfsConf",
- "parameters": {
+ method : "insertWfsConf",
+ parameters: {
"wfsConf": wfsConf
+ },
+ url: "../php/mod_wfs_conf_server.php",
+ callback: function(result, success, message) {
+ if (success) {
+ $("#wfs_conf_id").val(result.id);
+
+ // update WFS conf array (add the latest entry)
+ getWfsConfsFromDb({
+ "callback": function(wfsConfArray) {
+ isNotBusy.trigger();
+ alert(message);
+ }
+ });
+ }
+ else {
+ isNotBusy.trigger();
+ alert(message);
+ }
}
});
isBusy.trigger();
- req.send("../php/mod_wfs_conf_server.php", function(result, success, message) {
- if (success) {
- $("#wfs_conf_id").val(result.id);
-
- // update WFS conf array (add the latest entry)
- getWfsConfsFromDb({
- "callback": function(wfsConfArray) {
- isNotBusy.trigger();
- alert(message);
- }
- });
- }
- else {
- isNotBusy.trigger();
- alert(message);
- }
- });
+ req.send();
};
var getWfsById = function (id) {
Modified: trunk/mapbender/lib/ajax.js
===================================================================
--- trunk/mapbender/lib/ajax.js 2009-06-26 14:34:50 UTC (rev 4255)
+++ trunk/mapbender/lib/ajax.js 2009-06-26 14:58:28 UTC (rev 4256)
@@ -4,95 +4,68 @@
* License (>=v2). Read the file gpl.txt that comes with Mapbender for details.
*/
-
-/*
- ***************************************************************************************
- * AJAX wrapper functions
- ***************************************************************************************
- */
/**
- * A wrapper for an AJAX request via GET
+ * Package: Ajax
*
- * @deprecated
- * @param {String} url the URL of a (presumably a server side) script.
- * @param {Object} param An object containing parameters, f.e. {name1:value1, name2:value2}
- * @param {Function} callback A function that is called when the server side script has been processed. The function is called with two parameters, result and status. Result is the output of the server side script (XML, HTML, whatever), status is a {String}, either "success" or "error".
+ * Description:
+ * An AJAX wrapper for client server interaction via JSON RPC
+ *
+ * Files:
+ * - lib/ajax.js
+ *
+ * Help:
+ * <none>
*/
-function mb_ajax_get(url, param, callback) {
- try {
-// $.ajaxSetup({async:false});
- $.get(url, param, callback);
+Mapbender.Ajax = {
+ /**
+ * Property: requestCount
+ *
+ * Description:
+ * counts the number of requests that have been made
+ */
+ requestCount: 0,
+ Messages: {
+ fatalError: "A fatal error occured.",
+ idMismatchError: "The ID of the response is not equal to the ID of the request."
}
- catch(e) {
- var error = new Mb_exception('map.php: mb_ajax_get:'+e);
- }
-}
+};
/**
- * A wrapper for an AJAX request via POST
+ * Package: Notification
+ *
+ * Description:
+ * An AJAX notification (it doesn't expect a reply from the server)
+ *
+ * Files:
+ * - lib/ajax.js
*
- * @deprecated
- * @param {String} url the URL of a (presumably a server side) script.
- * @param {Object} param An object containing parameters, f.e. {name1:value1, name2:value2}
- * @param {Function} callback A function that is called when the server side script has been processed. The function is called with two parameters, result and status. Result is the output of the server side script (XML, HTML, whatever), status is a {String}, either "success" or "error".
+ * Help:
+ * <none>
*/
-function mb_ajax_post(url, param, callback) {
- try {
-// $.ajaxSetup({async:false});
- $.post(url, param, callback);
- }
- catch(e) {
- var error = new Mb_exception('map.php: mb_ajax_post:'+e);
- }
-}
-
/**
- * A wrapper for an AJAX request via GET
- *
- * @deprecated
- * @param {String} url the URL of a (presumably a server side) script.
- * @param {Object} param An object containing parameters, f.e. {name1:value1, name2:value2}
- * @param {Function} callback A function that is called when the server side script has been processed. The function is called with two parameters, result and status. Result is the output of the server side script (a JavaScript Object, not a String!), status is a {String}, either "success" or "error".
+ * Constructor: Mapbender.Ajax.Request
+ *
+ * Parameters:
+ * options.url - (String) The URL or the server side script
+ * options.type - *[optional]* (String) "POST" (default) or "GET"
+ * options.log - *[optional]* (Boolean) logs the request
+ * as Mapbender.Notice (default: false)
+ * options.method - *[optional]* (String) The name of the method that
+ * is called on the server side (default: "")
+ * options.parameters - *[optional]* (Object) arguments being passed to
+ * the method given above
+ * <deprecated variable name> - *[deprecated]* <type and description>
*/
-function mb_ajax_json(url, param, callback) {
- try {
-// window.frames['ajax'].$.ajaxSetup({async:false}); //TODO: find out why async doesn't work sometimes
- $.getJSON(url, param, callback);
+Mapbender.Ajax.Notification = function (options) {
+ if (typeof options === "object") {
+ var url = (options.url) ? options.url : "";
+ var type = (options.type) ? options.type.toUpperCase() : "POST";
+ var log = (options.log) ? options.log : false;
+ var method = (options.method) ? options.method : "";
+ var parameters = (options.parameters) ? options.parameters : {};
}
- catch(e) {
- var error = new Mb_exception('map.php: mb_ajax_json:'+e);
- }
-}
-
-Mapbender.Ajax = {
- requestCount: 0,
- Messages: {
- "fatalError": "A fatal error occured.",
- "idMismatchError": "The ID of the response is not equal to the ID of the request."
- }
-};
-
-Mapbender.Ajax.Notification = function () {
- /**
- * The method to call on the server
- */
- var method = "";
-
- /**
- * The parameters to pass to the above method
- */
- var parameters = {};
- this.setMethod = function (aMethod) {
- method = aMethod.toString();
- };
-
- this.setParameter = function (key, value) {
- parameters[key] = value;
- return true;
- };
-
- this.send = function (type, url) {
+ this.send = function () {
switch (type.toUpperCase()) {
case "POST" :
$.post(url, getParameters(), function () {
@@ -103,6 +76,8 @@
});
break;
default:
+ new Mapbender.Exception("Invalid type (" + type +
+ ") in Mapbender.Ajax.Notification.");
return false;
}
return true;
@@ -115,64 +90,76 @@
"id": null
};
}
-
}
+
+/**
+ * Package: Request
+ *
+ * Description:
+ * An AJAX request (it expects a reply from the server)
+ *
+ * Files:
+ * - lib/ajax.js
+ *
+ * Help:
+ * <none>
+ */
+/**
+ * Constructor: Mapbender.Ajax.Request
+ *
+ * Parameters:
+ * options.url - (String) The URL to the server side script
+ * options.type - *[optional]* (String) "POST" (default) or "GET"
+ * options.log - *[optional]* (Boolean) logs the request
+ * as Mapbender.Notice (default: false)
+ * options.method - *[optional]* (String) The name of the method that
+ * is called on the server side (default: "")
+ * options.parameters - *[optional]* (Object) arguments being passed to
+ * the method given above
+ * options.callback - (Function) Will be called after the request
+ * is finished
+ * options.scope - *[optional]* (Object) the callback will
+ * be executed within the scope of this object
+ */
Mapbender.Ajax.Request = function (options) {
- /**
- * "POST" or "GET"
- */
- var type = (typeof(options) == "object" && options.type) ? options.type.toUpperCase() : "POST";
-
- /**
- * result of request will be logged as Mb_notice
- */
- var log = (typeof(options) == "object" && options.log) ? options.log : false;
-
- /**
- * The method to call on the server
- */
- var method = (typeof(options) == "object" && options.method) ? options.method : "";
+ if (typeof options === "object") {
+ var url = (options.url) ? options.url : "";
+ var type = (options.type) ? options.type.toUpperCase() : "POST";
+ var log = (options.log) ? options.log : false;
+ var method = (options.method) ? options.method : "";
+ var parameters = (options.parameters) ? options.parameters : {};
+ var callback = (options.callback) ? options.callback : null;
+ var scope = (options.scope) ? options.scope : null;
+ }
+ else {
+ new Mapbender.Exception("No options specified in " +
+ "Mapbender.Ajax.Notification.");
+ return;
+ }
- /**
- * The parameters to pass to the above method
- */
- var parameters = (typeof(options) == "object" && options.parameters) ? options.parameters : {};
-
- /**
- * A unique identifier for this Ajax request
- */
+ // A unique identifier for this Ajax request
var id = ++Mapbender.Ajax.requestCount;
- /**
- * The result object, coming from the server
- */
+ // The result object, coming from the server
var result = {};
- /**
- * A message coming from the server
- */
+ // A message coming from the server
var message = "";
- /**
- * Did the request succeed?
- */
+ // Did the request succeed?
var success = false;
- /**
- * Did an internal error occur
- */
+ // Did an internal error occur
var internalError = false;
- /**
- * Checks if the response is valid.
- *
- * @param {String} json
- * @param {String} status
- */
+ // Did the session expire
+ var sessionExpired = false;
+
+ // Checks if the response is valid.
var receive = function (json, status) {
if (!json) {
message = Mapbender.Ajax.Messages.fatalError;
- new Mb_warning(message);
+ new Mapbender.Warning(message);
internalError = true;
return;
}
@@ -180,7 +167,7 @@
// some severe error has occured
if (typeof(resultObj) != "object" || status != "success") {
message = Mapbender.Ajax.Messages.fatalError;
- new Mb_warning(message);
+ new Mapbender.Warning(message);
internalError = true;
return;
}
@@ -195,7 +182,10 @@
if (resultObj.error.code == -1) {
internalError = true;
}
- new Mb_warning(message);
+ else if (resultObj.error.code == -2) {
+ sessionExpired = true;
+ }
+ new Mapbender.Warning(message);
return;
}
@@ -205,7 +195,7 @@
if (id != resultObj.id) {
message = Mapbender.Ajax.Messages.idMismatchError;
- new Mb_warning(message);
+ new Mapbender.Warning(message);
internalError = true;
return;
}
@@ -221,19 +211,36 @@
return;
}
- this.send = function (url, callback, scope) {
+ /**
+ * Method: send
+ *
+ * Description:
+ * Sends the request to the server side
+ */
+ this.send = function () {
internalError = false;
+ sessionExpired = false;
success = false;
var callbackWrapper = function (json, status) {
receive(json, status);
+ if (sessionExpired) {
+ alert(message);
+ window.location.reload();
+ return;
+ }
if (!internalError) {
- new Mb_notice("REQUEST #" + id + ": " + url + "\n\n" +
+ new Mapbender.Notice("REQUEST #" + id + ": " + url + "\n\n" +
"RESULT: " + $.toJSON(result) + "\n\n" +
"SUCCESS: " + success + "\n\n" +
"MESSAGE: " + message);
- if (scope !== undefined) {
+ if (typeof callback === null) {
+ new Mapbender.Warning("No callback function in " +
+ "Mapbender.Ajax.Request.");
+ return;
+ }
+ if (scope !== null) {
callback.apply(scope, [result, success, message]);
}
else {
Modified: trunk/mapbender/lib/ajax.php
===================================================================
--- trunk/mapbender/lib/ajax.php 2009-06-26 14:34:50 UTC (rev 4255)
+++ trunk/mapbender/lib/ajax.php 2009-06-26 14:58:28 UTC (rev 4256)
@@ -18,6 +18,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
require_once(dirname(__FILE__) . "/../http/classes/class_json.php");
+require_once(dirname(__FILE__) . "/class_Mapbender.php");
/**
* Represents an incoming JSON-RPC. It will NOT send a response to the client!
@@ -134,6 +135,16 @@
$this->message = _mb("Fatal error: Could not detect ID of AJAX request.");
$this->send();
}
+
+ if (!Mapbender::session()->get("mb_user_id") ||
+ !Mapbender::session()->get("mb_user_ip") ||
+ Mapbender::session()->get("mb_user_ip") != $_SERVER['REMOTE_ADDR']) {
+ $this->setSuccess(false);
+ $this->error = array(
+ "code" => -2,
+ "message" => _mb("The session has expired. Please log in again.")
+ );
+ }
}
/**
@@ -186,10 +197,12 @@
$dataObject["message"] = $this->message;
}
else {
- $this->error = array(
- "code" => -1,
- "message" => $this->message
- );
+ if (is_null($this->error)) {
+ $this->error = array(
+ "code" => -1,
+ "message" => $this->message
+ );
+ }
}
$obj = array(
"result" => $dataObject,
Modified: trunk/mapbender/lib/basic.js
===================================================================
--- trunk/mapbender/lib/basic.js 2009-06-26 14:34:50 UTC (rev 4255)
+++ trunk/mapbender/lib/basic.js 2009-06-26 14:58:28 UTC (rev 4256)
@@ -1,11 +1,6 @@
-var ie = document.all?1:0;
-var n6 = document.getElementById&&!document.all?1:0;
-var n4 = document.layers?1:0;
-
var clickX;
var clickY;
-var mb_log = null;
// transparent GIF
@@ -75,11 +70,6 @@
return c;
}
-function mb_timestamp(){
- var d = new Date();
- var ts = Math.round(Date.parse(d)/1000);
- return ts;
-}
/**
* @deprecated
Modified: trunk/mapbender/lib/exception.js
===================================================================
--- trunk/mapbender/lib/exception.js 2009-06-26 14:34:50 UTC (rev 4255)
+++ trunk/mapbender/lib/exception.js 2009-06-26 14:58:28 UTC (rev 4256)
@@ -4,111 +4,139 @@
* License (>=v2). Read the file gpl.txt that comes with Mapbender for details.
*/
-
-/*
- ***************************************************************************************
- * Javascript exception handling
- ***************************************************************************************
- */
-
-/**
- * @class An abstract class, logs JavaScript events like errors, warnings etc.
- *
- * @constructor
- */
-function Mb_log () {
- var that = this;
+(function () {
- var levelArray = global_log_levels.split(",");
- var log_level = global_mb_log_level;
- var log_js = global_mb_log_js;
-
- var indexOfLevel = function(aLevel) {
- for (var i = 0; i < levelArray.length; i++) {
- if (aLevel == levelArray[i]) {
- return i;
- }
- }
- return false;
- };
- var isValidLevel = function(aLevel) {
- var isNotOff = typeof(log_js) != 'undefined' && log_js != "off";
- var levelIndex = indexOfLevel(aLevel);
- var isAppropriate = (typeof(levelIndex)=='number' && levelIndex <= indexOfLevel(log_level));
- return (isNotOff && isAppropriate);
- };
- this.throwException = function (message, level) {
- if (isValidLevel(level)) {
- if (log_js == "on") {
- try {
- mb_ajax_post('../php/mb_js_exception.php', {level:level,text:message});
+ //An abstract class, logs JavaScript events like errors, warnings etc.
+ function Mb_log () {
+ var that = this;
+
+ var levelArray = global_log_levels.split(",");
+ var log_level = global_mb_log_level;
+ var log_js = global_mb_log_js;
+
+ var indexOfLevel = function(aLevel) {
+ for (var i = 0; i < levelArray.length; i++) {
+ if (aLevel == levelArray[i]) {
+ return i;
}
- catch(e) {
- alert(e + ": " + message);
- }
}
- else if (log_js == "alert") {
- alert(message);
- }
- else if (log_js == "console") {
- if ($.browser.msie) {
+ return false;
+ };
+ var isValidLevel = function(aLevel) {
+ var isNotOff = typeof(log_js) != 'undefined' && log_js != "off";
+ var levelIndex = indexOfLevel(aLevel);
+ var isAppropriate = (typeof(levelIndex)=='number' && levelIndex <= indexOfLevel(log_level));
+ return (isNotOff && isAppropriate);
+ };
+ this.throwException = function (message, level) {
+ if (isValidLevel(level)) {
+ if (log_js == "on") {
try {
mb_ajax_post('../php/mb_js_exception.php', {level:level,text:message});
}
catch(e) {
alert(e + ": " + message);
}
-
}
- else {
- if (level == "warning") {
- console.warn("%s", message);
+ else if (log_js == "alert") {
+ alert(message);
+ }
+ else if (log_js == "console") {
+ if ($.browser.msie) {
+ try {
+ mb_ajax_post('../php/mb_js_exception.php', {level:level,text:message});
+ }
+ catch(e) {
+ alert(e + ": " + message);
+ }
+
}
- else if (level == "error") {
- console.error("%s", message);
- }
else {
- console.log("%s", message);
+ if (level == "warning") {
+ console.warn("%s", message);
+ }
+ else if (level == "error") {
+ console.error("%s", message);
+ }
+ else {
+ console.log("%s", message);
+ }
}
}
}
- }
- };
-};
+ };
+ };
+
+ /**
+ * Class: Exception
+ *
+ * Description:
+ * Logs an exception in the log file, in a console window or as an alert
+ *
+ * Files:
+ * - lib/exception.js
+ *
+ * Help:
+ * <none>
+ */
+ /**
+ * Constructor: Exception
+ *
+ * Parameters:
+ * message - A message that is being logged
+ */
+ Mapbender.Exception = function (message) {
+ var level = "error";
+ this.throwException(message, level);
+ }
+ Mapbender.Exception.prototype = new Mb_log();
+
+ /**
+ * Class: Warning
+ *
+ * Description:
+ * Logs an warning in the log file, in a console window or as an alert
+ *
+ * Files:
+ * - lib/exception.js
+ *
+ * Help:
+ * <none>
+ */
+ /**
+ * Constructor: Warning
+ *
+ * Parameters:
+ * message - A message that is being logged
+ */
+ Mapbender.Warning = function (message) {
+ var level = "warning";
+ this.throwException(message, level);
+ }
+ Mapbender.Warning.prototype = new Mb_log();
+
+ /**
+ * Package: Notice
+ *
+ * Description:
+ * Logs a notice in the log file, in a console window or as an alert
+ *
+ * Files:
+ * - lib/exception.js
+ *
+ * Help:
+ * <none>
+ */
+ /**
+ * Constructor: Notice
+ *
+ * Parameters:
+ * message - A message that is being logged
+ */
+ Mapbender.Notice = function (message) {
+ var level = "notice";
+ this.throwException(message, level);
+ }
+ Mapbender.Notice.prototype = new Mb_log();
-/**
- * class for exception logging
- *
- * @extends {@link Mb_log}
- * @param message the message that is being logged
- */
-function Mb_exception(message) {
- var level = "error";
- this.throwException(message, level);
-}
-Mb_exception.prototype = new Mb_log();
-
-/**
- * class for warning logging
- *
- * @extends {@link Mb_log}
- * @param message the message that is being logged
- */
-function Mb_warning(message) {
- var level = "warning";
- this.throwException(message, level);
-}
-Mb_warning.prototype = new Mb_log();
-
-/**
- * class for notice logging
- *
- * @extends {@link Mb_log}
- * @param message the message that is being logged
- */
-
-function Mb_notice(message) {
- var level = "notice";
- this.throwException(message, level);
-}
-Mb_notice.prototype = new Mb_log();
\ No newline at end of file
+})();
More information about the Mapbender_commits
mailing list