[Mapbender-commits] r4261 - branches/kmq_dev/http/javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Sun Jun 28 17:06:42 EDT 2009
Author: kmq
Date: 2009-06-28 17:06:42 -0400 (Sun, 28 Jun 2009)
New Revision: 4261
Added:
branches/kmq_dev/http/javascripts/Editor.js
branches/kmq_dev/http/javascripts/List.js
branches/kmq_dev/http/javascripts/Object.js
branches/kmq_dev/http/javascripts/mod_admin.js
branches/kmq_dev/http/javascripts/mod_admin.php
branches/kmq_dev/http/javascripts/mod_gui.php
branches/kmq_dev/http/javascripts/mod_user.js
branches/kmq_dev/http/javascripts/mod_user.php
branches/kmq_dev/http/javascripts/user.php
Log:
client side scripts and html
Added: branches/kmq_dev/http/javascripts/Editor.js
===================================================================
--- branches/kmq_dev/http/javascripts/Editor.js (rev 0)
+++ branches/kmq_dev/http/javascripts/Editor.js 2009-06-28 21:06:42 UTC (rev 4261)
@@ -0,0 +1,160 @@
+
+// This function creates and returns constructor functions
+// configured for each type of derived Editor
+// this removes the need to call the superconstructor
+
+var MBconfObjectEditorConstructor = function(ObjectType){
+ return function(element){
+ this.element = element;
+ this.list = null;
+ this.confObject = null;
+ this.confObjectType = ObjectType;
+};
+};
+
+
+/*Editor Base Object*/
+var MBconfObjectEditor = MBconfObjectEditorConstructor(MBconfObject);
+
+//MBconfObjectEditor.prototype.constructor = MBconfObjectEditor(MBconfObject);
+
+// Copy the values from configObject into the html form
+// and set up eventhandlers
+MBconfObjectEditor.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
+MBconfObjectEditor.prototype.clear = function(){
+ confObject = null;
+ // set all fields in the html form to empty
+ // by some form of .value = ""-magic
+};
+
+// load specified configObject
+MBconfObjectEditor.prototype.load = function(url){
+ this.confObject = new this.confObjectType();
+ this.confObject.setEditor(this);
+ if(this.confObject.load(url) === null)
+ {
+ MBconfObjectEditor.prototype.onSave = function(){
+ MBconfObjectEditor.prototype.create();
+ };
+ }
+
+};
+
+// request configObject to update
+MBconfObjectEditor.prototype.update = function(){
+ //read data from form and then
+ this.confObject.update();
+};
+
+// request configObject to ask the server to create it // *ahem*
+MBconfObjectEditor.prototype.create = function(){
+ //TODO: send data to server specifying that the entry should be created
+ this.configObject = new MBconfObject("");
+ // read data from form and then:
+ this.configObject.create();
+};
+
+// request configObject to delete itself
+MBconfObjectEditor.prototype.remove = function(){
+ //TODO: ask server to delete the ressource
+ this.configObject.remove();
+ // and then, if successfull
+ this.clear();
+};
+
+// executed when the "save" button of the form is clicked
+MBconfObjectEditor.prototype.onSave = function(){
+ this.update();
+};
+
+// associate the list that links to this editor
+MBconfObjectEditor.prototype.setList = function(newList){
+ //TODO: checl newList for validity
+ this.list = newList;
+};
+
+
+
+
+/* User Editor*/
+var MBconfUserEditor = MBconfObjectEditorConstructor(MBconfUser);
+MBconfUserEditor.prototype = new MBconfObjectEditor();
+
+MBconfUserEditor.prototype.display = function() {
+ // also set up some variables that build up the complete save request
+
+ var prefix = this.element.id + '_';
+ var titleEl = this.element.getElementsByTagName('h2')[0];
+ titleEl.textContent = this.confObject.name;
+
+ var nameEl = document.getElementById(prefix+'Name');
+ nameEl.value = this.confObject.name;
+
+ var passwordEl = document.getElementById(prefix+'Password');
+ passwordEl.value = this.confObject.password;
+
+ var descrEl =document.getElementById(prefix+'Description');
+ descrEl.value = this.confObject.descr;
+
+ var ownerEl = document.getElementById(prefix+'Owner');
+ ownerEl.value = this.confObject.owner;
+
+ var loginCountEl =document.getElementById(prefix+'LoginCount');
+ loginCountEl.value = this.confObject.loginCount;
+
+ var emailEl = document.getElementById(prefix+'Email');
+ emailEl.value = this.confObject.email;
+
+ var phoneEl =document.getElementById(prefix+'Phone');
+ phoneEl.value = this.confObject.phone;
+
+ var deptEl = document.getElementById(prefix+'Department');
+ deptEl.value = this.confObject.dept;
+};
+
+
+/* Group Editor */
+
+var MBconfGroupEditor = MBconfObjectEditorConstructor(MBconfGroup);
+MBconfGroupEditor.prototype = new MBconfObjectEditor();
+
+MBconfGroupEditor.prototype.display = function() {
+
+ var prefix = this.element.id +'_';
+ var titleEl = this.element.getElementsByTagName('h2')[0];
+ titleEl.textContent = this.confObject.name;
+
+ var nameEl = document.getElementById(prefix+'Name');
+ nameEl.value = this.confObject.name;
+
+ var descrEl = document.getElementById(prefix+'Description');
+ descrEl.value = this.confObject.descr;
+
+ var ownerEl = document.getElementById(prefix+'Owner');
+ ownerEl.value = this.confObject.owner;
+}
+
+/* Gui Editor */
+
+var MBconfGuiEditor = MBconfObjectEditorConstructor(MBconfGui);
+MBconfGuiEditor.prototype = new MBconfObjectEditor();
+MBconfGuiEditor.prototype.display = function() {
+
+ var prefix = this.element.id +'_';
+ var titleEl = this.element.getElementsByTagName('h2')[0];
+ titleEl.textContent = this.confObject.name;
+
+ var nameEl = document.getElementById(prefix+'Name');
+ nameEl.value = this.confObject.name;
+
+ var descrEl = document.getElementById(prefix+'Description');
+ descrEl.value = this.confObject.descr;
+
+ var ownerEl = document.getElementById(prefix+'Public');
+ ownerEl.checked = this.confObject.public;
+}
Added: branches/kmq_dev/http/javascripts/List.js
===================================================================
--- branches/kmq_dev/http/javascripts/List.js (rev 0)
+++ branches/kmq_dev/http/javascripts/List.js 2009-06-28 21:06:42 UTC (rev 4261)
@@ -0,0 +1,113 @@
+var MBconfObjectList = function(type,element){
+
+// This Object displays availabe Configuration Objects in a given
+// category in a HTML ul element
+// and updates a corresponding editor with the Objects configuration
+// Options
+
+
+var me = this;
+this.type = type;
+this.element = element;
+this.allEntries = {};
+this.displayEntries = {};
+this.editor = null;
+
+// list entry JSON serializarion:
+// {"display":"<bla>","value":"<bla>"}
+
+};
+
+MBconfObjectList.prototype.load = function(url){
+ var me = this;
+ //TODO: cross browser
+ // Todo: make this more sophisticated to allow categories
+ // and also proper "Add XXX"
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET',url,true);
+ xhr.onreadystatechange = (function(){
+ if(xhr.readyState != 4){return;}
+ if(xhr.status != 200){return;}
+ me.allEntries = parseJSON(xhr.responseText);
+ me.displayEntries = me.allEntries;
+ me.display();
+ });
+ xhr.send(null);
+
+};
+
+
+MBconfObjectList.prototype.display = function(search){
+ if(!search) {search = "";}
+ while(this.element.firstChild)
+ {
+ this.element.removeChild(this.element.firstChild);
+ }
+
+ var listEntry = document.createElementNS('http://www.w3.org/1999/xhtml','li');
+
+ listEntry.className = 'listFilter';
+
+ var listFilter = document.createElementNS('http://www.w3.org/1999/xhtml','input');
+ listFilter.setAttribute('type','text');
+ listFilter.setAttribute('title','filter users by name');
+ listFilter.setAttribute('value',search);
+ listFilter.addEventListener('keyup',this.addOnFilterChangeHandler(),0)
+
+ listEntry.appendChild(listFilter);
+ this.element.appendChild(listEntry);
+
+ for(entry in this.displayEntries)
+ {
+ listEntry = document.createElementNS('http://www.w3.org/1999/xhtml','li');
+ listEntry.textContent = entry;
+ listEntry.addEventListener('click',this.addOnClickHandler(this.displayEntries[entry]),0);
+ this.element.appendChild(listEntry);
+
+ }
+ listEntry = document.createElementNS('http://www.w3.org/1999/xhtml','li');
+ listEntry.className = 'listCommand';
+ listEntry.textContent = 'Add ObjectType';
+ listEntry.addEventListener('click',this.addOnClickHandler(null),0);
+ this.element.appendChild(listEntry);
+ listFilter.focus();
+};
+
+MBconfObjectList.prototype.setEditor = function(newEditor){
+ //TODO: check newEditor for validity
+ this.editor = newEditor;
+ //TODO: assuming the editor.setList also tries to set the
+ // lists editor to itself, would cause some silly recursion.
+ // how do I deal with this
+ this.editor.setList(this);
+};
+
+MBconfObjectList.prototype.addOnClickHandler = function(objectURL){
+ if(this.editor === null || this.editor === undefined) { return (function(){});}
+ var editor = this.editor;
+ var handler = (function(){
+ editor.load(objectURL);
+ });
+ return handler;
+};
+
+MBconfObjectList.prototype.addOnFilterChangeHandler = function(){
+ var list = this;
+ return (function(evt) {
+ var e = evt;
+ var needle = e.target.value;
+ list.displayEntries = {};
+ //TODO: optimize
+ for(entry in list.allEntries)
+ {
+ if(entry.indexOf(needle) != -1)
+ {
+ list.displayEntries[entry] = list.allEntries[entry];
+ }
+
+ }
+ list.display(needle);
+
+ });
+
+};
Added: branches/kmq_dev/http/javascripts/Object.js
===================================================================
--- branches/kmq_dev/http/javascripts/Object.js (rev 0)
+++ branches/kmq_dev/http/javascripts/Object.js 2009-06-28 21:06:42 UTC (rev 4261)
@@ -0,0 +1,287 @@
+/* Config Base object */
+var MBconfObject = function(){ this.editor = null; };
+MBconfObject.prototype.constructor = MBconfObject;
+
+// send local data to server and request the creation
+// of a new object with it.
+// this is a "static" function
+MBconfObject.create = function(newConfObject){
+ // creates newConfObject on the server
+};
+
+// get data from the server
+MBconfObject.prototype.load = function(name){
+};
+
+// send local changes to server
+MBconfObject.update = function(){
+ //TODO: send data to server
+};
+
+
+// ask the server to remove the object,and delete self
+// maybe not delete(me), but something like that
+MBconfObject.prototype.remove = function(){
+ //TODO: ask server to redlete the ressource
+ // and then, if successfull
+ me.clear();
+};
+
+MBconfObject.prototype.setEditor = function(newEditor) {
+ this.editor = newEditor;
+};
+
+/* UserConfig Object */
+
+var MBconfUser = function(name) {
+ // defaults all empty, server should define them
+ this.name = "";
+ this.password = "";
+ this.descr = "";
+ this.owner = "";
+ this.loginCount = "";
+ this.email = "";
+ this.phone = "";
+ this.dept = "";
+
+ this.editor = null;
+};
+
+MBconfUser.prototype = new MBconfObject();
+
+MBconfUser.prototype.load = function(url) {
+
+ if (url === null){
+ //this needs to be done here, because it is ususally
+ //done at the end of the async call below
+ //might cange when it getys connected to the server
+ //FIXME: l10n
+ this.name = "New User";
+ if(this.editor){this.editor.display();}
+ return null;
+
+ }
+ var userinfo = null;
+ var userURL = url;
+ var me = this;
+
+ alert("whee");
+
+ var req = new Mapbender.Ajax.Request({
+
+ "method":"user_load",
+ "parameters":{"name":me.name}
+
+ });
+
+ req.send("http://mapbender/javascript/user.php",function(obj,success,message){
+
+ alert("obj: " + obj);
+ alert("success: " + success);
+ alert("message: " + message);
+
+ });
+
+
+
+
+
+//FIXME: cross browser
+
+
+
+ /*
+ var xhr = XMLHttpRequest();
+ xhr.open('GET',userURL,true);
+ xhr.onreadystatechange = (function(){
+ //TODO: crossbrowser
+ if(xhr.readyState != 4) {return;}
+ if(xhr.status != 200) {return;} // 30X?
+
+ if(xhr.responseText == "")
+ {
+ userinfo = {};
+ }else{
+ userinfo = parseJSON(xhr.responseText);
+ }
+
+ for (key in userinfo)
+ {
+ switch(key)
+ {
+ case "name":
+ me.name = userinfo.name;
+ break;
+
+ case "password":
+ me.password = userinfo.password;
+ break;
+
+ case "descr":
+ me.descr = userinfo.descr;
+ break;
+
+ case "owner":
+ me.owner = userinfo.owner;
+ break;
+
+ case "loginCount":
+ me.loginCount = userinfo.loginCount;
+ break;
+
+ case "email":
+ me.email = userinfo.email;
+ break;
+
+ case "phone":
+ me.phone = userinfo.phone;
+ break;
+
+ case "dept":
+ me.dept = userinfo.dept;
+ break;
+
+ }
+ }
+ if(me.editor !== null){me.editor.display();}
+
+ });
+
+ xhr.send(null);
+ */
+
+return true;
+}
+
+/* Group Conf Object */
+
+var MBconfGroup = function(name){
+ this.name = "";
+ this.descr = "";
+ this.owner = "";
+
+ this.editor = null;
+};
+
+MBconfGroup.prototype = new MBconfObject();
+
+MBconfGroup.prototype.load = function(url){
+
+ if(url === null) {
+
+ this.name = "New Group";
+ if(this.editor){ this.editor.display();}
+ return null;
+ }
+ var groupinfo = null;
+ var groupURL = url;
+ var me = this;
+ var xhr = XMLHttpRequest();
+ xhr.open('GET',groupURL, true);
+ xhr.onreadystatechange = (function(){
+
+ if(xhr.readyState != 4) {return;}
+ if(xhr.status != 200) {return;} // 30X?
+
+ if(xhr.responseText == "")
+ {
+ groupinfo = {};
+ }else{
+ groupinfo = parseJSON(xhr.responseText);
+ }
+
+
+ for (key in groupinfo)
+ {
+ switch(key)
+ {
+ case "name":
+ me.name = groupinfo.name;
+ break;
+
+ case "owner":
+ me.owner = groupinfo.owner;
+ break;
+
+ case "descr":
+ me.descr = groupinfo.descr;
+ break;
+
+ }
+ }
+ if(me.editor !== null){me.editor.display();}
+
+
+ });
+ xhr.send(null);
+
+};
+
+
+/* Gui conf Object */
+
+var MBconfGui = function(name){
+this.name = "";
+this.descr = "";
+this.public = false;
+
+this.editor = null;
+};
+
+MBconfGui.prototype = new MBconfObject();
+
+MBconfGui.prototype.load = function(url){
+
+ if(url === null) {
+
+ this.name = "New Group";
+ if(this.editor){ this.editor.display();}
+ return null;
+ }
+ var guiinfo = null;
+ var guiURL = url;
+ var me = this;
+ var xhr = XMLHttpRequest();
+ xhr.open('GET',guiURL, true);
+ xhr.onreadystatechange = (function(){
+
+ if(xhr.readyState != 4) {return;}
+ if(xhr.status != 200) {return;} // 30X?
+
+ if(xhr.responseText == "")
+ {
+ guiinfo = {};
+ }else{
+ guiinfo = parseJSON(xhr.responseText);
+ }
+
+
+ for (key in guiinfo)
+ {
+ switch(key)
+ {
+ case "name":
+ me.name = guiinfo.name;
+ break;
+
+ case "owner":
+ me.owner = guiinfo.owner;
+ break;
+
+ case "descr":
+ me.descr = guiinfo.descr;
+ break;
+
+ case "public":
+ me.public = guiinfo.public;
+ break;
+
+ }
+ }
+ if(me.editor !== null){me.editor.display();}
+
+
+ });
+ xhr.send(null);
+
+};
Added: branches/kmq_dev/http/javascripts/mod_admin.js
===================================================================
--- branches/kmq_dev/http/javascripts/mod_admin.js (rev 0)
+++ branches/kmq_dev/http/javascripts/mod_admin.js 2009-06-28 21:06:42 UTC (rev 4261)
@@ -0,0 +1,89 @@
+var Mapbender = Mapbender || {};
+
+function object(o){
+ function F() {}
+ F.prototype = o;
+ return new F();
+}
+
+Mapbender.Admin = {};
+
+ /*
+ * Alist of registered modules
+ */
+Mapbender.Admin.modules = {};
+
+/*
+ * Represents a Configuration Module. All Available Modules have to be registered here
+ */
+Mapbender.Admin.Module = function(options){
+
+ options = options || {};
+
+ /*
+ * The title displayed to the user
+ */
+ this.title = options.title || "";
+
+ /*
+ * The relative path to the File that contains the
+ * derived MBconfigObject, and MBConfigObjectEditor
+ */
+ this.path = options.path || "";
+
+ /*
+ * The path where to send RPCs
+ */
+ this.endpoint = options.endpoint || "";
+
+ /*
+ * wether the Module should active in the current page
+ */
+ this.active = options.active || false;
+
+ this.class = options.class || "";
+
+ this.load = function()
+ {
+
+ };
+
+};
+Mapbender.Admin.Module.prototype.constructor = Mapbender.Admin.Module;
+
+
+//TODO: move these into their respective files
+Mapbender.Admin.modules.User = new Mapbender.Admin.Module({title: "User",
+ path: "mod_user.php",
+ endpoint : "user.php",
+ class: "MBUserEditor",
+ confObject: Mapbender.Admin.confUser});
+
+Mapbender.Admin.modules.Group = new Mapbender.Admin.Module({title: "Groups",
+ path: "mod_group.php",
+ endpoint: "group.php",
+ class: "MBGroupEditor"});
+
+
+
+
+/*
+ * Scans the current Page for any modules to be activated
+*/
+Mapbender.Admin.scan = function(){
+
+ for(module in Mapbender.Admin.modules)
+ {
+ if(!Mapbender.Admin.modules.hasOwnProperty(module)) { continue; }
+ var selector = "." + Mapbender.Admin.modules[module].class;
+ var elements = $(selector);
+ for(var i =0; i < elements.length; i++)
+ {
+ elements[i].style.backgroundColor = "red";
+
+ }
+
+ }
+
+};
+
Added: branches/kmq_dev/http/javascripts/mod_admin.php
===================================================================
--- branches/kmq_dev/http/javascripts/mod_admin.php (rev 0)
+++ branches/kmq_dev/http/javascripts/mod_admin.php 2009-06-28 21:06:42 UTC (rev 4261)
@@ -0,0 +1,73 @@
+
+<!-- TODO: Need my header! -->
+<html>
+<head>
+
+
+<script src="../extensions/jquery-1.3.2.min.js" type="text/javascript"></script>
+<script src="../extensions/jquery-ui-1.7.1.w.o.effects.min.js" type="text/javascript"></script>
+<script src="../extensions/jqjson.js" type="text/javascript"></script>
+<script src="mod_admin.js" type="text/javascript"></script>
+<script src="Object.js" type="text/javascript"></script>
+<script src="Editor.js" type="text/javascript"></script>
+<script src="List.js" type="text/javascript"></script>
+
+<script type="text/javascript">
+//<![CDATA[
+var Mapbender = {};
+
+<?php
+echo "var global_mb_log_js = '".LOG_JS."';";
+echo "var global_mb_log_level = '".LOG_LEVEL."';";
+echo "var global_log_levels = '".LOG_LEVEL_LIST."';";
+
+require_once "../../lib/ajax.js";
+require_once "../../lib/exception.js";
+require_once "../../lib/event.js";
+
+?>
+//]]>
+</script>
+<script src="mod_admin.js" type="text/javascript" ></script>
+<script type="text/javascript" >
+//<![CDATA[
+
+function body_onload(evt){
+ Mapbender.Admin.scan();
+}
+//]]>
+</script>
+</head>
+<body onload="body_onload(event)">
+<!--
+
+Check which adminGUI elements are defined for this GUI and put them on the page
+like this:
+
+require_once("mod_user.php");
+
+echo mod_user_editor();
+
+which would output something like this:
+bla
+<div class="MBUserEditor">
+</div>
+
+The javascript on the clientside then scans for each of these modules, loads
+their javascript executes:
+
+$(".MBUserEditor").Mapbender.Admin.UserEditor();
+
+
+-->
+
+<?php
+
+include_once("mod_user.php");
+echo $mod_user_html;
+
+?>
+
+
+</body>
+</html>
Added: branches/kmq_dev/http/javascripts/mod_gui.php
===================================================================
--- branches/kmq_dev/http/javascripts/mod_gui.php (rev 0)
+++ branches/kmq_dev/http/javascripts/mod_gui.php 2009-06-28 21:06:42 UTC (rev 4261)
@@ -0,0 +1,44 @@
+<?php
+
+
+Class Mod_User()
+{
+
+
+public $javascript = <<<JAVASCRIPT
+//<![CDATA[
+
+
+//]]>
+JAVASCRIPT;
+
+public $html = <<<HTML
+
+<div class="mbFrame formContainer MBGUIEditor">
+<h2>GUINameGoesHere</h2>
+<form action="post">
+
+<ul>
+ <li>UserEditor (class MBUserEditor)</li>
+ <li>Group (class MBGroupEditor)</li>
+ <li>GUIEdit (class MBGUIEditor)</li>
+</ul>
+
+<input type="submit" value="save" />
+</form>
+</div>
+HTML;
+};
+
+if($_SERVER['QUERY_STRING'] == 'html')
+{
+ echo Mod_User->html;
+}
+elseif($_SERVER['QUERY_STRING'] == 'javascript')
+{
+ header("Content-Type: text/javascript");
+ echo Mod_User->javascript;
+}
+
+?>
+
Added: branches/kmq_dev/http/javascripts/mod_user.js
===================================================================
--- branches/kmq_dev/http/javascripts/mod_user.js (rev 0)
+++ branches/kmq_dev/http/javascripts/mod_user.js 2009-06-28 21:06:42 UTC (rev 4261)
@@ -0,0 +1,5 @@
+Mapbender.Admin.Modules.User = {};
+
+//define Mapbender.Modules.User.Editor
+//define Mapbender.Modules.User.ConfObject
+//
Added: branches/kmq_dev/http/javascripts/mod_user.php
===================================================================
--- branches/kmq_dev/http/javascripts/mod_user.php (rev 0)
+++ branches/kmq_dev/http/javascripts/mod_user.php 2009-06-28 21:06:42 UTC (rev 4261)
@@ -0,0 +1,48 @@
+<?php
+
+
+$mod_user_javascript = <<<JAVASCRIPT
+//<![CDATA[
+
+
+//]]>
+JAVASCRIPT;
+
+$mod_user_html = <<<HTML
+
+<div class="mbFrame formContainer MBUserEditor">
+<h2>UserNameGoesHere</h2>
+<ul class="tabList">
+<li class="active">core data</li>
+<li>rights</li>
+</ul>
+<form action="post">
+<ul>
+ <li><label for="mbe_editor_user_Name">Username</label><input id="mbe_editor_user_Name" type="text" /></li>
+ <li><label for="mbe_editor_user_Password">Password</label><input id="mbe_editor_user_Password" type="password" /></li>
+ <li><label for="mbe_editor_user_Description">Description</label><input id="mbe_editor_user_Description" type="text" /></li>
+ <li><label for="mbe_editor_user_Owner">Owner</label><input id="mbe_editor_user_Owner" type="text" /></li>
+ <li><label for="mbe_editor_user_LoginCount">Number of Logins</label><input id="mbe_editor_user_LoginCount" type="text" /></li>
+ <li><label for="mbe_editor_user_Email">Email</label><input id="mbe_editor_user_Email" type="text" /></li>
+ <li><label for="mbe_editor_user_Phone">Phone</label><input id="mbe_editor_user_Phone" type="text" /></li>
+ <li><label for="mbe_editor_user_Department">Department</label><input id="mbe_editor_user_Department" type="text" /></li>
+</ul>
+<p>
+<input type="submit" value="save" />
+</p>
+</form>
+</div>
+HTML;
+
+
+if($_SERVER['QUERY_STRING'] == 'html')
+{
+ echo $mod_user_html;
+}
+elseif($_SERVER['QUERY_STRING'] == 'javascript')
+{
+ header("Content-Type: text/javascript");
+ echo $mod_user_javascript;
+}
+
+?>
Added: branches/kmq_dev/http/javascripts/user.php
===================================================================
--- branches/kmq_dev/http/javascripts/user.php (rev 0)
+++ branches/kmq_dev/http/javascripts/user.php 2009-06-28 21:06:42 UTC (rev 4261)
@@ -0,0 +1,139 @@
+<?php
+require_once(dirname(__FILE___)."/../classes/class_mb_exception.php");
+require_once(dirname(__FILE___)."/../classes/class_user.php");
+require_once(dirname(__FILE___)."/../classes/class_json.php");
+
+//TODO: serious need for errorhandling
+
+
+//echo http_get_request_headers();
+$http_body = file_get_contents('php://input');
+$ajaxResponse = new AjaxRPC($http_body);
+
+$method = $ajaxResponse->getMethod(); //get from JSON-RPC
+$id = $ajaxResponse->getId();
+$result ="";
+
+// need userfactory to get user by name
+// this should return an empty userObject if
+// method is "create"
+
+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"));
+ }
+
+ try{
+ $user->create();
+ }
+ catch(Exception $E)
+ {
+ $ajaxResponse->setSuccess(false);
+ $ajaxResponse->setMessage(_mb("Could not create user"));
+ }
+ break;
+
+ case 'update':
+ $userinfo = $ajaxResponse->getParameter('userinfo');
+ $user = User::ByName($userinfo->name);
+ if($user == null)
+ {
+ $ajaxResponse->setSuccess(false);
+ $ajaxResponse->setMessage(_mb("No such user"));
+ }
+ try{
+ $user->change($userinfo);
+ }
+ catch(Exception $E)
+ {
+ $ajaxResponse->setSuccess(false);
+ $ajaxResponse->setMessage(_mb("Could not change user"));
+ }
+
+ try{
+ $user->commit();
+ }
+ catch(Exception $E)
+ {
+ $ajaxResponse->setSuccess(false);
+ $ajaxResponse->setMessage(_mb("Could not change user"));
+ }
+ break;
+
+ case 'delete':
+ $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;
+
+ 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();
+ }
+ catch(Exception $E)
+ {
+ $ajaxResponse->setSuccess(false);
+ $ajaxResponse->setMessage(_mb("Could not load user data"));
+ }
+ break;
+
+ case 'lIST':
+ //get list of users
+ $result = '[';
+ $users = User::getList('');
+ if(!$sers)
+ {
+ $ajaxResponse->setSuccess(false);
+ $ajaxResponse->setMessage(_mb("Error fetching list of users"));
+ }
+
+ foreach( $users as $user)
+ {
+ $result .= '{"name":"'. $user->name .'",';
+ $result .= '"value":"'. $user->name .'"},';
+ }
+
+ $result = $result; //TODO:remove trailing ','
+ $result .= ']';
+ break;
+
+ default:
+
+}
+
+ $ajaxResponse->send();
+
+
+?>
More information about the Mapbender_commits
mailing list