Hi, after some test and investigation I deveop a component that hack upload button (using well know technique). The component is not still perfect and is in development. I post it now to share and will send then other post when I fix and improve some.
The goals is create a multiple instantiable component with the follow elements:
- A image space -> show uploaded image at realtime
- A upload button -> send image and reload it from server
- A reset button -> request server to clear image and reload it form server (empty)
- A title
- A error/warning message space near image
"Attach1" is an example of final results.
This is current code (ind evelopment):
Then I need a multi instance shared I frame to submit form
And callback functions loaded into IFrame from response server (I post only the one need to reload image after upload or delete)
Please help me to get better and elegant code and share you opinion and better solutions.
Thanks.
The goals is create a multiple instantiable component with the follow elements:
- A image space -> show uploaded image at realtime
- A upload button -> send image and reload it from server
- A reset button -> request server to clear image and reload it form server (empty)
- A title
- A error/warning message space near image
"Attach1" is an example of final results.
This is current code (ind evelopment):
Code:
isc.ClassFactory.defineClass("AdvancedUploadForm","HStack").addProperties({ width:"30",defaultLayoutAlign: "left", fetchUrl: "", uploadUrl: "", deleteUrl: "", reloadUserPhoto: function(){ this.uploadPhoto.setSrc(this.fetchUrl+"&rand="+(new Date()).getTime()); this.uploadPhoto.resetSrc(); //clearErrorMessage(); }, uploadPanelDefaults: { _constructor:isc.HLayout, width: 120 }, uploadPhotoDefaults: { _constructor:isc.Img, width:100, height:100, border:"1px solid gray", imageType: "center", backgroundColor: "#262626", autoParent:"uploadPanel", }, imageControlsDefaults: { _constructor:isc.VLayout, autoParent:"uploadPanel", height: 50,width: 24 }, uploadButtonDefaults : { _constructor:isc.HTMLPane, autoParent:"imageControls", contents: "" }, deleteButtonDefaults : { _constructor:isc.ImgButton, autoParent:"imageControls", imageType: "center", align: "right", width: "24", height: "24", showRollOver: false, showFocused: false, showDown: false, src: "icons/24/deleteFile.png", prompt: "Elimina foto", actionType: "button", click : function () { var me = this; isc.RPCManager.sendRequest({ callback: function(){ //Request photo me.creator.reloadUserPhoto(); // Must clear input form value to admit upload as last one document.getElementById("filefield_"+me.creator.getID()).value = ""; }, actionURL: this.deleteUrl+"?rand="+(new Date()).getTime() }); } }, initWidget : function () { this.Super("initWidget", arguments); this.addAutoChild("uploadPanel"); this.addAutoChild("uploadPhoto",{src: this.fetchUrl}); this.addAutoChild("imageControls"); this.addAutoChild("uploadButton",{contents:"<div style='position:relative;height:24'>"+ "<img src='<s:url value="images/icons/24/upload.png"/>' width='24' height='24' alt=''/>"+ "<div style='z-index:9999999;opacity:0;filter:alpha(opacity=0);width:24px;height:24px;overflow:hidden;position:absolute;top:0;left:0;'>"+ "<form method='post' target='uploadFormIframe' action='" + this.uploadUrl + "' enctype='multipart/form-data'>"+ "<input id='filefield_"+this.getID()+"' name='upload' onchange='submit()' style='direction:rtl;font-size:0em;width:24px;height:24px;' type='file' name='datafile' size='0' width='0'/>"+ "</form></div></div>"}); this.addAutoChild("deleteButton",{deleteUrl : this.deleteUrl,fetchUrl : this.fetchUrl}); } }); isc.AdvancedUploadForm.create({ ID: "uploadUserPhotoForm", fetchUrl: "<s:url value='/userAction_getPhoto.action'/>?image.size=NORMAL", uploadUrl: "<s:url value="/userAction_uploadPhoto.action"/>", deleteUrl: "<s:url value="/userAction_deletePhoto.action"/>", });
Code:
isc.Canvas.create({ ID: "uploadFormIframe", contents: "<iframe name=\"uploadFormIframe\"></iframe>", autoDraw: true, visibility: "hidden" });
Code:
function reloadUserPhoto(){ uploadUserPhotoForm.reloadUserPhoto(); }
Thanks.
Comment