Permalink
Browse files

Export FileDropZone, add FolderPicker methods. Connexion.uploadFile r…

…eturns xhr for ability to abort transfer.
  • Loading branch information...
1 parent 94fbeba commit 0d2b048b46607ae9ada4109a68142c45c81800ba @cdujeu cdujeu committed Sep 18, 2016
@@ -81,16 +81,26 @@ class PydioApi{
}
}
+ /**
+ *
+ * @param file
+ * @param fileParameterName
+ * @param queryStringParams
+ * @param onComplete
+ * @param onError
+ * @param onProgress
+ * @returns XHR Handle to abort transfer
+ */
uploadFile(file, fileParameterName, queryStringParams='', onComplete=function(){}, onError=function(){}, onProgress=function(){}){
if(window.Connexion){
var c = new Connexion();
- c.uploadFile(file, fileParameterName, queryStringParams, onComplete, onError, onProgress);
+ return c.uploadFile(file, fileParameterName, queryStringParams, onComplete, onError, onProgress);
}else if(window.jQuery){
var formData = new FormData();
formData.append(fileParameterName, file);
queryStringParams += '&secure_token' + this._secureToken;
- jQuery.ajax(this._baseUrl + '&' + queryStringParams, {
+ return jQuery.ajax(this._baseUrl + '&' + queryStringParams, {
method:'POST',
data:formData,
complete:onComplete,
@@ -235,7 +235,8 @@ Class.create("Connexion", {
}else if(file.getAsBinary){
this.xhrSendAsBinary(xhr, file.name, file.getAsBinary(), fileParameterName)
}
-
+ return xhr;
+
},
initializeXHRForUpload : function(url, onComplete, onError, onProgress){
@@ -899,6 +899,17 @@
this.refs.fileInput.getDOMNode().click();
},
+ onFolderPicked: function(e){
+ if(this.props.onFolderPicked){
+ this.props.onFolderPicked(e.target.files);
+ }
+ },
+
+ openFolderPicker: function(){
+ this.refs.folderInput.getDOMNode().setAttribute("webkitdirectory", "true");
+ this.refs.folderInput.getDOMNode().click();
+ },
+
render: function() {
var className = this.props.className || 'dropzone';
@@ -914,10 +925,13 @@
if(this.props.style){
style = LangUtils.objectMerge(this.props.style, style);
}
-
+ if(this.props.enableFolders){
+ var folderInput = <input style={{display:'none'}} name="userfolder" type="file" ref="folderInput" onChange={this.onFolderPicked}/>;
+ }
return (
<div className={className} style={style} onClick={this.onClick} onDragLeave={this.onDragLeave} onDragOver={this.onDragOver} onDrop={this.onDrop}>
<input style={{display:'none'}} name="userfile" type="file" multiple={this.props.multiple} ref="fileInput" onChange={this.onDrop} accept={this.props.accept}/>
+ {folderInput}
{this.props.children}
</div>
);
@@ -1991,6 +2005,7 @@
PydioForm.FormPanel = PydioFormPanel;
PydioForm.PydioHelper = PydioFormHelper;
PydioForm.HelperMixin = HelperMixin;
+ PydioForm.FileDropZone = FileDropzone;
global.PydioForm = PydioForm;

0 comments on commit 0d2b048

Please sign in to comment.