2011-08-25 22:08:39 -03:00
|
|
|
/*
|
2011-10-15 02:52:44 -03:00
|
|
|
---
|
|
|
|
name: MooDialog.Request
|
|
|
|
description: Loads Data into a Dialog with Request
|
|
|
|
authors: Arian Stolwijk
|
|
|
|
license: MIT-style license
|
|
|
|
requires: [MooDialog, Core/Request.HTML]
|
|
|
|
provides: MooDialog.Request
|
|
|
|
...
|
|
|
|
*/
|
2011-08-25 22:08:39 -03:00
|
|
|
|
|
|
|
MooDialog.Request = new Class({
|
|
|
|
|
2011-10-15 02:52:44 -03:00
|
|
|
Extends: MooDialog,
|
2011-08-25 22:08:39 -03:00
|
|
|
|
2011-10-15 02:52:44 -03:00
|
|
|
initialize: function(url, requestOptions, options) {
|
|
|
|
this.parent(options);
|
2011-10-17 10:12:27 -03:00
|
|
|
this.requestOptions = requestOptions || {};
|
2011-10-16 21:42:02 -03:00
|
|
|
this.requestOptions.update = this.content;
|
|
|
|
this.requestOptions.evalScripts = true;
|
2011-10-17 10:12:27 -03:00
|
|
|
this.requestOptions.noCache = true;
|
|
|
|
|
|
|
|
this.requestOptions.onFailure = function(xhr) {
|
|
|
|
// Intercept form requests ...
|
|
|
|
console.log("Failure:");
|
|
|
|
console.log(xhr);
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
this.requestOptions.onSuccess = function() {
|
|
|
|
// Intercept form requests ...
|
|
|
|
var forms = this.content.getElements('form');
|
|
|
|
forms.forEach(function(form) {
|
|
|
|
form.addEvent('submit', function(event) {
|
|
|
|
// Intercept form ...
|
|
|
|
this.requestOptions.url = form.action;
|
|
|
|
this.requestOptions.method = form.method ? form.method : 'post';
|
|
|
|
var request = new Request.HTML(this.requestOptions);
|
|
|
|
request.post(form);
|
|
|
|
event.stopPropagation();
|
|
|
|
return false;
|
|
|
|
}.bind(this))
|
|
|
|
}.bind(this));
|
|
|
|
}.bind(this);
|
|
|
|
|
2011-10-15 02:52:44 -03:00
|
|
|
this.addEvent('open', function() {
|
2011-10-17 10:12:27 -03:00
|
|
|
this.requestOptions.url = url;
|
|
|
|
this.requestOptions.method = 'get';
|
|
|
|
var request = new Request.HTML(this.requestOptions);
|
|
|
|
request.send();
|
|
|
|
|
2011-10-16 21:42:02 -03:00
|
|
|
MooDialog.Request.active = this;
|
2011-10-15 02:52:44 -03:00
|
|
|
}.bind(this));
|
2011-08-25 22:08:39 -03:00
|
|
|
|
2011-10-17 10:12:27 -03:00
|
|
|
this.addEvent('close', function() {
|
|
|
|
MooDialog.Request.active = null;
|
|
|
|
}.bind(this));
|
2011-08-25 22:08:39 -03:00
|
|
|
|
2011-10-17 10:12:27 -03:00
|
|
|
if (this.options.autoOpen) this.open();
|
2011-08-25 22:08:39 -03:00
|
|
|
},
|
|
|
|
|
2011-10-15 02:52:44 -03:00
|
|
|
setRequestOptions: function(options) {
|
|
|
|
this.requestOptions = Object.merge(this.requestOptions, options);
|
|
|
|
return this;
|
|
|
|
}
|
2011-08-25 22:08:39 -03:00
|
|
|
|
|
|
|
});
|