      1 // ==========================================================================
      2 // Project:   The M-Project - Mobile HTML5 Application Framework
      3 // Copyright: (c) 2010 M-Way Solutions GmbH. All rights reserved.
      4 // Creator:   Sebastian
      5 // Date:      19.11.2010
      6 // License:   Dual licensed under the MIT or GPL Version 2 licenses.
      7 //            http://github.com/mwaylabs/The-M-Project/blob/master/MIT-LICENSE
      8 //            http://github.com/mwaylabs/The-M-Project/blob/master/GPL-LICENSE
      9 // ==========================================================================
     10
     11 m_require('core/utility/logger.js');
     12
     13 /**
     14  * @class
     15  *
     16  * The prototype for every validator. All validation logic is implemented in the specific validators.
     17  *
     18  * @extends M.Object
     19  */
     20 M.Validator = M.Object.extend(
     21 /** @scope M.Validator.prototype */ {
     22
     23     /**
     24      * The type of this object.
     25      * @type String
     26      */
     27     type: 'M.Validator',
     28
     29     /**
     30      * "Class-wide" array containing error objects.
     31      * Specific validators do NOT have an own validationErrors array, but use this one to write errors to.
     32      *
     33      * Error object represent errors that occured during validation.
     34      * E.g. error object:
     35      *
     36      * {
     37      *   msg: 'E-Mail adress not valid.',
     38      *   modelId: 'Task_123',
     39      *   property: 'email',
     40      *   viewId: 'm_123',
     41      *   validator: 'EMAIL',
     42      *   onSuccess: function(){proceed();}
     43      *   onError: function(markTextFieldError(); console.log('email not valid')};
     44      * }
     45      *
     46      *
     47      * @type Array|Object
     48      */
     49     validationErrors: [],
     50
     51     /**
     52      * extends this.
     53      *
     54      * Can be used to provide a custom error msg to a validator
     55      * E.g.
     56      * M.EmailValidator.customize({msg: 'Please provide a valid e-mail adress.'});
     57      *
     58      * @param obj
     59      * @returns {Object} The customized validator.
     60      */
     61     customize: function(obj) {
     62         return this.extend(obj);
     63     },
     64
     65     /**
     66      * Empties the error buffer, is done before each new validation process
     67      */
     68     clearErrorBuffer: function() {
     69         this.validationErrors.length = 0;
     70     }
     71
     72
     73
     74 });