mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
4a5d9b03f8
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@39001 467b73ca-7a2a-4603-9d3b-597d59a354a9
92 lines
2.7 KiB
JavaScript
Executable File
92 lines
2.7 KiB
JavaScript
Executable File
ComplexTableFieldPopupForm = Class.create();
|
|
ComplexTableFieldPopupForm.prototype = {
|
|
initialize: function() {
|
|
Behaviour.register({
|
|
"form#ComplexTableField_Popup_DetailForm .Actions input.action": {
|
|
onclick: this.submitForm.bind(this)
|
|
}
|
|
});
|
|
},
|
|
|
|
submitForm : function(e) {
|
|
// if custom validation implementation (extend class to implement)
|
|
if(this.validate) {
|
|
if(!this.validate()) {
|
|
Event.stop(e);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// only do ajaxy stuff for content loaded in an iframe
|
|
if(window != top && parent.parent.GB_hide) {
|
|
var theForm = Event.findElement(e,"form");
|
|
var submitButton = document.getElementsBySelector("input.action",theForm)[0];
|
|
parent.parent.statusMessage('saving');
|
|
submitButton.setAttribute("disabled","true");
|
|
|
|
showIndicator('ComplexTableField_submitForm', submitButton.parentNode);
|
|
|
|
new parent.parent.Ajax.Request(
|
|
theForm.getAttribute("action"),
|
|
{
|
|
parameters: Form.serialize(theForm)+"&ajax=1",
|
|
onComplete: this.updateTableAfterSave.bind(this)
|
|
}
|
|
);
|
|
Event.stop(e);
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
},
|
|
|
|
updateTableAfterSave : function(response) {
|
|
eval(response.responseText);
|
|
var theForm =document.getElementsByTagName("form")[0];
|
|
|
|
// don't update when validation is present and failed
|
|
if(!this.validate || (this.validate && !hasHadFormError())) {
|
|
new parent.parent.Ajax.Request(
|
|
parent.parent.GB_RefreshLink,
|
|
{
|
|
onComplete: this.updateAndHide.bind(parent.parent),
|
|
onFailure : this.ajaxErrorHandler
|
|
}
|
|
);
|
|
} else {
|
|
var submitbutton = document.getElementsBySelector("input.action",theForm)[0];
|
|
submitbutton.disabled = false;
|
|
hideIndicator('ComplexTableField_submitForm');
|
|
}
|
|
},
|
|
|
|
ajaxErrorHandler: function(response) {
|
|
var submitbutton = document.getElementsBySelector("input.action",theForm)[0];
|
|
submitbutton.disabled = false;
|
|
hideIndicator('ComplexTableField_submitForm');
|
|
|
|
// does not work due to sandbox-iframe restrictions?
|
|
parent.parent.ajaxErrorHandler();
|
|
},
|
|
|
|
updateAndHide: function(response) {
|
|
var theForm =document.getElementsByTagName("form")[0];
|
|
|
|
var submitbutton = document.getElementsBySelector("input.action",theForm)[0];
|
|
submitbutton.disabled = false;
|
|
hideIndicator('ComplexTableField_submitForm');
|
|
|
|
// apparently firefox doesn't remember its DOM after innerHTML, so we help out here...
|
|
var cachedObj = this.GB_OpenerObj;
|
|
var cachedParentObj = this.GB_OpenerObj.parentNode;
|
|
Element.replace(this.GB_OpenerObj, response.responseText);
|
|
this.Behaviour.apply(cachedParentObj);
|
|
cachedObj = null;
|
|
this.GB_OpenerObj = null;
|
|
|
|
// causes IE6 to go nuts
|
|
//this.GB_hide();
|
|
|
|
}
|
|
}
|
|
ComplexTableFieldPopupForm.applyTo('form#ComplexTableField_Popup_DetailForm'); |