diff --git a/control/FormResponse.php b/control/FormResponse.php deleted file mode 100644 index 80e80e84a..000000000 --- a/control/FormResponse.php +++ /dev/null @@ -1,273 +0,0 @@ -getResponse(); - $response->addHeader('Content-Type', 'text/javascript'); - return self::get_javascript(); - } elseif(!empty(self::$non_ajax_content)) { - return self::$non_ajax_content; - } elseif(!empty(self::$redirect_url)) { - Director::redirect(self::$redirect_url); - return null; - } elseif(!Director::redirected_to()) { - Director::redirectBack(); - return null; - } else { - return null; - } - - } - - /** - * Caution: Works only for forms which inherit methods from LeftAndMain.js - */ - static function load_form($content, $id = 'Form_EditForm') { - // make sure form-tags are stripped - // loadNewPage() uses innerHTML to replace the form, which makes IE cry when replacing an element with itself - $content = preg_replace(array('/]*>/','/<\/form>/'), '', $content); - $JS_content = Convert::raw2js($content); - self::$rules[] = "\$('{$id}').loadNewPage('{$JS_content}');"; - self::$rules[] = "\$('{$id}').initialize();"; - } - - /** - * Add custom scripts. - * Caution: Not escaped for backwards-compatibility. - * - * @param $scriptContent string - * - * @todo Should this content be escaped? - */ - static function add($scriptContent, $uniquenessID = null) { - if(isset($uniquenessID)) { - self::$rules[$uniquenessID] = $scriptContent; - } else { - self::$rules[] = $scriptContent; - } - } - - static function clear() { - self::$rules = array(); - } - - /** - * @param $id int - */ - static function get_page($id, $form = 'Form_EditForm', $uniquenessID = null) { - $JS_id = (int)$id; - if($JS_id){ - if(isset($uniquenessID)) { - self::$rules[$uniquenessID] = "\$('$form').getPageFromServer($JS_id);"; - } else { - self::$rules[] = "\$('$form').getPageFromServer($JS_id);"; - } - } - } - - /** - * Sets the status-message (overlay-notification in the CMS). - * You can call this method multiple times, it will default to the "worst" statusmessage. - * - * @param $message string - * @param $status string - */ - static function status_message($message = "", $status = null) { - $JS_message = Convert::raw2js($message); - $JS_status = Convert::raw2js($status); - if(isset($JS_status)) { - self::$status_messages[$JS_status] = "statusMessage('{$JS_message}', '{$JS_status}');"; - } else { - self::$status_messages['unknown'] = "statusMessage('{$JS_message}');"; - } - } - - /** - * Alias for status_message($messsage, 'bad') - * - * @param $message string - */ - static function error($message = "") { - $JS_message = Convert::raw2js($message); - self::$status_messages['bad'] = $JS_message; - } - - /** - * Update the status (upper right corner) of the given Form - * - * @param $status string - * @param $form string - */ - static function update_status($status, $form = "Form_EditForm") { - $JS_form = Convert::raw2js($form); - $JS_status = Convert::raw2js($status); - self::$rules[] = "\$('$JS_form').updateStatus('$JS_status');"; - } - - /** - * Set the title of a single page in the pagetree - * - * @param $id int - * @param $title string - */ - static function set_node_title($id, $title = "") { - $JS_id = Convert::raw2js($id); - $JS_title = Convert::raw2js($title); - self::$rules[] = "$('sitetree').setNodeTitle('$JS_id', '$JS_title');"; - } - - /** - * Fallback-method to supply normal HTML-response when not being called by ajax. - * - * @param $content string HTML-content - */ - static function set_non_ajax_content($content) { - self::$non_ajax_content = $content; - } - - /** - * @param $url string - */ - static function set_redirect_url($url) { - self::$redirect_url = $url; - } - - /** - * @return string - */ - static function get_redirect_url() { - return self::$redirect_url; - } - - /** - * Replace a given DOM-element with the given content. - * It automatically prefills {$non_ajax_content} with the passed content (as a fallback). - * - * @param $domID string The DOM-ID of an HTML-element that should be replaced - * @param $domContent string The new HTML-content - * @param $reapplyBehaviour boolean Applies behaviour to the given domID after refreshing it - * @param $replaceMethod string Method for replacing - either 'replace' (=outerHTML) or 'update' (=innerHTML) - * (Caution: "outerHTML" might cause problems on the client-side, e.g. on table-tags) - * - * @todo More fancy replacing with loading-wheel etc. - */ - static function update_dom_id($domID, $domContent, $reapplyBehaviour = true, $replaceMethod = 'replace', $uniquenessID = null) { - //self::$non_ajax_content = $domContent; - $JS_domID = Convert::raw2js($domID); - $JS_domContent = Convert::raw2js($domContent); - $JS_replaceMethod = Convert::raw2js($replaceMethod); - if(isset($uniquenessID)) { - self::$rules[$uniquenessID] = "Element.$JS_replaceMethod('{$JS_domID}','{$JS_domContent}');"; - } else { - self::$rules[] = "Element.$JS_replaceMethod('{$JS_domID}','{$JS_domContent}');"; - } - if($reapplyBehaviour) { - if(isset($uniquenessID)) { - self::$behaviour_apply_rules[$uniquenessID] .= "Behaviour.apply('{$JS_domID}', true);"; - } else { - self::$behaviour_apply_rules[] = "Behaviour.apply('{$JS_domID}', true);"; - } - } - } - - /** - * @return string Compiled string of javascript-function-calls (needs to be evaluated on the client-side!) - */ - protected static function get_javascript() { - $js = ""; - - // select only one status message (with priority on "bad" messages) - $msg = ""; - foreach(self::$status_include_order as $status) { - if(isset(self::$status_messages[$status])) { - $msg = self::$status_messages[$status]; - break; - } - } - if(!empty($msg)) self::$rules[] = $msg; - - - $js .= implode("\n", self::$rules); - $js .= Requirements::get_custom_scripts(); - - // make sure behaviour is applied AFTER all registers are collected - $js .= implode("\n", self::$behaviour_apply_rules); - - return $js; - } -} - diff --git a/forms/ComplexTableField.php b/forms/ComplexTableField.php index 20d82b7b8..2e0d657b0 100644 --- a/forms/ComplexTableField.php +++ b/forms/ComplexTableField.php @@ -228,7 +228,7 @@ class ComplexTableField extends TableListField { $js = <<value = null; $items = $this->sourceItems(); - FormResponse::update_dom_id($this->id(), $this->FieldHolder()); + // FormResponse::update_dom_id($this->id(), $this->FieldHolder()); } } diff --git a/forms/Validator.php b/forms/Validator.php index 9c5a2e26a..6823526c7 100644 --- a/forms/Validator.php +++ b/forms/Validator.php @@ -7,9 +7,6 @@ * * Acts as a visitor to individual form fields. * - * @todo Automatically mark fields after serverside validation and replace the form through - * FormResponse if the request was made by ajax. - * * @package forms * @subpackage validators */