commit 2da8cee9da38407d6106b669b4d53459e2beef44
parent d73c72ba58fdbe062297a790f69cc44f3353316a
Author: Felicitus <felicitus@felicitus.org>
Date: Wed, 4 Jul 2012 15:36:29 +0200
Fixed several bugs in the footprint editor which was messed up due to duplicate ids
Diffstat:
3 files changed, 67 insertions(+), 34 deletions(-)
diff --git a/src/frontend/js/Components/Footprint/FootprintTree.js b/src/frontend/js/Components/Footprint/FootprintTree.js
@@ -26,8 +26,8 @@ Ext.define("PartKeepr.FootprintTree", {
this.addEvents("itemEdit");
this.on("itemclick", Ext.bind(function (t,record) {
- if (record.get("footprintId")) {
- this.fireEvent("itemEdit", record.get("footprintId"));
+ if (record.self.getName() == "PartKeepr.Footprint") {
+ this.fireEvent("itemEdit", record.get("id"));
}
}, this));
@@ -54,24 +54,28 @@ Ext.define("PartKeepr.FootprintTree", {
this.getSelectionModel().on("deselect", this._onItemDeselect, this);
},
/**
- * Called when a footprint is about to be added
+ * Called when a footprint is about to be added. This prepares the to-be-edited record with the proper category id.
*/
_onAddFootprint: function () {
- var r = this.getSelectionModel().getLastSelected();
+ var record = this.getSelectionModel().getLastSelected();
+
+ if (!record) {
+ // Nothing is selected, use the root node's ID as category
+ this.fireEvent("itemAdd", { category: this.getRootNode().get("id") });
+ }
- if (r && !r.get("footprintId")) {
- this.fireEvent("itemAdd", { category: r.get("id") });
+ if (record.self.getName() == "PartKeepr.FootprintCategory") {
+ // Selected node is a footprint category
+ this.fireEvent("itemAdd", { category: record.get("id") });
} else {
- if (!r) {
- this.fireEvent("itemAdd", this.getRootNode().get("id"));
+ // Selected node is a footprint
+ if (record.parentNode && record.parentNode.self.getName() == "PartKeepr.FootprintCategory") {
+ // Selected parent node is a category, perfect. Let's use this
+ this.fireEvent("itemAdd", { category: record.parentNode.get("id") });
} else {
- /* Try to find the category's parent id */
- if (r.parentNode && !r.parentNode.get("footprintId")) {
- this.fireEvent("itemAdd", { category: r.parentNode.get("id") });
- } else {
- this.fireEvent("itemAdd", this.getRootNode().get("id"));
- }
- }
+ // Something went probably wrong, use the root node
+ this.fireEvent("itemAdd", { category: this.getRootNode().get("id") });
+ }
}
},
@@ -94,7 +98,7 @@ Ext.define("PartKeepr.FootprintTree", {
*/
_updateDeleteButton: function (selectionModel, record) {
/* Right now, we support delete on a single record only */
- if (this.getSelectionModel().getCount() == 1 && record.get("footprintId")) {
+ if (this.getSelectionModel().getCount() == 1 && record.self.getName() == "PartKeepr.Footprint") {
this.deleteButton.enable();
} else {
this.deleteButton.disable();
@@ -113,33 +117,47 @@ Ext.define("PartKeepr.FootprintTree", {
this.loadCategories();
},
+ /**
+ * Injects all footprints into the correct categories. That way, we don't have to implement a complete
+ * own tree, but rather take what's already there for the categories and extend that.
+ */
_onCategoriesLoaded: function () {
this.callParent(arguments);
+
var store = PartKeepr.getApplication().getFootprintStore();
- var category_id;
var nodeData, record;
+ Ext.data.NodeInterface.decorate("PartKeepr.Footprint");
+
for (var i=0;i<store.getCount();i++) {
record = store.getAt(i);
-
nodeData = {
- name: record.getRecordName(),
- footprintId: record.get("id"),
+ text: record.getRecordName(),
+ id: record.get("id"),
leaf: true,
iconCls:'icon-footprint'
};
-
+ console.log(record.getRecordName());
+ var newNode = Ext.create("PartKeepr.Footprint", nodeData);
+
if (record.get("category") === 0) {
- this.getRootNode().firstChild.appendChild(nodeData);
+ this.getRootNode().firstChild.appendChild(newNode);
} else {
- var node = this.getRootNode().findChild("id", record.get("category"), true);
+
+ var node = this.getRootNode().findChildBy(function () {
+ if (this.self.getName() == "PartKeepr.FootprintCategory" && this.get("id") == record.get("category")) {
+ return true;
+ } else {
+ return false;
+ }
+ }, false, true);
if (node) {
- node.appendChild(nodeData);
+ node.appendChild(newNode);
} else {
- this.getRootNode().firstChild.appendChild(nodeData);
- }
+ this.getRootNode().firstChild.appendChild(newNode);
+ }
}
}
@@ -149,28 +167,41 @@ Ext.define("PartKeepr.FootprintTree", {
var draggedRecord = data.records[0];
var droppedOn = this.getView().getRecord(node);
- if (droppedOn.get("footprintId")) {
+ if (droppedOn.self.getName() == "PartKeepr.Footprint") {
// Target record is a footprint, we don't allow moving categories onto footprints
return false;
}
- if (draggedRecord.get("footprintId")) {
+ if (draggedRecord.self.getName() == "PartKeepr.Footprint") {
/* Move Footprint */
var call = new PartKeepr.ServiceCall("Footprint", "moveFootprint");
- call.setParameter("id", draggedRecord.get("footprintId"));
+ call.setParameter("id", draggedRecord.get("id"));
call.setParameter("targetCategory", droppedOn.get("id"));
call.setHandler(Ext.bind(function () {
- var node = this.getRootNode().findChild("footprintId", draggedRecord.get("footprintId"), true);
+ var sourceNode = this.getRootNode().findChildBy(function () {
+ if (this.self.getName() == "PartKeepr.Footprint" && this.get("id") == draggedRecord.get("id")) {
+ return true;
+ } else {
+ return false;
+ }
+ }, false, true);
+
+ var targetNode = this.getRootNode().findChildBy(function () {
+ if (this.self.getName() == "PartKeepr.FootprintCategory" && this.get("id") == droppedOn.get("id")) {
+ return true;
+ } else {
+ return false;
+ }
+ }, false, true);
- var targetNode = this.getRootNode().findChild("id", droppedOn.get("id"), true);
targetNode.expand();
- node.remove();
+ sourceNode.remove();
- targetNode.appendChild(node);
+ targetNode.appendChild(sourceNode);
- var oldRecordIndex = PartKeepr.getApplication().getFootprintStore().find("id", draggedRecord.get("footprintId"));
+ var oldRecordIndex = PartKeepr.getApplication().getFootprintStore().find("id", draggedRecord.get("id"));
var oldRecord = PartKeepr.getApplication().getFootprintStore().getAt(oldRecordIndex);
oldRecord.set("category", droppedOn.get("id"));
diff --git a/src/frontend/js/Models/Footprint.js b/src/frontend/js/Models/Footprint.js
@@ -3,6 +3,7 @@ Ext.define("PartKeepr.Footprint", {
fields: [
{ id: 'id', name: 'id', type: 'int' },
{ name: 'name', type: 'string' },
+ { name: 'text', type: 'string' },
{ name: 'description', type: 'string' },
// image_id needs to be a string because we need to be able to push TMP:<id> back
{ name: 'image_id', type: 'string' },
diff --git a/src/frontend/js/Models/FootprintCategory.js b/src/frontend/js/Models/FootprintCategory.js
@@ -3,6 +3,7 @@ Ext.define("PartKeepr.FootprintCategory", {
fields: [
{ name: 'id', type: 'int' },
{ name: 'name', type: 'string' },
+ { name: 'text', type: 'string' },
{ name: 'description', type: 'string' },
{ name: 'parent', type: 'int' }
],