RequiredPartFields.js (3840B)
1 Ext.define('PartKeepr.Components.SystemPreferences.Preferences.RequiredPartFields', { 2 extend: 'PartKeepr.Components.Preferences.PreferenceEditor', 3 4 initComponent: function () 5 { 6 7 this.fieldSelector = Ext.create("PartKeepr.Components.Widgets.FieldSelector", { 8 height: 150, 9 sourceModel: PartKeepr.PartBundle.Entity.Part, 10 recurseSubModels: false, 11 excludeFields: [ 12 "@id", 13 "name", 14 "needsReview", 15 "stockLevel", 16 "averagePrice", 17 "createDate", 18 "removals", 19 "lowStock", 20 "minStockLevel" 21 ], 22 initiallyChecked: PartKeepr.getApplication().getSystemPreference("partkeepr.part.requiredFields", []) 23 }); 24 25 this.items = [ 26 { 27 xtype: "fieldcontainer", 28 fieldLabel: i18n("Required Fields"), 29 items: [ 30 { 31 border: false, 32 html: "The fields <strong>Name</strong>, <strong>Category</strong> and <strong>Storage Location</strong> are always required.", 33 style: "padding-top: 4px; padding-bottom: 5px;" 34 }, 35 this.fieldSelector 36 ] 37 }, 38 { 39 xtype: 'fieldcontainer', 40 fieldLabel: i18n("Minimum Numbers"), 41 items: [ 42 { 43 fieldLabel: i18n("Distributors"), 44 xtype: 'numberfield', 45 minValue: 0, 46 id: 'requirePartDistributorsAmount' 47 }, 48 { 49 fieldLabel: i18n("Manufacturers"), 50 xtype: 'numberfield', 51 minValue: 0, 52 id: 'requirePartManufacturersAmount' 53 }, 54 { 55 fieldLabel: i18n("Attachments"), 56 xtype: 'numberfield', 57 minValue: 0, 58 id: 'requirePartAttachmentsAmount' 59 } 60 ] 61 } 62 63 ]; 64 65 this.callParent(arguments); 66 67 this.down("#requirePartDistributorsAmount").setValue( 68 PartKeepr.getApplication().getSystemPreference("partkeepr.part.constraints.distributorCount", 0)); 69 this.down("#requirePartManufacturersAmount").setValue( 70 PartKeepr.getApplication().getSystemPreference("partkeepr.part.constraints.manufacturerCount", 0)); 71 this.down("#requirePartAttachmentsAmount").setValue( 72 PartKeepr.getApplication().getSystemPreference("partkeepr.part.constraints.attachmentCount", 0)); 73 74 }, 75 onSave: function () 76 { 77 var selection = this.fieldSelector.getChecked(); 78 var fields = []; 79 80 for (var i = 0; i < selection.length; i++) { 81 fields.push(selection[i].data.data.name); 82 } 83 84 PartKeepr.getApplication().setSystemPreference("partkeepr.part.requiredFields", fields); 85 PartKeepr.getApplication().setSystemPreference("partkeepr.part.constraints.distributorCount", 86 this.down("#requirePartDistributorsAmount").getValue()); 87 PartKeepr.getApplication().setSystemPreference("partkeepr.part.constraints.manufacturerCount", 88 this.down("#requirePartManufacturersAmount").getValue()); 89 PartKeepr.getApplication().setSystemPreference("partkeepr.part.constraints.attachmentCount", 90 this.down("#requirePartAttachmentsAmount").getValue()); 91 }, 92 statics: { 93 iconCls: 'fugue-icon block--plus', 94 title: i18n('Part'), 95 menuPath: [{text: i18n("Required Fields")}] 96 } 97 });