partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 43499cf56858efaf36053b6c1040c5c04ec5b67e
parent 9dadcbae2dbfdff59f6864aa28a13570e3b20632
Author: Timo A. Hummel <timo@netraver.de>
Date:   Mon, 23 May 2011 18:49:20 +0200

New: Adding parts to database

Diffstat:
Mfrontend/js/de.RaumZeitLabor.PartDB2/PartsManager/PartsManagerAddPartForm.js | 110+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Msrc/de/RaumZeitLabor/PartDB2/Part/PartManager.php | 38++++++++++++++++++++++++++++++++++++++
Msrc/de/RaumZeitLabor/PartDB2/Part/PartManagerService.php | 15+++++++++++++++
Msrc/de/RaumZeitLabor/PartDB2/StorageLocation/StorageLocationManager.php | 10++++++++++
4 files changed, 171 insertions(+), 2 deletions(-)

diff --git a/frontend/js/de.RaumZeitLabor.PartDB2/PartsManager/PartsManagerAddPartForm.js b/frontend/js/de.RaumZeitLabor.PartDB2/PartsManager/PartsManagerAddPartForm.js @@ -4,6 +4,7 @@ de.RaumZeitLabor.PartDB2.PartsManagerAddPartForm = Ext.extend(Ext.form.FormPanel frame: true, border: false, monitorValid: true, + mode: 'add', initComponent: function () { @@ -27,6 +28,23 @@ de.RaumZeitLabor.PartDB2.PartsManagerAddPartForm = Ext.extend(Ext.form.FormPanel flex: 1 }); + this.categoryComboBox = new de.RaumZeitLabor.PartDB2.CategoryComboBox({ + fieldLabel: 'Kategorie', + name: 'parent', + anchor: '100%', + style: 'margin-bottom: 8px;', + validator: function (value) { + if (value == "") { + return "Es muß eine Kategorie ausgewählt werden"; + } + return true; + }.createDelegate(this), + }); + + this.commentField = new Ext.form.TextArea({ + fieldLabel: 'Kommentar', + anchor: '100%', + }); // @todo Put the storage location combobox into an own component this.storageLocationCall = new org.jerrymouse.service.Call( @@ -52,7 +70,13 @@ de.RaumZeitLabor.PartDB2.PartsManagerAddPartForm = Ext.extend(Ext.form.FormPanel anchor: '100%', mode: 'local', valueField: "id", - fieldLabel: "Lagerort" + fieldLabel: "Lagerort", + validator: function (value) { + if (value == "") { + return "Ein Lagerort muß ausgewählt oder eingegeben werden"; + } + + }.createDelegate(this) }); // @todo Put the footprint combobox into an own component @@ -75,6 +99,14 @@ de.RaumZeitLabor.PartDB2.PartsManagerAddPartForm = Ext.extend(Ext.form.FormPanel }); this.footprintCombo = new Ext.form.ComboBox({ + validator: function (value) { + return true; + /*if (value == "") { + return "Es muß ein Footprint ausgewählt werden"; + } + console.log(this.footprintCombo.getValue()); + console.log(value);*/ + }.createDelegate(this), store: this.footprintStore, displayField: "footprint", anchor: '100%', @@ -84,6 +116,7 @@ de.RaumZeitLabor.PartDB2.PartsManagerAddPartForm = Ext.extend(Ext.form.FormPanel }); this.items = [ + this.categoryComboBox, this.partName, { xtype: "compositefield", @@ -99,10 +132,83 @@ de.RaumZeitLabor.PartDB2.PartsManagerAddPartForm = Ext.extend(Ext.form.FormPanel ] }, this.partStorageLocation, - this.footprintCombo]; + this.footprintCombo, + this.commentField + ]; + var btntext; + + if (this.mode == "add") { + btntext = "Hinzufügen"; + } else { + btntext = "Speichern"; + } + + this.addButton = new Ext.Button({ + text: btntext, + handler: this.onAddAction.createDelegate(this) + }); + + this.cancelButton = new Ext.Button({ + text: "Abbrechen" + }); + this.buttons = [ + this.addButton, + this.cancelButton + ]; de.RaumZeitLabor.PartDB2.PartsManagerAddPartForm.superclass.initComponent.call(this); }, + isStoreLocationInList: function () { + var foundId = this.partStorageLocation.store.findExact("id", this.partStorageLocation.getValue()); + var foundName = this.partStorageLocation.store.findExact("name", this.partStorageLocation.getValue()); + + if (foundId !== -1) { + return true; + } else if (foundName !== -1) { + return true; + } else { + return false; + } + }, + getStoreLocation: function () { + var foundId = this.partStorageLocation.store.findExact("id", this.partStorageLocation.getValue()); + var foundName = this.partStorageLocation.store.findExact("name", this.partStorageLocation.getValue()); + + if (foundId !== -1) { + return foundId; + } + + if (foundName !== 1) { + return foundName; + } + + return null; + }, + onAddAction: function () { + if (this.getForm().isValid()) { + + if (this.mode == "add") { + 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"); + } + + 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("footprint", this.footprintCombo.getValue()); + call.setParameter("comment", this.commentField.getValue()); + + //call.setHandler(this.onCategoriesLoaded.createDelegate(this)) + call.doCall(); + } + }, reloadStorageLocations: function () { this.storageLocationStore.reload(); this.footprintStore.reload(); diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartManager.php b/src/de/RaumZeitLabor/PartDB2/Part/PartManager.php @@ -1,5 +1,12 @@ <?php namespace de\raumzeitlabor\PartDB2\Part; +use de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation; + +use de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocationManager; + +use de\RaumZeitLabor\PartDB2\Part\Part; +use de\RaumZeitLabor\PartDB2\Footprint\FootprintManager; + declare(encoding = 'UTF-8'); use de\RaumZeitLabor\PartDB2\Util\Singleton, @@ -107,6 +114,37 @@ class PartManager extends Singleton { return array("parts" => $result, "totalCount" => $count); } + public function addPart ($aParameters) { + + $part = new Part(); + $part->setName($aParameters["name"]); + $part->setMinStockLevel($aParameters["minstock"]); + $part->setComment($aParameters["comment"]); + + try { + $footprint = FootprintManager::getInstance()->getFootprint($aParameters["footprint"]); + $part->setFootprint($footprint); + } catch (\Exception $e) {} + + try { + $storageLocation = StorageLocationManager::getInstance()->getStorageLocation($aParameters["storagelocation"]); + $part->setStorageLocation($storageLocation); + } catch (\Exception $e) { + $storageLocation = new StorageLocation(); + $storageLocation->setName($aParameters["storagelocation"]); + $part->setStorageLocation($storageLocation); + + PartDB2::getEM()->persist($storageLocation); + } + + + $category = CategoryManager::getInstance()->getCategory($aParameters["category"]); + $part->setCategory($category->getNode()); + + PartDB2::getEM()->persist($part); + PartDB2::getEM()->flush(); + + } public function deletePart ($id) { $part = PartManager::getInstance()->getPart($id); diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartManagerService.php b/src/de/RaumZeitLabor/PartDB2/Part/PartManagerService.php @@ -38,6 +38,21 @@ class PartManagerService extends Service { return true; } + public function addPart () { + $aParameters = array(); + + $aParameters["category"] = $this->getParameter("category"); + $aParameters["name"] = $this->getParameter("name"); + $aParameters["quantity"] = $this->getParameter("quantity"); + $aParameters["minstock"] = $this->getParameter("minstock"); + $aParameters["storagelocation"] = $this->getParameter("storagelocation"); + $aParameters["footprint"] = $this->getParameter("footprint"); + $aParameters["comment"] = $this->getParameter("comment"); + + PartManager::getInstance()->addPart($aParameters); + + } + public function deleteStock () { $part = PartManager::getInstance()->getPart($this->getParameter("part")); diff --git a/src/de/RaumZeitLabor/PartDB2/StorageLocation/StorageLocationManager.php b/src/de/RaumZeitLabor/PartDB2/StorageLocation/StorageLocationManager.php @@ -26,4 +26,14 @@ class StorageLocationManager extends Singleton { return array("storageLocations" => $result, "totalCount" => $count); } + + public function getStorageLocation ($id) { + $storageLocation = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation", $id); + + if ($storageLocation) { + return $storageLocation; + } else { + throw new \Exception("StorageLocation not found"); + } + } } \ No newline at end of file