⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpletype.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 2 页
字号:
    // @param [component] (DataBoundComponent) component calling this formatter, if applicable    // @param [record] (Object) Full record, if applicable    //    // @visibility external    //<    // get a type definition    getType : function (typeName, ds) {        // respect local types (dataSource.getType() calls us back, but without passing itself)        if (ds) return ds.getType(typeName);         var type = isc.builtinTypes[typeName];        return type;    },            // get the type this typeName or type definition inherits from    getBaseType : function (type, ds) {        if (isc.isA.String(type)) type = this.getType(type, ds);        if (type == null) return null; // return null for being passed null and for                                       // non-existant types        while (type.inheritsFrom) {            var parentType = this.getType(type.inheritsFrom, ds);            if (parentType == null) return null; // no such parentType            type = parentType;        }        return type.name;    },    // determine whether one type inherits from another    inheritsFrom : function (type, otherType, ds) {        if (isc.isA.String(type)) type = this.getType(type, ds);        if (type == null) return false; // return false for non-existant types        if (type.name == otherType) return true;        while (type.inheritsFrom) {            var parentType = this.getType(type.inheritsFrom, ds);            if (parentType == null) return null; // no such parentType            if (parentType.name == otherType) return true;            type = parentType;        }        return false;    },    // validate a value of simple type    validateValue : function (type, value, ds) {                var field = { name:"_temp", type:type };        isc.SimpleType.addTypeDefaults(field);        var ds = ds || isc.DS.get("Object");        return ds.validateFieldValue(field, value);    },    // add the type defaults to a field, once ever    addTypeDefaults : function (field, ds) {         if (field == null || field._typeDefaultsAdded) return;        field._typeDefaultsAdded = true; // should only every happen once        // get the type definition, looking for locally defined type if a DataSource is passed        // in        var type = this.getType(field.type, ds);        if (type == null) return;        // hang the type definition itself on the field, since when formatters are called, they        // need to be invoked on the type        field._simpleType = type;        // add the valueMap to the field        if (field.valueMap == null) {            var valueMap = this.getInheritedProperty(type, "valueMap", ds);            if (valueMap != null) type.valueMap = field.valueMap = valueMap;        }                if (field.editorType == null) {            var editorType = this.getInheritedProperty(type, "editorType", ds);            if (editorType != null) type.editorType = field.editorType = editorType;        }        // add formatters / parsers                var formatter = this.getInheritedProperty(type, "shortDisplayFormatter", ds)        if (formatter != null) type.shortDisplayFormatter = field._shortDisplayFormatter = formatter;        var formatter = this.getInheritedProperty(type, "normalDisplayFormatter", ds)        if (formatter != null) type.normalDisplayFormatter = field._normalDisplayFormatter = formatter;        // these aren't documented yet because they only get called by inline editing, not        // normal forms        var formatter = this.getInheritedProperty(type, "editFormatter", ds)        if (formatter != null) type.editFormatter = field._editFormatter = formatter;        var parser = this.getInheritedProperty(type, "parseInput", ds)        if (parser != null) type.parseInput = field._parseInput = parser;        // add validators        var typeValidators = this.getValidators(type, ds);        if (typeValidators == null) return;            if (!field.validators) {                        field.validators = typeValidators;        } else {            // there are both field validators and type validators            if (!isc.isAn.Array(field.validators)) field.validators = [field.validators];            field.validators.addAsList(typeValidators);            this._reorderTypeValidator(field.validators);        }    },    // get a property that can be defined in this type, or any type this type inherits from    getInheritedProperty : function (type, propertyName, ds) {        while (type != null) {            if (type[propertyName] != null) return type[propertyName]            type = this.getType(type.inheritsFrom, ds);        }    },    // return all validators for the given type (can be the name or the type definition), taking    // inheritance into account        getValidators : function (type, ds) {        if (isc.isA.String(type)) type = this.getType(type, ds);        // _normalized flag indicates we've already made sure the "validators" Array is in the        // canconical Array of Objects format        if (type._normalized) return type.validators;        var validators = type.validators;        if (validators != null) {             // handle validators expressed as a single string or object            if (!isc.isAn.Array(validators)) validators = [validators];            var normalizedValidators = [];            // if any of the validators are strings, replace them with validator objects,            // setting the type to the string            for (var i = 0; i < validators.length; i++) {                var validator = validators[i];                if (isc.isA.String(validator)) {                    validator = {"type":validator};                                } else if (validator.type == null && isc.isAn.emptyObject(validator)) {                    continue;                }                validator._generated = true;                normalizedValidators.add(validator);            }            validators = normalizedValidators;        }        // lookup the parent type's validators and combine        var parentTypeID = type.inheritsFrom;        if (parentTypeID != null) {            var parentType = this.getType(parentTypeID, ds);            if (parentType != null) {                var parentValidators = this.getValidators(parentType, ds);                if (parentValidators != null) {                    validators = validators || [];                    // NOTE: this intentionally places the subType's validators first, to allow                    // error message overrides                    validators.addAsList(parentValidators);                    this._reorderTypeValidator(validators);                }            }        }        // flag this Array of validators as the default for the type        if (validators) validators._typeValidators = true;        // store the normalized and combined validators        type.validators = validators;        type._normalized = true;        return validators;    },    _$typeCastValidator:"typeCastValidator",    _reorderTypeValidator : function (validators) {                //this.logWarn("validators are: " + this.echoAll(validators));        // find the typeCast validator to determine the basic type this field inherits from        // (equivalent to looking up the base type given the field type)        var castValidator = validators.find(this._$typeCastValidator, true);        if (castValidator) {            // look for the most recent declaration of the basic type validator, in order to             // support redeclaration of the type validator with a custom error message, eg            // { type:"isDate", errorMessage:"customMessage" }            var castType = castValidator.type;            //this.logWarn("cast validator is type: " + castType);            for (var i = 0; i < validators.length; i++) {                if (validators[i].type == castType) break;            }                // promote the most recent declaration of the basic type validator so that it will            // run first, so subsequent validators don't have to check type                        //this.logWarn("moving validator to front: " + this.echo(validators[i]));            if (i != 0) validators.unshift(validators[i]);            validators[0].stopIfFalse = true;        }    } });isc.SimpleType.addMethods({    init : function () { isc.builtinTypes[this.name] = this; }});

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -