svn commit: samba r21048 - in branches/SAMBA_4_0/webapps/swat/source/class/swat/module/ldbbrowse: .

idra at samba.org idra at samba.org
Tue Jan 30 00:09:35 GMT 2007


Author: idra
Date: 2007-01-30 00:09:33 +0000 (Tue, 30 Jan 2007)
New Revision: 21048

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=21048

Log:

Start coding add/modify widgets.
Not functional yet.


Added:
   branches/SAMBA_4_0/webapps/swat/source/class/swat/module/ldbbrowse/LdbModify.js
Modified:
   branches/SAMBA_4_0/webapps/swat/source/class/swat/module/ldbbrowse/Gui.js


Changeset:
Modified: branches/SAMBA_4_0/webapps/swat/source/class/swat/module/ldbbrowse/Gui.js
===================================================================
--- branches/SAMBA_4_0/webapps/swat/source/class/swat/module/ldbbrowse/Gui.js	2007-01-29 22:51:44 UTC (rev 21047)
+++ branches/SAMBA_4_0/webapps/swat/source/class/swat/module/ldbbrowse/Gui.js	2007-01-30 00:09:33 UTC (rev 21048)
@@ -16,6 +16,8 @@
   qx.core.Object.call(this);
 });
 
+//qx.OO.addProperty({ name : "_table", type : "object" });
+//qx.OO.addProperty({ name : "_ldbmod", type : "object" });
 
 /**
  * Build the raw graphical user interface.
@@ -141,7 +143,13 @@
     break;
 
   case "tree_selection_changed":
+
+    // Always update the table, even if it is not visible
     this._displayTreeSelectionChangedResults(module, rpcRequest);
+
+    // Update the base field in ldbmod
+    this._displayLdbmodBaseChanged(module, rpcRequest);
+
     break;
 
   case "database_name_changed":
@@ -300,6 +308,17 @@
   var splitpane = new qx.ui.splitpane.HorizontalSplitPane("1*", "2*");
   splitpane.setEdge(0);
 
+  // We need a vertical box layout for the tree and the buttons
+  var vlayout = new qx.ui.layout.VerticalBoxLayout();
+  vlayout.set({
+               height: "100%",
+               top: 5,
+               left: 5,
+               right: 5,
+               bottom: 5,
+               spacing: 10
+           });
+
   // Create a tree row structure for the tree root
   var trsInstance = qx.ui.treefullcontrol.TreeRowStructure.getInstance();
   var trs = trsInstance.standard(module.dbFile);
@@ -310,11 +329,7 @@
                backgroundColor: 255,
                border: qx.renderer.border.BorderPresets.getInstance().inset,
                overflow: "auto",
-               height: null,
-               top: 10,
-               left: 0,
-               right: 0,
-               bottom: 10,
+               height: "1*",
                open: false,
                alwaysShowPlusMinusSymbol: true
            });
@@ -333,9 +348,37 @@
   fsm.addObject("tree", tree);
   fsm.addObject("tree:manager", tree.getManager());
 
-  // Add the tree to the page.
-  splitpane.addLeft(tree);
+  // Add the tree to the vlayout.
+  vlayout.add(tree);
 
+  // Add an horizonatl layout for the "New" and "Modify" buttons
+  // We need a vertical box layout for the tree and the buttons
+  var hlayout = new qx.ui.layout.HorizontalBoxLayout();
+  hlayout.set({
+               height: "auto",
+               spacing: 10
+           });
+
+  // Add the "New" button
+  this._newb = new qx.ui.form.Button("New");
+  this._newb.addEventListener("execute", this._switchToNewrecord, this);
+
+  // Add the button to the hlayout
+  hlayout.add(this._newb);
+
+  // Add the "New" button
+  this._modb = new qx.ui.form.Button("Modify");
+  this._modb.addEventListener("execute", this._switchToModrecord, this);
+
+  // Add the button to the hlayout
+  hlayout.add(this._modb);
+  
+  // Add the hlayout to the vlayout.
+  vlayout.add(hlayout);
+
+  //Add the left vlayout to the splitpane
+  splitpane.addLeft(vlayout);
+
   // Create a simple table model
   var tableModel = new qx.ui.table.SimpleTableModel();
   tableModel.setColumns([ "Attribute", "Value" ]);
@@ -345,8 +388,8 @@
   fsm.addObject("tableModel:browse", tableModel);
 
   // Create a table
-  var table = new qx.ui.table.Table(tableModel);
-  table.set({
+  this._table = new qx.ui.table.Table(tableModel);
+  this._table.set({
                 top: 10,
                 left: 0,
                 right: 0,
@@ -354,24 +397,66 @@
                 statusBarVisible: false,
                 columnVisibilityButtonVisible: false
             });
-  table.setColumnWidth(0, 180);
-  table.setColumnWidth(1, 320);
-  table.setMetaColumnCounts([1, -1]);
-  fsm.addObject("table:browse", table);
+  this._table.setColumnWidth(0, 180);
+  this._table.setColumnWidth(1, 320);
+  this._table.setMetaColumnCounts([1, -1]);
+  fsm.addObject("table:browse", this._table);
 
+  //table.setDisplay(false);
+
   // Add the table to the bottom portion of the splitpane
-  splitpane.addRight(table);
+  splitpane.addRight(this._table);
 
+  // Build the create/modify widget
+  this._ldbmod = new swat.module.ldbbrowse.LdbModify(fsm);
+  this._ldbmod.set({
+                top: 10,
+                left: 0,
+                right: 0,
+                bottom: 10
+            });
+  // Not displayed by default
+  this._ldbmod.setDisplay(false);
+
+  fsm.addObject("ldbmod:browse", this._ldbmod);
+
+  splitpane.addRight(this._ldbmod);
+
   // Add the first splitpane to the page
   page.add(splitpane);
 };
 
+qx.Proto._switchToNormal = function()
+{
+  this._table.setDisplay(true);
+  this._ldbmod.setDisplay(false);
+  this._newb.setEnabled(true);
+  this._modb.setEnabled(true);
+}
 
+qx.Proto._switchToNewrecord = function()
+{
+  this._table.setDisplay(false);
+  this._ldbmod.setDisplay(true);
+  this._newb.setEnabled(false);
+  this._modb.setEnabled(false);
+  this._ldbmod.initNew(this._switchToNormal, this);
+}
+
+qx.Proto._switchToModrecord = function()
+{
+  this._table.setDisplay(false);
+  this._ldbmod.setDisplay(true);
+  this._newb.setEnabled(false);
+  this._modb.setEnabled(false);
+  this._ldbmod.initMod(this._table, this._switchToNormal, this);
+}
+
 qx.Proto._displaySearchResults = function(module, rpcRequest)
 {
   var fsm = module.fsm;
 
-  // Obtain the table and tableModel objects
+  // Obtain the ldif object
   var ldifview = fsm.getObject("LdifView");
 
   ldifview.reset();
@@ -455,7 +540,23 @@
   }
 };
 
+qx.Proto._displayLdbmodBaseChanged = function(module, rpcRequest)
+{
+  var fsm = module.fsm;
 
+  // Obtain the result object
+  var result = rpcRequest.getUserData("result").data;
+
+  // If we received an empty list, ...
+  if (result == null)
+  {
+    // ... then ??
+    return;
+  }
+
+  this._ldbmod.setBase(result[0]["dn"]);
+};
+
 qx.Proto._displayTreeSelectionChangedResults = function(module, rpcRequest)
 {
   var fsm = module.fsm;

Added: branches/SAMBA_4_0/webapps/swat/source/class/swat/module/ldbbrowse/LdbModify.js
===================================================================
--- branches/SAMBA_4_0/webapps/swat/source/class/swat/module/ldbbrowse/LdbModify.js	2007-01-29 22:51:44 UTC (rev 21047)
+++ branches/SAMBA_4_0/webapps/swat/source/class/swat/module/ldbbrowse/LdbModify.js	2007-01-30 00:09:33 UTC (rev 21048)
@@ -0,0 +1,197 @@
+/*                                                                                                                    
+ * Copyright::                                                                                                         
+ *   (C) 2006 by Simo Sorce
+ * 
+ * License: 
+ *   GPL v2 or later
+ */
+
+/**
+ * Ldb Modifier Class
+ */
+
+qx.OO.defineClass("swat.module.ldbbrowse.LdbModify", qx.ui.layout.VerticalBoxLayout,
+function(fsm)
+{
+  qx.ui.layout.VerticalBoxLayout.call(this);
+
+  this._mainArea = new qx.ui.layout.VerticalBoxLayout();
+  this._mainArea.set({
+                     height: "1*",
+                     spacing: 5
+                    });
+
+  // Add an horizonatl layout for the "New" and "Modify" buttons
+  // We need a vertical box layout for the tree and the buttons
+  this._hlayout = new qx.ui.layout.HorizontalBoxLayout();
+  this._hlayout.set({
+               height: "auto",
+               spacing: 10
+           });
+
+  // add a spacer to align buttons to the right
+  this._leftSpacer = new qx.ui.basic.HorizontalSpacer();
+
+  // Add the "Cancel" button
+  this._cancelbtn = new qx.ui.form.Button("Cancel");
+  this._cancelbtn.addEventListener("execute", this._cancelOp, this);
+
+  // Add the "OK" button
+  this._okbtn = new qx.ui.form.Button("OK");
+  this._okbtn.addEventListener("execute", fsm.eventListener, fsm);
+
+  // We'll be receiving events on the object, so save its friendly name
+  fsm.addObject("domod", this._okbtn, "swat.main.fsmUtils.disable_during_rpc");
+
+  // Add the buttons to the hlayout
+  this._hlayout.add(this._leftSpacer, this._cancelbtn, this._okbtn);
+  
+  // Add the hlayout to the vlayout.
+  this.add(this._mainArea, this._hlayout);
+
+  // By default this is a new record creator
+  this._type = "new";
+
+  // By default this is inactive
+  this._active = false;
+
+  this.basedn = "";
+});
+
+qx.OO.addProperty({ name : "basedn", type : "string" });
+
+/**
+ * Set the type of operation
+ * 
+ * @param type {String}
+ *   A string containing "new" or "modify"
+ *
+ * @param data {object}
+ *   An LDB object with the current object parameters
+ *   Used only if type = "modify"
+ *
+ */
+
+qx.Proto.isActive = function() {
+  if (this._active == true) {
+    return true;
+  }
+}
+
+/** 
+ * Set the base of the object to add
+ *
+ * @param type {string}
+ *   A string containing the base DN
+ */
+
+qx.Proto.setBase = function(base) {
+
+  this.basedn = base;
+
+  if (this._active) {
+    if (this._type == "new") {
+
+      this._basedn.setValue(this.basedn);
+      this._basedn.setWidth(8 * this.basedn.length);
+    }
+  }
+}
+
+qx.Proto.initNew = function(callback, obj) {
+
+  this._setExitCallback(callback, obj);
+
+  this._active = true;
+  this._type = "new";
+
+  var hlayout = new qx.ui.layout.HorizontalBoxLayout();
+  hlayout.set({ height: "auto", spacing: 10 });
+
+  var dnlabel = new qx.ui.basic.Label("DN: ");
+
+  // The name of the new/modified object
+  // TODO: add validator
+  this._rdn = new qx.ui.form.TextField(""); 
+  this._rdn.setWidth(128);
+
+  var dnsep = new qx.ui.basic.Label(",");
+
+  // The basedn of the object
+  // TODO: add validator
+  this._basedn = new qx.ui.form.TextField(this.basedn);
+  this._basedn.setWidth(8 * this.basedn.length);
+
+  hlayout.add(dnlabel, this._rdn, dnsep, this._basedn);
+
+  this._mainArea.add(hlayout);
+
+  return;
+}
+
+qx.Proto.initMod = function(table, callback, obj) {
+
+  this._setExitCallback(callback, obj);
+
+  if (this.basedn == "") {
+    this._callExitCallback();
+    return;
+  }
+
+  this._active = true;
+  this._type = "modify";
+
+  this._dn = new qx.ui.basic.Label("DN: " + this.basedn);
+
+  this._mainArea.add(this._dn);
+
+  //TODO: for each entry in the table, add new entries in the object
+
+  return;
+}
+
+qx.Proto._setExitCallback = function(vFunction, vObject) {
+
+  if(typeof vFunction !== "function") {
+    throw new Error("swat.module.ldbbrowse.LdbModify: setExitCallback(" + vFunction + "' is not a function!");
+  }
+
+  this._exitCallback = {
+      handler : vFunction,
+      object : vObject
+    }
+}
+
+qx.Proto._callExitCallback = function() {
+
+  // Shortcuts for handler and object
+  vFunction = this._exitCallback.handler;
+  vObject = this._exitCallback.object;
+
+  // Call object function
+  try
+  {
+    if(typeof vFunction === "function") {
+      vFunction.call(qx.util.Validation.isValid(vObject) ? vObject : this);
+    }
+  }
+  catch(ex)
+  {
+    this.error("swat.module.ldbbrowse.LdbModify: Could not call exit callback: ", ex);
+  }
+}
+
+qx.Proto._reset = function() {
+
+  // Remove existing attributes
+  this._mainArea.removeAll();
+  this._active = false;
+  this._type = "null";
+  return;
+}
+
+qx.Proto._cancelOp = function() {
+
+  this._reset();
+  this._callExitCallback();
+}



More information about the samba-cvs mailing list