2011-09-13 59 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

好答案!我要改變的唯一事情就是在事件發生之前序列化數據。沒有技術需求,那麼爲什麼不交出模型本身作爲參考,並在需要時將其序列化到應用程序中? –