first commit

This commit is contained in:
2020-10-20 00:58:15 +02:00
commit 7f1b9bfca5
222 changed files with 56918 additions and 0 deletions

View File

@ -0,0 +1,219 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/

package com.yahoo.astra.managers {
import com.yahoo.astra.containers.formClasses.FormItem;
import com.yahoo.astra.containers.formClasses.FormLayoutStyle;
import com.yahoo.astra.events.FormDataManagerEvent;
import com.yahoo.astra.utils.IValueParser;
import com.yahoo.astra.utils.ValueParser;
import flash.display.DisplayObject;
import flash.events.EventDispatcher;
import flash.events.MouseEvent;
/**
* Collects user input data and validate it before you submit the data to the server.
* Astra does not provide a separate validation class, but there are compatible validation classes available from Adobe.
* Another option for the validation is the mx.validators distributed in the Flex SDK. For convenient use of Flex validators, you can use the Astra <code>MXValidatorHelper</code> class.
* Flex MXvalidator provides a variety of validation types and detailed error messages. However, the use of the MXvalidator will increase your overall file size by approximately 20K.
* @example The following code shows a use of <code>FormDataManager</code>:
* <listing version="3.0">
* import fl.controls.Button;
* import fl.controls.TextInput;
* import com.adobe.as3Validators.as3DataValidation;
* import com.yahoo.astra.containers.formClasses.FormItem;
* import com.yahoo.astra.events.FormDataManagerEvent;
* import com.yahoo.astra.fl.utils.FlValueParser;
* import com.yahoo.astra.managers.FormDataManager;
*
* // Make sure that you have TextInput and Button component in your library
* var nameTextInput:TextInput = new TextInput();
* var nameFormItem : FormItem = new FormItem("Name", nameTextInput);
* this.addChild(nameFormItem);
*
* var emailTextInput : TextInput = new TextInput();
* var emailFormItem : FormItem = new FormItem("Email", emailTextInput);
* emailFormItem.required = true;
* emailFormItem.y = 30;
* this.addChild(emailFormItem);
*
* var submitButton : Button = new Button();
* submitButton.label="SUBMIT";
* submitButton.y = 60;
* this.addChild(submitButton);
*
* // Init FormDataManager with FlValueParser.
* var formDataManager : FormDataManager = new FormDataManager(FlValueParser);
* formDataManager.functionValidationPassed = handlerValidationPassed;
* formDataManager.functionValidationFailed = handlerValidationFailed;
* formDataManager.addTrigger(submitButton, handlerDataCollectionSuccess, handlerDataCollectionFail);
*
* var validator : as3DataValidation = new as3DataValidation();
* formDataManager.dataSource = [{ id: "name", source:nameTextInput},
* { id:"email", source:emailTextInput, required:true, validator:validator.isEmail, eventTargetObj:emailFormItem }];
*
* // This will be called when eventTargetObj receives FormDataManagerEvent.VALIDATION_PASSED
* function handlerValidationPassed(e : FormDataManagerEvent):void {
* trace("required collectedData:", e.collectedData.toString());
* if (e.target is FormItem) {
* // If the eventTargetObj is FormItem, hide the requiredIndicator(.
* var formItemRequiredIndicator : DisplayObject = (e.target as FormItem).requiredIndicator;
* if (formItemRequiredIndicator) formItemRequiredIndicator.visible = false;
* }
* }
*
* // This will be called when eventTargetObj receives FormDataManagerEvent.VALIDATION_FAILED
* function handlerValidationFailed(e : FormDataManagerEvent):void {
* trace("required errorMessage:", e.errorMessage.toString());
* if (e.target is FormItem) {
* // If the eventTargetObj is FormItem, show the requiredIndicator(.
* var formItemRequiredIndicator : DisplayObject = (e.target as FormItem).requiredIndicator;
* if (formItemRequiredIndicator) formItemRequiredIndicator.visible = true;
* }
* }
* // Below will be called when all the required fields are passed validation(FormDataManagerEvent.DATACOLLECTION_SUCCESS).
* function handlerDataCollectionSuccess(e : FormDataManagerEvent) {
* for (var i:String in FormDataManager.collectedData) {
* trace("SUCCESS ",i + " : " + FormDataManager.collectedData[i] + "\n");
* // "SUCCESS ", email : address&#64;yahoo.com
* }
* }
* // Below will be called when there is any invalid required field(FormDataManagerEvent.DATACOLLECTION_FAIL).
* function handlerDataCollectionFail(e : FormDataManagerEvent) {
* for (var i:String in FormDataManager.failedData) {
* trace("FAIL ",i + " :: " + FormDataManager.failedData[i] + "\n");
* // "FAIL ", email : Missing an &#64; character in your email address.
* }
* }
* </listing>
*
* @see com.yahoo.astra.utils.ValueParser
* @see com.yahoo.astra.fl.utils.FlValueParser
* @see com.yahoo.astra.utils.MXValidationHelper
* @see http://code.google.com/p/flash-validators
* @author kayoh
*/
public class FormDataManager extends EventDispatcher implements IFormDataManager {
//--------------------------------------
// Constructor
//--------------------------------------
/**
* Constructor.
*
* @param customValuePaser IValuePaser Class. If there is no defined <code>customValuePaser</code>, <code>com.yahoo.astra.utils.ValuePaser</code> will be used to strip input data.
*/
public function FormDataManager(customValuePaser : Class = null) {
valueParser = (customValuePaser) ? customValuePaser : ValueParser;
managerArray = [];
}
//--------------------------------------
// Properties
//--------------------------------------
/**
* @private
*/
private var valueParser : Class = null;
/**
* @private
*/
private var managerArray : Array = [];
/**
* @private
*/
private var validFunction : Function = null;
/**
* @private
*/
private var inValidFunction : Function = null;
/**
* @private
*/
private var idToRemove : String ;
/**
* @private
*/
private var _functionValidationPassed : Function = null;
/**
* Sets the method to be called as a handler function, when validation is success(FormDataManagerEvent.VALIDATION_PASSED).
*/
public function get functionValidationPassed() : Function {
return _functionValidationPassed;
}
/**
* @private
*/
public function set functionValidationPassed(value : Function) : void {
_functionValidationPassed = value;
}
/**
* @private
*/
private var _functionValidationFailed : Function = null;
/**
* Gets and sets the method to be called as a handler function, when validation is failed(FormDataManagerEvent.VALIDATION_FAILED).
*/
public function get functionValidationFailed() : Function {
return _functionValidationFailed;
}
/**
* @private
*/
public function set functionValidationFailed(value : Function) : void {
_functionValidationFailed = value;
}
/**
* @private
*/
private var _errorString : String = FormLayoutStyle.DEFAULT_ERROR_STRING;
/**
* Gets and sets the text representing error.
*
* @default "Invalid input"
*/
public function get errorString() : String {
return _errorString;
}
/**
* @private
*/
public function set errorString(value : String) : void {
_errorString = value;
}
/**
* @private
*/
private static var _collectedData : Object;
/**
* Collection of form input data variables object array.
* The <code>"id"</code> will be the key and the user input from the <code>"source"</code> will be value of the array.(e.g. collectedData["zip"] = "94089")
* You can loop over each value within the <code>collectedData</code> object instance by using a for..in loop.
*
* @example The following code configures shows usage of <code>collectedData</code>:
* <listing version="3.0">
* for (var i:String in FormDataManager.collectedData) {
* trace( i + " : " + FormDataManager.collectedData[i] + "\n");
* }
* // state : CA
* // zip : 94089
* </listing>
*
*/
public static function get collectedData() : Object {
return _collectedData;
}
/**

View File

@ -0,0 +1,10 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.managers {
import flash.display.DisplayObject;
import flash.events.MouseEvent;
/**
* Methods expected to be defined by <code>FormDataManager</code>.
* @author kayoh