Author: michiel Date: 2010-03-08 17:24:18 +0100 (Mon, 08 Mar 2010) New Revision: 41291
Modified: mmbase/branches/MMBase-1_9/base-webapp/src/main/webapp/mmbase/validation/validation.js.jsp Log: recommendations of js2-mode Modified: mmbase/branches/MMBase-1_9/base-webapp/src/main/webapp/mmbase/validation/validation.js.jsp =================================================================== --- mmbase/branches/MMBase-1_9/base-webapp/src/main/webapp/mmbase/validation/validation.js.jsp 2010-03-08 16:12:47 UTC (rev 41290) +++ mmbase/branches/MMBase-1_9/base-webapp/src/main/webapp/mmbase/validation/validation.js.jsp 2010-03-08 16:24:18 UTC (rev 41291) @@ -1,6 +1,6 @@ -// -*- mode: javascript; -*- -<%...@taglib uri="http://www.mmbase.org/mmbase-taglib-2.0" prefix="mm" +/*<%...@taglib uri="http://www.mmbase.org/mmbase-taglib-2.0" prefix="mm" %><mm:content type="text/javascript" expires="300"> +*/ /** * See test.jspx for example usage. @@ -21,10 +21,10 @@ this.logEnabled = false; this.traceEnabled = false; - <mm:cloud jspvar="cloud"> + //<mm:cloud jspvar="cloud"> this.uri = '<%=cloud.getCloudContext().getUri()%>'; this.cloud = '<%=cloud.getName()%>'; - </mm:cloud> + //</mm:cloud> this.invalidElements = 0; //this.changedElements = 0; this.elements = []; @@ -74,7 +74,7 @@ } setTimeout(MMBaseValidator.watcher, 150); -} +}; @@ -91,7 +91,7 @@ self.onLoad(event); }); } -} +}; MMBaseValidator.prototype.onLoad = function(event) { @@ -101,7 +101,7 @@ //console.log("Root" + this.root); this.addValidation(this.root); //validatePage(target); -} +}; @@ -117,7 +117,7 @@ } } } -} +}; MMBaseValidator.prototype.trace = function (msg) { if (this.traceEnabled && this.logEnabled) { @@ -131,7 +131,7 @@ } } } -} +}; /** * Returns the mmbase node number associated with the given input element. Or null, if there is @@ -139,7 +139,7 @@ */ MMBaseValidator.prototype.getNode = function(el) { return this.getDataTypeKey(el).node; -} +}; /** * Whether a restriction a certain input element mus be enforced. @@ -151,7 +151,7 @@ if (enf == 'absolute') return true; if (enf == 'oncreate') return this.getNode(el) == null; if (enf == 'onchange') return this.getNode(el) == null || this.isChanged(el); -} +}; MMBaseValidator.prototype.isChanged = function(el) { if (el != null) { @@ -164,7 +164,7 @@ } return false; } -} +}; /** * Work around http://dev.jquery.com/ticket/155 @@ -190,7 +190,7 @@ tag = tag.nextSibling; } return r; -} +}; /** @@ -202,7 +202,7 @@ el.mm_isrequired = re != null && ("true" == "" + re.getAttribute("value")); el.mm_isrequired_enforce = re != null && re.getAttribute("enforce"); return el.mm_isrequired; -} +}; MMBaseValidator.prototype.warnedUpload = false; @@ -216,7 +216,7 @@ }, 3000); } -} +}; MMBaseValidator.prototype.getLength = function(el) { var length; @@ -259,7 +259,7 @@ } } return length; -} +}; /** * Returns the mimetype as reported by the browser for the given file @@ -272,7 +272,7 @@ if (el.type === "file") { if (el.value === "") { this.getDataTypeKey(el); // set also mm_length - type = el.mm_initial_mimetype + type = el.mm_initial_mimetype; } else { if (el.files == null) { try { @@ -305,7 +305,7 @@ } } } - } else { + } else { var value = this.getValue(el); if (value == null) { type = null; @@ -315,7 +315,7 @@ } } return type; -} +}; /** * Whether the value in the form element obeys the restrictions on length (minLength, maxLength, length) @@ -371,7 +371,7 @@ } } return true; -} +}; // much much, too simple MMBaseValidator.prototype.javaScriptPattern = function(javaPattern) { @@ -399,7 +399,7 @@ this.log(ex); return null; } -} +}; MMBaseValidator.prototype.patternValid = function(el) { if (this.isString(el)) { @@ -420,7 +420,7 @@ } else { return true; } -} +}; MMBaseValidator.prototype.hasJavaClass = function(el, javaClass) { var key = this.getDataTypeKey(el).string() + ":" + javaClass; @@ -451,7 +451,7 @@ return MMBaseValidator.hasJavaClassesCache[key]; } -} +}; /** * Whether the form element represents a numeric value. There is made no difference between float, @@ -461,52 +461,57 @@ if (el.mm_isnumeric != null) return el.mm_isnumeric; el.mm_isnumeric = this.hasJavaClass(el, "org\.mmbase\.datatypes\.NumberDataType"); return el.isnumeric; -} +}; MMBaseValidator.prototype.isBoolean = function(el) { if (el.mm_isboolean != null) return el.mm_isboolean; el.mm_isboolean = this.hasJavaClass(el, "org\.mmbase\.datatypes\.BooleanDataType"); return el.isboolean; -} +}; + MMBaseValidator.prototype.isInteger = function(el) { if (el.mm_isinteger != null) return el.mm_isinteger; el.mm_isinteger = this.hasJavaClass(el, "(org\.mmbase\.datatypes\.IntegerDataType|org\.mmbase\.datatypes\.LongDataType)"); return el.mm_isinteger; -} +}; + MMBaseValidator.prototype.isFloat = function(el) { if (el.mm_isfloat != null) return el.mm_isfloat; el.mm_isfloat = this.hasJavaClass(el, "(org\.mmbase\.datatypes\.FloatDataType|org\.mmbase\.datatypes\.DoubleDataType)"); return el.mm_isfloat; -} +}; + MMBaseValidator.prototype.isString = function(el) { if (el.mm_isstring != null) { return el.mm_isstring; } el.mm_isstring = this.hasJavaClass(el, "org\.mmbase\.datatypes\.StringDataType"); return el.mm_isstring; -} +}; MMBaseValidator.prototype.isDateTime = function(el) { if (el.mm_isdatetime != null) return el.mm_isdatetime; el.mm_isdatetime = this.hasJavaClass(el, "org\.mmbase\.datatypes\.DateTimeDataType"); return el.mm_isdatetime; -} +}; + MMBaseValidator.prototype.isBinary = function(el) { if (el.mm_isbinary != null) return el.mm_isbinary; el.mm_isbinary = this.hasJavaClass(el, "org\.mmbase\.datatypes\.BinaryDataType"); return el.mm_isbinary; -} +}; + MMBaseValidator.prototype.isCheckEquality = function(el) { if (el.mm_ischeckequality != null) return el.mm_ischeckequality; el.mm_ischeckequality = this.hasJavaClass(el, "org\.mmbase\.datatypes\.CheckEqualityDataType"); return el.ischeckequality; -} +}; MMBaseValidator.prototype.isXml = function(el) { if (el.mm_isxml != null) return el.mm_isxml; el.mm_isxml= this.hasJavaClass(el, "org\.mmbase\.datatypes\.XmlDataType"); return el.mm_isxml; -} +}; MMBaseValidator.prototype.INTEGER = /^[+-]?\d+$/; @@ -524,7 +529,7 @@ } return true; -} +}; @@ -543,7 +548,7 @@ } else { return value; } -} +}; /** * Whether the value of the given form element satisfies possible restrictions on minimal and @@ -613,7 +618,7 @@ } return true; -} +}; /** @@ -647,7 +652,7 @@ this.trace("Found in cache " + dataType); } return dataType; -} +}; function Key() { @@ -660,7 +665,7 @@ } Key.prototype.string = function() { return this.cloud + "@" + this.uri + "," + this.dataType + "," + this.field + "," + this.nodeManager; -} +}; /** * Given an element, returns the associated MMBase DataType as a structutre. This structure has three fields: @@ -669,7 +674,7 @@ * MMBase DataType. */ MMBaseValidator.prototype.getDataTypeKey = function(el) { - if (el == null) return; + if (el == null) return null; if (el.mm_dataTypeStructure == null) { var classNames = el.className.split(" "); @@ -701,7 +706,7 @@ el.mm_dataTypeStructure = result; } return el.mm_dataTypeStructure; -} +}; /** @@ -722,7 +727,7 @@ } } } -} +}; MMBaseValidator.prototype.checkPrefetch = function() { var nodemanagers = ""; @@ -766,7 +771,7 @@ } }); } -} +}; /** @@ -781,7 +786,7 @@ } else { return {field: key.field, nodemanager: key.nodeManager, uri: key.uri, cloud: key.cloud}; } -} +}; /** @@ -798,7 +803,7 @@ $(el).addClass("invalid"); $(el).removeClass("valid"); } -} +}; MMBaseValidator.prototype.getValue = function(el) { @@ -822,7 +827,7 @@ } return value; } -} +}; MMBaseValidator.prototype.getDateValue = function(el) { @@ -858,7 +863,7 @@ } else { return el.value; } -} +}; /** * Returns whether a form element contains a valid value. I.e. in a fast way, validation is done in @@ -901,7 +906,7 @@ return true; -} +}; @@ -989,7 +994,7 @@ } }); } -} +}; /** * Determins whether a form element contains a valid value, according to the server. @@ -1041,7 +1046,7 @@ this.log(ex); throw ex; } -} +}; /** * The result of {...@link #serverValidation} is parsed, and converted to a simple boolean @@ -1057,14 +1062,14 @@ this.log(ex); throw ex; } -} +}; /** * Cross browser hack. We hate all browsers. Especially IE. */ MMBaseValidator.prototype.target = function(event) { return event.target || event.srcElement; -} +}; MMBaseValidator.prototype.getElement = function(event) { var target = this.target(event); @@ -1077,7 +1082,7 @@ } else { return null; } -} +}; /** * The event handler which is linked to form elements @@ -1088,11 +1093,11 @@ //this.log("event " + event.type + " on " + target.id); var element = this.getElement(event); return this.validateElement(element, server); -} +}; MMBaseValidator.prototype.serverValidate = function(event) { this.validate(event, true); -} +}; MMBaseValidator.prototype.showServerErrors = function(element, serverXml, id) { var valid = this.validResult(serverXml); @@ -1116,7 +1121,7 @@ } } this.updateValidity(element, valid); -} +}; MMBaseValidator.prototype.updateValidity = function(element, valid) { if (valid != element.prevValid) { @@ -1133,7 +1138,7 @@ } $(element).trigger("mmValidate", [this, valid]); return valid; -} +}; MMBaseValidator.prototype.validateElement = function(element, server) { var valid; @@ -1159,7 +1164,7 @@ return valid; } -} +}; /** * Validates al mm_validate form entries which were marked for @@ -1173,7 +1178,7 @@ this.validateElement(entry, server); } return this.invalidElements == 0; -} +}; MMBaseValidator.prototype.hasElement = function(el) { var els = this.elements; @@ -1184,9 +1189,8 @@ } } return false; +}; -} - MMBaseValidator.prototype.removeValidation = function(el) { if (el == null) { el = document.documentElement; @@ -1195,7 +1199,7 @@ var els = $(el).find(".mm_validate").each(function() { self.removeValidationFromElement(this); }); -} +}; MMBaseValidator.prototype.removeValidationFromElement = function(el) { var self = this; @@ -1212,7 +1216,7 @@ }); self.elements = newElements; } -} +}; @@ -1220,7 +1224,7 @@ var target = this.getElement(event); target.lastChange = new Date(); target.serverValidated = false; -} +}; MMBaseValidator.prototype.addValidationForElements = function(els) { for (var i = 0; i < els.length; i++) { @@ -1287,7 +1291,7 @@ } } -} +}; /** * Adds event handlers to all mm_validate form entries @@ -1300,7 +1304,8 @@ this.log("Will validate elements in " + el + " (" + els.length + " elements)"); this.addValidationForElements(els); el = null; -} +}; - +/* </mm:content> +*/ \ No newline at end of file _______________________________________________ Cvs mailing list [email protected] http://lists.mmbase.org/mailman/listinfo/cvs
