commit 57238f61a627c5e3c19149569dbbed1444803adf
parent 2159771cdfb1884701df82a6b1b1d6450039e353
Author: Felicitus <felicitus@felicitus.org>
Date: Tue, 21 Jun 2011 13:14:13 +0200
Reworked manufacturers to the new nested record method
Diffstat:
5 files changed, 64 insertions(+), 31 deletions(-)
diff --git a/frontend/js/Components/Manufacturer/ManufacturerEditor.js b/frontend/js/Components/Manufacturer/ManufacturerEditor.js
@@ -93,21 +93,16 @@ Ext.define('PartKeepr.ManufacturerEditor', {
}];
- this.on("itemSaved", this.syncSlaveStores, this);
+ this.on("itemSaved", this._onItemSaved, this);
this.callParent();
},
- syncSlaveStores: function () {
- this.iclogoGrid.store.each(function (record) {
- record.set("manufacturer_id", this.record.get("id"));
- }, this);
-
- this.iclogoGrid.store.sync();
+ _onItemSaved: function (record) {
+ this.iclogoGrid.bindStore(record.iclogos());
},
onFileUploaded: function (response) {
this.iclogoGrid.getStore().add({
- type: 'tmp',
- tmp_id: response.id,
+ id: "TMP:"+response.id,
manufacturer_id: this.record.get("id")
});
},
diff --git a/frontend/js/Models/ManufacturerICLogo.js b/frontend/js/Models/ManufacturerICLogo.js
@@ -1,10 +1,13 @@
Ext.define("PartKeepr.ManufacturerICLogo", {
extend: "Ext.data.Model",
fields: [
- { id: 'id', name: 'id', type: 'int' },
- { name: 'manufacturer_id', type: 'int' },
- { name: 'type', type: 'string' },
- { name: 'tmp_id', type: 'int' }
+ { id: 'id', name: 'id', type: 'string' },
+ { name: 'originalFilename', type: 'string' },
+ { name: 'footprint_id', type: 'int' },
+ { name: 'mimetype', type: 'string' },
+ { name: 'extension', type: 'string' },
+ { name: 'description', type: 'string' },
+ { name: 'size', type: 'string' }
],
belongsTo: { type: 'belongsTo', model: 'PartKeepr.Manufacturer', primaryKey: 'id', foreignKey: 'manufacturer_id'},
proxy: PartKeepr.getRESTProxy("ManufacturerICLogo")
diff --git a/src/de/RaumZeitLabor/PartKeepr/Manufacturer/Manufacturer.php b/src/de/RaumZeitLabor/PartKeepr/Manufacturer/Manufacturer.php
@@ -1,5 +1,7 @@
<?php
namespace de\RaumZeitLabor\PartKeepr\Manufacturer;
+use de\RaumZeitLabor\PartKeepr\Util\Deserializable;
+
use de\RaumZeitLabor\PartKeepr\Util\Serializable;
use de\RaumZeitLabor\PartKeepr\Util\BaseEntity;
@@ -11,7 +13,7 @@ use de\RaumZeitLabor\PartKeepr\PartKeepr;
/**
* Represents a manufacturer
* @Entity **/
-class Manufacturer extends BaseEntity implements Serializable {
+class Manufacturer extends BaseEntity implements Serializable, Deserializable {
/**
* The name of the manufacturer
* @Column(type="string",unique=true)
@@ -209,4 +211,36 @@ class Manufacturer extends BaseEntity implements Serializable {
"iclogos" => $this->serializeChildren($this->getICLogos())
);
}
+
+ /**
+ * Deserializes the footprint
+ * @param array $parameters The array with the parameters to set
+ */
+ public function deserialize (array $parameters) {
+ foreach ($parameters as $key => $value) {
+ switch ($key) {
+ case "name":
+ $this->setName($value);
+ break;
+ case "url":
+ $this->setURL($value);
+ break;
+ case "comment":
+ $this->setComment($value);
+ break;
+ case "email":
+ $this->setEmail($value);
+ break;
+ case "address":
+ $this->setAddress($value);
+ break;
+ case "iclogos":
+ $this->deserializeChildren($value, $this->getICLogos(), "de\RaumZeitLabor\PartKeepr\Manufacturer\ManufacturerICLogo");
+ foreach ($this->getICLogos() as $iclogo) {
+ $iclogo->setManufacturer($this);
+ }
+ break;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/de/RaumZeitLabor/PartKeepr/Manufacturer/ManufacturerICLogo.php b/src/de/RaumZeitLabor/PartKeepr/Manufacturer/ManufacturerICLogo.php
@@ -1,5 +1,7 @@
<?php
namespace de\RaumZeitLabor\PartKeepr\Manufacturer;
+use de\RaumZeitLabor\PartKeepr\Util\Deserializable;
+
use de\RaumZeitLabor\PartKeepr\Util\Serializable;
declare(encoding = 'UTF-8');
@@ -10,7 +12,7 @@ use de\RaumZeitLabor\PartKeepr\Image\Image;
* Holds a manufacturer IC logo
* @Entity
**/
-class ManufacturerICLogo extends Image implements Serializable {
+class ManufacturerICLogo extends Image implements Serializable, Deserializable {
/**
* The manufacturer object
* @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer")
@@ -49,4 +51,16 @@ class ManufacturerICLogo extends Image implements Serializable {
public function serialize () {
return array("id" => $this->getId(), "manufacturer_id" => $this->getManufacturer()->getId());
}
+
+ /**
+ * Deserializes the iclogo
+ * @param array $parameters The array with the parameters to set
+ */
+ public function deserialize (array $parameters) {
+ if (array_key_exists("id", $parameters)) {
+ if (substr($parameters["id"], 0, 4) === "TMP:") {
+ $this->replaceFromTemporaryFile($parameters["id"]);
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/de/RaumZeitLabor/PartKeepr/Manufacturer/ManufacturerService.php b/src/de/RaumZeitLabor/PartKeepr/Manufacturer/ManufacturerService.php
@@ -45,8 +45,7 @@ class ManufacturerService extends Service implements RestfulService {
$this->requireParameter("name");
$manufacturer = new Manufacturer;
-
- $this->setManufacturerData($manufacturer);
+ $manufacturer->deserialize($this->getParameters());
PartKeepr::getEM()->persist($manufacturer);
PartKeepr::getEM()->flush();
@@ -55,18 +54,6 @@ class ManufacturerService extends Service implements RestfulService {
}
/**
- * Sets the data for the manufacturer.
- * @param Manufacturer $manufacturer The manufacturer to process
- */
- private function setManufacturerData (Manufacturer $manufacturer) {
- $manufacturer->setName($this->getParameter("name"));
- $manufacturer->setComment($this->getParameter("comment", ""));
- $manufacturer->setAddress($this->getParameter("address", ""));
- $manufacturer->setURL($this->getParameter("url", ""));
- $manufacturer->setEmail($this->getParameter("email", ""));
- }
-
- /**
* (non-PHPdoc)
* @see de\RaumZeitLabor\PartKeepr\Service.RestfulService::update()
*/
@@ -74,8 +61,8 @@ class ManufacturerService extends Service implements RestfulService {
$this->requireParameter("id");
$this->requireParameter("name");
$manufacturer = ManufacturerManager::getInstance()->getManufacturer($this->getParameter("id"));
-
- $this->setManufacturerData($manufacturer);
+ $manufacturer->deserialize($this->getParameters());
+
PartKeepr::getEM()->flush();
return array("data" => $manufacturer->serialize());