mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Merged from trunk
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@72384 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
3222a080a4
commit
dd6ff797e2
@ -546,7 +546,7 @@ class Requirements_Backend {
|
|||||||
function includeInHTML($templateFile, $content) {
|
function includeInHTML($templateFile, $content) {
|
||||||
if(isset($_GET['debug_profile'])) Profiler::mark("Requirements::includeInHTML");
|
if(isset($_GET['debug_profile'])) Profiler::mark("Requirements::includeInHTML");
|
||||||
|
|
||||||
if(strpos($content, '</head') !== false && ($this->javascript || $this->css || $this->customScript || $this->customHeadTags)) {
|
if(strpos($content, '</head') !== false && ($this->css || $this->javascript || $this->customCSS || $this->customScript || $this->customHeadTags)) {
|
||||||
$requirements = '';
|
$requirements = '';
|
||||||
$jsRequirements = '';
|
$jsRequirements = '';
|
||||||
|
|
||||||
|
@ -14,34 +14,64 @@
|
|||||||
* @subpackage validators
|
* @subpackage validators
|
||||||
*/
|
*/
|
||||||
abstract class Validator extends Object {
|
abstract class Validator extends Object {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Form $form
|
||||||
|
*/
|
||||||
protected $form;
|
protected $form;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array $errors
|
||||||
|
*/
|
||||||
protected $errors;
|
protected $errors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static for default value of $this->javascriptValidationHandler.
|
* Static for default value of $this->javascriptValidationHandler.
|
||||||
* Set with Validator::set_javascript_validation_handler();
|
* Set with Validator::set_javascript_validation_handler();
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected static $javascript_validation_handler = null;
|
protected static $javascript_validation_handler = "prototype";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for javascript validation. Can be "prototype" or "none"
|
* Handler for javascript validation. Can be "prototype" or "none".
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $javascriptValidationHandler = "prototype";
|
protected $javascriptValidationHandler = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this function to set the javascript validation handler for all valdiation on your site.
|
* Call this function to set the javascript validation handler for all valdiation on your site.
|
||||||
* This could be called from _config.php to set site-wide javascript validation, or from ContentController::init()
|
* This could be called from _config.php to set site-wide javascript validation, or from ContentController::init()
|
||||||
* to affect only the front-end site.
|
* to affect only the front-end site.
|
||||||
|
* Use instance method {@link setJavascriptValidationHandler()} to
|
||||||
|
* only set handler for a specific form instance.
|
||||||
*
|
*
|
||||||
* @param $handler A string representing the handler to use: 'prototype' or 'none'.
|
* @param $handler A string representing the handler to use: 'prototype' or 'none'.
|
||||||
* @todo Add 'jquery' as a handler option.
|
* @todo Add 'jquery' as a handler option.
|
||||||
*/
|
*/
|
||||||
public function set_javascript_validation_handler($handler = 'prototype') {
|
public static function set_javascript_validation_handler($handler) {
|
||||||
|
if($handler == 'prototype' || $handler == 'none') {
|
||||||
self::$javascript_validation_handler = $handler;
|
self::$javascript_validation_handler = $handler;
|
||||||
|
} else {
|
||||||
|
user_error("Validator::setJavascriptValidationHandler() passed bad handler '$handler'", E_USER_WARNING);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable JavaScript validation for this validator
|
* Returns global validation handler used for all forms by default,
|
||||||
|
* unless overwritten by {@link setJavascriptValidationHandler()}.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_javascript_validator_handler() {
|
||||||
|
return self::$javascript_validation_handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set JavaScript validation for this validator.
|
||||||
|
* Use static method {@link set_javascript_validation_handler()}
|
||||||
|
* to set handlers globally.
|
||||||
|
*
|
||||||
|
* @param string $handler
|
||||||
*/
|
*/
|
||||||
public function setJavascriptValidationHandler($handler) {
|
public function setJavascriptValidationHandler($handler) {
|
||||||
if($handler == 'prototype' || $handler == 'none') {
|
if($handler == 'prototype' || $handler == 'none') {
|
||||||
@ -51,19 +81,26 @@ abstract class Validator extends Object {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct() {
|
/**
|
||||||
if(self::$javascript_validation_handler) $this->setJavascriptValidationHandler(self::$javascript_validation_handler);
|
* Gets the current javascript validation handler for this form.
|
||||||
|
* If not set, falls back to the global static {@link self::$javascript_validation_handler}.
|
||||||
if($this->javascriptValidationHandler && $this->javascriptValidationHandler != 'none') {
|
*
|
||||||
Requirements::javascript(SAPPHIRE_DIR . '/javascript/Validator.js');
|
* @return string
|
||||||
}
|
*/
|
||||||
parent::__construct();
|
public function getJavascriptValidationHandler() {
|
||||||
|
return ($this->javascriptValidationHandler) ? $this->javascriptValidationHandler : self::$javascript_validation_handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Form $form
|
||||||
|
*/
|
||||||
function setForm($form) {
|
function setForm($form) {
|
||||||
$this->form = $form;
|
$this->form = $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array Errors (if any)
|
||||||
|
*/
|
||||||
function validate(){
|
function validate(){
|
||||||
$this->errors = null;
|
$this->errors = null;
|
||||||
$this->php($this->form->getData());
|
$this->php($this->form->getData());
|
||||||
@ -86,8 +123,11 @@ abstract class Validator extends Object {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated 2.4 Use Validator->getCombinedError() and custom code
|
||||||
|
*/
|
||||||
function showError() {
|
function showError() {
|
||||||
debug::show($this->errors);
|
Debug::show($this->errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCombinedError(){
|
function getCombinedError(){
|
||||||
@ -109,10 +149,11 @@ abstract class Validator extends Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function includeJavascriptValidation() {
|
function includeJavascriptValidation() {
|
||||||
if($this->javascriptValidationHandler == 'prototype') {
|
if($this->getJavascriptValidationHandler() == 'prototype') {
|
||||||
Requirements::javascript(THIRDPARTY_DIR . "/prototype.js");
|
Requirements::javascript(THIRDPARTY_DIR . "/prototype.js");
|
||||||
Requirements::javascript(THIRDPARTY_DIR . "/behaviour.js");
|
Requirements::javascript(THIRDPARTY_DIR . "/behaviour.js");
|
||||||
Requirements::javascript(THIRDPARTY_DIR . "/prototype_improvements.js");
|
Requirements::javascript(THIRDPARTY_DIR . "/prototype_improvements.js");
|
||||||
|
//Requirements::add_i18n_javascript(SAPPHIRE_DIR);
|
||||||
Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js");
|
Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js");
|
||||||
Requirements::javascript(SAPPHIRE_DIR . "/javascript/Validator.js");
|
Requirements::javascript(SAPPHIRE_DIR . "/javascript/Validator.js");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user