[Mapbender-commits] r4381 - in branches/kmq_dev/http: classes javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Jul 17 04:54:28 EDT 2009


Author: kmq
Date: 2009-07-17 04:54:27 -0400 (Fri, 17 Jul 2009)
New Revision: 4381

Added:
   branches/kmq_dev/http/classes/class_RPCEndpoint.php
   branches/kmq_dev/http/classes/class_group.php
   branches/kmq_dev/http/javascripts/group.php
Modified:
   branches/kmq_dev/http/classes/class_user.php
   branches/kmq_dev/http/javascripts/ConfEditor.js
   branches/kmq_dev/http/javascripts/ConfObject.js
   branches/kmq_dev/http/javascripts/mod_AdminTabs.js
   branches/kmq_dev/http/javascripts/mod_group.js
   branches/kmq_dev/http/javascripts/mod_user.js
   branches/kmq_dev/http/javascripts/user.php
Log:
Generalized client an server side

Added: branches/kmq_dev/http/classes/class_RPCEndpoint.php
===================================================================
--- branches/kmq_dev/http/classes/class_RPCEndpoint.php	                        (rev 0)
+++ branches/kmq_dev/http/classes/class_RPCEndpoint.php	2009-07-17 08:54:27 UTC (rev 4381)
@@ -0,0 +1,235 @@
+<?php
+
+require_once(dirname(__FILE__)."/../classes/class_user.php");
+
+interface RPCObject{
+
+  public function create();
+  public function change($changes);
+  public function commit();
+  public function remove();
+  public function load();
+  public function getFields();
+  public static function getList($filter);
+  public static function byName($name);
+
+}
+
+class RPCEndpoint {
+  
+  var $ObjectConf;
+  var $ajaxResponse;
+
+  var $method;
+
+  public function __construct ($ObjectConf,$ajaxResponse){
+    $this->ObjectConf = $ObjectConf;
+    $this->ajaxResponse = $ajaxResponse;
+    $this->method = $this->ajaxResponse->getMethod();
+  }
+
+  // When we upgrade to 5.3.0 this needs to desperately upgraded to
+  // "Added support for dynamic access of static members using $foo::myFunc(). (Etienne Kneuss)"
+  // from http://php.net/ChangeLog-5.php
+  // so we can get rid of this sillyness here
+  public function RPCObjectByName($name){
+
+    switch($this->ObjectConf['ClassName']){
+
+      case 'User':
+        return User::byName($name);
+
+      case 'Group':
+        return Group::byName($name);
+      
+      default:
+        // or throw exception ?
+        return null;
+    }
+
+  }
+
+  public function RPCObjectGetList(){
+    
+    switch($this->ObjectConf['ClassName']){
+
+      case 'User':
+        return User::getList("");
+
+      case 'Group':
+        return Group::getList("");
+
+      default:
+        return null;
+    }
+  }
+
+  public function run(){
+
+    switch($this->method)
+    {
+      case 'create':
+        try{
+          $this->rpc_create($this->ajaxResponse->getParameter('fields'));
+        }catch(Exception $E){
+          $this->ajaxResponse->setMessage("Create failed. Error: " . $E);
+        }
+        break;
+
+      case 'update':
+        try{
+          $this->rpc_update($this->ajaxResponse->getParameter('name'),$this->ajaxResponse->getParameter('fields'));
+        }catch(Exception $E){
+          $this->ajaxResponse->setMessage("Update failed. Error: " . $E);
+        }
+          
+        break;
+
+      case 'delete':
+        try{
+          $this->rpc_delete($this->ajaxResponse->getParameter('name'));
+        }catch(Exception $E){
+          $this->ajaxResponse->setMessage("Delete failed. Error: " . $E);
+        }
+        break;
+
+      case 'load':
+        try{
+          $this->rpc_load($this->ajaxResponse->getParameter('name'));
+        }catch(Exception $E){
+          $this->ajaxResponse->setMessage("Load failed. Error: " . $E);
+        }
+        break;
+
+      case 'list':
+        try{
+          $this->rpc_list();
+        }catch(Exception $E){
+          $this->ajaxResponse->setMessage("List failed. Error: " + $E);
+        }
+        break;
+
+      default:
+          $this->ajaxResponse->setSuccess(false);
+          $this->ajaxResponse->setMessage(_mb("invalid method"));
+    }
+
+    $this->ajaxResponse->send();
+  
+    
+  }
+
+  public function rpc_create($fields){
+    $instance = new $this->Object(null);
+    try {
+        $instance->change($fields);
+    }
+    catch (Exception $E)
+    {
+      $this->ajaxResponse->setSuccess(false);
+      $this->ajaxResponse->setMessage(_mb("Could not create "). $this->ObjectConf['internalName'] . "  Error: " . $E);
+    }
+    
+    try{
+        $instance->create();
+    }
+    catch(Exception $E)
+    {
+      $this->ajaxResponse->setSuccess(false);
+      $this->ajaxResponse->setMessage(_mb("Could not create instance "). $this->ObjectConf['internalName'] . " Error: ". $E );
+    }
+  
+  }
+
+  public function rpc_update($name,$fields){
+    $instance = $this->RPCObjectByName($name);
+    if($instance == null)
+    {
+      $this->ajaxResponse->setSuccess(false);
+      $this->ajaxResponse->setMessage(_mb($this->ObjectConf['internalName'] . _mb(" does not exist: ". $name)));
+    }
+    try{
+        $instance->change($fields);
+    }
+    catch(Exception $E)
+    {
+      $this->ajaxResponse->setSuccess(false);
+      $this->ajaxResponse->setMessage(_mb("Could not change "). $this->ObjectConf['internalName'] . " Error: " .$E);
+    }
+
+    try{
+        $instance->commit();
+    }
+    catch(Exception $E)
+    {
+      $this->ajaxResponse->setSuccess(false);
+      $this->ajaxResponse->setMessage(_mb("Could not change "). $this->ObjectConf['internalName'] . " Error: " . $E);
+    }
+
+  }
+
+  public function rpc_delete($name){
+    $instance = $this->RPCObjectByName($name);
+    if($instance == null)
+    {
+      $this->ajaxResponse->setSuccess(true);
+      $this->ajaxResponse->setMessage(_mb("No such "). $this->ObjectConf['internalName']);
+      break;
+    }
+    try{
+        $instance->remove();
+    }
+    catch(Exception $E)
+    {
+      $this->ajaxResponse->setSuccess(false);
+      $this->ajaxResponse->setMessage(_mb("Could not delete "). $this->ObjectConf['internalName'] . " Error: ". $E);
+    }
+
+  }
+
+  public function rpc_load($name){
+    $instance = $this->RPCObjectByName($name);
+    if($instance == null)
+    {
+      $this->ajaxResponse->setSuccess(true);
+      $this->ajaxResponse->setMessage(_mb("No such ". $this->ObjectConf['internalName'] .": $name"));
+      $this->ajaxResponse->setResult("error",true);
+      break;
+    }
+  try{
+    $instance->load();
+    $result = $instance->getFields();
+  }
+  catch(Exception $E)
+  {
+      $this->ajaxResponse->setSuccess(true);
+      $this->ajaxResponse->setMessage(_mb("Could not load data: "). $this->ObjectConf['internalName'] ." Error: " . $E);
+      $this->ajaxResponse->setResult("error",true);
+  }
+  $this->ajaxResponse->setResult("data",$result);
+
+  }
+
+  public function rpc_list(){
+    $result = array();
+    $instances = array();
+    $instances = $this->RPCObjectGetList('');
+    if(!$instances)
+    {
+      $this->ajaxResponse->setSuccess(false);
+      $this->ajaxResponse->setMessage(_mb("Error fetching list of "). $this->ObjectConf['internalName']);
+      return;
+    }
+    
+    foreach( $instances as $instance)
+    {
+      $result[] = array("name" =>  $instance->name, "value" => $instance->name);
+    }
+    $this->ajaxResponse->setResult("list",$result);
+    $this->ajaxResponse->setResult("type", array("display" => $this->ObjectConf['displayName'], 
+                                           "internal" => $this->ObjectConf['internalName']));
+
+  }
+
+}
+?>

Added: branches/kmq_dev/http/classes/class_group.php
===================================================================
--- branches/kmq_dev/http/classes/class_group.php	                        (rev 0)
+++ branches/kmq_dev/http/classes/class_group.php	2009-07-17 08:54:27 UTC (rev 4381)
@@ -0,0 +1,239 @@
+<?php
+# $Id: class_kml_geometry.php 1966 2008-01-15 08:25:15Z christoph $
+# http://www.mapbender.org/index.php/class_wmc.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# 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_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_RPCEndpoint.php");
+
+/**
+ * A Mapbender user as described in the table mb_group.
+ */
+class Group implements RPCObject {
+	/**
+	 * @var Integer The Group ID
+	 */
+	var $id;
+	var $name;
+	var $owner = 0;  
+	var $description ="";
+
+    static $displayName = "Group";
+    static $internalName = "group";
+	
+	/**
+	 * Constructor
+	 * @param $groupId Integer 	the ID of the group that is represented by 
+	 * 							this object.
+	 */
+	public function __construct ($groupId) {
+		$this->id = $groupId;
+		try{
+			if($groupId) {$this->load();}
+		}
+		catch(Exception $E)
+		{	
+			new mb_exception($E->getMessage());
+		}
+
+	}	
+
+	
+	/**
+	 * @return String the ID of this group
+	 */
+	public function __toString () {
+		return (string) $this->id;	
+	}
+
+	/*
+	* @return JSON serialization of this group
+	*/
+    //This is useless, the Ajaxode does this for me
+	public function toJSON() {
+			
+		$result = '{"name":"'. 				$this->name .'",'
+							.'"owner":"'. 			$this->owner .'",'
+							.'"description":"'. 			$this->description .'"}';
+
+		return $result;
+	}
+
+    /*
+    * @return Assoc Array containing the fields to send to the user
+    */
+    public function getFields() {
+      return array(
+        "name" => $this->name,
+        "owner" => $this->owner,
+        "description" => $this->description
+      );
+    }
+
+	public function  create() {
+		if($this->name == ""){ $e = new Exception("Can' t create group without name");}
+		
+		$sql_group_create = "INSERT INTO mb_group (mb_group_name) VALUES ('". $this->name ."');";
+		$v = array($this->name);
+		$t = array("s");
+	
+		db_begin();
+		
+		$insert_result = db_query($sql_group_create);
+		if($insert_result == false)
+		{
+			db_rollback();
+			$e = new Exception("Could not insert new group");
+		}
+
+		$id = db_insertid($insert_result,'mb_group','mb_group_id');
+		if($id != 0)
+		{
+			$this->id = $id;
+		}
+	
+		$commit_result = $this->commit();
+		if($commit_result == false)
+		{
+			try {
+				db_rollback();
+			}
+			catch(Exception $E)
+			{
+				$newE = new Exception("Could not set inital values of new group");
+				throw $newE;
+			}
+		}
+
+
+		db_commit();
+
+
+	}
+
+
+	/*
+	*	@param	$changes JSON  keys and their values of what to change in the object
+	*/
+	public function change($changes) {
+
+		$this->name = $changes->name ? $changes->name : $this->name;
+		$this->owner = $changes->owner ? $changes->owner : $this->owner;
+		$this->description = $changes->description ? $changes->description : $this->description;
+		$this->id = $changes->id ? $changes->id : $this->id;
+
+        return true;
+	}
+
+	public function commit() {
+
+		$sql_update = "UPDATE mb_group SET ".
+			"mb_group_name = $1, ".
+			"mb_group_owner = $2, ".
+			"mb_group_description = $3, ".
+			"WHERE mb_group_id = $17;";
+
+
+			$v = array($this->name,
+									$this->owner,
+									$this->description,
+									$this->id);
+
+			$t = array("s", "i", "s", "i");
+
+			$update_result = db_prep_query($sql_update,$v,$t);
+			if(!$update_result)
+			{
+				throw new Exception("Database error updating Group");
+			}
+
+		return true;
+	}
+
+	public function remove() {
+
+		$sql_group_remove = "DELETE FROM mb_group WHERE mb_group_id = $1";
+		$v = array($this->id);
+		$t = array("i");
+		$result = db_prep_query($sql_group_remove,$v,$t);
+		
+		if($result == false)
+		{
+			$e = new mb_exception("Database error deleting group");
+		}
+		return true;
+	}
+
+	public function load() {
+		$sql_group = "SELECT * from mb_group WHERE mb_group_id = $1; ";
+		$v = array($this->id);
+		$t = array("i");
+		$res_group = db_prep_query($sql_group,$v,$t);
+		if($row = db_fetch_array($res_group)){
+
+			$this->name = $row['mb_group_name'];
+			$this->owner = $row['mb_group_owner'];
+			$this->description	= $row['mb_group_description'];
+
+		}else{
+			 throw new Exception("no such group");
+		}
+		return true;
+	}
+
+    /*
+    * @return Array of groups
+    * @param $filter UNUSED! string that must be contained in the username
+    */
+    public static function getList($filter) {
+      $users = Array();
+      $sql_grouplist = "SELECT mb_group_id FROM mb_group";
+      $res_groups = db_query($sql_grouplist);
+
+      while($row = db_fetch_array($res_groups))
+      {
+        try{
+          $users[] = new Group($row['mb_group_id']);
+        }
+        catch(Exception $E)
+        {
+          continue;
+          //FIXME: should catch some errors here
+        }
+      }
+      return $users;
+      
+    }
+
+    /*
+    * tries to initialize a Groupobject by Name
+    * @return A group Object
+    * @param $name the name of the group to find
+    */
+
+    public static function byName($name) {
+      $sql_group = "SELECT mb_group_id FROM mb_group WHERE mb_group_name = '$name'";
+      $res_group = db_query($sql_group);
+      if($row = db_fetch_array($res_group))
+      {
+        return  new Group($row['mb_group_id']);
+      }
+      return null;
+
+    }
+	}
+?>

Modified: branches/kmq_dev/http/classes/class_user.php
===================================================================
--- branches/kmq_dev/http/classes/class_user.php	2009-07-16 15:20:05 UTC (rev 4380)
+++ branches/kmq_dev/http/classes/class_user.php	2009-07-17 08:54:27 UTC (rev 4381)
@@ -18,11 +18,12 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/..//classes/class_RPCEndpoint.php");
 
 /**
  * A Mapbender user as described in the table mb_user.
  */
-class User {
+class User implements RPCObject{
 	/**
 	 * @var Integer The user ID
 	 */
@@ -101,7 +102,33 @@
         );
 		return $result;
 	}
+	
+    public function getFields() {
+			
+        $result = array(
+                            "name" => $this->name,
+							"password" =>  "*************",
+							"owner" => $this->owner, 
+							"description" => $this->descr, 
+							"loginCount" => $this->loginCount, 
+							"email" => $this->email, 
+							"phone" => $this->phone, 
+							"department" => $this->department, 
+							"resolution" => $this->resolution, 
+							"organization" => $this->organizatin, 
+							"position" => $this->position, 
+							"phone1" => $this->phone1,	
+							"fax" => $this->fax,	
+							"deliveryPoint" => $this->deliveryPoint,	
+							"city" => $this->city,	
+							"postalCode" => $this->postalCode,	
+							"country" => $this->country,	
+							"url" => $this->url	
 
+        );
+		return $result;
+	}
+
 	public function  create() {
 		//FIXME: can users exist that have the same name? I think not, but the db does not enforce it
 		if($this->name == ""){ $e = new Exception("Can' t create user without name");}
@@ -284,7 +311,7 @@
     public static function getList($filter) {
     //FIXME: optimize
       $users = Array();
-      $sql_userlist = "SELECT mb_user_id FROM mb_user";
+      $sql_userlist = "SELECT mb_user_id FROM mb_user ORDER BY mb_user_name";
       $res_users = db_query($sql_userlist);
 
       while($row = db_fetch_array($res_users))

Modified: branches/kmq_dev/http/javascripts/ConfEditor.js
===================================================================
--- branches/kmq_dev/http/javascripts/ConfEditor.js	2009-07-16 15:20:05 UTC (rev 4380)
+++ branches/kmq_dev/http/javascripts/ConfEditor.js	2009-07-17 08:54:27 UTC (rev 4381)
@@ -1,113 +1,102 @@
-
-// This function creates  and returns constructor functions
-// configured for each type of derived Editor
-// this removes the need to  call the superconstructor
-
-var ConfObjectEditorConstructor = function(ObjectType,element,options){
-  return  function(){
-  this.element = element;
-  this.options = options;
-  this.list = null;
-  this.confObject = null;
-  this.confObjectType = ObjectType;
-  this.modified = false;
+var ConfEditor = function(){
 };
-};
 
-
-/*Editor Base Object*/
-var ConfObjectEditor = ConfObjectEditorConstructor(ConfObject);
-
-//ConfObjectEditor.prototype.constructor = ConfObjectEditor(ConfObject);
-
-// Copy the values from configObject into the html form
-// and set up eventhandlers
-ConfObjectEditor.prototype.display = function(){
-  //TODO: this should set all regured fields in the form element
-  alert(typeof(this) + ' Should implemet method "display()"');
-};
-
-
-// clear all fields, remove eventhandlers and set configObjects to null
-ConfObjectEditor.prototype.clear = function(){
-  confObject = null;
-  $("#"+this.options.id +"_Form :text").val("");
-
-  
-};
-
-// load specified configObject 
-ConfObjectEditor.prototype.load = function(key){
-  this.confObject = this.confObject ||  new this.confObjectType();
+ConfEditor.prototype.load = function(key){
+  var objectParams = {options: this.options, fields: this.fields, url: this.rpcEndpoint};
+  this.confObject = new ConfObject(objectParams);
   this.confObject.setEditor(this);
-
-  // cases:
-  //
-  // 1) key is empty -> load empty editor
-  // 2a) key is passed -> load 
-  // 2b) key is passed, but there is no such entry -> fail
-  
   if(!key)
   {
-    this.confObject = new this.confObjectType();
-    this.confObject.name = "New User";
+    //FIXME: i18n
+    this.confObject.fields.name.value = this.confObject.fields.name.defaultValue;
     this.clear();
     this.display();
-    this.save = function(){
-    
-    this.create();
-    
-    };
+    //FIXME: set something that would make "save" redirect to "create"\n\
   }
+  
+  //TODO: do something nicer
+  try{
+    this.confObject.load(key);
+  }catch(E){
+    alert("ConfEditor: unable to Load : "+ key +". ("+ E +")"); 
+  }
+};
 
-  // Try loading an  object, if we are loading a non-exisitig
-  // object, we change the onSave function to call "create"
-  // instead of update
-  if(this.confObject.load(key) === false)
+ConfEditor.prototype.remove = function(){
+  if(this.confObject)
   {
-    // tell user that there is no such object
+    //TODO: do something nicer
+    try{
+      this.confObject.remove();
+    }catch(E){
+      alert(E);
+    }
+  }else{
+    //TODO: notify user
+    alert("can't remove: no user loaded");
   }
 };
 
-// request configObject to update
-ConfObjectEditor.prototype.update = function(){
-  this.confObject.update();
-};
+ConfEditor.prototype.save = function(){
+  if(this.confObject){
 
-// refresh configObeject data from server
-
-ConfObjectEditor.prototype.refresh = function() {
-  if(this.confObject) { this.confObject.load();} 
-  if(this.list) {  this.list.load(); }
+  }else{
+    //TODO: notify user
+    alert("cant save : no user loaded");
+  }
 };
 
-/*
-// request configObject to ask the server to create it // *ahem*
-ConfObjectEditor.prototype.create = function(){
-  //TODO: send data to server specifying that the entry should be created
-  this.configObject = new this.confObjectType(); // this.ConfObject("");
-  // read data from form and then:
+ConfEditor.prototype.create = function(){
+  //see comments in display 
+  for(var c = 0;c<this.fields.length;c++)
+  {
+    try{
+      this.fields[c].value = $('#' + options.id + this.fields[c].name);
+    }catch(E){
+      alert("Error trying to read fieldvalue " +E);
+    }
+  }
+  this.confObject.fields = this.fields;
   this.confObject.create();
-  ConfObjectEditor.prototype.save = function () {
-    this.update();
-  };
+  this.refresh();
 };
-*/
-// request configObject to delete itself
-ConfObjectEditor.prototype.remove = function(){
-  //TODO: ask server to delete the ressource
-  this.confObject.remove();
-  // and then, if successfull
-  this.clear();
+
+ConfEditor.prototype.refresh = function() {
+  if(this.confObject){
+    this.confObject.load(this.confObject.name);
+  }else{
+    alert("can't refresh :  no user loaded");
+  }
 };
 
-// executed when the "save" button of the form is clicked
-ConfObjectEditor.prototype.save = function(){
-  this.update();
+ConfEditor.prototype.display = function(){
+  //form is a jQuery Object
+  //FIXME: this needs to differentiate between the different possible fieldtypes
+  for(field in this.confObject.fields)
+  {
+    try{
+      $('#' + this.options.id + this.confObject.fields[field].name).val(this.confObject.fields[field].value);
+    }catch(E){
+      alert("Error trying to set " +E);
+    }
+  }
 };
 
-// associate the list that links to this editor
-ConfObjectEditor.prototype.setList = function(newList){
-  //TODO: check newList for validity
-  this.list = newList;
+ConfEditor.prototype.reset = function(){
+  //see comments in display();
+  var objectParams = {options: this.options, fields: this.fields, url: this.rpcEndpoint};
+  this.confObject = new ConfObject(objectParams);
+  this.confObject = this.ConfObject || new ConfObject(objectParams);
+  for(var c = 0;c<this.confObject.fields.length;c++)
+  {
+    try{
+      $('#' + this.options.id + this.confObject.fields[c].name).val(this.confObject.fields[c].defaultValue);
+    }catch(E){
+      alert("Error trying to set " +E);
+    }
+  }
 };
+
+ConfEditor.prototype.setList = function(newList) {
+  this.list = newList || null;
+};

Modified: branches/kmq_dev/http/javascripts/ConfObject.js
===================================================================
--- branches/kmq_dev/http/javascripts/ConfObject.js	2009-07-16 15:20:05 UTC (rev 4380)
+++ branches/kmq_dev/http/javascripts/ConfObject.js	2009-07-17 08:54:27 UTC (rev 4381)
@@ -1,61 +1,80 @@
-/* Config Base object */
-var ConfObject = function(){ this.editor = null; };
-ConfObject.prototype.constructor = ConfObject;
 
-// send local data to server and request the creation
-// of a new object with it.
-// this is a "static" function
-ConfObject.prototype.create = function(newConfObject){
-  var me = this;
-  var req  = new Mapbender.Ajax.Request({
-    method: "create",
-    url: "http://mapbender/javascripts/user.php",
-    parameters: { "userinfo": {
-                  "name": me.name,
-                  "password": me.password,
-                  "description": me.description,
-                  "owner": me.owner,
-                  "loginCount": me.loginCount,
-                  "email": me.email,
-                  "phone": me.phone,
-                  "dept": me.dept}
-    },
-    callback: function(){
-      me.editor.save = function() { me.editor.update() };
-      me.editor.refresh();
+var ConfObject = function(params) {
+  this.options = params.options || null;
+  this.fields = params.fields || {};
+  this.url = params.url || "";
+};
+
+ConfObject.prototype.load = function(key) {
+  var me = this; 
+  var req = Mapbender.Ajax.Request({
+    url           :  me.url,
+    method        : "load",
+    parameters    : {
+      name    : key
+      },
+    callback: function(result,success,message){
+      if(result.data.error){
+        alert("Could not load ConfObject, server said: " + message);
+        return;
       }
-    
+      for(key in result.data)
+      {
+        me.fields[key].value = result.data[key];
+      }
+      me.editor.display();
+    }
+});
+  req.send();
+};
+
+ConfObject.prototype.remove = function(){
+  var me = this; 
+  var req = Mapbender.Ajax.Request({
+    url           :  me.options.url,
+    method        : "remove",
+    parameters    : {
+      name    : me.field.name
+      },
+    callback      : function(){
+      throw("remove needs a callback");
+    }
   });
   req.send();
-
 };
 
-// get data from the server
-//ConfObject.prototype.load = function(name){
-//alert("it's me");
-//};
-
-// send local changes to server
 ConfObject.prototype.update = function(){
-alert("implement me");
+  var me = this;
+  var req =  Mapbender.Ajax.Request({
+    url           :  me.options.url,
+    method        : "update",
+    parameters    : {
+      name    : me.fields.name,
+      fields  : me.fields
+      },
+    callback      : function(){
+      throw("update needs a callback");
+    }
+  });
+  req.send();
 };
 
-// ask the server to remove the object,and delete self
-// maybe not delete(me), but something like that
-ConfObject.prototype.remove = function(){
+ConfObject.prototype.create = function(){
   var me = this;
-  var req = new Mapbender.Ajax.Request({
-    url : "http://mapbender/javascripts/user.php",
-    method: "remove",
-    parameters: { name: me.name },
-    callback: function() {
-      me.editor.clear();
-      me.editor.refresh();
-      }
+  var req = Mapbender.Ajax.Request({
+    url           :  me.options.url,
+    method        : "update",
+    parameters    : {
+      name    : me.fields.name,
+      fields  : me.fields
+      },
+    callback      : function(){
+      throw("create needs a callback");
+    }
   });
   req.send();
 };
 
 ConfObject.prototype.setEditor = function(newEditor) {
-  this.editor = newEditor;
+  this.editor = newEditor || null;
 };

Added: branches/kmq_dev/http/javascripts/group.php
===================================================================
--- branches/kmq_dev/http/javascripts/group.php	                        (rev 0)
+++ branches/kmq_dev/http/javascripts/group.php	2009-07-17 08:54:27 UTC (rev 4381)
@@ -0,0 +1,17 @@
+<?php
+require_once(dirname(__FILE___)."/../classes/class_mb_exception.php");
+require_once(dirname(__FILE___)."/../classes/class_group.php");
+require_once(dirname(__FILE___)."/../classes/class_RPCEndpoint.php");
+require_once(dirname(__FILE___)."/../classes/class_json.php");
+
+$ajaxResponse  = new AjaxResponse($_REQUEST);
+
+$ObjectConf = array("DisplayName"   => "Group",
+                    "internalname"  => "group",
+                    "ClassName"     => "Group");
+
+$rpc = new RPCEndpoint($ObjectConf,$ajaxResponse);
+$rpc->run();
+
+
+?>

Modified: branches/kmq_dev/http/javascripts/mod_AdminTabs.js
===================================================================
--- branches/kmq_dev/http/javascripts/mod_AdminTabs.js	2009-07-16 15:20:05 UTC (rev 4380)
+++ branches/kmq_dev/http/javascripts/mod_AdminTabs.js	2009-07-17 08:54:27 UTC (rev 4381)
@@ -123,7 +123,6 @@
 var Tabs = $(me).replaceWith(list);
 */
 var AdminTabs = function() {
-
   for(module in Mapbender.modules){
     if(Mapbender.modules[module].MB_ADMIN_MODULE)
     {
@@ -147,7 +146,7 @@
       var listElement = $("<ul></ul>");
       listElement.addClass("mbList");
       $("body").append(listElement);
-      var userList = new MBconfObjectList("http://mapbender/javascripts/user.php",listElement);
+      var userList = new MBconfObjectList('http://mapbender/javascripts/'+Mapbender.modules[adminModules[module]].rpcEndpoint ,listElement);
       userList.setEditor(Mapbender.modules[adminModules[module]]);
       userList.editor.setList(userList);
       userList.load();
@@ -158,4 +157,3 @@
 };
 
 Mapbender.modules[options.id] = new AdminTabs();
-

Modified: branches/kmq_dev/http/javascripts/mod_group.js
===================================================================
--- branches/kmq_dev/http/javascripts/mod_group.js	2009-07-16 15:20:05 UTC (rev 4380)
+++ branches/kmq_dev/http/javascripts/mod_group.js	2009-07-17 08:54:27 UTC (rev 4381)
@@ -1,199 +1,46 @@
-
-var ConfObject = function(options,fields) {
-  this.options = options;
-  this.fields = fields;
-};
-
-ConfObject.prototype.load = function(key) {
-  var me = this; 
-  var req = Mapbender.Ajax.Request({
-    url           :  me.options.url,
-    method        : "load",
-    parameters    : {
-      name    : key
-      },
-    callback: function(){
-      throw("load needs a callback");
-    }
-  });
-  req.send();
-};
-
-ConfObject.prototype.remove = function(){
-  var me = this; 
-  var req = Mapbender.Ajax.Request({
-    url           :  me.options.url,
-    method        : "remove",
-    parameters    : {
-      name    : me.field.name
-      },
-    callback      : function(){
-      throw("remove needs a callback");
-    }
-  });
-  req.send();
-};
-
-ConfObject.prototype.update = function(){
-  var me = this;
-  var req =  Mapbender.Ajax.Request({
-    url           :  me.options.url,
-    method        : "update",
-    parameters    : {
-      name    : me.fields.name,
-      fields  : me.fields
-      },
-    callback      : function(){
-      throw("update needs a callback");
-    }
-  });
-  req.send();
-};
-
-ConfObject.prototype.create = function(){
-  var me = this;
-  var req = Mapbender.Ajax.Request({
-    url           :  me.options.url,
-    method        : "update",
-    parameters    : {
-      name    : me.fields.name,
-      fields  : me.fields
-      },
-    callback      : function(){
-      throw("create needs a callback");
-    }
-  });
-  req.send();
-};
-
-ConfObject.prototype.setEditor = function(newEditor) {
-  this.editor = newEditor || null;
-};
-
-/****************************************************************************************************************/
-
-var ConfEditor = function(){
-  alert("Please override the ConfEditor Constructor");
-};
-
-ConfEditor.prototype.oad = function(key){
-  this.confObject = new ConfObject(this.options,this.fields);
-  if(!key)
-  {
-    //FIXME: i18n
-    this.confObject.fields.name = "New User";
-    this.clear();
-    this.display();
-    //FIXME: set something that would make "save" redirect to "create"\n\
-  }
-  
-  //TODO: do something nicer
-  try{
-    this.confObject.load(key);
-  }catch(E){
-    alert(E);
-  }
-};
-
-ConfEditor.prototype.remove = function(){
-  if(this.confObject)
-  {
-    //TODO: do something nicer
-    try{
-      this.confObject.remove();
-    }catch(E){
-      alert(E);
-    }
-  }else{
-    //TODO: notify user
-    alert("can't remove: no user loaded");
-  }
-};
-
-ConfEditor.prototype.save = function(){
-  if(this.confObject){
-
-  }else{
-    //TODO: notify user
-    alert("cant save : no user loaded");
-  }
-};
-
-ConfEditor.prototype.create = function(){
-  //see comments in display 
-  for(var c = 0;c<this.fields.length;c++)
-  {
-    try{
-      this.fields[c].value = $('#' + options.id + this.fields[c].name);
-    }catch(E){
-      alert("Error trying to read fieldvalue " +E);
-    }
-  }
-  this.confObject.fields = this.fields;
-  this.confObject.create();
-  this.refresh();
-};
-
-ConfEditor.prototype.refresh = function() {
-  if(this.confObject){
-    this.confObject.load(this.confObject.name);
-  }else{
-    alert("can't refresh :  no user loaded");
-  }
-};
-
-ConfEditor.prototype.display = function(){
-  //form is a jQuery Object
-  //FIXME: this needs to differentiate between the different possible fieldtypes
-  for(var c = 0;c<this.fields.length;c++)
-  {
-    try{
-      this.form.select('#' + options.id + this.fields[c].name).val(this.fields[c].defaultValue);
-    }catch(E){
-      alert("Error trying to set " +E);
-    }
-  }
-};
-
-ConfEditor.prototype.reset = function(){
-  //see comments in display();
-  for(var c = 0;c<this.fields.length;c++)
-  {
-    try{
-      this.form.select('#' + options.id + this.fields[c].name).val(this.fields[c].defaultValue);
-    }catch(E){
-      alert("Error trying to set " +E);
-    }
-  }
-};
-
-ConfEditor.prototype.setList = function(newList) {
-  this.list = newList || null;
-};
-
-
-
-
-/****************************************************************************************************************/
 var me = this;
 
 
 var GroupEditor = function(){
   
   // chose the id to be of the form: options.id + <fieldname>
-  var form = $('<div> <h2>groupEditor</h2> <form> <input id="'+options.id + 'name" type="text" /> </div>');
+  this.form = $('\n\
+      <div class="mbFrame formContainer UserEditor">\n\
+      <h2>GroupNameGoesHere</h2>\n\
+      <form method="post" id="'+ options.id +'_Form" >\n\
+      <ul>\n\
+        <li><label for="'+ options.id +'Name">Name</label><input id="'+ options.id +'name" type="text" /></li>\n\
+        <li><label for="'+ options.id +'_Description">Description</label><input id="'+ options.id +'description" type="text" /></li>\n\
+        <li><label for="'+ options.id +'_Owner">Owner</label><input id="'+ options.id +'owner" type="text" /></li>\n\
+      </ul>\n\
+      <p>\n\
+      <input id="'+options.id +'_Save" type="button" value="save" onclick="Mapbender.modules[\''+ options.id  +'\'].save(); return false;" />\n\
+      <input id="'+options.id +'_Delete" type="button" value="delete" onclick="Mapbender.modules[\''+ options.id  +'\'].remove(); return false;" />\n\
+      </p>\n\
+      </form>\n\
+      </div>');
+
   this.fields = [];
-  this.fields.name  = { name: "name", defaultValue : "", value: "", display: "Group Name",  type: "text"};
+  this.fields.name  = { name: "name", defaultValue : "New Group", value: "", display: "Group Name",  type: "text"};
   this.fields.owner = { name: "owner",       defaultValue : "", value:"", display: "Owner",       type: "text"};
-
+  this.fields.description = { name: "description",       defaultValue : "", value:"", display: "Description",  type: "text"};
   this.name = this.fields.name.value;
+  this.name = this.fields.name.value;
+  this.rpcEndpoint = "../javascripts/group.php"; 
+  this.options = options;
   
-  $(me).replaceWith(form);
-  me = form;
+  $(me).replaceWith(this.form);
+  me = this.form;
   this.reset();
 
 };
 
 GroupEditor.prototype = new ConfEditor();
 GroupEditor.prototype.constructor = GroupEditor;
+
+
 Mapbender.modules[options.id] = new GroupEditor();
+if(Mapbender.modules['AdminTabs'])
+{
+  Mapbender.modules['AdminTabs'].register(options.id);
+}

Modified: branches/kmq_dev/http/javascripts/mod_user.js
===================================================================
--- branches/kmq_dev/http/javascripts/mod_user.js	2009-07-16 15:20:05 UTC (rev 4380)
+++ branches/kmq_dev/http/javascripts/mod_user.js	2009-07-17 08:54:27 UTC (rev 4381)
@@ -1,90 +1,8 @@
-
-
-// Setup reference to myself
-// 'this' will point to the wrong objext in the inner functions
 var me = this;
 
-/* SUPPORT Objects */
 
-
-/* UserConfig Object */
-
-var ConfUser = function(name) {
-    // defaults all empty, server should define them
-    this.name = ""; 
-    this.password = ""; 
-    this.description = ""; 
-    this.owner = ""; 
-    this.loginCount = ""; 
-    this.email = ""; 
-    this.phone = ""; 
-    this.dept = ""; 
-
-    this.editor = null;
-};
-
-ConfUser.prototype = new ConfObject();
-
-ConfUser.prototype.load = function(key) {
-
-  if (!key){
-    // a call to an undefined object doesn't make alot of sense:
-    return false;
-   }   
-
-  var userinfo = null;
-  var userURL = key;
-  var me = this;
-  var req = new Mapbender.Ajax.Request({
-       method: "load",
-       parameters:{"name":key},
-       url: "http://mapbender/javascripts/user.php",
-       callback: function(result,success,message){
-        
-          
-          me.name = message.name   || ""; //we should raise an error here, a name must exist 
-          me.password = "**********";
-          me.description = message.description || "";
-          me.owner = message.owner || "";
-          me.loginCount = message.loginCount || "";
-          me.email = message.email || "";
-          me.phone = message.phone || "";
-          me.dept = message.dept   || "";
-          
-          me.editor.display();
-          } 
-      });
-    req.send();
-      
-   return true;
-};
-        
-ConfUser.prototype.update = function(){
-  var me = this;
-  var req  = new Mapbender.Ajax.Request({
-    method: "update",
-    url: "http://mapbender/javascripts/user.php",
-    parameters: { "userinfo": {
-                  "name": me.name,
-                  "password": me.password,
-                  "description": me.description,
-                  "owner": me.owner,
-                  "loginCount": me.loginCount,
-                  "email": me.email,
-                  "phone": me.phone,
-                  "dept": me.dept}
-    }, 
-    callback: function(){  me.editor.refresh(); }
-    });
-  req.send();
-};
-
-
-
-
-/* MODULE */
-//load html elements into me
-var data = $('\n\
+var UserEditor = function(){
+var form = $('\n\
 <div class="mbFrame formContainer UserEditor">\n\
 <h2>UserNameGoesHere</h2>\n\
 <ul class="tabList">\n\
@@ -93,81 +11,41 @@
 </ul>\n\
 <form method="post" id="'+ options.id +'_Form" >\n\
 <ul>\n\
-  <li><label for="'+ options.id +'_Name">Username</label><input id="'+ options.id +'_Name" type="text" /></li>\n\
-  <li><label for="'+ options.id +'_Password">Password</label><input id="'+ options.id +'_Password" type="password" /></li>\n\
-  <li><label for="'+ options.id +'_Description">Description</label><input id="'+ options.id +'_Description" type="text" /></li>\n\
-  <li><label for="'+ options.id +'_Owner">Owner</label><input id="'+ options.id +'_Owner" type="text" /></li>\n\
-  <li><label for="'+ options.id +'_LoginCount">Number of Logins</label><input id="'+ options.id +'_LoginCount" type="text" /></li>\n\
-  <li><label for="'+ options.id +'_Email">Email</label><input id="'+ options.id +'_Email" type="text" /></li>\n\
-  <li><label for="'+ options.id +'_Phone">Phone</label><input id="'+ options.id +'_Phone" type="text" /></li>\n\
-  <li><label for="'+ options.id +'_Department">Department</label><input id="'+ options.id +'_Department" type="text" /></li>\n\
+  <li><label for="'+ options.id +'Name">Username</label><input id="'+ options.id +'name" type="text" /></li>\n\
+  <li><label for="'+ options.id +'Password">Password</label><input id="'+ options.id +'password" type="password" /></li>\n\
+  <li><label for="'+ options.id +'Description">Description</label><input id="'+ options.id +'description" type="text" /></li>\n\
+  <li><label for="'+ options.id +'Owner">Owner</label><input id="'+ options.id +'owner" type="text" /></li>\n\
+  <li><label for="'+ options.id +'LoginCount">Number of Logins</label><input id="'+ options.id +'loginCount" type="text" /></li>\n\
+  <li><label for="'+ options.id +'Email">Email</label><input id="'+ options.id +'email" type="text" /></li>\n\
+  <li><label for="'+ options.id +'Phone">Phone</label><input id="'+ options.id +'phone" type="text" /></li>\n\
+  <li><label for="'+ options.id +'Department">Department</label><input id="'+ options.id +'department" type="text" /></li>\n\
 </ul>\n\
 <p>\n\
-<input id="'+options.id +'_Save" type="button" value="save" onclick="Mapbender.modules[\''+ options.id  +'\'].save(); return false;" />\n\
-<input id="'+options.id +'_Delete" type="button" value="delete" onclick="Mapbender.modules[\''+ options.id  +'\'].remove(); return false;" />\n\
+<input id="'+options.id +'save" type="button" value="save" onclick="Mapbender.modules[\''+ options.id  +'\'].save(); return false;" />\n\
+<input id="'+options.id +'delete" type="button" value="delete" onclick="Mapbender.modules[\''+ options.id  +'\'].remove(); return false;" />\n\
 </p>\n\
 </form>\n\
 </div>');
-  $(me).replaceWith(data);
-  element = data;
 
-    
-  var UserEditor = ConfObjectEditorConstructor(ConfUser,element,options);
-  UserEditor.prototype = new ConfObjectEditor();
+  this.fields = [];
+  this.fields.name = { name: "name", defaultValue: "New User", value: "", display: "User Name", type: "text"};
 
-  // This is defined, so that the admin navigationbar recognizes it
- UserEditor.prototype.MB_ADMIN_MODULE = true;
-
-  UserEditor.prototype.display = function() {
-  // also set up some variables that build up the complete save request 
-
-    var titleEl = this.element.children("h2").html(this.confObject.name);
-    var nameEl = $("#"+options.id+'_Name').val(this.confObject.name);
-    var passwordEl = $("#"+options.id+'_Password').val(this.confObject.password);
-    var descrEl =$("#"+options.id+'_Description').val(this.confObject.description);
-    var ownerEl = $("#"+options.id+'_Owner').val(this.confObject.owner);
-    var loginCountEl =$("#"+options.id+'_LoginCount').val(this.confObject.loginCount);
-    var emailEl = $("#"+options.id+'_Email').val(this.confObject.email);
-    var phoneEl =$("#"+options.id+'_Phone').val(this.confObject.phone);
-    var deptEl = $("#"+options.id+'_Department').val(this.confObject.dept);
+  this.name = this.fields.name.value;
+  this.rpcEndpoint = "../javascripts/user.php"; 
+  this.options = options;
   
-    //FIXME: alert("dear jquery how do I disable a button?");
-  };
+  
+  $(me).replaceWith(form);
+  me = form;
+  this.reset();
+  
+};
+UserEditor.prototype = new ConfEditor();
+UserEditor.prototype.constructor = UserEditor;
 
-  UserEditor.prototype.update = function() {
-    
-    this.confObject.name = $("#"+options.id+'_Name').val();
-    this.confObject.password = $("#"+options.id+'_Password').val();
-    this.confObject.description = $("#"+options.id+'_Description').val();
-    this.confObject.owner = $("#"+options.id+'_Owner').val();
-    this.confObject.loginCount = $("#"+options.id+'_LoginCount').val();
-    this.confObject.email = $("#"+options.id+'_Email').val();
-    this.confObject.phone = $("#"+options.id+'_Phone').val();
-    this.confObject.dept = $("#"+options.id+'_Department').val();
+//Mapbender.modules[options.id] = new UserEditor();
+if(Mapbender.modules['AdminTabs'])
+{
+   // Mapbender.modules['AdminTabs'].register(options.id);
+}
 
-    this.confObject.update();
-  };
-
-  UserEditor.prototype.create = function() {
-    
-    this.confObject.name = $("#"+options.id+'_Name').val();
-    this.confObject.password = $("#"+options.id+'_Password').val();
-    this.confObject.description = $("#"+options.id+'_Description').val();
-    this.confObject.owner = $("#"+options.id+'_Owner').val();
-    this.confObject.loginCount = $("#"+options.id+'_LoginCount').val();
-    this.confObject.email = $("#"+options.id+'_Email').val();
-    this.confObject.phone = $("#"+options.id+'_Phone').val();
-    this.confObject.dept = $("#"+options.id+'_Department').val();
-
-    this.confObject.setEditor(this);
-    this.confObject.create();
-  }
-
-
-  Mapbender.modules[options.id] = new UserEditor();
-  if(Mapbender.modules['AdminTabs'])
-  {
-    Mapbender.modules['AdminTabs'].register(options.id);
-  }
-
-

Modified: branches/kmq_dev/http/javascripts/user.php
===================================================================
--- branches/kmq_dev/http/javascripts/user.php	2009-07-16 15:20:05 UTC (rev 4380)
+++ branches/kmq_dev/http/javascripts/user.php	2009-07-17 08:54:27 UTC (rev 4381)
@@ -1,150 +1,17 @@
 <?php
 require_once(dirname(__FILE___)."/../classes/class_mb_exception.php");
 require_once(dirname(__FILE___)."/../classes/class_user.php");
+require_once(dirname(__FILE___)."/../classes/class_RPCEndpoint.php");
 require_once(dirname(__FILE___)."/../classes/class_json.php");
 
-//TODO: serious need for errorhandling
-
-
 $ajaxResponse  = new AjaxResponse($_REQUEST);
 
-$method = $ajaxResponse->getMethod(); //get from JSON-RPC
-$id = $ajaxResponse->getId();
-$result ="";
+$ObjectConf = array("DisplayName"   => "User",
+                    "internalname"  => "user",
+                    "ClassName"     => "User");
 
-// need userfactory to get user by name
-// this should return an empty userObject if 
-// method is "create"
+$rpc = new RPCEndpoint($ObjectConf,$ajaxResponse);
+$rpc->run();
 
-switch($method)
-{
 
-	case 'create':
-        $userinfo = $ajaxResponse->getParameter('userinfo');
-        $user = new User(null);
-		try {
-			$user->change($userinfo);
-		}
-		catch (Exception $E)
-		{
-          $ajaxResponse->setSuccess(false);
-          $ajaxResponse->setMessage(_mb("Could not create user"));
-          break;
-		}
-		
-        try{
-			$user->create();
-		}
-		catch(Exception $E)
-		{
-          $ajaxResponse->setSuccess(false);
-          $ajaxResponse->setMessage(_mb("Could not create user"));
-          break;
-		}
-		break;
-
-	case 'update':
-        $userinfo = $ajaxResponse->getParameter('userinfo');
-        $user = User::ByName($userinfo->name);
-        if($user == null)
-        {
-          $ajaxResponse->setSuccess(false);
-          $ajaxResponse->setMessage(_mb("No such user"));
-          break;
-        }
-		try{
-			$user->change($userinfo);
-		}
-		catch(Exception $E)
-		{
-          $ajaxResponse->setSuccess(false);
-          $ajaxResponse->setMessage(_mb("Could not change user"));
-          break;
-		}
-
-		try{
-			$user->commit();
-		}
-		catch(Exception $E)
-		{
-          $ajaxResponse->setSuccess(false);
-          $ajaxResponse->setMessage(_mb("Could not change user"));
-          break;
-		}
-		break;
-
-	case 'remove':
-        $name = $ajaxResponse->getParameter('name');
-        $user = User::ByName($name);
-        if($user == null)
-        {
-          $ajaxResponse->setSuccess(false);
-          $ajaxResponse->setMessage(_mb("No such user"));
-          break;
-        }
-		try{
-			$user->remove();
-		}
-		catch(Exception $E)
-		{
-          $ajaxResponse->setSuccess(false);
-          $ajaxResponse->setMessage(_mb("Could not delete user"));
-          break;
-		}
-		break;
-
-    case 'load':
-        $name = $ajaxResponse->getParameter('name');
-        $user = User::byName($name);
-        if($user == null)
-        {
-          $ajaxResponse->setSuccess(false);
-          $ajaxResponse->setMessage(_mb("No such user"));
-          break;
-        }
-      try{
-        $user->load();
-        $result = $user->toJSON();
-        $ajaxResponse->setSuccess(true);
-        $ajaxResponse->setMessage($result);
-        break;
-      }
-      catch(Exception $E)
-      {
-          $ajaxResponse->setSuccess(false);
-          $ajaxResponse->setMessage(_mb("Could not load user data"));
-          break;
-      }
-      break;
-
-    case 'list':
-        //get list of users
-        $result = array();
-        $users = User::getList('');
-        if(!$users)
-        {
-          $ajaxResponse->setSuccess(false);
-          $ajaxResponse->setMessage(_mb("Error fetching list of users"));
-          break;
-        }
-        
-        foreach( $users as $user)
-        {
-          $result[] = array ( "name"  => $user->name, 
-                              "value" => $user->name);
-        }
-        $ajaxResponse->setResult("list",$result);
-        $ajaxResponse->setResult("type", array("display"  => _mb("User"),
-                                               "internal" => "user")); 
-      break;
-
-    default:
-      $ajaxResponse->setSuccess(false);
-      $ajaxResponse->setMessage(_mb("invalid method"));
-
-}
-
-  $ajaxResponse->send();
-
-
 ?>



More information about the Mapbender_commits mailing list