partkeepr

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

commit 604f979e35c1bbb77f0c09f4283b3c1a867fba74
parent 28644957a3aa03b5fe161b46f8da4d41faf035c6
Author: Felicitus <felicitus@felicitus.org>
Date:   Sat, 14 Nov 2015 16:50:47 +0100

Added storage location picker

Diffstat:
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/CategoryEditor/CategoryEditorTree.js | 25++++++++++++++++---------
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Editor/EditorGrid.js | 12+++++++++++-
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/Editor/PartEditor.js | 13+------------
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/StorageLocation/StorageLocationGrid.js | 22++++++++++++----------
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/StorageLocation/StorageLocationNavigation.js | 55++++++++++++++++++++++++++++++++++++++++---------------
Asrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/StorageLocationPicker.js | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/PartKeepr/FrontendBundle/Resources/views/index.html.twig | 1+
7 files changed, 143 insertions(+), 47 deletions(-)

diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/CategoryEditor/CategoryEditorTree.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/CategoryEditor/CategoryEditorTree.js @@ -10,6 +10,7 @@ Ext.define("PartKeepr.CategoryEditorTree", { hideHeaders: true, categoryModel: null, categoryService: null, + categoryEditActions: true, columns: [ { xtype: 'treecolumn', @@ -20,9 +21,9 @@ Ext.define("PartKeepr.CategoryEditorTree", { ], initComponent: function () { - this.createToolbar(); + this.callParent(); this.getView().on("drop", Ext.bind(this.onCategoryDrop, this)); @@ -131,20 +132,26 @@ Ext.define("PartKeepr.CategoryEditorTree", { disabled: true }); - this.toolbar = Ext.create("Ext.toolbar.Toolbar", { - enableOverflow: true, - dock: 'top', - items: [ - this.toolbarExpandButton, - this.toolbarCollapseButton, - this.toolbarReloadButton, + var actions = [ + this.toolbarExpandButton, + this.toolbarCollapseButton, + this.toolbarReloadButton + ]; + + if (this.categoryEditActions) { + actions.push( { xtype: 'tbseparator' }, this.toolbarAddButton, this.toolbarEditButton, this.toolbarDeleteButton - ] + ); + } + this.toolbar = Ext.create("Ext.toolbar.Toolbar", { + enableOverflow: true, + dock: 'top', + items: actions }); Ext.apply(this, { diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Editor/EditorGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Editor/EditorGrid.js @@ -67,6 +67,11 @@ Ext.define('PartKeepr.EditorGrid', { enableEditing: true, /** + * @cfg {Boolean} boolean Defines if the edit event should pass the object (true) or as id (false) + */ + editItemAsObject: false, + + /** * @cfg {String} The title property */ titleProperty: null, @@ -74,6 +79,7 @@ Ext.define('PartKeepr.EditorGrid', { listeners: { 'reconfigure': 'onReconfigure' }, + /** * @event itemSelect * Fires if a record was selected within the grid. @@ -245,7 +251,11 @@ Ext.define('PartKeepr.EditorGrid', { */ _onItemEdit: function (view, record) { - this.fireEvent("itemEdit", record.getId()); + if (this.editItemAsObject) { + this.fireEvent("itemEdit", record); + } else { + this.fireEvent("itemEdit", record.getId()); + } }, /** * Called when an item was selected diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/Editor/PartEditor.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/Editor/PartEditor.js @@ -29,7 +29,7 @@ Ext.define('PartKeepr.PartEditor', { labelWidth: 150 }); - this.storageLocationComboBox = Ext.create("PartKeepr.StorageLocationComboBox", + this.storageLocationComboBox = Ext.create("PartKeepr.StorageLocationPicker", { fieldLabel: i18n("Storage Location"), name: 'storageLocation', @@ -37,17 +37,6 @@ Ext.define('PartKeepr.PartEditor', { labelWidth: 150 }); - this.storageLocationComboBox.store.on("load", function () - { - // Re-trigger validation because of asynchronous loading of the storage location field, - // which would be marked invalid because validation happens immediately, but after loading - // the storage locations, the field is valid, but not re-validated. - - // This workaround is done twice; once after the store is loaded and once when we start editing, - // because we don't know which event will come first - this.getForm().isValid(); - }, this); - this.footprintNone = Ext.create("Ext.form.field.Radio", { boxLabel: i18n("None"), name: 'footprint_mode', diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/StorageLocation/StorageLocationGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/StorageLocation/StorageLocationGrid.js @@ -21,22 +21,24 @@ Ext.define('PartKeepr.StorageLocationGrid', { { this.callParent(); - // Adds a button which shows the multi-create window - this.multiCreateButton = Ext.create("Ext.button.Button", { - iconCls: 'partkeepr-icon storagelocation_multiadd', - tooltip: i18n("Multi-create storage locations"), - handler: this.onMultiCreateClick, - scope: this - }); + if (this.enableEditing) { + // Adds a button which shows the multi-create window + this.multiCreateButton = Ext.create("Ext.button.Button", { + iconCls: 'partkeepr-icon storagelocation_multiadd', + tooltip: i18n("Multi-create storage locations"), + handler: this.onMultiCreateClick, + scope: this + }); - this.topToolbar.insert(2, {xtype: 'tbseparator'}); - this.topToolbar.insert(3, this.multiCreateButton); + this.topToolbar.insert(2, {xtype: 'tbseparator'}); + this.topToolbar.insert(3, this.multiCreateButton); + } }, /** * Creates a new storage location multi-create window. */ onMultiCreateClick: function () { - this.fireEvent("storageLocationMultiAdd") + this.fireEvent("storageLocationMultiAdd"); } }); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/StorageLocation/StorageLocationNavigation.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/StorageLocation/StorageLocationNavigation.js @@ -7,35 +7,59 @@ Ext.define("PartKeepr.StorageLocationNavigation", { * @var {Ext.data.Store} */ store: null, - items: [ - { - xtype: 'partkeepr.StorageLocationTree', - region: 'center' - }, { + verticalLayout: false, + dragAndDrop: true, + categoryEditActions: true, + itemEditActions: true, + editItemAsObject: false, + + initComponent: function () + { + var gridConfig = { xtype: 'partkeepr.StorageLocationGrid', resizable: true, split: true, - region: 'south', - height: "50%", - viewConfig: { + titleProperty: "name" + }; + + if (this.verticalLayout) { + gridConfig.region = "east"; + gridConfig.width = "75%"; + } else { + gridConfig.region = "south"; + gridConfig.height = "50%"; + } + + if (this.dragAndDrop) { + gridConfig.viewConfig = { plugins: { ddGroup: 'StorageLocationTree', ptype: 'gridviewdragdrop', enableDrop: false } - }, - enableDragDrop: true + }; + + gridConfig.enableDragDrop = true; } - ], - initComponent: function () - { + gridConfig.enableEditing = this.itemEditActions; + gridConfig.editItemAsObject = this.editItemAsObject; + + this.items = [ + { + xtype: 'partkeepr.StorageLocationTree', + region: 'center', + categoryEditActions: this.categoryEditActions + }, gridConfig + ]; + this.callParent(arguments); this.down("partkeepr\\.StorageLocationTree").on("itemclick", this.onCategoryClick, this); this.down("partkeepr\\.StorageLocationGrid").setStore(this.store); - this.down("partkeepr\\.StorageLocationGrid").on("storageLocationMultiAdd", this.onMultiAddStorageLocation, this); + this.down("partkeepr\\.StorageLocationGrid").on("storageLocationMultiAdd", this.onMultiAddStorageLocation, + this); this.down("partkeepr\\.StorageLocationGrid").on("itemAdd", this.onAddStorageLocation, this); this.down("partkeepr\\.StorageLocationGrid").on("itemDelete", function (id) { @@ -131,7 +155,8 @@ Ext.define("PartKeepr.StorageLocationNavigation", { /** * Reloads the store after the multi-create window was closed */ - onMultiCreateWindowDestroy: function () { + onMultiCreateWindowDestroy: function () + { this.store.load(); }, /** diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/StorageLocationPicker.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/StorageLocationPicker.js @@ -0,0 +1,62 @@ +Ext.define("PartKeepr.StorageLocationPicker", { + extend: "Ext.form.field.Picker", + alias: 'widget.StorageLocationPicker', + + + initComponent: function () + { + this.store = Ext.create("Ext.data.Store", { + model: 'PartKeepr.StorageLocationBundle.Entity.StorageLocation', + autoLoad: true, + remoteFilter: true, + remoteSort: true, + sorters: [ + { + property: 'category.categoryPath', + direction: 'ASC' + },{ + property: 'name', + direction:'ASC' + } + ], + groupField: 'categoryPath' + }); + + + this.callParent(); + }, + + setValue: function (value) { + this.selectedStorageLocation = value; + PartKeepr.StorageLocationPicker.superclass.setValue.call(this, value.get("name")); + }, + /** + * Creates and returns the tree panel to be used as this field's picker. + */ + createPicker: function() { + var me = this, + picker = new PartKeepr.StorageLocationNavigation({ + store: me.store, + floating: true, + minHeight: me.minPickerHeight, + maxHeight: me.maxPickerHeight, + manageHeight: false, + shadow: false, + height: 250, + verticalLayout: true, + dragAndDrop: false, + categoryEditActions: false, + itemEditActions: false, + editItemAsObject: true, + listeners: { + itemEdit: function (v) { + this.setValue(v); + this.collapse(); + }, + scope: this + } + }); + + return picker; + } +}); diff --git a/src/PartKeepr/FrontendBundle/Resources/views/index.html.twig b/src/PartKeepr/FrontendBundle/Resources/views/index.html.twig @@ -217,6 +217,7 @@ '@PartKeeprFrontendBundle/Resources/public/js/Components/CategoryEditor/CategoryEditorWindow.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/CategoryEditor/CategoryEditorForm.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Picker/CharPicker.js' + '@PartKeeprFrontendBundle/Resources/public/js/Components/Widgets/StorageLocationPicker.js' '@PartKeeprFrontendBundle/Resources/public/js/Models/Message.js' '@PartKeeprFrontendBundle/Resources/public/js/Ext.ux.Wizard.Card.js' '@PartKeeprFrontendBundle/Resources/public/js/Ext.ux.Wizard.Header.js'