Commit 4f7572b4 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Connect comments drag-drop with backend.

Dropping comments on another comments now actually does the request to
backend, changing the parent of the comment, and then reloads the whole
list of comments.
parent 39d1318d
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -118,6 +118,24 @@ Ext.define('Docs.model.Comment', {
        });
    },

    /**
     * Sets new parent for the comment.
     * @param {Docs.model.Comment} parent
     * @param {Function} callback
     * @param {Object} scope
     */
    setParent: function(parent, callback, scope) {
        this.request({
            url: '/comments/' + this.get("id") + '/set_parent',
            method: 'POST',
            params: {
                parentId: parent.get("id")
            },
            success: callback,
            scope: scope
        });
    },

    /**
     * Adds tag to comment.
     * @param {String} tagname
+10 −2
Original line number Diff line number Diff line
@@ -40,9 +40,17 @@ Ext.define("Docs.view.comments.DropZone", {

    onNodeDrop: function(target, dd, e, data) {
        if (this.isValidDropTarget(target, data)) {
            alert("drop!");
            this.onValidDrop(data.comment, this.view.getRecord(target));
            return true;
        }
        return false;
    }
    },

    /**
     * Called when comment successfully dropped on another one.
     * @template
     * @param {Docs.model.Comment} comment The comment that was dragged.
     * @param {Docs.model.Comment} parent The comment that it got dropped on.
     */
    onValidDrop: Ext.emptyFn
});
+10 −1
Original line number Diff line number Diff line
@@ -100,9 +100,18 @@ Ext.define('Docs.view.comments.Expander', {
        this.list = new Docs.view.comments.ListWithForm({
            target: this.target,
            newCommentTitle: this.newCommentTitle,
            renderTo: this.getEl()
            renderTo: this.getEl(),
            listeners: {
                reorder: this.reload,
                scope: this
            }
        });

        this.reload();
    },

    // Reloads the comments list from backend.
    reload: function() {
        Docs.Comments.load(this.target, function(comments) {
            this.list.load(comments);
        }, this);
+13 −1
Original line number Diff line number Diff line
@@ -98,7 +98,9 @@ Ext.define('Docs.view.comments.List', {

        // initialize drag-drop
        new Docs.view.comments.DragZone(this);
        new Docs.view.comments.DropZone(this);
        new Docs.view.comments.DropZone(this, {
            onValidDrop: Ext.Function.bind(this.setParent, this)
        });
    },

    delegateClick: function(selector, callback, scope) {
@@ -180,6 +182,16 @@ Ext.define('Docs.view.comments.List', {
        comment.removeTag(tagname);
    },

    setParent: function(comment, parent) {
        comment.setParent(parent, function() {
            /**
             * @event reorder
             * Fired when comments reordered with drag-drop.
             */
            this.fireEvent("reorder");
        }, this);
    },

    /**
     * Loads array of comments into the view.
     * @param {Object[]} comments
+22 −14
Original line number Diff line number Diff line
@@ -37,7 +37,11 @@ Ext.define('Docs.view.comments.ListWithForm', {
         * @event countChange
         * @inheritdoc Docs.view.comments.List#countChange
         */
        this.relayEvents(this.list, ["countChange"]);
        /**
         * @event reorder
         * @inheritdoc Docs.view.comments.List#reorder
         */
        this.relayEvents(this.list, ["countChange", "reorder"]);

        this.callParent(arguments);
    },
@@ -67,8 +71,10 @@ Ext.define('Docs.view.comments.ListWithForm', {
            this.remove(this.commentingForm);
            delete this.commentingForm;
        }
        if (!this.authForm) {
            this.authForm = new Docs.view.auth.Form();
            this.add(this.authForm);
        }
    },

    /**
@@ -79,6 +85,7 @@ Ext.define('Docs.view.comments.ListWithForm', {
            this.remove(this.authForm);
            delete this.authForm;
        }
        if (!this.commentingForm) {
            this.commentingForm = new Docs.view.comments.Form({
                title: this.newCommentTitle,
                user: Docs.Auth.getUser(),
@@ -90,6 +97,7 @@ Ext.define('Docs.view.comments.ListWithForm', {
                }
            });
            this.add(this.commentingForm);
        }
    },

    postComment: function(content) {