Widget File Sync部分的HTML和JS(个人风格)

index.html

 

<html>
    <head>
        <title>REUTERS</title>
    </head>
    <script type="text/javascript" language="javasrcipt" src="script/file.js"></script>
    <body onLoad="init()">
        <div id="top"><img src="images/top1.png"/></div>
        <div id="bgimage" style="width:240px;">
            <div  id="menuPad">
                <a href="#" οnclick='reset();showDownloadPad();'>&nbsp;&nbsp;&nbsp;&nbsp;同步下载&nbsp;&nbsp;&nbsp;&nbsp;</a>
                <a href="#" οnclick='reset();showUploadPad();'>&nbsp;&nbsp;&nbsp;&nbsp;同步上传&nbsp;&nbsp;&nbsp;&nbsp;</a>
                <a href="#" οnclick='reset();sourceInputPad();'>&nbsp;&nbsp;&nbsp;&nbsp;文件共享&nbsp;&nbsp;&nbsp;&nbsp;</a><br/>
            </div>
            <div id="showPad1"></div>
            <div id="showPad2"></div>
            <div id="showPad3"></div>
        </div>
    </body>
</html>

 

file.js

 

var filepath;//上传文件的绝对路径
var root;//手机根目录列表
var downfiles = new Array();//选择后的文件下载列表
var sourceID;//取得的共享目标
var uploadfile;//上传文件参数设置JSONObject字符串
function init()
{
    File.init();
    var downlist = File.getDownloadList();
    if(downlist.length > 5)
        if(confirm('同步文件超过5条,是否选择下载'))
            showDownloadPad();
    else
    {
        if(File.syncDownload(downlist))
            alert('同步成功!');
        else
            alert('同步失败!');
    }
}
function setFile(arg){
    filepath = arg;
    //document.getElementById('showPad2').innerHtml = filepath;//For test!
}
function setRoot(arg){
    root= arg;
}

function setDownload(arg)
{
    var id = 'downloadfile' +arg;
    if(document.getElementById(id).checked)
        downfiles.push(document.getElementById(id).value);
    else{
        var removeValue = document.getElementById(id).value;
        var temp = new Array();
        for (var i=0; i<downfiles.length; i++ )
            if(downfiles[i] != removeValue)
                temp.push(downfiles[i]);
        downfiles = temp;
    }
    document.getElementById('showPad2').innerHtml = '<a href="#" οnclick="startDownload(downfiles);">开始下载</a>';
    //document.getElementById('showPad2').innerHtml = downfiles.toString();//For test!
}
function startDownload(arg)
{
    if(File.download(arg))
    {
        reset();
        alert('下载成功');
    }
    else
    {
        reset();
        if(confirm('下载失败,是否重试?'))
        {
            if(confirm('进行同步下载?'))
                showDownloadPad();
            else
                sourceInputPad();
        }
    }
}
function showList(arg)
{
    var result = '';
    var downlist = arg;
   
    if(downlist.length > 0)
    {
        for (var i=0; i<downlist.length; i++ )
        {
            var temp = eval('('+downlist[i]+')');
            result += '<input type="checkbox" name="checkbox" id="downloadfile'+i+'" value="'+temp['name']+'.'+temp['type']+'"'
            +'οnclick="setDownload('+i+')">'
            +'文件: '+temp['name']+'.'+temp['type']+'&nbsp;&nbsp;&nbsp;&nbsp;大小: '+temp['size']+'字节<br/>描述: '+temp['description']
            +'</input><br/>';
        }
        document.getElementById('showPad1').innerHtml = result;
    }
    else
        document.getElementById('showPad1').innerHtml = '无可下载内容!';
}
function showDownloadPad()
{  
    var result = '';
    showList(File.getDownloadList());

   
}
function showUploadPad()
{   
    //获得根目录
    var result = '选择根目录<select id="rootlist" οnchange="setRoot(document.getElementById(/'rootlist/').value);showAllFiles();">';
    var rootlist = new Array();
    rootlist = File.getRoots();
    for (var i=0; i<rootlist.length; i++ )
    {
        result += '<option value="'+rootlist[i]+'">'+rootlist[i]+'</option>';
    }

    result += '</select>';
    document.getElementById('showPad1').innerHtml = result;
    showAllFiles();
}
function showAllFiles()
{
    //获得根目录下文件
    var result = '选择该根目录下文件<br/><select id="filelist" οnchange="setFile(document.getElementById(/'filelist/').value);">';
    var filelist = new Array();
    root = document.getElementById('rootlist').value;
    filelist = File.getFiles(root);
    for (var i=0; i<filelist.length; i++ )
    {
        result += '<option value="'+filelist[i]+'">'+filelist[i]+'</option>';
    }
    result += '</select><br/><br/>上传文件参数设置<br/>';
    result += '文件名<input id="uploadFileName"/><br/>类&nbsp;&nbsp;&nbsp;&nbsp;型<input id="uploadFileType"/><br/>文件描述信息<input id="uploadFileDescription" value="It is a file.."/><br/>'+
        '文件访问权限<select id="uploadFileAccessibility"><option value="personal">personal</option>'+
        '<option value ="friendly">friendly</option><option value ="public">public</option>'+
        '</select><br/>';
    document.getElementById('showPad2').innerHtml = result;
    filepath = document.getElementById('filelist').value
    getUploadPadChange();
    document.getElementById('showPad3').innerHtml = '<a href="#" οnclick="getUploadPadChange();startUpload(uploadfile,filepath);">开始上传</a>';
}
function startUpload(arg1,arg2)
{
    if(File.upload(arg1,arg2))
    {
        reset();
        alert('上传成功');
    }
    else
    {
        reset();
        if(conform('上传失败!是否重试?'))
            showUploadPad();
    }
}
function getUploadPadChange()
{
    uploadfile = '{"name":"'+document.getElementById('uploadFileName').value+'",'
    +'"type":"'+document.getElementById('uploadFileType').value+'",'
    +'"accessibility":"'+document.getElementById('uploadFileAccessibility').value+'",'
    +'"desciption":"'+document.getElementById('uploadFileDescription').value+'"'
    +'}';
}
function getSource()
{
    sourceID = document.getElementById('source').value;
}
function sourceInputPad()
{
   
    document.getElementById('showPad1').innerHtml = '共享目标用户ID<input id="source" οnchange="getSource()"></input><br/>';
    document.getElementById('showPad2').innerHtml = '<a href="#" οnclick="showSharePad(sourceID)">确定</a>';
}

function showSharePad(arg)
{   
    showList(File.getShareList(arg));
}
function reset()
{
    //清空各个div
    document.getElementById('showPad1').innerHtml = '';
    document.getElementById('showPad2').innerHtml = '';
    document.getElementById('showPad3').innerHtml = '';
    //清空downfiles全局变量
    var downfiles = new Array();
}
/*以下均为测试用桩函数*/
/*function getRoots(){
    return new Array('1','2');
}*/
/*function getFiles(){
    return new Array('1','2');
}*/
/*function getDownloadList()
{
    return new Array('{"name":"test","type":"mpeg","size":1024 ,"description":"test mpeg movie"}','{"name":"demo","type":"3pg","size":128,"description":"demo 3gp movie"}');
}*/
/*function getShareList(arg)
{
    return new Array('{"name":"test","type":"mpeg","size":1024 ,"description":"test mpeg movie"}','{"name":"demo","type":"3pg","size":128,"description":"demo 3gp movie"}');
}*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值