From: <bh...@us...> - 2008-10-31 07:28:28
|
Revision: 18397 http://gallery.svn.sourceforge.net/gallery/?rev=18397&view=rev Author: bharat Date: 2008-10-31 07:28:22 +0000 (Fri, 31 Oct 2008) Log Message: ----------- Updates to comment module: * We now only show the 3 most recent comments * Inline addition works properly with jQuery. The new comment slides in and gets highlighted when it appears * Refactored the comment block out into the comment list and the form so that we can refresh just the list separately. Modified Paths: -------------- trunk/eval/gx/kohana/modules/comment/controllers/comment.php trunk/eval/gx/kohana/modules/comment/libraries/Comment.php trunk/eval/gx/kohana/modules/comment/views/show_comment.html.php Added Paths: ----------- trunk/eval/gx/kohana/modules/comment/views/comment_form.html.php trunk/eval/gx/kohana/modules/comment/views/comment_list.html.php Modified: trunk/eval/gx/kohana/modules/comment/controllers/comment.php =================================================================== --- trunk/eval/gx/kohana/modules/comment/controllers/comment.php 2008-10-31 07:12:42 UTC (rev 18396) +++ trunk/eval/gx/kohana/modules/comment/controllers/comment.php 2008-10-31 07:28:22 UTC (rev 18397) @@ -20,7 +20,7 @@ $comment->item_id = $item_id; $comment->save(); - print Comment::ShowComments($item_id); + print Comment::ShowCommentList($item_id); } } ?> \ No newline at end of file Modified: trunk/eval/gx/kohana/modules/comment/libraries/Comment.php =================================================================== --- trunk/eval/gx/kohana/modules/comment/libraries/Comment.php 2008-10-31 07:12:42 UTC (rev 18396) +++ trunk/eval/gx/kohana/modules/comment/libraries/Comment.php 2008-10-31 07:28:22 UTC (rev 18397) @@ -35,9 +35,25 @@ static function ShowComments($item_id) { $v = new View('show_comment.html'); - $v->item_id = $item_id; - $v->set('comments', ORM::factory('Comment')->where('item_id', $item_id)->find_all()); + + $v->comment_list = Comment::ShowCommentList($item_id); + $v->comment_form = Comment::ShowCommentForm($item_id); $v->render(true); } + + static function ShowCommentList($item_id) { + $v = new View('comment_list.html'); + $v->item_id = $item_id; + $v->comments = ORM::factory('Comment')->where('item_id', $item_id) + ->orderby('datetime', 'desc') + ->limit(3)->find_all()->as_array(); + return $v; + } + + static function ShowCommentForm($item_id) { + $v = new View('comment_form.html'); + $v->item_id = $item_id; + return $v; + } } ?> \ No newline at end of file Added: trunk/eval/gx/kohana/modules/comment/views/comment_form.html.php =================================================================== --- trunk/eval/gx/kohana/modules/comment/views/comment_form.html.php (rev 0) +++ trunk/eval/gx/kohana/modules/comment/views/comment_form.html.php 2008-10-31 07:28:22 UTC (rev 18397) @@ -0,0 +1,38 @@ +<script type="text/javascript"> + // <![CDATA[ + $(document).ready(function(){ + $("#gCommentAdd").ajaxForm( + { target: "#gCommentThread", + url: "index.php?/comment/add", + success: function() { + $("#gCommentThread li:last") + .hide() + .slideDown("slow") + .animate({ backgroundColor: "#ff9" }, 1000) + .animate({ backgroundColor: "#fff" }, 1000) + } + }) + .clearForm(); + }); + // ]]> +</script> +<form method="post" action="index.php?/comment/Add" id="gCommentAdd" class="gCompactForm"> + <fieldset> + <legend>Add comment</legend> + <div class="row"> + <label for="gCommentAuthor">Your Name</label> + <input type="text" name="author" id="gCommentAuthor" class="text" /> + </div> + <div class="row"> + <label for="gCommentEmail">Your Email (not displayed)</label> + <input type="text" name="email" id="gCommentEmail" class="text" /> + </div> + <div class="row"> + <label for="gCommentText">Comment</label> + <textarea name="text" id="gCommentText"></textarea> + </div> + <input type="hidden" id="gItemId" name="item_id" value="<?= $item_id ?>" /> + <input type="submit" id="gCommentSubmit" value="Add" /> + </fieldset> +</form> + Property changes on: trunk/eval/gx/kohana/modules/comment/views/comment_form.html.php ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/eval/gx/kohana/modules/comment/views/comment_list.html.php =================================================================== --- trunk/eval/gx/kohana/modules/comment/views/comment_list.html.php (rev 0) +++ trunk/eval/gx/kohana/modules/comment/views/comment_list.html.php 2008-10-31 07:28:22 UTC (rev 18397) @@ -0,0 +1,14 @@ +<ul id="gCommentThread"> + <? foreach (array_reverse($comments) as $index => $comment): ?> + <li class="gComment" id="gComment-<?= $index; ?>"> + <p> + <a href="#" class="gAuthor"> <?= $comment->author ?></a> + said <?= round((time() - $comment->datetime)/60) ?> minutes ago + <span class="gDate understate"><?= strftime('%c', $comment->datetime) ?></span> + </p> + <div> + <?= $comment->text ?> + </div> + </li> + <? endforeach; ?> +</ul> Property changes on: trunk/eval/gx/kohana/modules/comment/views/comment_list.html.php ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/eval/gx/kohana/modules/comment/views/show_comment.html.php =================================================================== --- trunk/eval/gx/kohana/modules/comment/views/show_comment.html.php 2008-10-31 07:12:42 UTC (rev 18396) +++ trunk/eval/gx/kohana/modules/comment/views/show_comment.html.php 2008-10-31 07:28:22 UTC (rev 18397) @@ -1,68 +1,8 @@ -<? if ($comments): ?> -<script type="text/javascript"> - // <![CDATA[ - - // http://docs.jquery.com - // https://www.ibm.com/developerworks/web/library/wa-jquery1/ - // http://plugins.jquery.com - - // Avoid conflicts w/ other JS frameworks that use $, like prototype - // This allows the use of other JS frameworks - j$ = jQuery.noConflict(); - - // Wait for the DOM to load - j$(document).ready(function(){ - j$("#gCommentAdd").ajaxForm({ - target: "#gComments", - url: "index.php?/comment/add"}) - .clearForm(); - -// // Hide the new comment and then fadeIn() or slideDown() -// j$("#" + newCommentID) -// .hide() -// .slideDown("slow") -// .animate({ backgroundColor: "#ff9" }, 1000) -// .animate({ backgroundColor: "#fff" }, 1000); - }); - -// ]]> -</script> - <div id="gComments"> - <h2>Comments</h2> - <ul id="gCommentThread"> - <? foreach ($comments as $index=>$comment): ?> - <li class="gComment" id="gComment-<?= $index; ?>"> - <p> - <a href="#" class="gAuthor"> <?= $comment->author ?></a> - said <?= round((time() - $comment->datetime)/60) ?> minutes ago - <span class="gDate understate"><?= strftime('%c', $comment->datetime) ?></span> - </p> - <div> - <?= $comment->text ?> - </div> - </li> - <? endforeach; ?> - </ul> + <? if ($comment_list): ?> + <h2>Comments</h2> + <?= $comment_list ?> + <? endif ?> - <form method="post" action="index.php?/comment/Add" id="gCommentAdd" class="gCompactForm"> - <fieldset> - <legend>Add comment</legend> - <div class="row"> - <label for="gCommentAuthor">Your Name</label> - <input type="text" name="author" id="gCommentAuthor" class="text" /> - </div> - <div class="row"> - <label for="gCommentEmail">Your Email (not displayed)</label> - <input type="text" name="email" id="gCommentEmail" class="text" /> - </div> - <div class="row"> - <label for="gCommentText">Comment</label> - <textarea name="text" id="gCommentText"></textarea> - </div> - <input type="hidden" id="gItemId" value="<?= $item_id ?>" /> - <input type="submit" id="gCommentSubmit" value="Add" /> - </fieldset> - </form> + <?= $comment_form ?> </div> -<? endif; ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |