diff options
author | xue <> | 2006-04-25 01:27:04 +0000 |
---|---|---|
committer | xue <> | 2006-04-25 01:27:04 +0000 |
commit | 1afc913c386bba8e6072c278b0eb4fd9818ab310 (patch) | |
tree | 40cc63eb41f47e0ac392c692619640dca57cd262 | |
parent | fd019bf034ef4dbedfc305c77fed0dbd83a732c4 (diff) |
Undo previous checkin (which goes int 3.0 branch and will be merged back).
34 files changed, 325 insertions, 1852 deletions
diff --git a/.gitattributes b/.gitattributes index de232c2e..09a257fd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,7 +4,6 @@ /UPGRADE -text /build.xml -text buildscripts/.htaccess -text -buildscripts/jsbuilder/JavaScript[!!-~]Documentation[!!-~]Tool.html -text buildscripts/jsbuilder/build.php -text buildscripts/phing/style/coverage-frames.xsl -text buildscripts/phing/style/log.xsl -text @@ -978,7 +977,6 @@ framework/Web/UI/WebControls/TLabel.php -text framework/Web/UI/WebControls/TLinkButton.php -text framework/Web/UI/WebControls/TListBox.php -text framework/Web/UI/WebControls/TListControl.php -text -framework/Web/UI/WebControls/TListControlValidator.php -text framework/Web/UI/WebControls/TLiteral.php -text framework/Web/UI/WebControls/TMultiView.php -text framework/Web/UI/WebControls/TOutputCache.php -text @@ -1162,14 +1160,12 @@ tests/FunctionalTests/validators/protected/pages/CheckBox.php -text tests/FunctionalTests/validators/protected/pages/CompareValidator.page -text tests/FunctionalTests/validators/protected/pages/CustomValidator.page -text tests/FunctionalTests/validators/protected/pages/CustomValidator.php -text -tests/FunctionalTests/validators/protected/pages/DatePicker.page -text tests/FunctionalTests/validators/protected/pages/ImageButton.page -text tests/FunctionalTests/validators/protected/pages/ImageButton.php -text tests/FunctionalTests/validators/protected/pages/Layout.php -text tests/FunctionalTests/validators/protected/pages/Layout.tpl -text tests/FunctionalTests/validators/protected/pages/LinkButton.page -text tests/FunctionalTests/validators/protected/pages/LinkButton.php -text -tests/FunctionalTests/validators/protected/pages/ListControl.page -text tests/FunctionalTests/validators/protected/pages/RangeValidatorDate.page -text tests/FunctionalTests/validators/protected/pages/RangeValidatorFloat.page -text tests/FunctionalTests/validators/protected/pages/RangeValidatorInteger.page -text @@ -1183,10 +1179,8 @@ tests/FunctionalTests/validators/tests/ButtonTestCase.php -text tests/FunctionalTests/validators/tests/CheckBoxTestCase.php -text tests/FunctionalTests/validators/tests/CompareValidatorTestCase.php -text tests/FunctionalTests/validators/tests/CustomValidatorTestCase.php -text -tests/FunctionalTests/validators/tests/DatePickerTestCase.php -text tests/FunctionalTests/validators/tests/ImageButtonTestCase.php -text tests/FunctionalTests/validators/tests/LinkButtonTestCase.php -text -tests/FunctionalTests/validators/tests/ListControlTestCase.php -text tests/FunctionalTests/validators/tests/RangeValidatorTestCase.php -text tests/FunctionalTests/validators/tests/RegExpValidatorTestCase.php -text tests/FunctionalTests/validators/tests/RequiredFieldTestCase.php -text diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 2b2c3957..00000000 --- a/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -buildscripts/jsbuilder/JSDoc -tests/FunctionalTests/features/assets/589569dd -tests/FunctionalTests/features/assets/8fb9443f -tests/FunctionalTests/features/assets/a4d5cb67 -tests/FunctionalTests/features/assets/d7c2e63b -tests/FunctionalTests/features/assets/fcff0f02 -tests/FunctionalTests/features/protected/runtime/application.xml -tests/FunctionalTests/results.dat -tests/FunctionalTests/validators/assets/8fb9443f -tests/FunctionalTests/validators/assets/a4d5cb67 -tests/FunctionalTests/validators/protected/runtime/global.cache diff --git a/buildscripts/jsbuilder/JavaScript Documentation Tool.html b/buildscripts/jsbuilder/JavaScript Documentation Tool.html deleted file mode 100644 index 5a61fd5a..00000000 --- a/buildscripts/jsbuilder/JavaScript Documentation Tool.html +++ /dev/null @@ -1,496 +0,0 @@ -<html> - <head> - <title>JSDoc Homepage - JavaScript Documentation Tool</title> - <link rel="stylesheet" type="text/css" href="stylesheet.css"/> - <style> - .comment { - color: #000066; - } - - .comment_emph { - color: #FF0000 - } - </style> - </head> - <body> - <a name="top"> - <h1 - class="TableHeadingColor" - style="padding: 8px; border: solid black 1px">JSDoc <i class="subh1">- JavaScript Documentation Tool</i></h1></a> - <table> - <tr> - <td> - <ul> - <li><a href="#intro">Introduction</a></li> - <li><a href="#install">Installation</a></li> - <li><a href="#usage">Usage</a></li> - <li><a href="#tagref">Tag Reference</a></li> - <li><a href="#faq">Frequently Asked Questions</a></li> - <li><a href="#moreinfo">More Information</a></li> - </ul> - </td> - </tr> - </table> - <table> - <tr> - <td class="TableSubHeadingColor"><h3><a name="intro">Introduction</a></h3></td> - </tr> - <tr> - <td class="TableRowColor"> - <p> - <a href="http://sourceforge.net/projects/jsdoc">JSDoc</a> is a tool that parses inline documentation in JavaScript source files, and produces an documentation of the JavaScript code. This is typically in the form of HTML (<a href="example/index.html">example</a>), but XML and XMI (UML) export are also supported. JSDoc is based on the (very successful) <code>javadoc</code> tool that was created for the same purpose for the Java programming language. - </p> - - <p> - JSDoc is primarily intended for libraries of object-oriented JavaScript files, although it also works with procedural code. There is a basic ability to determine inheritance built into the parser, although some more obscure dynamic constructs will not be understood (for example, defining a method to set one class as the superclass of another). - </p> - - <p> - Anyone familiar with the <code>javadoc</code> tool will be able to use JSDoc right away; for anyone else it is a very simple matter to get started. JSDoc picks up on comments that are opened with a slash followed by two stars (<code>/**</code>), and closed with the typical star-slash (<code>*/</code>). - </p> - <div class="toplink"><a href="#top">Top</a></div> - </td> - </tr> - </table> - - - <table> - <tr> - <td class="TableSubHeadingColor"><h3><a name="install">Installation</a></h3></td> - </tr> - <tr> - <td class="TableRowColor"> - JSDoc is implemented in Perl, as as such, requires the perl executable. This shouldn't be a problem for Linux/Unix users, but Windows users will probably have to install a perl runtime; <a href="http://www.activeperl.com">ActivePerl</a> is recommended. - <p>JSDoc is distributed as a gzipped tarball, and can be downloaded from the <a href="http://sourceforge.net/projects/jsdoc">JSDoc project page</a>. Once you have downloaded JSDoc-x-x.tgz, just unpack it (tar zxf JSDoc-x-x.tgz on Linux/Unix, use WinZip on Windows), and you're ready to go. You can immediately try out JSDoc on the included test.js JavaScript file by going into the JSDoc directory and entering the command - <pre> - perl jsdoc.pl test.js - </pre> - This should output a set of HTML files in a directory called js_docs_out. - - <p> - If you get an error message right away that looks something like - <pre> - Can't locate HTML/Template.pm in @INC ...... - </pre> - then you will need to install the HTML::Template Perl module. Luckily, this is a very trivial operation thanks to the <a href="http://www.cpan.org">CPAN</a>. In a Linux/Unix/POSIX-style operating system, open a terminal and run the following command as root: - <pre> - # perl -MCPAN -e 'install HTML::Template' - </pre> - <p> - If you're running Windows and ActivePerl, open a command prompt window and enter the following command: - <pre> - C:\> ppm - </pre> - This will start the Perl Package Manager; at the PPM prompt, enter the following two commands (PPM> is the PPM prompt): - <pre> - PPM> install HTML-Template - PPM> quit - </pre> - <p> - JSDoc <i>should</i> run without problems now. - - <div class="toplink"><a href="#top">Top</a></div> - </td> - </tr> - </table> - - - <table> - <tr> - <td class="TableSubHeadingColor"><h3><a name="usage">Usage</a></h3></td> - </tr> - <tr> - <td class="TableRowColor"> - <p> - The general idea of JSDoc is to pick up the form and documentation of code. A major part of JSDoc's functionality is based around documentation strings embedded in JavaScript code. The definitive reference to writing documentation strings for Java (with a large amount of carry-over to JSDoc) can be found at the <a href="http://java.sun.com/j2se/javadoc/writingdoccomments/">javadoc reference page</a>. - <p/> - - <p> - JSDoc currently supports a subset of javadoc's '@'-prefixed attributes, but the parser is customizable (as explained later). An example JavaScript file (test.js) is included with the JSDoc distribution. Most functionality of JSDoc can be seen within this script file, however for the impatient a small (and incomplete) example of a common usage of JSDoc is shown below - </p> - - <p> - <pre> - <span class="comment"> - /** - * Shape is an abstract base class. It is defined simply - * to have something to inherit from for geometric - * subclasses - * @constructor - */</span> - function Shape(color){ - this.color = color; - } - - // Bind the Shape_getColor method to the Shape class - Shape.prototype.getColor = Shape_getColor; - <span class="comment"> - /** - * Get the name of the color for this shape - * @returns A color string for this shape - */</span> - function Shape_getColor(){ - return this.color; - } - <span class="comment"> - /** - * Circle is a subclass of Shape - */</span> - function Circle(radius){ - this.radius = radius; - } - <span class="comment"> - /** - * A very rough value for pi - */</span> - Circle.PI = 3.14; - <span class="comment"> - /** - * Get the radius of this circle - * @returns The radius of this circle - */</span> - function Circle_getRadius(){ - return this.radius; - } - - // Circle is a subclass of Shape - Circle.prototype = new Shape(null); - </pre> - </p> - - <p> - One important difference between javadoc and JSDoc is that JSDoc deals with a much more dynamic language that javadoc. For example, in JavaScript there are many different ways to make one class a subclass of another. The JSDoc parser is able to catch some of these methods, but for particularly dynamic scripts the parser will not be able to do it all on its own. For that reason, JSDoc is customizable with a file called .jsdoc_config that resides in the JSDoc install directory. In this configuration file, JSDoc's behaviour can be customized for any kind of '@'-prefixed attribute. Although this configuration file actually contains Perl code, simple customizations can be done by someone with minimal experience with Perl. - </p> - <!--p> - The '@' attributes that are currently recognized by JSDoc are the following (behaviour is generally the same as javadoc): - <ul> - <li><code>@param</code></li> - <li><code>@argument</code> <i>(synonym for @param)</i></li> - <li><code>@return</code></li> - <li><code>@returns</code> <i>(synonym for @return)</i></li> - <li><code>@author</code></li> - <li><code>@deprecated</code></li> - <li><code>@see</code></li> - <li><code>@version</code></li> - <li><code>@requires</code></li> - <li><code>@throws</code></li> - <li><code>@exception</code> <i>(synonym for @throws)</i></li> - <li><code>@link</code></li> - </ul--> - - JSDoc also uses a several non-javadoc '@'-attributes: <code>@constructor</code> and <code>@private</code> are two of the most important ones. As noted above, JavaScript has the capability to be a much more dynamic language than Java. The JSDoc parser can usually find class constructors on it's own, but there are some situations when it needs some additional assistance. For this reason, it is a good practice to always include the <code>@constructor</code> tag in the documentation for a class constructor, as shown below: - <pre> - <span class="comment"> - /** - * Nothing is a class that represents nothing - * <span class="comment_emph">@constructor</span> - */</span> - function Nothing(){ - // ... initialization ... - } - </pre> - - The <code>@private</code> attribute simply displays the marked method as being private. - </p> - <p> - To get more information on the use of the jsdoc.pl executable itself, run it with the <code>--help</code> commandline option. - </p> - <div class="toplink"><a href="#top">Top</a></div> - </td> - </tr> - </table> - - <table> - <tr> - <td class="TableSubHeadingColor"><h3><a name="tagref">Tag Reference</a></h3></td> - </tr> - <tr> - <td class="TableRowColor"> - The following is a summary of the supported tags ('@'-attributes) that are supported by JSDoc. For actual examples of the usage of these tags, please see the test.js JavaScript file that is included in the JSDoc distribution. - <table class="tagtable"> - <tr> - <td><code>@param</code></td> - <td> - Provide information about a function parameter. A datatype indicator can be added between curly braces with this tag, as follows: - <pre> - /** - * @param {String} paramName This is a string parameter - */ - </pre> - </td> - </tr> - - <tr> - <td><code>@argument</code></td> - <td>Synonym for <code>@param</code> - </td> - </tr> - - <tr> - <td><code>@return</code></td> - <td>Provide information about the return value of a function. - </td> - </tr> - - <tr> - <td><code>@returns</code></td> - <td>Synonym for <code>@return</code> - </td> - </tr> - - <tr> - <td><code>@author</code></td> - <td>Provide information about the author of a JavaScript file or a function. - </td> - </tr> - - <tr> - <td><code>@deprecated</code></td> - <td> - Signify that a function or class is deprecated, and should not be used if possible. - </td> - </tr> - - <tr> - <td><code>@see</code></td> - <td> - Link to another class or function that is of importance to the current class or function. This tag can take several forms. - <p> - To link to another method within the same class: - <pre> - @see #methodName - </pre> - <p> - To link to another class: - <pre> - @see ClassName - </pre> - <p> - To link to a specific method of another class: - <pre> - @see ClassName#methodName - </pre> - </td> - </tr> - - <tr> - <td><code>@version</code></td> - <td>Show the version number of the current file or class - </td> - </tr> - - <tr> - <td><code>@requires</code></td> - <td>Define a dependency upon another class. The syntax for this tag is as follows: - <pre> - @requires OtherClassName This is text to be shown - </pre> - </td> - </tr> - - <tr> - <td><code>@throws</code></td> - <td> - Show that a method can throw a certain type of exception. The syntax for this tag is: - <pre> - @throws ExceptionType This is the label text - </pre> - </td> - </tr> - - <tr> - <td><code>@exception</code></td> - <td>Synonym for <code>@throws</code> - </td> - </tr> - - <tr> - <td><code>@link</code></td> - <td>This is a powerful tag that can be used to link to a large number of other pages. It is also the only tag that can be used in the description text of a documentation string before the '@'-tag section. The usage is very similar to that of the <code>@see</code> tag, but the entire tag is wrapped in curly braces. For example: - <pre> - /** - * This utility method is also a member of the {@link String} class, - * in the form of the {@link String#utility} method. - */ - </pre> - </td> - </tr> - - <tr> - <td><code>@fileoverview</code></td> - <td>This is a special-use tag. If the first block of documentation in a file starts with a <code>@fileoverview</code> tag, the rest of the documentation block will be used to provide a file overview in the documentation. - </td> - </tr> - - <tr> - <td><code>@class</code></td> - <td>This tag is used in a constructor's documentation block to provide information about the actual class. The included documentation will then not be included in the constructor's documentation. - </td> - </tr> - - <tr> - <td><code>@constructor</code></td> - <td>Signify that a function is the constructor for a class. - </td> - </tr> - - <tr> - <td><code>@type</code></td> - <td>Show the return type of a function. For example: - <pre> - /** - * This function returns a String. - * @return The name of the current user - * @type String - */ - </pre> - </td> - </tr> - - <tr> - <td><code>@extends</code></td> - <td>Used to show that a class is a subclass of another class. JSDoc is often quite good at picking this up on its own, but in some situations this tag is required. - </td> - </tr> - - <tr> - <td><code>@private</code></td> - <td> - Signify that a function or class is private. Private classes and functions will not be available in the documentation unless JSDoc is run with the <code>--private</code> commandline option. - </td> - </tr> - - <tr> - <td><code>@final</code></td> - <td> - Flag a value as being a final (constant) value. - </td> - </tr> - - <tr> - <td><code>@member</code></td> - <td> - Show that a function is a member of a given class: - <pre> - /** - * @member MyClass - */ - function SomeFunc(){ - } - </pre> - </td> - </tr> - - <tr> - <td><code>@ignore</code></td> - <td> - Tell JSDoc to totally ignore this method. - </td> - </tr> - <tr> - <td><code>@base</code></td> - <td> - Force JSDoc to view the current class constructor - as a subclass of the class given as the value to - this tag: - <pre> - /** - * This is a subclass of Shape - * @constructor - * @base Shape - */ - function Circle(){ - // ... - } - </pre> - </td> - </tr> - - <tr> - <td><code>@addon</code></td> - <td> - Mark a function as being an "addon" to a core - JavaScript function that isn't defined within - your own sources, as shown below: - <pre> - /** - * This is an addon function to SomeCoreClass which is - * not defined within our own sources. - * @addon - */ - SomeCoreClass.someFunction = function(){ - // ... - } </pre> - </td> - </tr> - - <tr> - <td><code>@exec</code></td> - <td><b><i>Experimental!</i></b><br/> - Force JSDoc to "execute" this method as part of its - preprocessing step, in the same way that class - contructors are executed. This can allow attributes - to be added to a class from within a function. - </td> - </tr> - - </table> - <div class="toplink"><a href="#top">Top</a></div> - </td> - </tr> - </table> - - - <table> - <tr> - <td class="TableSubHeadingColor"><h3><a name="faq">Frequently Asked Questions</a></h3></td> - </tr> - <tr> - <td class="TableRowColor"> - <ul> - <li><b>I get an error message that says <i>Can't locate HTML/Template.pm in @INC ......</i>. What's going on?</b> - <p>This means that you don't have the HTML::Template perl module installed. Luckily, it's very easy to remedy this problem; see the Installation section of this page.</li> - - <li><b>I've found a bug in JSDoc. What should I do?</b> - <p>Go to the <a href="http://sourceforge.net/projects/jsdoc">JSDoc Project Page</a> and register a bug report. You can also send information about the bug to the <a href="http://sourceforge.net/mail/?group_id=30801">JSDoc-user mailing list</a>. But just before you do that, please make sure that it's actually a bug that we're talking about, and not just JSDoc acting differently that what you were expecting.</li> - - <li><b>JSDoc segfaults! What should I do?</b> - <p>This is a tough one to answer. JSDoc uses a lot of recursive regular expressions, and sometimes a certain combination of a certain build of perl and a certain JavaScript file will cause perl to segfault while running JSDoc. This problem mostly occurs with binary installations of perl; downloading the most recent source distribution of perl and building it on your own machine seems to solve this problem. </p> - <p>Another action that can sometimes help in this situation (and doesn't require a new install of perl) is by changing the recursion limit for recursive regexes. You can do this by altering the value given to the constant <code>RECURSION</code> in JSDoc.pm (at line 124 at the time of writing). Changing the value from 10 to a lower value, such as 6, can sometimes take care of this issue. The main risk in taking this action is that some deeply-nested constructs in your JavaScript code might not be processed by JSDoc.</p></li> - - <li><b>I want JSDoc to do <i>X</i>, but it doesn't!</b> - <p>Well, that's actually not a question, it's more of a statement. However, it is stated quite frequently, so it's not totally out of place here. If you're interested in having a new feature added to JSDoc, you can register a Feature Request at the <a href="http://sourceforge.net/projects/jsdoc">JSDoc Project Page</a>. You may also want to consider sending information about your request to the <a href="http://sourceforge.net/mail/?group_id=30801">JSDoc-user mailing list</a>.</li> - - <li><b>Is there a mailing list for JSDoc?</b> - <p>Okay, I admit that this isn't actually a Frequently Asked Question; it's actually just an attempt to promote the <a href="http://sourceforge.net/mail/?group_id=30801">JSDoc-user mailing list</a>.</li> - - <li><b>I want to help out with JSDoc. Where should I start?</b> - <p>First of all, help is very welcome! The most welcome kinds of help are context diffs that fix a bug in JSDoc, but pretty much anything that's an attempt at helping out is appreciated. Use the <a href="http://sourceforge.net/mail/?group_id=30801">JSDoc-user mailing list</a>.</li> - - - </ul> - <div class="toplink"><a href="#top">Top</a></div> - </td> - </tr> - </table> - - <table> - <tr> - <td class="TableSubHeadingColor"><h3><a name="moreinfo">More Information</a></h3></td> - </tr> - <tr> - <td class="TableRowColor"> - <p> - A very complete and informative article (written by Rainer Eschen) on the use of JSDoc can be found at <a href="http://www.webetiser.de/jsdoc">Webetiser</a>. The article is based on JSDoc 1.5, but is still very relevant. I've been told that the article will be updated in the near future. - - <p> - As noted above, the definitive reference for writing Java docstrings can be found at the <a href="http://java.sun.com/j2se/javadoc/writingdoccomments/">javadoc reference page</a>. Please send comments, bugs, complaints, requests for additional information, and whatever else to the <a href="http://sourceforge.net/mail/?group_id=30801">JSDoc mailing list</a>. - </p> - <div class="toplink"><a href="#top">Top</a></div> - </td> - </tr> - </table> - - <a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=30801&type=7" width="210" height="62" border="0" alt="SourceForge.net Logo" /></a> - </body> -</html> diff --git a/buildscripts/jsbuilder/build.php b/buildscripts/jsbuilder/build.php index 910f0394..d5d04713 100644 --- a/buildscripts/jsbuilder/build.php +++ b/buildscripts/jsbuilder/build.php @@ -27,18 +27,6 @@ define('SOURCE_DIR',realpath(dirname(__FILE__).'/../../framework/Web/JavaScripts * The directory for storing compressed js files
*/
define('TARGET_DIR',realpath(dirname(__FILE__).'/../../framework/Web/JavaScripts/js'));
-/**
- * Location of the perl JS doc generator.
- */
-define('JS_DOC', realpath(dirname(__FILE__).'/JSDoc/jsdoc.pl'));
-/**
- * Javascript documentation output directory.
- */
-define('DOC_OUTPUT_DIR', realpath(dirname(__FILE__).'/../../docs/Javascript'));
-/**
- * Javascript documentation build command
- */
-define('BUILD_DOC', sprintf('perl "%s" --no-sources -d "%s" ', JS_DOC, DOC_OUTPUT_DIR).'%s');
if(SOURCE_DIR===false || TARGET_DIR===false)
die('Unable to determine the build path.');
@@ -166,18 +154,7 @@ foreach($libraries as $libFile => $sourceFiles) echo "Saving file {$libFile}\n";
$builds++;
}
-if(preg_match('/doc*/', $argv[1]))
-{
- $files = "";
- foreach($libraries as $lib)
- {
- foreach($lib as $source)
- $files .= sprintf(' "%s/%s"', SOURCE_DIR, $source);
- }
- $command = sprintf(BUILD_DOC, $files);
- system($command);
-}
-else if($builds > 0)
+if($builds > 0)
echo "\nJavascript build complete, {$builds} file(s) compressed.";
else
echo "No files to build.";
diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt index 20bafba2..cde4eae1 100644 --- a/framework/Exceptions/messages.txt +++ b/framework/Exceptions/messages.txt @@ -231,8 +231,6 @@ basevalidator_forcontrol_unsupported = {0}.ForControl is not supported. comparevalidator_controltocompare_invalid = TCompareValidator.ControlToCompare contains an invalid control ID path.
-tlistcontrolvalidator_invalid_control = {0}.ControlToValidate contains an invalid TListControl ID path, "{1}" is a {2}.
-
repeater_template_required = TRepeater.{0} requires a template instance implementing ITemplate interface.
datalist_template_required = TDataList.{0} requires a template instance implementing ITemplate interface.
templatecolumn_template_required = TTemplateColumn.{0} requires a template instance implementing ITemplate interface.
diff --git a/framework/Util/TSimpleDateFormatter.php b/framework/Util/TSimpleDateFormatter.php index 2a3da63a..052e0074 100644 --- a/framework/Util/TSimpleDateFormatter.php +++ b/framework/Util/TSimpleDateFormatter.php @@ -190,20 +190,18 @@ class TSimpleDateFormatter /**
* Parse the string according to the pattern.
- * @param string|int date string or integer to parse
+ * @param string date string to parse
* @return int date time stamp
* @throws TInvalidDataValueException if date string is malformed.
*/
public function parse($value,$defaultToCurrentTime=true)
{
- if(is_int($value))
- return $value;
- else if(!is_string($value))
+ if(!is_string($value))
throw new TInvalidDataValueException('date_to_parse_must_be_string', $value);
if(empty($this->pattern)) return time();
- $date = time();
+ $date = $this->getDate(time());
if($this->length(trim($value)) < 1)
return $defaultToCurrentTime ? $date : null;
diff --git a/framework/Web/Javascripts/colorpicker/colorpicker.js b/framework/Web/Javascripts/colorpicker/colorpicker.js index dc80f0c7..cc4587ff 100644 --- a/framework/Web/Javascripts/colorpicker/colorpicker.js +++ b/framework/Web/Javascripts/colorpicker/colorpicker.js @@ -83,7 +83,7 @@ Object.extend(Prado.WebUI.TColorPicker.prototype, if(mode == "Full")
this.initializeFullPicker();
}
- this.show(mode);
+ this.show();
},
show : function(type)
@@ -108,7 +108,6 @@ Object.extend(Prado.WebUI.TColorPicker.prototype, if(type == "Full")
{
- this.observeMouseMovement();
var color = Rico.Color.createFromHex(this.input.value);
this.inputs.oldColor.style.backgroundColor = color.asHex();
this.setColor(color,true);
@@ -125,14 +124,8 @@ Object.extend(Prado.WebUI.TColorPicker.prototype, this.element.style.display = "none";
this.showing = false;
- Event.stopObserving(document.body, "click", this._documentClickEvent);
+ Event.stopObserving(document.body, "click", this._documentClickEvent);
Event.stopObserving(document,"keydown", this._documentKeyDownEvent);
-
- if(this._observingMouseMove)
- {
- Event.stopObserving(document.body, "mousemove", this._onMouseMove);
- this._observingMouseMove = false;
- }
}
},
@@ -215,7 +208,7 @@ Object.extend(Prado.WebUI.TColorPicker.prototype, {
this.input.value = color.toString().toUpperCase();
this.button.style.backgroundColor = color.toString();
- if(typeof(this.onChange) == "function")
+ if(isFunction(this.onChange))
this.onChange(color);
},
@@ -253,7 +246,7 @@ Object.extend(Prado.WebUI.TColorPicker.prototype, TR(null,
TD(null,'H:'),
- TD(null,this.inputs['H'], '??')),
+ TD(null,this.inputs['H'], '°')),
TR(null,
TD(null,'S:'),
@@ -340,46 +333,34 @@ Object.extend(Prado.WebUI.TColorPicker.prototype, this._onMouseMove = this.onMouseMove.bind(this);
Event.observe(this.inputs.background, "mousedown", this._onColorMouseDown);
- Event.observe(this.inputs.selector, "mousedown", this._onColorMouseDown);
Event.observe(this.inputs.hue, "mousedown", this._onHueMouseDown);
- Event.observe(this.inputs.slider, "mousedown", this._onHueMouseDown);
Event.observe(document.body, "mouseup", this._onMouseUp);
-
- this.observeMouseMovement();
+
+ //Because of using the CSS filter, IE can't do colour change quickly
+ //if(!Prado.Browser().ie)
+ Event.observe(document.body, "mousemove", this._onMouseMove);
Event.observe(this.buttons.Cancel, "click", this.hide.bindEvent(this,this.options['Mode']));
Event.observe(this.buttons.OK, "click", this.onOKClicked.bind(this));
},
- observeMouseMovement : function()
- {
- if(!this._observingMouseMove)
- {
- Event.observe(document.body, "mousemove", this._onMouseMove);
- this._observingMouseMove = true;
- }
- },
-
onColorMouseDown : function(ev)
{
this.isMouseDownOnColor = true;
this.onMouseMove(ev);
- Event.stop(ev);
},
onHueMouseDown : function(ev)
{
this.isMouseDownOnHue = true;
this.onMouseMove(ev);
- Event.stop(ev);
},
onMouseUp : function(ev)
{
this.isMouseDownOnColor = false;
this.isMouseDownOnHue = false;
- Event.stop(ev);
},
onMouseMove : function(ev)
@@ -388,7 +369,6 @@ Object.extend(Prado.WebUI.TColorPicker.prototype, this.changeSV(ev);
if(this.isMouseDownOnHue)
this.changeH(ev);
- Event.stop(ev);
},
changeSV : function(ev)
@@ -396,25 +376,18 @@ Object.extend(Prado.WebUI.TColorPicker.prototype, var px = Event.pointerX(ev);
var py = Event.pointerY(ev);
var pos = Position.cumulativeOffset(this.inputs.background);
-
var x = this.truncate(px - pos[0],0,255);
var y = this.truncate(py - pos[1],0,255);
+ var h = this.truncate(this.inputs.H.value,0,360)/360;
var s = x/255;
var b = (255-y)/255;
- var current_s = parseInt(this.inputs.S.value);
- var current_b = parseInt(this.inputs.V.value);
-
- if(current_s == parseInt(s*100) && current_b == parseInt(b*100)) return;
-
- var h = this.truncate(this.inputs.H.value,0,360)/360;
var color = new Rico.Color();
color.rgb = Rico.Color.HSBtoRGB(h,s,b);
-
this.inputs.selector.style.left = x+"px";
this.inputs.selector.style.top = y+"px";
@@ -430,10 +403,6 @@ Object.extend(Prado.WebUI.TColorPicker.prototype, var y = this.truncate(py - pos[1],0,255);
var h = (255-y)/255;
- var current_h = this.truncate(this.inputs.H.value,0,360);
- current_h = current_h == 0 ? 360 : current_h;
- if(current_h == parseInt(h*360)) return;
-
var s = parseInt(this.inputs.S.value)/100;
var b = parseInt(this.inputs.V.value)/100;
var color = new Rico.Color();
@@ -503,8 +472,14 @@ Object.extend(Prado.WebUI.TColorPicker.prototype, var images = Prado.WebUI.TColorPicker.UIImages;
var changeCss = color.isBright() ? 'removeClassName' : 'addClassName';
- Element[changeCss](this.inputs.selector, 'target_white');
-
+ Element[changeCss](this.inputs.selector, 'target_white');
+/* if(color.isBright())
+ Element.removeCssClass(this.inputs.selector, 'target_white');
+ //this.inputs.selector.src = images['target_black.gif'];
+ else
+ Element.addCssClass(this.inputs.selector, 'target_white');
+ //this.inputs.selector.src = images['target_white.gif'];
+*/
if(update)
this.updateSelectors(color);
},
diff --git a/framework/Web/Javascripts/datepicker/datepicker.js b/framework/Web/Javascripts/datepicker/datepicker.js index 79763811..e906120c 100644 --- a/framework/Web/Javascripts/datepicker/datepicker.js +++ b/framework/Web/Javascripts/datepicker/datepicker.js @@ -1,51 +1,10 @@ Prado.WebUI.TDatePicker = Class.create();
-Object.extend(Prado.WebUI.TDatePicker,
-{
- /**
- * @return Date the date from drop down list options.
- */
- getDropDownDate : function(control)
- {
- var now=new Date();
- var year=now.getFullYear();
- var month=now.getMonth();
- var day=1;
-
- var month_list = this.getMonthListControl(control);
- var day_list = this.getDayListControl(control);
- var year_list = this.getYearListControl(control);
-
- var day = day_list ? $F(day_list) : 1;
- var month = month_list ? $F(month_list) : now.getMonth();
- var year = year_list ? $F(year_list) : now.getFullYear();
-
- return new Date(year,month,day, 0, 0, 0);
- },
-
- getYearListControl : function(control)
- {
- return $(control.id+"_year");
- },
-
- getMonthListControl : function(control)
- {
- return $(control.id+"_month");
- },
-
- getDayListControl : function(control)
- {
- return $(control.id+"_day");
- }
-});
-
Prado.WebUI.TDatePicker.prototype =
{
MonthNames : [ "January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
],
- AbbreviatedMonthNames : ["Jan", "Feb", "Mar", "Apr", "May",
- "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
ShortWeekDayNames : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
@@ -229,7 +188,7 @@ Prado.WebUI.TDatePicker.prototype = var todayButton = document.createElement("button");
todayButton.className = "todayButton";
var today = this.newDate();
- var buttonText = today.SimpleFormat(this.Format,this);
+ var buttonText = today.SimpleFormat(this.Format);
todayButton.appendChild(document.createTextNode(buttonText));
div.appendChild(todayButton);
@@ -427,27 +386,20 @@ Prado.WebUI.TDatePicker.prototype = return false;
},
- onChange : function()
+ onchange : function()
{
if(this.options.InputMode == "TextBox")
- {
this.control.value = this.formatDate();
- Event.fireEvent(this.control, "change");
- }
else
{
- var day = Prado.WebUI.TDatePicker.getDayListControl(this.control);
- var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
- var year = Prado.WebUI.TDatePicker.getYearListControl(this.control);
+ var day = $(this.options.ID+"_day");
+ var month = $(this.options.ID+"_month");
+ var year = $(this.options.ID+"_year");
var date = this.selectedDate;
if(day)
- {
day.selectedIndex = date.getDate()-1;
- }
if(month)
- {
month.selectedIndex = date.getMonth();
- }
if(year)
{
var years = year.options;
@@ -455,20 +407,19 @@ Prado.WebUI.TDatePicker.prototype = for(var i = 0; i < years.length; i++)
years[i].selected = years[i].value.toInteger() == currentYear;
}
- Event.fireEvent(day || month || year, "change");
}
},
formatDate : function()
{
- return this.selectedDate ? this.selectedDate.SimpleFormat(this.Format,this) : '';
+ return this.selectedDate ? this.selectedDate.SimpleFormat(this.Format) : '';
},
newDate : function(date)
{
if(!date)
date = new Date();
- if(typeof(date) == "string" || typeof(date) == "number")
+ if(isString(date) || isNumber(date))
date = new Date(date);
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0,0,0);
},
@@ -481,8 +432,8 @@ Prado.WebUI.TDatePicker.prototype = this.updateHeader();
this.update();
- if (typeof(this.onChange) == "function")
- this.onChange();
+ if (isFunction(this.onchange))
+ this.onchange();
},
getElement : function()
@@ -492,7 +443,7 @@ Prado.WebUI.TDatePicker.prototype = getSelectedDate : function ()
{
- return this.selectedDate == null ? null : this.newDate(this.selectedDate);
+ return isNull(this.selectedDate) ? null : this.newDate(this.selectedDate);
},
setYear : function(year)
@@ -529,9 +480,8 @@ Prado.WebUI.TDatePicker.prototype = pos[1] += this.control.offsetHeight;
else
{
- var dayList = Prado.WebUI.TDatePicker.getDayListControl(this.control);
- if(dayList)
- pos[1] += dayList.offsetHeight-1;
+ if($(this.options.ID+"_day"))
+ pos[1] += $(this.options.ID+"_day").offsetHeight-1;
}
this._calDiv.style.display = "block";
@@ -543,7 +493,7 @@ Prado.WebUI.TDatePicker.prototype = this.documentKeyDownEvent = this.keyPressed.bindEvent(this);
Event.observe(document.body, "click", this.documentClickEvent);
var date = this.getDateFromInput();
- if(date)
+ if(!isNull(date))
{
this.selectedDate = date;
this.setSelectedDate(date);
@@ -558,7 +508,20 @@ Prado.WebUI.TDatePicker.prototype = if(this.options.InputMode == "TextBox")
return Date.SimpleParse($F(this.control), this.Format);
else
- return Prado.WebUI.TDatePicker.getDropDownDate(this.control);
+ {
+ var now=new Date();
+ var year=now.getFullYear();
+ var month=now.getMonth();
+ var date=1;
+ if($(this.options.ID+"_day"))
+ day = $F(this.options.ID+"_day");
+ if($(this.options.ID+"_month"))
+ month = $F(this.options.ID+"_month");
+ if($(this.options.ID+"_year"))
+ year = $F(this.options.ID+"_year");
+ var newdate=new Date(year,month,day, 0, 0, 0);
+ return newdate;
+ }
},
//hide the calendar when clicked outside any calendar
@@ -647,10 +610,7 @@ Prado.WebUI.TDatePicker.prototype = hover : function(ev)
{
//conditionally add the hover class to the event target element.
- if(ev.type == "mouseover")
- Event.element(ev).addClassName("hover");
- else
- Event.element(ev).removeClassName("hover");
+ Element.condClassName(Event.element(ev), "hover", ev.type=="mouseover");
},
updateHeader : function () {
diff --git a/framework/Web/Javascripts/extended/event.js b/framework/Web/Javascripts/extended/event.js index 13e875da..40cf60a1 100644 --- a/framework/Web/Javascripts/extended/event.js +++ b/framework/Web/Javascripts/extended/event.js @@ -95,10 +95,9 @@ Object.extend(Event, else if(element.fireEvent)
{
element.fireEvent('on'+type);
- if(element[type])
- element[type]();
+ element[type]();
}
- else if(element[type])
+ else
element[type]();
}
});
\ No newline at end of file diff --git a/framework/Web/Javascripts/js/colorpicker.js b/framework/Web/Javascripts/js/colorpicker.js index b926dc93..27e180b0 100644 --- a/framework/Web/Javascripts/js/colorpicker.js +++ b/framework/Web/Javascripts/js/colorpicker.js @@ -257,7 +257,7 @@ this.input.parentNode.appendChild(this.iePopUp); if(mode == "Full") this.initializeFullPicker(); } -this.show(mode); +this.show(); }, show : function(type) { @@ -276,7 +276,6 @@ Event.observe(document,"keydown", this._documentKeyDownEvent); this.showing = true; if(type == "Full") { -this.observeMouseMovement(); var color = Rico.Color.createFromHex(this.input.value); this.inputs.oldColor.style.backgroundColor = color.asHex(); this.setColor(color,true); @@ -293,11 +292,6 @@ this.element.style.display = "none"; this.showing = false; Event.stopObserving(document.body, "click", this._documentClickEvent); Event.stopObserving(document,"keydown", this._documentKeyDownEvent); -if(this._observingMouseMove) -{ -Event.stopObserving(document.body, "mousemove", this._onMouseMove); -this._observingMouseMove = false; -} } }, keyPressed : function(event,type) @@ -373,7 +367,7 @@ updateColor : function(color) { this.input.value = color.toString().toUpperCase(); this.button.style.backgroundColor = color.toString(); -if(typeof(this.onChange) == "function") +if(isFunction(this.onChange)) this.onChange(color); }, getFullPickerContainer : function(pickerID) @@ -400,7 +394,7 @@ TD({className:'currentcolor',colSpan:2}, this.inputs['currentColor'], this.inputs['oldColor'])), TR(null, TD(null,'H:'), -TD(null,this.inputs['H'], '??')), +TD(null,this.inputs['H'], '°')), TR(null, TD(null,'S:'), TD(null,this.inputs['S'], '%')), @@ -469,39 +463,26 @@ this._onHueMouseDown = this.onHueMouseDown.bind(this); this._onMouseUp = this.onMouseUp.bind(this); this._onMouseMove = this.onMouseMove.bind(this); Event.observe(this.inputs.background, "mousedown", this._onColorMouseDown); -Event.observe(this.inputs.selector, "mousedown", this._onColorMouseDown); Event.observe(this.inputs.hue, "mousedown", this._onHueMouseDown); -Event.observe(this.inputs.slider, "mousedown", this._onHueMouseDown); Event.observe(document.body, "mouseup", this._onMouseUp); -this.observeMouseMovement(); +Event.observe(document.body, "mousemove", this._onMouseMove); Event.observe(this.buttons.Cancel, "click", this.hide.bindEvent(this,this.options['Mode'])); Event.observe(this.buttons.OK, "click", this.onOKClicked.bind(this)); }, -observeMouseMovement : function() -{ -if(!this._observingMouseMove) -{ -Event.observe(document.body, "mousemove", this._onMouseMove); -this._observingMouseMove = true; -} -}, onColorMouseDown : function(ev) { this.isMouseDownOnColor = true; this.onMouseMove(ev); -Event.stop(ev); }, onHueMouseDown : function(ev) { this.isMouseDownOnHue = true; this.onMouseMove(ev); -Event.stop(ev); }, onMouseUp : function(ev) { this.isMouseDownOnColor = false; this.isMouseDownOnHue = false; -Event.stop(ev); }, onMouseMove : function(ev) { @@ -509,7 +490,6 @@ if(this.isMouseDownOnColor) this.changeSV(ev); if(this.isMouseDownOnHue) this.changeH(ev); -Event.stop(ev); }, changeSV : function(ev) { @@ -518,12 +498,9 @@ var py = Event.pointerY(ev); var pos = Position.cumulativeOffset(this.inputs.background); var x = this.truncate(px - pos[0],0,255); var y = this.truncate(py - pos[1],0,255); +var h = this.truncate(this.inputs.H.value,0,360)/360; var s = x/255; var b = (255-y)/255; -var current_s = parseInt(this.inputs.S.value); -var current_b = parseInt(this.inputs.V.value); -if(current_s == parseInt(s*100) && current_b == parseInt(b*100)) return; -var h = this.truncate(this.inputs.H.value,0,360)/360; var color = new Rico.Color(); color.rgb = Rico.Color.HSBtoRGB(h,s,b); this.inputs.selector.style.left = x+"px"; @@ -537,9 +514,6 @@ var py = Event.pointerY(ev); var pos = Position.cumulativeOffset(this.inputs.background); var y = this.truncate(py - pos[1],0,255); var h = (255-y)/255; -var current_h = this.truncate(this.inputs.H.value,0,360); -current_h = current_h == 0 ? 360 : current_h; -if(current_h == parseInt(h*360)) return; var s = parseInt(this.inputs.S.value)/100; var b = parseInt(this.inputs.V.value)/100; var color = new Rico.Color(); diff --git a/framework/Web/Javascripts/js/datepicker.js b/framework/Web/Javascripts/js/datepicker.js index 19d39bbe..e82507ea 100644 --- a/framework/Web/Javascripts/js/datepicker.js +++ b/framework/Web/Javascripts/js/datepicker.js @@ -1,41 +1,10 @@ Prado.WebUI.TDatePicker = Class.create(); -Object.extend(Prado.WebUI.TDatePicker, -{ -getDropDownDate : function(control) -{ -var now=new Date(); -var year=now.getFullYear(); -var month=now.getMonth(); -var day=1; -var month_list = this.getMonthListControl(control); - var day_list = this.getDayListControl(control); - var year_list = this.getYearListControl(control); -var day = day_list ? $F(day_list) : 1; -var month = month_list ? $F(month_list) : now.getMonth(); -var year = year_list ? $F(year_list) : now.getFullYear(); -return new Date(year,month,day, 0, 0, 0); -}, -getYearListControl : function(control) -{ -return $(control.id+"_year"); -}, -getMonthListControl : function(control) -{ -return $(control.id+"_month"); -}, -getDayListControl : function(control) -{ -return $(control.id+"_day"); -} -}); Prado.WebUI.TDatePicker.prototype = { MonthNames : ["January","February","March","April", "May","June","July","August", "September","October","November","December" ], -AbbreviatedMonthNames : ["Jan", "Feb", "Mar", "Apr", "May", -"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], ShortWeekDayNames : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ], Format : "yyyy-MM-dd", FirstDayOfWeek : 1, @@ -169,7 +138,7 @@ this._calDiv.appendChild(div); var todayButton = document.createElement("button"); todayButton.className = "todayButton"; var today = this.newDate(); -var buttonText = today.SimpleFormat(this.Format,this); +var buttonText = today.SimpleFormat(this.Format); todayButton.appendChild(document.createTextNode(buttonText)); div.appendChild(todayButton); if(Prado.Browser().ie) @@ -323,27 +292,20 @@ var m = d.getMonth() + n; this.setMonth(m); return false; }, -onChange : function() +onchange : function() { if(this.options.InputMode == "TextBox") -{ this.control.value = this.formatDate(); -Event.fireEvent(this.control, "change"); -} else { -var day = Prado.WebUI.TDatePicker.getDayListControl(this.control); -var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control); -var year = Prado.WebUI.TDatePicker.getYearListControl(this.control); +var day = $(this.options.ID+"_day"); +var month = $(this.options.ID+"_month"); +var year = $(this.options.ID+"_year"); var date = this.selectedDate; if(day) -{ day.selectedIndex = date.getDate()-1; -} if(month) -{ month.selectedIndex = date.getMonth(); -} if(year) { var years = year.options; @@ -351,18 +313,17 @@ var currentYear = date.getFullYear(); for(var i = 0; i < years.length; i++) years[i].selected = years[i].value.toInteger() == currentYear; } -Event.fireEvent(day || month || year, "change"); } }, formatDate : function() { -return this.selectedDate ? this.selectedDate.SimpleFormat(this.Format,this) : ''; +return this.selectedDate ? this.selectedDate.SimpleFormat(this.Format) : ''; }, newDate : function(date) { if(!date) date = new Date(); -if(typeof(date) == "string" || typeof(date) == "number") +if(isString(date)|| isNumber(date)) date = new Date(date); return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0,0,0); }, @@ -373,8 +334,8 @@ return; this.selectedDate = this.newDate(date); this.updateHeader(); this.update(); -if (typeof(this.onChange) == "function") -this.onChange(); +if (isFunction(this.onchange)) +this.onchange(); }, getElement : function() { @@ -382,7 +343,7 @@ return this._calDiv; }, getSelectedDate : function () { -return this.selectedDate == null ? null : this.newDate(this.selectedDate); +return isNull(this.selectedDate) ? null : this.newDate(this.selectedDate); }, setYear : function(year) { @@ -413,9 +374,8 @@ if(this.options.InputMode == "TextBox") pos[1] += this.control.offsetHeight; else { -var dayList = Prado.WebUI.TDatePicker.getDayListControl(this.control); -if(dayList) -pos[1] += dayList.offsetHeight-1; +if($(this.options.ID+"_day")) +pos[1] += $(this.options.ID+"_day").offsetHeight-1; } this._calDiv.style.display = "block"; this._calDiv.style.top = (pos[1]-1) + "px"; @@ -425,7 +385,7 @@ this.documentClickEvent = this.hideOnClick.bindEvent(this); this.documentKeyDownEvent = this.keyPressed.bindEvent(this); Event.observe(document.body, "click", this.documentClickEvent); var date = this.getDateFromInput(); -if(date) +if(!isNull(date)) { this.selectedDate = date; this.setSelectedDate(date); @@ -439,7 +399,20 @@ getDateFromInput : function() if(this.options.InputMode == "TextBox") return Date.SimpleParse($F(this.control), this.Format); else -return Prado.WebUI.TDatePicker.getDropDownDate(this.control); +{ +var now=new Date(); +var year=now.getFullYear(); +var month=now.getMonth(); +var date=1; +if($(this.options.ID+"_day")) +day = $F(this.options.ID+"_day"); +if($(this.options.ID+"_month")) +month = $F(this.options.ID+"_month"); +if($(this.options.ID+"_year")) +year = $F(this.options.ID+"_year"); +var newdate=new Date(year,month,day, 0, 0, 0); +return newdate; +} }, hideOnClick : function(ev) { @@ -511,10 +484,7 @@ this.dateSlot[index].data.parentNode.className = "empty"; }, hover : function(ev) { -if(ev.type == "mouseover") -Event.element(ev).addClassName("hover"); -else -Event.element(ev).removeClassName("hover"); +Element.condClassName(Event.element(ev), "hover", ev.type=="mouseover"); }, updateHeader : function () { var options = this._monthSelect.options; diff --git a/framework/Web/Javascripts/js/prado.js b/framework/Web/Javascripts/js/prado.js index c7145188..6737d4ce 100644 --- a/framework/Web/Javascripts/js/prado.js +++ b/framework/Web/Javascripts/js/prado.js @@ -1299,10 +1299,9 @@ element.dispatchEvent(event); else if(element.fireEvent) { element.fireEvent('on'+type); -if(element[type]) element[type](); } -else if(element[type]) +else element[type](); } }); @@ -1869,9 +1868,9 @@ lastFocus.value = options['EventTarget']; } $('PRADO_POSTBACK_TARGET').value = options['EventTarget']; $('PRADO_POSTBACK_PARAMETER').value = options['EventParameter']; +Event.fireEvent(form,"submit"); if(options['StopEvent']) Event.stop(event); -Event.fireEvent(form,"submit"); } Prado.Element = { diff --git a/framework/Web/Javascripts/js/validator.js b/framework/Web/Javascripts/js/validator.js index 38d8a2a4..7d343d87 100644 --- a/framework/Web/Javascripts/js/validator.js +++ b/framework/Web/Javascripts/js/validator.js @@ -26,7 +26,6 @@ if(this.managers[formID]) this.managers[formID].addValidator(validator); else throw new Error("A validation manager for form '"+formID+"' needs to be created first."); -return this.managers[formID]; }, addSummary : function(formID, validator) { @@ -34,11 +33,9 @@ if(this.managers[formID]) this.managers[formID].addSummary(validator); else throw new Error("A validation manager for form '"+formID+"' needs to be created first."); -return this.managers[formID]; } }); -Prado.ValidationManager = Class.create(); -Prado.ValidationManager.prototype = +Prado.Validation.prototype = { validators : [], summaries : [], @@ -59,12 +56,13 @@ return this._validateNonGroup(); _validateGroup: function(groupID) { var valid = true; +var manager = this; if(this.groups.include(groupID)) { this.validators.each(function(validator) { if(validator.group == groupID) -valid = valid & validator.validate(); +valid = valid & validator.validate(manager); else validator.hide(); }); @@ -75,10 +73,11 @@ return valid; _validateNonGroup : function() { var valid = true; +var manager = this; this.validators.each(function(validator) { if(!validator.group) -valid = valid & validator.validate(); +valid = valid & validator.validate(manager); else validator.hide(); }); @@ -272,9 +271,8 @@ enabled : true, visible : false, isValid : true, options : {}, -_isObserving : {}, +_isObserving : false, group : null, -manager : null, initialize : function(options) { options.OnValidate = options.OnValidate || Prototype.emptyFunction; @@ -284,7 +282,7 @@ this.options = options; this.control = $(options.ControlToValidate); this.message = $(options.ID); this.group = options.ValidationGroup; -this.manager = Prado.Validation.addValidator(options.FormID, this); +Prado.Validation.addValidator(options.FormID, this); }, getErrorMessage : function() { @@ -298,7 +296,6 @@ if(this.options.Display == "Dynamic") this.isValid ? this.message.hide() : this.message.show(); this.message.style.visibility = this.isValid ? "hidden" : "visible"; } -if(this.control) this.updateControlCssClass(this.control, this.isValid); if(this.options.FocusOnError && !this.isValid) Prado.Element.focus(this.options.FocusElementID); @@ -321,36 +318,33 @@ this.isValid = true; this.updateControl(); this.visible = false; }, -validate : function() +validate : function(manager) { if(this.enabled) -this.isValid = this.evaluateIsValid(); -this.options.OnValidate(this); +this.isValid = this.evaluateIsValid(manager); +this.options.OnValidate(this, manager); this.updateControl(); if(this.isValid) -this.options.OnSuccess(this); +this.options.OnSuccess(this, manager); else -this.options.OnError(this); -this.observeChanges(this.control); +this.options.OnError(this, manager); +this.observeChanges(manager); return this.isValid; }, -observeChanges : function(control) +observeChanges : function(manager) { -if(!control) return; -var canObserveChanges = this.options.ObserveChanges != false; -var currentlyObserving = this._isObserving[control.id+this.options.ID]; -if(canObserveChanges && !currentlyObserving) +if(this.options.ObserveChanges != false && !this._isObserving) { var validator = this; -Event.observe(control, 'change', function() +Event.observe(this.control, 'change', function() { if(validator.visible) { -validator.validate(); -validator.manager.updateSummary(validator.group); +validator.validate(manager); +manager.updateSummary(validator.group); } }); -this._isObserving[control.id+this.options.ID] = true; +this._isObserving = true; } }, trim : function(value) @@ -360,7 +354,7 @@ return typeof(value) == "string" ? value.trim() : ""; convert : function(dataType, value) { if(typeof(value) == "undefined") -value = this.getValidationValue(); +value = $F(this.control); var string = new String(value); switch(dataType) { @@ -369,116 +363,18 @@ return string.toInteger(); case "Double" : case "Float" : return string.toDouble(this.options.DecimalChar); +case "Currency" : +return string.toCurrency(this.options.GroupChar, this.options.Digits, this.options.DecimalChar); case "Date": -if(typeof(value) != "string") -return value; -else -{ var value = string.toDate(this.options.DateFormat); if(value && typeof(value.getTime) == "function") return value.getTime(); else return null; -} case "String": return string.toString(); } return value; -}, -getValidationValue : function(control) - { - if(!control) - control = this.control - switch(this.options.ControlType) - { - case 'TDatePicker': - if(control.type == "text") - return this.trim($F(control)); - else - { - this.observeDatePickerChanges(); -return Prado.WebUI.TDatePicker.getDropDownDate(control).getTime(); - } - default: - if(this.isListControlType()) - return this.getFirstSelectedListValue(); - else - return this.trim($F(control)); - } - }, -observeDatePickerChanges : function() - { - if(Prado.Browser().ie) - { - var DatePicker = Prado.WebUI.TDatePicker; - this.observeChanges(DatePicker.getDayListControl(this.control)); -this.observeChanges(DatePicker.getMonthListControl(this.control)); -this.observeChanges(DatePicker.getYearListControl(this.control)); - } - }, -getSelectedValuesAndChecks : function(elements, initialValue) -{ -var checked = 0; -var values = []; -var isSelected = this.isCheckBoxType(elements[0]) ? 'checked' : 'selected'; -elements.each(function(element) -{ -if(element[isSelected] && element.value != initialValue) -{ -checked++; -values.push(element.value); -} -}); -return {'checks' : checked, 'values' : values}; -}, -getListElements : function() -{ -switch(this.options.ControlType) -{ -case 'TCheckBoxList': case 'TRadioButtonList': -var elements = []; -for(var i = 0; i < this.options.TotalItems; i++) -{ -var element = $(this.options.ControlToValidate+"_"+i); -if(this.isCheckBoxType(element)) -elements.push(element); -} -return elements; -case 'TListBox': -var elements = []; -var element = $(this.options.ControlToValidate); -if(element && (type = element.type.toLowerCase())) -{ -if(type == "select-one" || type == "select-multiple") -elements = $A(element.options); -} -return elements; -default: -return []; -} -}, -isCheckBoxType : function(element) -{ -if(element && element.type) -{ -var type = element.type.toLowerCase(); -return type == "checkbox" || type == "radio"; -} -return false; -}, -isListControlType : function() -{ -var list = ['TCheckBoxList', 'TRadioButtonList', 'TListBox']; -return list.include(this.options.ControlType); -}, -getFirstSelectedListValue : function() -{ -var initial = ""; -if(typeof(this.options.InitialValue) != "undefined") -initial = this.options.InitialValue; -var elements = this.getListElements(); -var selection = this.getSelectedValuesAndChecks(elements, initial); -return selection.values.length > 0 ? selection.values[0] : initial; } } Prado.WebUI.TRequiredFieldValidator = Class.extend(Prado.WebUI.TBaseValidator, @@ -492,7 +388,7 @@ return true; } else { -var a = this.getValidationValue(); +var a = this.trim($F(this.control)); var b = this.trim(this.options.InitialValue); return(a != b); } @@ -500,24 +396,41 @@ return(a != b); }); Prado.WebUI.TCompareValidator = Class.extend(Prado.WebUI.TBaseValidator, { -evaluateIsValid : function() +_observingComparee : false, +evaluateIsValid : function(manager) { -var value = this.getValidationValue(); +var value = this.trim($F(this.control)); if (value.length <= 0) return true; var comparee = $(this.options.ControlToCompare); if(comparee) -var compareTo = this.getValidationValue(comparee); +var compareTo = this.trim($F(comparee)); else var compareTo = this.options.ValueToCompare || ""; var isValid =this.compare(value, compareTo); if(comparee) { this.updateControlCssClass(comparee, isValid); -this.observeChanges(comparee); +this.observeComparee(comparee, manager); } return isValid; }, +observeComparee : function(comparee, manager) +{ +if(this.options.ObserveChanges != false && !this._observingComparee) +{ +var validator = this; +Event.observe(comparee, "change", function() +{ +if(validator.visible) +{ +validator.validate(manager); +manager.updateSummary(validator.group); +} +}); +this._observingComparee = true; +} +}, compare : function(operand1, operand2) { var op1, op2; @@ -544,9 +457,9 @@ return (op1 == op2); }); Prado.WebUI.TCustomValidator = Class.extend(Prado.WebUI.TBaseValidator, { -evaluateIsValid : function() +evaluateIsValid : function(manager) { -var value = this.getValidationValue(); +var value = $F(this.control); var clientFunction = this.options.ClientValidationFunction; if(typeof(clientFunction) == "string" && clientFunction.length > 0) { @@ -558,9 +471,9 @@ return true; }); Prado.WebUI.TRangeValidator = Class.extend(Prado.WebUI.TBaseValidator, { -evaluateIsValid : function() +evaluateIsValid : function(manager) { -var value = this.getValidationValue(); +var value = this.trim($F(this.control)); if(value.length <= 0) return true; if(typeof(this.options.DataType) == "undefined") @@ -568,6 +481,7 @@ this.options.DataType = "String"; var min = this.convert(this.options.DataType, this.options.MinValue || null); var max = this.convert(this.options.DataType, this.options.MaxValue || null); value = this.convert(this.options.DataType, value); +Logger.warn(min+" <= "+value+" <= "+max); if(value == null) return false; var valid = true; @@ -580,9 +494,9 @@ return valid; }); Prado.WebUI.TRegularExpressionValidator = Class.extend(Prado.WebUI.TBaseValidator, { -evaluateIsValid : function() +evaluateIsValid : function(master) { -var value = this.getValidationValue(); +var value = this.trim($F(this.control)); if (value.length <= 0) return true; var rx = new RegExp(this.options.ValidationExpression); @@ -591,52 +505,3 @@ return (matches != null && value == matches[0]); } }); Prado.WebUI.TEmailAddressValidator = Prado.WebUI.TRegularExpressionValidator; -Prado.WebUI.TListControlValidator = Class.extend(Prado.WebUI.TBaseValidator, -{ -evaluateIsValid : function() -{ -var elements = this.getListElements(); -if(elements && elements.length <= 0) -return true; -this.observeListElements(elements); -var selection = this.getSelectedValuesAndChecks(elements); -return this.isValidList(selection.checks, selection.values); -}, -observeListElements : function(elements) - { -if(Prado.Browser().ie && this.isCheckBoxType(elements[0])) -{ -var validator = this; -elements.each(function(element) -{ -validator.observeChanges(element); -}); -} - }, -isValidList : function(checked, values) -{ -var exists = true; -var required = this.getRequiredValues(); -if(required.length > 0) -{ -if(values.length < required.length) -return false; -required.each(function(requiredValue) -{ -exists = exists && values.include(requiredValue); -}); -} -var min = typeof(this.options.Min) == "undefined" ? -Number.NEGATIVE_INFINITY : this.options.Min; -var max = typeof(this.options.Max) == "undefined" ? -Number.POSITIVE_INFINITY : this.options.Max; -return exists && checked >= min && checked <= max; -}, -getRequiredValues : function() -{ -var required = []; -if(this.options.Required && this.options.Required.length > 0) -required = this.options.Required.split(/,\s*/); -return required; -} -}); diff --git a/framework/Web/Javascripts/prado/form.js b/framework/Web/Javascripts/prado/form.js index 2beb945b..addad893 100644 --- a/framework/Web/Javascripts/prado/form.js +++ b/framework/Web/Javascripts/prado/form.js @@ -129,9 +129,9 @@ Prado.PostBack = function(event,options) $('PRADO_POSTBACK_TARGET').value = options['EventTarget'];
$('PRADO_POSTBACK_PARAMETER').value = options['EventParameter'];
+ Event.fireEvent(form,"submit");
if(options['StopEvent'])
Event.stop(event);
- Event.fireEvent(form,"submit");
}
/*
diff --git a/framework/Web/Javascripts/prado/validation3.js b/framework/Web/Javascripts/prado/validation3.js index 4c189532..10169aab 100644 --- a/framework/Web/Javascripts/prado/validation3.js +++ b/framework/Web/Javascripts/prado/validation3.js @@ -1,58 +1,6 @@ /**
- * Prado client-side javascript validation fascade.
- *
- * There are 4 basic classes, Validation, ValidationManager, ValidationSummary
- * and TBaseValidator, that interact together to perform validation.
- * The <tt>Prado.Validation</tt> class co-ordinates together the
- * validation scheme and is responsible for maintaining references
- * to ValidationManagers.
- *
- * The ValidationManager class is responsible for maintaining refereneces
- * to individual validators, validation summaries and their associated
- * groupings.
- *
- * The ValidationSummary take cares of display the validator error messages
- * as html output or an alert output.
- *
- * The TBaseValidator is the base class for all validators and contains
- * methods to interact with the actual inputs, data type conversion.
- *
- * An instance of ValidationManager must be instantiated first for a
- * particular form before instantiating validators and summaries.
- *
- * Usage example: adding a required field to a text box input with
- * ID "input1" in a form with ID "form1".
- * <code>
- * <script type="text/javascript" src="../prado.js"></script>
- * <script type="text/javascript" src="../validator.js"></script>
- * <form id="form1" action="...">
- * <div>
- * <input type="text" id="input1" />
- * <span id="validator1" style="display:none; color:red">*</span>
- * <input type="submit text="submit" />
- * <script type="text/javascript">
- * new Prado.ValidationManager({FormID : 'form1'});
- * var options =
- * {
- * ID : 'validator1',
- * FormID : 'form1',
- * ErrorMessage : '*',
- * ControlToValidate : 'input1'
- * }
- * new Prado.WebUI.TRequiredFieldValidator(options);
- * new Prado.WebUI.TValidationSummary({ID:'summary1',FormID:'form1'});
- *
- * //watch the form onsubmit event, check validators, stop if not valid.
- * Event.observe("form1", "submit" function(ev)
- * {
- * if(Prado.WebUI.Validation.isValid("form1") == false)
- * Event.stop(ev);
- * });
- * </script>
- * </div>
- * </form>
- * </code>
+ * Prado client-side javascript validation manager.
*/
Prado.Validation = Class.create();
@@ -106,7 +54,6 @@ Object.extend(Prado.Validation, * Add a new validator to a particular form.
* @param string the form that the validator belongs.
* @param object a validator
- * @return object the manager
*/
addValidator : function(formID, validator)
{
@@ -114,14 +61,12 @@ Object.extend(Prado.Validation, this.managers[formID].addValidator(validator);
else
throw new Error("A validation manager for form '"+formID+"' needs to be created first.");
- return this.managers[formID];
},
/**
* Add a new validation summary.
* @param string the form that the validation summary belongs.
* @param object a validation summary
- * @return object manager
*/
addSummary : function(formID, validator)
{
@@ -129,19 +74,14 @@ Object.extend(Prado.Validation, this.managers[formID].addSummary(validator);
else
throw new Error("A validation manager for form '"+formID+"' needs to be created first.");
- return this.managers[formID];
}
});
-Prado.ValidationManager = Class.create();
/**
* Validation manager instances. Manages validators for a particular
- * HTML form. The manager contains references to all the validators
- * summaries, and their groupings for a particular form.
- * Generally, <tt>Prado.Validation</tt> methods should be called rather
- * than calling directly the ValidationManager.
+ * HTML form.
*/
-Prado.ValidationManager.prototype =
+Prado.Validation.prototype =
{
validators : [], // list of validators
summaries : [], // validation summaries
@@ -180,12 +120,13 @@ Prado.ValidationManager.prototype = _validateGroup: function(groupID)
{
var valid = true;
+ var manager = this;
if(this.groups.include(groupID))
{
this.validators.each(function(validator)
{
if(validator.group == groupID)
- valid = valid & validator.validate();
+ valid = valid & validator.validate(manager);
else
validator.hide();
});
@@ -201,10 +142,11 @@ Prado.ValidationManager.prototype = _validateNonGroup : function()
{
var valid = true;
+ var manager = this;
this.validators.each(function(validator)
{
if(!validator.group)
- valid = valid & validator.validate();
+ valid = valid & validator.validate(manager);
else
validator.hide();
});
@@ -520,9 +462,8 @@ Prado.WebUI.TBaseValidator.prototype = visible : false,
isValid : true,
options : {},
- _isObserving : {},
+ _isObserving : false,
group : null,
- manager : null,
/**
* <code>
@@ -552,7 +493,7 @@ Prado.WebUI.TBaseValidator.prototype = this.message = $(options.ID);
this.group = options.ValidationGroup;
- this.manager = Prado.Validation.addValidator(options.FormID, this);
+ Prado.Validation.addValidator(options.FormID, this);
},
/**
@@ -577,8 +518,7 @@ Prado.WebUI.TBaseValidator.prototype = this.message.style.visibility = this.isValid ? "hidden" : "visible";
}
- if(this.control)
- this.updateControlCssClass(this.control, this.isValid);
+ this.updateControlCssClass(this.control, this.isValid);
if(this.options.FocusOnError && !this.isValid)
Prado.Element.focus(this.options.FocusElementID);
@@ -617,23 +557,24 @@ Prado.WebUI.TBaseValidator.prototype = /**
* Calls evaluateIsValid() function to set the value of isValid property.
* Triggers onValidate event and onSuccess or onError event.
+ * @param Validation manager
* @return boolean true if valid.
*/
- validate : function()
+ validate : function(manager)
{
if(this.enabled)
- this.isValid = this.evaluateIsValid();
+ this.isValid = this.evaluateIsValid(manager);
- this.options.OnValidate(this);
+ this.options.OnValidate(this, manager);
this.updateControl();
if(this.isValid)
- this.options.OnSuccess(this);
+ this.options.OnSuccess(this, manager);
else
- this.options.OnError(this);
-
- this.observeChanges(this.control);
+ this.options.OnError(this, manager);
+
+ this.observeChanges(manager);
return this.isValid;
},
@@ -641,28 +582,21 @@ Prado.WebUI.TBaseValidator.prototype = /**
* Observe changes to the control input, re-validate upon change. If
* the validator is not visible, no updates are propagated.
- * @param HTMLElement control to observe changes
*/
- observeChanges : function(control)
+ observeChanges : function(manager)
{
- if(!control) return;
-
- var canObserveChanges = this.options.ObserveChanges != false;
- var currentlyObserving = this._isObserving[control.id+this.options.ID];
-
- if(canObserveChanges && !currentlyObserving)
+ if(this.options.ObserveChanges != false && !this._isObserving)
{
var validator = this;
-
- Event.observe(control, 'change', function()
+ Event.observe(this.control, 'change', function()
{
if(validator.visible)
{
- validator.validate();
- validator.manager.updateSummary(validator.group);
+ validator.validate(manager);
+ manager.updateSummary(validator.group);
}
});
- this._isObserving[control.id+this.options.ID] = true;
+ this._isObserving = true;
}
},
@@ -676,14 +610,14 @@ Prado.WebUI.TBaseValidator.prototype = /**
* Convert the value to a specific data type.
- * @param {string} the data type, "Integer", "Double", "Date" or "String"
+ * @param {string} the data type, "Integer", "Double", "Currency", "Date" or "String"
* @param {string} the value to convert.
* @type {mixed|null} the converted data value.
*/
convert : function(dataType, value)
{
if(typeof(value) == "undefined")
- value = this.getValidationValue();
+ value = $F(this.control);
var string = new String(value);
switch(dataType)
{
@@ -692,149 +626,18 @@ Prado.WebUI.TBaseValidator.prototype = case "Double" :
case "Float" :
return string.toDouble(this.options.DecimalChar);
+ case "Currency" :
+ return string.toCurrency(this.options.GroupChar, this.options.Digits, this.options.DecimalChar);
case "Date":
- if(typeof(value) != "string")
- return value;
+ var value = string.toDate(this.options.DateFormat);
+ if(value && typeof(value.getTime) == "function")
+ return value.getTime();
else
- {
- var value = string.toDate(this.options.DateFormat);
- if(value && typeof(value.getTime) == "function")
- return value.getTime();
- else
- return null;
- }
+ return null;
case "String":
return string.toString();
}
return value;
- },
-
- /**
- * @return mixed control value to validate
- */
- getValidationValue : function(control)
- {
- if(!control)
- control = this.control
- switch(this.options.ControlType)
- {
- case 'TDatePicker':
- if(control.type == "text")
- return this.trim($F(control));
- else
- {
- this.observeDatePickerChanges();
-
- return Prado.WebUI.TDatePicker.getDropDownDate(control).getTime();
- }
- default:
- if(this.isListControlType())
- return this.getFirstSelectedListValue();
- else
- return this.trim($F(control));
- }
- },
-
- /**
- * Observe changes in the drop down list date picker, IE only.
- */
- observeDatePickerChanges : function()
- {
- if(Prado.Browser().ie)
- {
- var DatePicker = Prado.WebUI.TDatePicker;
- this.observeChanges(DatePicker.getDayListControl(this.control));
- this.observeChanges(DatePicker.getMonthListControl(this.control));
- this.observeChanges(DatePicker.getYearListControl(this.control));
- }
- },
-
- /**
- * Gets numeber selections and their values.
- * @return object returns selected values in <tt>values</tt> property
- * and number of selections in <tt>checks</tt> property.
- */
- getSelectedValuesAndChecks : function(elements, initialValue)
- {
- var checked = 0;
- var values = [];
- var isSelected = this.isCheckBoxType(elements[0]) ? 'checked' : 'selected';
- elements.each(function(element)
- {
- if(element[isSelected] && element.value != initialValue)
- {
- checked++;
- values.push(element.value);
- }
- });
- return {'checks' : checked, 'values' : values};
- },
-
- /**
- * Gets an array of the list control item input elements, for TCheckBoxList
- * checkbox inputs are returned, for TListBox HTML option elements are returned.
- * @return array list control option elements.
- */
- getListElements : function()
- {
- switch(this.options.ControlType)
- {
- case 'TCheckBoxList': case 'TRadioButtonList':
- var elements = [];
- for(var i = 0; i < this.options.TotalItems; i++)
- {
- var element = $(this.options.ControlToValidate+"_"+i);
- if(this.isCheckBoxType(element))
- elements.push(element);
- }
- return elements;
- case 'TListBox':
- var elements = [];
- var element = $(this.options.ControlToValidate);
- if(element && (type = element.type.toLowerCase()))
- {
- if(type == "select-one" || type == "select-multiple")
- elements = $A(element.options);
- }
- return elements;
- default:
- return [];
- }
- },
-
- /**
- * @return boolean true if element is of checkbox or radio type.
- */
- isCheckBoxType : function(element)
- {
- if(element && element.type)
- {
- var type = element.type.toLowerCase();
- return type == "checkbox" || type == "radio";
- }
- return false;
- },
-
- /**
- * @return boolean true if control to validate is of some of the TListControl type.
- */
- isListControlType : function()
- {
- var list = ['TCheckBoxList', 'TRadioButtonList', 'TListBox'];
- return list.include(this.options.ControlType);
- },
-
- /**
- * @return string gets the first selected list value, initial value if none found.
- */
- getFirstSelectedListValue : function()
- {
- var initial = "";
- if(typeof(this.options.InitialValue) != "undefined")
- initial = this.options.InitialValue;
- var elements = this.getListElements();
- var selection = this.getSelectedValuesAndChecks(elements, initial);
- return selection.values.length > 0 ? selection.values[0] : initial;
}
}
@@ -861,7 +664,7 @@ Prado.WebUI.TRequiredFieldValidator = Class.extend(Prado.WebUI.TBaseValidator, }
else
{
- var a = this.getValidationValue();
+ var a = this.trim($F(this.control));
var b = this.trim(this.options.InitialValue);
return(a != b);
}
@@ -883,6 +686,7 @@ Prado.WebUI.TRequiredFieldValidator = Class.extend(Prado.WebUI.TBaseValidator, * type before the comparison operation is performed. The following value types are supported:
* - <b>Integer</b> A 32-bit signed integer data type.
* - <b>Float</b> A double-precision floating point number data type.
+ * - <b>Currency</b> A decimal data type that can contain currency symbols.
* - <b>Date</b> A date data type. The format can be by the <tt>DateFormat</tt> option.
* - <b>String</b> A string data type.
*
@@ -899,35 +703,57 @@ Prado.WebUI.TRequiredFieldValidator = Class.extend(Prado.WebUI.TBaseValidator, */
Prado.WebUI.TCompareValidator = Class.extend(Prado.WebUI.TBaseValidator,
{
- //_observingComparee : false,
+ _observingComparee : false,
/**
* Compares the input to another input or a given value.
*/
- evaluateIsValid : function()
+ evaluateIsValid : function(manager)
{
- var value = this.getValidationValue();
+ var value = this.trim($F(this.control));
if (value.length <= 0)
return true;
var comparee = $(this.options.ControlToCompare);
if(comparee)
- var compareTo = this.getValidationValue(comparee);
+ var compareTo = this.trim($F(comparee));
else
- var compareTo = this.options.ValueToCompare || "";
+ var compareTo = this.options.ValueToCompare || "";
var isValid = this.compare(value, compareTo);
if(comparee)
{
this.updateControlCssClass(comparee, isValid);
- this.observeChanges(comparee);
+ this.observeComparee(comparee, manager);
}
return isValid;
},
/**
+ * Observe the comparee input element for changes.
+ * @param object HTML input element to observe
+ * @param object Validation manager.
+ */
+ observeComparee : function(comparee, manager)
+ {
+ if(this.options.ObserveChanges != false && !this._observingComparee)
+ {
+ var validator = this;
+ Event.observe(comparee, "change", function()
+ {
+ if(validator.visible)
+ {
+ validator.validate(manager);
+ manager.updateSummary(validator.group);
+ }
+ });
+ this._observingComparee = true;
+ }
+ },
+
+ /**
* Compares two values, their values are casted to type defined
* by <tt>DataType</tt> option. False is returned if the first
* operand converts to null. Returns true if the second operand
@@ -990,9 +816,9 @@ Prado.WebUI.TCustomValidator = Class.extend(Prado.WebUI.TBaseValidator, /**
* Calls custom validation function.
*/
- evaluateIsValid : function()
+ evaluateIsValid : function(manager)
{
- var value = this.getValidationValue();
+ var value = $F(this.control);
var clientFunction = this.options.ClientValidationFunction;
if(typeof(clientFunction) == "string" && clientFunction.length > 0)
{
@@ -1014,6 +840,7 @@ Prado.WebUI.TCustomValidator = Class.extend(Prado.WebUI.TBaseValidator, * operation is performed. The following value types are supported:
* - <b>Integer</b> A 32-bit signed integer data type.
* - <b>Float</b> A double-precision floating point number data type.
+ * - <b>Currency</b> A decimal data type that can contain currency symbols.
* - <b>Date</b> A date data type. The date format can be specified by
* setting <tt>DateFormat</tt> option, which must be recognizable
* by <tt>Date.SimpleParse</tt> javascript function.
@@ -1029,11 +856,11 @@ Prado.WebUI.TRangeValidator = Class.extend(Prado.WebUI.TBaseValidator, {
/**
* Compares the input value with a minimum and/or maximum value.
- * @return boolean true if the value is empty, returns false if conversion fails.
+ * Returns true if the value is empty, returns false if conversion fails.
*/
- evaluateIsValid : function()
+ evaluateIsValid : function(manager)
{
- var value = this.getValidationValue();
+ var value = this.trim($F(this.control));
if(value.length <= 0)
return true;
if(typeof(this.options.DataType) == "undefined")
@@ -1043,6 +870,8 @@ Prado.WebUI.TRangeValidator = Class.extend(Prado.WebUI.TBaseValidator, var max = this.convert(this.options.DataType, this.options.MaxValue || null);
value = this.convert(this.options.DataType, value);
+ Logger.warn(min+" <= "+value+" <= "+max);
+
if(value == null)
return false;
@@ -1068,9 +897,9 @@ Prado.WebUI.TRegularExpressionValidator = Class.extend(Prado.WebUI.TBaseValidato /**
* Compare the control input against a regular expression.
*/
- evaluateIsValid : function()
+ evaluateIsValid : function(master)
{
- var value = this.getValidationValue();
+ var value = this.trim($F(this.control));
if (value.length <= 0)
return true;
@@ -1087,84 +916,3 @@ Prado.WebUI.TRegularExpressionValidator = Class.extend(Prado.WebUI.TBaseValidato Prado.WebUI.TEmailAddressValidator = Prado.WebUI.TRegularExpressionValidator;
-/**
- * TListControlValidator checks the number of selection and their values
- * for a TListControl that allows multiple selections.
- */
-Prado.WebUI.TListControlValidator = Class.extend(Prado.WebUI.TBaseValidator,
-{
- /**
- * @return true if the number of selections and/or their values
- * match the requirements.
- */
- evaluateIsValid : function()
- {
- var elements = this.getListElements();
- if(elements && elements.length <= 0)
- return true;
-
- this.observeListElements(elements);
-
- var selection = this.getSelectedValuesAndChecks(elements);
- return this.isValidList(selection.checks, selection.values);
- },
-
- /**
- * Observe list elements for IE browsers of changes
- */
- observeListElements : function(elements)
- {
- if(Prado.Browser().ie && this.isCheckBoxType(elements[0]))
- {
- var validator = this;
- elements.each(function(element)
- {
- validator.observeChanges(element);
- });
- }
- },
-
- /**
- * Determine if the number of checked and the checked values
- * satisfy the required number of checks and/or the checked values
- * equal to the required values.
- * @return boolean true if checked values and number of checks are satisfied.
- */
- isValidList : function(checked, values)
- {
- var exists = true;
-
- //check the required values
- var required = this.getRequiredValues();
- if(required.length > 0)
- {
- if(values.length < required.length)
- return false;
- required.each(function(requiredValue)
- {
- exists = exists && values.include(requiredValue);
- });
- }
-
- var min = typeof(this.options.Min) == "undefined" ?
- Number.NEGATIVE_INFINITY : this.options.Min;
- var max = typeof(this.options.Max) == "undefined" ?
- Number.POSITIVE_INFINITY : this.options.Max;
- return exists && checked >= min && checked <= max;
- },
-
- /**
- * @return array list of required options that must be selected.
- */
- getRequiredValues : function()
- {
- var required = [];
- if(this.options.Required && this.options.Required.length > 0)
- required = this.options.Required.split(/,\s*/);
- return required;
- }
-});
-
-
-
-
diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php index adbc85ae..c5b5e7a5 100644 --- a/framework/Web/UI/WebControls/TBaseValidator.php +++ b/framework/Web/UI/WebControls/TBaseValidator.php @@ -131,7 +131,6 @@ abstract class TBaseValidator extends TLabel implements IValidator */ protected function getClientScriptOptions() { - $control = $this->getValidationTarget(); $options['ID'] = $this->getClientID(); $options['FormID'] = $this->getPage()->getForm()->getClientID(); $options['Display'] = $this->getDisplay(); @@ -142,9 +141,8 @@ abstract class TBaseValidator extends TLabel implements IValidator $options['FocusElementID'] = $this->getFocusElementID(); } $options['ValidationGroup'] = $this->getValidationGroup(); - $options['ControlToValidate'] = $control->getClientID(); + $options['ControlToValidate'] = $this->getValidationTarget()->getClientID(); $options['ControlCssClass'] = $this->getControlCssClass(); - $options['ControlType'] = get_class($control); return $options; } @@ -165,7 +163,7 @@ abstract class TBaseValidator extends TLabel implements IValidator $manager['FormID'] = $formID; $options = TJavaScript::encode($manager); $scripts->registerPradoScript('validator'); - $scripts->registerEndScript($scriptKey, "new Prado.ValidationManager({$options});"); + $scripts->registerEndScript($scriptKey, "new Prado.Validation({$options});"); } if($this->getEnableClientScript()) $this->registerClientScriptValidator(); diff --git a/framework/Web/UI/WebControls/TCheckBox.php b/framework/Web/UI/WebControls/TCheckBox.php index 681c8748..ff7f57f7 100644 --- a/framework/Web/UI/WebControls/TCheckBox.php +++ b/framework/Web/UI/WebControls/TCheckBox.php @@ -340,7 +340,7 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl if($clientID!=='')
$writer->addAttribute('id',$clientID);
$writer->addAttribute('type','checkbox');
- if(($value = $this->getValueAttribute()) !== '')
+ if(($value=$this->getValueAttribute())!=='')
$writer->addAttribute('value',$value);
if(($uniqueID=$this->getUniqueID())!=='')
$writer->addAttribute('name',$uniqueID);
@@ -378,4 +378,4 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl }
-?>
+?>
\ No newline at end of file diff --git a/framework/Web/UI/WebControls/TCheckBoxList.php b/framework/Web/UI/WebControls/TCheckBoxList.php index de332897..2f0cce7c 100644 --- a/framework/Web/UI/WebControls/TCheckBoxList.php +++ b/framework/Web/UI/WebControls/TCheckBoxList.php @@ -47,7 +47,7 @@ Prado::using('System.Web.UI.WebControls.TCheckBox'); * @package System.Web.UI.WebControls
* @since 3.0
*/
-class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingContainer, IPostBackDataHandler, IValidatable
+class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingContainer, IPostBackDataHandler
{
private $_repeatedControl;
private $_isEnabled;
@@ -381,16 +381,6 @@ class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingCont $this->setTabIndex($tabIndex);
}
}
-
- /**
- * Returns the value to be validated.
- * This methid is required by IValidatable interface.
- * @return mixed the value of the property to be validated.
- */
- public function getValidationPropertyValue()
- {
- return $this->getSelectedValue();
- }
}
?>
\ No newline at end of file diff --git a/framework/Web/UI/WebControls/TCompareValidator.php b/framework/Web/UI/WebControls/TCompareValidator.php index b5ebd3ab..172e472f 100644 --- a/framework/Web/UI/WebControls/TCompareValidator.php +++ b/framework/Web/UI/WebControls/TCompareValidator.php @@ -31,6 +31,7 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * type before the comparison operation is performed. The following value types are supported:
* - <b>Integer</b> A 32-bit signed integer data type.
* - <b>Float</b> A double-precision floating point number data type.
+ * - <b>Currency</b> A decimal data type that can contain currency symbols.
* - <b>Date</b> A date data type. The format can be specified by the
* {@link setDateFormat DateFormat} property
* - <b>String</b> A string data type.
@@ -55,13 +56,12 @@ class TCompareValidator extends TBaseValidator }
/**
- * Sets the data type (Integer, Float, Date, String) that the values being
- * compared are converted to before the comparison is made.
+ * Sets the data type (Integer, Float, Currency, Date, String) that the values being compared are converted to before the comparison is made.
* @param string the data type
*/
public function setDataType($value)
{
- $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','String'),'String');
+ $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','Currency','String'),'String');
}
/**
@@ -188,6 +188,16 @@ class TCompareValidator extends TBaseValidator return array(intval($value1), intval($value2));
case 'Float':
return array(floatval($value1), floatval($value2));
+ case 'Currency':
+ if(preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?/',$value1,$matches))
+ $value1=floatval($matches[0]);
+ else
+ $value1=0;
+ if(preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?/',$value2,$matches))
+ $value2=floatval($matches[0]);
+ else
+ $value2=0;
+ return array($value1, $value2);
case 'Date':
$dateFormat = $this->getDateFormat();
if($dateFormat!=='')
diff --git a/framework/Web/UI/WebControls/TDataTypeValidator.php b/framework/Web/UI/WebControls/TDataTypeValidator.php index d78be7bf..81c23ce4 100644 --- a/framework/Web/UI/WebControls/TDataTypeValidator.php +++ b/framework/Web/UI/WebControls/TDataTypeValidator.php @@ -23,6 +23,7 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * The following data types are supported:
* - <b>Integer</b> A 32-bit signed integer data type.
* - <b>Float</b> A double-precision floating point number data type.
+ * - <b>Currency</b> A decimal data type that can contain currency symbols.
* - <b>Date</b> A date data type.
* - <b>String</b> A string data type.
* For <b>Date</b> type, the property {@link setDateFormat DateFormat}
@@ -45,13 +46,12 @@ class TDataTypeValidator extends TBaseValidator }
/**
- * Sets the data type (Integer, Float, Date, String) that the values being
- * compared are converted to before the comparison is made.
+ * Sets the data type (Integer, Float, Currency, Date, String) that the values being compared are converted to before the comparison is made.
* @param string the data type
*/
public function setDataType($value)
{
- $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','String'),'String');
+ $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','Currency','String'),'String');
}
/**
@@ -85,6 +85,8 @@ class TDataTypeValidator extends TBaseValidator return preg_match('/^[-+]?[0-9]+$/',trim($value));
case 'Float':
return preg_match('/^[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?$/',trim($value));
+ case 'Currency':
+ return preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?$/',trim($value));
case 'Date':
$dateFormat = $this->getDateFormat();
if(strlen($dateFormat))
diff --git a/framework/Web/UI/WebControls/TDatePicker.php b/framework/Web/UI/WebControls/TDatePicker.php index 02386515..c6a2345b 100644 --- a/framework/Web/UI/WebControls/TDatePicker.php +++ b/framework/Web/UI/WebControls/TDatePicker.php @@ -245,16 +245,17 @@ class TDatePicker extends TTextBox /**
* @return integer current selected date from the date picker as timestamp.
*/
- public function getTimeStamp()
+ public function getDate()
{
- return $this->getTimeStampFromText();
+ $date = $this->getDateFromText();
+ return $date[0];
}
/**
* Sets the date for the date picker using timestamp.
* @param integer time stamp for the date picker
*/
- public function setTimeStamp($value)
+ public function setDate($value)
{
$date = TPropertyValue::ensureInteger($value);
$formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',
@@ -263,34 +264,6 @@ class TDatePicker extends TTextBox }
/**
- * @return string the date string.
- */
- public function getDate()
- {
- return $this->getText();
- }
-
- /**
- * @param string date string
- */
- public function setDate($value)
- {
- $this->setText($value);
- }
-
- /**
- * Returns the value to be validated.
- * This methid is required by IValidatable interface.
- * @return integer the value of the property to be validated.
- */
- public function getValidationPropertyValue()
- {
- if($this->getText() === '')
- return '';
- return $this->getTimeStamp();
- }
-
- /**
* Publish the date picker Css asset files.
*/
public function onPreRender($param)
@@ -423,7 +396,6 @@ class TDatePicker extends TTextBox $date = $this->getLocalizedCalendarInfo();
$options['MonthNames'] = TJavaScript::encode($date->getMonthNames(),false);
- $options['AbbreviatedMonthNames'] = TJavaScript::encode($date->getAbbreviatedMonthNames(),false);
$options['ShortWeekDayNames'] = TJavaScript::encode($date->getAbbreviatedDayNames(),false);
return $options;
@@ -467,8 +439,7 @@ class TDatePicker extends TTextBox $writer->addAttribute('class', $class);
$writer->renderBeginTag('span');
- $date = @getdate($this->getTimeStampFromText());
-
+ $date = $this->getDateFromText();
$this->renderCalendarSelections($writer, $date);
//render a hidden input field
@@ -510,9 +481,9 @@ class TDatePicker extends TTextBox /**
* Gets the date from the text input using TSimpleDateFormatter
- * @return integer current selected date timestamp
+ * @return array current selected date
*/
- protected function getTimeStampFromText()
+ protected function getDateFromText()
{
$pattern = $this->getDateFormat();
$pattern = str_replace(array('MMMM', 'MMM'), array('MM','MM'), $pattern);
@@ -588,7 +559,7 @@ class TDatePicker extends TTextBox case 'MMM':
case 'MM': return $info->getAbbreviatedMonthNames();
case 'M':
- $array = array(); for($i=1;$i<=12;$i++) $array[$i-1] = $i;
+ $array = array(); for($i=1;$i<=12;$i++) $array[$i] = $i;
return $array;
default : return $info->getMonthNames();
}
diff --git a/framework/Web/UI/WebControls/THtmlArea.php b/framework/Web/UI/WebControls/THtmlArea.php index 8e5fcd16..7e47d638 100644 --- a/framework/Web/UI/WebControls/THtmlArea.php +++ b/framework/Web/UI/WebControls/THtmlArea.php @@ -315,7 +315,7 @@ class THtmlArea extends TTextBox //default the variant to "en"
if(count($variants) == 0)
{
- if(empty($culture))
+ if($empty($culture))
return 'en';
$variants[] = strtolower($culture);
}
diff --git a/framework/Web/UI/WebControls/TListControlValidator.php b/framework/Web/UI/WebControls/TListControlValidator.php deleted file mode 100644 index 9264e891..00000000 --- a/framework/Web/UI/WebControls/TListControlValidator.php +++ /dev/null @@ -1,214 +0,0 @@ -<?php
-
-/**
- * TListControlValidator class file
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright © 2005 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Using TBaseValidator class
- */
-Prado::using('System.Web.UI.WebControls.TBaseValidator');
-
-/**
- * TListControlValidator class.
- *
- * TListControlValidator checks the number of selection and their values
- * for a <b>TListControl that allows multiple selection</b>.
- *
- * You can specify the minimum or maximum (or both) number of selections
- * required using the {@link setMinSelection MinSelection} and
- * {@link setMaxSelection MaxSelection} properties, respectively. In addition,
- * you can specify a comma separated list of required selected values via the
- * {@link setRequiredSelections RequiredSelections} property.
- *
- * Examples
- * - At least two selections
- * <code>
- * <com:TListBox ID="listbox" SelectionMode="Multiple">
- * <com:TListItem Text="item1" Value="value1" />
- * <com:TListItem Text="item2" Value="value2" />
- * <com:TListItem Text="item3" Value="value3" />
- * </com:TListBox>
- *
- * <com:TRequiredListValidator
- * ControlToValidate="listbox"
- * MinSelection="2"
- * ErrorMessage="Please select at least 2" />
- * </code>
- * - "value1" must be selected <b>and</b> at least 1 other
- * <code>
- * <com:TCheckBoxList ID="checkboxes">
- * <com:TListItem Text="item1" Value="value1" />
- * <com:TListItem Text="item2" Value="value2" />
- * <com:TListItem Text="item3" Value="value3" />
- * </com:TCheckBoxList>
- *
- * <com:TRequiredListValidator
- * ControlToValidate="checkboxes"
- * RequiredSelections="value1"
- * MinSelection="2"
- * ErrorMessage="Please select 'item1' and at least 1 other" />
- * </code>
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TListControlValidator extends TBaseValidator
-{
- /**
- * @return int min number of selections
- */
- function getMinSelection()
- {
- return $this->getViewState('MinSelection','');
- }
-
- /**
- * @param int minimum number of selections.
- */
- function setMinSelection($value)
- {
- $this->setViewState('MinSelection',$value,'');
- }
-
- /**
- * @return int max number of selections
- */
- function getMaxSelection()
- {
- return $this->getViewState('MaxSelection','');
- }
-
- /**
- * @param int max number of selections.
- */
- function setMaxSelection($value)
- {
- $this->setViewState('MaxSelection',$value,'');
- }
-
- /**
- * Get a comma separated list of required selected values.
- * @return string comma separated list of required values.
- */
- function getRequiredSelections()
- {
- return $this->getViewState('RequiredSelections','');
- }
-
- /**
- * Set the list of required values, using aa comma separated list.
- * @param string comma separated list of required values.
- */
- function setRequiredSelections($value)
- {
- $this->setViewState('RequiredSelections',$value,'');
- }
-
- /**
- * This method overrides the parent's implementation.
- * The validation succeeds if the input component changes its data
- * from the InitialValue or the input component is not given.
- * @return boolean whether the validation succeeds
- */
- public function evaluateIsValid()
- {
- $control=$this->getValidationTarget();
-
- $exists = true;
- list($count, $values) = $this->getSelection($control);
- $required = $this->getRequiredValues();
-
- //if required, check the values
- if(!empty($required))
- {
- if(count($values) < count($required) )
- return false;
- foreach($required as $require)
- $exists = $exists && in_array($require, $values);
- }
-
- $min = $this->getMinSelection();
- $max = $this->getMaxSelection();
-
- if($min !== '' && $max !=- '')
- return $exists && $count >= intval($min) && $count <= intval($max);
- else if($min === '' && $max !== '')
- return $exists && $count <= intval($max);
- else if($min !== '' && $max === '')
- return $exists && $count >= intval($min);
- }
-
- /**
- * @param TListControl control to validate
- * @return array number of selected values and its values.
- */
- protected function getSelection($control)
- {
- $count = 0;
- $values = array();
-
- //get the data
- foreach($control->getItems() as $item)
- {
- if($item->getSelected())
- {
- $count++;
- $values[] = $item->getValue();
- }
- }
- return array($count, $values);
- }
-
- /**
- * @return array list of required values.
- */
- protected function getRequiredValues()
- {
- $required = array();
- $string = $this->getRequiredSelections();
- if(!empty($string))
- $required = preg_split('/,\s*/', $string);
- return $required;
- }
-
- /**
- * Returns an array of javascript validator options.
- * @return array javascript validator options.
- */
- protected function getClientScriptOptions()
- {
- $options = parent::getClientScriptOptions();
- $control = $this->getValidationTarget();
-
- if(!$control instanceof TListControl)
- {
- throw new TConfigurationException(
- 'tlistcontrolvalidator_invalid_control',
- $this->getID(),$this->getControlToValidate(), get_class($control));
- }
-
- $min = $this->getMinSelection();
- $max = $this->getMaxSelection();
- if($min !== '')
- $options['Min']= intval($min);
- if($max !== '')
- $options['Max']= intval($max);
- $required = $this->getRequiredSelections();
- if(strlen($required) > 0)
- $options['Required']= $required;
- $options['TotalItems'] = $control->getItemCount();
-
- return $options;
- }
-}
-?>
\ No newline at end of file diff --git a/framework/Web/UI/WebControls/TRadioButton.php b/framework/Web/UI/WebControls/TRadioButton.php index fd13e88c..9a523b55 100644 --- a/framework/Web/UI/WebControls/TRadioButton.php +++ b/framework/Web/UI/WebControls/TRadioButton.php @@ -101,14 +101,14 @@ class TRadioButton extends TCheckBox $this->setViewState('GroupName',$value,'');
}
-/* protected function getValueAttribute()
+ protected function getValueAttribute()
{
if(($value=parent::getValueAttribute())==='')
return $this->getUniqueID();
else
return $value;
}
-*/
+
/**
* @return string the name used to fetch radiobutton post data
*/
@@ -146,8 +146,7 @@ class TRadioButton extends TCheckBox $writer->addAttribute('id',$clientID);
$writer->addAttribute('type','radio');
$writer->addAttribute('name',$this->getUniqueGroupName());
- if(($value = $this->getValueAttribute()) !== '')
- $writer->addAttribute('value',$value);
+ $writer->addAttribute('value',$this->getValueAttribute());
if($this->getChecked())
$writer->addAttribute('checked','checked');
if(!$this->getEnabled(true))
diff --git a/framework/Web/UI/WebControls/TRangeValidator.php b/framework/Web/UI/WebControls/TRangeValidator.php index b7387522..56cc16bc 100644 --- a/framework/Web/UI/WebControls/TRangeValidator.php +++ b/framework/Web/UI/WebControls/TRangeValidator.php @@ -29,6 +29,7 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * operation is performed. The following value types are supported:
* - <b>Integer</b> A 32-bit signed integer data type.
* - <b>Float</b> A double-precision floating point number data type.
+ * - <b>Currency</b> A decimal data type that can contain currency symbols.
* - <b>Date</b> A date data type. The date format can be specified by
* setting {@link setDateFormat DateFormat} property, which must be recognizable
* by {@link TSimpleDateFormatter}. If the property is not set,
@@ -86,13 +87,13 @@ class TRangeValidator extends TBaseValidator }
/**
- * Sets the data type (Integer, Float, Date, String) that the values being
- * compared are converted to before the comparison is made.
+ * Sets the data type (Integer, Float, Currency, Date, String) that the values
+ * being compared are converted to before the comparison is made.
* @param string the data type
*/
public function setDataType($value)
{
- $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','String'),'String');
+ $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','Currency','String'),'String');
}
/**
@@ -130,6 +131,8 @@ class TRangeValidator extends TBaseValidator return $this->isValidInteger($value);
case 'Float':
return $this->isValidFloat($value);
+ case 'Currency':
+ return $this->isValidCurrency($value);
case 'Date':
return $this->isValidDate($value);
default:
@@ -176,6 +179,38 @@ class TRangeValidator extends TBaseValidator }
/**
+ * Determine if the value is a valid currency range,
+ * @param string currency value
+ * @return boolean true if within range.
+ */
+ protected function isValidCurrency($value)
+ {
+ $minValue=$this->getMinValue();
+ $maxValue=$this->getMaxValue();
+
+ $valid=true;
+ $value = $this->getCurrencyValue($value);
+ if($minValue!=='')
+ $valid=$valid && ($value>= $this->getCurrencyValue($minValue));
+ if($maxValue!=='')
+ $valid=$valid && ($value<= $this->getCurrencyValue($minValue));
+ return $valid;
+ }
+
+ /**
+ * Parse the string into a currency value, return the float value of the currency.
+ * @param string currency as string
+ * @return float currency value.
+ */
+ protected function getCurrencyValue($value)
+ {
+ if(preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?/',$value,$matches))
+ return floatval($matches[0]);
+ else
+ return 0.0;
+ }
+
+ /**
* Determine if the date is within the specified range.
* Uses pradoParseDate and strtotime to get the date from string.
* @param string date as string to validate
diff --git a/framework/Web/UI/WebControls/TRequiredFieldValidator.php b/framework/Web/UI/WebControls/TRequiredFieldValidator.php index 04e333eb..ddbb12c8 100644 --- a/framework/Web/UI/WebControls/TRequiredFieldValidator.php +++ b/framework/Web/UI/WebControls/TRequiredFieldValidator.php @@ -21,9 +21,6 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * TRequiredFieldValidator makes the associated input control a required field.
* The input control fails validation if its value does not change from
* the {@link setInitialValue InitialValue} property upon losing focus.
- *
- * Validation will also succeed if input is of TListControl type and the number
- * of selected values different from the initial value is greater than zero.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
@@ -56,32 +53,12 @@ class TRequiredFieldValidator extends TBaseValidator * This method overrides the parent's implementation.
* The validation succeeds if the input component changes its data
* from the {@link getInitialValue InitialValue} or the input control is not given.
- *
- * Validation will also succeed if input is of TListControl type and the
- * number of selected values different from the initial value is greater
- * than zero.
- *
* @return boolean whether the validation succeeds
*/
protected function evaluateIsValid()
{
- $control = $this->getValidationTarget();
- $initial = trim($this->getInitialValue());
- if($control instanceof TListControl)
- {
- $count = 0;
- foreach($control->getItems() as $item)
- {
- if($item->getSelected() && $item->getValue() != $initial)
- $count++;
- }
- return $count > 0;
- }
- else
- {
- $value=$this->getValidationValue($control);
- return trim($value)!==$initial || (is_bool($value) && $value);
- }
+ $value=$this->getValidationValue($this->getValidationTarget());
+ return trim($value)!==trim($this->getInitialValue()) || (is_bool($value) && $value);
}
/**
@@ -92,9 +69,6 @@ class TRequiredFieldValidator extends TBaseValidator {
$options = parent::getClientScriptOptions();
$options['InitialValue']=$this->getInitialValue();
- $control = $this->getValidationTarget();
- if($control instanceof TListControl)
- $options['TotalItems'] = $control->getItemCount();
return $options;
}
}
diff --git a/tests/FunctionalTests/features/protected/pages/DatePicker.page b/tests/FunctionalTests/features/protected/pages/DatePicker.page index 261a6994..4347f748 100644 --- a/tests/FunctionalTests/features/protected/pages/DatePicker.page +++ b/tests/FunctionalTests/features/protected/pages/DatePicker.page @@ -12,47 +12,45 @@ </tr>
<tr>
- <td class="samplenote">Button Mode, pre-selected date</td>
+ <td class="samplenote">Button Mode</td>
<td class="sampleaction">
- <com:TDatePicker Mode="Button" Date="20-10-2005"/>
+ <com:TDatePicker Mode="Button" />
</td>
</tr>
<tr>
<td class="samplenote">InputMode="DropDownList", custom DateFormat</td>
<td class="sampleaction">
- <com:TDatePicker DateFormat="yyyy/MMM" InputMode="DropDownList"/>
+ <com:TDatePicker DateFormat="yyyy/MMMM" InputMode="DropDownList"/>
</td>
</tr>
<tr>
<td class="samplenote">InputMode="DropDownList", custom DateFormat, Culture</td>
<td class="sampleaction">
- <com:TDatePicker DateFormat="MMM/yyyy" Culture="fr" InputMode="DropDownList"/>
+ <com:TDatePicker DateFormat="MM/yyyy" Culture="fr" InputMode="DropDownList"/>
</td>
</tr>
<tr>
- <td class="samplenote">Custom DateFormat, culture, ImageButton mode, pre-selected date</td>
+ <td class="samplenote">Custom DateFormat, culture, ImageButton mode</td>
<td class="sampleaction">
- <com:TDatePicker Mode="ImageButton" Culture="zh_CN"
- DateFormat="日期:yyyy年M月d日"
- Timestamp=<%= @strtotime("-1 year") %>/>
+ <com:TDatePicker Mode="ImageButton" Culture="zh_CN" DateFormat="日期:yyyy年M月d日"/>
</td>
</tr>
<tr>
<td class="samplenote">Custom DateFormat, DropDownList, pre-selected date set in as Text</td>
<td class="sampleaction">
- <com:TDatePicker DateFormat="yyyy/MMMM/dd" Date="2005/05/15" InputMode="DropDownList"/>
+ <com:TDatePicker DateFormat="yyyy/MMMM/dd" Text="2005/05/15" InputMode="DropDownList"/>
</td>
</tr>
<tr>
<td class="samplenote">DropDownList, pre-selected date as integer</td>
<td class="sampleaction">
- <com:TDatePicker InputMode="DropDownList" Timestamp=<%= @strtotime("-1 month") %>/>
+ <com:TDatePicker InputMode="DropDownList" Date=<%= @strtotime("-1 month") %>/>
</td>
</tr>
diff --git a/tests/FunctionalTests/validators/protected/pages/DatePicker.page b/tests/FunctionalTests/validators/protected/pages/DatePicker.page deleted file mode 100644 index fdbbbeb1..00000000 --- a/tests/FunctionalTests/validators/protected/pages/DatePicker.page +++ /dev/null @@ -1,64 +0,0 @@ -<com:TContent ID="Content">
- <h1>Date Picker validation Test</h1>
- <com:TDatePicker ID="picker1" DateFormat="d/M/yyyy"/>
- <com:TRequiredFieldValidator
- ID="validator1"
- ControlToValidate="picker1"
- ErrorMessage="Please enter a date (d/M/yyyy)" />
- <com:TRangeValidator
- ID="validator2"
- ControlToValidate="picker1"
- DataType="Date"
- DateFormat="d/M/yyyy"
- ErrorMessage="Please enter a date greater than 17/4/2007"
- MinValue="17/4/2007" />
-
- <hr />
- <com:TDatePicker ID="picker2" DateFormat="d/M/yyyy" InputMode="DropDownList" />
-
- <com:TRangeValidator
- ID="validator4"
- ControlToValidate="picker2"
- DataType="Date"
- DateFormat="d/M/yyyy"
- ErrorMessage="Please enter a date between 9/9/2006 and 8/10/2006"
- MinValue="9/9/2006"
- MaxValue="8/10/2006" />
-
- <hr />
- Date 1:
- <com:TDatePicker ID="picker3" DateFormat="d/M/yyyy" />
- <com:TRequiredFieldValidator
- ID="validator5"
- ControlToValidate="picker3"
- ErrorMessage="Please enter a date (d/M/yyyy)" />
- <br />
- Date 2:
- <com:TDatePicker ID="picker4" DateFormat="d/M/yyyy" />
- <com:TCompareValidator
- ID="validator6"
- ControlToValidate="picker4"
- ControlToCompare="picker3"
- Operator="GreaterThan"
- DateFormat="d/M/yyyy"
- DataType="Date"
- ErrorMessage="Date 2 must be greater than Date 1" />
-
- <hr />
-
- Date 3:
- <com:TDatePicker ID="picker5" DateFormat="d/M/yyyy" InputMode="DropDownList" />
- <br />
- Date 4:
- <com:TDatePicker ID="picker6" DateFormat="d/M/yyyy" InputMode="DropDownList" />
- <com:TCompareValidator
- ID="validator8"
- ControlToValidate="picker6"
- ControlToCompare="picker5"
- Operator="GreaterThan"
- DateFormat="d/M/yyyy"
- DataType="Date"
- ErrorMessage="Date 2 must be greater than Date 1" />
- <com:TButton ID="submit1" Text="Submit" />
-
-</com:TContent>
\ No newline at end of file diff --git a/tests/FunctionalTests/validators/protected/pages/Layout.tpl b/tests/FunctionalTests/validators/protected/pages/Layout.tpl index 25dbea09..224481e1 100644 --- a/tests/FunctionalTests/validators/protected/pages/Layout.tpl +++ b/tests/FunctionalTests/validators/protected/pages/Layout.tpl @@ -21,11 +21,6 @@ margin-top: 2em;
display: block;
}
- .required
- {
- border: 1px solid red;
- background-color: pink;
- }
/*]]>*/
</style>
</com:THead>
diff --git a/tests/FunctionalTests/validators/protected/pages/ListControl.page b/tests/FunctionalTests/validators/protected/pages/ListControl.page deleted file mode 100644 index 1429e184..00000000 --- a/tests/FunctionalTests/validators/protected/pages/ListControl.page +++ /dev/null @@ -1,58 +0,0 @@ -<com:TContent ID="Content">
- <h1>List Control Required Field Validation Test</h1>
- <com:TCheckBoxList ID="list1">
- <com:TListItem Text="Select a color below" Value="" />
- <com:TListItem Text="Red" />
- <com:TListItem Text="Blue" />
- <com:TListItem Text="Green" />
- </com:TCheckBoxList>
-
- <com:TRequiredFieldValidator ID="validator1"
- ControlToValidate="list1"
- InitialValue="Select a color below"
- ErrorMessage="*" />
-
- <hr />
-
- <com:TDropDownList ID="list2">
- <com:TListItem Text="--- Select a color ---" />
- <com:TListItem Text="Red" />
- <com:TListItem Text="Blue" />
- <com:TListItem Text="Green" />
- </com:TDropDownList>
-
- <com:TRequiredFieldValidator ID="validator2"
- ControlToValidate="list2"
- InitialValue="--- Select a color ---"
- ErrorMessage="*" />
-
- <hr />
-
- <com:TListBox ID="list3">
- <com:TListItem Text="Don't select this one" />
- <com:TListItem Text="Red" />
- <com:TListItem Text="Blue" />
- <com:TListItem Text="Green" />
- </com:TListBox>
-
- <com:TRequiredFieldValidator ID="validator3"
- ControlToValidate="list3"
- InitialValue="Don't select this one"
- ErrorMessage="*" />
-
- <hr />
-
- <com:TRadioButtonList ID="list4">
- <com:TListItem Text="Select something else" />
- <com:TListItem Text="Red" />
- <com:TListItem Text="Blue" />
- <com:TListItem Text="Green" />
- </com:TRadioButtonList>
-
- <com:TRequiredFieldValidator ID="validator4"
- ControlToValidate="list4"
- InitialValue="Select something else"
- ErrorMessage="*" />
-
- <com:TButton ID="submit1" Text="Submit!" />
-</com:TContent>
\ No newline at end of file diff --git a/tests/FunctionalTests/validators/protected/pages/RequiredListValidator.page b/tests/FunctionalTests/validators/protected/pages/RequiredListValidator.page index 665d71b7..9bbd9d5a 100644 --- a/tests/FunctionalTests/validators/protected/pages/RequiredListValidator.page +++ b/tests/FunctionalTests/validators/protected/pages/RequiredListValidator.page @@ -8,7 +8,7 @@ <com:TListItem Value="3" Text="Three" />
<com:TListItem Value="4" Text="Four" />
</com:TCheckBoxList>
- <com:TListControlValidator
+ <com:TRequiredListValidator
ID="validator1"
ControlToValidate="list1"
ErrorMessage="Must select at least 1 and no more than 3"
@@ -18,31 +18,30 @@ </div>
<div>
- <com:TListBox ID="list2" SelectionMode="Multiple" Rows="5" Style="width:10em;">
+ <com:TListBox ID="list2" SelectionMode="Multiple" Rows="5" Style="width:10em">
<com:TListItem Value="1" Text="One" />
<com:TListItem Value="2" Text="Two" />
<com:TListItem Value="3" Text="Three" />
<com:TListItem Value="4" Text="Four" />
<com:TListItem Value="5" Text="Five" />
</com:TListBox>
- <com:TListControlValidator
+ <com:TRequiredListValidator
ID="validator2"
ControlToValidate="list2"
ErrorMessage='Must select at least 2 and no more than 3 and value "two"'
MinSelection="2"
MaxSelection="3"
- ControlCssClass="required"
RequiredSelections="2" />
</div>
<div class="lista">
- <com:TRadioButtonList ID="list3">
+ <com:TCheckBoxList ID="list3">
<com:TListItem Value="1" Text="One" />
<com:TListItem Value="2" Text="Two" />
<com:TListItem Value="3" Text="Three" />
<com:TListItem Value="4" Text="Four" />
- </com:TRadioButtonList>
- <com:TListControlValidator
+ </com:TCheckBoxList>
+ <com:TRequiredListValidator
ID="validator3"
ControlToValidate="list3"
ErrorMessage="Must select at least 1"
diff --git a/tests/FunctionalTests/validators/tests/DatePickerTestCase.php b/tests/FunctionalTests/validators/tests/DatePickerTestCase.php deleted file mode 100644 index 75894dc0..00000000 --- a/tests/FunctionalTests/validators/tests/DatePickerTestCase.php +++ /dev/null @@ -1,63 +0,0 @@ -<?php
-
-class DatePickerTestCase extends SeleniumTestCase
-{
- function test()
- {
- $base = "ctl0_Content_";
- $this->open("validators/index.php?page=DatePicker", "");
- $this->verifyTextPresent("Date Picker validation Test", "");
- $this->assertNotVisible("{$base}validator1", "");
- $this->assertNotVisible("{$base}validator2", "");
- $this->assertNotVisible("{$base}validator4", "");
- $this->assertNotVisible("{$base}validator5", "");
- $this->assertNotVisible("{$base}validator6", "");
- $this->assertNotVisible("{$base}validator8", "");
-
- $this->click("{$base}submit1");
- $this->assertVisible("{$base}validator1", "");
- $this->assertNotVisible("{$base}validator2", "");
- $this->assertVisible("{$base}validator4", "");
- $this->assertVisible("{$base}validator5", "");
- $this->assertNotVisible("{$base}validator6", "");
- $this->assertVisible("{$base}validator8", "");
-
- $this->click("{$base}submit1");
- $this->type("{$base}picker1", "13/4/2006");
- $this->select("{$base}picker2_month", "label=9");
- $this->select("{$base}picker2_day", "label=10");
- $this->type("{$base}picker3", "14/4/2006");
- $this->type("{$base}picker4", "7/4/2006");
- $this->select("{$base}picker5_day", "label=6");
- $this->select("{$base}picker5_month", "label=3");
- $this->select("{$base}picker5_year", "label=2007");
- $this->select("{$base}picker6_month", "label=3");
- $this->select("{$base}picker6_year", "label=2007");
- $this->select("{$base}picker6_day", "label=5");
-
- $this->click("{$base}submit1");
-
- $this->assertNotVisible("{$base}validator1", "");
- $this->assertVisible("{$base}validator2", "");
- $this->assertNotVisible("{$base}validator4", "");
- $this->assertNotVisible("{$base}validator5", "");
- $this->assertVisible("{$base}validator6", "");
- $this->assertVisible("{$base}validator8", "");
-
- $this->type("{$base}picker1", "20/4/2007");
- $this->type("{$base}picker4", "29/4/2006");
- $this->select("{$base}picker6_day", "label=10");
-
- $this->clickAndWait("{$base}submit1");
-
- $this->assertNotVisible("{$base}validator1", "");
- $this->assertNotVisible("{$base}validator2", "");
- $this->assertNotVisible("{$base}validator4", "");
- $this->assertNotVisible("{$base}validator5", "");
- $this->assertNotVisible("{$base}validator6", "");
- $this->assertNotVisible("{$base}validator8", "");
- }
-
-}
-
-?>
\ No newline at end of file diff --git a/tests/FunctionalTests/validators/tests/ListControlTestCase.php b/tests/FunctionalTests/validators/tests/ListControlTestCase.php deleted file mode 100644 index 6c0c73e7..00000000 --- a/tests/FunctionalTests/validators/tests/ListControlTestCase.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php
-/*
- * Created on 24/04/2006
- */
-
-class ListControlTestCase extends SeleniumTestCase
-{
- function test()
- {
- $base = "ctl0_Content_";
- $this->open("validators/index.php?page=ListControl", "");
- $this->verifyTextPresent("List Control Required Field Validation Test", "");
- $this->click("//input[@type='submit' and @value='Submit!']", "");
-
- $this->assertVisible("{$base}validator1");
- $this->assertVisible("{$base}validator2");
- $this->assertVisible("{$base}validator3");
- $this->assertVisible("{$base}validator4");
-
- $this->click("//input[@id='{$base}list1_1' and @value='Red']", "");
- $this->select("{$base}list2", "label=Red");
- $this->select("{$base}list3", "label=Blue");
- $this->click("{$base}list4_3", "");
- $this->clickAndWait("//input[@type='submit' and @value='Submit!']", "");
-
- $this->assertNotVisible("{$base}validator1");
- $this->assertNotVisible("{$base}validator2");
- $this->assertNotVisible("{$base}validator3");
- $this->assertNotVisible("{$base}validator4");
-
- $this->select("{$base}list3", "label=Don't select this one");
- $this->click("{$base}list4_0");
- $this->select("{$base}list2", "label=--- Select a color ---");
- $this->click("//input[@type='submit' and @value='Submit!']", "");
- $this->click("//input[@id='{$base}list1_1' and @value='Red']", "");
- $this->click("//input[@id='{$base}list1_0' and @value='Select a color below']", "");
- $this->click("//input[@type='submit' and @value='Submit!']", "");
-
- $this->assertVisible("{$base}validator1");
- $this->assertVisible("{$base}validator2");
- $this->assertVisible("{$base}validator3");
- $this->assertVisible("{$base}validator4");
-
- }
-
-}
-
-?>
diff --git a/tests/FunctionalTests/validators/tests/RequiredListTestCase.php b/tests/FunctionalTests/validators/tests/RequiredListTestCase.php index ad299dc5..1eab60d4 100644 --- a/tests/FunctionalTests/validators/tests/RequiredListTestCase.php +++ b/tests/FunctionalTests/validators/tests/RequiredListTestCase.php @@ -5,36 +5,35 @@ class RequiredListTestCase extends SeleniumTestCase function test()
{
- $base = "ctl0_Content_";
$this->open("validators/index.php?page=RequiredListValidator");
$this->assertLocation("index.php?page=RequiredListValidator");
- $this->click("{$base}submit1");
- $this->assertVisible("{$base}validator1");
- $this->assertVisible("{$base}validator2");
- $this->assertVisible("{$base}validator3");
- $this->click("{$base}list1_0");
- $this->select("{$base}list2", "label=One");
- $this->select("{$base}list2", "label=Two");
- $this->click("{$base}list3_3");
- $this->clickAndWait("{$base}submit1");
- $this->assertNotVisible("{$base}validator1");
- $this->assertNotVisible("{$base}validator2");
- $this->assertNotVisible("{$base}validator3");
- $this->click("{$base}list1_1");
- $this->click("{$base}list1_2");
- $this->click("{$base}list1_3");
- $this->select("{$base}list2", "label=Two");
- $this->click("{$base}list1_3");
- $this->click("{$base}submit1");
- $this->assertNotVisible("{$base}validator1");
- $this->assertNotVisible("{$base}validator2");
- $this->assertNotVisible("{$base}validator3");
- $this->click("{$base}list3_3");
- $this->click("{$base}submit1");
+ $this->click("submit1");
+ $this->assertVisible("validator1");
+ $this->assertVisible("validator2");
+ $this->assertVisible("validator3");
+ $this->click("list1:0");
+ $this->select("list2", "label=One");
+ $this->select("list2", "label=Two");
+ $this->click("list3:3");
+ $this->clickAndWait("submit1");
+ $this->assertNotVisible("validator1");
+ $this->assertNotVisible("validator2");
+ $this->assertNotVisible("validator3");
+ $this->click("list1:1");
+ $this->click("list1:2");
+ $this->click("list1:3");
+ $this->select("list2", "label=Two");
+ $this->click("list1:3");
+ $this->click("submit1");
+ $this->assertNotVisible("validator1");
+ $this->assertNotVisible("validator2");
+ $this->assertNotVisible("validator3");
+ $this->click("list3:3");
+ $this->click("submit1");
$this->pause(200);
- $this->assertNotVisible("{$base}validator1");
- $this->assertNotVisible("{$base}validator2");
- $this->assertNotVisible("{$base}validator3");
+ $this->assertNotVisible("validator1");
+ $this->assertNotVisible("validator2");
+ $this->assertVisible("validator3");
}
}
|