RemoteImageField.js (2320B)
1 /** 2 * @class PartKeepr.RemoteImageField 3 * <p>The RemoteImageField is a form field which can be used to upload one image. It automatically 4 * displays the remote image by id, assigns a temporary ID if it's a new image so the model can be 5 * syncronized at once. 6 * 7 */ 8 Ext.define('PartKeepr.RemoteImageField', { 9 extend: 'Ext.container.Container', 10 alias: 'widget.remoteimagefield', 11 12 xtype: 'remoteimagefield', 13 14 listeners: { 15 'click': "onClick" 16 }, 17 layout: 'vbox', 18 /** 19 * Initializes the field 20 */ 21 initComponent: function () 22 { 23 24 this.image = Ext.create("Ext.Img", { 25 maxHeight: this.maxHeight, 26 maxWidth: this.maxWidth, 27 autoEl: 'div', 28 width: this.maxWidth, 29 height: this.maxHeight, 30 flex: 1, 31 cls: 'remote-image-background' 32 }); 33 34 this.button = Ext.create("Ext.button.Button", { 35 text: i18n("Change Image"), 36 scope: this, 37 handler: this.onClick 38 }); 39 40 this.items = [this.image, this.button]; 41 this.minHeight = this.maxHeight; 42 this.minWidth = this.maxWidth; 43 44 this.callParent(); 45 }, 46 onClick: function () 47 { 48 var j = Ext.create("PartKeepr.FileUploadDialog", {imageUpload: true}); 49 j.on("fileUploaded", this.onFileUploaded, this); 50 j.show(); 51 }, 52 onFileUploaded: function (data) 53 { 54 this.fireEvent("fileUploaded", data); 55 }, 56 /** 57 * Sets a value for the field. If the value is numeric, we call the image service 58 * with the specified id and the specified type. If the value is a string and prefixed 59 * with TMP:, we use the type "TempImage" and pass the id which has to be specified after TMP:. 60 * 61 * Example 62 * TMP:12 would retrieve the temporary image with the ID 12 63 * @param {Mixed} value The value to set 64 * @return {Ext.form.field.Field} this 65 */ 66 setValue: function (value) 67 { 68 this.value = value; 69 70 if (value !== null) { 71 this.image.setSrc( 72 value.getId() + "/getImage?maxWidth=" + this.maxWidth + "&maxHeight=" + this.maxHeight + "&ts=" + new Date().getTime()); 73 } else { 74 this.image.setSrc(""); 75 } 76 77 return this; 78 } 79 }); 80