upgradefiles.js 7.55 KB
var timeout2;

$(document).ready(function(){
	
	var process = $("#process").val();
	if(process != "" && process != "0") {
		//bindnextclick(process);
		getData();
		clearInterval(timeout2);
		timeout2=setInterval(getData,1000);
	} else {
		doUpgrade();
	}

});
function  bindnextclick(process){
	
 	$("#next").unbind("click");
 	if(process =="100") {
 		$("#message").html("备份成功!请点击“下一步”开始执行脚本。<br><span style='font-size:10px;'>备份目录:"+$("#backuppath").val()+"</span>");
 		$("#next").click(function(){

	  	});
 	}
}
var clicktag = 0;
function next() {
    if (clicktag == 0) {
        clicktag = 1;
        $.get('/getProcess.do?date=' + (new Date()).valueOf(), function (res) {
            var pro = res.progress;
            var backuppath = res.backuppath;
            if (pro == "100") {
                window.onbeforeunload = null;
                processSql();
            } else {
                top.Dialog.alert("正在备份!");
            }
        });
        setTimeout(function() {
            clicktag = 0;
        }, 500);
    } else {
        alert("请勿频繁点击!");
    }
}
function doUpgrade()
{
	$("#message").html("开始备份,请稍候...");
	$("#bak").show();
    $.get('/upgrade.do?date='+(new Date()).valueOf(),function(data)
 	{
 		
 		var result = data;

 		if(""+result.isSuccess=="true")
 		{
	 		clearInterval(timeout2);

	 		$("#pro").css("width","100%");
	     	$("#promsg").html("100%");
	     	$("#message").html("备份成功!请点击“下一步”开始执行脚本。<br><span style='font-size:10px;'>系统已备份,备份目录:"+decodeURIComponent(decodeURIComponent(result.backuppath))+"</span>");
	     	$("#next").attr("disabled",false);
	     	$("#next").unbind("click");
 		}
 		else if(""+result.isSuccess=="false")
 		{
            if("100" == pro) {
                clearInterval(timeout2);
                top.Dialog.confirm("覆盖文件失败,确认还原?",
                    function(){
                        window.location.href="/updateclient/backup.jsp";
                    },
                    function(){
                        $("#message").html("覆盖文件失败!<br><span style='font-size:10px;'>系统已备份,备份目录:"+decodeURIComponent(decodeURIComponent(result.backuppath))+"</span>");
                    });
            } else {
                if(res.message == "BackupError" || res.message == "BackupClassbeanError") {
                    clearInterval(timeout2);
                    if(monitorMousedDown){
                        monitorMousedDown = false;
                        $("#message").html(res.message);
                        $("#message").html("覆盖文件失败!请重新升级。");
                        top.Dialog.confirm("覆盖文件失败,确认还原?(还原后系统仍不能正常使用,请联系泛微技术排查原因。)",
                            function(){
                                $.post('/backup.do?statusreset=1&date='+(new Date()).valueOf(),function(data){
                                    window.location.href="/updateclient/checkDB.jsp";
                                });
                            },
                            function(){
                            });
                    }
                }
            }

            return;

 		}
        
  	});	
	timeout2=setInterval(getData,1000);
}
function processSql() {
	
	$.post('/processSql.do?date='+(new Date()).valueOf(),function(data){
		window.location.href="/updateclient/processSql.jsp";
	});
}
function getData()
{
	$("#bak").show();
 	$.get('/getProcess.do?date='+(new Date()).valueOf(),function(res){
 			  //var backuppath = $("#backuppath").val();
 			 var pro = res.progress;
 		
 			 var backuppath = res.backuppath;
 			 backuppath = decodeURIComponent(decodeURIComponent(backuppath));
 			 var filecount = res.filecount;
 			 var filecurrent = res.filecurrent;
 			 var covererror = res.covererror;
    		 if(""+res.isSuccess=="false") {

                 var pro = res.progress;
                 if("100" == pro) {
                     clearInterval(timeout2);
                     top.Dialog.confirm("覆盖文件失败,确认还原?",
                         function(){
                             window.location.href="/updateclient/backup.jsp";
                         },
                         function(){
                             $("#message").html("覆盖文件失败!<br><span style='font-size:10px;'>系统已备份,备份目录:"+decodeURIComponent(decodeURIComponent(result.backuppath))+"</span>");
                         });
				 } else {
                 	if(res.message == "BackupError" || res.message == "BackupClassbeanError") {
                        clearInterval(timeout2);
                        if(monitorMousedDown){
                            monitorMousedDown = false;
                            $("#message").html(res.message);
                            $("#message").html("覆盖文件失败!请重新升级。");
                            top.Dialog.confirm("覆盖文件失败,确认还原?(还原后系统仍不能正常使用,请联系泛微技术排查原因。)",
                                function(){
                                    $.post('/backup.do?statusreset=1&date='+(new Date()).valueOf(),function(data){
                                        window.location.href="/updateclient/checkDB.jsp";
                                    });
                                },
                                function(){
                                });
                        }
                        return;
					}

				 }

        	 }
 			 
 			  $("#backuppath").val(backuppath);
 	     	  $("#pro").css("width",pro+"%");
 	     	  $("#promsg").html(pro+"%");
 	     	  $("#pro").show();
 	     	  if(covererror=="1") {//部分文件没有覆盖全
 	     			window.location.href="/updateclient/errorFiles.jsp?process="+pro;
 	     			clearInterval(timeout2);
 	     		
 	     	  }
 	     	  if(pro == "0") {
 	     		$("#message").html("正在备份ecology,请稍候...");
 	     	  } else if(pro == "5"){
 	     		$("#message").html("正在备份ecology,请稍候...");
 	     	  }else if(pro == "25") {
 	     		$("#message").html("正在备份resin,请稍候..."); 
 	     	  } else if(pro == "50") {
 	     		$("#message").html("正在覆盖ecology,请稍候...(补丁包中文件总数:"+filecount+",已覆盖数量:"+filecurrent+")<br><span style='font-size:10px;'>系统已备份,备份目录:"+backuppath+"</span>");
 	     	  } else if(pro == "75") {
 	     		$("#message").html("正在覆盖resin,请稍候...(补丁包中文件总数:"+filecount+",已覆盖数量:"+filecurrent+")<br><span style='font-size:10px;'>系统已备份,备份目录:"+backuppath+"</span>");
 	     	  } else if(pro == "90") {
 	     		$("#message").html("正在删除临时文件,请稍候...<br><span style='font-size:10px;'>系统已备份,备份目录:"+backuppath+"</span>");
 	     	  } else {
 	     		$("#message").html("备份成功!请点击“下一步”开始执行脚本。<br><span style='font-size:10px;'>系统已备份,备份目录:"+backuppath+"</span>");
 	     		clearInterval(timeout2);
 	     	  }
  	});	
} 
var dWidth = 600;
var dHeight = 500;
function doOpen(url,title){
	if(typeof dialog  == 'undefined' || dialog==null){
		dialog = new window.top.Dialog();
	}
	dialog.currentWindow = window;
	dialog.Title = title;
	dialog.Width =  dWidth || 700;
	dialog.Height =  dWidth || 300;
	dialog.Drag = true;
	dialog.maxiumnable = true;
	dialog.URL = url;
	
	dialog.show();
}