Handles the basic functionality of submitting a form and updating a dom element with the result. The result is appended to the DOM element instead of replacing its contents.
Form.Request.Append = new Class({
Extends: Form.Request,
options: {
onBeforeEffect: function(){},
useReveal: true,
revealOptions: {},
inject: 'bottom'
},
makeRequest: function(){
this.request = new Request.HTML(Object.merge({
url: this.element.get('action'),
method: this.element.get('method') || 'post',
spinnerTarget: this.element
}, this.options.requestOptions, {
evalScripts: false
})
).addEvents({
success: function(tree, elements, html, javascript){
var container;
var kids = Elements.from(html);
if (kids.length == 1){
container = kids[0];
} else {
container = new Element('div', {
styles: {
display: 'none'
}
}).adopt(kids);
}
container.inject(this.update, this.options.inject);
if (this.options.requestOptions.evalScripts) Browser.exec(javascript);
this.fireEvent('beforeEffect', container);
var finish = function(){
this.fireEvent('success', [container, this.update, tree, elements, html, javascript]);
}.bind(this);
if (this.options.useReveal){
container.get('reveal', this.options.revealOptions).chain(finish);
container.reveal();
} else {
finish();
}
}.bind(this),
failure: function(xhr){
this.fireEvent('failure', xhr);
}.bind(this)
});
}
});