[Mapbender-commits] r4350 - in branches/kmq_dev/http: classes css
javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Jul 14 00:48:15 EDT 2009
Author: kmq
Date: 2009-07-14 00:48:15 -0400 (Tue, 14 Jul 2009)
New Revision: 4350
Added:
branches/kmq_dev/http/css/gsoc09.css
branches/kmq_dev/http/javascripts/ConfEditor.js
branches/kmq_dev/http/javascripts/ConfObject.js
branches/kmq_dev/http/javascripts/mod_AdminTabs.js
Removed:
branches/kmq_dev/http/javascripts/Editor.js
branches/kmq_dev/http/javascripts/List.js
branches/kmq_dev/http/javascripts/Object.js
Modified:
branches/kmq_dev/http/classes/class_user.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:
user editing demo
Modified: branches/kmq_dev/http/classes/class_user.php
===================================================================
--- branches/kmq_dev/http/classes/class_user.php 2009-07-14 03:52:40 UTC (rev 4349)
+++ branches/kmq_dev/http/classes/class_user.php 2009-07-14 04:48:15 UTC (rev 4350)
@@ -76,33 +76,33 @@
* @return JSON serialization of this user
*/
- public function toJSON()
- {
+ public function toJSON() {
- $result = '{"name":"'. $this->name .'",'
- .'"password": "*************",'
- .'"owner":"'. $this->owner .'",'
- .'"descr":"'. $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 .'"}';
+ $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()
- {
+ 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");}
@@ -135,7 +135,6 @@
}
catch(Exception $E)
{
- print "caught it";
$newE = new Exception("Could not set inital values of new user");
throw $newE;
}
@@ -151,11 +150,9 @@
/*
* @param $changes JSON keys and their values of what to change in the object
*/
- public function change($changes)
- {
-
+ public function change($changes) {
+ //FIXME: validate input
$this->name = $changes->name ? $changes->name : $this->name;
- print "MY NAME IS $changes->name";
$this->owner = $changes->owner ? $changes->owner : $this->owner;
$this->description = $changes->description ? $changes->description : $this->description;
$this->email = $changes->email ? $changes->email : $this->email;
@@ -176,8 +173,8 @@
return true;
}
- public function commit()
- {
+ public function commit() {
+ //FIXME: fail well
$sql_update = "UPDATE mb_user SET ".
"mb_user_name = $1, ".
@@ -228,8 +225,7 @@
return true;
}
- public function remove()
- {
+ public function remove() {
$sql_user_remove = "DELETE FROM mb_user WHERE mb_user_id = $1";
$v = array($this->id);
@@ -243,8 +239,7 @@
return true;
}
- public function load()
- {
+ public function load() {
$sql_user = "SELECT * from mb_user WHERE mb_user_id = $1; ";
$v = array($this->id);
$t = array("i");
@@ -286,8 +281,8 @@
* @return Array of Users
* @param $filter UNUSED! string that must be contained in the username
*/
- public static function getList($filter)
- {
+ public static function getList($filter) {
+ //FIXME: optimize
$users = Array();
$sql_userlist = "SELECT mb_user_id FROM mb_user";
$res_users = db_query($sql_userlist);
@@ -313,8 +308,7 @@
* @param $name the name of the user to find
*/
- public static function byName($name)
- {
+ public static function byName($name) {
$sql_user = "SELECT mb_user_id FROM mb_user WHERE mb_user_name = '$name'";
$res_user = db_query($sql_user);
if($row = db_fetch_array($res_user))
Added: branches/kmq_dev/http/css/gsoc09.css
===================================================================
--- branches/kmq_dev/http/css/gsoc09.css (rev 0)
+++ branches/kmq_dev/http/css/gsoc09.css 2009-07-14 04:48:15 UTC (rev 4350)
@@ -0,0 +1,162 @@
+html,body
+{
+ background-color: #f0f0f0;
+ height: 100%;
+ padding: 0px;
+}
+
+#log
+{
+ display: block;
+ position: fixed;
+ top: 500px;
+ left:100px;
+ color:red;
+}
+
+h1.mbLogo
+{
+ font-size: larger;
+ font-stretch: extra-expanded;
+ font-weight: bold;
+}
+
+.mbFrame
+{
+ border: 1px solid black;
+ /* fugly
+ -moz-border-radius: 1em;
+ */
+ background-color: white;
+}
+
+ul
+{
+ list-style-type: none;
+}
+
+/* top menu */
+.tabList > li
+{
+ display: inline;
+ background-color: #aaaaaa;
+ margin: 0em;
+ padding: 0em;
+ cursor: pointer;
+}
+.tabList > li:after
+{
+/* content: " - "; */
+}
+.tabList > li:last-child:after
+{
+ /* content: ""; */
+}
+
+.tabList li.active
+{
+ background-color: transparent;
+ border: 1px gray solid;
+}
+
+
+/* left menu */
+
+.mbList
+{
+ margin-left: 0px;
+ padding-left: 1em;
+ padding-top: 1em;
+ width: 15em;
+ margin-top: 0.5em;
+ float: left;
+ position: absolute;
+ top: 1em;
+ left: 1em;
+
+ min-height: 20em;
+}
+
+.mbList li
+{
+ cursor: pointer;
+}
+
+.mbList li.listCommand
+{
+ font-style: italic;
+}
+
+.mbList li#listFilter
+{
+ margin-bottom: 1em;
+}
+
+/* content area */
+
+div.formContainer
+{
+ margin-left: 16.5em;
+ padding-top: 1em;
+ margin-top: 0.5em;
+ min-height: 30em;
+}
+
+div.formContainer ul
+{
+ margin-right: auto;
+}
+div.formContainer form ul li
+{
+ padding-top: 0.2em;
+ border-bottom: 1px dotted gray;
+ vertical-align: top;
+}
+
+div.formContainer form ul > li>label
+{
+ width: 11em;
+ display: block;
+ float: left;
+
+}
+div.formContainer form ul > li>label:after
+{
+ content: ' : ';
+}
+
+div.formContainer form ul > li>select, div.formContainer form >ul>li>input
+{
+ width: 12em;
+}
+div.formContainer form ul > li>select
+{
+ border: none;
+ margin-top: 0px;
+ margin-bottom: auto;
+}
+
+div.formContainer form input[type=submit]
+{
+ margin-left: 26em;
+}
+
+
+.hidden
+{
+ display: none;
+}
+
+
+input[type="checkbox"]
+{
+ border: none;
+}
+
+.UserEditor
+{
+ position: absolute;
+ top: 1em;
+ width: 40em;
+
+}
Property changes on: branches/kmq_dev/http/css/gsoc09.css
___________________________________________________________________
Added: svn:executable
+ *
Added: branches/kmq_dev/http/javascripts/ConfEditor.js
===================================================================
--- branches/kmq_dev/http/javascripts/ConfEditor.js (rev 0)
+++ branches/kmq_dev/http/javascripts/ConfEditor.js 2009-07-14 04:48:15 UTC (rev 4350)
@@ -0,0 +1,113 @@
+
+// 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;
+};
+};
+
+
+/*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();
+ 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";
+ this.clear();
+ this.display();
+ this.save = function(){
+
+ this.create();
+
+ };
+ }
+
+ // 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)
+ {
+ // tell user that there is no such object
+ }
+};
+
+// request configObject to update
+ConfObjectEditor.prototype.update = function(){
+ this.confObject.update();
+};
+
+// refresh configObeject data from server
+
+ConfObjectEditor.prototype.refresh = function() {
+ this.confObject.load();
+ this.list.load();
+};
+
+/*
+// 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:
+ this.confObject.create();
+ ConfObjectEditor.prototype.save = function () {
+ this.update();
+ };
+};
+*/
+// request configObject to delete itself
+ConfObjectEditor.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
+ConfObjectEditor.prototype.save = function(){
+ this.update();
+};
+
+// associate the list that links to this editor
+ConfObjectEditor.prototype.setList = function(newList){
+ //TODO: check newList for validity
+ this.list = newList;
+};
Added: branches/kmq_dev/http/javascripts/ConfObject.js
===================================================================
--- branches/kmq_dev/http/javascripts/ConfObject.js (rev 0)
+++ branches/kmq_dev/http/javascripts/ConfObject.js 2009-07-14 04:48:15 UTC (rev 4350)
@@ -0,0 +1,78 @@
+/* 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();
+ }
+
+ });
+ 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(){
+ 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();
+
+
+
+
+
+
+};
+
+
+// ask the server to remove the object,and delete self
+// maybe not delete(me), but something like that
+ConfObject.prototype.remove = function(){
+ //TODO: ask server to redlete the ressource
+ // and then, if successfull
+ me.clear();
+};
+
+ConfObject.prototype.setEditor = function(newEditor) {
+ this.editor = newEditor;
+};
Deleted: branches/kmq_dev/http/javascripts/Editor.js
===================================================================
--- branches/kmq_dev/http/javascripts/Editor.js 2009-07-14 03:52:40 UTC (rev 4349)
+++ branches/kmq_dev/http/javascripts/Editor.js 2009-07-14 04:48:15 UTC (rev 4350)
@@ -1,160 +0,0 @@
-
-// 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;
-}
Deleted: branches/kmq_dev/http/javascripts/List.js
===================================================================
--- branches/kmq_dev/http/javascripts/List.js 2009-07-14 03:52:40 UTC (rev 4349)
+++ branches/kmq_dev/http/javascripts/List.js 2009-07-14 04:48:15 UTC (rev 4350)
@@ -1,113 +0,0 @@
-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);
-
- });
-
-};
Deleted: branches/kmq_dev/http/javascripts/Object.js
===================================================================
--- branches/kmq_dev/http/javascripts/Object.js 2009-07-14 03:52:40 UTC (rev 4349)
+++ branches/kmq_dev/http/javascripts/Object.js 2009-07-14 04:48:15 UTC (rev 4350)
@@ -1,287 +0,0 @@
-/* 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_AdminTabs.js
===================================================================
--- branches/kmq_dev/http/javascripts/mod_AdminTabs.js (rev 0)
+++ branches/kmq_dev/http/javascripts/mod_AdminTabs.js 2009-07-14 04:48:15 UTC (rev 4350)
@@ -0,0 +1,160 @@
+//FIXME: "type" shoudl be set by the dataobject recieved form the server
+var MBconfObjectList = function(url,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 = "ObjectType";
+this.element = element;
+this.allEntries = {};
+this.displayEntries = {};
+this.editor = null;
+this.url = url; //RPC endpoint for getting objects
+
+};
+
+MBconfObjectList.prototype.load = function(){
+ var that = this;
+ var options = {
+ url: that.url,
+ method: "list",
+ callback :(function(result,success,message){
+ var users = result.list;
+ that.type = result.type.display || that.type;
+ that.allEntries = users;
+ that.displayEntries = that.allEntries;
+ that.display();
+ })
+ }
+
+ var request = new Mapbender.Ajax.Request(options);
+ request.send();
+
+};
+
+
+MBconfObjectList.prototype.display = function(search){
+ if(!search) {search = "";}
+ while(this.element.firstChild)
+ {
+ this.element.removeChild(this.element.firstChild);
+ }
+ $(this.element).html("");
+
+ var listEntry = $("<li></li>");
+ listEntry.addClass("listFilter");;
+
+ var listFilter = $('<input type="text" >');
+ listFilter.attr('title','filter users by name');
+ listFilter.bind('keyup',this.addOnFilterChangeHandler());
+
+
+ //listEntry.appendChild(listFilter);
+ listEntry.append(listFilter);
+ $(this.element).append(listEntry);
+
+ for(entry in this.displayEntries)
+ {
+ var name = this.displayEntries[entry].name;
+ var value = this.displayEntries[entry].value;
+ listEntry = $("<li></li>");
+ listEntry.html(name);
+ listEntry.bind('click', this.addOnClickHandler(this.displayEntries[entry]));
+ $(this.element).append(listEntry);
+
+ }
+ listEntry = $('<li></li>');
+ listEntry.addClass('listCommand');
+ listEntry.html('Add ' + this.type);
+ listEntry.bind('click',this.addOnClickHandler(value));
+ $(this.element).append(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(key){
+ if(this.editor === null || this.editor === undefined) { return (function(){});}
+ var editor = this.editor;
+ var handler = (function(){
+ editor.load(key.value);
+ });
+ 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);
+ });
+
+};
+
+
+var me = this;
+
+/*var list = $("<ul></ul>");
+list.css("position","absolute");
+list.css("top","1em");
+list.css("left","1em");
+var Tabs = $(me).replaceWith(list);
+*/
+var AdminTabs = function() {
+
+ for(module in Mapbender.modules){
+ if(Mapbender.modules[module].MB_ADMIN_MODULE)
+ {
+ }
+ }
+
+ var adminModules = [];
+ this.register = function(moduleId) {
+ for(var c = 0; c < adminModules.length;c++)
+ {
+ if(adminModules[c] == moduleId) { return; }
+ }
+ adminModules.push(moduleId);
+ init();
+ };
+
+ var init = function() {
+ for(module in adminModules)
+ {
+ //append ul element to body and make it a list
+ var listElement = $("<ul></ul>");
+ listElement.addClass("mbList");
+ $("body").append(listElement);
+ var userList = new MBconfObjectList("http://mapbender/javascripts/user.php",listElement);
+ userList.setEditor(Mapbender.modules[adminModules[module]]);
+ userList.editor.setList(userList);
+ userList.load();
+
+ }
+ };
+
+};
+
+Mapbender.modules[options.id] = new AdminTabs();
+
Modified: branches/kmq_dev/http/javascripts/mod_user.js
===================================================================
--- branches/kmq_dev/http/javascripts/mod_user.js 2009-07-14 03:52:40 UTC (rev 4349)
+++ branches/kmq_dev/http/javascripts/mod_user.js 2009-07-14 04:48:15 UTC (rev 4350)
@@ -1,5 +1,151 @@
-Mapbender.Admin.Modules.User = {};
-//define Mapbender.Modules.User.Editor
-//define Mapbender.Modules.User.ConfObject
-//
+
+// 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;
+};
+
+
+/* MODULE */
+//load html elements into me
+var data = $('\n\
+<div class="mbFrame formContainer UserEditor">\n\
+<h2>UserNameGoesHere</h2>\n\
+<ul class="tabList">\n\
+<li class="active">core data</li>\n\
+<li>rights</li>\n\
+</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\
+</ul>\n\
+<p>\n\
+<input id="'+options.id +'_Save" type="button" value="save" onclick="Mapbender.modules[\''+ options.id +'\'].save(); return false;" />\n\
+</p>\n\
+</form>\n\
+</div>');
+ $(me).replaceWith(data);
+ element = data;
+
+
+ var UserEditor = ConfObjectEditorConstructor(ConfUser,element,options);
+ UserEditor.prototype = new ConfObjectEditor();
+
+ // 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);
+
+ alert("dear jquery how do I disable a button?");
+ var saveButton = $(options.id + "_Save").enabled("");
+ };
+
+ 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();
+
+ 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/mod_user.php
===================================================================
--- branches/kmq_dev/http/javascripts/mod_user.php 2009-07-14 03:52:40 UTC (rev 4349)
+++ branches/kmq_dev/http/javascripts/mod_user.php 2009-07-14 04:48:15 UTC (rev 4350)
@@ -1,16 +1,8 @@
<?php
-
-$mod_user_javascript = <<<JAVASCRIPT
-//<![CDATA[
-
-
-//]]>
-JAVASCRIPT;
-
$mod_user_html = <<<HTML
-<div class="mbFrame formContainer MBUserEditor">
+<div class="mbFrame formContainer UserEditor">
<h2>UserNameGoesHere</h2>
<ul class="tabList">
<li class="active">core data</li>
@@ -34,15 +26,6 @@
</div>
HTML;
+echo $mod_user_html;
-if($_SERVER['QUERY_STRING'] == 'html')
-{
- echo $mod_user_html;
-}
-elseif($_SERVER['QUERY_STRING'] == 'javascript')
-{
- header("Content-Type: text/javascript");
- echo $mod_user_javascript;
-}
-
?>
Modified: branches/kmq_dev/http/javascripts/user.php
===================================================================
--- branches/kmq_dev/http/javascripts/user.php 2009-07-14 03:52:40 UTC (rev 4349)
+++ branches/kmq_dev/http/javascripts/user.php 2009-07-14 04:48:15 UTC (rev 4350)
@@ -6,8 +6,6 @@
//TODO: serious need for errorhandling
-//echo http_get_request_headers();
-#$http_body = file_get_contents('php://input');
$ajaxResponse = new AjaxResponse($_REQUEST);
$method = $ajaxResponse->getMethod(); //get from JSON-RPC
@@ -91,7 +89,7 @@
case 'load':
$name = $ajaxResponse->getParameter('name');
- $user = User::ByName($name);
+ $user = User::byName($name);
if($user == null)
{
$ajaxResponse->setSuccess(false);
@@ -101,6 +99,8 @@
try{
$user->load();
$result = $user->toJSON();
+ $ajaxResponse->setSuccess(true);
+ $ajaxResponse->setMessage($result);
}
catch(Exception $E)
{
@@ -111,7 +111,7 @@
case 'list':
//get list of users
- $result = '[';
+ $result = array();
$users = User::getList('');
if(!$users)
{
@@ -119,17 +119,14 @@
$ajaxResponse->setMessage(_mb("Error fetching list of users"));
}
- print "USER is: " . count($users);
foreach( $users as $user)
{
- //FIXME: need proper way to set result
- $result .= '{"name":"'. $user->name .'",';
- $result .= '"value":"'. $user->name .'"},';
+ $result[] = array ( "name" => $user->name,
+ "value" => $user->name);
}
-
- $result = $result; //TODO:remove trailing ','
- $result .= ']';
- $ajaxResponse->setResult("users",$result);
+ $ajaxResponse->setResult("list",$result);
+ $ajaxResponse->setResult("type", array("display" => _mb("User"),
+ "internal" => "user"));
break;
default:
More information about the Mapbender_commits
mailing list