From 2009.igem.org
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
/**
* File Download Widget
*
* @author Frederic Fournaise (http://frederic.fournaise.free.fr/qooxdoo-file-upload-widget.php), David Nellessen (mail@davidn.de)
* @copyright Frederic Fournaise
* @license GNU Lesser General Public License, see http://www.opensource.org/licenses/lgpl-license.php
*
* This Class provedes a basic download gadget for qooxdoo.
*
* TODO: The code is nearly identical to the upload gadget. This is why notation is wrong (upload instead of download).
**/
qx.Class.define("qooxwaveclient.Download",{
extend : qx.ui.container.Composite, //changed
construct : function(vUploadCGI, deltaid, store, addButton, enctype){
this.base(arguments);
this.setLayout(new qx.ui.layout.Canvas()); //changed
this.upload = new qx.ui.groupbox.GroupBox();
this.store = store;
this.deltaid = deltaid;
this.addButton = addButton;
this.vUploadCGI = vUploadCGI;
if(!enctype) this.enctype = "application/x-www-form-urlencoded";
else this.enctype = enctype;
var vUniqueId = (new Date).valueOf();
var vFrameName = "frame_" + vUniqueId;
//vFrameName = "_blank";
this.uploadFrm = "upload_" + vUniqueId;
this.inputfile = null;
//form
this.input=new qx.ui.embed.Html();
this.input.set({ height : 1, width : 300 }); //changed
this.input.setHtml('<form enctype="'+this.enctype+'" target="'+vFrameName+'" action="'+this.vUploadCGI+'" method="post" id="'+this.uploadFrm+'" name="'+this.uploadFrm+'"></form>');
this.add(this.input); //changed
//submit button //changed
if(this.addButton){
this.submitButton = new qx.ui.form.Button("submit");
this.add(this.submitButton, {left : 305});
this.submitButton.addListener("execute", this.submit, this);
}
//iframe // changed
this._iframeWidget = new qx.ui.embed.Iframe ("javascript:void(0)");
this._iframeWidget.setFrameName(vFrameName);
this._iframeWidget.addListener("load", this._onload, this);
this._iframeWidget.setHeight(1);
this.add(this._iframeWidget, {top: 0});
this._iframeWidget.setOpacity(0);
},
events: {
"sending" : "qx.event.type.Event",
"onload" : "qx.event.type.Event"
},
properties :{
isSent : {init:false, check: "Boolean"},
fileName : {init: new String(), check: "String", event : "ChangeFilename"}
},
members :{
_onload : function(){ //changed
if (this.getIsSent()){
if(this.addButton){
this.submitButton.setEnabled(true);
this.submitButton.setIcon(null);
}
this.submitDelta("completed");
this.fireEvent("onload");
}
},
_onSubmit : function () { //changed
if(this.addButton){
this.submitButton.setEnabled(false);
this.submitButton.setIcon("qooxwaveclient/ajax-loader.gif");
}
this.submitDelta("submitted");
this.fireEvent("sending");
},
submit : function () {
this.debug("FIRE EXECUTE");
d=document.forms[this.uploadFrm];
this.setFileName(this.vUploadCGI);
d.submit();
this.setIsSent( true);
this._onSubmit();
},
submitDelta : function (event) {
var delta = new Object();
var id = this.deltaid;
var value = this.getFileName();
delta[id] = "{'event' : '" + event + "', 'value' : { 'filename' : '" + value + "'} }";
this.store.submitEventDelta(delta);
},
modefieUri :function (param){
this.debug("PARAMETER TO SEND" + param);
d=document.forms[this.uploadFrm];
d.action = this.vUploadCGI + "?" + param;
}
}
});