commit d94412d8765f0232716fbd8a54990ad5ffe1ae26
parent dd12b408d58e2113b840c0d642593e59a68a5ad4
Author: Timo A. Hummel <timo@netraver.de>
Date: Mon, 6 Jun 2011 19:20:35 +0200
Added category scope function. This lets you select if you wish to see the selected category only, or the selected category + all sub categories
Diffstat:
4 files changed, 86 insertions(+), 13 deletions(-)
diff --git a/frontend/js/Components/Editor/EditorGrid.js b/frontend/js/Components/Editor/EditorGrid.js
@@ -53,17 +53,19 @@ Ext.define('PartDB2.EditorGrid', {
},
this.searchField]
});
+
+ this.bottomToolbar = Ext.create("Ext.toolbar.Paging", {
+ store: this.store,
+ dock: 'bottom',
+ displayInfo: false
+ });
+
Ext.apply(this, {
dockedItems: [
this.topToolbar,
- {
- xtype: 'pagingtoolbar',
- store: this.store,
- dock: 'bottom',
- displayInfo: false
- }]
-
- });
+ this.bottomToolbar
+ ]
+ });
this.callParent();
}
diff --git a/frontend/js/Components/Part/PartsGrid.js b/frontend/js/Components/Part/PartsGrid.js
@@ -9,8 +9,73 @@ Ext.define('PartDB2.PartsGrid', {
{header: i18n("Footprint"), dataIndex: 'footprintName'}
],
buttonTextMode: 'show',
+
+ categoryScope: 'all',
+
+ scopeAllText: i18n("All subcategories"),
+ scopeSelectedText: i18n('Only selected category'),
+
initComponent: function () {
this.callParent();
+
+ this.categoryScopeButton = Ext.create("Ext.button.Split", {
+ text: this.scopeAllText,
+ handler: this.categoryModeButtonHandler,
+ scope: this,
+ menu: {
+ items: [
+ {
+ text: this.scopeAllText,
+ handler: this.allSubcategoriesHandler,
+ scope: this
+ },
+ {
+ text: this.scopeSelectedText,
+ handler: this.onlySelectedCategoryHandler,
+ scope: this
+ }]
+ }
+ });
+
+ this.bottomToolbar.add(this.categoryScopeButton);
+ this.setScopeMode("all");
+ },
+ categoryModeButtonHandler: function () {
+ if (this.categoryScope == "all") {
+ this.setScopeMode("selected");
+ } else {
+ this.setScopeMode("all");
+ }
+ this.store.load();
+ },
+ allSubcategoriesHandler: function () {
+ this.setScopeMode("all");
+ this.store.load();
+ },
+ onlySelectedCategoryHandler: function () {
+ this.setScopeMode("selected");
+ this.store.load();
+ },
+ setScopeMode: function (mode) {
+ switch (mode) {
+ case "all":
+ case "selected":
+ this.categoryScope = mode;
+ break;
+ default:
+ alert("Invalid mode in setScopeMode!");
+ break;
+ }
+
+ /* Update button text */
+ if (this.categoryScope == "all") {
+ this.categoryScopeButton.setText(this.scopeAllText);
+ } else {
+ this.categoryScopeButton.setText(this.scopeSelectedText);
+ }
+
+ var proxy = this.store.getProxy();
+ proxy.extraParams.categoryScope = this.categoryScope;
},
setCategory: function (category) {
var proxy = this.store.getProxy();
diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartManager.php b/src/de/RaumZeitLabor/PartDB2/Part/PartManager.php
@@ -24,7 +24,7 @@ use de\RaumZeitLabor\PartDB2\Util\Singleton,
de\RaumZeitLabor\PartDB2\Footprint\Exceptions\FootprintNotFoundException;
class PartManager extends Singleton {
- public function getParts ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "", $category = 0) {
+ public function getParts ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "", $category = 0, $categoryScope = "all") {
$qb = PartDB2::getEM()->createQueryBuilder();
$qb->select("COUNT(p.id)")->from("de\RaumZeitLabor\PartDB2\Part\Part","p")
@@ -58,9 +58,14 @@ class PartManager extends Singleton {
if ($category !== 0) {
/* Fetch all children */
- $childs = CategoryManager::getInstance()->getChildNodes($category);
- $childs[] = $category;
- $qb->andWhere("p.category IN (".implode(",", $childs).")");
+ if ($categoryScope == "selected") {
+ $qb->andWhere("p.category = :category");
+ $qb->setParameter("category", $category);
+ } else {
+ $childs = CategoryManager::getInstance()->getChildNodes($category);
+ $childs[] = $category;
+ $qb->andWhere("p.category IN (".implode(",", $childs).")");
+ }
}
$totalQuery = $qb->getQuery();
diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartService.php b/src/de/RaumZeitLabor/PartDB2/Part/PartService.php
@@ -30,7 +30,8 @@ class PartService extends Service implements RestfulService {
$this->getParameter("sortby", $aSortParams["property"]),
$this->getParameter("dir", $aSortParams["direction"]),
$this->getParameter("query", ""),
- $this->getParameter("category", 0));
+ $this->getParameter("category", 0),
+ $this->getParameter("categoryScope", "all"));
}
}