partkeepr

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

commit 3f54b6d5defca9354b4ecbe7aa30db52685f2295
parent 58c246e58796662e134099a07ad1dff9b86c0fe8
Author: Felicitus <felicitus@felicitus.org>
Date:   Mon, 12 Mar 2012 09:33:16 +0100

Automatically remove empty rows for distributors, parameters and manufacturers. Fixes #143

Diffstat:
Msrc/frontend/js/Components/Editor/Editor.js | 19++++++++++++++++---
Msrc/frontend/js/Components/Part/Editor/PartEditor.js | 40++++++++++++++++++++++++++++++++++++++++
Msrc/frontend/js/Components/Part/Editor/PartEditorWindow.js | 2+-
3 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/src/frontend/js/Components/Editor/Editor.js b/src/frontend/js/Components/Editor/Editor.js @@ -35,7 +35,7 @@ Ext.define('PartKeepr.Editor', { this.saveButton = Ext.create("Ext.button.Button", { text: this.saveText, icon: 'resources/fugue-icons/icons/disk.png', - handler: Ext.bind(this.onItemSave, this) + handler: Ext.bind(this._onItemSave, this) }); this.cancelButton = Ext.create("Ext.button.Button", { @@ -65,7 +65,17 @@ Ext.define('PartKeepr.Editor', { // Waiting for reply on http://www.sencha.com/forum/showthread.php?135142-Ext.form.Basic.loadRecord-causes-form-to-be-dirty&p=607588#post607588 }); - this.addEvents("editorClose", "startEdit", "itemSaved"); + this.addEvents( + "editorClose", + "startEdit", + "itemSaved", + + /** + * Fired before the item is saved. + * + * @param record The record which is about to be saved + */ + "itemSave"); this.defaults.listeners = { "change": Ext.bind(this.onFieldChange, this) @@ -99,7 +109,7 @@ Ext.define('PartKeepr.Editor', { return null; } }, - onItemSave: function () { + _onItemSave: function () { // Disable the save button to indicate progress if (this.enableButtons) { this.saveButton.disable(); @@ -109,6 +119,9 @@ Ext.define('PartKeepr.Editor', { } this.getForm().updateRecord(this.record); + + this.fireEvent("itemSave", this.record); + this.record.save({ callback: this._onSave, scope: this diff --git a/src/frontend/js/Components/Part/Editor/PartEditor.js b/src/frontend/js/Components/Part/Editor/PartEditor.js @@ -209,6 +209,46 @@ Ext.define('PartKeepr.PartEditor', { this.callParent(); + this.on("itemSave", this.onItemSave, this); + + }, + onItemSave: function () { + var removeRecords = [], j; + + for (j=0;j<this.record.distributors().getCount();j++) { + if (this.record.distributors().getAt(j).get("id") === 0) { + removeRecords.push(this.record.distributors().getAt(j)); + } + } + + if (removeRecords.length > 0) { + this.record.distributors().remove(removeRecords); + } + + removeRecords = []; + + for (j=0;j<this.record.parameters().getCount();j++) { + if (this.record.parameters().getAt(j).get("id") === 0) { + removeRecords.push(this.record.parameters().getAt(j)); + } + } + + if (removeRecords.length > 0) { + this.record.parameters().remove(removeRecords); + } + + removeRecords = []; + + for (j=0;j<this.record.manufacturers().getCount();j++) { + if (this.record.manufacturers().getAt(j).get("id") === 0) { + removeRecords.push(this.record.manufacturers().getAt(j)); + } + } + + if (removeRecords.length > 0) { + this.record.manufacturers().remove(removeRecords); + } + }, onEditStart: function () { this.bindChildStores(); diff --git a/src/frontend/js/Components/Part/Editor/PartEditorWindow.js b/src/frontend/js/Components/Part/Editor/PartEditorWindow.js @@ -101,7 +101,7 @@ Ext.define('PartKeepr.PartEditorWindow', { // Sanity: If the save process fails, re-enable the button after 30 seconds Ext.defer(function () { this.saveButton.enable(); }, 30000, this); - this.editor.onItemSave(); + this.editor._onItemSave(); }, /** * Called when the item was saved