r9462 - in apps/gobi/trunk/code: Comment Global Page Page/skins

[email protected]
Newsgroups gmane.comp.java.helma.cvs
Message-ID <[email protected]>
Author: hannes
Date: 2008-12-22 15:50:18 +0100 (Mon, 22 Dec 2008)
New Revision: 9462

Modified:
   apps/gobi/trunk/code/Comment/embed.skin
   apps/gobi/trunk/code/Global/Global.js
   apps/gobi/trunk/code/Page/PageActions.js
   apps/gobi/trunk/code/Page/skins/commentForm.skin
   apps/gobi/trunk/code/Page/skins/javascript.skin
Log:
Make deletion of comments ajaxy.

Details at http://dev.helma.org/trac/helma/changeset/9462

Modified: apps/gobi/trunk/code/Comment/embed.skin
===================================================================
--- apps/gobi/trunk/code/Comment/embed.skin	2008-12-22 13:22:46 UTC (rev 9461)
+++ apps/gobi/trunk/code/Comment/embed.skin	2008-12-22 14:50:18 UTC (rev 9462)
@@ -3,5 +3,6 @@
 <% this.creator prefix=" by " %>
 <% this.createtime prefix=" at " %></b>
 <% this.actionlink action="edit" prefix="&nbsp;..." %>
-<% this.actionlink action="delete" prefix="&nbsp;..." %>
+<% this.actionlink action="delete" onclick="return deleteCommentShow(this);" prefix="&nbsp;..." %>
+<div class="deleteConfirm"></div>
 <% this.body %>
\ No newline at end of file

Modified: apps/gobi/trunk/code/Global/Global.js
===================================================================
--- apps/gobi/trunk/code/Global/Global.js	2008-12-22 13:22:46 UTC (rev 9461)
+++ apps/gobi/trunk/code/Global/Global.js	2008-12-22 14:50:18 UTC (rev 9462)
@@ -295,12 +295,19 @@
         }
     } else {
         var text = param.text || actionName;
-        if (isActive)
+        if (isActive) {
             res.write(text.bold());
-        else if (obj.checkAccess(param.action))
-            Html.link({href: obj.href(action)}, text);
-        else
+        } else if (obj.checkAccess(param.action)) {
+            var attr = { href: obj.href(action) };
+            for (var i in param) {
+                if (i != action) {
+                    attr[i] = param[i];
+                }
+            }
+            Html.link(attr, text);
+        } else {
             return;
+        }
     }
     if (param.separator)
         res.write(param.separator);

Modified: apps/gobi/trunk/code/Page/PageActions.js
===================================================================
--- apps/gobi/trunk/code/Page/PageActions.js	2008-12-22 13:22:46 UTC (rev 9461)
+++ apps/gobi/trunk/code/Page/PageActions.js	2008-12-22 14:50:18 UTC (rev 9462)
@@ -404,18 +404,21 @@
         res.redirect(parent.href());
     }
     this.cache.deleteKey = Math.random(10);
-    res.push();
-    res.write("<p>");
-    res.write(msg("delete_ask", this.name));
-    res.write("</p>");
-    Html.form({method: "post"});
-    Html.hidden({name: "key", value: this.cache.deleteKey});
-    Html.submit({name: "save", value: msg("delete_button")});
-    res.write(" ");
-    Html.submit({name: "cancel", value: msg("delete_cancel")});
-    res.data.body = res.pop();
-    this.renderSkin("page");
-    return;
+    var form = Html.Form({ method: "post", action: this.href("delete") },
+        Html.Hidden({name: "key", value: this.cache.deleteKey}),
+        Html.Submit({name: "save", value: msg("delete_button")}),
+        Html.Link({ href: this.href(),
+            onclick: "return deleteCommentCancel(this)" }, msg("cancel"))
+    );
+    if (!req.data.ajax) {
+        res.push();
+    }
+    res.write("<p>" + msg("delete_ask", this.name) + "</p>");
+    form.render();
+    if (!req.data.ajax) {
+        res.data.body = res.pop();
+        this.renderSkin("page");
+    }
 }
 
 /**

Modified: apps/gobi/trunk/code/Page/skins/commentForm.skin
===================================================================
--- apps/gobi/trunk/code/Page/skins/commentForm.skin	2008-12-22 13:22:46 UTC (rev 9461)
+++ apps/gobi/trunk/code/Page/skins/commentForm.skin	2008-12-22 14:50:18 UTC (rev 9462)
@@ -1,15 +1,15 @@
-<p><a href="#" onclick="return commentShowForm();" class="commentLink commentToggle"><%
-    msg name='comment_add' %></a></p>
+<p class="commentToggle"><a href="#" onclick="return commentShowForm();"
+    class="commentLink"><% msg 'comment_add' %></a></p>
 <form action="<% this.href action='comment' %>" method="post"
       class="commentToggle" id="commentForm" style="display: none;">
-    <div><label for="body"><% msg name='comment_label' %></label></div> 
+    <div><label for="body"><% msg 'comment_label' %></label></div>
     <textarea name="body" id="commentInput"></textarea>
     <p>
-    <input type="submit" value="<% msg name='comment_preview' %>" name="preview"
+    <input type="submit" value="<% msg 'comment_preview' %>" name="preview"
        onclick="return pagePreview(this.form);"/>
-    <input type="submit" value="<% msg name='comment_save' %>" name="save" />
-    <a href="#" onclick="return commentCancel();" class="commentLink"><%
-        msg name='cancel' %></a>
+    <input type="submit" value="<% msg 'comment_save' %>" name="save" />
+    <a href="#" onclick="return commentCancel();"
+        class="commentLink"><% msg 'cancel' %></a>
     </p>
     <div class="previewToggle" style="display: none;">
        <div id="pagePreview"></div>

Modified: apps/gobi/trunk/code/Page/skins/javascript.skin
===================================================================
--- apps/gobi/trunk/code/Page/skins/javascript.skin	2008-12-22 13:22:46 UTC (rev 9461)
+++ apps/gobi/trunk/code/Page/skins/javascript.skin	2008-12-22 14:50:18 UTC (rev 9462)
@@ -148,21 +148,39 @@
   }
 
   function commentShowForm() {
-      $('.commentToggle').toggle('fast');
-      $('#commentInput').focus();
-      $('html,body').animate({
-          scrollTop: $('#commentForm').offset().top
+      $('.commentToggle').toggle('fast', function() {
+          $('html,body').animate({
+              scrollTop: $('#commentForm').offset().top
+          });
+          $('#commentInput').focus();
       });
       return false;
   }
 
   function commentCancel() {
       // $('#commentInput').val('');
-      $('#pagePreview').html('');
-      $('.commentToggle').toggle('fast');
+      $('.commentToggle').slideToggle('fast', function() {
+          $('.previewToggle').slideUp();
+          $('#pagePreview').html('');
+      });
       return false;
   }
 
+  function deleteCommentShow(link) {
+      $(link).next().load(link.href, {ajax: true});
+      return false;
+  }
+
+  function deleteCommentCancel(link) {
+      var parent = $(link).parents('.deleteConfirm');
+
+      if (parent.length > 0) {
+          parent.html('');
+          return false;
+      }
+      return true;
+  }
+
   function pagePreview(form) {
       var input = $(form).find('[name=body]');
       var action = form.action || location.href;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.