Commit 8e058025 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Make Favorites#add/remove manage icons in tree.

Now when favorite removed by clicking "x" in dropdown menu, the
star icon will also disappear from the class node in tree.
parent b5265e8c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ Ext.define("Docs.Favorites", {
        if (!this.has(cls)) {
            this.store.add({cls: cls});
            this.syncStore();
            Ext.getCmp("treePanelCmp").setFavorite(cls, true);
        }
    },

@@ -27,6 +28,7 @@ Ext.define("Docs.Favorites", {
        if (this.has(cls)) {
            this.store.removeAt(this.store.findExact('cls', cls));
            this.syncStore();
            Ext.getCmp("treePanelCmp").setFavorite(cls, false);
        }
    },

+0 −2
Original line number Diff line number Diff line
@@ -163,10 +163,8 @@ Ext.define('Docs.controller.Classes', {
                var favEl = Ext.get(e.getTarget(".fav"));
                if (favEl.hasCls('show')) {
                    Docs.Favorites.remove(clsName);
                    favEl.removeCls("show");
                } else {
                    Docs.Favorites.add(clsName);
                    favEl.addCls("show");
                }
            }
            else {
+26 −9
Original line number Diff line number Diff line
@@ -81,18 +81,35 @@ Ext.define('Docs.view.tree.Tree', {
    /**
     * Selects class node in tree by name.
     *
     * @param {String} className
     * @param {String} cls
     */
    selectClass: function(className) {
        var classNode = this.getRootNode().findChildBy(function(n) {
            return className === n.raw.clsName;
        }, null, true);

        if (classNode) {
            this.getSelectionModel().select(classNode);
            classNode.bubble(function(n) {
    selectClass: function(cls) {
        var r = this.findRecordByClassName(cls);
        if (r) {
            this.getSelectionModel().select(r);
            r.bubble(function(n) {
                n.expand();
            });
        }
    },

    /**
     * Sets favorite status of class on or off.
     *
     * @param {String} cls  name of the class
     * @param {Boolean} enable  true to mark class as favorite.
     */
    setFavorite: function(cls, enable) {
        var r = this.findRecordByClassName(cls);
        if (r) {
            var el = this.getView().getNode(r);
            Ext.get(el).down(".fav")[enable ? "addCls" : "removeCls"]("show");
        }
    },

    findRecordByClassName: function(cls) {
        return this.getRootNode().findChildBy(function(n) {
            return cls === n.raw.clsName;
        }, this, true);
    }
});