Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / docs / app / Favorites.js
1 /**
2  * Favorites management.
3  */
4 Ext.define("Docs.Favorites", {
5     extend: 'Docs.LocalStore',
6     storeName: 'Favorites',
7     singleton: true,
8
9     /**
10      * Associates Favorites with Docs TreePanel component.
11      * @param {Docs.view.tree.Tree} tree
12      */
13     setTree: function(tree) {
14         this.tree = tree;
15     },
16
17     /**
18      * Adds class to favorites
19      *
20      * @param {String} cls  the class to add
21      */
22     add: function(cls) {
23         if (!this.has(cls)) {
24             this.store.add({cls: cls});
25             this.syncStore();
26             this.tree.setFavorite(cls, true);
27         }
28     },
29
30     /**
31      * Removes class from favorites.
32      *
33      * @param {String} cls  the class to remove
34      */
35     remove: function(cls) {
36         if (this.has(cls)) {
37             this.store.removeAt(this.store.findExact('cls', cls));
38             this.syncStore();
39             this.tree.setFavorite(cls, false);
40         }
41     },
42
43     /**
44      * Checks if class is in favorites
45      *
46      * @param {String} cls  the classname to check
47      * @return {Boolean} true when class exists in favorites.
48      */
49     has: function(cls) {
50         return this.store.findExact('cls', cls) > -1;
51     }
52 });