2007-07-19 12:40:28 +02:00
|
|
|
ComplexTableFieldPopupForm = Class.create();
|
|
|
|
ComplexTableFieldPopupForm.prototype = {
|
2007-10-17 04:29:42 +02:00
|
|
|
|
|
|
|
errorMessage: "Error talking to server",
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
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];
|
2007-10-17 04:29:42 +02:00
|
|
|
if(parent.parent.statusMessage != undefined) parent.parent.statusMessage('saving');
|
2007-07-19 12:40:28 +02:00
|
|
|
submitButton.setAttribute("disabled","true");
|
|
|
|
|
2007-10-17 04:29:42 +02:00
|
|
|
submitButton._oldValue = submitButton.value;
|
|
|
|
submitButton.value = ingize(submitButton.value);
|
|
|
|
Element.addClassName(submitButton,'loading');
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
new parent.parent.Ajax.Request(
|
|
|
|
theForm.getAttribute("action"),
|
|
|
|
{
|
|
|
|
parameters: Form.serialize(theForm)+"&ajax=1",
|
2007-10-17 04:29:42 +02:00
|
|
|
onComplete: this.updateTableAfterSave.bind(this),
|
|
|
|
onFailure: this.ajaxErrorHandler.bind(this)
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
Event.stop(e);
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
updateTableAfterSave : function(response) {
|
|
|
|
eval(response.responseText);
|
2007-10-17 04:29:42 +02:00
|
|
|
var theForm = document.getElementsByTagName("form")[0];
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
// 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;
|
2007-10-17 04:29:42 +02:00
|
|
|
submitButton.value = submitButton._oldValue;
|
|
|
|
Element.removeClassName(submitButton,'loading');
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
ajaxErrorHandler: function(response) {
|
2007-10-17 04:29:42 +02:00
|
|
|
var submitButton = document.getElementsBySelector("form input.action")[0];
|
|
|
|
submitButton.disabled = false;
|
|
|
|
submitButton.value = submitButton._oldValue;
|
|
|
|
Element.removeClassName(submitButton,'loading');
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2007-10-17 04:29:42 +02:00
|
|
|
// TODO does not work due to sandbox-iframe restrictions?
|
|
|
|
if(typeof(parent.parent.ajaxErrorHandler) == 'function') {
|
|
|
|
parent.parent.ajaxErrorHandler();
|
|
|
|
} else {
|
|
|
|
alert(this.errorMessage);
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
updateAndHide: function(response) {
|
|
|
|
var theForm =document.getElementsByTagName("form")[0];
|
|
|
|
|
2007-10-17 04:29:42 +02:00
|
|
|
var submitButton = document.getElementsBySelector("input.action",theForm)[0];
|
|
|
|
submitButton.disabled = false;
|
|
|
|
submitButton.value = submitButton._oldValue;
|
|
|
|
Element.removeClassName(submitButton,'loading');
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2007-10-17 04:29:42 +02:00
|
|
|
// TODO Fix DOM-relation after pagination inside popup
|
|
|
|
if(this.GB_OpenerObj) {
|
|
|
|
// 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;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
// causes IE6 to go nuts
|
|
|
|
//this.GB_hide();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ComplexTableFieldPopupForm.applyTo('form#ComplexTableField_Popup_DetailForm');
|