?login_element?

Subversion Repositories NedoOS

Rev

Rev 1549 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. var curDir='';
  2. var s;
  3. var xhr;
  4. var fileToUp;
  5. var fCnt;
  6. var r;
  7. var cyr866="АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмноп░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀рстуфхцчшщъыьэюяЁёЄєЇїЎў°∙·√№¤■ ";
  8. function to866(str){
  9.         var s866="";
  10.         for(var i=0;i<str.length;i++){
  11.                 var ch=str.charCodeAt(i);
  12.                 if(ch>127){
  13.                         ch=cyr866.indexOf(str[i])+128;
  14.                         if(ch>=0){s866+="%"+ch.toString(16).toUpperCase();}
  15.                         else{s866+="x";}
  16.                 }else{
  17.                         s866+=str[i];
  18.                 }
  19.         }
  20.         return s866;
  21. }
  22. function myGet(up, us) {
  23.         var r = new XMLHttpRequest();
  24.         us = to866(us)
  25.         if (up=='?d='){
  26.                 us = encodeURIComponent(us)
  27.         }
  28.         r.open("GET", up+us+"&r="+Math.random(), false);
  29.         r.send(null);  
  30.         return r.responseText;
  31. }
  32.  
  33. function mkdir(){
  34.         var ss = window.curDir+'/'+document.getElementById('dirName').value;
  35.         document.getElementById('log').innerHTML=myGet('?m=', ss);
  36.         rddir(window.curDir);
  37. }
  38.  
  39. function unlink(dirPath){
  40.         var ss = window.curDir+'/'+dirPath;
  41.         document.getElementById('log').innerHTML=myGet('?u=', ss);
  42.         rddir(window.curDir);
  43. }
  44. function runprog(dirPath){
  45.         var ss = dirPath;
  46.         document.getElementById('log').innerHTML=myGet('?s=', ss);
  47. }
  48. function compareFileInfo(finfoA, finfoB) {
  49.         if(finfoA.isdir==3 || finfoB.isdir==3) return 0;
  50.         return finfoA.fn.localeCompare(finfoB.fn);
  51. }
  52. function rddir(dirPath){
  53.         var i=0;
  54.         var k=0;
  55.         window.s='';
  56.         window.curDir=dirPath;
  57.         window.s+='Current dir: <a href="javascript:rddir(\'\')">0:</a>';
  58.         if(dirPath!=''){
  59.                 while((k=dirPath.indexOf('/',i))!=-1){
  60.                         window.s+='<a href="javascript:rddir(\''+dirPath.substring(0,k)+'\')">'+
  61.                                 dirPath.substring(i,k)+'</a>/';
  62.                         i=k+1;
  63.                 }
  64.                 window.s+=dirPath.substring(i);
  65.         }
  66.         window.s+='<br><table>';
  67.         j=JSON.parse(myGet('?d=', dirPath));
  68.         j.fno.sort(compareFileInfo);
  69.         j.fno.forEach(function(item, i, arr) {
  70.                 var n,pn;
  71.                 if(item.isdir==1){
  72.                         n=item.fn;
  73.                         if(n=='..')pn=dirPath.substr(0,dirPath.lastIndexOf('/'));
  74.                         else pn=((dirPath=='')?(''):(dirPath+'/'))+n;
  75.                         if(n!="."){
  76.                                 window.s+='<tr>';
  77.                                
  78.                                 window.s+='<td><a href="javascript:rddir(\''+pn+'\')">'+n+'</a></td><td></td><td></td><td>';
  79.                                
  80.                                 window.s+='</td><td><a href="javascript:unlink(\''+n+'\')">Remove</a><td>';
  81.                                 window.s+='</tr>';
  82.                         }
  83.                 }
  84.         });    
  85.         j.fno.forEach(function(item, i, arr) {
  86.                 var n,pn,iof;
  87.                 if(item.isdir==0){
  88.                         n=item.fn;
  89.                         pn=((dirPath=='/')?(''):(dirPath+'/'))+n;
  90.                         window.s+='<tr>';
  91.                        
  92.                         window.s+='<td>'+n+'</td><td>'+item.sz+'B </td><td>'+'<a href="?g='+encodeURIComponent(pn)+'">Download</a></td>';
  93.                         iof=n.lastIndexOf('.');
  94.                         if(iof != -1){
  95.                                 switch(n.toLowerCase().substring(iof)){
  96.                                         case '.com':
  97.                                                 window.s+='<td><a href="javascript:runprog(\''+pn+'\')">Run</a></td>';
  98.                                                 break;                                 
  99.                                         case '.pt3':   
  100.                                         case '.pt2':
  101.                                         case '.tfc':
  102.                                         case '.m':
  103.                                         case '.mt3':
  104.                                         case '.et':
  105.                                         case '.etc':
  106.                                         case '.cmp':
  107.                                         case '.tfd':
  108.                                         case '.tfm':                           
  109.                                                 window.s+='<td><a href="javascript:runprog(\'bin/player.com%20/'+pn+'\')">Play</a></td>';
  110.                                                 break;
  111.                                         case '.mod':                           
  112.                                                 window.s+='<td><a href="javascript:runprog(\'bin/modplay.com%20/'+pn+'\')">Play</a></td>';
  113.                                                 break;
  114.                                         case '.mp3':
  115.                                         case '.mid':
  116.                                         case '.ogg':
  117.                                         case '.aac':
  118.                                         case '.mdr':
  119.                                         case '.mwm':
  120.                                                 window.s+='<td><a href="javascript:runprog(\'bin/gp.com%20/'+pn+'\')">Play</a></td>';
  121.                                                 break;
  122.                                         case '.16c':
  123.                                         case '.fnt':
  124.                                         case '.img':
  125.                                         case '.3':
  126.                                         case '.888':
  127.                                         case '.y':
  128.                                         case '.+':
  129.                                         case '.-':
  130.                                         case '.plc':
  131.                                         case '.mc ':
  132.                                         case '.mcx':
  133.                                         case '.grf':
  134.                                         case '.ch$':
  135.                                         case '.mg1':
  136.                                         case '.mg2':
  137.                                         case '.mg4':
  138.                                         case '.mg8':
  139.                                         case '.rm':
  140.                                         case '.mlt':
  141.                                         case '.53c':                                           
  142.                                         case '.zxs':
  143.                                         case '.atr':
  144.                                         case '.scr':
  145.                                                 window.s+='<td><a href="javascript:runprog(\'bin/view.com%20/'+pn+'\')">View</a></td>';
  146.                                                 break;
  147.                                         case '.gif':
  148.                                         case '.jpg':
  149.                                         case '.png':
  150.                                         case '.htm':
  151.                                         case '.svg':
  152.                                                 window.s+='<td><a href="javascript:runprog(\'bin/browser.com%20/'+pn+'\')">View</a></td>';
  153.                                                 break;
  154.                                         case '.bmp':
  155.                                                 window.s+='<td><a href="javascript:runprog(\'bin/scratch.com%20/'+pn+'\')">View</a></td>';
  156.                                                 break;                 
  157.                                         default:
  158.                                                 window.s+='<td></td>';
  159.                                                 break;
  160.                                 }
  161.                         }else
  162.                                 window.s+='<td></td>';
  163.                         /*
  164.                         if(n.toLowerCase().substring(n.length-4)=='.com')
  165.                                 window.s+='<td><a href="javascript:runprog(\''+pn+'\')">Run</a></td>'; 
  166.                         else if(n.toLowerCase().substring(n.length-4)=='.pt3'){
  167.                                 window.s+='<td><a href="javascript:runprog(\'bin/player.com%20/'+pn+'\')">Play</a></td>';      
  168.                         }
  169.                         else
  170.                                 window.s+='<td></td>';
  171.                         */
  172.                         window.s+='</td><td><a href="javascript:unlink(\''+n+'\')">Remove</a></td>';
  173.                         window.s+='</tr>';
  174.                 }
  175.         });
  176.  
  177.         s+='</table>';
  178.         document.getElementById('divlog').innerHTML=s;
  179. }
  180.  
  181. function log(html) {
  182.         document.getElementById('log').innerHTML = html;
  183. }
  184. function endUp(){
  185.         if(window.r!==undefined){
  186.                 if(window.r.response=="") {
  187.                         setTimeout(endUp, 100);
  188.                         return;
  189.                 }
  190.         }
  191.         window.fcnt--;
  192.         if(window.fcnt>0){
  193.                 inpFilePtr();
  194.         }else{
  195.                 rddir(window.curDir);  
  196.                 window.fileToUp.files=null;
  197.                 document.getElementById('btnUpload').innerHTML='upload';
  198.                 window.r = new XMLHttpRequest();
  199.         }
  200. }
  201. fileToUp = document.getElementById("fileToUp");
  202. function inpFilePtr() {
  203.         var cf=window.fileToUp.files[window.fileToUp.files.length-window.fcnt];
  204.         document.getElementById('btnUpload').innerHTML=cf.name+'...';
  205.         window.r = new XMLHttpRequest();
  206.         window.r.open("PUT", to866(((window.curDir=='')?'':(window.curDir+'/'))+cf.name), true);
  207.         window.r.upload.onprogress = function(event) {
  208.                 document.getElementById('btnUpload').innerHTML=cf.name+' '+event.loaded + '/' + event.total;}
  209.         window.r.upload.onload = endUp;
  210.         window.r.upload.onerror = function(event) {
  211.                 inpFilePtr();}
  212.         window.r.send(cf);
  213. }
  214. fcnt=0;
  215. fileToUp.oninput = function(){
  216.         window.fcnt=window.fileToUp.files.length;
  217.     if(window.fcnt<=0) return;
  218.         inpFilePtr();
  219. };
  220. log('status');
  221. rddir('');
  222.  
  223.