diff options
author | Robin <robin@Amaya.(none)> | 2010-04-19 19:46:42 +0200 |
---|---|---|
committer | Robin <robin@Amaya.(none)> | 2010-04-19 19:46:42 +0200 |
commit | 38bdf4083a6e0d90afb35ded0d67cab8a518b2ea (patch) | |
tree | 10a29805a025802c6dc12c2c65c18a48cb2742f7 /js | |
parent | 6591740f5dd73969458de9a586790922fe6c27ea (diff) | |
download | nextcloud-server-38bdf4083a6e0d90afb35ded0d67cab8a518b2ea.tar.gz nextcloud-server-38bdf4083a6e0d90afb35ded0d67cab8a518b2ea.zip |
same fixes, this time hopefully without merge conflict
Diffstat (limited to 'js')
-rw-r--r-- | js/filebrowser.js | 586 | ||||
-rw-r--r-- | js/lib_ajax.js | 91 | ||||
-rw-r--r-- | js/lib_drag.js | 350 | ||||
-rwxr-xr-x | js/lib_event.js | 55 | ||||
-rw-r--r-- | js/lib_files.js | 354 | ||||
-rw-r--r-- | js/lib_xmlloader.js | 5 |
6 files changed, 1121 insertions, 320 deletions
diff --git a/js/filebrowser.js b/js/filebrowser.js index dac81327b69..f12cec44143 100644 --- a/js/filebrowser.js +++ b/js/filebrowser.js @@ -27,188 +27,367 @@ OC_FILES.browser.showInitial=function(){ if(loc.indexOf('#')!=-1){ dir=loc.substring(loc.indexOf('#')+1); } - OC_FILES.dir=dir; - OC_FILES.getdirectorycontent(dir,OC_FILES.browser.show_callback); + OC_FILES.getdirectorycontent(dir,OC_FILES.browser.show_callback,true); } OC_FILES.browser.show=function(dir){ - if(!dir){ + if(!dir || !dir.split){ dir=''; } - OC_FILES.dir=dir; OC_FILES.getdirectorycontent(dir,OC_FILES.browser.show_callback); } -OC_FILES.browser.show_callback=function(content){ - var dir=OC_FILES.dir - var dirs=dir.split('/'); - var tr=null; - var td=null; - var img=null; - - body=document.getElementsByTagName('body').item(0); - body.addEvent('onclick',OC_FILES.browser.hideallactions); - - //remove current content; - var contentNode=document.getElementById('content'); - contentNode.className='center'; - if(contentNode.hasChildNodes()){ - while(contentNode.childNodes.length >=1){ - contentNode.removeChild(contentNode.firstChild); - } - } - var table=document.createElement('table'); - table.className='browser'; - var tbody=document.createElement('tbody'); - var thead=document.createElement('thead'); - var tfoot=document.createElement('tfoot'); - table.appendChild(thead); - table.appendChild(tbody); - table.appendChild(tfoot); -// table.setAttribute('cellpadding',6); - - // breadcrumb - if(dirs.length>0) { - tr=document.createElement('tr'); - thead.appendChild(tr); - tr.className='breadcrumb'; - td=document.createElement('td'); - tr.appendChild(td); - td.className='fileSelector' - input=document.createElement('input'); - input.setAttribute('type','checkbox'); - input.setAttribute('name','fileSelector'); - input.setAttribute('value','select_all'); - input.setAttribute('id','select_all'); - input.addEvent('onclick',OC_FILES.selectAll); - td.appendChild(input); - td=document.createElement('td'); - tr.appendChild(td); - td.className='breadcrumb'; - var a=document.createElement('a'); - td.appendChild(a); - a.setAttribute('href','#'); - a.addEvent('onclick',OC_FILES.browser.show); - a.appendChild(document.createTextNode('Home')); - var currentdir=''; - for(var index=0;index<dirs.length;index++){ - d=dirs[index]; - currentdir=currentdir+'/'+d; - if(d!=''){ - a=document.createElement('a'); - td.appendChild(a); - a.setAttribute('href','#'+currentdir); - a.addEvent('onclick',OC_FILES.browser.show,currentdir); - img=document.createElement('img'); - a.appendChild(img); - img.src=WEBROOT+'/img/arrow.png'; - a.appendChild(document.createTextNode(' ' +d)); - } - } - } +OC_FILES.browser.breadcrumb=new Object(); +OC_FILES.browser.breadcrumb.node=null; +OC_FILES.browser.breadcrumb.crumbs=Array(); +OC_FILES.browser.breadcrumb.show=function(parent,path){ + if((!OC_FILES.browser.breadcrumb.node==parent && parent) || OC_FILES.browser.breadcrumb.node==null){ + OC_FILES.browser.breadcrumb.clear(); + OC_FILES.browser.breadcrumb.node=parent; + OC_FILES.browser.breadcrumb.add('Home','/'); + } + var dirs=path.split('/'); + var currentPath='/'; + var paths=Array(); + var currentPath; + if(dirs.length>0){ + for(var i=0;i<dirs.length;i++){ + dir=dirs[i]; + if(dir){ + currentPath+=dir+'/'; + paths[currentPath]=true; + if(!OC_FILES.browser.breadcrumb.crumbs[currentPath]){ + OC_FILES.browser.breadcrumb.add(dir,currentPath); + } + } + } + } + //remove all crumbs that are not part of our current path + for(currentPath in OC_FILES.browser.breadcrumb.crumbs){ + if(!paths[currentPath] && currentPath!='/'){ + OC_FILES.browser.breadcrumb.remove(currentPath); + } + } + +} +OC_FILES.browser.breadcrumb.add=function(name,path){ + var a=document.createElement('a'); + var div=document.createElement('div'); + OC_FILES.browser.breadcrumb.crumbs[path]=div; + div.className='breadcrumb'; + a.setAttribute('href','#'+path); + a.addEvent('onclick',OC_FILES.browser.show,path); + img=document.createElement('img'); + img.src=WEBROOT+'/img/arrow.png'; + a.appendChild(document.createTextNode(' ' +name)); + a.appendChild(img); + OC_FILES.files[path]=new OC_FILES.file('',path,'dir'); + div.makeDropTarget(); + div.file=OC_FILES.files[path]; + div.addEvent('ondropon',OC_FILES.browser.handleDropOn); + div.appendChild(a); + + OC_FILES.browser.breadcrumb.node.appendChild(div); +} +OC_FILES.browser.breadcrumb.remove=function(path){ + if(OC_FILES.browser.breadcrumb.crumbs[path]){ + var div=OC_FILES.browser.breadcrumb.crumbs[path]; + div.parentNode.removeChild(div); + delete OC_FILES.browser.breadcrumb.crumbs[path]; + } +} +OC_FILES.browser.breadcrumb.clear=function(){ + for(path in OC_FILES.browser.breadcrumb.crumbs){ + OC_FILES.browser.breadcrumb.remove(path); + } +} + +OC_FILES.browser.files=new Object(); +OC_FILES.browser.files.fileNodes=Array(); +OC_FILES.browser.files.node=null; +OC_FILES.browser.files.tbody=null; +OC_FILES.browser.files.show=function(parent,fileList){ + if(parent){ + OC_FILES.browser.files.node=parent; + } + var table=document.createElement('table'); + OC_FILES.browser.files.node.appendChild(table); + var tbody=document.createElement('tbody'); + OC_FILES.browser.files.tbody=tbody; + table.appendChild(tbody); + table.setAttribute('cellpadding',6); + table.setAttribute('cellspacing',0); + if(fileList){ + var name; + //remove files that no longer are in the folder + for(name in OC_FILES.browser.files.fileNodes){ + if(!fileList[name]){ + OC_FILES.browser.files.remove(name); + } + } + //add the files that arent in the list yet + for(name in fileList){ + file=fileList[name]; + if(!OC_FILES.browser.files.fileNodes[file.name]){ + OC_FILES.browser.files.add(file.name,file.type,file.size,file.date); + } + } + } +} +OC_FILES.browser.files.add=function(name,type,size,date){ + if(name){ + if(!size) size=0; + if(!date) date=getTimeString(); + OC_FILES.files[name]=new OC_FILES.file(OC_FILES.dir,name,type); + tr=document.createElement('tr'); + OC_FILES.browser.files.fileNodes[name]=tr; + OC_FILES.browser.files.tbody.appendChild(tr); + tr.className='browserline'; + td=document.createElement('td'); + tr.appendChild(td); + td.className='fileSelector'; + input=document.createElement('input'); + input.setAttribute('type','checkbox'); + input.setAttribute('name','fileSelector'); + input.setAttribute('value',name); + td.appendChild(input); + tr.appendChild(OC_FILES.browser.showicon(type)); + td=document.createElement('td'); + tr.appendChild(td); + td.makeDropTarget(); + td.addEvent('ondropon',OC_FILES.browser.handleDropOn); + td.className='nametext'; + td.setAttribute('name',name); + td.setAttribute('id',name); + var fileObject=OC_FILES.files[name]; + td.file=fileObject; + a=document.createElement('a'); + td.appendChild(a); + a.appendChild(document.createTextNode(name)); + a.addEvent('onclick',new callBack(fileObject.actions['default'],fileObject)); + a.makeDraggable(); + a.addEvent('ondrop',OC_FILES.browser.handleDrop); + if(type=='dir'){ + td.setAttribute('colspan',2); + var dirname=name; + if(OC_FILES.dir[OC_FILES.dir.length-1]!='/'){ + dirname='/'+name; + } + a.setAttribute('href','#'+OC_FILES.dir+dirname); + }else{ + a.setAttribute('href','#'+OC_FILES.dir); + sizeTd=document.createElement('td'); + tr.appendChild(sizeTd); + sizeTd.className='sizetext'; + sizeTd.appendChild(document.createTextNode(sizeFormat(size))); + } + a=document.createElement('a'); + var img=document.createElement('img'); + td.appendChild(img); + img.className='file_actions'; + img.alt='' + img.title='actions'; + img.src=WEBROOT+'/img/arrow_down.png'; + img.addEvent('onclick',OC_FILES.browser.showactions,name); + td=document.createElement('td'); + tr.appendChild(td); + td.className='sizetext'; + td.appendChild(document.createTextNode(date)); + } +} + +OC_FILES.browser.files.remove=function(name){ + if(OC_FILES.browser.files.fileNodes[name]){ + tr=OC_FILES.browser.files.fileNodes[name]; + tr.parentNode.removeChild(tr); + delete OC_FILES.browser.files.fileNodes[name]; + } + +} +OC_FILES.browser.files.clear=function(){ + for(name in OC_FILES.browser.files.fileNodes){ + OC_FILES.browser.files.remove(name); + } +} - // files and directories - - var filesfound=false; - var sizeTd=null; - if(content){ +OC_FILES.browser.table=null; +OC_FILES.browser.show_callback=function(content){ + var dir=OC_FILES.dir + var tr=null; + var td=null; + var img=null; + if(!OC_FILES.browser.table){ + body=document.getElementsByTagName('body').item(0); + body.addEvent('onclick',OC_FILES.browser.hideallactions); + + //remove current content; + var contentNode=document.getElementById('content'); + contentNode.className='center'; + if(contentNode.hasChildNodes()){ + while(contentNode.childNodes.length >=1){ + contentNode.removeChild(contentNode.firstChild); + } + } + var table=document.createElement('table'); + OC_FILES.browser.table=table; + table.className='browser'; + var tbody=document.createElement('tbody'); + var thead=document.createElement('thead'); + var tfoot=document.createElement('tfoot'); + table.appendChild(thead); + table.appendChild(tbody); + table.appendChild(tfoot); + OC_FILES.files=Array(); + table.setAttribute('cellpadding',6); + + tr=document.createElement('tr'); + thead.appendChild(tr); + tr.className='breadcrumb'; + td=document.createElement('td'); + tr.appendChild(td); + input=document.createElement('input'); + input.className='fileSelector' + input.setAttribute('type','checkbox'); + input.setAttribute('name','fileSelector'); + input.setAttribute('value','select_all'); + input.setAttribute('id','select_all'); + input.addEvent('onclick',OC_FILES.selectAll); + td.appendChild(input); + td.className='breadcrumb'; + OC_FILES.browser.breadcrumb.show(td,dir); + // files and directories tr=document.createElement('tr'); tbody.appendChild(tr); td=document.createElement('td'); - td.setAttribute('colspan','6'); tr.appendChild(td); div=document.createElement('div'); - td.appendChild(div); div.className='fileList'; - div.setAttribute('style','max-height:'+(parseInt(document.body.clientHeight)-300)+'px;'); - table2=document.createElement('table'); - div.appendChild(table2); - tbody2=document.createElement('tbody'); - table2.appendChild(tbody2); - table2.setAttribute('cellpadding',6); - table2.setAttribute('cellspacing',0); - for(index in content){ - var file=content[index]; - if(file.name){ - file.name=file.name.replace('\'',''); - OC_FILES.files[file['name']]=new OC_FILES.file(dir,file['name'],file['type']); - tr=document.createElement('tr'); - tbody2.appendChild(tr); - tr.className='browserline'; - td=document.createElement('td'); - tr.appendChild(td); - td.className='fileSelector'; - input=document.createElement('input'); - input.setAttribute('type','checkbox'); - input.setAttribute('name','fileSelector'); - input.setAttribute('value',file['name']); - td.appendChild(input); - tr.appendChild(OC_FILES.browser.showicon(file['type'])); - td=document.createElement('td'); - tr.appendChild(td); - td.className='nametext'; - td.setAttribute('name',file['name']); - td.setAttribute('id',file['name']); - a=document.createElement('a'); - td.appendChild(a); - a.appendChild(document.createTextNode(file['name'])); - var fileObject=OC_FILES.files[file['name']]; - a.addEvent('onclick',new callBack(fileObject.actions['default'],fileObject)); - if(file['type']=='dir'){ - td.setAttribute('colspan',2); - a.setAttribute('href','#'+dir+'/'+file['name']); - }else{ - a.setAttribute('href','#'+dir); - sizeTd=document.createElement('td'); - tr.appendChild(sizeTd); - sizeTd.className='sizetext'; - sizeTd.appendChild(document.createTextNode(sizeFormat(file['size']))); - } - a=document.createElement('a'); - var img=document.createElement('img'); - td.appendChild(img); - img.className='file_actions'; - img.alt='' - img.title='actions'; - img.src=WEBROOT+'/img/arrow_down.png'; - var name=file['name']; - img.addEvent('onclick',OC_FILES.browser.showactions,name); - td=document.createElement('td'); - tr.appendChild(td); - td.className='sizetext'; - td.appendChild(document.createTextNode(file['date'])); - } - } - } - tr=document.createElement('tr'); - tfoot.appendChild(tr); - tr.className='utilityline'; - td=document.createElement('td'); - tr.appendChild(td); - td.setAttribute('colspan','4'); - span=document.createElement('span'); - td.appendChild(span); - dropdown=document.createElement('select'); - span.appendChild(dropdown); - dropdown.setAttribute('id','selected_action'); - for(index in this.actions_selected){ - if(this.actions_selected[index].call){ + td.appendChild(div); + OC_FILES.browser.files.show(div,content); + tr=document.createElement('tr'); + tfoot.appendChild(tr); + tr.className='utilityline'; + td=document.createElement('td'); + tr.appendChild(td); + td.className='actionsSelected'; + dropdown=document.createElement('select'); + td.appendChild(dropdown); + dropdown.setAttribute('id','selected_action'); + for(index in OC_FILES.actions_selected){ + if(OC_FILES.actions_selected[index].call){ + option=document.createElement('option'); + dropdown.appendChild(option); + option.setAttribute('value',index); + option.appendChild(document.createTextNode(capitaliseFirstLetter(index))); + } + } + td.appendChild(document.createTextNode(' Selected ')); + button=document.createElement('button'); + td.appendChild(button); + button.appendChild(document.createTextNode('Go')); + button.addEvent('onclick',OC_FILES.action_selected); + div=document.createElement('div'); + td.appendChild(div); + div.className='moreActionsButton'; + OC_FILES.maxUpload=content['max_upload']; + var p=document.createElement('p'); + div.appendChild(p); + p.appendChild(document.createTextNode('More Actions')); + div.setAttribute('id','moreActionsButton'); + OC_FILES.browser.moreActionsShown=false; + p.addEvent('onclick',OC_FILES.browser.showMoreActions); + contentNode.appendChild(table); + }else{ + OC_FILES.browser.breadcrumb.show(null,dir); + OC_FILES.browser.files.show(null,content); + } +} + +OC_FILES.browser.handleDropOn=function(event,node){ + var dropTargetFile=this.file; + var dropFile=node.parentNode.file; + if(dropTargetFile!=dropFile){ + if(dropTargetFile.actions.dropOn && dropTargetFile.actions.dropOn.call){ + dropTargetFile.actions.dropOn.call(dropTargetFile,dropFile); + } + return false; + } +} + +OC_FILES.browser.handleDrop=function(event,node){ + var dropTargetFile=node.file; + var dropFile=this.parentNode.file; + if(dropFile.actions.drop && dropFile.actions.drop.call){ + dropFile.actions.drop.call(dropFile,dropTargetFile); + } + return false; +} + +OC_FILES.browser.showMoreActions=function(){ + if(!OC_FILES.browser.moreActionsList){ + var div=document.createElement('div'); + div.className='moreActionsList'; + var table=document.createElement('table'); + div.appendChild(table); + var tbody=document.createElement('tbody'); + table.appendChild(tbody); + var tr=document.createElement('tr'); + tbody.appendChild(tr); + var td=document.createElement('td'); + tr.appendChild(td); + OC_FILES.browser.showuploader(OC_FILES.dir,td,OC_FILES.maxUpload); + tr=document.createElement('tr'); + tbody.appendChild(tr); + td=document.createElement('td'); + tr.appendChild(td); + var form=document.createElement('form'); + td.appendChild(form); + form.appendChild(document.createTextNode('New ')); + var dropdown=document.createElement('select'); + form.appendChild(dropdown); + dropdown.setAttribute('id','newFileType'); + var option=document.createElement('option'); + dropdown.appendChild(option); + option.setAttribute('value','dir'); + option.appendChild(document.createTextNode('Folder')); option=document.createElement('option'); dropdown.appendChild(option); - option.setAttribute('value',index); - option.appendChild(document.createTextNode(capitaliseFirstLetter(index))); + option.setAttribute('value','file'); + option.appendChild(document.createTextNode('File')); + form.appendChild(document.createTextNode(' ')); + var input=document.createElement('input'); + form.appendChild(input); + input.setAttribute('id','newFileName'); + form.addEvent('onsubmit',OC_FILES.browser.newFile); + var submit=document.createElement('input'); + form.appendChild(submit); + submit.type='submit'; + submit.value='Create'; + OC_FILES.browser.moreActionsList=div; + }else{ + var div=OC_FILES.browser.moreActionsList; } + var button=document.getElementById('moreActionsButton'); + if(!OC_FILES.browser.moreActionsShown){ + button.appendChild(div); + OC_FILES.browser.moreActionsShown=true; + button.className='moreActionsButton moreActionsButtonClicked'; + }else{ + OC_FILES.browser.moreActionsShown=false; + button.removeChild(div); + button.className='moreActionsButton'; } - span.appendChild(document.createTextNode(' Selected ')); - button=document.createElement('button'); - span.appendChild(button); - button.appendChild(document.createTextNode('Go')); - button.addEvent('onclick',OC_FILES.action_selected); - span=document.createElement('span'); - span.className='upload'; - td.appendChild(span); - OC_FILES.browser.showuploader(dir,span,content['max_upload']); - contentNode.appendChild(table); +} + +OC_FILES.browser.newFile=function(event){ + if(event.preventDefault){ + event.preventDefault(); + }; + var typeSelect=document.getElementById('newFileType'); + var type=typeSelect.options[typeSelect.selectedIndex].value; + var name=document.getElementById('newFileName').value; + OC_FILES.newFile(type,name,OC_FILES.dir); + return false; } OC_FILES.browser.showicon=function(filetype){ @@ -220,36 +399,42 @@ OC_FILES.browser.showicon=function(filetype){ img.setAttribute('height',16); if(filetype=='dir'){ img.src=WEBROOT+'/img/icons/folder.png'; + }else if(filetype=='incomplete'){ + img.src=WEBROOT+'/img/icons/loading.gif'; }else{ img.src=WEBROOT+'/img/icons/other.png'; } return td; } +OC_FILES.uploadIFrames=Array(); OC_FILES.browser.showuploader=function(dir,parent,max_upload){ - OC_FILES.uploadForm=document.createElement('form'); - OC_FILES.uploadForm.setAttribute('target','uploadIFrame'); - OC_FILES.uploadForm.setAttribute('action','files/upload.php?dir='+dir); - OC_FILES.uploadForm.method='post'; - OC_FILES.uploadForm.setAttribute('enctype','multipart/form-data'); - OC_FILES.uploadIFrame=document.createElement('iframe'); - OC_FILES.uploadIFrame.className='hidden'; - OC_FILES.uploadIFrame.name='uploadIFrame'; - var input=document.createElement('input'); - input.setAttribute('type','hidden'); - input.setAttribute('name','MAX_FILE_SIZE'); - input.setAttribute('value',max_upload); - input.setAttribute('id','max_upload'); - OC_FILES.uploadForm.appendChild(input); - var file=document.createElement('input'); - file.name='file'; - file.setAttribute('id','fileSelector'); - file.setAttribute('type','file'); - file.addEvent('onchange',OC_FILES.upload,[dir]); - OC_FILES.uploadForm.appendChild(document.createTextNode('Upload file: ')); - OC_FILES.uploadForm.appendChild(file); - parent.appendChild(OC_FILES.uploadForm); - parent.appendChild(OC_FILES.uploadIFrame); + var iframeId=OC_FILES.uploadIFrames.length + OC_FILES.uploadForm=document.createElement('form'); + OC_FILES.uploadForm.setAttribute('target','uploadIFrame'+iframeId); + OC_FILES.uploadForm.setAttribute('action','files/upload.php?dir='+dir); + OC_FILES.uploadForm.method='post'; + OC_FILES.uploadForm.setAttribute('enctype','multipart/form-data'); + OC_FILES.uploadIFrames[iframeId]=document.createElement('iframe'); + OC_FILES.uploadIFrames[iframeId].uploadParent=parent; + OC_FILES.uploadIFrames[iframeId].className='hidden'; + OC_FILES.uploadIFrames[iframeId].name='uploadIFrame'+iframeId; + var input=document.createElement('input'); + input.setAttribute('type','hidden'); + input.setAttribute('name','MAX_FILE_SIZE'); + input.setAttribute('value',max_upload); + input.setAttribute('id','max_upload'); + OC_FILES.uploadForm.appendChild(input); + var file=document.createElement('input'); + file.name='file'; + file.setAttribute('id','fileSelector'); + file.setAttribute('type','file'); + file.addEvent('onchange',OC_FILES.upload,[dir,iframeId]); + OC_FILES.uploadForm.appendChild(document.createTextNode('Upload file: ')); + OC_FILES.uploadForm.appendChild(file); + parent.appendChild(OC_FILES.uploadForm); + var body=document.getElementsByTagName('body').item(0); + body.appendChild(OC_FILES.uploadIFrames[iframeId]); } OC_FILES.browser.show_rename=function(dir,file){ @@ -290,7 +475,7 @@ OC_FILES.browser.rename_cancel=function(file){ OC_FILES.browser.showactions=function(file,hide){ node=document.getElementById(file); - if(node &&(node.actionsshown || hide)){ + if(node &&(node.actionsshown || hide===true)){ if(node.actionsdiv){ node.removeChild(node.actionsdiv); } @@ -308,7 +493,7 @@ OC_FILES.browser.showactions=function(file,hide){ var file=OC_FILES.files[file] var actions=file.actions; for(name in actions){ - if(actions[name].call && name!='default'){ + if(actions[name].call && name!='default' && name!='dropOn' && name!='drop'){ tr=document.createElement('tr'); tbody.appendChild(tr); td=document.createElement('td'); @@ -341,17 +526,20 @@ OC_FILES.browser.hideallactions=function(){ OC_FILES.hideallenabled=true; //used to prevent browsers from hiding actionslists right after they are displayed; sizeFormat=function(size){ - var orig=size; - var steps=Array('B','KiB','MiB','GiB','TiB'); - var step=0; - while(size>(1024*2)){ - step++; - size=size/1024; - } - if(size.toFixed){ - size=size.toFixed(2); - } - return ''+size+' '+steps[step]; + if(isNaN(size)){ + return false; + } + var orig=size; + var steps=Array('B','KiB','MiB','GiB','TiB'); + var step=0; + while(size>(1024*2)){ + step++; + size=size/1024; + } + if(size.toFixed){ + size=size.toFixed(2); + } + return ''+size+' '+steps[step]; } OC_FILES.browser.showImage=function(dir,file){ diff --git a/js/lib_ajax.js b/js/lib_ajax.js index 319875d40e7..6a2ae53ee32 100644 --- a/js/lib_ajax.js +++ b/js/lib_ajax.js @@ -75,7 +75,7 @@ OC_onload.run=function(){ //implement Node.prototype under IE if(typeof Node=='undefined'){ - Node=new Object(); + Node=function(){}; Node.prototype=new Object(); tmpObj=new Object(); @@ -86,8 +86,9 @@ if(typeof Node=='undefined'){ document.createElement=function(tagName){ // alert(tagName); node=document.createElementNative(tagName); - for(name in Node.prototype){ - node[name]=Node.prototype[name]; + var proto=new Node() + for(name in proto){ + node[name]=proto[name]; } return node; } @@ -98,10 +99,10 @@ if(typeof Node=='undefined'){ node=node.item(0) } if(node.nodeType==1){ - for(name in Node.prototype){ -// node[name]=Node.prototype[name]; - eval('node.'+name+'=Node.prototype.'+name+';'); - } + var proto=new Node() + for(name in proto){ + node[name]=proto[name]; + } if(node.hasChildNodes){ var childs=node.childNodes; for(var i=0;i<childs.length;i++){ @@ -112,4 +113,80 @@ if(typeof Node=='undefined'){ } OC_onload.add(new function(){addNodePrototype(document.documentElement);}); OC_onload.add(addNodePrototype,true); +} + +function getStyle(x,styleProp) +{ + if (x.currentStyle){ + alert(x.currentStyle); + var y = x.currentStyle[styleProp]; + }else if (window.getComputedStyle){ + var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp); + } + return y; +} + +Node.prototype.getStyle=function(styleProp){ + return getStyle(this,styleProp) +} + +Node.prototype.clearNode=function(){ + if (this.hasChildNodes() ){ + while(this.childNodes.length>= 1){ + this.removeChild(this.firstChild); + } + } +} + +setDebug=function(text){ + node=document.getElementById('debug'); + if(node){ + node.clearNode(); + node.appendChild(document.createTextNode(text)); + } +} + +arrayMerge=function(array1,array2){ + var array=Array(); + for(i in array1){ + array[i]=array1[i]; + } + for(i in array2){ + array[i]=array2[i]; + } + return array; +} + +if(!Math.sign){ + Math.sign=function(x){ + return x/Math.abs(x); + } +} + +if(!Node.prototype.clearNode){ + Node.prototype.clearNode=function(){ + if(this.hasChildNodes()){ + while(this.childNodes.length >=1){ + this.removeChild(this.firstChild); + } + } + } +} + +getTimeString=function(){ + var date=new Date(); + var months=new Array(12); + months[0]="Jan"; + months[1]="Feb"; + months[2]="Mar"; + months[3]="Apr"; + months[4]="May"; + months[5]="Jun"; + months[6]="Jul"; + months[7]="Aug"; + months[8]="Sep"; + months[9]="Oct"; + months[10]="Nov"; + months[11]="Dec"; + return date.getDate()+' '+months[date.getMonth()]+' '+date.getFullYear()+' '+date.getHours()+':'+date.getMinutes(); }
\ No newline at end of file diff --git a/js/lib_drag.js b/js/lib_drag.js new file mode 100644 index 00000000000..bc6a8610500 --- /dev/null +++ b/js/lib_drag.js @@ -0,0 +1,350 @@ +/** +* Javascript Drag&Drop - Modified for ownCloud +* +* @author Robin Appelman +* @copyright 2010 Robin Appelman icewind1991@gmail.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +position=function(x,y){ + if(x)this.x=x; + if(y)this.y=y; + return this; +} +position.prototype={ + x:0, + y:0, + add:function(pos2){ + return new position(this.x+pos2.x,this.y+pos2.y); + }, + substract:function(pos2){ + return new position(this.x-pos2.x,this.y-pos2.y); + },toString:function(){ + return 'x:'+this.x+',y:'+this.y; + },inside:function(pos2){ + return Math.abs(this.x)<Math.abs(pos2.x) && Math.abs(this.y)<Math.abs(pos2.y) && Math.sign(this.x)==Math.sign(pos2.x) && Math.sign(this.y)==Math.sign(pos2.y); + },outside:function(pos2){ + return !this.inside(pos2); + } +} + +Node.prototype.drag=new Object +/** + * is the node dragable + */ +Node.prototype.drag.dragable=false; +/** + * Are we currently dragging the node + */ +Node.prototype.drag.active=false; +/** + * Create a clone to drag around + */ +Node.prototype.drag.clone=true; +/** + * The node we (visually drag around) + */ +Node.prototype.drag.node=false; +/** + * can we drop nodes on this + */ +Node.prototype.drag.isDropTarget=false; +/** + * our current drop target + */ +Node.prototype.drag.dropTarget=null; +/** + * can we drop this node now + */ +Node.prototype.drag.dropable=false; +/** + * function called when we are being dropped on a node + * @return bool + */ +Node.prototype.drag.onDrop=function(node){}; +/** + * function called when an node is dropped on us + * @param Node node + * @return bool + */ +Node.prototype.drag.onDropOn=function(node){}; +/** + * where did we start the drag + */ +Node.prototype.drag.startPosition=new position(); +/** + * where are we now + */ +Node.prototype.drag.position=new position(); +/** + * how big are we + */ +Node.prototype.drag.size=new position(); +/** + * where is the mouse + */ +Node.prototype.drag.mousePosition=new position(); +/** + * where is the mouse relative to our node + */ +Node.prototype.drag.mouseOffset=new position(); + +document.drag=new Object(); +/** + * is there currently something dragged + */ +document.drag.active=false; +/** + * what is currently being dragged + */ +document.drag.node=null; +document.drag.dropTargets=Array(); +/** + * start the dragging. (onmousedown) + * @param Event event + */ +Node.prototype.drag.start=function(event){ + if(!event)var event=window.event; + if(!this.drag.active && this.drag.dragable){ + document.drag.active=true; + document.drag.node=this; + this.drag.active=true; + this.drag.position=this.getPosition(); + this.drag.startPosition=this.getPosition(); + this.drag.mousePosition=getMousePosition(event); + this.drag.mouseOffset=this.drag.mousePosition.substract(this.drag.position); + } +} + +/** + * update the dragging. (onmousemove) + * @param Event event + */ +Node.prototype.drag.update=function(event){ + if(!event)var event=window.event; + if(this.drag.active && this.drag.dragable){ + this.drag.mousePosition=getMousePosition(event); + this.drag.position=this.drag.mousePosition.substract(this.drag.mouseOffset); + if(this.drag.clone && !this.drag.node){ + this.drag.node=this.cloneNode(true); + this.drag.node.className='dragClone'; + if(this.drag.node.hasAttribute('id')){ + this.drag.node.setAttribute('id',this.drag.node.getAttribute('id')+'_dragClone'); + } + document.getElementsByTagName('body').item(0).appendChild(this.drag.node); + }else if(!this.drag.node){ + this.drag.node=this; + this.drag.node.style.position='absolute'; + } + this.drag.node.style.left=this.drag.position.x+'px'; + this.drag.node.style.top=this.drag.position.y+'px'; + } + return true; +} + +/** + * stop the dragging/drop. (onmouseup) + * @param Event event + * @return bool + */ +Node.prototype.drag.stop=function(event){ + if(!event)var event=window.event; + if(this.drag.active && this.drag.dragable){ + this.drag.active=false; + this.drag.mousePosition=getMousePosition(event); + this.drag.position=this.drag.mousePosition.substract(this.drag.mouseOffset); + if(this.drag.node){ + this.drag.node.style.left=this.drag.position.x; + this.drag.node.style.top=this.drag.position.y; + } + var target; + this.drag.dropTarget=null; + this.drag.dropable=false; + for(var i=0;i<document.drag.dropTargets.length;i++){ + target=document.drag.dropTargets[i]; + target.drag.checkDropTarget.call(target,event); + } + if(this.drag.dropable && this.drag.dropTarget){ + if(this.drag.onDrop){ + this.drag.onDrop.call(this,event,this.drag.dropTarget); + this.triggerEvent.call(this,'ondrop',event,this.drag.dropTarget); + } + if(this.drag.dropTarget.drag.onDropOn){ + this.drag.dropTarget.drag.onDropOn.call(this.drag.dropTarget,event,this); + this.drag.dropTarget.triggerEvent.call(this.drag.dropTarget,'ondropon',event,this); + } + } + if(this.drag.clone && this.drag.node){ + this.drag.node.parentNode.removeChild(this.drag.node); + this.drag.node=null; + } + document.drag.active=false; + document.drag.node=null; + } +} + +/** + * is there currently something being dragged over us + * @param Event event + */ +Node.prototype.drag.checkDropTarget=function(event){ + if(this.drag.isDropTarget & document.drag.active){ + mousePos=getMousePosition(event); + this.drag.position=this.getPosition(); + this.drag.size=this.getSize(true); + var offSet=mousePos.substract(this.drag.position); + if(offSet.inside(this.drag.size)){ + document.drag.node.drag.dropTarget=this; + document.drag.node.drag.dropable=true; + setDebug('ontarget'); + } + } +} + +/** + * called when the mouse is leaving a drop target + * @param Event event + */ +Node.prototype.drag.leaveDropTarget=function(event){ + if(this.drag.isDropTarget & document.drag.active){ + document.drag.node.drag.dropTarget=null; + document.drag.node.drag.dropable=false; + setDebug('offtarget'); + } +} +/** + * initiate the node as drop target + */ +Node.prototype.drag.initDropTarget=function(){ + this.drag.isDropTarget=true; + document.drag.dropTargets.push(this); +} +Node.prototype.makeDropTarget=function(){ + this.drag.initDropTarget.call(this); +} + +/** + * initiate the node as draggable + */ +Node.prototype.drag.init=function(){ + this.drag.dragable=true; + this.drag.size.x=this.getStyle('width'); + this.drag.size.y=this.getStyle('height'); + this.addEvent('onmousedown',new callBack(this.drag.start,this)); +} +Node.prototype.makeDraggable=function(){ + this.drag.init.call(this); +} + +/** + * update the dragging. (onmousemove) + * @param Event event + */ +document.drag.update=function(event){ + var target; + if(document.drag.active && document.drag.node){ + document.drag.node.drag.update.call(document.drag.node,event); + } + return false; +} + +/** + * update the dragging. (onmousemove) + * @param Event event + */ +document.drag.stop=function(event){ + if(document.drag.active && document.drag.node){ + document.drag.node.drag.stop.call(document.drag.node,event); + } + return false; +} +document.events.add(document,'onmousemove',document.drag.update); +document.events.add(document,'onmouseup',document.drag.stop); + +function getMousePosition(event){ + var pos=new position(); + if(!event)var event = window.event; + if(event.pageX||event.pageY){ + pos.x=event.pageX; + pos.y=event.pageY; + } + else if(event.clientX||event.clientY){ + pos.x=event.clientX+document.body.scrollLeft+document.documentElement.scrollLeft; + pos.y=event.clientY+document.body.scrollTop+document.documentElement.scrollTop; + } + return pos; +} + +/** + * get our position + **/ +Node.prototype.getPosition=function(){ + var pos=new position(); + element=this; + do{ + pos.y+=element.offsetTop; + pos.x+=element.offsetLeft; + }while(element=element.offsetParent); + return pos; +} + +/** + * get our size +* @param bool full (also include padding and border) + **/ +Node.prototype.getSize=function(full){ + var pos=new position(); + pos.y= parseInt(this.getStyle('height')); + pos.x= parseInt(this.getStyle('width')); + if(full){ + var extraY=['border-size','padding-top','padding-bottom','border-size']; + var extraX=['border-size','padding-left','padding-right','border-size']; + var tmp; + for(var i=0;i<extraY.length;i++){ + tmp=parseInt(this.getStyle(extraY[i])); + if(tmp){ + pos.y+=tmp; + } + } + for(var i=0;i<extraX.length;i++){ + tmp=parseInt(this.getStyle(extraX[i])); + if(tmp){ + pos.x+=tmp; + } + } + } + return pos; +} + +function mouseTest(event){ + var pos=getMousePosition(event); + setDebug(pos.toString()); +} + +function testDrag(){ + var node=document.getElementById('debug'); +// document.addEvent('onclick',getOffSet,[node]); + node.makeDropTarget(); +} + +function getOffSet(node,event){ + var nodePos=node.getPosition(); + var mousePos=getMousePosition(event); + return mousePos.substract(nodePos); +} + + +// OC_onload.add(testDrag);
\ No newline at end of file diff --git a/js/lib_event.js b/js/lib_event.js index f8482402d09..f44a2049fb2 100755 --- a/js/lib_event.js +++ b/js/lib_event.js @@ -17,33 +17,80 @@ document.events.functions=Array(); document.events.args=Array(); document.events.add=function(element,type,func,args){ + if(!element.eventCallBacks){ + element.eventCallBacks=Array(); + } + if(!element.eventCallBacks[type]){ + element.eventCallBacks[type]=Array(); + } if(args){ - if(typeof args!='object' && typeof args!='Object'){ + if(!args.push){ args=[args]; } } if(!args){ args=Array(); } + args.push('eventHolder'); + args.push('argHolder'); if (type && element){ //wrap the function in a function, otherwise it won't work if func is actually a callBack var funcId=document.events.functions.length; document.events.functions[funcId]=func; document.events.args[funcId]=args; - eval('callback=function(event){result=document.events.functions['+funcId+'].apply(this,document.events.args['+funcId+']);if(result===false){if(event.preventDefault){event.preventDefault();}}};'); + eval('var callback=function(event,arg){document.events.callback.call(this,'+funcId+',event,arg)};'); + element.eventCallBacks[type].push(callback); if(element.addEventListener){ var eventType=type; if(eventType.substr(0,2)=='on'){ eventType=eventType.substr(2); } element.addEventListener(eventType,callback,false); - }else{ + }else if(element.attachEvent){ element.attachEvent(type,callback); } + return callback; + } +} +document.events.remove=function(element,type,func){ + if(element.removeEventListener){ + if(type.substr(0,2)=='on'){ + type=type.substr(2); + } + element.removeEventListener(type,func,false); + }else if(element.detachEvent){ + element.detachEvent(type,func) + } +} + +document.events.callback=function(funcId,event,arg){ + if(!event)var event=window.event; + var args=document.events.args[funcId]; + args[args.length-2]=event; + args[args.length-1]=arg; + result=document.events.functions[funcId].apply(this,args); + if(result===false){ + if(event.preventDefault){ + event.preventDefault(); + }; + } + return result; +} + +document.events.trigger=function(element,type,event,args){ + var callbacks=element.eventCallBacks[type]; + for(var i=0;i<callbacks.length;i++){ + callbacks[i].call(element,event,args); } } Node.prototype.addEvent=function(type,func,arguments){ - document.events.add(this,type,func,arguments); + return document.events.add(this,type,func,arguments); +} +Node.prototype.removeEvent=function(type,func){ + document.events.remove(this,type,func); +} +Node.prototype.triggerEvent=function(type,event,arg){ + return document.events.trigger(this,type,event,arg); }
\ No newline at end of file diff --git a/js/lib_files.js b/js/lib_files.js index 443d440380e..c231af2f03f 100644 --- a/js/lib_files.js +++ b/js/lib_files.js @@ -20,92 +20,184 @@ */ OC_FILES=new Object(); + +OC_FILES.cache=new Object(); + +OC_FILES.cache.files=Array(); +OC_FILES.cache.incomplete=Array(); +OC_FILES.cache.actions=new Object(); + +OC_FILES.cache.actions.move=Array(); +OC_FILES.cache.actions.rename=Array(); +OC_FILES.cache.actions['new']=Array(); +OC_FILES.cache.actions['delete']=Array(); +OC_FILES.cache.actions.upload=Array(); + +OC_FILES.cache.refresh=function(){ + OC_FILES.getdirectorycontent(OC_FILES.dir,false,true); +} + OC_FILES.xmlloader=new OCXMLLoader(); OC_FILES.getdirectorycontent_parse=function(req){ - var files=new Array(); - var response=req.responseXML; - if(response){ - var dir=response.getElementsByTagName('dir').item(0); - files['max_upload']=dir.getAttribute('max_upload'); - var fileElements=response.getElementsByTagName('file'); - if(fileElements.length>0){ - for(index=0;index<fileElements.length;index++){ -// for(index in fileElements){ - var file=new Array(); - var attributes=Array('size','name','type','directory','date'); - for(i in attributes){ - var name=attributes[i]; - file[name]=fileElements.item(index).getAttribute(name); - } - files[file.name]=file; - } - } - if(OC_FILES.getdirectorycontent_callback){ - OC_FILES.getdirectorycontent_callback(files); - } - } -} - -OC_FILES.getdirectorycontent=function(dir,callback){ - if(callback){ - OC_FILES.getdirectorycontent_callback=callback; - } - OC_FILES.xmlloader.setCallBack(OC_FILES.getdirectorycontent_parse); - OC_FILES.xmlloader.load('files/get_files.php?dir='+dir); + var files=new Array(); + var response=req.responseXML; + OC_FILES.cache.files=Array(); + if(response){ + var dir=response.getElementsByTagName('dir').item(0); + var fileElements=response.getElementsByTagName('file'); + if(fileElements.length>0){ + for(index=0;index<fileElements.length;index++){ + var file=new Array(); + var attributes=Array('size','name','type','directory','date'); + for(i in attributes){ + var name=attributes[i]; + file[name]=fileElements.item(index).getAttribute(name); + } + files[file.name]=file; + } + } + OC_FILES.cache.files=files; + if(OC_FILES.cache.incomplete[OC_FILES.dir]){ + files=arrayMerge(files,OC_FILES.cache.incomplete[OC_FILES.dir]); + } + files['max_upload']=dir.getAttribute('max_upload'); + if(OC_FILES.getdirectorycontent_callback){ + OC_FILES.getdirectorycontent_callback(files); + } + } +} + +OC_FILES.getdirectorycontent=function(dir,callback,refresh){ + if(refresh || OC_FILES.dir!=dir){ + OC_FILES.dir=dir; + if(callback){ + OC_FILES.getdirectorycontent_callback=callback; + } + OC_FILES.xmlloader.setCallBack(OC_FILES.getdirectorycontent_parse); + OC_FILES.xmlloader.load('files/get_files.php?dir='+dir); + }else{ + var files=OC_FILES.cache.files + if(OC_FILES.cache.incomplete[OC_FILES.dir]){ + files=arrayMerge(files,OC_FILES.cache.incomplete[OC_FILES.dir]); + } + callback(files); + } } OC_FILES.dir=''; -OC_FILES.upload=function(dir){ - OC_FILES.uploadIFrame.addEvent('onload',new callBack(OC_FILES.upload_callback,OC_FILES),dir); - var fileSelector=document.getElementById('fileSelector'); - var max_upload=document.getElementById('max_upload').value; - if(fileSelector.files && fileSelector.files[0].fileSize){ - var size=fileSelector.files[0].fileSize; - if(size>max_upload){ - new OCNotification('File to large',10000) - return false; - } - } - OC_FILES.uploadForm.submit(); +OC_FILES.upload=function(dir,iframeId){ + var file=new Object; + var fileSelector=document.getElementById('fileSelector'); + var max_upload=document.getElementById('max_upload').value; + var name=false; + if(fileSelector.files && fileSelector.files[0].fileName){ + name=fileSelector.files[0].fileName; + } + if(fileSelector.files && fileSelector.files[0].fileSize){ + var size=fileSelector.files[0].fileSize; + if(size>max_upload){ + new OCNotification('File to large',10000) + return false; + } + } + file.dir=dir; + file.name=name; + file.type='file'; + file.size=size; + file.iframeId=iframeId; + if(!OC_FILES.cache.incomplete[dir]){ + OC_FILES.cache.incomplete[dir]=Array(); + } + OC_FILES.cache.incomplete[dir][name]=Array(); + OC_FILES.cache.incomplete[dir][name]['name']=name; + OC_FILES.cache.incomplete[dir][name]['type']='incomplete'; + OC_FILES.cache.incomplete[dir][name]['size']=size; + OC_FILES.uploadIFrames[iframeId].file=file; + OC_FILES.uploadIFrames[iframeId].addEvent('onload',new callBack(OC_FILES.upload_callback,OC_FILES.uploadIFrames[iframeId])); + OC_FILES.browser.files.add(name,'incomplete',size); + OC_FILES.uploadForm.submit(); + if(OC_FILES.uploadForm.parentElement){ + OC_FILES.uploadForm.className='hidden'; + OC_FILES.uploadForm.parentNode.removeChild(OC_FILES.uploadForm); + var body=document.getElementsByTagName('body').item(0); + body.appendChild(OC_FILES.uploadForm); + OC_FILES.uploadIFrames[iframeId].uploadForm=OC_FILES.uploadForm; + OC_FILES.browser.showuploader(OC_FILES.dir,OC_FILES.uploadIFrames[iframeId].uploadParent,OC_FILES.maxUpload) + } } -OC_FILES.upload_callback=function(dir){ - this.browser.show(dir); +OC_FILES.upload_callback=function(iframeId){ + var file=this.file; + if(OC_FILES.cache.incomplete[file.dir][file.name]){ + OC_FILES.browser.files.remove(file.name); + OC_FILES.cache.files[file.name]=OC_FILES.cache.incomplete[file.dir][file.name] + delete OC_FILES.cache.incomplete[file.dir][file.name]; + OC_FILES.cache.files[file.name]['type']=file.type; + this.uploadForm.parentNode.removeChild(this.uploadForm); + this.parentNode.removeChild(this); + delete OC_FILES.uploadIFrames[file.iframeId]; + OC_FILES.browser.show(file.dir); + } } -OC_FILES.rename=function(dir,file){ - var item=document.getElementById(file+'_newname'); - var newname=item.value; - if(newname==''){ - return false; - }else if(file==newname){ - OC_FILES.browser.show(OC_FILES.dir); - return false; - } - xmlloader=new OCXMLLoader(); - xmlloader.setCallBack(OC_FILES.rename_callback); - xmlloader.load('files/rename.php?dir='+dir+'&file='+file+'&newname='+newname); - return false; +OC_FILES.rename=function(dir,file,event){ + if(event && event.preventDefault){ + event.preventDefault(); + } + var item=document.getElementById(file+'_newname'); + var newname=item.value; + if(newname==''){ + return false; + }else if(file==newname){ + OC_FILES.browser.show(OC_FILES.dir); + return false; + } + xmlloader=new OCXMLLoader(); + xmlloader.setCallBack(OC_FILES.rename_callback); + xmlloader.arg=new Object; + xmlloader.arg.oldname=file; + xmlloader.arg.newname=newname; + xmlloader.arg.dir=dir; + xmlloader.arg.type=OC_FILES.cache.files[file]['type']; + xmlloader.load('files/rename.php?dir='+dir+'&file='+file+'&newname='+newname); + if(!OC_FILES.cache.incomplete[dir]){ + OC_FILES.cache.incomplete[dir]=Array(); + } + OC_FILES.cache.files[file]['type']='incomplete'; + OC_FILES.cache.incomplete[dir][newname]=OC_FILES.cache.files[file]; + OC_FILES.cache.incomplete[dir][newname]['name']=newname; + OC_FILES.browser.files.remove(file); + OC_FILES.browser.files.add(newname,'incomplete'); + return false; } -OC_FILES.rename_callback=function(req){ - OC_FILES.browser.show(OC_FILES.dir); +OC_FILES.rename_callback=function(req,file){ + delete OC_FILES.cache.files[file.oldname] + OC_FILES.cache.files[file.newname]=OC_FILES.cache.incomplete[file.dir][file.newname]; + delete OC_FILES.cache.incomplete[file.dir][file.newname]; + OC_FILES.browser.files.remove(file.newname); + OC_FILES.cache.files[file.newname]['type']=file.type; + OC_FILES.browser.show(OC_FILES.dir); } OC_FILES.remove=function(dir,file){ - remove=confirm('remove file \''+file+'\'?'); - if(remove){ - xmlloader=new OCXMLLoader(); - xmlloader.setCallBack(OC_FILES.remove_callback); - xmlloader.load('files/delete.php?dir='+dir+'&file='+file); - } + remove=confirm('remove file \''+file+'\'?'); + if(remove){ + xmlloader=new OCXMLLoader(); + xmlloader.setCallBack(OC_FILES.remove_callback); + xmlloader.arg=file; + xmlloader.load('files/delete.php?dir='+dir+'&file='+file); + OC_FILES.browser.files.remove(file); + delete OC_FILES.cache.files[file]; + } } -OC_FILES.remove_callback=function(req){ - OC_FILES.browser.show(OC_FILES.dir); +OC_FILES.remove_callback=function(req,name){ +// OC_FILES.browser.files.remove(name); +// OC_FILES.browser.show(OC_FILES.dir); } OC_FILES.getSelected=function(){ @@ -119,6 +211,63 @@ OC_FILES.getSelected=function(){ return files; } +OC_FILES.newFile=function(type,name,dir){ + xmlloader=new OCXMLLoader(); + xmlloader.arg=new Object; + xmlloader.arg.name=name; + xmlloader.arg.dir=dir; + xmlloader.arg.type=type; + xmlloader.setCallBack(OC_FILES.new_callback); + xmlloader.load('files/new.php?type='+type+'&dir='+dir+'&name='+name); + if(!OC_FILES.cache.incomplete[dir]){ + OC_FILES.cache.incomplete[dir]=Array(); + } + OC_FILES.cache.incomplete[dir][name]=Array(); + OC_FILES.cache.incomplete[dir][name]['name']=name; + OC_FILES.cache.incomplete[dir][name]['type']='incomplete'; + OC_FILES.cache.incomplete[dir][name]['size']=0; + OC_FILES.browser.files.add(name,'incomplete'); +} + +OC_FILES.new_callback=function(req,file){ + OC_FILES.cache.files[file.name]=OC_FILES.cache.incomplete[file.dir][file.name]; + delete OC_FILES.cache.incomplete[file.dir][file.name]; + OC_FILES.cache.files[file.name]['type']=file.type; + OC_FILES.browser.files.remove(name); + OC_FILES.browser.show(OC_FILES.dir); +} + +OC_FILES.move=function(source,target,sourceDir,targetDir){ + if(sourceDir!=targetDir || source!=target){ + if(!OC_FILES.cache.incomplete[sourceDir]){ + OC_FILES.cache.incomplete[sourceDir]=Array(); + } + if(!OC_FILES.cache.incomplete[targetDir]){ + OC_FILES.cache.incomplete[targetDir]=Array(); + } + if(!OC_FILES.cache.incomplete[targetDir+'/'+target]){ + OC_FILES.cache.incomplete[targetDir+'/'+target]=Array(); + } + xmlloader=new OCXMLLoader(); + xmlloader.arg=new Object; + xmlloader.arg.source=source; + xmlloader.arg.target=target; + xmlloader.arg.sourceDir=sourceDir; + xmlloader.arg.targetDir=targetDir; + xmlloader.arg.type=OC_FILES.cache.files[source]['type']; + OC_FILES.cache.files[source]['type']='incomplete'; + OC_FILES.cache.incomplete[targetDir+'/'+target][source]=OC_FILES.cache.files[source] + xmlloader.setCallBack(OC_FILES.move_callback); + xmlloader.load('files/move.php?sourcedir='+sourceDir+'&targetdir='+targetDir+'&source='+source+'&target='+target); + } +} + +OC_FILES.move_callback=function(req,file){ + OC_FILES.cache.incomplete[file.targetDir+'/'+file.target][file.source]['type']=file.type; + delete OC_FILES.cache.files[file.source]; + OC_FILES.browser.show(OC_FILES.dir); +} + OC_FILES.selectAll=function(){ var value=document.getElementById('select_all').checked; var nodes=document.getElementsByName('fileSelector'); @@ -161,31 +310,33 @@ OC_FILES.actions_selected['delete']=function(){ OC_FILES.files=Array(); OC_FILES.file=function(dir,file,type){ - this.type=type; - this.file=file; - this.dir=dir; - this.actions=new Object(); - if(file.lastIndexOf('.')){ - this.extention=file.substr(file.lastIndexOf('.')+1); - }else{ - this.extention; - } - for(index in OC_FILES.fileActions.all){ - if(OC_FILES.fileActions.all[index].call){ - this.actions[index]=OC_FILES.fileActions.all[index]; - } - } - if(OC_FILES.fileActions[this.type]){ - for(index in OC_FILES.fileActions[this.type]){ - if(OC_FILES.fileActions[this.type][index].call){ - this.actions[index]=OC_FILES.fileActions[this.type][index]; + if(file){ + this.type=type; + this.file=file; + this.dir=dir; + this.actions=new Object(); + if(file.lastIndexOf('.')){ + this.extention=file.substr(file.lastIndexOf('.')+1); + }else{ + this.extention; + } + for(index in OC_FILES.fileActions.all){ + if(OC_FILES.fileActions.all[index].call){ + this.actions[index]=OC_FILES.fileActions.all[index]; } } - } - if(OC_FILES.fileActions[this.extention]){ - for(index in OC_FILES.fileActions[this.extention]){ - if(OC_FILES.fileActions[this.extention][index].call){ - this.actions[index]=OC_FILES.fileActions[this.extention][index]; + if(OC_FILES.fileActions[this.type]){ + for(index in OC_FILES.fileActions[this.type]){ + if(OC_FILES.fileActions[this.type][index].call){ + this.actions[index]=OC_FILES.fileActions[this.type][index]; + } + } + } + if(OC_FILES.fileActions[this.extention]){ + for(index in OC_FILES.fileActions[this.extention]){ + if(OC_FILES.fileActions[this.extention][index].call){ + this.actions[index]=OC_FILES.fileActions[this.extention][index]; + } } } } @@ -221,6 +372,10 @@ OC_FILES.fileActions.dir.open=function(){ } OC_FILES.fileActions.dir['default']=OC_FILES.fileActions.dir.open; +OC_FILES.fileActions.dir.dropOn=function(file){ + OC_FILES.move(file.file,this.file,file.dir,this.dir); +} + OC_FILES.fileActions.jpg=new Object() OC_FILES.fileActions.jpg.show=function(){ @@ -233,21 +388,4 @@ OC_FILES.fileActions.jpg['default']=OC_FILES.fileActions.jpg.show; OC_FILES.fileActions.jpeg=OC_FILES.fileActions.jpg OC_FILES.fileActions.png=OC_FILES.fileActions.jpg OC_FILES.fileActions.gif=OC_FILES.fileActions.jpg -OC_FILES.fileActions.bmp=OC_FILES.fileActions.jpg - -function getStyle(el,styleProp) -{ -// var x = document.getElementById(el); - var x=el; - if (x.currentStyle){ - alert(x.currentStyle); - var y = x.currentStyle[styleProp]; - }else if (window.getComputedStyle){ - var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp); - } - return y; -} - -Node.prototype.getStyle=function(styleProp){ - return getStyle(this,styleProp) -}
\ No newline at end of file +OC_FILES.fileActions.bmp=OC_FILES.fileActions.jpg
\ No newline at end of file diff --git a/js/lib_xmlloader.js b/js/lib_xmlloader.js index ce6fd824fc1..12ebfa474b6 100644 --- a/js/lib_xmlloader.js +++ b/js/lib_xmlloader.js @@ -38,6 +38,7 @@ OCXMLLoader.prototype={ request:'', callBack:null, async:true, + arg:null, /** * Loads an XML document @@ -85,9 +86,9 @@ OCXMLLoader.prototype={ var HttpStatus=req.status; if (HttpStatus==200 || HttpStatus==0){ //alert("response: "+this.req.responseText); - this.callBack(this.req); + this.callBack(this.req,this.arg); }else{ - this.errorCallBack(this.req); + this.errorCallBack(this.req,this.arg); } } }, |