Commit 2159c47c authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Initial implementation of Favories.

Quick and dirty copy/paste implementation based on History.

Needs to be refactored and cleaned up.
parent 9f3aa0cf
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ Ext.application({

    launch: function() {
        Docs.App = this;
        Docs.Favorites.init();
        Docs.History.init();
    }
});
+50 −0
Original line number Diff line number Diff line
/**
 * Favorites management.
 */
Ext.define("Docs.Favorites", {
    singleton: true,

    /**
     * Initializes favorites management.
     */
    init: function() {
        // Load Favorites from localStorage
        this.store = Ext.getStore("Favorites");
        this.store.load();
    },

    /**
     * Adds class to favorites
     *
     * @param {String} cls  the class to add
     */
    add: function(cls) {
        if (!this.has(cls)) {
            this.store.add({cls: cls});
            this.store.sync();
        }
    },

    /**
     * Removes class from favorites.
     *
     * @param {String} cls  the class to remove
     */
    remove: function(cls) {
        if (this.has(cls)) {
            this.store.removeAt(this.store.find('cls', cls));
            this.store.sync();
        }
    },

    /**
     * Checks if class is in favorites
     *
     * @param {String} cls  the classname to check
     * @return {Boolean} true when class exists in favorites.
     */
    has: function(cls) {
        return this.store.find('cls', cls) > -1;
    }

});
+15 −4
Original line number Diff line number Diff line
@@ -11,15 +11,18 @@ Ext.define('Docs.controller.Classes', {
    views: [
        'cls.List',
        'tree.Tree',
        'tree.Favorites',
        'tree.History',
        'tree.HistoryItems'
    ],

    stores: [
        'Favorites',
        'History'
    ],

    models: [
        'Favorite',
        'History'
    ],

@@ -160,15 +163,23 @@ Ext.define('Docs.controller.Classes', {
        });
    },

    treeItemClick: function(view, node) {
    treeItemClick: function(view, node, item, index, e) {
        var clsName = node.raw ? node.raw.clsName : node.data.clsName;

        if (clsName) {
            if (e.getTarget(".fav")) {
                Docs.Favorites.add(clsName);
                Ext.get(e.getTarget(".fav")).addCls("show");
            }
            else {
                this.loadClass(clsName);
        } else if (!node.isLeaf()) {
            }
        }
        else if (!node.isLeaf()) {
            if (node.isExpanded()) {
                node.collapse(false);
            } else {
            }
            else {
                node.expand(false);
            }
        }
+11 −0
Original line number Diff line number Diff line
/**
 * Favorite classes
 */
Ext.define('Docs.model.Favorite', {
    fields: ['id', 'cls'],
    extend: 'Ext.data.Model',
    proxy: {
        type: 'localstorage',
        id  : 'docs-favorites'
    }
});
+7 −0
Original line number Diff line number Diff line
/**
 * Favorites Store
 */
Ext.define('Docs.store.Favorites', {
    extend: 'Ext.data.Store',
    model: 'Docs.model.Favorite'
});
Loading