commit fe248aa563c5784b5b757c3b5403f26def323a1b
parent 494df379a243995d9774f776f2f7bdc6dc201ac3
Author: Timo A. Hummel <felicitus@felicitus.org>
Date: Mon, 27 Jul 2015 22:26:40 +0200
Fixed the multi storage location create functionality
Diffstat:
3 files changed, 127 insertions(+), 92 deletions(-)
diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/StorageLocation/StorageLocationGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/StorageLocation/StorageLocationGrid.js
@@ -35,20 +35,6 @@ Ext.define('PartKeepr.StorageLocationGrid', {
* Creates a new storage location multi-create window.
*/
onMultiCreateClick: function () {
- var j = Ext.create("PartKeepr.StorageLocationMultiCreateWindow", {
- listeners: {
- destroy: {
- fn: this.onMultiCreateWindowDestroy,
- scope: this
- }
- }
- });
- j.show();
- },
- /**
- * Reloads the store after the multi-create window was closed
- */
- onMultiCreateWindowDestroy: function () {
- this.store.load();
+ this.fireEvent("storageLocationMultiAdd")
}
});
\ No newline at end of file
diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/StorageLocation/StorageLocationMultiAddWindow.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/StorageLocation/StorageLocationMultiAddWindow.js
@@ -3,81 +3,95 @@
* @class PartKeepr.StorageLocationMultiCreateWindow
*/
Ext.define("PartKeepr.StorageLocationMultiCreateWindow", {
- extend: 'Ext.Window',
-
- // Layout stuff
- layout: 'fit',
- width: 500,
- height: 250,
-
- // Title
- title: i18n("Multi-Create Storage Locations"),
-
- /**
- * Initializes the window by adding the buttons and the form
- */
- initComponent: function () {
- this.form = Ext.create("PartKeepr.StorageLocationMultiAddDialog");
-
- this.items = [ this.form ];
-
- // Creates the add button as instance, so we can disable it easily.
- this.addButton = Ext.create("Ext.button.Button", {
- text: i18n("Create Storage Locations"),
- icon: 'resources/silkicons/add.png',
- handler: this.onAddClick,
- scope: this
- });
-
- this.dockedItems = [{
- xtype: 'toolbar',
- defaults: {minWidth: 100},
- dock: 'bottom',
- ui: 'footer',
- pack: 'start',
- items: [this.addButton,
- {
- text: i18n("Close"),
- handler: this.onCloseClick,
- scope: this,
- icon: 'resources/silkicons/cancel.png'
- }]
- }];
-
- this.callParent();
- },
- /**
- * Called when the "Add" button was clicked. Sends a call to the server
- * to create the storage locations
- */
- onAddClick: function () {
- this.addButton.disable();
- var call = new PartKeepr.ServiceCall("StorageLocation", "massCreate");
- call.setParameter("storageLocations", this.form.getStorageLocations());
- call.setHandler(Ext.bind(this.onAdded, this));
- call.doCall();
-
- },
- /**
- * Called when the service call was completed. Displays an error dialog
- * if something went wrong.
- * @param response The server response
- */
- onAdded: function (response) {
- this.addButton.enable();
-
-
- if (response.data.length > 0) {
- Ext.Msg.alert(i18n("Errors occured"), implode("<br>", response.data));
- } else {
- this.close();
- }
- },
- /**
- * Close the dialog
- */
- onCloseClick: function () {
- this.close();
- }
-
+ extend: 'Ext.Window',
+
+ // Layout stuff
+ layout: 'fit',
+ width: 500,
+ height: 250,
+
+ // Title
+ title: i18n("Multi-Create Storage Locations"),
+
+ /**
+ * Initializes the window by adding the buttons and the form
+ */
+ initComponent: function () {
+ this.form = Ext.create("PartKeepr.StorageLocationMultiAddDialog");
+
+ this.items = [this.form];
+
+ // Creates the add button as instance, so we can disable it easily.
+ this.addButton = Ext.create("Ext.button.Button", {
+ text: i18n("Create Storage Locations"),
+ icon: 'resources/silkicons/add.png',
+ handler: this.onAddClick,
+ scope: this
+ });
+
+ this.dockedItems = [{
+ xtype: 'toolbar',
+ defaults: {minWidth: 100},
+ dock: 'bottom',
+ ui: 'footer',
+ pack: 'start',
+ items: [this.addButton,
+ {
+ text: i18n("Close"),
+ handler: this.onCloseClick,
+ scope: this,
+ icon: 'resources/silkicons/cancel.png'
+ }]
+ }];
+
+ this.callParent();
+ },
+ /**
+ * Called when the "Add" button was clicked. Sends a call to the server
+ * to create the storage locations
+ */
+ onAddClick: function () {
+ this.addButton.disable();
+
+ var storageLocations = this.form.getStorageLocations();
+
+ for (var i=0;i<storageLocations.length;i++) {
+ var j = Ext.create("PartKeepr.StorageLocationBundle.Entity.StorageLocation");
+ j.setCategory(this.category);
+ j.set("name", storageLocations[i]);
+
+
+ if (i == storageLocations.length -1) {
+ j.save({
+ scope: this,
+ success: function (a) {
+ this.close();
+ }
+ });
+ } else {
+ j.save();
+ }
+ }
+ },
+ /**
+ * Called when the service call was completed. Displays an error dialog
+ * if something went wrong.
+ * @param response The server response
+ */
+ onAdded: function (response) {
+ this.addButton.enable();
+
+ if (response.data.length > 0) {
+ Ext.Msg.alert(i18n("Errors occured"), implode("<br>", response.data));
+ } else {
+ this.close();
+ }
+ },
+ /**
+ * Close the dialog
+ */
+ onCloseClick: function () {
+ this.close();
+ }
+
});
\ No newline at end of file
diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/StorageLocation/StorageLocationNavigation.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/StorageLocation/StorageLocationNavigation.js
@@ -64,6 +64,8 @@ Ext.define("PartKeepr.StorageLocationNavigation", {
this.down("partkeepr\\.StorageLocationTree").setStore(this.treeStore);
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("itemAdd", this.onAddStorageLocation, this);
this.down("partkeepr\\.StorageLocationGrid").on("itemDelete", function (id)
{
@@ -131,6 +133,39 @@ Ext.define("PartKeepr.StorageLocationNavigation", {
});
},
/**
+ * Called when a storage location is about to be added. This prepares the to-be-edited record with the proper category id.
+ */
+ onMultiAddStorageLocation: function ()
+ {
+ var selection = this.down("partkeepr\\.StorageLocationTree").getSelection();
+
+ var category;
+ if (selection.length === 0) {
+ category = this.down("partkeepr\\.StorageLocationTree").getRootNode().firstChild.getId();
+ } else {
+ var item = selection.shift();
+ category = item.getId();
+ }
+
+ var j = Ext.create("PartKeepr.StorageLocationMultiCreateWindow", {
+ category: category,
+ listeners: {
+ destroy: {
+ fn: this.onMultiCreateWindowDestroy,
+ scope: this
+ }
+ }
+ });
+ j.show();
+
+ },
+ /**
+ * Reloads the store after the multi-create window was closed
+ */
+ onMultiCreateWindowDestroy: function () {
+ this.store.load();
+ },
+ /**
* Triggers a reload of the store when an edited record affects the store
*/
syncChanges: function ()