Author: michiel
Date: 2010-03-02 17:06:23 +0100 (Tue, 02 Mar 2010)
New Revision: 41233
Modified:
mmbase/trunk/base-webapp/src/main/webapp/mmbase/validation/binaryValid.jspx
mmbase/trunk/base-webapp/src/main/webapp/mmbase/validation/validation.js.jsp
Log:
dealing a bit beter if the browser does not property recognize the file
Modified:
mmbase/trunk/base-webapp/src/main/webapp/mmbase/validation/binaryValid.jspx
===================================================================
--- mmbase/trunk/base-webapp/src/main/webapp/mmbase/validation/binaryValid.jspx
2010-03-02 16:05:30 UTC (rev 41232)
+++ mmbase/trunk/base-webapp/src/main/webapp/mmbase/validation/binaryValid.jspx
2010-03-02 16:06:23 UTC (rev 41233)
@@ -28,13 +28,16 @@
if (length == null) {
//probably using the horrible 'browser' from redmond
//MultiPart.MMultipartRequest multipart =
MultiPart.getMultipartRequest((HttpServletRequest) pageContext.getRequest(),
(HttpServletResponse) pageContext.getResponse());
- length = request.getContentLength() - 224/* it's too much, we need to
guess the size of the headers, about 224 */;
+ length = request.getContentLength() - 224/* it's too much, we need to
guess the size of the headers, which would be about 224 */;
}
value = new SerializableInputStream(new NullInputStream(length), length);
if (type.length() > 0) {
- value.setContentType(type);
+ value.setContentType(new MimeType(type));
}
- Collection<LocalizedString> errors = dataType == null ? new
ArrayList<LocalizedString>() : dataType.validate(value, node == null ?
null : new ChangedNode(node, field.getName()), field);
+ Collection<LocalizedString> errors = dataType == null ?
+ new
ArrayList<LocalizedString>() :
+ dataType.validate(value,
+ node ==
null ? null : new ChangedNode(node, field.getName()), field);
pageContext.setAttribute("errors", errors);
pageContext.setAttribute("node", node);
pageContext.setAttribute("field", field);
Modified:
mmbase/trunk/base-webapp/src/main/webapp/mmbase/validation/validation.js.jsp
===================================================================
---
mmbase/trunk/base-webapp/src/main/webapp/mmbase/validation/validation.js.jsp
2010-03-02 16:05:30 UTC (rev 41232)
+++
mmbase/trunk/base-webapp/src/main/webapp/mmbase/validation/validation.js.jsp
2010-03-02 16:06:23 UTC (rev 41233)
@@ -1,3 +1,6 @@
+// -*- mode: javascript; -*-
+<%...@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.
@@ -8,12 +11,9 @@
* @author Michiel Meeuwissen
* @version $Id$
*/
-/*
-<%...@taglib uri="http://www.mmbase.org/mmbase-taglib-2.0" prefix="mm"
-%><mm:content type="text/javascript" expires="300">
-*/
+
function MMBaseValidator(root, id) {
this.uniqueId = id == null ? new Date().getTime() : id;
@@ -21,15 +21,15 @@
this.logEnabled = false;
this.traceEnabled = false;
- //<mm:cloud jspvar="cloud">
- this.uri = '<%=cloud.getCloudContext().getUri()%>';
- this.cloud = '<%=cloud.getName()%>';
- //</mm:cloud>
+ <mm:cloud jspvar="cloud">
+ this.uri = '<%=cloud.getCloudContext().getUri()%>';
+ this.cloud = '<%=cloud.getName()%>';
+ </mm:cloud>
this.invalidElements = 0;
//this.changedElements = 0;
this.elements = [];
- this.validateHook = null; // deprecated
+ this.validateHook; // deprecated
this.root = root;
this.setup();
@@ -77,6 +77,7 @@
}
+
MMBaseValidator.prototype.setup = function(el) {
if (el != null) {
this.root = el;
@@ -103,6 +104,7 @@
}
+
MMBaseValidator.prototype.log = function (msg) {
if (this.logEnabled) {
var errorTextArea = document.getElementById(this.logarea);
@@ -132,15 +134,15 @@
}
/**
- * Returns the mmbase node number associated with the given input element. Or
null, if there is
+* Returns the mmbase node number associated with the given input element. Or
null, if there is
* no such node, or the node is not yet created.
- */
+*/
MMBaseValidator.prototype.getNode = function(el) {
return this.getDataTypeKey(el).node;
}
/**
- * Whether a restriction on a certain input element mus be enforced.
+ * Whether a restriction a certain input element mus be enforced.
*/
MMBaseValidator.prototype.enforce = function(el, enf) {
this.trace("Enforce " + enf);
@@ -259,6 +261,12 @@
return length;
}
+/**
+ * Returns the mimetype as reported by the browser for the given file
+ * upload input.
+ * Probably won't work in IE.
+ * If it can't be determined, this method returns the empty string.
+ */
MMBaseValidator.prototype.getMimeType = function(el) {
var type;
if (el.type === "file") {
@@ -280,14 +288,15 @@
} catch (e) {
// Out of luck, both el.files and the silly activexobject
are not working.
this.showWarning(e);
- type = null;
+ type = "";
}
} else {
// most other browsers simply support the following (Note the
incredible ease and simplicity, compared to the horrible shit of IE).
if (el.files.length > 0) {
type = el.files.item(0).type;
+ //type = "";
} else {
- type = "application/octet-stream";
+ type = "";
}
}
}
@@ -296,6 +305,7 @@
if (value == null) {
type = null;
} else {
+ type = "";
//
}
}
@@ -356,7 +366,7 @@
}
}
return true;
-};
+}
// much much, too simple
MMBaseValidator.prototype.javaScriptPattern = function(javaPattern) {
@@ -384,7 +394,7 @@
this.log(ex);
return null;
}
-};
+}
MMBaseValidator.prototype.patternValid = function(el) {
if (this.isString(el)) {
@@ -405,7 +415,7 @@
} else {
return true;
}
-};
+}
MMBaseValidator.prototype.hasJavaClass = function(el, javaClass) {
var key = this.getDataTypeKey(el).string() + ":" + javaClass;
@@ -436,7 +446,7 @@
return MMBaseValidator.hasJavaClassesCache[key];
}
-};
+}
/**
* Whether the form element represents a numeric value. There is made no
difference between float,
@@ -446,46 +456,52 @@
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+$/;
@@ -503,7 +519,7 @@
}
return true;
-};
+}
@@ -522,7 +538,7 @@
} else {
return value;
}
-};
+}
/**
* Whether the value of the given form element satisfies possible restrictions
on minimal and
@@ -592,7 +608,7 @@
}
return true;
-};
+}
/**
@@ -788,11 +804,16 @@
return $(el).text();
}
var value = $(el).val();
+
if( this.isNumeric(el)) {
if (value === "") {
} else {
value = parseFloat(value);
}
+ } else if (this.isBoolean(el)) {
+ if ("checkbox" === el.type) {
+ value = $(el).is(":checked");
+ }
}
return value;
}
@@ -889,8 +910,12 @@
var validationUrl = '<mm:url page="/mmbase/validation/binaryValid.jspx"
/>?';
var self = this;
var params = this.getDataTypeArguments(key);
- if (this.lang != null) params.lang = this.lang;
- if (this.sessionName != null) params.sessionname = this.sessionName;
+ if (this.lang != null) {
+ params.lang = this.lang;
+ }
+ if (this.sessionName != null) {
+ params.sessionname = this.sessionName;
+ }
if (key.node != null && key.node > 0) {
params.node = key.node;
}
@@ -927,6 +952,10 @@
}
});
} else {
+ // jquery.form based upload
+ //
+ // TODO, probably won't work.
+ // An anyhow, uploading the entire thing just for validation is not
such a good idea.
if (typeof($.fn.ajaxSubmit) == "undefined") {
if (this.valid(el)) {
@@ -1102,7 +1131,6 @@
}
MMBaseValidator.prototype.validateElement = function(element, server) {
- //this.log("Validating element " + server);
var valid;
if (server) {
var prevValue = element.prevValue;
@@ -1111,7 +1139,7 @@
server = false;
element.serverValidated = true;
// already validated, so nothing to do.
- return true;
+ return false;
}
element.prevValue = "" + curValue;
}
@@ -1219,10 +1247,11 @@
case "checkbox":
$(entry).bind("click", function(ev) { self.setLastChange(ev);
self.validate(ev); });
$(entry).bind("blur", function(ev) { self.serverValidate(ev); });
+ $(entry).bind("change", function(ev) { self.serverValidate(ev);
});
break;
case "file":
$(entry).bind("change", function(ev) {
- self.setLastChange(ev); self.validate(ev);
+ self.setLastChange(ev); self.serverValidate(ev);
});
break;
case "select-one":
@@ -1268,6 +1297,5 @@
el = null;
}
-/*
+
</mm:content>
-*/
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs