This is an automated email from the ASF dual-hosted git repository.
piotrz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push:
new 2766910 Jewel: Add CreditCardValidator ported from Flex
2766910 is described below
commit 2766910c35a559afbd7b87ce9fc5a21f8776d977
Author: Piotr Zarzycki <[email protected]>
AuthorDate: Tue Jul 16 16:47:32 2019 +0200
Jewel: Add CreditCardValidator ported from Flex
- Add example of usage CreditCardValidator
---
examples/build.xml | 1 +
.../CreditCardValidatorExample.as3proj | 118 ++++
.../CreditCardValidatorExample/asconfig.json | 31 +
.../royale/CreditCardValidatorExample/build.xml | 64 ++
examples/royale/CreditCardValidatorExample/pom.xml | 70 +++
.../src/main/resources/app-styles.css | 23 +
.../resources/jewel-example-index-template.html | 30 +
.../main/royale/CreditCardValidatorExample.mxml | 34 +
.../src/main/royale/MainContent.mxml | 74 +++
.../Jewel/src/main/resources/jewel-manifest.xml | 3 +-
.../projects/Jewel/src/main/royale/JewelClasses.as | 2 +
.../jewel/beads/validators/CreditCardValidator.as | 687 +++++++++++++++++++++
.../validators/CreditCardValidatorCardType.as | 91 +++
13 files changed, 1227 insertions(+), 1 deletion(-)
diff --git a/examples/build.xml b/examples/build.xml
index ea1de10..814e74c 100644
--- a/examples/build.xml
+++ b/examples/build.xml
@@ -94,6 +94,7 @@
<ant dir="${basedir}/royale/Flex2Royale"/>
<ant dir="${basedir}/royale/JSON2ASVO"/>
<ant dir="${basedir}/royale/TourDeJewel"/>
+ <ant dir="${basedir}/royale/CreditCardValidatorExample"/>
<ant dir="${basedir}/royale/RoyaleTeamPage_MDL"/>
<ant dir="${basedir}/royale/RoyaleWebsite"/>
<ant dir="${basedir}/royale/RoyaleWebsiteStatsViewer"/>
diff --git
a/examples/royale/CreditCardValidatorExample/CreditCardValidatorExample.as3proj
b/examples/royale/CreditCardValidatorExample/CreditCardValidatorExample.as3proj
new file mode 100644
index 0000000..9451f6f
--- /dev/null
+++
b/examples/royale/CreditCardValidatorExample/CreditCardValidatorExample.as3proj
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<project>
+ <output>
+ <movie fps="60"/>
+ <movie height="600"/>
+ <movie disabled="False"/>
+ <movie background="#FFFFFF"/>
+ <movie path="bin-debug/CreditCardValidatorExample.swf"/>
+ <movie width="800"/>
+ <movie platform="Flash Player"/>
+ <movie version="11"/>
+ <movie input=""/>
+ </output>
+ <!-- Other classes to be compiled into your SWF -->
+ <jsOutput>
+ <option path=""/>
+ </jsOutput>
+ <classpaths>
+ <class path="src/main/royale"/>
+ </classpaths>
+ <moonshineResourcePaths>
+ <class path="src/main/resources"/>
+ </moonshineResourcePaths>
+ <moonshineNativeExtensionPaths></moonshineNativeExtensionPaths>
+ <build>
+ <option customSDK="D:\Work\royale_ide\royale_nightly_js"/>
+ <option loadConfig=""/>
+ <option linkReport=""/>
+ <option locale=""/>
+ <option staticLinkRSL="False"/>
+ <option showActionScriptWarnings="True"/>
+ <option compilerConstants=""/>
+ <option allowSourcePathOverlap="False"/>
+ <option showBindingWarnings="True"/>
+ <option optimize="False"/>
+ <option showDeprecationWarnings="True"/>
+ <option
additional="-theme=${royalelib}/themes/JewelTheme/src/main/resources/defaults.css
-html-template=src/main/resources/jewel-index-template.html"/>
+ <option strict="True"/>
+ <option antBuildPath="build/build.xml"/>
+ <option accessible="False"/>
+ <option useNetwork="True"/>
+ <option showUnusedTypeSelectorWarnings="True"/>
+ <option useResourceBundleMetadata="True"/>
+ <option benchmark="False"/>
+ <option warnings="True"/>
+ <option es="False"/>
+ <option verboseStackTraces="False"/>
+ </build>
+ <mavenBuild>
+ <option settingsFilePath=""/>
+ <option mavenBuildPath=""/>
+ <option commandLine=""/>
+ <actions>
+ <action actionName="Build" action="install"/>
+ <action actionName="Clean and package" action="clean package"/>
+ <action actionName="Clean" action="clean"/>
+ <action actionName="Clean and Build" action="clean install"/>
+ <action actionName="Exploded" action="war:exploded"/>
+ </actions>
+ </mavenBuild>
+ <includeLibraries></includeLibraries>
+ <libraryPaths></libraryPaths>
+ <externalLibraryPaths></externalLibraryPaths>
+ <rslPaths></rslPaths>
+ <intrinsics>
+ <element path="Library/AS3/frameworks/Flex4"/>
+ <element path="Library\AS3\frameworks\Flex4"/>
+ <element path="Library\AS3\frameworks\Flex4"/>
+ </intrinsics>
+ <library></library>
+ <compileTargets>
+ <compile path="src/main/royale/CreditCardValidatorExample.mxml"/>
+ </compileTargets>
+ <hiddenPaths></hiddenPaths>
+ <preBuildCommand>null</preBuildCommand>
+ <postBuildCommand alwaysRun="False">null</postBuildCommand>
+ <trustSVNCertificate>False</trustSVNCertificate>
+ <options>
+ <option isRoyale="True"/>
+ <option showHiddenPaths="False"/>
+ <option testMovie=""/>
+ <option testMovieCommand=""/>
+ <option isExportedToExistingSource="False"/>
+ <option defaultBuildTargets=""/>
+ <option visualEditorExportPath=""/>
+ <option isPrimeFacesVisualEditor="False"/>
+ </options>
+ <moonshineRunCustomization>
+ <option targetPlatform="2"/>
+ <option urlToLaunch=""/>
+ <option customUrlToLaunch=""/>
+ <option deviceSimulator="null"/>
+ <option projectType="2"/>
+ <option launchMethod="Simulator"/>
+ <deviceSimulator>null</deviceSimulator>
+ <certAndroid>null</certAndroid>
+ <certIos>null</certIos>
+ <certIosProvisioning>null</certIosProvisioning>
+ </moonshineRunCustomization>
+</project>
\ No newline at end of file
diff --git a/examples/royale/CreditCardValidatorExample/asconfig.json
b/examples/royale/CreditCardValidatorExample/asconfig.json
new file mode 100644
index 0000000..53c3507
--- /dev/null
+++ b/examples/royale/CreditCardValidatorExample/asconfig.json
@@ -0,0 +1,31 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+{
+ "config": "royale",
+ "compilerOptions": {
+ "debug": false,
+ "targets": ["JSRoyale"],
+ "source-map": true
+ },
+ "additionalOptions": "-remove-circulars
-js-output-optimization=skipAsCoercions",
+ "files":
+ [
+ "src/main/royale/CreditCardValidatorExample.mxml"
+ ]
+}
diff --git a/examples/royale/CreditCardValidatorExample/build.xml
b/examples/royale/CreditCardValidatorExample/build.xml
new file mode 100644
index 0000000..bc014cf
--- /dev/null
+++ b/examples/royale/CreditCardValidatorExample/build.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+
+
+<project name="CreditCardValidatorExample" default="main" basedir=".">
+ <property name="ROYALE_HOME" location="../../.."/>
+ <property name="example" value="App" />
+
+ <property file="${ROYALE_HOME}/env.properties"/>
+ <property environment="env"/>
+ <property file="${ROYALE_HOME}/build.properties"/>
+ <property name="ROYALE_HOME" value="${ROYALE_HOME}"/>
+
+ <include file="${basedir}/../../build_example.xml" />
+
+ <target name="main" depends="clean,build_example.compile"
description="Clean build of ${example}">
+ <mkdir dir="${basedir}/bin/js-debug/assets" />
+ <copy todir="${basedir}/bin/js-debug/assets" failonerror="false">
+ <fileset dir="${basedir}/src/main/resources/assets">
+ <include name="**" />
+ </fileset>
+ </copy>
+ <mkdir dir="${basedir}/bin/js-release/assets" />
+ <copy todir="${basedir}/bin/js-release/assets" failonerror="false">
+ <fileset dir="${basedir}/src/main/resources/assets">
+ <include name="**" />
+ </fileset>
+ </copy>
+ </target>
+
+ <target name="clean">
+ <delete dir="${basedir}/bin" failonerror="false" />
+ <delete dir="${basedir}/bin-debug" failonerror="false" />
+ <delete dir="${basedir}/bin-release" failonerror="false" />
+ <delete dir="${basedir}/target" failonerror="false" />
+ </target>
+
+ <target name="examine" depends="build_example.get.browser">
+ <property name="which" value="debug" />
+ <echo message="See various team members."/>
+ <exec executable="${browser}" dir="${basedir}/bin/js-${which}"
failonerror="true">
+ <arg value="${basedir}/bin/js-${which}/index.html"/>
+ </exec>
+ </target>
+
+
+</project>
diff --git a/examples/royale/CreditCardValidatorExample/pom.xml
b/examples/royale/CreditCardValidatorExample/pom.xml
new file mode 100644
index 0000000..cfef4dd
--- /dev/null
+++ b/examples/royale/CreditCardValidatorExample/pom.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.royale.examples</groupId>
+ <artifactId>examples-royale</artifactId>
+ <version>0.9.6-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>CreditCardValidatorExample</artifactId>
+ <version>0.9.6-SNAPSHOT</version>
+ <packaging>swf</packaging>
+
+ <name>Apache Royale: Examples: Royale: CreditCardValidatorExample</name>
+
+ <build>
+ <sourceDirectory>src/main/royale</sourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.royale.compiler</groupId>
+ <artifactId>royale-maven-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <mainClass>CreditCardValidatorExample.mxml</mainClass>
+ <targets>JSRoyale</targets>
+
<htmlTemplate>${basedir}/src/main/resources/jewel-example-index-template.html</htmlTemplate>
+ <debug>true</debug>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.royale.framework</groupId>
+ <artifactId>Jewel</artifactId>
+ <version>0.9.6-SNAPSHOT</version>
+ <type>swc</type>
+ <classifier>js</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.royale.framework</groupId>
+ <artifactId>JewelTheme</artifactId>
+ <version>0.9.6-SNAPSHOT</version>
+ <type>swc</type>
+ <scope>theme</scope>
+ <classifier>js</classifier>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git
a/examples/royale/CreditCardValidatorExample/src/main/resources/app-styles.css
b/examples/royale/CreditCardValidatorExample/src/main/resources/app-styles.css
new file mode 100644
index 0000000..927529e
--- /dev/null
+++
b/examples/royale/CreditCardValidatorExample/src/main/resources/app-styles.css
@@ -0,0 +1,23 @@
+/*
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+*/
+@namespace "http://www.w3.org/1999/xhtml";
+@namespace j "library://ns.apache.org/royale/jewel";
+
diff --git
a/examples/royale/CreditCardValidatorExample/src/main/resources/jewel-example-index-template.html
b/examples/royale/CreditCardValidatorExample/src/main/resources/jewel-example-index-template.html
new file mode 100644
index 0000000..764fe53
--- /dev/null
+++
b/examples/royale/CreditCardValidatorExample/src/main/resources/jewel-example-index-template.html
@@ -0,0 +1,30 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <meta name="Custom Template for injecting custom style CSS">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0,
maximum-scale=1.0, user-scalable=no" />
+ <link rel="stylesheet" type="text/css" href="${application}.css">
+ <link href="https://fonts.googleapis.com/css?family=Lato:400,700"
rel="stylesheet">
+${head}
+</head>
+<body>
+${body}
+</body>
+</html>
diff --git
a/examples/royale/CreditCardValidatorExample/src/main/royale/CreditCardValidatorExample.mxml
b/examples/royale/CreditCardValidatorExample/src/main/royale/CreditCardValidatorExample.mxml
new file mode 100644
index 0000000..ea97d3d
--- /dev/null
+++
b/examples/royale/CreditCardValidatorExample/src/main/royale/CreditCardValidatorExample.mxml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<j:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
+ xmlns:j="library://ns.apache.org/royale/jewel"
+ xmlns:js="library://ns.apache.org/royale/basic"
+ xmlns:local="*">
+
+ <fx:Style source="../resources/app-styles.css"/>
+
+ <j:valuesImpl>
+ <js:SimpleCSSValuesImpl />
+ </j:valuesImpl>
+
+ <j:initialView>
+ <local:MainContent />
+ </j:initialView>
+</j:Application>
diff --git
a/examples/royale/CreditCardValidatorExample/src/main/royale/MainContent.mxml
b/examples/royale/CreditCardValidatorExample/src/main/royale/MainContent.mxml
new file mode 100644
index 0000000..4074dcc
--- /dev/null
+++
b/examples/royale/CreditCardValidatorExample/src/main/royale/MainContent.mxml
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<j:ApplicationResponsiveView xmlns:fx="http://ns.adobe.com/mxml/2009"
+
xmlns:j="library://ns.apache.org/royale/jewel"
+
xmlns:js="library://ns.apache.org/royale/basic"
+
xmlns:html="library://ns.apache.org/royale/html"
+
initComplete="onInit(event)">
+ <fx:Script>
+ <![CDATA[
+ import org.apache.royale.collections.ArrayList;
+
+ private function onInit(event:Event):void
+ {
+ creditCardType.dataProvider = new ArrayList(["American
Express", "Discover", "MasterCard", "Visa"]);
+ }
+ ]]>
+</fx:Script>
+ <j:Form>
+ <j:beads>
+ <j:FormValidator trigger="{btnSubmit}"
triggerEvent="click"
+
requiredFieldError="There are invalid data, please check it."/>
+ </j:beads>
+ <j:FormItem label="Name" required="true">
+ <j:TextInput localId="userNameTextInput">
+ <j:beads>
+ <j:StringValidator required="4"
requiredFieldError="Requires more than 4 characters"/>
+ </j:beads>
+ </j:TextInput>
+ </j:FormItem>
+ <j:FormItem label="CC Type">
+ <j:DropDownList localId="creditCardType">
+ <j:beads>
+ <j:RequireSelection
requireSelection="true"/>
+ </j:beads>
+ </j:DropDownList>
+ </j:FormItem>
+ <j:FormItem label="CC Number" required="true">
+ <j:TextInput localId="creditCardNumber">
+ <j:beads>
+ <j:Restrict pattern="[^0-9]"/>
+ <j:CreditCardValidator
cardTypeSource="{creditCardType}" cardTypeProperty="selectedItem"/>
+ </j:beads>
+ </j:TextInput>
+ </j:FormItem>
+ <j:FormItem label="Expiration Date (MMYY)" required="true">
+ <j:TextInput localId="expiredOnTextInput">
+ <j:beads>
+ <j:Restrict pattern="[^0-9]"/>
+ <j:StringValidator required="4"
autoTrim="true" requiredFieldError="Requires 4 digits"/>
+ </j:beads>
+ </j:TextInput>
+ </j:FormItem>
+ <j:FormItem>
+ <j:Button localId="btnSubmit"/>
+ </j:FormItem>
+ </j:Form>
+</j:ApplicationResponsiveView>
diff --git a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
index 877f84a..296adc7 100644
--- a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
+++ b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
@@ -85,7 +85,8 @@
<component id="CheckBoxValidator"
class="org.apache.royale.jewel.beads.validators.CheckBoxValidator"/>
<component id="RadioButtonValidator"
class="org.apache.royale.jewel.beads.validators.RadioButtonValidator"/>
<component id="EmailValidator"
class="org.apache.royale.jewel.beads.validators.EmailValidator"/>
-
+ <component id="CreditCardValidator"
class="org.apache.royale.jewel.beads.validators.CreditCardValidator"/>
+
<component id="AssignTabContent"
class="org.apache.royale.jewel.beads.controls.tabbar.AssignTabContent"/>
<component id="HorizontalListScroll"
class="org.apache.royale.jewel.beads.controls.list.HorizontalListScroll"/>
diff --git a/frameworks/projects/Jewel/src/main/royale/JewelClasses.as
b/frameworks/projects/Jewel/src/main/royale/JewelClasses.as
index 1b25904..60b99b4 100644
--- a/frameworks/projects/Jewel/src/main/royale/JewelClasses.as
+++ b/frameworks/projects/Jewel/src/main/royale/JewelClasses.as
@@ -117,6 +117,8 @@ package
import org.apache.royale.jewel.beads.validators.removeErrorTip;
removeErrorTip;
+ import
org.apache.royale.jewel.supportClasses.validators.CreditCardValidatorCardType;
CreditCardValidatorCardType;
+
import dialogPolyfill; dialogPolyfill;
import hljs; hljs;
}
diff --git
a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/CreditCardValidator.as
b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/CreditCardValidator.as
new file mode 100644
index 0000000..36738f6
--- /dev/null
+++
b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/CreditCardValidator.as
@@ -0,0 +1,687 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.jewel.beads.validators
+{
+ import
org.apache.royale.jewel.supportClasses.validators.CreditCardValidatorCardType;
+
+ import org.apache.royale.core.IPopUpHost;
+ import org.apache.royale.core.IUIBase;
+ import org.apache.royale.events.Event;
+ import org.apache.royale.utils.UIUtils;
+
+ public class CreditCardValidator extends StringValidator
+ {
+ private static const DECIMAL_DIGITS:String = "0123456789";
+
+ private static const MISSING_CARD_TYPE:String = "The value
being validated doesn't contain a cardType property.";
+ private static const MISSING_CARD_NUMBER:String = "The value
being validated doesn't contain a cardNumber property.";
+ private static const CNS_ATTRIBUTE:String = "The
cardNumberSource attribute, '{0}', can not be of type String.";
+ private static const CTS_ATTRIBUTE:String = "The cardTypeSource
attribute, '{0}', can not be of type String.";
+
+ private static const INVALID_FORMAT_CHARS:String = "The
allowedFormatChars parameter is invalid. It cannot contain any digits.";
+
+
//--------------------------------------------------------------------------
+ //
+ // Constructor
+ //
+
//--------------------------------------------------------------------------
+
+ /**
+ * Constructor.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function CreditCardValidator()
+ {
+ super();
+ }
+
+ /**
+ * @private
+ * Storage for the allowedFormatChars property.
+ */
+ private var _allowedFormatChars:String = " -";
+
+ /**
+ * The set of formatting characters allowed in the
+ * <code>cardNumber</code> field.
+ *
+ * @default " -" (space and dash)
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function get allowedFormatChars():String
+ {
+ return _allowedFormatChars;
+ }
+
+ /**
+ * @private
+ */
+ public function set allowedFormatChars(value:String):void
+ {
+ if (value != null)
+ {
+ var n:int = value.length;
+ for (var i:int = 0; i < n; i++)
+ {
+ if
(DECIMAL_DIGITS.indexOf(value.charAt(i)) != -1)
+ {
+ value = " -";
+ }
+ }
+ }
+
+ _allowedFormatChars = value;
+ }
+
+ /**
+ * @private
+ * Storage for the invalidCharError property.
+ */
+ private var _invalidCharError:String = "Invalid characters in
your credit card number. (Enter numbers only.)";
+
+ /**
+ * Error message when the <code>cardNumber</code> field
contains invalid characters.
+ *
+ * @default "Invalid characters in your credit card number.
(Enter numbers only.)"
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function get invalidCharError():String
+ {
+ return _invalidCharError;
+ }
+
+ /**
+ * @private
+ */
+ public function set invalidCharError(value:String):void
+ {
+ _invalidCharError = value;
+ }
+
+ /**
+ * @private
+ * Storage for the invalidNumberError property.
+ */
+ private var _invalidNumberError:String = "The credit card
number is invalid.";
+
+
+ /**
+ * Error message when the credit card number is invalid.
+ *
+ * @default "The credit card number is invalid."
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function get invalidNumberError():String
+ {
+ return _invalidNumberError;
+ }
+
+ /**
+ * @private
+ */
+ public function set invalidNumberError(value:String):void
+ {
+ _invalidNumberError = value;
+ }
+
+ /**
+ * @private
+ * Storage for the noNumError property.
+ */
+ private var _noNumError:String = "No credit card number is
specified.";
+
+ /**
+ * Error message when the <code>cardNumber</code> field is
empty.
+ *
+ * @default "No credit card number is specified."
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function get noNumError():String
+ {
+ return _noNumError;
+ }
+
+ /**
+ * @private
+ */
+ public function set noNumError(value:String):void
+ {
+ _noNumError = value;
+ }
+
+ /**
+ * @private
+ * Storage for the noTypeError property.
+ */
+ private var _noTypeError:String = "No credit card type is
specified or the type is not valid.";
+
+ /**
+ * Error message when the <code>cardType</code> field is blank.
+ *
+ * @default "No credit card type is specified or the type is
not valid."
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function get noTypeError():String
+ {
+ return _noTypeError;
+ }
+
+ /**
+ * @private
+ */
+ public function set noTypeError(value:String):void
+ {
+ _noTypeError = value;
+ }
+
+ //----------------------------------
+ // wrongLengthError
+ //----------------------------------
+
+ /**
+ * @private
+ * Storage for the wrongLengthError property.
+ */
+ private var _wrongLengthError:String = "Your credit card number
contains the wrong number of digits.";
+
+ /**
+ * Error message when the <code>cardNumber</code> field
contains the wrong
+ * number of digits for the specified credit card type.
+ *
+ * @default "Your credit card number contains the wrong number
of digits."
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function get wrongLengthError():String
+ {
+ return _wrongLengthError;
+ }
+
+ /**
+ * @private
+ */
+ public function set wrongLengthError(value:String):void
+ {
+ _wrongLengthError = value;
+ }
+
+ //----------------------------------
+ // wrongTypeError
+ //----------------------------------
+
+ /**
+ * @private
+ * Storage for the wrongTypeError property.
+ */
+ private var _wrongTypeError:String = "Incorrect card type is
specified.";
+
+ /**
+ * Error message the <code>cardType</code> field contains an
invalid credit card type.
+ * You should use the predefined constants for the
<code>cardType</code> field:
+ * <code>CreditCardValidatorCardType.MASTER_CARD</code>,
+ * <code>CreditCardValidatorCardType.VISA</code>,
+ * <code>CreditCardValidatorCardType.AMERICAN_EXPRESS</code>,
+ * <code>CreditCardValidatorCardType.DISCOVER</code>, or
+ * <code>CreditCardValidatorCardType.DINERS_CLUB</code>.
+ *
+ * @default "Incorrect card type is specified."
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function get wrongTypeError():String
+ {
+ return _wrongTypeError;
+ }
+
+ /**
+ * @private
+ */
+ public function set wrongTypeError(value:String):void
+ {
+ _wrongTypeError = value;
+ }
+
+ /**
+ * Name of the card type property to validate.
+ * This attribute is optional, but if you specify the
+ * <code>cardTypeSource</code> property,
+ * you should also set this property.
+ *
+ * <p>In MXML, valid values are:</p>
+ * <ul>
+ * <li><code>"American Express"</code></li>
+ * <li><code>"Diners Club"</code></li>
+ * <li><code>"Discover"</code></li>
+ * <li><code>"MasterCard"</code></li>
+ * <li><code>"Visa"</code></li>
+ * </ul>
+ *
+ * <p>In ActionScript, you can use the following constants to
set this property:</p>
+ *
<p><code>CreditCardValidatorCardType.AMERICAN_EXPRESS</code>,
+ * <code>CreditCardValidatorCardType.DINERS_CLUB</code>,
+ * <code>CreditCardValidatorCardType.DISCOVER</code>,
+ * <code>CreditCardValidatorCardType.MASTER_CARD</code>, and
+ * <code>CreditCardValidatorCardType.VISA</code>.</p>
+ *
+ * @see mx.validators.CreditCardValidatorCardType
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ private var _cardTypeProperty:String;
+
+ public function get cardTypeProperty():String
+ {
+ return _cardTypeProperty;
+ }
+
+ public function set cardTypeProperty(value:String):void
+ {
+ _cardTypeProperty = value;
+ }
+
+ /**
+ * @private
+ * Storage for the cardTypeSource property.
+ */
+ private var _cardTypeSource:Object;
+
+ /**
+ * Object that contains the value of the card type field.
+ * If you specify a value for this property, you must also
specify
+ * a value for the <code>cardTypeProperty</code> property.
+ * Do not use this property if you set the <code>source</code>
+ * and <code>property</code> properties.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function get cardTypeSource():Object
+ {
+ return _cardTypeSource;
+ }
+
+ /**
+ * @private
+ */
+ public function set cardTypeSource(value:Object):void
+ {
+ if (_cardTypeSource == value)
+ return;
+
+ _cardTypeSource = value;
+
+ //Add default event handler for cardTypeSource
+ triggerCardTypeEvent = Event.CHANGE;
+ }
+
+ private var _triggerCardTypeEvent:String;
+
+ /**
+ * Specifies the event that triggers the validation.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ [Bindable(event="triggerCardTypeEventChanged")]
+ public function get triggerCardTypeEvent():String
+ {
+ return _triggerCardTypeEvent;
+ }
+
+ public function set triggerCardTypeEvent(value:String):void
+ {
+ if (triggerCardTypeEvent != value)
+ {
+ if(cardTypeSource)
+ {
+ if(triggerCardTypeEvent)
+ {
+
cardTypeSource.removeEventListener(triggerEvent, validate);
+ }
+
+ if(value)
+ {
+
cardTypeSource.addEventListener(value, validate);
+ }
+ }
+
+ _triggerCardTypeEvent = value;
+ if(hostComponent != null)
+ {
+ hostComponent.dispatchEvent(new
Event("triggerCardTypeEventChanged"));
+ }
+ }
+ }
+
+ /**
+ * Override of the base class validate() method to validate a
the host textinput as email.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ override public function validate(event:Event = null):Boolean
+ {
+ //always return true if disabled:
+ if (super.validate(event))
+ {
+ var value:Object = getValueFromSource();
+ var errors:String = validateCreditCard(value);
+ if (errors)
+ {
+ createErrorTip(errors);
+ }
+ else
+ {
+ var host:IPopUpHost =
UIUtils.findPopUpHost(hostComponent);
+ (host as IUIBase).dispatchEvent(new
Event("cleanValidationErrors"));
+ }
+
+ }
+ return !isError;
+ }
+
+ /**
+ * Convenience method for calling a validator.
+ * Each of the standard Flex validators has a similar
convenience method.
+ *
+ * @param validator The CreditCardValidator instance.
+ *
+ * @param value A field to validate, which must contain
+ * the following fields:
+ * <ul>
+ * <li><code>cardType</code> - Specifies the type of credit
card being validated.
+ * Use the static constants
+ * <code>CreditCardValidatorCardType.MASTER_CARD</code>,
+ * <code>CreditCardValidatorCardType.VISA</code>,
+ * <code>CreditCardValidatorCardType.AMERICAN_EXPRESS</code>,
+ * <code>CreditCardValidatorCardType.DISCOVER</code>, or
+ * <code>CreditCardValidatorCardType.DINERS_CLUB</code>.</li>
+ * <li><code>cardNumber</code> - Specifies the number of the
card
+ * being validated.</li></ul>
+ *
+ * @param baseField Text representation of the subfield
+ * specified in the value parameter.
+ * For example, if the <code>value</code> parameter
+ * specifies value.date, the <code>baseField</code> value is
"date".
+ *
+ * @return An Array of ValidationResult objects, with one
ValidationResult
+ * object for each field examined by the validator.
+ *
+ * @see mx.validators.ValidationResult
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ private function validateCreditCard(value:Object):String
+ {
+ // Resource-backed properties of the validator.
+ var allowedFormatChars:String = this.allowedFormatChars;
+
+ var valid:String = DECIMAL_DIGITS + allowedFormatChars;
+ var cardType:String = value ? value.cardType : null;
+ var cardNum:String = value ? value.cardNumber : null;
+ var digitsOnlyCardNum:String = "";
+
+ var n:int;
+ var i:int;
+
+ if (!cardType)
+ {
+ return MISSING_CARD_TYPE;
+ }
+
+ if (!cardNum)
+ {
+ return MISSING_CARD_NUMBER;
+ }
+
+ if (this.required > 1)
+ {
+ if (cardType.length == 0)
+ {
+ return this.requiredFieldError;
+ }
+
+ if (!cardNum)
+ {
+ return this.requiredFieldError;
+ }
+ }
+
+ n = allowedFormatChars.length;
+ for (i = 0; i < n; i++)
+ {
+ if
(DECIMAL_DIGITS.indexOf(allowedFormatChars.charAt(i)) != -1)
+ {
+ return INVALID_FORMAT_CHARS;
+ }
+ }
+
+ if (!cardType)
+ {
+ return this.noTypeError;
+ }
+ else if (cardType !=
CreditCardValidatorCardType.MASTER_CARD &&
+ cardType !=
CreditCardValidatorCardType.VISA &&
+ cardType !=
CreditCardValidatorCardType.AMERICAN_EXPRESS &&
+ cardType !=
CreditCardValidatorCardType.DISCOVER &&
+ cardType !=
CreditCardValidatorCardType.DINERS_CLUB)
+ {
+ return this.wrongTypeError;
+ }
+
+ if (!cardNum)
+ {
+ return this.noNumError;
+ }
+
+ if (cardNum)
+ {
+ n = cardNum.length;
+ for (i = 0; i < n; i++)
+ {
+ var temp:String = "" +
cardNum.substring(i, i + 1);
+ if (valid.indexOf(temp) == -1)
+ {
+ return this.invalidCharError;
+ }
+
+ if (DECIMAL_DIGITS.indexOf(temp) != -1)
+ {
+ digitsOnlyCardNum += temp;
+ }
+ }
+ }
+
+ var cardNumLen:int =
digitsOnlyCardNum.toString().length;
+ var correctLen:Number = -1;
+ var correctLen2:Number = -1;
+ var correctPrefixArray:Array = [];
+
+ // diner club cards with a beginning digit of 5 need to
be treated as
+ // master cards. Go to the following link for more info.
+ //
http://www.globalpaymentsinc.com/myglobal/industry_initiatives/mc-dc-canada.html
+ if (cardType == CreditCardValidatorCardType.DINERS_CLUB
&&
+ digitsOnlyCardNum.charAt(0) == "5")
+ {
+ cardType =
CreditCardValidatorCardType.MASTER_CARD;
+ }
+
+ switch (cardType)
+ {
+ case CreditCardValidatorCardType.MASTER_CARD:
+ {
+ correctLen = 16;
+ correctPrefixArray.push("51");
+ correctPrefixArray.push("52");
+ correctPrefixArray.push("53");
+ correctPrefixArray.push("54");
+ correctPrefixArray.push("55");
+ break;
+ }
+ case CreditCardValidatorCardType.VISA:
+ {
+ correctLen = 13;
+ correctLen2 = 16;
+ correctPrefixArray.push("4");
+ break;
+ }
+ case
CreditCardValidatorCardType.AMERICAN_EXPRESS:
+ {
+ correctLen = 15;
+ correctPrefixArray.push("34");
+ correctPrefixArray.push("37");
+ break;
+ }
+ case CreditCardValidatorCardType.DISCOVER:
+ {
+ correctLen = 16;
+ correctPrefixArray.push("6011");
+ break;
+ }
+ case CreditCardValidatorCardType.DINERS_CLUB:
+ {
+ correctLen = 14;
+ correctPrefixArray.push("300");
+ correctPrefixArray.push("301");
+ correctPrefixArray.push("302");
+ correctPrefixArray.push("303");
+ correctPrefixArray.push("304");
+ correctPrefixArray.push("305");
+ correctPrefixArray.push("36");
+ correctPrefixArray.push("38");
+ break;
+ }
+ default:
+ {
+ return this.wrongTypeError;
+ }
+ }
+
+ if ((cardNumLen != correctLen) && (cardNumLen !=
correctLen2))
+ {
+ return this.wrongLengthError;
+ }
+
+ // Validate the prefix
+ var foundPrefix:Boolean = false;
+ for (i = correctPrefixArray.length - 1; i >= 0; i--)
+ {
+ if
(digitsOnlyCardNum.indexOf(correctPrefixArray[i]) == 0)
+ {
+ foundPrefix = true;
+ break;
+ }
+ }
+
+ if (!foundPrefix)
+ {
+ return this.invalidNumberError;
+ }
+
+ // Implement Luhn formula testing of this.cardNumber
+ var doubledigit:Boolean = false;
+ var checkdigit:int = 0;
+ var tempdigit:int;
+ for (i = cardNumLen - 1; i >= 0; i--)
+ {
+ tempdigit = Number(digitsOnlyCardNum.charAt(i));
+ if (doubledigit)
+ {
+ tempdigit *= 2;
+ checkdigit += (tempdigit % 10);
+ if ((tempdigit / 10) >= 1.0)
+ checkdigit++;
+ doubledigit = false;
+ }
+ else
+ {
+ checkdigit = checkdigit + tempdigit;
+ doubledigit = true;
+ }
+ }
+
+ if ((checkdigit % 10) != 0)
+ {
+ return this.invalidNumberError;
+ }
+
+ return null;
+ }
+
+ /**
+ * @private
+ * Grabs the data for the validator from two different sources
+ */
+ private function getValueFromSource():Object
+ {
+ var value:Object = {};
+
+ if (cardTypeSource && cardTypeProperty)
+ {
+ value.cardType =
cardTypeSource[cardTypeProperty];
+ }
+
+ value.cardNumber = hostComponent["text"];
+
+ return value;
+ }
+ }
+}
\ No newline at end of file
diff --git
a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/supportClasses/validators/CreditCardValidatorCardType.as
b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/supportClasses/validators/CreditCardValidatorCardType.as
new file mode 100644
index 0000000..2c9c50a
--- /dev/null
+++
b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/supportClasses/validators/CreditCardValidatorCardType.as
@@ -0,0 +1,91 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.jewel.supportClasses.validators
+{
+ /**
+ * The CreditCardValidatorCardType class defines value constants
+ * for specifying the type of credit card to validate.
+ * These values are used in the
<code>CreditCardValidator.cardType</code>
+ * property.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public class CreditCardValidatorCardType
+ {
+
//--------------------------------------------------------------------------
+ //
+ // Class constants
+ //
+
//--------------------------------------------------------------------------
+
+ /**
+ * Specifies the card type as MasterCard.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public static const MASTER_CARD:String = "MasterCard";
+
+ /**
+ * Specifies the card type as Visa.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public static const VISA:String = "Visa";
+
+ /**
+ * Specifies the card type as American Express.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public static const AMERICAN_EXPRESS:String = "American
Express";
+
+ /**
+ * Specifies the card type as Discover.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public static const DISCOVER:String = "Discover";
+
+ /**
+ * Specifies the card type as Diners Club.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public static const DINERS_CLUB:String = "Diners Club";
+ }
+
+}