StorageLocationMultiAddWindow.js (2649B)
1 /** 2 * Represents the multi create window. 3 * @class PartKeepr.StorageLocationMultiCreateWindow 4 */ 5 Ext.define("PartKeepr.StorageLocationMultiCreateWindow", { 6 extend: 'Ext.Window', 7 8 // Layout stuff 9 layout: 'fit', 10 width: 500, 11 height: 250, 12 13 // Title 14 title: i18n("Multi-Create Storage Locations"), 15 16 /** 17 * Initializes the window by adding the buttons and the form 18 */ 19 initComponent: function () { 20 this.form = Ext.create("PartKeepr.StorageLocationMultiAddDialog"); 21 22 this.items = [this.form]; 23 24 // Creates the add button as instance, so we can disable it easily. 25 this.addButton = Ext.create("Ext.button.Button", { 26 text: i18n("Create Storage Locations"), 27 iconCls: 'web-icon add', 28 handler: this.onAddClick, 29 scope: this 30 }); 31 32 this.dockedItems = [{ 33 xtype: 'toolbar', 34 defaults: {minWidth: 100}, 35 dock: 'bottom', 36 ui: 'footer', 37 pack: 'start', 38 items: [this.addButton, 39 { 40 text: i18n("Close"), 41 handler: this.onCloseClick, 42 scope: this, 43 iconCls: 'web-icon cancel' 44 }] 45 }]; 46 47 this.callParent(); 48 }, 49 /** 50 * Called when the "Add" button was clicked. Sends a call to the server 51 * to create the storage locations 52 */ 53 onAddClick: function () { 54 this.addButton.disable(); 55 56 var storageLocations = this.form.getStorageLocations(); 57 58 for (var i=0;i<storageLocations.length;i++) { 59 var j = Ext.create("PartKeepr.StorageLocationBundle.Entity.StorageLocation"); 60 j.setCategory(this.category); 61 j.set("name", storageLocations[i]); 62 63 64 if (i == storageLocations.length -1) { 65 j.save({ 66 scope: this, 67 success: function (a) { 68 this.close(); 69 } 70 }); 71 } else { 72 j.save(); 73 } 74 } 75 }, 76 /** 77 * Called when the service call was completed. Displays an error dialog 78 * if something went wrong. 79 * @param response The server response 80 */ 81 onAdded: function (response) { 82 this.addButton.enable(); 83 84 if (response.data.length > 0) { 85 Ext.Msg.alert(i18n("Errors occured"), implode("<br>", response.data)); 86 } else { 87 this.close(); 88 } 89 }, 90 /** 91 * Close the dialog 92 */ 93 onCloseClick: function () { 94 this.close(); 95 } 96 97 });