partkeepr

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

commit 39c23535955e555f9c4c37e32b4ec148e2f251af
parent e1c800a2d89eac4cd6694bbc86154c8e36dc7bee
Author: Felicitus <felicitus@felicitus.org>
Date:   Tue,  3 Jan 2012 12:05:34 +0100

Added part duplication functionality

Diffstat:
Msrc/frontend/js/Components/Part/PartsGrid.js | 37+++++++++++++++++++++++++++++++++++++
Msrc/frontend/js/Components/Part/PartsManager.js | 27+++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/src/frontend/js/Components/Part/PartsGrid.js b/src/frontend/js/Components/Part/PartsGrid.js @@ -87,6 +87,43 @@ Ext.define('PartKeepr.PartsGrid', { } }); + this.addFromTemplateButton = Ext.create("Ext.button.Button", { + disabled: true, + handler: Ext.bind(function () { + this.fireEvent("itemCreateFromTemplate"); + }, this), + tooltip: i18n("Add a new part, using the selected part as template"), + text: i18n("Create from Template"), + icon: 'resources/silkicons/brick_link.png' + }); + + this.topToolbar.insert(2, this.addFromTemplateButton); + + }, + /** + * Called when an item was selected. Enables/disables the delete button. + */ + _updateAddTemplateButton: function (selectionModel, record) { + /* Right now, we support delete on a single record only */ + if (this.getSelectionModel().getCount() == 1) { + this.addFromTemplateButton.enable(); + } else { + this.addFromTemplateButton.disable(); + } + }, + /** + * Called when an item was selected + */ + _onItemSelect: function (selectionModel, record) { + this._updateAddTemplateButton(selectionModel, record); + this.callParent(arguments); + }, + /** + * Called when an item was deselected + */ + _onItemDeselect: function (selectionModel, record) { + this._updateAddTemplateButton(selectionModel, record); + this.callParent(arguments); }, /** * Called when the record was double-clicked diff --git a/src/frontend/js/Components/Part/PartsManager.js b/src/frontend/js/Components/Part/PartsManager.js @@ -58,6 +58,7 @@ Ext.define('PartKeepr.PartManager', { this.grid.on("itemDeselect", this.onItemSelect, this); this.grid.on("itemAdd", this.onItemAdd, this); this.grid.on("itemDelete", this.onItemDelete, this); + this.grid.on("itemCreateFromTemplate", this.onItemCreateFromTemplate, this); this.tree.on("syncCategory", this.onSyncCategory, this); // Listen on the partChanged event, which is fired when the users edits the part @@ -128,6 +129,32 @@ Ext.define('PartKeepr.PartManager', { Ext.Msg.confirm(i18n("Delete Part"), sprintf(i18n("Do you really wish to delete the part %s?"),r.get("name")), this.deletePart, this); }, /** + * Creates a duplicate from the selected item. Loads the selected part and calls createPartDuplicate + * after the part was loaded. + * + * @param none + * @return nothing + */ + onItemCreateFromTemplate: function () { + var r = this.grid.getSelectionModel().getLastSelected(); + + this.loadPart(r.get("id"), Ext.bind(this.createPartDuplicate, this)); + }, + /** + * Creates a part duplicate from the given record and opens the editor window. + * @param rec The record to duplicate + */ + createPartDuplicate: function (rec) { + var copy = rec.copy(); + Ext.data.Model.id(copy); + copy.set("id", null); + + var j = Ext.create("PartKeepr.PartEditorWindow"); + j.editor.on("partSaved", this.onPartSaved, this); + j.editor.editItem(copy); + j.show(); + }, + /** * Deletes the selected part. * * @param {String} btn The clicked button in the message box window.