Source: Comm_lib/process.js

import("system.translate");
import("system.net");
import("system.mail");
import("system.cti");


/**
 * provides somehow static methods for validation of communication data
 * do not create an instance of this
 */
function CommValidationUtil(){
}

/**
 * creates a function depending on a given COMM-category (like PHONE, EMAIL, etc.) or null if no validation-function was defined for the given category
 * @param {string} commCategory category that determines which function shall be created, e.g. "EMAIL" 
 * @return {function} function that receives the following arguments:
 * <br/> - commAddress
 * <br/> - extensions
 * <br/>the function has to return null if everything is OK or a value with details if validation failed
 */
CommValidationUtil.makeValidationFn = function (commCategory){
    var callbackFn;

    switch (commCategory) {
        case "EMAIL":
            callbackFn = function (addrValue){
//                if (!mail.isValidMailAddress(addrValue)) //TODO: enable JDito-methods
//                    return translate.text("no valid mail-address format");
                return null;
            }
            break;
        case "LINK":
            callbackFn = function (addrValue){
//                if (!net.isValidUrl(addrValue, ["http", "https"]))//TODO: enable JDito-methods
//                    return translate.text("no valid format");
                return null;
            }
            break;
        case "TELEPHONE":
            callbackFn = function (addrValue, ext){
                var country = null;
                if (addrValue[0] != "+") //if the number starts with a country-identifier (e.g. +49) no country needs to be specified
                    country = ext.countryCode;
//                if (!cti.isValidPhoneNumber(addrValue, country))//TODO: enable JDito-methods
//                    return translate.text("no valid phone number");
                return null;
            }
            break;
        default:
            callbackFn = null;
            break;
    }
    return callbackFn;
}

/**
 * returns a blueprint for validation extensions; these extensions are needed for validating comm data and can be passed to other functions
 * @return {object} a object with properties that have a specific default value; normally you want to overwrite that value
 */
CommValidationUtil.getExtensionsBlueprint = function(){
    return {
        countryCode: null
    };
}