1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- var webdav={};
- webdav.set=
- function(parentClass){
- this.parent=parentClass;
- }
-
- webdav.uploadFile=
- function(file,context){
- let url=LABKEY.ActionURL.getBaseURL();
- url+='_webdav';
- url+=LABKEY.ActionURL.getContainer();
- url+='/@files';
- url+='/'+context['dirName'];
- this.parent.print('uploadFile url: '+url);
- let uploadConfig=new Object();
- uploadConfig.file=file;
- uploadConfig.context=context;
- uploadConfig.url=url;
- let that=this;
- uploadConfig.success=function(cfg){that.afterBaseDir(cfg);};
- uploadConfig.failure=function(cfg){that.tryMakeDir(cfg);};
- this.webdavCheck(uploadConfig);
- }
- webdav.afterBaseDir=
- function(cfg){
- this.parent.print('afterBaseDir');
- cfg.url+='/'+cfg.context['ID'];
- let that=this;
- cfg.success=function(x){that.afterIDDir(x);};
- cfg.failure=function(x){that.tryMakeDir(x);};
- this.webdavCheck(cfg);
- }
- webdav.afterIDDir=
- function(cfg){
- this.parent.print('afterIDDir');
- this.parent.print('Uploading '+cfg.file.name);
- let suf=cfg.file.name.split('.').pop();
- cfg.url+='/'+cfg.context['ID']+'.'+suf;
- cfg.data=cfg.file;
- let that=this;
- cfg.success=function(x){that.afterUpload(x);};
- cfg.failure=function(x){that.onFailure(x);};
- this.webdavPut(cfg);
- }
- webdav.afterUpload=
- function(cfg){
- this.parent.print('afterUpload');
- }
- webdav.tryMakeDir=
- function(cfg){
- this.parent.print('tryMakeDir '+cfg.url);
- let that=this;
- cfg.failure=function(x){that.onFailure(x);};
- this.webdavMakeDir(cfg);
- }
- webdav.request=
- function (cfg,verb,data){
- this.parent.print('request['+verb+'] '+cfg.url);
- let connRequest=new XMLHttpRequest();
- let that=this;
- let action=function(connRequest,cfg){that.checkResponse(connRequest,cfg);};
- connRequest.addEventListener("loadend",action);
- connRequest.open(verb, cfg.url);
- connRequest.send(data);
- //this.print('request['+verb+'] sent');
- }
- webdav.checkResponse=
- function(xrq,cfg){
- //this.print('checkResponse: readyState '+xrq.readyState);
- //this.print('checkResponse: status '+xrq.status);
- if (xrq.status<400) {
- //client errors 400-499
- //server errors 500-599
- cfg.success(cfg);
- return;
- }
- cfg.status=xrq.status;
- cfg.failure(cfg);
- }
- webdav.webdavMakeDir=function(cfg){ this.request(cfg,'MKCOL',null);}
- webdav.webdavCheck=function(cfg) { this.request(cfg,'GET',null);}
- webdav.webdavPut=function(cfg) { this.request(cfg,'PUT',cfg.data);}
- webdav.onFailuer=function(cfg){
- this.parent.print('request failed with status='+cfg.status);
- }
|