/**
 *  Copyright 2015 Jaime Pajuelo
 *
 *  Licensed 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.
 */


"use strict";


/**
 * @namespace
 */
var validators = {};


validators.ValidationError = (function () {

    /**
     * @constructor
     * @param {String} message
     */
    var ValidationError = function ValidationError(message) {
        this.parentClass.captureStackTrace(this, this.constructor);
        this.message = message;

        this.element = document.createElement('div');
        this.element.className = "control-error";
        this.element.textContent = message;
    };

    ValidationError.inherit(Error);

    /**
     * @type {String}
     */
    ValidationError.member('name', "ValidationError");

    return ValidationError;

})();


validators.BaseValidator = (function () {

    /**
     * @constructor
     * @param {Object.<String, *>} [options]
     */
    var BaseValidator = function BaseValidator(options) {
        var defaultOptions = {
            'code': "",
            'message': ""
        };

        options = utils.updateObject(defaultOptions, options);

        this.code = options.code;
        this.message = options.message;
    };

    /**
     * @param {String} fieldValue
     * @returns {BaseValidator} The instance on which this method was called.
     */
    BaseValidator.member('validate', function validate(fieldValue) {
        return this;
    });

    return BaseValidator;

})();


validators.RequiredValidator = (function () {

    /**
     * @constructor
     * @extends {BaseValidator}
     * @param {Object.<String, *>} [options]
     */
    var RequiredValidator = function RequiredValidator(options) {
        var defaultOptions = {
            'code': 'required',
            'message': "This field is required."
        };

        this.parentClass.call(this, utils.updateObject(defaultOptions, options));
    };

    RequiredValidator.inherit(validators.BaseValidator);

    /**
     * @override
     * @param {String} fieldValue
     * @returns {RequiredValidator} The instance on which this method was called.
     */
    RequiredValidator.member('validate', function validate(fieldValue) {
        if (!fieldValue.length) {
            throw new validators.ValidationError(this.message);
        }

        return this;
    });

    return RequiredValidator;

})();


validators.MaxLengthValidator = (function () {

    /**
     * @constructor
     * @extends {BaseValidator}
     * @param {Number} maxLength
     * @param {Object.<String, *>} [options]
     */
    var MaxLengthValidator = function MaxLengthValidator(maxLength, options) {
        var defaultOptions = {
            'code': 'max_length',
            'message': "This field must not exceed %(maxLength)s chars."
        };

        defaultOptions.message = utils.formatString(defaultOptions.message, {
            'maxLength': maxLength
        });

        this.parentClass.call(this, utils.updateObject(defaultOptions, options));
        this.maxLength = maxLength;
    };

    MaxLengthValidator.inherit(validators.BaseValidator);

    /**
     * @override
     * @param {String} fieldValue
     * @returns {MaxLengthValidator} The instance on which this method was called.
     */
    MaxLengthValidator.member('validate', function validate(fieldValue) {
        if (fieldValue.length > this.maxLength) {
            throw new validators.ValidationError(this.message);
        }

        return this;
    });

    return MaxLengthValidator;

})();


validators.MinLengthValidator = (function () {

    /**
     * @constructor
     * @extends {BaseValidator}
     * @param {Number} minLength
     * @param {Object.<String, *>} [options]
     */
    var MinLengthValidator = function MinLengthValidator(minLength, options) {
        var defaultOptions = {
            'code': 'min_length',
            'message': "This field must contain at least %(minLength)s chars."
        };

        defaultOptions.message = utils.formatString(defaultOptions.message, {
            'minLength': minLength
        });

        this.parentClass.call(this, utils.merge(defaultOptions, options));
        this.minLength = minLength;
    };

    MinLengthValidator.inherit(validators.BaseValidator);

    /**
     * @override
     * @param {String} fieldValue
     * @returns {MinLengthValidator} The instance on which this method was called.
     */
    MinLengthValidator.member('validate', function validate(fieldValue) {
        if (fieldValue.length < this.minLength) {
            throw new validators.ValidationError(this.message);
        }

        return this;
    });

    return MinLengthValidator;

})();

@@ -2495,32 +2495,65 @@
 ing%7D fieldValue%0A
+     * @throws %7BValidationError%7D%0A
      * @returns 
@@ -2610,32 +2610,32 @@
 hod was called.%0A
-
      */%0A    Requ
@@ -3662,32 +3662,65 @@
 ing%7D fieldValue%0A
+     * @throws %7BValidationError%7D%0A
      * @returns 
@@ -4813,32 +4813,32 @@
     * @override%0A
-
      * @param %7BS
@@ -4847,32 +4847,65 @@
 ing%7D fieldValue%0A
+     * @throws %7BValidationError%7D%0A
      * @returns 

Add @throws in methods that throw Validation Error