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

idra at samba.org idra at samba.org
Fri Feb 9 23:43:43 GMT 2007


Author: idra
Date: 2007-02-09 23:43:42 +0000 (Fri, 09 Feb 2007)
New Revision: 21266

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

Log:

Add/Modify/Delete operations seem to work correctly now
Still no refresh, so the results may seem confusing


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


Changeset:
Modified: branches/SAMBA_4_0/webapps/swat/source/class/swat/module/ldbbrowse/Fsm.js
===================================================================
--- branches/SAMBA_4_0/webapps/swat/source/class/swat/module/ldbbrowse/Fsm.js	2007-02-09 23:14:23 UTC (rev 21265)
+++ branches/SAMBA_4_0/webapps/swat/source/class/swat/module/ldbbrowse/Fsm.js	2007-02-09 23:43:42 UTC (rev 21266)
@@ -85,7 +85,10 @@
               "Transition_Idle_to_AwaitRpcResult_via_search",
 
             "commit" :
-              "Transition_Idle_to_AwaitRpcResult_via_commit"
+              "Transition_Idle_to_AwaitRpcResult_via_commit",
+
+            "delete" :
+              "Transition_Idle_to_AwaitRpcResult_via_delete"
           },
 
           // If a previously unexpanded tree node is expanded, issue a request
@@ -210,6 +213,45 @@
   /*
    * Transition: Idle to AwaitRpcResult
    *
+   * Cause: "execute" on OK button
+   *
+   * Action:
+   *  Delete a record from ldb
+   */
+  var trans = new qx.util.fsm.Transition(
+    "Transition_Idle_to_AwaitRpcResult_via_delete",
+    {
+      "nextState" :
+        "State_AwaitRpcResult",
+
+      "ontransition" :
+        function(fsm, event)
+        {
+          // Get our module descriptor
+          var module = fsm.getObject("swat.main.module");
+
+          // Retrieve the database handle
+          var dbHandle = module.dbHandle;
+
+          // Retrieve the ldbmod object
+          var ldbmod = fsm.getObject("ldbmod");
+
+          // Issue a Search call
+          var request = _this.callRpc(fsm,
+                                      "samba.ldb",
+                                      "del",
+				      [ dbHandle, ldbmod.getBase() ]);
+
+          // When we get the result, we'll need to know what type of request
+          // we made.
+          request.setUserData("requestType", "delete");
+        }
+    });
+  state.addTransition(trans);
+
+  /*
+   * Transition: Idle to AwaitRpcResult
+   *
    * Cause: "treeOpenWhileEmpty" on tree
    *
    * Action:

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-02-09 23:14:23 UTC (rev 21265)
+++ branches/SAMBA_4_0/webapps/swat/source/class/swat/module/ldbbrowse/Gui.js	2007-02-09 23:43:42 UTC (rev 21266)
@@ -139,7 +139,9 @@
     break;
 
   case "add":
-    this._displayCommitResults(module, rpcRequest, "add");
+  case "modify":
+  case "delete":
+    this._displayCommitResults(module, rpcRequest, requestType);
     break;
  
   case "tree_open":
@@ -478,52 +480,11 @@
 
 qx.Proto._confirmDeleteRecord = function()
 {
-
-  var main = qx.ui.core.ClientDocument.getInstance();
-
-  if (this._dmw == null) {
-
-    this._dmw = new qx.ui.window.Window("New Attribute Name");
-    this._dmw.set({
-      width: 200,
-      height: 100,
-      modal: true,
-      centered: true,
-      restrictToPageOnOpen: true,
-      showMinimize: false,
-      showMaximize: false,
-      showClose: false,
-      resizeable: false
-    });
-
-    var warningLabel = new qx.ui.basic.Label("Are you sure you want to delete <record name here> ?");
-    this._dmw.add(warningLabel);
-
-    var cancelButton = new qx.ui.form.Button("Cancel");
-    cancelButton.addEventListener("execute", function() {
-      this._dmw.close();
-    }, this);
-    cancelButton.set({ top: 45, left: 32 }); 
-    this._dmw.add(cancelButton);
-
-    this._dmw.addEventListener("appear",function() { 
-      cancelButton.focus();
-    }, this._dmw);
-
-    main.add(this._dmw);
-    var okButton = new qx.ui.form.Button("OK");
-    okButton.addEventListener("execute", function() {
-      //TODO: call search.addEventListener("execute", fsm.eventListener, fsm);
-      
-      this._dmw.close();
-    }, this);
-    okButton.set({ top: 45, right: 32 });
-    this._dmw.add(okButton);
-
-    main.add(this._dmw);
-  }
-
-  this._dmw.open();
+  
+  //this._newb.setEnabled(false);
+  //this._modb.setEnabled(false);
+  //this._delb.setEnabled(false);
+  this._ldbmod.showConfirmDelete();
 };
 
 qx.Proto._displayCommitResults = function(module, rpcRequest, type)

Modified: 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-02-09 23:14:23 UTC (rev 21265)
+++ branches/SAMBA_4_0/webapps/swat/source/class/swat/module/ldbbrowse/LdbModify.js	2007-02-09 23:43:42 UTC (rev 21266)
@@ -15,6 +15,8 @@
 {
   qx.ui.layout.VerticalBoxLayout.call(this);
 
+  this._fsm = fsm;
+
   this._mainArea = new qx.ui.layout.VerticalBoxLayout();
   this._mainArea.set({
                      overflow: "auto",
@@ -39,10 +41,10 @@
 
   // Add the "OK" button
   this._okbtn = new qx.ui.form.Button("OK");
-  this._okbtn.addEventListener("execute", fsm.eventListener, fsm);
+  this._okbtn.addEventListener("execute", this._fsm.eventListener, this._fsm);
 
   // We'll be receiving events on the object, so save its friendly name
-  fsm.addObject("commit", this._okbtn, "swat.main.fsmUtils.disable_during_rpc");
+  this._fsm.addObject("commit", this._okbtn, "swat.main.fsmUtils.disable_during_rpc");
 
   // Add the buttons to the hlayout
   this._hlayout.add(this._leftSpacer, this._cancelbtn, this._okbtn);
@@ -58,7 +60,7 @@
 
   this.basedn = "";
 
-  this._amw = null;
+  this._dmw = null;
 });
 
 qx.OO.addProperty({ name : "basedn", type : "string" });
@@ -101,6 +103,12 @@
   }
 }
 
+qx.Proto.getBase = function() {
+
+  return this.basedn;
+
+}
+
 qx.Proto.initNew = function(callback, obj) {
 
   this._setExitCallback(callback, obj);
@@ -152,14 +160,18 @@
 
   this._createAttributesArea();
 
+  this._modBaseHash = new Array();
+
   // for each entry in the table, add new entries in the object
   var count = tablemodel.getRowCount();
   for (var i = 0; i < count; i++) {
     var row = tablemodel.getRowData(i);
     this._addNewAttribute(row[0], row[1]);
+    if (this._modBaseHash[row[0]] == null) {
+      this._modBaseHash[row[0]] = new Array();
+    }
+    this._modBaseHash[row[0]].push(row[1]);
   }
-
-  this._modBaseTableModel = tablemodel;
 }
 
 qx.Proto._setExitCallback = function(vFunction, vObject) {
@@ -268,23 +280,215 @@
 }
 
 qx.Proto.getLdif = function() {
-  //TODO: modify
-  if (this._type != "add") {
+
+  if (this._active != true) {
     return null;
   }
 
-  var ldif = "# Add operation\n";
-  ldif = ldif + "dn: " + this._rdn.getValue() + "," + this._basedn.getValue() + "\n";
-
   c = this._attrArea.getChildren();
 
-  for (var i = 0; i < c.length; i++) {
-    if (c[i] instanceof qx.ui.layout.HorizontalBoxLayout) {
-      ldif = ldif + c[i].getUserData("attrName").getComputedValue() + ": " + c[i].getUserData("attrVal").getComputedValue() + "\n";
+  switch (this._type) {
+
+  case "add":
+
+    var ldif = "dn: " + this._rdn.getValue() + "," + this._basedn.getValue() + "\n";
+
+    for (var i = 0; i < c.length; i++) {
+      if (c[i] instanceof qx.ui.layout.HorizontalBoxLayout) {
+        ldif = ldif + c[i].getUserData("attrName").getComputedValue() + ": " + c[i].getUserData("attrVal").getComputedValue() + "\n";
+      }
     }
+    break;
+
+  case "modify":
+
+    var ldif = "dn: " + this.basedn + "\n";
+
+    ldif = ldif + "changetype: modify\n";
+
+    var submAttrs = new Array();
+
+    // Build an array of the submitted data
+    for (var i = 0; i < c.length; i++) {
+      if (c[i] instanceof qx.ui.layout.HorizontalBoxLayout) {
+
+        var attrName = c[i].getUserData("attrName").getComputedValue();
+        var attrVal = c[i].getUserData("attrVal").getComputedValue();
+        
+        if (submAttrs[attrName] == null) {
+          submAttrs[attrName] = new Array();
+        }
+        submAttrs[attrName].push(attrVal);
+      }
+    }
+
+    // compare arrays and find out what changed, built an hash of the modifications
+    var modAttrs = new Array();
+
+    for (var i in this._modBaseHash) {
+      modAttrs[i] = new Array();
+      modAttrs[i][0] = "skip";
+
+      if (submAttrs[i] == null) {
+        modAttrs[i][0] = "delete";
+      } else {
+        // check if the arrays are identical
+        if (this._modBaseHash[i].length <= submAttrs[i].length) {
+          for (var j = 0; j < this._modBaseHash[i].length; j++) {
+            for (var k = 0; k < submAttrs[i].length; k++) {
+              if (this._modBaseHash[i][j] == submAttrs[i][k]) {
+                break;
+              }
+            }
+            if (k >= submAttrs[i].length) {
+              modAttrs[i][0] = "replace";
+              break;
+            }
+          }
+          // if all the attributes in base hash are contained in sumbAttr
+          // it means only additions were done, sort out what was addedd
+          if (modAttrs[i][0] != "replace") {
+            for (var j = 0; j < submAttrs[i].length; j++) {
+              for (var k = 0; k < this._modBaseHash[i].length; k++) {
+                if (submAttrs[i][j] == this._modBaseHash[i][k]) break;
+              }
+              // this element was not found in original array
+              if (k >= this._modBaseHash[i].length) {
+                if (modAttrs[i][0] != "add") {
+                  modAttrs[i][0] = "add";
+                }
+                modAttrs[i].push(submAttrs[i][j]);
+              }
+            }
+          }
+        } else {
+          modAttrs[i] = [ "replace" ];
+        }
+      }
+      // if they differ replace the whole content
+      if (modAttrs[i][0] == "replace") {
+        for (var j = 0; j < submAttrs[i].length; j++) {
+          modAttrs[i].push(submAttrs[i][j]);
+        }
+      }
+
+      // wipe out attr from sumbAttr, so that we can later found truly new attrs addedd to the array
+      submAttrs[i] = null;
+    }
+
+    for (var i in submAttrs) {
+      if (submAttrs[i] != null) {
+        modAttrs[i] = new Array();
+        modAttrs[i][0] = "add";
+
+        for (var j = 0; j < submAttrs[i].length; j++) {
+          modAttrs[i].push(submAttrs[i][j]);
+        }
+      }
+    }
+
+    //track if we did any mod at all
+    var nmods = 0;
+
+    for (var i in modAttrs) {
+      switch (modAttrs[i][0]) {
+
+      case "delete":
+        nmods++;
+        ldif = ldif + "delete: " + i + "\n";
+        break;
+
+      case "add":
+        nmods++;
+        ldif = ldif + "add: " + i + "\n";
+        for (var j = 1; j < modAttrs[i].length; j++) {
+          ldif = ldif + i + ": " + modAttrs[i][j] + "\n";
+        }
+        break;
+
+      case "replace":
+        nmods++;
+        ldif = ldif + "replace: " + i + "\n";
+        for (var j = 1; j < modAttrs[i].length; j++) {
+          ldif = ldif + i + ": " + modAttrs[i][j] + "\n";
+        }
+        break;
+
+      default:
+        //skip
+        break;
+      }
+    }
+
+    if (nmods == 0) {
+      alert("No modifications?");
+    }
+
+    break;
+
+  default:
+
+    return null;
+
   }
+
   // terminate ldif record
   ldif = ldif + "\n";
 
   return ldif;
-}
+};
+
+qx.Proto.showConfirmDelete = function() {
+
+  var main = qx.ui.core.ClientDocument.getInstance();
+
+  if (this._dmw == null) {
+    this._dmw = new qx.ui.window.Window("-- DELETE Object --");
+    this._dmw.set({
+      width: 300,
+      height: 125,
+      modal: true,
+      centered: true,
+      restrictToPageOnOpen: true,
+      showMinimize: false,
+      showMaximize: false,
+      showClose: false,
+      resizeable: false
+    });
+
+    var warningLabel = new qx.ui.basic.Label("Error Dialog not initialized!");
+    this._dmw.add(warningLabel);
+    this._dmw.setUserData("label", warningLabel);
+
+    var cancelButton = new qx.ui.form.Button("Cancel");
+    cancelButton.addEventListener("execute", function() {
+      this._dmw.close();
+    }, this);
+    cancelButton.set({ top: 45, left: 32 }); 
+    this._dmw.add(cancelButton);
+
+    this._dmw.addEventListener("appear",function() { 
+      cancelButton.focus();
+    }, this._dmw);
+
+    main.add(this._dmw);
+    var okButton = new qx.ui.form.Button("OK");
+    okButton.addEventListener("execute", function() {
+      this._dmw.close();
+    }, this);
+    // We'll be receiving events on the object, so save its friendly name
+    this._fsm.addObject("delete", okButton, "swat.main.fsmUtils.disable_during_rpc");
+    okButton.addEventListener("execute", this._fsm.eventListener, this._fsm);
+      
+    okButton.set({ top: 45, right: 32 });
+    this._dmw.add(okButton);
+
+    main.add(this._dmw);
+  }
+
+  var label = this._dmw.getUserData("label");
+
+  label.setHtml("<pre>Do you really want to delete\n" + this.basedn + " ?</pre>");
+
+  this._dmw.open();
+};



More information about the samba-cvs mailing list