Author: michiel
Date: 2010-03-08 18:10:52 +0100 (Mon, 08 Mar 2010)
New Revision: 41295

Modified:
   mmbase/trunk/base-webapp/src/main/webapp/mmbase/upload/MMUpload.js.jsp
   mmbase/trunk/base-webapp/src/main/webapp/mmbase/upload/upload.body.jspx
   mmbase/trunk/base-webapp/src/main/webapp/mmbase/validation/validation.js.jsp
Log:
port from 1.9

Modified: mmbase/trunk/base-webapp/src/main/webapp/mmbase/upload/MMUpload.js.jsp
===================================================================
--- mmbase/trunk/base-webapp/src/main/webapp/mmbase/upload/MMUpload.js.jsp      
2010-03-08 17:09:48 UTC (rev 41294)
+++ mmbase/trunk/base-webapp/src/main/webapp/mmbase/upload/MMUpload.js.jsp      
2010-03-08 17:10:52 UTC (rev 41295)
@@ -36,12 +36,13 @@
         $(el).append(message);
         if (fadeout) {
             var p = el;
-            $(el).fadeTo(4000, 0.1, function() {
+            $(el).fadeTo(4000, 0.1,
+                         function() {
                              $(p).empty(); $(p).append(p.originalTextContent); 
}
                         );
         }
   }
-}
+};
 
 
 MMUploader.prototype.uploadProgress = function(fileid) {
@@ -50,7 +51,7 @@
             
$(this.statusElement).load("${mm:link('/mmbase/upload/progress.jspx')}");
         }
     }
-}
+};
 
 /**
  * Given an input[type=file], returns the node number which is represented in 
it.
@@ -67,7 +68,7 @@
         }
     }
     return null;
-}
+};
 
 
 MMUploader.prototype.upload = function(fileid) {
@@ -109,6 +110,14 @@
     } else {
         //console.log("Validator not set");
     }
+    var classes = $(fileItem).attr("class").split(' ');
+    for (var i in classes) {
+        var clazz = classes[i];
+        if (clazz.indexOf("mm_length_") == 0) {
+            $(fileItem).removeClass(clazz);
+            break;
+        }
+    }
 
     $.ajaxFileUpload ({
             url: "${mm:link('/mmbase/upload/upload.jspx')}" + "?uid=" + 
self.uid + "&name=" + fileItem.attr("name") + "&n=" + node + "&transaction=" + 
self.transaction,
@@ -123,12 +132,16 @@
                         alert(data.msg);
                     }
                 } else {
+                    console.log("UPLOADED");
                     try {
                         var fileItem = $("#" + fileid);
                         fileItem.val(null);
                         fileItem.prevAll(".mm_gui").remove();
                         fileItem.prevAll("input[type=hidden]").remove();
 
+                        var newLength = $(data).find("div.length").text();
+                        $(fileItem).addClass("mm_length_" + newLength);
+
                         var created = $(data).find("div.fieldgui .mm_gui, 
div.fieldgui input[type=hidden]");
                         fileItem.before(created);
                         var name = $(fileItem).attr("name");
@@ -137,6 +150,7 @@
                             $(fileItem).attr("name", name);
                         }
 
+
                         // Rebind  event handlers:
                         for (var event in events) {
                             for (var key in events[event]) {
@@ -165,7 +179,7 @@
         }
         );
     return;
-}
+};
 /*
 </mm:content></fmt:bundle>
 */

Modified: 
mmbase/trunk/base-webapp/src/main/webapp/mmbase/upload/upload.body.jspx
===================================================================
--- mmbase/trunk/base-webapp/src/main/webapp/mmbase/upload/upload.body.jspx     
2010-03-08 17:09:48 UTC (rev 41294)
+++ mmbase/trunk/base-webapp/src/main/webapp/mmbase/upload/upload.body.jspx     
2010-03-08 17:10:52 UTC (rev 41295)
@@ -24,6 +24,7 @@
   </jsp:scriptlet>
   <mm:node number="${n}" commitonclose="false" jspvar="node">
     <jsp:scriptlet>node.setValue(field, new 
org.mmbase.util.SerializableInputStream(f, is.getName()));</jsp:scriptlet>
+    <div class="length"><jsp:expression>is.getSize()</jsp:expression></div>
     <div class="nodegui">
       <mm:nodeinfo type="gui" />
     </div>

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-08 17:09:48 UTC (rev 41294)
+++ 
mmbase/trunk/base-webapp/src/main/webapp/mmbase/validation/validation.js.jsp    
    2010-03-08 17:10:52 UTC (rev 41295)
@@ -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,15 +21,15 @@
     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        = [];
 
-    this.validateHook; // deprecated
+    this.validateHook    = null; // deprecated
 
     this.root = root;
     this.setup();
@@ -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 {
@@ -294,13 +294,18 @@
                 // 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;
+                    if (type == null) {
+                        // This happens sometimes in some Windows, I don't 
understand that.
+                        type = "";
+                    }
                     //type = "";
                 } else {
+                    //alert("Did not recognize type of " + el.files);
                     type = "";
                 }
             }
         }
-    } else {
+   } else {
         var value = this.getValue(el);
         if (value == null) {
             type = null;
@@ -310,15 +315,15 @@
         }
     }
     return type;
-}
+};
 
 /**
  * Whether the value in the form element obeys the restrictions on length 
(minLength, maxLength, length)
  */
 MMBaseValidator.prototype.lengthValid = function(el) {
     var length = this.getLength(el);
-    if (! this.isRequired(el) && this.enforce(el, el.mm_isrequired_enforce) && 
length == 0) {
-        return true;
+    if (this.isRequired(el) && this.enforce(el, el.mm_isrequired_enforce) && 
length == 0) {
+        return false;
     }
     var xml = this.getDataTypeXml(el);
 
@@ -366,7 +371,7 @@
         }
     }
     return true;
-}
+};
 
 // much much, too simple
 MMBaseValidator.prototype.javaScriptPattern = function(javaPattern) {
@@ -394,7 +399,7 @@
         this.log(ex);
         return null;
     }
-}
+};
 
 MMBaseValidator.prototype.patternValid = function(el) {
     if (this.isString(el)) {
@@ -415,7 +420,7 @@
     } else {
         return true;
     }
-}
+};
 
 MMBaseValidator.prototype.hasJavaClass = function(el, javaClass) {
     var key = this.getDataTypeKey(el).string() + ":" + javaClass;
@@ -446,7 +451,7 @@
         return MMBaseValidator.hasJavaClassesCache[key];
 
     }
-}
+};
 
 /**
  * Whether the form element represents a numeric value. There is made no 
difference between float,
@@ -456,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+$/;
 
@@ -519,7 +529,7 @@
     }
     return true;
 
-}
+};
 
 
 
@@ -538,7 +548,7 @@
     } else {
         return value;
     }
-}
+};
 
 /**
  * Whether the value of the given form element satisfies possible restrictions 
on minimal and
@@ -608,7 +618,7 @@
     }
     return true;
 
-}
+};
 
 
 /**
@@ -642,7 +652,7 @@
         this.trace("Found in cache " + dataType);
     }
     return dataType;
-}
+};
 
 
 function Key() {
@@ -655,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:
@@ -664,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(" ");
@@ -696,7 +706,7 @@
         el.mm_dataTypeStructure = result;
     }
     return el.mm_dataTypeStructure;
-}
+};
 
 
 /**
@@ -717,7 +727,7 @@
             }
         }
     }
-}
+};
 
 MMBaseValidator.prototype.checkPrefetch = function() {
     var nodemanagers = "";
@@ -761,7 +771,7 @@
                 }
             });
     }
-}
+};
 
 
 /**
@@ -776,7 +786,7 @@
     } else {
         return {field: key.field, nodemanager: key.nodeManager, uri: key.uri, 
cloud: key.cloud};
     }
-}
+};
 
 
 /**
@@ -793,7 +803,7 @@
         $(el).addClass("invalid");
         $(el).removeClass("valid");
     }
-}
+};
 
 
 MMBaseValidator.prototype.getValue = function(el) {
@@ -817,7 +827,7 @@
         }
         return value;
     }
-}
+};
 
 
 MMBaseValidator.prototype.getDateValue = function(el) {
@@ -853,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
@@ -870,7 +880,7 @@
         return true; // not yet supported
     }
 
-    if (! this.isString(el)) { // For Strings, you cannot enter 'null'. The 
empty stirng is interpreted as "" in
+    if (! this.isString(el)) { // For Strings, you cannot enter 'null'. The 
empty string is interpreted as "" in
                                // stead. So skip the 'required' checks.
         if (this.isRequired(el) && this.enforce(el, el.mm_isrequired_enforce)) 
{
             if (this.getLength(el) <= 0 && (value === "" || value == null)) {
@@ -896,7 +906,7 @@
 
 
     return true;
-}
+};
 
 
 
@@ -984,7 +994,7 @@
                 }
             });
     }
-}
+};
 
 /**
  * Determins whether a form element contains a valid value, according to the 
server.
@@ -1036,7 +1046,7 @@
         this.log(ex);
         throw ex;
     }
-}
+};
 
 /**
  * The result of {...@link #serverValidation} is parsed, and converted to a 
simple boolean
@@ -1052,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);
@@ -1072,7 +1082,7 @@
     } else {
        return null;
     }
-}
+};
 
 /**
  * The event handler which is linked to form elements
@@ -1083,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);
@@ -1111,7 +1121,7 @@
         }
     }
     this.updateValidity(element, valid);
-}
+};
 
 MMBaseValidator.prototype.updateValidity = function(element, valid) {
     if (valid != element.prevValid) {
@@ -1128,7 +1138,7 @@
     }
     $(element).trigger("mmValidate", [this, valid]);
     return valid;
-}
+};
 
 MMBaseValidator.prototype.validateElement = function(element, server) {
     var valid;
@@ -1154,7 +1164,7 @@
         return valid;
     }
 
-}
+};
 
 /**
  * Validates al mm_validate form entries which were marked for
@@ -1168,7 +1178,7 @@
         this.validateElement(entry, server);
     }
     return this.invalidElements == 0;
-}
+};
 
 MMBaseValidator.prototype.hasElement = function(el) {
     var els = this.elements;
@@ -1179,9 +1189,28 @@
         }
     }
     return false;
+};
 
-}
+MMBaseValidator.prototype.getElementsWithClass = function(className) {
+    var result = [];
+    var els = this.elements;
+    for (var  i = 0; i < els.length; i++) {
+        var e = els[i];
+        if ($(e).hasClass(className)) {
+            result[result.length] = e;
+        }
+    }
+    return result;
+};
 
+MMBaseValidator.prototype.getInvalidElements = function() {
+    return this.getElementsWithClass("invalid");
+};
+
+MMBaseValidator.prototype.getValidElements = function() {
+    return this.getElementsWithClass("valid");
+};
+
 MMBaseValidator.prototype.removeValidation = function(el) {
     if (el == null) {
         el = document.documentElement;
@@ -1190,7 +1219,7 @@
     var els = $(el).find(".mm_validate").each(function() {
             self.removeValidationFromElement(this);
         });
-}
+};
 
 MMBaseValidator.prototype.removeValidationFromElement = function(el) {
     var self = this;
@@ -1207,7 +1236,7 @@
            });
         self.elements = newElements;
     }
-}
+};
 
 
 
@@ -1215,7 +1244,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++) {
@@ -1282,7 +1311,7 @@
         }
     }
 
-}
+};
 
 /**
  * Adds event handlers to all mm_validate form entries
@@ -1295,7 +1324,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

Reply via email to