Commit 305dff77 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Loading of comments when Expander clicked.

Comments get rendered through the comments.List view.
parent 2f867851
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -59,6 +59,25 @@ Ext.define('Docs.Comments', {
        return this.counts.getClassTotal(className);
    },

    /**
     * Loads the comments of a particular target.
     * @param {String[]} target An array of `[type, cls, member]`
     * @param {Function} callback Called when finished.
     * @param {Object[]} callback.comments An array of comments.
     * @param {Object} scope
     */
    load: function(target, callback, scope) {
        this.request("jsonp", {
            url: '/comments',
            method: 'GET',
            params: {
                startkey: Ext.JSON.encode(target)
            },
            success: callback,
            scope: scope
        });
    },

    /**
     * Performs request to the comments server.
     *
+16 −10
Original line number Diff line number Diff line
@@ -4,6 +4,10 @@
Ext.define('Docs.view.comments.Expander', {
    alias: "widget.commentsExpander",
    extend: 'Ext.Component',
    requires: [
        'Docs.Comments',
        'Docs.view.comments.List'
    ],

    /**
     * @cfg {String} type
@@ -21,12 +25,6 @@ Ext.define('Docs.view.comments.Expander', {
     * @cfg {Number} count
     */

    /**
     * @event fetchComments
     * Fired when new comments need to be loaded.
     * @param {String} id ID of the comments expander div.
     */

    initComponent: function() {
        this.tpl = new Ext.XTemplate(
            '<div class="comments-div first-child" id="comments-{id}">',
@@ -40,8 +38,6 @@ Ext.define('Docs.view.comments.Expander', {
            }
        );

        this.loadingTpl = new Ext.XTemplate('<div class="loading">Loading...</div>');

        var cls = this.type + '-' + this.className.replace(/\./g, '-');
        this.data = {
            id: this.memberId ? cls+"-"+this.memberId : cls,
@@ -86,8 +82,7 @@ Ext.define('Docs.view.comments.Expander', {
            list.setStyle('display', 'block');
        }
        else {
            this.loadingTpl.append(div);
            this.fireEvent("fetchComments", div.getAttribute('id'));
            this.loadComments(div);
        }
    },

@@ -103,6 +98,17 @@ Ext.define('Docs.view.comments.Expander', {
        }
    },

    loadComments: function(div) {
        this.list = new Docs.view.comments.List({
            renderTo: div
        });

        var target = [this.type, this.className, this.memberId];
        Docs.Comments.load(target, function(comments) {
            this.list.load(comments);
        }, this);
    },

    /**
     * Updates the comment count.
     * @param {Number} count
+16 −2
Original line number Diff line number Diff line
@@ -3,9 +3,15 @@
 */
Ext.define('Docs.view.comments.List', {
    extend: 'Ext.view.View',
    requires: [
        'Docs.Auth'
    ],

    itemSelector: "div.comment",

    emptyText: '<div class="loading">Loading...</div>',
    deferEmptyText: false,

    initComponent: function() {
        this.store = Ext.create('Ext.data.Store', {
            fields: [
@@ -62,6 +68,14 @@ Ext.define('Docs.view.comments.List', {
        this.callParent(arguments);
    },

    /**
     * Loads array of comments into the view.
     * @param {Object[]} comments
     */
    load: function(comments) {
        this.store.loadData(comments);
    },

    dateStr: function(date) {
        try {
            var now = Math.ceil(Number(new Date()) / 1000);
@@ -100,11 +114,11 @@ Ext.define('Docs.view.comments.List', {
    },

    isMod: function() {
        return Docs.App.getController('Auth').currentUser.mod;
        return Docs.Auth.isModerator();
    },

    isAuthor: function(author) {
        return Docs.App.getController('Auth').currentUser.userName == author;
        return Docs.Auth.getUser().userName == author;
    },

    target: function(target) {