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