From d28faae514b30bd898fee30e524dbd8e3e3b62ae Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 30 Jan 2008 22:57:23 +0000 Subject: [PATCH] updating form in ctf-popup after saving (including validation-errors and fields that have may changed on the serverside, e.g. ImageField) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@48867 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/ComplexTableField.php | 11 +++++--- javascript/ComplexTableField_popup.js | 37 +++++++++++++++------------ 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/forms/ComplexTableField.php b/forms/ComplexTableField.php index 4722de28b..0d429a8c3 100755 --- a/forms/ComplexTableField.php +++ b/forms/ComplexTableField.php @@ -333,7 +333,6 @@ JS; if (is_numeric($childID)) { if ($this->methodName == "show" || $this->methodName == "edit") { - $form->loadDataFrom($childData); } } @@ -767,8 +766,14 @@ class ComplexTableField_Popup extends Form { $this->saveInto($childObject); $childObject->write(); - // if ajax-call in an iframe, close window by javascript, else redirect to referrer - if(!Director::is_ajax()) { + if(Director::is_ajax()) { + // if ajax-call in an iframe, update window + $form = $this->controller->DetailForm(); + $form->loadDataFrom($childObject); + FormResponse::update_dom_id($form->FormName(), $form->formHtmlContent(), true, 'update'); + return FormResponse::respond(); + } else { + // else redirect to referrer Director::redirect(substr($_SERVER['REQUEST_URI'],0,strpos($_SERVER['REQUEST_URI'],"?"))); } } diff --git a/javascript/ComplexTableField_popup.js b/javascript/ComplexTableField_popup.js index c0110e23b..750918899 100755 --- a/javascript/ComplexTableField_popup.js +++ b/javascript/ComplexTableField_popup.js @@ -23,14 +23,13 @@ ComplexTableFieldPopupForm.prototype = { // 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]; if(parent.parent.statusMessage != undefined) parent.parent.statusMessage('saving'); - submitButton.setAttribute("disabled","true"); + var submitButton = document.getElementsBySelector("input.action",theForm)[0]; + if(typeof submitButton != 'undefined') { + submitButton.disabled = true; + Element.addClassName(submitButton,'loading'); + } - submitButton._oldValue = submitButton.value; - submitButton.value = ingize(submitButton.value); - Element.addClassName(submitButton,'loading'); - new parent.parent.Ajax.Request( theForm.getAttribute("action"), { @@ -48,6 +47,7 @@ ComplexTableFieldPopupForm.prototype = { updateTableAfterSave : function(response) { eval(response.responseText); + var theForm = document.getElementsByTagName("form")[0]; // don't update when validation is present and failed @@ -60,18 +60,20 @@ ComplexTableFieldPopupForm.prototype = { } ); } else { - var submitbutton = document.getElementsBySelector("input.action",theForm)[0]; - submitbutton.disabled = false; - submitButton.value = submitButton._oldValue; - Element.removeClassName(submitButton,'loading'); + var submitButton = document.getElementsBySelector("input.action",theForm)[0]; + if(typeof submitButton != 'undefined') { + submitButton.disabled = false; + Element.removeClassName(submitButton,'loading'); + } } }, ajaxErrorHandler: function(response) { - var submitButton = document.getElementsBySelector("form input.action")[0]; - submitButton.disabled = false; - submitButton.value = submitButton._oldValue; - Element.removeClassName(submitButton,'loading'); + var submitButton = document.getElementsBySelector("input.action",theForm)[0]; + if(typeof submitButton != 'undefined') { + submitButton.disabled = false; + Element.removeClassName(submitButton,'loading'); + } // TODO does not work due to sandbox-iframe restrictions? if(typeof(parent.parent.ajaxErrorHandler) == 'function') { @@ -85,9 +87,10 @@ ComplexTableFieldPopupForm.prototype = { var theForm =document.getElementsByTagName("form")[0]; var submitButton = document.getElementsBySelector("input.action",theForm)[0]; - submitButton.disabled = false; - submitButton.value = submitButton._oldValue; - Element.removeClassName(submitButton,'loading'); + if(typeof submitButton != 'undefined') { + submitButton.disabled = false; + Element.removeClassName(submitButton,'loading'); + } // TODO Fix DOM-relation after pagination inside popup if(this.GB_OpenerObj) {