コード例 #1
0
    validateAttribute: function(object, attribute) {
        var value = object.get(attribute);

        if (!Jii._.isString(value)) {
            this.addError(object, attribute, this.message);
            return;
        }

        var length = value.length;

        if (this.min !== null && length < this.min) {
            this.addError(object, attribute, this.tooShort, {
                min: this.min
            });
        }
        if (this.max !== null && length > this.max) {
            this.addError(object, attribute, this.tooLong, {
                max: this.max
            });
        }
        if (this.length !== null && length !== this.length) {
            this.addError(object, attribute, this.notEqual, {
                length: this.length
            });
        }
    },
コード例 #2
0
    init: function() {
        this.__super();

        if (Jii._.isArray(this.length)) {
            if (this.length[0]) {
                this.min = this.length[0];
            }
            if (this.length[1]) {
                this.max = this.length[1];
            }
            this.length = null;
        }

        if (this.message === null) {
            this.message = Jii.t('jii', '{attribute} must be a string.');
        }
        if (this.min !== null && this.tooShort === null) {
            this.tooShort = Jii.t('jii', '{attribute} should contain at least {min} characters.');
        }
        if (this.max !== null && this.tooLong === null) {
            this.tooLong = Jii.t('jii', '{attribute} should contain at most {max} characters.');
        }
        if (this.length !== null && this.notEqual === null) {
            this.notEqual = Jii.t('jii', '{attribute} should contain {length} characters.');
        }
    },
コード例 #3
0
    validateValue: function(value) {
        if (!Jii._.isString(value)) {
            return false;
        }

        var length = value.length;
        return (this.min === null || length >= this.min) &&
            (this.max === null || length <= this.max) &&
            (this.length === null || length === this.length);
    }
コード例 #4
0
    prepare: function (forcePrepare) {
        forcePrepare = forcePrepare || false;

        if (forcePrepare || !this._isModelsPrepare) {
            this.splice(0, this.length);
            Jii._.each(this.prepareModels(), function (model) {
                this.push(model);
            }.bind(this));
        }
        if (forcePrepare || this._keys === null) {
            this._keys = this.prepareKeys(this._models);
        }
    },
コード例 #5
0
    validateAttribute: function(object, attribute) {
        var value = object.get(attribute);

        if (Jii._.isArray(value)) {
            this.addError(object, attribute, this.message);
            return;
        }

        if (!this.validateValue(value)) {
            this.addError(object, attribute, this.message);
        } else if (this.timestampAttribute !== null) {
            // @todo Parse by format
            var timestamp = Date.parse(value);
            object.set(this.timestampAttribute, Math.round(timestamp / 1000));
        }
    },
コード例 #6
0
 validateValue: function(value) {
     // @todo Validate by format
     var timestamp = Date.parse(value);
     return !Jii._.isNaN(timestamp);
 }