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

Add static tab for comments.

Show the tab only when user is logged in as moderator.

Renamed CSS class 'comments' to 'comments-div' to avoid conflict with
styles to the static tab, which mush have class 'comments'.
parent d4ebfa0b
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
 */
Ext.define('Docs.controller.Comments', {
    extend: 'Docs.controller.Content',
    baseUrl: '#!/comments',
    baseUrl: '#!/comment',
    title: 'Comments',

    mixins: {
@@ -56,9 +56,11 @@ Ext.define('Docs.controller.Comments', {
            },
            loggedIn:  function() {
                Docs.view.Comments.renderNewCommentForms();
                this.isMod() && this.getController("Tabs").showCommentsTab();
            },
            loggedOut: function() {
                Docs.view.Comments.renderNewCommentForms();
                this.getController("Tabs").hideCommentsTab();
            },
            scope: this
        });
@@ -119,7 +121,7 @@ Ext.define('Docs.controller.Comments', {
            'classoverview toolbar': {
                afterrender: function(cmp) {
                    cmp.el.addListener('click', function() {
                        var commentsDiv = Ext.get(Ext.query('#m-comment .comments')[0]);
                        var commentsDiv = Ext.get(Ext.query('#m-comment .comments-div')[0]);
                        this.getOverview().scrollToEl('#m-comment', -20);
                        this.openComments(commentsDiv);
                    }, this, {
@@ -130,6 +132,10 @@ Ext.define('Docs.controller.Comments', {
        });
    },

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

    enableComments: function() {
        if (!this.commentsEnabled) {
            this.commentsEnabled = true;
@@ -174,7 +180,7 @@ Ext.define('Docs.controller.Comments', {
        }

        var postButton = Ext.get(el),
            comments = postButton.up('.comments'),
            comments = postButton.up('.comments-div'),
            id = comments.getAttribute('id'),
            target = Ext.JSON.encode(this.commentId(id)),
            textarea = comments.down('textarea').dom,
@@ -311,7 +317,7 @@ Ext.define('Docs.controller.Comments', {
     */
    deleteComment: function(cmp, el) {
        var id = Ext.get(el).up('.comment').getAttribute('id'),
            commentsEl = Ext.get(el).up('.comments'),
            commentsEl = Ext.get(el).up('.comments-div'),
            cls = commentsEl && commentsEl.getAttribute('id');

        Ext.Ajax.request({
@@ -459,7 +465,7 @@ Ext.define('Docs.controller.Comments', {
    },

    toggleComments: function(cmp, el) {
        var commentsDiv = Ext.get(el).up('.comments');
        var commentsDiv = Ext.get(el).up('.comments-div');

        if (commentsDiv.hasCls('open')) {
            this.closeComments(commentsDiv);
@@ -500,7 +506,7 @@ Ext.define('Docs.controller.Comments', {

    showMemberComments: function(cml, el) {
        var member = Ext.get(el).up('.member'),
            commentsDiv = member.down('.comments');
            commentsDiv = member.down('.comments-div');

        member.addCls('open');
        this.openComments(commentsDiv);
+24 −0
Original line number Diff line number Diff line
@@ -29,6 +29,10 @@ Ext.define('Docs.controller.Tabs', {
            ref: 'exampleIndex',
            selector: '#exampleindex'
        },
        {
            ref: 'commentIndex',
            selector: '#commentindex'
        },
        {
            ref: 'classTree',
            selector: '#classtree'
@@ -118,6 +122,10 @@ Ext.define('Docs.controller.Tabs', {
            this.getExampleIndex().getTab()
        ], function(x){return x;}));

        // just initialize the comments tab.
        // show/hide of it is performed separately.
        this.commentsTab = this.getCommentIndex().getTab();

        var tabs = Docs.Settings.get('tabs');
        if (tabs) {
            Ext.Array.forEach(tabs, function(url) {
@@ -127,6 +135,22 @@ Ext.define('Docs.controller.Tabs', {
        Docs.History.notifyTabsLoaded();
    },

    /**
     * Makes comments tab visible.
     */
    showCommentsTab: function() {
        var tabs = this.getDoctabs().getStaticTabs();
        this.getDoctabs().setStaticTabs(tabs.concat(this.commentsTab));
    },

    /**
     * Hides comments tab.
     */
    hideCommentsTab: function() {
        var tabs = this.getDoctabs().getStaticTabs();
        this.getDoctabs().setStaticTabs(Ext.Array.remove(tabs, this.commentsTab));
    },

    /**
     * Adds a tab based on information from the class tree
     * @param {String} url The url of the record in the tree
+2 −2
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ Ext.define('Docs.view.Comments', {
        );

        var commentsMeta = [
            '<div class="comments first-child" id="comments-{id}">',
            '<div class="comments-div first-child" id="comments-{id}">',
                '<a href="#" class="side toggleComments"><span></span></a>',
                '<a href="#" class="name toggleComments">', numComments.join(''), '</a>',
            '</div>'
@@ -358,7 +358,7 @@ Ext.define('Docs.view.Comments', {
            var memberEl = Ext.get(memberDom),
                memberId = memberEl.getAttribute('id'),
                memberCls = memberEl.down('.meta .defined-in').getAttribute('rel'),
                commentsWrap = memberEl.down('.comments a.name'),
                commentsWrap = memberEl.down('.comments-div a.name'),
                memberTitle = memberEl.down('.title'),
                numComments = Docs.commentMeta['class'][memberCls] && Docs.commentMeta['class'][memberCls][memberId],
                memberTitleComments = memberTitle.down('.toggleMemberComments');
+11 −0
Original line number Diff line number Diff line
@@ -70,6 +70,14 @@ Ext.define('Docs.view.Tabs', {
        this.refresh();
    },

    /**
     * Returns array of static tab configs.
     * @return {Object[]} See {@link #setStaticTabs} for details.
     */
    getStaticTabs: function(tab) {
        return this.staticTabs;
    },

    /**
     * Adds a new tab
     *
@@ -484,6 +492,9 @@ Ext.define('Docs.view.Tabs', {
        else if (/#!?\/example/.test(url)) {
            return 'Examples';
        }
        else if (/#!?\/comment/.test(url)) {
            return 'Comments';
        }
        else {
            return 'Index';
        }
+9 −1
Original line number Diff line number Diff line
@@ -12,5 +12,13 @@ Ext.define('Docs.view.comments.Index', {
    items: [
        { xtype: 'container', html: '<h1>Recent Comments</h1>' },
        { xtype: 'container', id: 'recentcomments' }
    ]
    ],

    /**
     * Returns tab config for comments page.
     * @return {Object}
     */
    getTab: function() {
        return Docs.enableComments ? {cls: 'comments', href: '#!/comment', tooltip: 'Comments'} : false;
    }
});
Loading