[aur-dev] [PATCH 5/5] pkg_comments.php: Add JavaScript function to edit comments
Marcel Korpel
marcel.korpel at gmail.com
Mon Jul 20 22:08:48 UTC 2015
Signed-off-by: Marcel Korpel <marcel.korpel at gmail.com>
---
web/template/pkg_comments.php | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php
index 26fddfd..ec50dbf 100644
--- a/web/template/pkg_comments.php
+++ b/web/template/pkg_comments.php
@@ -72,3 +72,28 @@ $count = pkgbase_comments_count($base_id, $include_deleted);
</h3>
</div>
<?php endif; ?>
+<script>
+$(document).ready(function() {
+ $(".edit-comment").click(function () {
+ var parent_element = this.parentElement;
+ var edit_form = $(parent_element).next();
+ var comment_id = parent_element.id.substr(8);
+ $.getJSON('/rpc', {type: 'load-comment', arg: comment_id}, function (data) {
+ edit_form.html(data.form);
+ edit_form.find('input[type="submit"]').click(function () {
+ var comment = edit_form.find('textarea').val();
+ $.post('/rpc',
+ {type: 'save-comment', arg: {comment: comment, id: comment_id}},
+ function (data) {
+ if (data.success) {
+ edit_form.html('<p>' + data.html + '</p>');
+ } else {
+ alert(data.error);
+ }
+ });
+ });
+ });
+ return false;
+ });
+});
+</script>
--
2.4.6
More information about the aur-dev
mailing list