2

Is there any class (like goog.ui.dialog) that let me show a dialog which its content can be fetched by ajax from another file?

  • Is goog.ui.Dialog an appropriate class for this goal?
  • Shall I implement it by other fundamental classes such as good.net.XHR and goog.ui.Popup?
ehsun7b
  • 4,796
  • 14
  • 59
  • 98

1 Answers1

2

You can extends the goog.ui.dialog and fetch the content.

A simple example wich can help you:

my.ui.Dialog = function(opt_iframe) {
  goog.ui.Dialog.call(this, null, opt_iframe);

  this.xhr_  = new goog.net.XhrIo();
  this.xhr_.addEventListener(goog.net.EventType.COMPLETE,
                             this.onComplete_, false, this);

  goog.events.listen(this, goog.ui.Dialog.EventType.SELECT,
                     this.dispatch_, false, this);
};
my.ui.Dialog.prototype.buildWindow_ = function (responseJson) {
  this.setTitle(responseJson.title);
  this.setContent(responseJson.content);
  this.setButtonSet(eval(responseJson.buttons));
};
my.ui.Dialog.EventType = {
  'COMPLETE': 'complete'
};
my.ui.Dialog.prototype.onComplete_ = function (event) {
var json = this.xhr_.getResponseJson ()
    this.buildWindow_ (json);
    this.reposition ();
};
my.ui.Dialog.prototype.send = function (uri, method, post_data) {
  this.xhr_.send(uri, method, post_data, null, {'X-DIALOG':'AJAX'});
};
goog.inherits (my.ui.Dialog, goog.ui.Dialog);

That's use a response in json to build the ui.Dialog like this:

{"buttons": "goog.ui.Dialog.Buttons.OK_CANCEL", 
 "content": "<html><body><h1>Hello</h1></body></html>", 
 "title": "Hello World"}

This example can don't work directly :/

sahid
  • 2,570
  • 19
  • 25