Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / docs / app / Favorites.js
diff --git a/docs/app/Favorites.js b/docs/app/Favorites.js
new file mode 100644 (file)
index 0000000..3a9e108
--- /dev/null
@@ -0,0 +1,52 @@
+/**
+ * Favorites management.
+ */
+Ext.define("Docs.Favorites", {
+    extend: 'Docs.LocalStore',
+    storeName: 'Favorites',
+    singleton: true,
+
+    /**
+     * Associates Favorites with Docs TreePanel component.
+     * @param {Docs.view.tree.Tree} tree
+     */
+    setTree: function(tree) {
+        this.tree = tree;
+    },
+
+    /**
+     * Adds class to favorites
+     *
+     * @param {String} cls  the class to add
+     */
+    add: function(cls) {
+        if (!this.has(cls)) {
+            this.store.add({cls: cls});
+            this.syncStore();
+            this.tree.setFavorite(cls, true);
+        }
+    },
+
+    /**
+     * Removes class from favorites.
+     *
+     * @param {String} cls  the class to remove
+     */
+    remove: function(cls) {
+        if (this.has(cls)) {
+            this.store.removeAt(this.store.findExact('cls', cls));
+            this.syncStore();
+            this.tree.setFavorite(cls, false);
+        }
+    },
+
+    /**
+     * 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.findExact('cls', cls) > -1;
+    }
+});