commit d49637160a86e634277f883deb8fa1f67d9ca7d7
parent 581651316d4ad4233626c2f1639b3bcd57ab6c0b
Author: Felicitus <privat@timohummel.com>
Date: Mon, 23 May 2011 21:50:55 +0200
Finalized part editing
Diffstat:
6 files changed, 161 insertions(+), 30 deletions(-)
diff --git a/frontend/js/de.RaumZeitLabor.PartDB2/PartsManager/PartsManagerAddPartDialog.js b/frontend/js/de.RaumZeitLabor.PartDB2/PartsManager/PartsManagerAddPartDialog.js
@@ -27,7 +27,24 @@ de.RaumZeitLabor.PartDB2.PartsManagerAddPartDialog = Ext.extend(Ext.Window, {
this.hide();
}.createDelegate(this));
+ this.addPartForm.on("partloaded", this.onPartLoaded.createDelegate(this));
+ this.addPartForm.on("partSaved", this.onPartSaved.createDelegate(this));
+
de.RaumZeitLabor.PartDB2.PartsManagerAddPartDialog.superclass.initComponent.call(this);
+ },
+ addPart: function () {
+ this.addPartForm.setAddMode();
+ this.addPartForm.clearForm(true);
+ this.show();
+ },
+ editPart: function (part) {
+ this.addPartForm.loadPart(part);
+ },
+ onPartSaved: function () {
+ this.hide();
+ },
+ onPartLoaded: function () {
+ this.show();
}
});
\ No newline at end of file
diff --git a/frontend/js/de.RaumZeitLabor.PartDB2/PartsManager/PartsManagerAddPartForm.js b/frontend/js/de.RaumZeitLabor.PartDB2/PartsManager/PartsManagerAddPartForm.js
@@ -46,6 +46,11 @@ de.RaumZeitLabor.PartDB2.PartsManagerAddPartForm = Ext.extend(Ext.form.FormPanel
anchor: '100%',
});
+ this.partQuantityDisplay = new Ext.form.DisplayField({
+ fieldLabel: 'Aktuelle Stückzahl',
+ hidden: true,
+ width: 100
+ });
// @todo Put the storage location combobox into an own component
this.storageLocationCall = new org.jerrymouse.service.Call(
"de.RaumZeitLabor.PartDB2.StorageLocation.StorageLocationService",
@@ -127,6 +132,7 @@ de.RaumZeitLabor.PartDB2.PartsManagerAddPartForm = Ext.extend(Ext.form.FormPanel
xtype: "compositefield",
fieldLabel: "Stück",
items: [
+ this.partQuantityDisplay,
this.partQuantity,
{
xtype: "label",
@@ -167,7 +173,7 @@ de.RaumZeitLabor.PartDB2.PartsManagerAddPartForm = Ext.extend(Ext.form.FormPanel
];
- this.addEvents("cancelEntry");
+ this.addEvents("cancelEntry", "partLoaded", "partSaved");
de.RaumZeitLabor.PartDB2.PartsManagerAddPartForm.superclass.initComponent.call(this);
},
isStoreLocationInList: function () {
@@ -199,21 +205,20 @@ de.RaumZeitLabor.PartDB2.PartsManagerAddPartForm = Ext.extend(Ext.form.FormPanel
onAddAction: function () {
if (this.getForm().isValid()) {
- if (this.mode == "add") {
- var call = new org.jerrymouse.service.Call(
+ var call = new org.jerrymouse.service.Call(
"de.RaumZeitLabor.PartDB2.Part.PartManagerService",
- "addPart");
- } else {
- var call = new org.jerrymouse.service.Call(
- "de.RaumZeitLabor.PartDB2.Part.PartManagerService",
- "updatePart");
+ "addOrUpdatePart");
+
+ if (this.mode == "edit") {
+ call.setParameter("part", this.partId)
}
call.setParameter("category", this.categoryComboBox.parentId)
call.setParameter("name", this.partName.getValue());
call.setParameter("quantity", this.partQuantity.getValue());
call.setParameter("minstock", this.partMinStock.getValue());
- call.setParameter("storagelocation", this.partStorageLocation.getValue());
+
+ call.setParameter("storagelocation", this.getStorageLocation());
call.setParameter("footprint", this.footprintCombo.getValue());
call.setParameter("comment", this.commentField.getValue());
@@ -221,31 +226,100 @@ de.RaumZeitLabor.PartDB2.PartsManagerAddPartForm = Ext.extend(Ext.form.FormPanel
call.doCall();
}
},
+ getStorageLocation: function () {
+ var idx = this.partStorageLocation.store.findExact("id", this.partStorageLocation.getValue());
+
+ if (idx !== -1) {
+ return this.partStorageLocation.store.getAt(idx).get("id");
+ }
+
+ var idx = this.partStorageLocation.store.findExact("name", this.partStorageLocation.getValue());
+
+ if (idx !== -1) {
+ return this.partStorageLocation.store.getAt(idx).get("id");
+ }
+
+ return idx;
+ },
onPartAdded: function () {
this.clearForm();
+ if (this.mode == "edit") {
+ this.fireEvent("partSaved");
+ }
},
onCancelAction: function () {
this.clearForm(true);
this.fireEvent("cancelEntry");
},
+ loadPart: function (part) {
+ var call = new org.jerrymouse.service.Call(
+ "de.RaumZeitLabor.PartDB2.Part.PartManagerService",
+ "getPart");
+
+ this.setEditMode(part);
+
+ call.setParameter("part", part);
+ call.setHandler(this.onPartLoaded.createDelegate(this));
+ call.doCall();
+ },
+ setEditMode: function (part) {
+ this.mode = "edit";
+ this.partQuantity.disable();
+ this.keepStorageLocation.hide();
+ this.partId = part;
+ this.partQuantityDisplay.show();
+ this.partQuantity.hide();
+ this.addButton.setText("Speichern");
+ },
+ setAddMode: function () {
+ this.mode = "add";
+ this.keepStorageLocation.show();
+ this.partQuantity.enable();
+ this.partId = null;
+ this.partQuantityDisplay.hide();
+ this.partQuantity.show();
+ this.addButton.setText("Hinzufügen");
+ },
+ onPartLoaded: function (response) {
+
+ this.commentField.setValue(response.comment);
+ this.footprintCombo.setValue(response.footprint.footprint);
+ this.partMinStock.setValue(response.minStockLevel);
+ this.partName.setValue(response.name);
+
+ if (this.mode == "edit") {
+ this.partQuantityDisplay.setValue(response.stockLevel);
+ } else {
+ this.partQuantity.setValue(response.stockLevel);
+ }
+
+ this.partStorageLocation.setValue(response.storageLocation.name);
+
+ this.categoryComboBox.setValue(response.category.name);
+ this.categoryComboBox.parentId = response.category.id;
+
+ this.fireEvent("partLoaded");
+ },
clearForm: function (force) {
- this.partName.reset();
- this.partQuantity.reset();
- this.partMinStock.reset();
- this.footprintCombo.reset();
- this.commentField.reset();
+ this.partName.setRawValue("");
+ this.partQuantity.setRawValue(0);
+ this.partMinStock.setRawValue(0);
+ this.footprintCombo.setRawValue("");
+ this.commentField.setRawValue("");
if (this.keepStorageLocation.getValue() !== true || force == true)
{
- this.partStorageLocation.reset();
+ this.partStorageLocation.setRawValue("");
}
+ this.categoryComboBox.setValue("");
+ this.categoryComboBox.parentId = null;
+
this.partName.focus(false, 10);
},
reloadStorageLocations: function () {
this.storageLocationStore.reload();
this.footprintStore.reload();
}
-});
- -
\ No newline at end of file
+});+
\ No newline at end of file
diff --git a/frontend/js/de.RaumZeitLabor.PartDB2/PartsManager/PartsManagerListGrid.js b/frontend/js/de.RaumZeitLabor.PartDB2/PartsManager/PartsManagerListGrid.js
@@ -26,6 +26,8 @@ de.RaumZeitLabor.PartDB2.PartsManagerListGrid = Ext.extend(Ext.grid.GridPanel, {
this.sm = new Ext.grid.RowSelectionModel({ singleSelect: true });
+ this.sm.on("selectionchange", this.onSelectionChange.createDelegate(this));
+
this.addPartDialog = new de.RaumZeitLabor.PartDB2.PartsManagerAddPartDialog();
this.store = new Ext.data.JsonStore({
@@ -83,9 +85,18 @@ de.RaumZeitLabor.PartDB2.PartsManagerListGrid = Ext.extend(Ext.grid.GridPanel, {
handler: this.onPartAdd.createDelegate(this)
});
+ this.editPartButton = new Ext.Button({
+ text: "Bauteil editieren",
+ cls:'x-btn-text-icon',
+ icon: 'resources/silkicons/brick_edit.png',
+ disabled: true,
+ handler: this.onPartEdit.createDelegate(this)
+ });
+
this.deletePartButton = new Ext.Button({
text: "Bauteil löschen",
cls:'x-btn-text-icon',
+ disabled: true,
icon: 'resources/silkicons/brick_delete.png',
handler: this.onPartDelete.createDelegate(this)
});
@@ -97,13 +108,17 @@ de.RaumZeitLabor.PartDB2.PartsManagerListGrid = Ext.extend(Ext.grid.GridPanel, {
displayInfo: false,
items: [
this.addPartButton,
+ this.editPartButton,
this.deletePartButton
]
});
de.RaumZeitLabor.PartDB2.PartsManagerListGrid.superclass.initComponent.call(this);
},
onPartAdd: function () {
- this.addPartDialog.show();
+ this.addPartDialog.addPart();
+ },
+ onPartEdit: function () {
+ this.addPartDialog.editPart(this.getSelectionModel().getSelected().get("id"));
},
onPartDelete: function () {
var r = this.getSelectionModel().getSelected();
@@ -129,5 +144,14 @@ de.RaumZeitLabor.PartDB2.PartsManagerListGrid = Ext.extend(Ext.grid.GridPanel, {
},
setLimitCategory: function (category) {
this.limitCategory = category;
+ },
+ onSelectionChange: function () {
+ if (this.getSelectionModel().getCount() == 0) {
+ this.editPartButton.disable();
+ this.deletePartButton.disable();
+ } else {
+ this.editPartButton.enable();
+ this.deletePartButton.enable();
+ }
}
});
\ No newline at end of file
diff --git a/src/de/RaumZeitLabor/PartDB2/Part/Part.php b/src/de/RaumZeitLabor/PartDB2/Part/Part.php
@@ -99,7 +99,8 @@ class Part {
"stockLevel" => $this->getStockLevel(),
"footprint" => is_object($this->footprint) ? $this->footprint->serialize() : null,
"minStockLevel" => $this->minStockLevel,
- "storageLocation" => is_object($this->storageLocation) ? $this->storageLocation->serialize() : null
+ "storageLocation" => is_object($this->storageLocation) ? $this->storageLocation->serialize() : null,
+ "category" => $this->category->serialize()
);
diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartManager.php b/src/de/RaumZeitLabor/PartDB2/Part/PartManager.php
@@ -116,9 +116,27 @@ class PartManager extends Singleton {
return array("parts" => $result, "totalCount" => $count);
}
- public function addPart ($aParameters) {
+ public function addOrUpdatePart ($aParameters) {
+
+ if ($aParameters["part"] !== null) {
+ try {
+ $part = $this->getPart($aParameters["part"]);
+ } catch (\Exception $e) {
+ $part = new Part();
+ $user = SessionManager::getCurrentSession()->getUser();
+
+ $stock = new StockEntry($part, $aParameters["quantity"], $user);
+ PartDB2::getEM()->persist($stock);
+ }
+ } else {
+ $part = new Part();
+
+ $user = SessionManager::getCurrentSession()->getUser();
+
+ $stock = new StockEntry($part, $aParameters["quantity"], $user);
+ PartDB2::getEM()->persist($stock);
+ }
- $part = new Part();
$part->setName($aParameters["name"]);
$part->setMinStockLevel($aParameters["minstock"]);
$part->setComment($aParameters["comment"]);
@@ -143,12 +161,7 @@ class PartManager extends Singleton {
$category = CategoryManager::getInstance()->getCategory($aParameters["category"]);
$part->setCategory($category->getNode());
- $user = SessionManager::getCurrentSession()->getUser();
-
- $stock = new StockEntry($part, $aParameters["quantity"], $user);
-
PartDB2::getEM()->persist($part);
- PartDB2::getEM()->persist($stock);
PartDB2::getEM()->flush();
}
diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartManagerService.php b/src/de/RaumZeitLabor/PartDB2/Part/PartManagerService.php
@@ -38,9 +38,11 @@ class PartManagerService extends Service {
return true;
}
- public function addPart () {
+ public function addOrUpdatePart () {
$aParameters = array();
+ $aParameters["part"] = $this->getParameter("part", null);
+
$aParameters["category"] = $this->getParameter("category");
$aParameters["name"] = $this->getParameter("name");
$aParameters["quantity"] = $this->getParameter("quantity");
@@ -49,11 +51,11 @@ class PartManagerService extends Service {
$aParameters["footprint"] = $this->getParameter("footprint");
$aParameters["comment"] = $this->getParameter("comment");
- PartManager::getInstance()->addPart($aParameters);
+ PartManager::getInstance()->addOrUpdatePart($aParameters);
return true;
}
-
+
public function deleteStock () {
$part = PartManager::getInstance()->getPart($this->getParameter("part"));