2011-09-13 52 views
2

我想在Qooxdoo应用程序中有一些对话框,但我不知道如何在某些情况下定义它们。在Qooxdoo演示(它是窗口小部件的例子,函数getModalWindow2)中,我看到窗口可以像一个简单的JS函数一样定义,并返回它的窗口小部件。 是否有更好的方式在Qooxdoo中创建对话框?Qooxdoo对话框

据我所知,我可以定义类的对话框窗口,并为这个类设置一些类的属性。那么,如何在应用程序中添加一些具有复杂形式的对话框?

例如,它可能是服务器上的用户目录树。并且在用户按下“确定”按钮后,树的选定元素必须存储在对话框类的对象中,并且该对话框将被关闭。

回答

1

现在我找到了我自己的问题的答案(在俄罗斯blog关于Qooxdoo,在这里我将翻译答案)。

因此,在主应用程序和对话框的单独文件中有单独的类。

在对话框中,我们正在为通过此事件输出的结果添加qx.event.type.Data

因此,例如,我们有Qooxdoo应用程序,就像在文档中那样命名为“custom”。

在application.js中,我们把这个代码类的工作:

// Adding dialog window 
    this.__uiWindow = new custom.UserDialog(); 
    this.__uiWindow.moveTo(320, 30); 
    this.__uiWindow.open(); 

    // Adding the listener for pressing "Ok" 
    this.__uiWindow.addListener("changeUserData", function (e) { 
     this.debug(e.getData()); 
    }); 

e.getData()是给予所产生的信息。

然后我们必须创建类名为文件UserDialog.js,包含事件和形式:

qx.Class.define("custom.UserDialog", { 
     extend: qx.ui.window.Window, 
     events: { 
      "changeUserData": "qx.event.type.Data" 
     }, 
     construct: function() { 
      this.base(arguments, this.tr("User info")); 

      // Layout 
      var layout = new qx.ui.layout.Basic(); 
      this.setLayout(layout); 
      this.setModal(true); 

      this.__form = new qx.ui.form.Form(); 

      // User id field 
      var usrId = new qx.ui.form.TextField(); 
      this.__form.add(usrId, this.tr("ID"), null, "Id"); 

      // User password field 
      var usrPassword = new qx.ui.form.PasswordField(); 
      usrPassword.setRequired(true); 
      this.__form.add(usrPassword, this.tr("Password"), null, "Password"); 

      // Adding form controller and model 
      var controller = new qx.data.controller.Form(null, this.__form); 
      this.__model = controller.createModel(); 

      // Save button 
      var okbutton = new qx.ui.form.Button(this.tr("Ok")); 
      this.__form.addButton(okbutton); 
      okbutton.addListener("execute", function() { 
       if (this.__form.validate()) { 
        var usrData = qx.util.Serializer.toJson(this.__model); 
        this.fireDataEvent("changeUserData", usrData); 
        this.close(); 
       }; 
      }, this); 

      // Cancel button 
      var cancelbutton = new qx.ui.form.Button(this.tr("Cancel")); 
      this.__form.addButton(cancelbutton); 
      cancelbutton.addListener("execute", function() { 
       this.close(); 
      }, this); 

      var renderer = new qx.ui.form.renderer.Single(this.__form); 
      this.add(renderer); 
     } 
    }); 
+1

好答案!我要改变的唯一事情就是在事件发生之前序列化数据。没有技术需求,那么为什么不交出模型本身作为参考,并在需要时将其序列化到应用程序中? –