FootprintEditor.js (2063B)
1 Ext.define('PartKeepr.FootprintEditor', { 2 extend: 'PartKeepr.Editor', 3 alias: 'widget.FootprintEditor', 4 saveText: i18n("Save Footprint"), 5 layout: 'column', 6 defaultListenerScope: true, 7 syncDirect: true, 8 labelWidth: 75, 9 initComponent: function () { 10 this.on("startEdit", this.onEditStart, this, { delay: 50 }); 11 12 this.attachmentGrid = Ext.create("PartKeepr.FootprintAttachmentGrid", { 13 height: 200, 14 width: '100%', 15 border: true 16 }); 17 18 this.items = [{ 19 columnWidth: 1, 20 minWidth: 500, 21 layout: 'anchor', 22 xtype: 'container', 23 margin: '0 5 0 0', 24 items: [ 25 { 26 xtype: 'textfield', 27 name: 'name', 28 labelWidth: 75, 29 anchor: '100%', 30 fieldLabel: i18n("Name") 31 },{ 32 labelWidth: 75, 33 xtype: 'textarea', 34 name: 'description', 35 anchor: '100%', 36 fieldLabel: i18n("Description") 37 },{ 38 labelWidth: 75, 39 xtype: 'fieldcontainer', 40 anchor: '100%', 41 fieldLabel: i18n("Attachments"), 42 items: this.attachmentGrid 43 } 44 ] 45 },{ 46 width: 370, 47 height: 250, 48 xtype: 'fieldcontainer', 49 items: { 50 xtype: 'remoteimagefield', 51 itemId: 'image', 52 maxHeight: 256, 53 maxWidth: 256, 54 listeners: { 55 'fileUploaded': "onFileUploaded" 56 } 57 }, 58 labelWidth: 75, 59 fieldLabel: i18n("Image") 60 61 }]; 62 63 this.on("itemSaved", this._onItemSaved, this); 64 this.callParent(); 65 }, 66 onFileUploaded: function (data) { 67 var uploadedFile = Ext.create("PartKeepr.UploadedFileBundle.Entity.TempUploadedFile", data); 68 69 if (this.record.getImage() === null) { 70 this.record.setImage(data); 71 } else { 72 this.record.getImage().set("replacement", uploadedFile.getId()); 73 } 74 75 this.down('#image').setValue(uploadedFile); 76 }, 77 _onItemSaved: function (record) { 78 this.attachmentGrid.bindStore(record.attachments()); 79 }, 80 onEditStart: function () { 81 var store = this.record.attachments(); 82 this.attachmentGrid.bindStore(store); 83 this.down('#image').setValue(this.record.getImage()); 84 85 } 86 });