summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/comment/controllers/comment.php13
-rw-r--r--modules/comment/views/comment_form.html.php20
2 files changed, 18 insertions, 15 deletions
diff --git a/modules/comment/controllers/comment.php b/modules/comment/controllers/comment.php
index fab18498..67a4897b 100644
--- a/modules/comment/controllers/comment.php
+++ b/modules/comment/controllers/comment.php
@@ -77,14 +77,21 @@ class Comment_Controller extends REST_Controller {
$comment->datetime = time();
$comment->item_id = $this->input->post('item_id');
$comment->save();
+
+ $data = array('valid' => true, 'html' => sprintf(comment::show_comment_list($item_id)));
} else {
- print $form->render("form.html");
+ $data = array('valid' => false, 'html' => sprintf($form->render("form.html")));
+ }
+
+ if (request::method() == "get") {
+ print $data['html'];
+ } else if (request::method() == "post") {
+ print json_encode($data);
}
}
public function get_item_comments($item_id) {
- $v = comment::show_comment_list($item_id);
- print $v;
+ print comment::show_comment_list($item_id);
}
/**
diff --git a/modules/comment/views/comment_form.html.php b/modules/comment/views/comment_form.html.php
index f96023a6..86c76dba 100644
--- a/modules/comment/views/comment_form.html.php
+++ b/modules/comment/views/comment_form.html.php
@@ -4,30 +4,26 @@
function show_comment_add_form(url) {
$("#gCommentAddLink").hide();
$.get(url, function(data) {
- $("#gAddCommentFormContainer").html(data);
+ $("#gCommentAddFormContainer").html(data);
ajaxify_comment_add_form();
});
}
function ajaxify_comment_add_form() {
$("form#gComment").ajaxForm({
- target: "#gAddCommentFormContainer",
- success: function(responseText, statusText) {
- if (!responseText) {
- reload_comments();
+ dataType: 'json',
+ success: function(response_data, status_text) {
+ if (response_data['valid']) {
+ $("#gCommentThread").html(response_data["html"]);
+ $("#gCommentAddFormContainer").html("");
$("#gCommentAddLink").show();
} else {
+ $("#gCommentAddFormContainer").html(response_data["html"]);
ajaxify_comment_add_form();
}
},
});
}
-
-function reload_comments() {
- $.get("<?= url::site("photo/{$item_id}/comments") ?>", function(data) {
- $("#gCommentThread").html(data);
- });
-}
// ]]>
</script>
<span id="gCommentAddLink">
@@ -35,5 +31,5 @@ function reload_comments() {
<?= _("Add Comment") ?>
</a>
</span>
-<div id="gAddCommentFormContainer"></div>
+<div id="gCommentAddFormContainer"></div>