r21126: Enhance the modal window so that it gets focus and just presing enter works.
authorSimo Sorce <idra@samba.org>
Fri, 2 Feb 2007 17:38:04 +0000 (17:38 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:44:31 +0000 (14:44 -0500)
Still I don't see the cursor :(

Swap -/+ buttons, you risk to delete an attribute by mistake when instead you want to add a new one,
and you might even not notice it.

Simo.

webapps/swat/source/class/swat/module/ldbbrowse/LdbModify.js

index ff05872e6afb23d05ca4d619b0196b7cebff5010..cb1b326d7cb33a9d82e2145ddda08a8cb33a1719 100644 (file)
@@ -57,6 +57,8 @@ function(fsm)
   this._active = false;
 
   this.basedn = "";
+
+  this._amw = null;
 });
 
 qx.OO.addProperty({ name : "basedn", type : "string" });
@@ -214,11 +216,11 @@ qx.Proto._addNewAttribute = function(name, value, before) {
   var hlayout = new qx.ui.layout.HorizontalBoxLayout();
   hlayout.set({ width: "auto", height: "auto", spacing: 10 });
 
-  var rButton = new qx.ui.form.Button("-");
-  rButton.set({ width: 15, height: 15});
-  rButton.addEventListener("execute", function() {
-    hlayout.setParent(null);
-  });
+  var aButton = new qx.ui.form.Button("+");
+  aButton.set({ width: 15, height: 15});
+  aButton.addEventListener("execute", function() {
+    this._addNewAttribute(name, null, hlayout);
+  }, this);
 
   var aLabel = new qx.ui.basic.Label(name);
   aLabel.setWidth(150);
@@ -226,17 +228,18 @@ qx.Proto._addNewAttribute = function(name, value, before) {
   var aTextField = new qx.ui.form.TextField(value);
   aTextField.setWidth(250);
 
-  var aButton = new qx.ui.form.Button("+");
-  aButton.set({ left: 5, width: 15, height: 15});
-  aButton.addEventListener("execute", function() {
-    this._addNewAttribute(name, null, hlayout);
+  var rButton = new qx.ui.form.Button("-");
+  rButton.set({ left: 5, width: 15, height: 15});
+  rButton.addEventListener("execute", function() {
+    hlayout.setParent(null);
   }, this);
 
-  hlayout.add(rButton, aLabel, aTextField, aButton);
+  hlayout.add(aButton, aLabel, aTextField, rButton);
 
   if (before) {
     this._attrArea.addAfter(hlayout, before);
   } else {
+    //TODO: check the same attribute is not already present, if so just add a new value instead
     this._attrArea.addBefore(hlayout, this._attrAddButton);
   }
 }
@@ -245,39 +248,51 @@ qx.Proto._createNewAttribute = function() {
 
   var main = qx.ui.core.ClientDocument.getInstance();
 
-  var amw = new qx.ui.window.Window("New Attribute Name");
-  amw.set({
-    width: 200,
-    height: 70,
-    modal: true,
-    centered: true,
-    restrictToPageOnOpen: true,
-    showMinimize: false,
-    showMaximize: false,
-    showClose: false,
-    resizeable: false
-  });
-
-
-  var attrName = new qx.ui.form.TextField();
-  attrName.addEventListener("execute", function() {
-    this._addNewAttribute(attrName.getValue());
-    amw.close();
-  }, this);
-  attrName.set({ top: 15, left: 10 });
-  amw.add(attrName);
-
-  var okButton = new qx.ui.form.Button("OK");
-  okButton.addEventListener("execute", function() {
-    this._addNewAttribute(attrName.getValue());
-    amw.close();
-  }, this);
-  okButton.set({ top: 12, left: 155 });
-  amw.add(okButton);
-
-  main.add(amw);
+  if (this._amw == null) {
+
+    this._amw = new qx.ui.window.Window("New Attribute Name");
+    this._amw.set({
+      width: 200,
+      height: 70,
+      modal: true,
+      centered: true,
+      restrictToPageOnOpen: true,
+      showMinimize: false,
+      showMaximize: false,
+      showClose: false,
+      resizeable: false
+    });
+
+    attrName = new qx.ui.form.TextField();
+    var enterCommand = new qx.client.Command("Enter");
+    enterCommand.addEventListener("execute", function() { 
+      this._addNewAttribute(attrName.getComputedValue());
+      this._amw.close();
+    }, this);
+    attrName.set({ top: 15, left: 10, command: enterCommand });
+    this._amw.add(attrName);
+
+    this._amw.setUserData("textfield", attrName);
+    var okButton = new qx.ui.form.Button("OK");
+    okButton.addEventListener("execute", function() {
+      this._addNewAttribute(attrName.getValue());
+      this._amw.close();
+    }, this);
+    okButton.set({ top: 12, left: 155 });
+    this._amw.add(okButton);
+
+    this._amw.addEventListener("appear",function() {
+      attrName.focus();
+    }, this._amw);
+  
+    main.add(this._amw);
+  }
+  else {
+    this._amw.getUserData("textfield").setValue("");
+  }
 
-  amw.open();
+  this._amw.open();
 }
 
 qx.Proto._createAttributesArea = function() {