Update of /var/cvs/contributions/didactor2/src/core/templates/content/js
In directory james.mmbase.org:/tmp/cvs-serv7737/js

Modified Files:
        open.jsp 
Log Message:
translated to jquery


See also: 
http://cvs.mmbase.org/viewcvs/contributions/didactor2/src/core/templates/content/js


Index: open.jsp
===================================================================
RCS file: 
/var/cvs/contributions/didactor2/src/core/templates/content/js/open.jsp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- open.jsp    20 Mar 2008 17:17:03 -0000      1.5
+++ open.jsp    28 Mar 2008 16:40:45 -0000      1.6
@@ -111,7 +111,7 @@
 function disablePopups() {
     if (enabledPopups) {
         enabledPopups = false;
-        var popups = getElementsByClass(document, "popup");
+        var popups = $(document).find(".popup");
         for(var i = 0; i < popups.length; i++) {
             popups[i].style.display = "none";
         }
@@ -122,7 +122,7 @@
 function enablePopups() {
     if (! enabledPopups) {
         enabledPopups = true;
-        var popups = getElementsByClass(document, "popup");
+        var popups = $(document).find(".popup");
         for(var i = 0; i < popups.length; i++) {
             popups[i].style.display = "inline";
         }
@@ -142,19 +142,19 @@
    var content = usedFrames[href];
    if (content == null) {
        loadIconOn();
-       var xmlhttp = new XMLHttpRequest();
-       xmlhttp.open("GET", href, true);
-       xmlhttp.onreadystatechange = function()  {
-           if (xmlhttp.readyState == 4) {
-               try {
                     var contentEl = document.getElementById('contentFrame');
+       $.ajax({async: true, url: href, type: "GET", dataType: "xml", data: 
null,
+                   complete: function(res, status){
+                   loadIconOff();
+                   if (status == "success") {
+                       $(contentEl).empty();
+                       $(contentEl).append(res.responseText);
                     //                    console.log("updating " + contentEl 
+ "with" + xmlhttp.responseXML);
-                    Sarissa.updateContentFromNode(xmlhttp.responseXML, 
contentEl, null, loadIconOff);
                     contentEl.validator = new MMBaseValidator();
                     //contentEl.validator.logEnabled = true;
                     //contentEl.validator.traceEnabled = true;
                     contentEl.validator.validateHook = function(valid) {
-                        var buttons = getElementsByClass(contentEl, 
"formbutton", "input");
+                           var buttons = $(contentEl).find("input.formbutton");
                         for (i = 0; i < buttons.length; i++) {
                             var disabled = 
(contentEl.validator.invalidElements > 0);
                             buttons[i].disabled = disabled;
@@ -165,15 +165,8 @@
                     };
                     contentEl.validator.validatePage(false, contentEl);
                     contentEl.validator.addValidation(contentEl);
-                    
check(xmlhttp.responseXML.documentElement.getAttribute('class'));
+                       
check(res.responseXML.documentElement.getAttribute('class'));
                     document.href_frame = href;
-               } catch (exception) {
-                   // backwards compatibility
-                   contentEl.innerHTML = "<iframe width='100%' height='100%' 
id='content' name='content' frameborder='0'  src='" + href + "' />";
-                   resize();
-                   //throw exception;
-                   alert(exception);
-               }
                var array = new Array();
                // in case it is more than one element (e.g. comments or so), 
store all childnodes.
 
@@ -186,11 +179,11 @@
                }
                usedFrames[href] = array;
            }
-       };
-       xmlhttp.send(null);
+               }
+           });
    } else {
        var contentEl = document.getElementById('contentFrame');
-       Sarissa.clearChildNodes(contentEl);
+       $(contentEl).empty();
        for (var i=0; i < content.length; i++) {
            contentEl.appendChild(content[i]);
        }
@@ -201,41 +194,35 @@
 
 function postContent(href, form) {
     loadIconOn();
-    var xmlhttp = new XMLHttpRequest();
-    xmlhttp.open("POST", href, true);
-    xmlhttp.setRequestHeader('Content-Type', 
'application/x-www-form-urlencoded');
-    xmlhttp.onreadystatechange =  function()  {
-        //console.log("" + xmlhttp);
-        if (xmlhttp.readyState == 4) {
-            //console.log("ready")
-            if (xmlhttp.status == 200) {
+    var params = {};
+    $(form).each("textarea", function() {
+            params[this.name] = this.value;
+        });
+    $(form).each("input", function() {
+            if (this.type == "checkbox" && ! this.checked) {
+            } else {
+                params[this.name] = this.value;
+            }
+        });
+
+    $.ajax({url: href, type: "POST", dataType: "xml", data: params,
+                complete: function(res, status) {
+                if (status == "success") {
                 var contentEl = document.getElementById('contentFrame');
-                Sarissa.updateContentFromNode(xmlhttp.responseXML, contentEl, 
null, afterPost);
+                    $(contentEl).empty();
+                    $(contentEl).append(res.responseText);
+                    afterPost();
                 usedFrames[document.href_frame] = null;
                 document.href_frame = href;
                 //console.log("Found result " + contentEl);
                 usedFrames[href] = contentEl.childNodes;
             } else {
-                alert(xmlhttp.status);
-            }
+                    alert(status);
         }
-    };
-    var content = '';
-    var sep = '';
-    var textareas = form.getElementsByTagName("textarea");
-    for (i=0; i<textareas.length; i++) {
-        var ta = textareas[i];
-        content += sep + ta.name + '=' + ta.value;
-        sep = '&';
-    }
-    var textareas = form.getElementsByTagName("input");
-    for (i=0; i<textareas.length; i++) {
-        if (textareas[i].type == "checkbox" && !textareas[i].checked)
-            continue;
-        var ta = textareas[i];
-        content += sep + ta.name + '=' + ta.value;
-        sep = '&';
     }
+        });
+
+
     //console.log("posting " + content);
     xmlhttp.send(content);
     scrollToTop();
@@ -446,7 +433,7 @@
     function reloadEducationTree() {
         usedFrames    = new Object();
         //console.log("Updating '" + document.getElementById('education-tree') 
+ " with url ${_}");
-        Sarissa.updateContentFromURI('${_}', 
document.getElementById('education-tree'), null, closeAppropriate);
+        $("education-tree").load('${_}');
 
     }
 </mm:treefile>
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to