commit 8fe7ca36434bb32f7301fe269c2da4e63ff0f18f
parent 07411d16d6f5af8073d1c6c8580af7dcf6a12ed2
Author: Felicitus <felicitus@felicitus.org>
Date: Thu, 5 Jul 2012 01:07:03 +0200
Renamed the "Create from template" button to "Duplicate" to make it more obvious what it does. Also supports full copy now, or only basic data via a SplitButton.
Diffstat:
2 files changed, 61 insertions(+), 10 deletions(-)
diff --git a/src/frontend/js/Components/Part/PartsGrid.js b/src/frontend/js/Components/Part/PartsGrid.js
@@ -85,15 +85,35 @@ Ext.define('PartKeepr.PartsGrid', {
}
});
-
- this.addFromTemplateButton = Ext.create("Ext.button.Button", {
+ var duplicateBasicData = i18n("Duplicates the selected part with the data found in the \"basic\" tab and opens the editor. Doesn't immediately saves the duplicate, in order to allow editing.");
+ var duplicateAllData = i18n("Duplicates the selected part with all data including attachments, distributors etc. Doesn't immediately saves the duplicate, in order to allow editing.");
+
+ this.addFromTemplateButton = Ext.create("Ext.button.Split", {
disabled: true,
handler: Ext.bind(function () {
- this.fireEvent("itemCreateFromTemplate");
+ this.fireEvent("duplicateItemWithBasicData");
}, this),
- tooltip: i18n("Add a new part, using the selected part as template"),
- text: i18n("Create from Template"),
- icon: 'resources/silkicons/brick_link.png'
+ tooltip: duplicateBasicData,
+ text: i18n("Duplicate"),
+ icon: 'resources/silkicons/brick_link.png',
+ menu: new Ext.menu.Menu({
+ items: [{
+ text: i18n("Duplicate with all data"),
+ tooltip: duplicateAllData,
+ handler: function () {
+ this.fireEvent("duplicateItemWithAllData");
+ },
+ scope: this
+ },{
+ text: i18n("Duplicate basic data only"),
+ tooltip: duplicateBasicData,
+ handler: function () {
+ this.fireEvent("duplicateItemWithBasicData");
+ },
+ scope: this
+ }
+ ]
+ })
});
this.topToolbar.insert(2, this.addFromTemplateButton);
diff --git a/src/frontend/js/Components/Part/PartsManager.js b/src/frontend/js/Components/Part/PartsManager.js
@@ -58,7 +58,8 @@ 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.grid.on("duplicateItemWithBasicData", this.onDuplicateItemWithBasicData, this);
+ this.grid.on("duplicateItemWithAllData", this.onDuplicateItemWithAllData, this);
this.tree.on("syncCategory", this.onSyncCategory, this);
// Listen on the partChanged event, which is fired when the users edits the part
@@ -129,18 +130,30 @@ 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.
+ * Creates a duplicate with the basic data only from the selected item. Loads the selected part and calls
+ * createPartDuplicate after the part was loaded.
*
* @param none
* @return nothing
*/
- onItemCreateFromTemplate: function () {
+ onDuplicateItemWithBasicData: function () {
var r = this.grid.getSelectionModel().getLastSelected();
this.loadPart(r.get("id"), Ext.bind(this.createPartDuplicate, this));
},
/**
+ * Creates a full duplicate from the selected item. Loads the selected part and calls createPartDuplicate
+ * after the part was loaded.
+ *
+ * @param none
+ * @return nothing
+ */
+ onDuplicateItemWithAllData: function () {
+ var r = this.grid.getSelectionModel().getLastSelected();
+
+ this.loadPart(r.get("id"), Ext.bind(this.createFullPartDuplicate, this));
+ },
+ /**
* Creates a part duplicate from the given record and opens the editor window.
* @param rec The record to duplicate
*/
@@ -158,6 +171,24 @@ Ext.define('PartKeepr.PartManager', {
j.show();
},
/**
+ * Creates a part duplicate from the given record and opens the editor window.
+ * @param rec The record to duplicate
+ */
+ createFullPartDuplicate: function (rec) {
+ var data = rec.getData(true);
+ data.id = null;
+ newItem = Ext.create("PartKeepr.Part");
+ newItem.setDataWithAssociations(data);
+
+ var j = Ext.create("PartKeepr.PartEditorWindow", {
+ partMode: 'create'
+ });
+
+ j.editor.on("partSaved", this.onPartSaved, this);
+ j.editor.editItem(newItem);
+ j.show();
+ },
+ /**
* Deletes the selected part.
*
* @param {String} btn The clicked button in the message box window.