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)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2008-04-26 08:35:27 +02:00
|
|
|
loadNewPage : function(content) {
|
|
|
|
this.innerHTML = content;
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
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");
|
2008-02-25 02:06:39 +01:00
|
|
|
if(parent.parent.statusMessage != undefined) parent.parent.statusMessage('saving');
|
2008-02-25 03:10:37 +01:00
|
|
|
var submitButton = document.getElementsBySelector("input.action",theForm)[0];
|
|
|
|
if(typeof submitButton != 'undefined') {
|
|
|
|
submitButton.disabled = true;
|
|
|
|
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) {
|
2008-04-26 08:35:27 +02:00
|
|
|
try {
|
|
|
|
eval(response.responseText);
|
|
|
|
} catch(er) { alert(er.message); }
|
2008-02-25 03:10:37 +01:00
|
|
|
|
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 {
|
2008-02-25 03:10:37 +01:00
|
|
|
var submitButton = document.getElementsBySelector("input.action",theForm)[0];
|
|
|
|
if(typeof submitButton != 'undefined') {
|
|
|
|
submitButton.disabled = false;
|
|
|
|
Element.removeClassName(submitButton,'loading');
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
ajaxErrorHandler: function(response) {
|
2008-02-25 03:10:37 +01:00
|
|
|
var submitButton = document.getElementsBySelector("input.action",theForm)[0];
|
|
|
|
if(typeof submitButton != 'undefined') {
|
|
|
|
submitButton.disabled = false;
|
|
|
|
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];
|
2008-02-25 03:10:37 +01:00
|
|
|
if(typeof submitButton != 'undefined') {
|
|
|
|
submitButton.disabled = false;
|
|
|
|
Element.removeClassName(submitButton,'loading');
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-04-26 08:51:30 +02:00
|
|
|
onload_init_tabstrip();
|
|
|
|
|
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');
|