Commit df8c87ab authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Implement marking comments as read.

Also show the read status.
parent 2fd3f4ab
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -185,6 +185,32 @@ Ext.define('Docs.Comments', {
        });
    },

    /**
     * Marks the comment as deleted or undoes the delete.
     * @param {Object} cfg
     * @param {Docs.model.Comment} cfg.comment
     * @param {Boolean} cfg.deleted True to delete, false to undo.
     * @param {Function} cfg.success
     * @param {Function} cfg.failure
     * @param {Object} cfg.scope
     */
    markRead: function(cfg) {
        Docs.Comments.request("ajax", {
            url: '/comments/' + cfg.comment.get("id") + '/read',
            method: 'POST',
            callback: function(options, success, response) {
                var data = Ext.JSON.decode(response.responseText);
                if (success && data.success) {
                    cfg.success && cfg.success.call(cfg.scope);
                }
                else {
                    cfg.failure && cfg.failure.call(cfg.scope, data.reason);
                }
            },
            scope: this
        });
    },

    /**
     * Performs request to the comments server.
     *
+1 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ Ext.define('Docs.model.Comment', {
        "upVote",
        "downVote",
        "contentHtml",
        "read",
        "deleted"
    ],
    proxy: {
+13 −0
Original line number Diff line number Diff line
@@ -63,6 +63,9 @@ Ext.define('Docs.view.comments.List', {
        this.delegateClick("a.undoDeleteComment", function(el, r) {
            this.setDeleted(el, r, false);
        }, this);
        this.delegateClick("a.readComment", function(el, r) {
            this.markRead(el, r);
        }, this);
    },

    delegateClick: function(selector, callback, scope) {
@@ -155,6 +158,16 @@ Ext.define('Docs.view.comments.List', {
        });
    },

    markRead: function(el, comment) {
        Docs.Comments.markRead({
            comment: comment,
            success: function() {
                comment.set("read", true);
                comment.commit();
            }
        });
    },

    /**
     * Loads array of comments into the view.
     * @param {Object[]} comments