[Mapbender-commits] r4355 - branches/kmq_dev/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jul 15 04:00:40 EDT 2009


Author: kmq
Date: 2009-07-15 04:00:39 -0400 (Wed, 15 Jul 2009)
New Revision: 4355

Added:
   branches/kmq_dev/http/javascripts/mod_group.js
Log:
Group Editor, done slighlty different (better) than the UserEditor

Added: branches/kmq_dev/http/javascripts/mod_group.js
===================================================================
--- branches/kmq_dev/http/javascripts/mod_group.js	                        (rev 0)
+++ branches/kmq_dev/http/javascripts/mod_group.js	2009-07-15 08:00:39 UTC (rev 4355)
@@ -0,0 +1,199 @@
+
+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.fields = [];
+  this.fields.name  = { name: "name", defaultValue : "", value: "", display: "Group Name",  type: "text"};
+  this.fields.owner = { name: "owner",       defaultValue : "", value:"", display: "Owner",       type: "text"};
+
+  this.name = this.fields.name.value;
+  
+  $(me).replaceWith(form);
+  me = form;
+  this.reset();
+
+};
+
+GroupEditor.prototype = new ConfEditor();
+GroupEditor.prototype.constructor = GroupEditor;
+Mapbender.modules[options.id] = new GroupEditor();



More information about the Mapbender_commits mailing list