commit 18a58d9e07e8d92dc92e0067550e288147d9f973
parent fae7843ef8af91447fe3e66c676bc723b9ddc574
Author: Timo A. Hummel <timo@netraver.de>
Date: Tue, 7 Jun 2011 11:00:02 +0200
Modified part unit handling: We now have a default part unit in the database, which can be changed via the GUI.
Diffstat:
13 files changed, 139 insertions(+), 19 deletions(-)
diff --git a/frontend/index.html b/frontend/index.html
@@ -31,6 +31,7 @@
<script type="text/javascript" src="js/Ext.ux/ClearableComboBox.js"></script>
<script type="text/javascript" src="js/Ext.ux/TabCloseMenu.js"></script>
+ <script type="text/javascript" src="js/Ext.ux/Ext.ux.CheckboxValue.js"></script>
<script type="text/javascript" src="js/Components/Widgets/CategoryComboBox.js"></script>
<script type="text/javascript" src="js/Components/Widgets/StorageLocationComboBox.js"></script>
diff --git a/frontend/js/Components/Editor/EditorGrid.js b/frontend/js/Components/Editor/EditorGrid.js
@@ -48,9 +48,7 @@ Ext.define('PartDB2.EditorGrid', {
}, this)
},
this.deleteButton,
- {
- xtype: 'tbfill'
- },
+ { xtype: 'tbfill' },
this.searchField]
});
diff --git a/frontend/js/Components/Part/PartEditor.js b/frontend/js/Components/Part/PartEditor.js
@@ -1,6 +1,5 @@
Ext.define('PartDB2.PartEditor', {
extend: 'PartDB2.Editor',
- autoScroll: true,
border: false,
model: 'PartDB2.Part',
mode: 'add',
@@ -60,6 +59,7 @@ Ext.define('PartDB2.PartEditor', {
items: [{
xtype: 'panel',
border: false,
+ autoScroll: true,
layout: 'anchor',
defaults: {
anchor: '100%',
diff --git a/frontend/js/Components/Part/PartsGrid.js b/frontend/js/Components/Part/PartsGrid.js
@@ -200,6 +200,8 @@ Ext.define('PartDB2.PartsGrid', {
proxy.extraParams.stockMode = this.stockMode;
},
setCategory: function (category) {
+ this.currentCategory = category;
+
var proxy = this.store.getProxy();
proxy.extraParams.category = category;
diff --git a/frontend/js/Components/Part/PartsManager.js b/frontend/js/Components/Part/PartsManager.js
@@ -60,7 +60,15 @@ Ext.define('PartDB2.PartManager', {
},
onItemAdd: function () {
var j = Ext.create("PartDB2.PartEditorWindow");
- j.applyRecord({});
+
+ var defaults = {};
+
+ var defaultPartUnit = PartDB2.getApplication().getPartUnitStore().find("default", true);
+
+ defaults.partUnit_id = defaultPartUnit;
+ defaults.category_id = this.grid.currentCategory;
+
+ j.applyRecord(defaults);
j.show();
},
onEditPart: function (id) {
diff --git a/frontend/js/Components/PartUnit/PartUnitGrid.js b/frontend/js/Components/PartUnit/PartUnitGrid.js
@@ -2,8 +2,47 @@ Ext.define('PartDB2.PartUnitGrid', {
extend: 'PartDB2.EditorGrid',
alias: 'widget.PartUnitGrid',
columns: [
- {header: i18n("Part Unit"), dataIndex: 'name', flex: 1}
+ {header: i18n("Part Unit"), dataIndex: 'name', flex: 1},
+ {header: i18n("Default"), dataIndex: 'default', width: 60, renderer: function (val) { if (val === true) { return "✓"; } else { return ""; }}}
],
addButtonText: i18n("Add Part Unit"),
- deleteButtonText: i18n("Delete Part Unit")
+ deleteButtonText: i18n("Delete Part Unit"),
+ initComponent: function () {
+ this.callParent();
+
+ this.defaultButton = Ext.create("Ext.button.Button", {
+ icon: 'resources/silkicons/accept.png',
+ tooltip: i18n('Mark Item as Default'),
+ disabled: true,
+ handler: this.onDefaultClick,
+ scope: this
+ });
+
+ this.getSelectionModel().on("deselect",
+ Ext.bind(function (rsm, r, i) {
+ this.defaultButton.disable();
+ }, this));
+
+ this.getSelectionModel().on("select",
+ Ext.bind(function (rsm, r, i) {
+ this.defaultButton.enable();
+ }, this));
+ this.topToolbar.insert(2, {xtype: 'tbseparator'});
+ this.topToolbar.insert(3, this.defaultButton);
+ },
+ onDefaultClick: function () {
+ var r = this.getSelectionModel().getLastSelected();
+
+ var call = new PartDB2.ServiceCall(
+ "PartUnit",
+ "setDefault");
+
+ call.setParameter("id", r.get("id"));
+
+ call.setHandler(Ext.bind(this.onDefaultHandler, this));
+ call.doCall();
+ },
+ onDefaultHandler: function () {
+ this.store.load();
+ }
});
\ No newline at end of file
diff --git a/frontend/js/Models/PartUnit.js b/frontend/js/Models/PartUnit.js
@@ -3,7 +3,8 @@ PartDB2.PartUnit = Ext.define("PartUnit", {
fields: [
{ id: 'id', name: 'id', type: 'int' },
{ name: 'name', type: 'string'},
- { name: 'shortName', type: 'string'}
+ { name: 'shortName', type: 'string'},
+ { name: 'default', type: 'bool'}
],
proxy: PartDB2.getRESTProxy("PartUnit"),
getName: function () {
diff --git a/frontend/js/PartDB2.js b/frontend/js/PartDB2.js
@@ -87,11 +87,7 @@ Ext.application({
this.footprintStore.load();
this.manufacturerStore.load();
this.distributorStore.load();
- this.partUnitStore.load({
- callback: function (records, operation, success) {
- this.insert(0, { id: null, name: i18n("Pieces"), shortName: i18n("pcs")});
- }
- });
+ this.partUnitStore.load();
Ext.defer(PartDB2.getApplication().reloadStores, 100000, this);
},
createLayout: function () {
diff --git a/src/de/RaumZeitLabor/PartDB2/Part/Part.php b/src/de/RaumZeitLabor/PartDB2/Part/Part.php
@@ -75,7 +75,7 @@ class Part {
public function __construct () {
$this->distributors = new \Doctrine\Common\Collections\ArrayCollection();
- $this->manufacturers = new \Doctrine\Common\Collections\ArrayCollection();
+ $this->manufacturers = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getName () {
@@ -88,7 +88,7 @@ class Part {
* @param PartUnit $partUnit The part unit object to set
* @return nothing
*/
- public function setPartUnit (PartUnit $partUnit = null) {
+ public function setPartUnit (PartUnit $partUnit) {
$this->partUnit = $partUnit;
}
diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartUnit.php b/src/de/RaumZeitLabor/PartDB2/Part/PartUnit.php
@@ -30,6 +30,23 @@ class PartUnit {
private $shortName;
/**
+ * Defines if the unit is default or not.
+ *
+ * @Column(type="boolean")
+ * @var boolean
+ */
+ private $is_default;
+
+ /**
+ * Creates a new part unit.
+ *
+ * Sets the default to false.
+ */
+ public function __construct () {
+ $this->setDefault(false);
+ }
+
+ /**
* Sets the name for this unit
* @param string $name The name for this unit
* @return nothing
@@ -77,6 +94,23 @@ class PartUnit {
}
/**
+ * Defines if the unit is default or not.
+ * @param boolean $default True if the unit is default, false otherwise
+ */
+ public function setDefault ($default) {
+ $this->is_default = (bool)$default;
+ }
+
+ /**
+ * Returns if the unit is default or not
+ * @param none
+ * @return boolean True if the unit is default, false for not
+ */
+ public function getDefault () {
+ return $this->is_default;
+ }
+
+ /**
* Serializes the object and returns it as array, suitable
* to process via json_encode.
* @param none
@@ -86,7 +120,8 @@ class PartUnit {
return array(
"id" => $this->getId(),
"name" => $this->getName(),
- "shortName" => $this->getShortName()
+ "shortName" => $this->getShortName(),
+ "default" => $this->getDefault()
);
}
}
diff --git a/src/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitManager.php b/src/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitManager.php
@@ -12,7 +12,7 @@ class PartUnitManager extends Singleton {
public function getPartUnits ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") {
$qb = PartDB2::getEM()->createQueryBuilder();
- $qb->select("st.id, st.name, st.shortName")->from("de\RaumZeitLabor\PartDB2\Part\PartUnit","st");
+ $qb->select("st.id, st.name, st.shortName, st.is_default AS default")->from("de\RaumZeitLabor\PartDB2\Part\PartUnit","st");
if ($filter != "") {
$qb = $qb->where("st.name LIKE :filter");
@@ -30,6 +30,18 @@ class PartUnitManager extends Singleton {
$result = $query->getResult();
+ foreach ($result as $key => $row) {
+ foreach ($row as $rowkey => $column) {
+ if ($rowkey == "default") {
+ if ($column == 0) {
+ $result[$key][$rowkey] = false;
+ } else {
+ $result[$key][$rowkey] = true;
+ }
+ }
+ }
+ }
+
$totalQueryBuilder = PartDB2::getEM()->createQueryBuilder();
$totalQueryBuilder->select("COUNT(st.id)")->from("de\RaumZeitLabor\PartDB2\Part\PartUnit","st");
@@ -61,4 +73,16 @@ class PartUnitManager extends Singleton {
PartDB2::getEM()->remove($partUnit);
PartDB2::getEM()->flush();
}
+
+ public function setDefaultPartUnit ($id) {
+ PartDB2::getEM()->beginTransaction();
+
+ $dql = 'UPDATE de\RaumZeitLabor\PartDB2\Part\PartUnit pu SET pu.is_default = 1 WHERE pu.id = :id';
+ PartDB2::getEM()->createQuery($dql)->setParameter("id", $id)->execute();
+
+ $dql = 'UPDATE de\RaumZeitLabor\PartDB2\Part\PartUnit pu SET pu.is_default = 0 WHERE pu.id != :id';
+ PartDB2::getEM()->createQuery($dql)->setParameter("id", $id)->execute();
+
+ PartDB2::getEM()->commit();
+ }
}
\ No newline at end of file
diff --git a/src/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitService.php b/src/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitService.php
@@ -70,4 +70,12 @@ class PartUnitService extends Service implements RestfulService {
return array("data" => null);
}
+
+ public function setDefault () {
+ $this->requireParameter("id");
+
+ $partUnit = PartUnitManager::getInstance()->setDefaultPartUnit($this->getParameter("id"));
+
+ return array("data" => null);
+ }
}
\ No newline at end of file
diff --git a/testing/SetupDatabase.php b/testing/SetupDatabase.php
@@ -8,7 +8,7 @@ use de\RaumZeitLabor\PartDB2\Auth\User;
use de\RaumZeitLabor\PartDB2\Footprint\Footprint;
use de\RaumZeitLabor\PartDB2\Footprint\FootprintManager;
use de\RaumZeitLabor\PartDB2\PartDB2;
-
+use de\RaumZeitLabor\PartDB2\Part\PartUnit;
use de\RaumZeitLabor\PartDB2\Category\Category;
use de\RaumZeitLabor\PartDB2\Part\Part;
use de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation;
@@ -78,6 +78,14 @@ $newCategories = array();
mysql_connect("localhost", "partdb", "partdb");
mysql_select_db("partdb");
+$partUnit = new PartUnit();
+$partUnit->setName(PartDB2::i18n("Pieces"));
+$partUnit->setShortName(PartDB2::i18n("pcs"));
+$partUnit->setDefault(true);
+
+PartDB2::getEM()->persist($partUnit);
+PartDB2::getEM()->flush();
+
echo "Creating footprints from SetupData/footprints.php\n";
$r = mysql_query("SELECT * FROM footprints");
@@ -185,7 +193,7 @@ while ($part = mysql_fetch_assoc($r)) {
$oPart->setCategory($newCategories[$part["id_category"]]);
$oPart->setStorageLocation($newStorageLocations[$part["id_storeloc"]]);
$oPart->setMinStockLevel($part["mininstock"]);
-
+ $oPart->setPartUnit($partUnit);
for ($i=0;$i<rand(0,15);$i++) {
$randomManufacturer = rand(0, count($aManufacturers)-1);
$oPart->getManufacturers()->add(new PartManufacturer($oPart, $aManufacturers[$randomManufacturer]));