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

Open editor when "edit" link clicked.

Nothing more for start.
parent ce983812
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ Ext.define('Docs.view.comments.Form', {
     */
    constructor: function(cfg) {
        Ext.apply(this, cfg);
        this.updateComment = (this.content !== undefined);

        var innerTpl = [
            '<div class="com-meta">',
@@ -139,7 +140,7 @@ Ext.define('Docs.view.comments.Form', {
    render: function() {
        var wrap = this.tpl.overwrite(this.renderTo, {
            definedIn: this.updateComment ? undefined : this.extractDefinedIn(this.renderTo),
            updateComment: this.content !== undefined,
            updateComment: this.updateComment,
            content: this.content,
            userSubscribed: this.userSubscribed,
            user: this.user
+30 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ Ext.define('Docs.view.comments.List', {
        'Docs.Syntax',
        'Docs.Comments',
        'Docs.view.comments.Template',
        'Docs.view.comments.Form',
        'Docs.Tip'
    ],

@@ -59,6 +60,9 @@ Ext.define('Docs.view.comments.List', {
        this.delegateClick("a.voteCommentDown", function(el, r) {
            this.vote(el, r, "down");
        }, this);
        this.delegateClick("a.editComment", function(el, r) {
            this.edit(el, r);
        }, this);
    },

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

    // starts an editor on the comment
    edit: function(el, comment) {
        this.loadOrigContent(comment, function(content) {
            var contentEl = Ext.get(el).up(".comment").down(".content");
            new Docs.view.comments.Form({
                renderTo: contentEl,
                user: Docs.Auth.getUser(),
                content: content
            });
        }, this);
    },

    loadOrigContent: function(comment, callback, scope) {
        Docs.Comments.request("ajax", {
            url: '/comments/' + comment.get("_id"),
            method: 'GET',
            callback: function(options, success, response) {
                var data = Ext.JSON.decode(response.responseText);
                if (data.success) {
                    callback.call(scope, data.content);
                }
            },
            scope: this
        });
    },

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