Commit 9aa371e6 authored by Nick Poulden's avatar Nick Poulden
Browse files

Tons of comment updates

parent faaa35b8
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -182,6 +182,11 @@ class JsDuckRunner
  end

  def add_ext3
    head_html = <<-EOHTML
      <link rel="canonical" href="http://docs.sencha.com/ext-js/3-4/" />
      <meta name="description" content="Ext JS 3.4 API Documentation from Sencha. Class documentation, Guides and Videos on how to create Javascript applications with Ext JS 3.4" />
    EOHTML

    @options += [
      "--title", "Sencha Docs - Ext JS 3.4",
      "--footer", "Ext JS 3.4 Docs - Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> revison #{revision}",
+10 −8
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ Ext.define('Docs.controller.Auth', {
            cors: true,
            callback: function(options, success, response) {

                if (success) {
                    if (response && response.responseText) {
                        this.currentUser = JSON.parse(response.responseText);
                    }
@@ -81,6 +82,7 @@ Ext.define('Docs.controller.Auth', {
                        this.setSid(null);
                        this.getAuth().showLoggedOut();
                    }
                }
            },
            scope: this
        });
+159 −23
Original line number Diff line number Diff line
@@ -15,6 +15,10 @@ Ext.define('Docs.controller.Comments', {
            ref: 'viewport',
            selector: '#viewport'
        },
        {
            ref: 'overview',
            selector: 'classoverview'
        },
        {
            ref: 'index',
            selector: '#commentindex'
@@ -55,7 +59,7 @@ Ext.define('Docs.controller.Comments', {
        });

        this.control({
            'classoverview': {
            'viewport': {
                afterrender: function(cmp) {
                    // Map user interactions to methods
                    Ext.Array.each([
@@ -63,8 +67,11 @@ Ext.define('Docs.controller.Comments', {
                        [ '.toggleMemberComments', 'click', this.showMemberComments],
                        [ '.toggleNewComment',     'click', this.toggleNewComment],
                        [ '.toggleCommentGuide',   'click', this.toggleCommentGuide],
                        // [ '.toggleCodeEditor',     'click', this.toggleCodeEditor],
                        [ '.postComment',          'click', this.postComment],
                        [ '.updateComment',        'click', this.updateComment],
                        [ '.deleteComment',        'click', this.promptDeleteComment],
                        [ '.editComment',          'click', this.editComment],
                        [ '.voteCommentUp',        'click', this.voteUp],
                        [ '.voteCommentDown',      'click', this.voteDown]
                    ], function(delegate) {
@@ -117,7 +124,7 @@ Ext.define('Docs.controller.Comments', {
                user: currentUser && currentUser.userName
            },
            success: function(response) {
                callback.call(this, response.rows, id);
                callback.call(this, response.rows, id, opts);
            },
            scope: this
        });
@@ -129,10 +136,18 @@ Ext.define('Docs.controller.Comments', {
            return false;
        }

        var comments = Ext.get(el).up('.comments'),
        var postButton = Ext.get(el),
            comments = postButton.up('.comments'),
            id = comments.getAttribute('id'),
            comment = comments.down('textarea').getValue(),
            target = Ext.JSON.encode(this.commentId(id));
            target = Ext.JSON.encode(this.commentId(id)),
            textarea = comments.down('textarea').dom;

        var comment = textarea.editor.getValue();

        if (postButton.hasCls('disabled')) {
            return false;
        }
        postButton.addCls('disabled');

        Ext.Ajax.request({
            url: this.addSid(Docs.baseUrl + '/' + Docs.commentsDb),
@@ -144,11 +159,13 @@ Ext.define('Docs.controller.Comments', {
            },
            callback: function(options, success, response) {
                if (success) {
                    var data = Ext.JSON.decode(response.responseText);
                    this.fireEvent('add', id);
                    comments.down('textarea').dom.value = '';
                    textarea.editor.setValue('');
                    postButton.removeCls('disabled');
                    this.toggleNewComment(null, el);
                    this.fetchComments(id, this.appendNewComment, {id: data.id});
                }
                this.fetchComments(id, this.appendNewComment);
            },
            scope: this
        });
@@ -166,7 +183,7 @@ Ext.define('Docs.controller.Comments', {
            method: 'GET',
            params: {
                descending: true,
                limit: 10
                limit: 100
            },
            success: function(response) {
                this.renderComments(response.rows, id, {showCls: true, hideCommentForm: true});
@@ -202,10 +219,11 @@ Ext.define('Docs.controller.Comments', {
    /**
     * Sends a delete comment request to the server.
     */
    deleteComment: function(cmp, dom) {
    deleteComment: function(cmp, el) {

        var id = Ext.get(el).up('.comment').getAttribute('id'),
            cls = Ext.get(el).up('.comments').getAttribute('id');
            commentsEl = Ext.get(el).up('.comments'),
            cls = commentsEl && commentsEl.getAttribute('id');

        Ext.Ajax.request({
            url: this.addSid(Docs.baseUrl + '/' + Docs.commentsDb + '/' + id + '/delete'),
@@ -215,7 +233,9 @@ Ext.define('Docs.controller.Comments', {
                var data = Ext.JSON.decode(response.responseText);

                if (data.success) {
                    if (cls) {
                        this.fireEvent('remove', cls);
                    }
                    Ext.get(id).remove();
                }
            },
@@ -223,6 +243,65 @@ Ext.define('Docs.controller.Comments', {
        });
    },

    editComment: function(cmp, el) {
        var commentEl = Ext.get(el).up('.comment'),
            commentId = commentEl.getAttribute('id'),
            contentEl = commentEl.down('.content'),
            currentUser = this.getController('Auth').currentUser;

        Ext.Ajax.request({
            url: this.addSid(Docs.baseUrl + '/' + Docs.commentsDb + '/' + commentId),
            method: 'GET',
            callback: function(options, success, response) {
                var data = Ext.JSON.decode(response.responseText);
                if (data.success) {
                    var editForm = Docs.view.Comments.editCommentTpl.overwrite(contentEl, Ext.merge(currentUser, {
                        content: data.content,
                        update: true
                    }), true);

                    var textarea = editForm.down('textarea').dom;
                    this.makeCodeMirror(textarea);
                }
            },
            scope: this
        });
    },

    updateComment: function(cmp, el) {

        if (!this.loggedIn()) {
            return false;
        }

        var postButton = Ext.get(el),
            comment = postButton.up('.comment'),
            id = comment.getAttribute('id');

        var content = comment.down('textarea').dom.editor.getValue();

        if (postButton.hasCls('disabled')) {
            return false;
        }
        postButton.addCls('disabled');

        Ext.Ajax.request({
            url: this.addSid(Docs.baseUrl + '/' + Docs.commentsDb + '/' + id),
            method: 'POST',
            cors: true,
            params: {
                content: content
            },
            callback: function(options, success, response) {
                var data = Ext.JSON.decode(response.responseText);
                if (data.success) {
                    comment.down('.content').update(data.content);
                }
            },
            scope: this
        });
    },

    voteUp: function(cmp, el) {
        this.vote('up', el);
    },
@@ -257,6 +336,7 @@ Ext.define('Docs.controller.Comments', {
            callback: function(options, success, response) {
                var data = Ext.JSON.decode(response.responseText);

                if (data.success) {
                    Ext.Array.each(meta.query('.vote a'), function(voteEl) {
                        Ext.get(voteEl).removeCls('selected');
                    });
@@ -264,6 +344,10 @@ Ext.define('Docs.controller.Comments', {
                        Ext.get(meta.query('.vote a.voteComment' + (data.direction == 'up' ? 'Up' : 'Down'))[0]).addCls('selected');
                    }
                    scoreEl.update(String(data.total));
                } else {
                    this.showError(data.reason, el);
                    return false;
                }
            },
            scope: this
        });
@@ -335,11 +419,28 @@ Ext.define('Docs.controller.Comments', {
        if (opts.hideCommentForm) {
            comments.addCls('hideCommentForm');
        } else if (!comments.hasCls('hideCommentForm')) {
            var commentTpl = (this.loggedIn() ? Docs.view.Comments.loggedInCommentTpl : Docs.view.Comments.loggedOutCommentTpl);
            commentTpl.overwrite(comments.down('.new-comment-wrap'), this.loggedIn() ? this.getController('Auth').currentUser : {});

            var commentWrap = comments.down('.new-comment-wrap');

            if (this.loggedIn()) {
                var wrap = Docs.view.Comments.loggedInCommentTpl.overwrite(commentWrap, this.getController('Auth').currentUser, true),
                    textarea = wrap.down('textarea').dom;

                this.makeCodeMirror(textarea);
            } else {
                Docs.view.Comments.loggedOutCommentTpl.overwrite(commentWrap, {});
            }
        }
    },

    makeCodeMirror: function(textarea) {
        textarea.editor = CodeMirror.fromTextArea(textarea, {
            enterMode: "keep",
            mode: 'markdown',
            indentUnit: 4
        });
    },

    toggleNewComment: function(cmp, el) {
        if (!this.loggedIn()) {
            return;
@@ -353,11 +454,22 @@ Ext.define('Docs.controller.Comments', {
        }
    },

    appendNewComment: function(rows, id) {
        var newCommentWrap = Ext.get(id).down('.new-comment-wrap'),
            data = rows[rows.length - 1].value;
    appendNewComment: function(rows, domId, opts) {
        var newCommentWrap = Ext.get(domId).down('.new-comment-wrap'),
            data;

        if (opts.id) {
            Ext.Array.each(rows, function(row) {
                if (row.id == opts.id) {
                    data = row.value;
                    data.id = opts.id;
                }
            })
        } else {
            data = rows[rows.length - 1].value;
            data.id = rows[rows.length - 1].id;
        }

        Docs.view.Comments.commentTpl.insertBefore(newCommentWrap, data);
    },

@@ -366,13 +478,37 @@ Ext.define('Docs.controller.Comments', {
    },

    toggleCommentGuide: function(e, el) {
        var commentForm = Ext.get(el).up('.newCommentForm'),
        var commentForm = Ext.get(el).up('form'),
            guideText = commentForm.down('.commentGuideTxt'),
            curDisplay = guideText.getStyle('display');

        guideText.setStyle('display', (curDisplay == 'none') ? 'block' : 'none');
    },

    // toggleCodeEditor: function(e, el) {
    //
    //     var but = Ext.get(el),
    //         textarea = but.up('form').down('textarea').dom;
    //
    //     if (but.hasCls('selected')) {
    //         this.closeCodeEditor(but);
    //     } else {
    //         but.addCls('selected');
    //         but.editor = CodeMirror.fromTextArea(textarea, {
    //             enterMode: "keep",
    //             mode: { name: 'markdown' },
    //             indentUnit: 4
    //         });
    //     }
    // },

    closeCodeEditor: function(but) {
        but.removeCls('selected');
        if (but.editor) {
            but.editor.toTextArea();
        }
    },

    showError: function(msg, el) {

        if (this.errorTip) {
+7 −7
Original line number Diff line number Diff line
@@ -23,7 +23,8 @@ Ext.define('Docs.controller.CommentsMeta', {
    init: function() {

        Docs.commentMeta = {
            idMap: {}
            idMap: {},
            'class': {}
        };

        this.addEvents(
@@ -49,7 +50,7 @@ Ext.define('Docs.controller.CommentsMeta', {

        this.getController('Classes').on({
            showIndex: function() {
                if (Docs.commentMeta['class']) {
                if (this.metaLoaded) {
                    Docs.view.Comments.updateClassIndex();
                } else {
                    this.addListener('afterLoad', function() {
@@ -61,17 +62,16 @@ Ext.define('Docs.controller.CommentsMeta', {
            },
            showClass: function(cls, opts) {
                if (opts.reRendered) {
                    if (Docs.commentMeta['class']) {
                        this.createCommentIdMap(this.getController('Classes').currentCls);
                    if (this.metaLoaded) {
                        Docs.view.Comments.updateClassCommentMeta(cls);
                    } else {
                        this.addListener('afterLoad', function() {
                            this.createCommentIdMap(this.getController('Classes').currentCls);
                            Docs.view.Comments.updateClassCommentMeta(cls);
                        }, this, {
                            single: true
                        });
                    }
                    this.createCommentIdMap(this.getController('Classes').currentCls);
                }
            },
            scope: this
@@ -90,7 +90,7 @@ Ext.define('Docs.controller.CommentsMeta', {
        this.control({
            'hovermenu': {
                refresh : function(cmp) {
                    if (Docs.commentMeta['class']) {
                    if (this.metaLoaded) {
                        Docs.view.Comments.renderHoverMenuMeta(cmp.el);
                    } else {
                        this.addListener('afterLoad', function() {
@@ -120,6 +120,7 @@ Ext.define('Docs.controller.CommentsMeta', {
                    this.updateMeta(r.key, r.value.num);
                }, this);

                this.metaLoaded = true;
                this.fireEvent('afterLoad');
                Docs.view.Comments.updateClassIndex();
            },
@@ -198,7 +199,6 @@ Ext.define('Docs.controller.CommentsMeta', {
     * Creates a mapping between comment element IDs and CouchDB view keys
     */
    createCommentIdMap: function(cls) {

        var key, commentId, member
        Docs.commentMeta.idMap[('comments-class-' + cls.name).replace(/\./g, '-')] = ['class', cls.name, ''];

+78 −56
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ Ext.define('Docs.view.Comments', {
                            '<span class="target"> on {[this.target(values.target)]}</span>',
                        '</tpl>',
                    '</div>',
                    '<tpl if="this.isMod() || this.isAuthor(values.author)"><a href="#" class="deleteComment">Delete</a></tpl>',
                    '<tpl if="this.isMod() || this.isAuthor(values.author)"><a href="#" class="editComment">Edit</a><a href="#" class="deleteComment">Delete</a></tpl>',
                    '<div class="time">{[this.date(values.createdAt)]}</div>',
                    '<div class="vote">',
                        '<a href="#" class="voteCommentUp{[values.upVote ? " selected" : ""]}" title="Vote Up">&nbsp;</a>',
@@ -77,7 +77,7 @@ Ext.define('Docs.view.Comments', {
                    url += '-' + target[2];
                    title += ' ' + target[2];
                }
                return '<a href="#" class="docClass" rel="' + url + '">' + title + '</a>';
                return '<a href="#!/api/' + url + '" class="docClass" rel="' + url + '">' + title + '</a>';
            }
        };

@@ -96,23 +96,20 @@ Ext.define('Docs.view.Comments', {
            commentTplMethods
        );

        this.loggedInCommentTpl = Ext.create('Ext.XTemplate',
            '<div class="new-comment{[values.hide ? "" : " open"]}">',
                '<a href="#" class="toggleNewComment"><span></span>Post a comment</a>',
                '<form class="newCommentForm">',
                    '<textarea></textarea>',
        var commentMetaAndGuide = [
            '<div class="com-meta">',
                '<img class="avatar" width="25" height="25"',
                    ' src="http://www.gravatar.com/avatar/{emailHash}?s=25&amp;r=PG&amp;d=http://www.sencha.com/img/avatar.png">',
                '<div class="author">Logged in as {userName}</div>',
                        '<a href="#" class="toggleCommentGuide">Toggle commenting guide</a>',
                        '<input type="submit" class="postComment" value="Post comment" />',
                '<a href="#" class="toggleCommentGuide">Help</a>',
                '<input type="submit" class="{[values.update ? "update" : "post"]}Comment" value="{[values.update ? "Update" : "Post"]} comment" />',
            '</div>',
            '<div class="commentGuideTxt" style="display: none">',
                '<ul>',
                    '<li>Comments should be an <strong>extension</strong> of the documentation.</li>',
                    '<li>For any <em>questions</em> about code or usage, please use the <a href="http://www.sencha.com/forum" target="_blank">Forum</a>.</li>',
                    '<li>Comments may be edited or deleted at any time by a moderator.</li>',
                    '<li>Avatars can be managed at <a href="http://www.gravatar.com" target="_blank">Gravatar</a> (use your forum email address).</li>',
                    '<li>Comments will be formatted using the Markdown syntax, eg:</li>',
                '</ul>',
                '<div class="markdown preview">',
@@ -150,15 +147,42 @@ Ext.define('Docs.view.Comments', {
                        '<li>Second unordered list item</li>',
                    '</ul>',
                '</div>',
                    '</div>',
            '</div>'
        ];

        this.loggedInCommentTpl = Ext.create('Ext.XTemplate',
            '<div class="new-comment{[values.hide ? "" : " open"]}">',
                '<a href="#" class="toggleNewComment"><span></span>Post a comment</a>',
                '<form class="newCommentForm">',
                    '<span class="action">',
                        'Action: ',
                        '<select>',
                            '<option value="comment">Post a comment</option>',
                            '<option value="question">Ask a question</option>',
                            '<option value="problem">Report a problem</option>',
                            '<option value="problem">Request a feature</option>',
                        '</select>',
                    '</span>',
                    // '<a href="#" class="toggleCodeEditor" title="Toggle code editor">Code editor</a>',
                    '<textarea></textarea>',
                    commentMetaAndGuide.join(''),
                '</form>',
            '</div>'
        );

        this.editCommentTpl = Ext.create('Ext.XTemplate',
            '<form class="editCommentForm">',
                '<span class="action">Edit comment</span>',
                // '<a href="#" class="toggleCodeEditor" title="Toggle code editor">Code editor</a>',
                '<textarea>{content}</textarea>',
                commentMetaAndGuide.join(''),
            '</form>'
        );

        if (Ext.isIE && Ext.ieVersion <= 7) {
            this.loggedOutCommentTpl = Ext.create('Ext.XTemplate',
                '<div class="new-comment">',
                    '<span class="toggleNewComment"><span></span>Sorry, adding comments is only supported in IE 8+</span>',
                    '<span class="toggleNewComment"><span></span>Sorry, adding comments is not supported in IE 7 or earlier</span>',
                '</div>'
            );
        } else {
@@ -239,8 +263,6 @@ Ext.define('Docs.view.Comments', {
                numComments = Docs.commentMeta['class'][memberCls] && Docs.commentMeta['class'][memberCls][memberId],
                memberTitleComments = memberTitle.down('.toggleMemberComments');

            // console.log('updating', memberId, numComments, memberTitleComments)

            if (numComments) {
                this.numCommentsTpl.overwrite(commentsWrap, {
                    num: numComments
@@ -311,7 +333,7 @@ Ext.define('Docs.view.Comments', {

        Ext.Array.each(Ext.query('.new-comment-wrap'), function(newComment) {

            var hideCommentForm = Ext.get(newComment).up('.commentList').parent.hasCls('hideCommentForm');
            var hideCommentForm = Ext.get(newComment).up('.comment-list').parent().hasCls('hideCommentForm');

            if (hideCommentForm) {
            } else if (Docs.App.getController('Auth').isLoggedIn()) {
Loading