commit 7315a0bb868dc7edf9db687073016442eb45b1fa
parent b42d71aadd2f18fa1f7bb1865234c4b1d4a1b178
Author: Felicitus <felicitus@felicitus.org>
Date: Thu, 30 Jun 2011 02:49:33 +0200
Admins can now edit the user for stock history changes
Diffstat:
4 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/frontend/js/Components/Part/PartStockHistory.js b/frontend/js/Components/Part/PartStockHistory.js
@@ -17,7 +17,25 @@ Ext.define('PartKeepr.PartStockHistory', {
},
width: 20
},
- {header: i18n("User"), dataIndex: 'username', flex: 0.4, minWidth: 80 },
+ {
+ header: i18n("User"),
+ dataIndex: 'user_id',
+ flex: 0.4,
+ minWidth: 80,
+ renderer: function (val) {
+ var rec = PartKeepr.getApplication().getUserStore().findRecord("id", val);
+
+ if (rec) {
+ return rec.get("username");
+ } else {
+ return i18n("Unknown user");
+ }
+
+ },
+ editor: {
+ xtype: 'UserComboBox'
+ }
+ },
{header: i18n("Amount"), dataIndex: 'amount', width: 50,
editor: {
xtype:'numberfield',
@@ -95,6 +113,12 @@ Ext.define('PartKeepr.PartStockHistory', {
if (!PartKeepr.getApplication().isAdmin()) {
return false;
}
+ break;
+ case "user":
+ if (!PartKeepr.getApplication().isAdmin()) {
+ return false;
+ }
+ break;
}
},
/**
diff --git a/frontend/js/Models/StockEntry.js b/frontend/js/Models/StockEntry.js
@@ -3,6 +3,7 @@ Ext.define("PartKeepr.StockEntry", {
fields: [
{ id: 'id', name: 'id', type: 'int' },
{ name: 'username', type: 'string'},
+ { name: 'user_id', type: 'int'},
{ name: 'datetime', type: 'datetime'},
{ name: 'amount', type: 'int'},
{ name: 'direction', type: 'string'},
diff --git a/src/de/RaumZeitLabor/PartKeepr/Stock/StockEntry.php b/src/de/RaumZeitLabor/PartKeepr/Stock/StockEntry.php
@@ -195,6 +195,7 @@ class StockEntry extends BaseEntity implements Serializable {
return array(
"id" => $this->getId(),
"username" => is_object($this->getUser()) ? $this->getUser()->getUsername() : PartKeepr::i18n("Unknown User"),
+ "user_id" => is_object($this->getUser()) ? $this->getUser()->getId() : null,
"amount" => abs($this->getStockLevel()),
"datetime" => $this->getDateTime()->format("Y-m-d H:i:s"),
"direction" => ($this->getStockLevel() < 0) ? "out" : "in",
diff --git a/src/de/RaumZeitLabor/PartKeepr/Stock/StockService.php b/src/de/RaumZeitLabor/PartKeepr/Stock/StockService.php
@@ -5,6 +5,7 @@ declare(encoding = 'UTF-8');
use de\RaumZeitLabor\PartKeepr\Stock\StockEntry,
de\RaumZeitLabor\PartKeepr\PartKeepr,
+ de\RaumZeitLabor\PartKeepr\User\User,
de\RaumZeitLabor\PartKeepr\Session\SessionManager,
de\RaumZeitLabor\PartKeepr\Service\RestfulService,
de\RaumZeitLabor\PartKeepr\Service\Service;;
@@ -26,6 +27,7 @@ class StockService extends Service implements RestfulService {
foreach ($results as $result) {
$aData[] = array(
"username" => is_object($result->getUser()) ? $result->getUser()->getUsername() : PartKeepr::i18n("Unknown User"),
+ "user_id" => is_object($result->getUser()) ? $result->getUser()->getId() : null,
"amount" => abs($result->getStockLevel()),
"datetime" => $result->getDateTime()->format("Y-m-d H:i:s"),
"id" => $result->getId(),
@@ -68,6 +70,15 @@ class StockService extends Service implements RestfulService {
$stockEntry->setStockLevel($this->getParameter("amount"));
}
+ if (SessionManager::getCurrentSession()->getUser()->isAdmin()) {
+ try {
+ $stockEntry->setUser(User::loadById($this->getParameter("user_id")));
+ } catch (\Exception $e) {
+ $stockEntry->setUser(null);
+ }
+
+ }
+
PartKeepr::getEM()->flush();
return array("data" => $stockEntry->serialize());