partkeepr

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

commit 60ab3375fb7f347abcdb1d5ea89f1e543eb537cd
parent 5a5d707a8ada6be9c83e4e9158f60d494acee99a
Author: Felicitus <felicitus@felicitus.org>
Date:   Sun, 25 Dec 2011 12:07:57 +0100

Project Editor: Inline-Adding of new Parts

Diffstat:
Msrc/frontend/js/Components/Part/Editor/PartEditor.js | 2+-
Msrc/frontend/js/Components/Part/Editor/PartEditorWindow.js | 2+-
Msrc/frontend/js/Components/Part/PartsManager.js | 2++
Msrc/frontend/js/Components/Project/ProjectPartGrid.js | 30+++++++++++++++++++++++++++++-
4 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/src/frontend/js/Components/Part/Editor/PartEditor.js b/src/frontend/js/Components/Part/Editor/PartEditor.js @@ -194,7 +194,7 @@ Ext.define('PartKeepr.PartEditor', { this.fireEvent("partSaved", this.record); if (this.keepOpenCheckbox.getValue() !== true) { - this.fireEvent("editorClose"); + this.fireEvent("editorClose", this); } else { var newItem = Ext.create("PartKeepr.Part", this.partDefaults); this.editItem(newItem); diff --git a/src/frontend/js/Components/Part/Editor/PartEditorWindow.js b/src/frontend/js/Components/Part/Editor/PartEditorWindow.js @@ -46,7 +46,7 @@ Ext.define('PartKeepr.PartEditorWindow', { * We need a delay, since if others are listening for "editorClose", the dialog plus the record could be destroyed * before any following listeners have a chance to receive the record, resulting in strange problems. */ - this.editor.on("editorClose", function (record) { this.close();}, this, { delay: 200 }); + this.editor.on("editorClose", function (context) { this.close();}, this, { delay: 200 }); this.editor.on("titleChange", function (val) { this.setTitle(val); }, this); diff --git a/src/frontend/js/Components/Part/PartsManager.js b/src/frontend/js/Components/Part/PartsManager.js @@ -171,6 +171,8 @@ Ext.define('PartKeepr.PartManager', { j.editor.editItem(record); j.show(); + + return j; }, /** * Called when a part was edited. Refreshes the grid. diff --git a/src/frontend/js/Components/Project/ProjectPartGrid.js b/src/frontend/js/Components/Project/ProjectPartGrid.js @@ -62,10 +62,15 @@ Ext.define('PartKeepr.ProjectPartGrid', { this.dockedItems = [{ xtype: 'toolbar', items: [{ - text: 'Add', + text: i18n('Add'), scope: this, icon: 'resources/silkicons/brick_add.png', handler: this.onAddClick + },{ + text: i18n("Create new Part"), + scope: this, + icon: 'resources/silkicons/brick_add.png', + handler: this.onAddPartClick }, this.deleteButton, this.viewButton @@ -91,6 +96,29 @@ Ext.define('PartKeepr.ProjectPartGrid', { this.editing.startEdit(rec, this.columns[0]); }, /** + * Creates a new part, adds it to the list and sets the default quantity to 1. + */ + onAddPartClick: function () { + var win = Ext.getCmp("partkeepr-partmanager").onItemAdd(); + win.editor.on("editorClose", function (context) { + // End this if the record is a phatom and thus hasn't been saved yet + if (context.record.phantom) { return; } + + // Insert the new record + this.editing.cancelEdit(); + + var rec = new PartKeepr.ProjectPart({ + quantity: 1, + part_id: context.record.get("id"), + part_name: context.record.get("name") + }); + + this.store.insert(this.store.count(), rec); + + this.editing.startEdit(rec, this.columns[0]); + }, this); + }, + /** * Removes the currently selected row */ onDeleteClick: function () {