home.js 55.7 KB
Newer Older
高源 已提交
1
/**
青阳龙野's avatar
青阳龙野 已提交
2
 * home.js kiftd主页面操作定义 by 青阳龙野 该文件为home.html的操作定义文件,包含了kiftd页面上的主要操作实现。
高源 已提交
3 4
 */

青阳龙野's avatar
青阳龙野 已提交
5 6 7 8
var locationpath = "root";// 记录当前文件路径
var parentpath = "null";// 记录当前文件路径的父级目录
var ap;// 音乐播放器对象
var zipTimer;// 打包下载计时器
青阳龙野's avatar
青阳龙野 已提交
9 10 11 12
var folderView;// 返回的文件系统视图对象
var originFolderView;// 保存原始的文件视图对象
var fs;// 选中的要上传的文件列表
var checkedMovefiles;// 移动文件的存储列表
青阳龙野's avatar
青阳龙野 已提交
13
var constraintLevel;// 当前文件夹限制等级
青阳龙野's avatar
青阳龙野 已提交
14
var account;// 用户账户
青阳龙野's avatar
青阳龙野 已提交
15
var isUpLoading=false;// 是否正在执行其他上传操作
高源 已提交
16

青阳龙野's avatar
青阳龙野 已提交
17
// 页面初始化
高源 已提交
18
$(function() {
青阳龙野's avatar
青阳龙野 已提交
19
	getServerOS();// 得到服务器操作系统信息
青阳龙野's avatar
青阳龙野 已提交
20
	showFolderView("root");// 显示根节点页面视图
青阳龙野's avatar
青阳龙野 已提交
21
	// 点击空白处取消选中文件并重新加载文件视图(不支持火狐)
青阳龙野's avatar
青阳龙野 已提交
22 23 24
	$(document).click(function(e) {
		var filetable = $("#filetable")[0];
		if (e.target !== filetable && !$.contains(filetable, e.target)) {
青阳龙野's avatar
青阳龙野 已提交
25 26 27
			$(".filerow").removeClass("info");
		}
	});
青阳龙野's avatar
青阳龙野 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40
	// 关闭音乐播放模态框自动停止播放并将进度归0
	$('#audioPlayerModal').on('hidden.bs.modal', function(e) {
		if (ap != null) {
			ap.seek(0);
			ap.pause();
		}
	});
	// 关闭打包下载模态框自动停止计时
	$('#downloadAllCheckedModal').on('hidden.bs.modal', function(e) {
		if(zipTimer!=null){
			window.clearInterval(zipTimer);
		}
	});
青阳龙野's avatar
青阳龙野 已提交
41 42 43 44 45
	// 关闭登陆模态框自动清空输入数据
	$('#loginModal').on('hidden.bs.modal', function(e) {
		$("#accountid").val('');
		$("#accountpwd").val('');
	});
青阳龙野's avatar
青阳龙野 已提交
46 47 48 49 50 51 52 53
	// 各个模态框的回车响应功能。该功能仅对“首选”的按钮有效,对其他按钮无效,以避免用户误操作。
	$('.modal').on('shown.bs.modal', function(e) {
		$(this).addClass("shown");
	});
	$('.modal').on('hidden.bs.modal', function(e) {
		$(this).removeClass("shown");
	});
	$("body").keypress(function(e) {
青阳龙野's avatar
青阳龙野 已提交
54
		var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
青阳龙野's avatar
青阳龙野 已提交
55
		if(keyCode == 13) {
青阳龙野's avatar
青阳龙野 已提交
56 57 58 59 60 61 62
			var g=$(".shown .btn-primary");
			if(g.get(0)!=null){
				g.click();
			}else{
				doSearchFile();
			}
			return false;
青阳龙野's avatar
青阳龙野 已提交
63 64
		}
	});
青阳龙野's avatar
青阳龙野 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
	// 开启登陆模态框自动聚焦账户输入框
	$('#loginModal').on('shown.bs.modal', function(e) {
		$("#accountid").focus();
	});
	// 开启新建文件夹框自动初始化状态
	$('#newFolderModal').on('show.bs.modal', function(e) {
		$("#folderalert").removeClass("alert");
		$("#folderalert").removeClass("alert-danger");
		$("#foldernamebox").removeClass("has-error");
		$("#foldername").val("");
		$("#foldertypelist").html("");
		if(account!=null){
			$("#foldername").attr("folderConstraintLevel",constraintLevel+"");
			$("#newfoldertype").text(folderTypes[constraintLevel]);
			for(var i=constraintLevel;i<folderTypes.length;i++){
				$("#foldertypelist").append("<li><a onclick='changeNewFolderType("+i+")'>"+folderTypes[i]+"</a></li>");
			}
		}else{
			$("#foldertypelist").append("<li><a onclick='changeNewFolderType(0)'>"+folderTypes[0]+"</a></li>");
		}
	});
青阳龙野's avatar
青阳龙野 已提交
86 87 88 89
	// 开启新建文件夹模态框自动聚焦文件名输入框
	$('#newFolderModal').on('shown.bs.modal', function(e) {
		$("#foldername").focus();
	});
青阳龙野's avatar
青阳龙野 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
	// 开启编辑文件夹框自动初始化状态
	$('#renameFolderModal').on('show.bs.modal', function(e) {
		$("#newfolderalert").removeClass("alert");
		$("#newfolderalert").removeClass("alert-danger");
		$("#folderrenamebox").removeClass("has-error");
		$("#newfolderalert").text("");
		$("#editfoldertypelist").html("");
		if(account!=null){
			for(var i=constraintLevel;i<folderTypes.length;i++){
				$("#editfoldertypelist").append("<li><a onclick='changeEditFolderType("+i+")'>"+folderTypes[i]+"</a></li>");
			}
		}else{
			$("#editfoldertypelist").append("<li><a onclick='changeEditFolderType(0)'>"+folderTypes[0]+"</a></li>");
		}
	});
青阳龙野's avatar
青阳龙野 已提交
105 106
	// 响应拖动上传文件
	document.ondragover = function(e) {
青阳龙野's avatar
青阳龙野 已提交
107 108 109 110 111 112 113
		if(e.preventDefault){
			e.preventDefault();
			e.stopPropagation();
		}else{
			window.event.cancelBubble=true;
			window.event.returnValue=false;
		}
青阳龙野's avatar
青阳龙野 已提交
114 115
	}
	document.ondrop = function(e) {
青阳龙野's avatar
青阳龙野 已提交
116 117 118 119 120 121 122
		if(e.preventDefault){
			e.preventDefault();
			e.stopPropagation();
		}else{
			window.event.cancelBubble=true;
			window.event.returnValue=false;
		}
青阳龙野's avatar
青阳龙野 已提交
123
		if (folderView.authList != null) {
青阳龙野's avatar
青阳龙野 已提交
124 125 126 127 128 129 130 131
			if (checkAuth(folderView.authList, "U")) {// 如果有上传权限且未进行其他上传
				if(isUpLoading){
					alert("提示:您正在执行另一项上传任务,请在上传窗口关闭后再试。");
				}else{
					if (!(window.ActiveXObject||"ActiveXObject" in window)){// 判断是否为IE
						var dt;
						if(e.dataTransfer != null){
							dt = e.dataTransfer; // 获取到拖入上传的文件对象
青阳龙野's avatar
青阳龙野 已提交
132
						}else{
青阳龙野's avatar
青阳龙野 已提交
133
							dt = window.event.dataTransfer;
青阳龙野's avatar
青阳龙野 已提交
134
						}
青阳龙野's avatar
青阳龙野 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
						var testFile=true;
						if(dt.items!==undefined){
							for(var i=0;i<dt.items.length;i++){
								var item = dt.items[i];
								if(item.kind === "file" && item.webkitGetAsEntry().isFile) {
									
								}else{
									testFile=false;
								}
							}
						}else{
							for(var i = 0; i < dt.files.length; i++){
					            var dropFile = df.files[i];
					            if ( dropFile.type ) {
					               
					            } else {
					                try {
					                    var fileReader = new FileReader();
					                    fileReader.readAsDataURL(dropFile.slice(0, 10));
					                    fileReader.addEventListener('load', function (e) {
					                        
					                    }, false);
					                    fileReader.addEventListener('error', function (e) {
					                    		testFile=false;
					                    }, false);
					                } catch (e) {
					                		testFile=false;
					                }
					            }
					        }
						}
						if(testFile){
							fs = e.dataTransfer.files; // 获取到拖入上传的文件对象
							showfilepath();
							showUploadFileModel();
							checkUploadFile();
						}else{
							alert("提示:您拖入的文件中包含了一个或多个文件夹,无法进行上传。");
						}
					}else{
						alert("提示:IE浏览器不支持拖拽上传。您可以使用现代浏览器或将浏览模式切换为“极速模式”来体验该功能。");
青阳龙野's avatar
青阳龙野 已提交
176 177 178
					}
				}
			}else{
青阳龙野's avatar
青阳龙野 已提交
179
				alert("提示:您不具备上传权限,无法上传文件。");
青阳龙野's avatar
青阳龙野 已提交
180 181
			}
		}else{
青阳龙野's avatar
青阳龙野 已提交
182
			alert("提示:您不具备上传权限,无法上传文件。");
青阳龙野's avatar
青阳龙野 已提交
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
		}
	}
	// Shift+A全选文件/反选文件
	$(document).keypress(function (e) {
		var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
		if (keyCode == 65){
			if (window.event.shiftKey) {
				checkallfile();
			}
		}
	});
	// 关闭移动提示框自动取消移动
	$('#moveFilesModal').on('hidden.bs.modal', function(e) {
		checkedMovefiles=undefined;
		$("#cutSignTx").text("剪切");
青阳龙野's avatar
青阳龙野 已提交
198
		$("#cutSignTx").removeClass("cuted");
青阳龙野's avatar
青阳龙野 已提交
199 200 201
		$('#moveFilesBox').html("");
	});
	// IE内核浏览器内的startsWith方法的自实现
青阳龙野's avatar
青阳龙野 已提交
202 203 204 205 206
	if(typeof String.prototype.startsWith != 'function') {
		String.prototype.startsWith = function(prefix) {
			return this.slice(0, prefix.length) === prefix;
		};
	}
青阳龙野's avatar
青阳龙野 已提交
207 208 209 210 211
	if(typeof String.prototype.endsWith != 'function') {
		String.prototype.endsWith = function(suffix) {
			return this.indexOf(suffix, this.length - suffix.length) !== -1;
		};
	}
青阳龙野's avatar
青阳龙野 已提交
212 213 214 215 216 217 218 219
	// 开启详细信息模态框自动显示信息内容
	$('#folderInfoModal').on('show.bs.modal', function(e) {
		var f=folderView.folder;
		$("#fim_name").text(f.folderName);
		$("#fim_creator").text(f.folderCreator);
		$("#fim_folderCreationDate").text(f.folderCreationDate);
		$("#fim_statistics").text("共包含 "+folderView.folderList.length+" 个文件夹, "+folderView.fileList.length+" 个文件。");
	});
高源 已提交
220 221
});

青阳龙野's avatar
青阳龙野 已提交
222
// 全局请求失败提示
青阳龙野's avatar
青阳龙野 已提交
223
function doAlert(){
青阳龙野's avatar
青阳龙野 已提交
224
	alert("错误:无法连接到kiftd服务器,请检查您的网络连接或查看服务器运行状态。");
青阳龙野's avatar
青阳龙野 已提交
225 226
}

高源 已提交
227 228 229 230 231 232 233 234 235 236
// 获取服务器操作系统
function getServerOS() {
	$.ajax({
		type : "POST",
		dataType : "text",
		data : {

		},
		url : "homeController/getServerOS.ajax",
		success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
237
			if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
238
				window.location.href = "login.html";
青阳龙野's avatar
青阳龙野 已提交
239
			}
高源 已提交
240 241 242 243 244 245 246 247 248 249
			$("#serverOS").text(result);
		},
		error : function() {
			$("#serverOS").html("<a onclick='getServerOS()'>获取失败,点击重试</a>");
		}
	});
}

// 获取实时文件夹视图
function showFolderView(fid) {
青阳龙野's avatar
青阳龙野 已提交
250
	startLoading();
高源 已提交
251 252 253 254 255 256 257 258
	$.ajax({
		type : 'POST',
		dataType : 'text',
		data : {
			fid : fid
		},
		url : 'homeController/getFolderView.ajax',
		success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
259
			endLoading();
青阳龙野's avatar
青阳龙野 已提交
260
			if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
261
				window.location.href = "login.html";
青阳龙野's avatar
青阳龙野 已提交
262 263
			}else if(result == "notAccess"){
				window.location.href="/";
青阳龙野's avatar
青阳龙野 已提交
264
			} else {
青阳龙野's avatar
青阳龙野 已提交
265
				folderView = eval("(" + result + ")");
青阳龙野's avatar
青阳龙野 已提交
266 267
				locationpath = folderView.folder.folderId;
				parentpath = folderView.folder.folderParent;
青阳龙野's avatar
青阳龙野 已提交
268
				constraintLevel=folderView.folder.folderConstraint;
青阳龙野's avatar
青阳龙野 已提交
269 270
				screenedFoldrView=null;
				$("#sreachKeyWordIn").val("");
青阳龙野's avatar
青阳龙野 已提交
271 272 273
				showParentList(folderView);
				showAccountView(folderView);
				showPublishTime(folderView);
青阳龙野's avatar
青阳龙野 已提交
274 275 276 277 278
				originFolderView=$.extend(true, {}, folderView);
				$("#sortByFN").removeClass();
				$("#sortByCD").removeClass();
				$("#sortByFS").removeClass();
				$("#sortByCN").removeClass();
青阳龙野's avatar
青阳龙野 已提交
279 280
				showFolderTable(folderView);
			}
高源 已提交
281 282
		},
		error : function() {
青阳龙野's avatar
青阳龙野 已提交
283 284
			endLoading();
			doAlert();
高源 已提交
285 286 287 288 289 290 291 292
			$("#tb").html("<span class='graytext'>获取失败,请尝试刷新</span>");
			$("#publishTime").html("<span class='graytext'>获取失败,请尝试刷新</span>");
			$("#parentlistbox")
					.html("<span class='graytext'>获取失败,请尝试刷新</span>");
		}
	});
}

青阳龙野's avatar
青阳龙野 已提交
293
// 开始文件视图加载动画
青阳龙野's avatar
青阳龙野 已提交
294
function startLoading(){
青阳龙野's avatar
青阳龙野 已提交
295
	$('#loadingModal').modal({backdrop:'static', keyboard: false}); 
青阳龙野's avatar
青阳龙野 已提交
296 297 298
	$('#loadingModal').modal('show');
}

青阳龙野's avatar
青阳龙野 已提交
299
// 结束文件视图加载动画
青阳龙野's avatar
青阳龙野 已提交
300 301 302 303
function endLoading(){
	$('#loadingModal').modal('hide');
}

青阳龙野's avatar
青阳龙野 已提交
304
// 开始登陆加载动画
青阳龙野's avatar
青阳龙野 已提交
305 306 307 308 309 310
function startLogin(){
	$("#accountid").attr('disabled','disabled');
	$("#accountpwd").attr('disabled','disabled');
	$("#dologinButton").attr('disabled','disabled');
}

青阳龙野's avatar
青阳龙野 已提交
311
// 结束登陆加载动画
青阳龙野's avatar
青阳龙野 已提交
312 313 314 315 316 317
function finishLogin(){
	$("#accountid").removeAttr('disabled','disabled');
	$("#accountpwd").removeAttr('disabled','disabled');
	$("#dologinButton").removeAttr('disabled','disabled');
}

高源 已提交
318 319
// 登录操作
function dologin() {
青阳龙野's avatar
青阳龙野 已提交
320 321
	var accountId = $("#accountid").val();
	var accountPwd = $("#accountpwd").val();
高源 已提交
322
	var check = "y";
青阳龙野's avatar
青阳龙野 已提交
323
	if (accountId.length == 0) {
高源 已提交
324
		$("#accountidbox").addClass("has-error");
青阳龙野's avatar
青阳龙野 已提交
325
		check = "n";
高源 已提交
326 327 328
	} else {
		$("#accountidbox").removeClass("has-error");
	}
青阳龙野's avatar
青阳龙野 已提交
329
	if (accountPwd.length == 0) {
高源 已提交
330
		$("#accountpwdbox").addClass("has-error");
青阳龙野's avatar
青阳龙野 已提交
331
		check = "n";
高源 已提交
332 333 334 335
	} else {
		$("#accountpwdbox").removeClass("has-error");
	}
	if (check == "y") {
青阳龙野's avatar
青阳龙野 已提交
336
		startLogin();
青阳龙野's avatar
青阳龙野 已提交
337
		// 加密认证-获取公钥并将请求加密发送给服务器,避免中途被窃取
高源 已提交
338
		$.ajax({
青阳龙野's avatar
青阳龙野 已提交
339 340 341 342
			url : 'homeController/getPublicKey.ajax',
			type : 'POST',
			data : {},
			dataType : 'text',
高源 已提交
343
			success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
344 345 346 347 348 349 350 351
				var publicKeyInfo=eval("("+result+")");
				var date = new Date();// 这个是客户浏览器上的当前时间
				var loginInfo = '{accountId:"' + accountId + '",accountPwd:"'
						+ accountPwd + '",time:"' + publicKeyInfo.time + '"}';
				var encrypt = new JSEncrypt();// 加密插件对象
				encrypt.setPublicKey(publicKeyInfo.publicKey);// 设置公钥
				var encrypted = encrypt.encrypt(loginInfo);// 进行加密
				sendLoginInfo(encrypted);
高源 已提交
352 353
			},
			error : function() {
青阳龙野's avatar
青阳龙野 已提交
354
				finishLogin();
高源 已提交
355 356 357 358 359 360 361 362
				$("#alertbox").addClass("alert");
				$("#alertbox").addClass("alert-danger");
				$("#alertbox").text("提示:登录请求失败,请检查网络或服务器运行状态");
			}
		});
	}
}

青阳龙野's avatar
青阳龙野 已提交
363 364 365 366 367 368 369 370 371 372
// 发送加密文本
function sendLoginInfo(encrypted) {
	$.ajax({
		type : "POST",
		dataType : "text",
		url : "homeController/doLogin.ajax",
		data : {
			encrypted : encrypted
		},
		success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
373
			finishLogin();
青阳龙野's avatar
青阳龙野 已提交
374 375 376 377 378 379 380
			$("#alertbox").removeClass("alert");
			$("#alertbox").removeClass("alert-danger");
			$("#alertbox").text("");
			switch (result) {
			case "permitlogin":
				$("#accountidbox").removeClass("has-error");
				$("#accountpwdbox").removeClass("has-error");
青阳龙野's avatar
青阳龙野 已提交
381 382
				$('#loginModal').modal('hide');
				showFolderView(locationpath);
青阳龙野's avatar
青阳龙野 已提交
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
				break;
			case "accountnotfound":
				$("#accountidbox").addClass("has-error");
				$("#accountpwdbox").removeClass("has-error");
				$("#alertbox").addClass("alert");
				$("#alertbox").addClass("alert-danger");
				$("#alertbox").text("提示:登录失败,账户不存在或未设置");
				break;
			case "accountpwderror":
				$("#accountpwdbox").addClass("has-error");
				$("#accountidbox").removeClass("has-error");
				$("#alertbox").addClass("alert");
				$("#alertbox").addClass("alert-danger");
				$("#alertbox").text("提示:登录失败,密码错误或未设置");
				break;
			case "error":
				$("#alertbox").addClass("alert");
				$("#alertbox").addClass("alert-danger");
				$("#alertbox").text("提示:登录失败,登录请求无法通过效验(可能是请求耗时过长导致的)");
				break;
			default:
				$("#alertbox").addClass("alert");
				$("#alertbox").addClass("alert-danger");
				$("#alertbox").text("提示:无法登录,未知错误");
				break;
			}
		},
		error : function() {
青阳龙野's avatar
青阳龙野 已提交
411
			finishLogin();
青阳龙野's avatar
青阳龙野 已提交
412 413 414 415 416 417 418
			$("#alertbox").addClass("alert");
			$("#alertbox").addClass("alert-danger");
			$("#alertbox").text("提示:登录请求失败,请检查网络或服务器运行状态");
		}
	});
}

高源 已提交
419 420 421
// 注销操作
function dologout() {
	$('#logoutModal').modal('hide');
青阳龙野's avatar
青阳龙野 已提交
422 423 424 425 426 427 428 429 430 431 432 433 434 435
	$.ajax({
		url:'homeController/doLogout.ajax',
		type:'POST',
		data:{},
		dataType:'text',
		success:function(result){
			if(result=="SUCCESS"){
				showFolderView(locationpath);
			}
		},
		error:function(){
			doAlert();
		}
	});
高源 已提交
436 437 438 439
}

// 显示当前文件夹的父级路径
function showParentList(folderView) {
青阳龙野's avatar
青阳龙野 已提交
440
	$("#parentFolderList").html("");
高源 已提交
441
	var f = folderView.folder;
青阳龙野's avatar
青阳龙野 已提交
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
	if(folderView.parentList.length>0){
		$.each(folderView.parentList, function(n, val) {
			$("#parentFolderList").append("<li><a href='javascript:void(0);' onclick='entryFolder("+'"' + val.folderId +'"'+")'>"+val.folderName+"</a></li>");
		});
	}else{
		$("#parentFolderList").html("<li class='disabled'><a>无</a></li>");
	}
	if(f.folderName.length>6){
		$("#currentFolderName").text(f.folderName.substr(0,6)+"...");
	}else{
		$("#currentFolderName").text(f.folderName);
	}
	if(f.folderName=="ROOT"){
		$("#folderIconSpan").removeClass("glyphicon-folder-close");
		$("#folderIconSpan").addClass("glyphicon-home");
	}else{
		$("#folderIconSpan").removeClass("glyphicon-home");
		$("#folderIconSpan").addClass("glyphicon-folder-close");
高源 已提交
460 461 462 463 464 465
	}
}

// 显示用户视图,包括文件列表、登录信息、操作权限接口等
function showAccountView(folderView) {
	$("#tb").html("");
青阳龙野's avatar
青阳龙野 已提交
466
	account=folderView.account;
高源 已提交
467 468 469 470 471 472 473 474 475 476 477 478 479 480
	if (folderView.account != null) {
		// 说明已经等陆,显示注销按钮
		$("#tb")
				.append(
						"<button class='btn btn-link rightbtn' data-toggle='modal' data-target='#logoutModal'>注销 ["
								+ folderView.account
								+ "] <span class='glyphicon glyphicon-off' aria-hidden='true'></span></button>");
	} else {
		// 说明用户未登录,显示登录按钮
		$("#tb")
				.append(
						"<button class='btn btn-link rightbtn' data-toggle='modal' data-target='#loginModal'>登入<span class='glyphicon glyphicon-user' aria-hidden='true'></span></button>");
	}
	var authList = folderView.authList;
青阳龙野's avatar
青阳龙野 已提交
481 482 483 484
	// 对操作菜单进行初始化,根据权限显示可操作的按钮(并非约束)。
	$("#fileListDropDown li").addClass("disabled");
	$("#fileListDropDown li a").attr("onclick","");
	$("#fileListDropDown li a").attr("href","javascript:void(0);");
高源 已提交
485 486
	if (authList != null) {
		if (checkAuth(authList, "C")) {
青阳龙野's avatar
青阳龙野 已提交
487 488
			$("#createFolderButtonLi").removeClass("disabled");
			$("#createFolderButtonLi a").attr("onclick","showNewFolderModel()");
高源 已提交
489 490
		}
		if (checkAuth(authList, "U")) {
青阳龙野's avatar
青阳龙野 已提交
491 492
			$("#uploadFileButtonLi").removeClass("disabled");
			$("#uploadFileButtonLi a").attr("onclick","showUploadFileModel()");
高源 已提交
493
		}
青阳龙野's avatar
青阳龙野 已提交
494
		if (checkAuth(authList, "L")) {
青阳龙野's avatar
青阳龙野 已提交
495 496 497 498 499
			$("#packageDownloadBox")
					.html(
							"<button class='btn btn-link navbar-btn' onclick='showDownloadAllCheckedModel()'><span class='glyphicon glyphicon-briefcase'></span> 打包下载</button>");
		}else{
			$("#packageDownloadBox").html("");
青阳龙野's avatar
青阳龙野 已提交
500 501
		}
		if (checkAuth(authList, "D")) {
青阳龙野's avatar
青阳龙野 已提交
502 503
			$("#deleteSeelectFileButtonLi").removeClass("disabled");
			$("#deleteSeelectFileButtonLi a").attr("onclick","showDeleteAllCheckedModel()");
青阳龙野's avatar
青阳龙野 已提交
504
		}
青阳龙野's avatar
青阳龙野 已提交
505
		if (checkAuth(authList, "M")) {
青阳龙野's avatar
青阳龙野 已提交
506 507
			$("#cutFileButtonLi").removeClass("disabled");
			$("#cutFileButtonLi a").attr("onclick","startMoveFile()");
青阳龙野's avatar
青阳龙野 已提交
508 509
			if(checkedMovefiles!==undefined&&checkedMovefiles.length>0){
				$("#cutSignTx").text("粘贴("+checkedMovefiles.length+"");
青阳龙野's avatar
青阳龙野 已提交
510
				$("#cutSignTx").addClass("cuted");
青阳龙野's avatar
青阳龙野 已提交
511 512
			}
		}
高源 已提交
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
	}
}

// 检查权限列表
function checkAuth(authList, auth) {
	var k = false;
	$.each(authList, function(n, a) {
		if (a == auth) {
			k = true;
		}
	});
	return k;
}

// 显示视图更新时间
function showPublishTime(folderView) {
	$("#publishTime").html("");
	var pt = "";
	if (folderView.publishTime != null) {
		pt = folderView.publishTime;
	} else {
		pt = "--";
	}
	$("#publishTime").text(pt);
}

// 刷新文件夹视图
function refreshFolderView() {
	if (locationpath != null && locationpath.length > 0) {
		showFolderView(locationpath);
	} else {
		showFolderView('root');
	}
}

// 返回上一级文件夹
function returnPF() {
	if (parentpath != null && parentpath != "null") {
		showFolderView(parentpath);
	} else {
		showFolderView('root');
	}
}

// 显示文件夹内容
function showFolderTable(folderView) {
	$("#foldertable").html("");
	if (parentpath != null && parentpath != "null") {
		$("#foldertable")
				.append(
青阳龙野's avatar
青阳龙野 已提交
563
						"<tr onclick='returnPF()'><td><button onclick='returnPF()' class='btn btn-link btn-xs'>../</button></td><td>--</td><td>--</td><td>--</td><td>--</td></tr>");
高源 已提交
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
	}
	var authList = folderView.authList;
	var aD = false;
	var aR = false;
	var aL = false;
	if (checkAuth(authList, "D")) {
		aD = true;
	}
	if (checkAuth(authList, "R")) {
		aR = true;
	}
	if (checkAuth(authList, "L")) {
		aL = true;
	}
	$
			.each(
					folderView.folderList,
					function(n, f) {
						var folderRow = "<tr><td><button onclick='entryFolder("
								+ '"' + f.folderId + '"'
								+ ")' class='btn btn-link btn-xs'>/"
								+ f.folderName + "</button></td><td>"
								+ f.folderCreationDate + "</td><td>--</td><td>"
								+ f.folderCreator + "</td><td>";
						if (aD) {
							folderRow = folderRow
									+ "<button onclick='showDeleteFolderModel("
									+ '"'
									+ f.folderId
									+ '","'
									+ f.folderName
									+ '"'
									+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-remove'></span> 删除</button>";
						}
						if (aR) {
							folderRow = folderRow
									+ "<button onclick='showRenameFolderModel("
									+ '"'
									+ f.folderId
									+ '","'
									+ f.folderName
青阳龙野's avatar
青阳龙野 已提交
605 606 607
									+ '",'
									+ f.folderConstraint
									+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-wrench'></span> 编辑</button>";
高源 已提交
608 609 610 611 612 613 614 615 616 617 618
						}
						if (!aR && !aD) {
							folderRow = folderRow + "--";
						}
						folderRow = folderRow + "</td></tr>";
						$("#foldertable").append(folderRow);
					});
	$
			.each(
					folderView.fileList,
					function(n, fi) {
青阳龙野's avatar
青阳龙野 已提交
619 620 621 622 623 624
						var fileRow = "<tr onclick='checkfile(" + '"'
								+ fi.fileId + '"' + ")' id='" + fi.fileId
								+ "' class='filerow'><td>" + fi.fileName
								+ "</td><td>" + fi.fileCreationDate
								+ "</td><td>" + fi.fileSize + "MB</td><td>"
								+ fi.fileCreator + "</td><td>";
高源 已提交
625 626 627 628 629 630 631 632 633
						if (aL) {
							fileRow = fileRow
									+ "<button onclick='showDownloadModel("
									+ '"'
									+ fi.fileId
									+ '","'
									+ fi.fileName
									+ '"'
									+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-cloud-download'></span> 下载</button>";
634 635 636
							// 对于各种特殊格式文件提供的预览和播放功能
							if (getSuffix(fi.fileName) == "mp4"
									|| getSuffix(fi.fileName) == "webm") {
637 638 639 640 641 642
								fileRow = fileRow
										+ "<button onclick='playVideo("
										+ '"'
										+ fi.fileId
										+ '"'
										+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-play'></span> 播放</button>";
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
							} else if (getSuffix(fi.fileName) == "pdf") {
								fileRow = fileRow
										+ "<button onclick='pdfView("
										+ '"'
										+ fi.fileId
										+ '"'
										+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-eye-open'></span> 预览</button>";
							} else if (getSuffix(fi.fileName) == "jpg"
									|| getSuffix(fi.fileName) == "jpeg"
									|| getSuffix(fi.fileName) == "gif"
									|| getSuffix(fi.fileName) == "png"
									|| getSuffix(fi.fileName) == "bmp") {
								fileRow = fileRow
										+ "<button onclick='showPicture("
										+ '"'
										+ fi.fileId
										+ '"'
										+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-picture'></span> 查看</button>";
青阳龙野's avatar
青阳龙野 已提交
661 662 663 664 665 666 667 668 669
							} else if (getSuffix(fi.fileName) == "mp3"
									|| getSuffix(fi.fileName) == "wav"
									|| getSuffix(fi.fileName) == "ogg") {
								fileRow = fileRow
										+ "<button onclick='playAudio("
										+ '"'
										+ fi.fileId
										+ '"'
										+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-play'></span> 播放</button>";
670
							}
高源 已提交
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
						}
						if (aD) {
							fileRow = fileRow
									+ "<button onclick='showDeleteFileModel("
									+ '"'
									+ fi.fileId
									+ '","'
									+ fi.fileName
									+ '"'
									+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-remove'></span> 删除</button>";
						}
						if (aR) {
							fileRow = fileRow
									+ "<button onclick='showRenameFileModel("
									+ '"'
									+ fi.fileId
									+ '"'
									+ ","
									+ '"'
									+ fi.fileName
									+ '"'
									+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-wrench'></span> 重命名</button>";
						}
						if (!aR && !aD && !aL) {
							fileRow = fileRow + "--";
						}
						fileRow = fileRow + "</td></tr>";
						$("#foldertable").append(fileRow);
					});
}

青阳龙野's avatar
青阳龙野 已提交
702 703
var folderTypes=['公开的','仅小组','仅创建者'];// 文件夹约束条件(由小至大)

高源 已提交
704 705
// 显示新建文件夹模态框
function showNewFolderModel() {
青阳龙野's avatar
青阳龙野 已提交
706 707 708 709 710 711 712
	$('#newFolderModal').modal('show');
}

// 修改新建文件夹约束等级
function changeNewFolderType(type){
	$("#newfoldertype").text(folderTypes[type]);
	$("#foldername").attr("folderConstraintLevel",type+"");
高源 已提交
713 714 715 716 717
}

// 创建新的文件夹
function createfolder() {
	var fn = $("#foldername").val();
青阳龙野's avatar
青阳龙野 已提交
718
	var fc=$("#foldername").attr("folderConstraintLevel");
高源 已提交
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
	var reg = new RegExp("^[0-9a-zA-Z_\\u4E00-\\u9FFF]+$", "g");
	if (fn.length == 0) {
		showFolderAlert("提示:文件夹名称不能为空。");
	} else if (fn.length > 20) {
		showFolderAlert("提示:文件夹名称太长。");
	} else if (reg.test(fn)) {
		$("#folderalert").removeClass("alert");
		$("#folderalert").removeClass("alert-danger");
		$("#foldernamebox").removeClass("has-error");
		$("#folderalert").text("");
		$.ajax({
			type : "POST",
			dataType : "text",
			data : {
				parentId : locationpath,
青阳龙野's avatar
青阳龙野 已提交
734 735
				folderName : fn,
				folderConstraint : fc
高源 已提交
736 737 738
			},
			url : "homeController/newFolder.ajax",
			success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
739
				if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
740
					window.location.href = "login.html";
高源 已提交
741
				} else {
青阳龙野's avatar
青阳龙野 已提交
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
					if (result == "noAuthorized") {
						showFolderAlert("提示:您的操作未被授权,创建文件夹失败");
					} else if (result == "errorParameter") {
						showFolderAlert("提示:参数不正确,创建文件夹失败");
					} else if (result == "cannotCreateFolder") {
						showFolderAlert("提示:出现意外错误,可能未能创建文件夹");
					} else if (result == "folderAlreadyExist") {
						showFolderAlert("提示:该文件夹已经存在,请更换文件夹名称");
					} else if (result == "createFolderSuccess") {
						$('#newFolderModal').modal('hide');
						showFolderView(locationpath);
					} else {
						$('#newFolderModal').modal('hide');
						showFolderView(locationpath);
					}
高源 已提交
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
				}
			},
			error : function() {
				showFolderAlert("提示:出现意外错误,可能未能创建文件夹");
			}
		});
	} else {
		showFolderAlert("提示:文件夹名只能包含英文字母、数组、汉字和下划线。");
	}
}

// 显示新建文件夹状态提示
function showFolderAlert(txt) {
	$("#folderalert").addClass("alert");
	$("#folderalert").addClass("alert-danger");
	$("#foldernamebox").addClass("has-error");
	$("#folderalert").text(txt);
}

// 进入某一文件夹
function entryFolder(folderId) {
	showFolderView(folderId);
}

// 显示删除文件夹模态框
function showDeleteFolderModel(folderId, folderName) {
	$('#deleteFolderBox')
			.html(
					"<button id='dmbutton' type='button' class='btn btn-danger' onclick='deleteFolder("
							+ '"' + folderId + '"' + ")'>删除</button>");
	$("#dmbutton").attr('disabled', false);
	$('#deleteFolderMessage').text(
			"提示:确定要彻底删除文件夹:[" + folderName + "]及其全部内容么?该操作不可恢复");
	$('#deleteFolderModal').modal('toggle');
}

// 执行删除文件夹
function deleteFolder(folderId) {
	$("#dmbutton").attr('disabled', true);
	$('#deleteFolderMessage').text("提示:正在删除,请稍候...");
	$.ajax({
		type : "POST",
		dataType : "text",
		data : {
			folderId : folderId
		},
		url : "homeController/deleteFolder.ajax",
		success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
805
			if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
806
				window.location.href = "login.html";
高源 已提交
807
			} else {
青阳龙野's avatar
青阳龙野 已提交
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823
				if (result == "noAuthorized") {
					$('#deleteFolderMessage').text("提示:您的操作未被授权,删除文件夹失败");
					$("#dmbutton").attr('disabled', false);
				} else if (result == "errorParameter") {
					$('#deleteFolderMessage').text("提示:参数不正确,删除文件夹失败");
					$("#dmbutton").attr('disabled', false);
				} else if (result == "cannotDeleteFolder") {
					$('#deleteFolderMessage').text("提示:出现意外错误,可能未能删除文件夹");
					$("#dmbutton").attr('disabled', false);
				} else if (result == "deleteFolderSuccess") {
					$('#deleteFolderModal').modal('hide');
					showFolderView(locationpath);
				} else {
					$('#deleteFolderMessage').text("提示:出现意外错误,可能未能删除文件夹");
					$("#dmbutton").attr('disabled', false);
				}
高源 已提交
824 825 826 827 828 829 830 831 832 833
			}
		},
		error : function() {
			$('#deleteFolderMessage').text("提示:出现意外错误,可能未能删除文件夹");
			$("#dmbutton").attr('disabled', false);
		}
	});
}

// 显示重命名文件夹模态框
青阳龙野's avatar
青阳龙野 已提交
834
function showRenameFolderModel(folderId, folderName, type) {
高源 已提交
835 836 837 838
	$("#renameFolderBox").html(
			"<button type='button' class='btn btn-primary' onclick='renameFolder("
					+ '"' + folderId + '"' + ")'>修改</button>");
	$("#newfoldername").val(folderName);
青阳龙野's avatar
青阳龙野 已提交
839 840 841 842
	changeEditFolderType(type);
	$("#renameFolderModal").modal('show');
}

青阳龙野's avatar
青阳龙野 已提交
843
// 修改编辑文件夹的约束等级
青阳龙野's avatar
青阳龙野 已提交
844 845 846
function changeEditFolderType(type){
	$("#editfoldertype").text(folderTypes[type]);
	$("#newfoldername").attr("folderConstraintLevel",type+"");
高源 已提交
847 848
}

青阳龙野's avatar
青阳龙野 已提交
849
// 执行重命名文件夹
高源 已提交
850 851
function renameFolder(folderId) {
	var newName = $("#newfoldername").val();
青阳龙野's avatar
青阳龙野 已提交
852
	var fc=$("#newfoldername").attr("folderConstraintLevel");
高源 已提交
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
	var reg = new RegExp("^[0-9a-zA-Z_\\u4E00-\\u9FFF]+$", "g");
	if (newName.length == 0) {
		showRenameFolderAlert("提示:文件夹名称不能为空。");
	} else if (newName.length > 20) {
		showRenameFolderAlert("提示:文件夹名称太长。");
	} else if (reg.test(newName)) {
		$("#newfolderalert").removeClass("alert");
		$("#newfolderalert").removeClass("alert-danger");
		$("#folderrenamebox").removeClass("has-error");
		$("#newfolderalert").text("");
		$.ajax({
			type : "POST",
			dataType : "text",
			data : {
				folderId : folderId,
青阳龙野's avatar
青阳龙野 已提交
868 869
				newName : newName,
				folderConstraint : fc
高源 已提交
870 871 872
			},
			url : "homeController/renameFolder.ajax",
			success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
873
				if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
874
					window.location.href = "login.html";
高源 已提交
875
				} else {
青阳龙野's avatar
青阳龙野 已提交
876
					if (result == "noAuthorized") {
青阳龙野's avatar
青阳龙野 已提交
877
						showRenameFolderAlert("提示:您的操作未被授权,编辑失败");
青阳龙野's avatar
青阳龙野 已提交
878
					} else if (result == "errorParameter") {
青阳龙野's avatar
青阳龙野 已提交
879
						showRenameFolderAlert("提示:参数不正确,编辑失败");
青阳龙野's avatar
青阳龙野 已提交
880 881 882 883
					} else if (result == "renameFolderSuccess") {
						$('#renameFolderModal').modal('hide');
						showFolderView(locationpath);
					} else {
青阳龙野's avatar
青阳龙野 已提交
884
						showRenameFolderAlert("提示:出现意外错误,可能未能编辑文件夹");
青阳龙野's avatar
青阳龙野 已提交
885
					}
高源 已提交
886 887 888
				}
			},
			error : function() {
青阳龙野's avatar
青阳龙野 已提交
889
				showRenameFolderAlert("提示:出现意外错误,可能未能编辑文件夹");
高源 已提交
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
			}
		});
	} else {
		showRenameFolderAlert("提示:文件夹名只能包含英文字母、数组、汉字和下划线");
	}
}

// 显示重命名文件夹状态提示
function showRenameFolderAlert(txt) {
	$("#newfolderalert").addClass("alert");
	$("#newfolderalert").addClass("alert-danger");
	$("#folderrenamebox").addClass("has-error");
	$("#newfolderalert").text(txt);
}

// 显示上传文件模态框
function showUploadFileModel() {
	$("#uploadFileAlert").removeClass("alert");
	$("#uploadFileAlert").removeClass("alert-danger");
	$("#uploadFileAlert").text("");
青阳龙野's avatar
青阳龙野 已提交
910 911 912 913 914 915 916 917 918 919
	if(isUpLoading==false){
		$("#uploadfile").val("");
		$("#filepath").val("");
		$("#pros").width("0%");
		$("#umbutton").attr('disabled', false);
		$("#filecount").text("");
		$("#uploadstatus").text("");
		$("#selectcount").text("");
	}
	$('#uploadFileModal').modal('show');
高源 已提交
920 921 922 923 924 925 926
}

// 点击文本框触发input:file选择文件动作
function checkpath() {
	$('#uploadfile').click();
}

青阳龙野's avatar
青阳龙野 已提交
927 928 929 930 931 932
// 获取选中文件
function getInputUpload(){
	fs = $("#uploadfile").get(0).files;
	showfilepath();
}

高源 已提交
933 934
// 文件选中后自动回填文件路径
function showfilepath() {
青阳龙野's avatar
青阳龙野 已提交
935 936 937 938 939 940 941 942 943 944 945 946 947
	var filename = "";
	for (var i = 0; i < fs.length; i++) {
		filename = filename + fs[i].name;
		if (i < (fs.length - 1)) {
			filename = filename + "";
		}
	}
	if (fs.length <= 1) {
		$("#selectcount").text("");
	} else {
		$("#selectcount").text("(共" + fs.length + "个)");
	}
	$("#filepath").val(filename);
高源 已提交
948 949 950 951
}

// 检查是否能够上传
function checkUploadFile() {
青阳龙野's avatar
青阳龙野 已提交
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991
	if(isUpLoading==false){
		if(fs!=null&&fs.length>0){
			isUpLoading=true;
			$("#umbutton").attr('disabled', true);
			$("#uploadFileAlert").removeClass("alert");
			$("#uploadFileAlert").removeClass("alert-danger");
			$("#uploadFileAlert").text("");
			var filenames = new Array();
			for (var i = 0; i < fs.length; i++) {
				filenames[i] = fs[i].name.replace(/^.+?\\([^\\]+?)?$/gi, "$1");
			}
			var namelist = JSON.stringify(filenames);
			
			$.ajax({
				type : "POST",
				dataType : "text",
				data : {
					folderId : locationpath,
					namelist : namelist
				},
				url : "homeController/checkUploadFile.ajax",
				success : function(result) {
					if (result == "mustLogin") {
						window.location.href = "login.html";
					} else {
						if (result == "errorParameter") {
							showUploadFileAlert("提示:参数不正确,无法开始上传");
						} else if (result == "noAuthorized") {
							showUploadFileAlert("提示:您的操作未被授权,无法开始上传");
						} else if (result.startsWith("duplicationFileName:")) {
							showUploadFileAlert("提示:本路径下已存在同名的文件:["
									+ result.substring(20) + "],无法开始上传");
						} else if (result == "permitUpload") {
							doupload(1);
						} else {
							showUploadFileAlert("提示:出现意外错误,无法开始上传");
						}
					}
				},
				error : function() {
青阳龙野's avatar
青阳龙野 已提交
992 993
					showUploadFileAlert("提示:出现意外错误,无法开始上传");
				}
青阳龙野's avatar
青阳龙野 已提交
994 995 996
			});
		}else{
			showUploadFileAlert("提示:您未选择任何文件,无法开始上传");
高源 已提交
997
		}
青阳龙野's avatar
青阳龙野 已提交
998
	}
高源 已提交
999 1000 1001 1002 1003
}

var xhr;

// 执行文件上传并实现上传进度显示
青阳龙野's avatar
青阳龙野 已提交
1004 1005
function doupload(count) {
	var fcount = fs.length;
高源 已提交
1006
	$("#pros").width("0%");// 先将进度条置0
青阳龙野's avatar
青阳龙野 已提交
1007
	var uploadfile = fs[count - 1];// 获取要上传的文件
高源 已提交
1008
	if (uploadfile != null) {
青阳龙野's avatar
青阳龙野 已提交
1009 1010 1011 1012 1013 1014 1015
		var fname = uploadfile.name;
		if (fcount > 1) {
			$("#filecount").text("" + count + "/" + fcount + "");// 显示当前进度
		}
		$("#uploadstatus").prepend(
				"<p>" + fname + "<span id='uls_" + count
						+ "'>[正在上传...]</span></p>");
高源 已提交
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
		xhr = new XMLHttpRequest();// 这东西类似于servlet里面的request

		var fd = new FormData();// 用于封装文件数据的对象

		fd.append("file", uploadfile);// 将文件对象添加到FormData对象中,字段名为uploadfile
		fd.append("folderId", locationpath);

		xhr.open("POST", "homeController/douploadFile.ajax", true);// 上传目标

		xhr.upload.addEventListener("progress", uploadProgress, false);// 这个是对上传进度的监听
		// 上面的三个参数分别是:事件名(指定名称)、回调函数、是否冒泡(一般是false即可)

		xhr.send(fd);// 上传FormData对象

		// 上传结束后执行的回调函数
		xhr.onloadend = function() {
			if (xhr.status === 200) {
				// TODO 上传成功
				var result = xhr.responseText;
				if (result == "uploadsuccess") {
青阳龙野's avatar
青阳龙野 已提交
1036 1037 1038 1039 1040
					$("#uls_" + count).text("[已完成]");
					if (count < fcount) {
						doupload(count + 1);
					} else {
						// 清空所有提示信息,还原上传窗口
青阳龙野's avatar
青阳龙野 已提交
1041
						isUpLoading=false;
青阳龙野's avatar
青阳龙野 已提交
1042 1043 1044 1045 1046 1047 1048
						$("#uploadfile").val("");
						$("#filepath").val("");
						$("#pros").width("0%");
						$("#umbutton").attr('disabled', false);
						$("#filecount").text("");
						$("#uploadstatus").text("");
						$("#selectcount").text("");
青阳龙野's avatar
青阳龙野 已提交
1049 1050
						$('#uploadFileModal').modal('hide');
						showFolderView(locationpath);
青阳龙野's avatar
青阳龙野 已提交
1051
					}
高源 已提交
1052
				} else if (result == "uploaderror") {
青阳龙野's avatar
青阳龙野 已提交
1053 1054 1055
					showUploadFileAlert("提示:出现意外错误,文件:[" + fname
							+ "]上传失败,上传被中断。");
					$("#uls_" + count).text("[失败]");
高源 已提交
1056
				} else {
青阳龙野's avatar
青阳龙野 已提交
1057 1058
					showUploadFileAlert("提示:出现意外错误,文件:[" + fname
							+ "]上传失败,上传被中断。");
青阳龙野's avatar
青阳龙野 已提交
1059
					$("#uls_" + count).text("[失败]");
高源 已提交
1060 1061
				}
			} else {
青阳龙野's avatar
青阳龙野 已提交
1062 1063
				showUploadFileAlert("提示:出现意外错误,文件:[" + fname + "]上传失败,上传被中断。");
				$("#uls_" + count).text("[失败]");
高源 已提交
1064 1065 1066
			}
		};
	} else {
青阳龙野's avatar
青阳龙野 已提交
1067 1068 1069
		showUploadFileAlert("提示:要上传的文件不存在。");
		$("#uploadstatus").prepend(
				"<p>未找到要上传的文件<span id='uls_" + count + "'>[失败]</span></p>");
高源 已提交
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
	}
}

function uploadProgress(evt) {
	if (evt.lengthComputable) {
		// evt.loaded:文件上传的大小 evt.total:文件总的大小
		var percentComplete = Math.round((evt.loaded) * 100 / evt.total);
		// 加载进度条,同时显示信息
		$("#pros").width(percentComplete + "%");
	}
}

// 显示上传文件状态提示
function showUploadFileAlert(txt) {
青阳龙野's avatar
青阳龙野 已提交
1084
	isUpLoading=false;
高源 已提交
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
	$("#uploadFileAlert").addClass("alert");
	$("#uploadFileAlert").addClass("alert-danger");
	$("#uploadFileAlert").text(txt);
	$("#umbutton").attr('disabled', false);
}

// 显示下载文件模态框
function showDownloadModel(fileId, fileName) {
	$("#downloadModal").modal('toggle');
	$("#downloadFileName").text("提示:您确认要下载文件:[" + fileName + "]么?");
	$("#downloadFileBox")
			.html(
					"<button id='dlmbutton' type='button' class='btn btn-primary' onclick='dodownload("
							+ '"' + fileId + '"' + ")'>开始下载</button>");
	$("#dlmbutton").attr('disabled', false);
}

// 执行下载操作
function dodownload(fileId) {
	$("#dlmbutton").attr('disabled', true);
	$("#downloadFileName").text("提示:准备开始下载,请稍候...");
	var t = setTimeout("$('#downloadModal').modal('hide');", 800);
	window.location.href = "homeController/downloadFile.do?fileId=" + fileId;
}

// 显示删除文件模态框
function showDeleteFileModel(fileId, fileName) {
	$('#deleteFileBox')
			.html(
					"<button id='dfmbutton' type='button' class='btn btn-danger' onclick='deleteFile("
							+ '"' + fileId + '"' + ")'>删除</button>");
	$("#dfmbutton").attr('disabled', false);
	$('#deleteFileMessage').text("提示:确定要彻底删除文件:[" + fileName + "]么?该操作不可恢复");
	$('#deleteFileModal').modal('toggle');
}

// 执行删除文件操作
function deleteFile(fileId) {
	$("#dfmbutton").attr('disabled', true);
	$('#deleteFileMessage').text("提示:正在删除,请稍候...");
	$.ajax({
		type : "POST",
		dataType : "text",
		data : {
			fileId : fileId
		},
		url : "homeController/deleteFile.ajax",
		success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
1133
			if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
1134
				window.location.href = "login.html";
高源 已提交
1135
			} else {
青阳龙野's avatar
青阳龙野 已提交
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
				if (result == "noAuthorized") {
					$('#deleteFileMessage').text("提示:您的操作未被授权,删除失败");
					$("#dfmbutton").attr('disabled', false);
				} else if (result == "errorParameter") {
					$('#deleteFileMessage').text("提示:参数不正确,删除失败");
					$("#dfmbutton").attr('disabled', false);
				} else if (result == "cannotDeleteFile") {
					$('#deleteFileMessage').text("提示:出现意外错误,可能未能删除文件");
					$("#dfmbutton").attr('disabled', false);
				} else if (result == "deleteFileSuccess") {
					$('#deleteFileModal').modal('hide');
					showFolderView(locationpath);
				} else {
					$('#deleteFileMessage').text("提示:出现意外错误,可能未能删除文件");
					$("#dfmbutton").attr('disabled', false);
				}
高源 已提交
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189
			}
		},
		error : function() {
			$('#deleteFileMessage').text("提示:出现意外错误,可能未能删除文件");
			$("#dfmbutton").attr('disabled', false);
		}
	});
}

// 显示重命名文件模态框
function showRenameFileModel(fileId, fileName) {
	$("#newFileNamealert").removeClass("alert");
	$("#newFileNamealert").removeClass("alert-danger");
	$("#filerenamebox").removeClass("has-error");
	$("#newFileNamealert").text("");
	$("#renameFileBox").html(
			"<button type='button' class='btn btn-primary' onclick='renameFile("
					+ '"' + fileId + '"' + ")'>修改</button>");
	$("#newfilename").val(fileName);
	$("#renameFileModal").modal('toggle');
}

// 修改文件名
function renameFile(fileId) {
	var reg = new RegExp("[\/\|\\s\\\\\*\\<\\>" + '"' + "]+", "g");
	var newFileName = $("#newfilename").val();
	if (newFileName.length > 0) {
		if (newFileName.length < 128) {
			if (!reg.test(newFileName)) {
				$.ajax({
					type : "POST",
					dataType : "text",
					data : {
						fileId : fileId,
						newFileName : newFileName
					},
					url : "homeController/renameFile.ajax",
					success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
1190
						if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
1191
							window.location.href = "login.html";
高源 已提交
1192
						} else {
青阳龙野's avatar
青阳龙野 已提交
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
							if (result == "cannotRenameFile") {
								showRenameFolderAlert("提示:出现意外错误,可能未能重命名文件");
							} else if (result == "renameFileSuccess") {
								$('#renameFileModal').modal('hide');
								showFolderView(locationpath);
							} else if (result == "errorParameter") {
								showRenameFolderAlert("提示:参数错误,重命名失败");
							} else if (result == "noAuthorized") {
								showRenameFolderAlert("提示:您的操作未被授权,重命名失败");
							} else {
								showRenameFolderAlert("提示:出现意外错误,可能未能重命名文件");
							}
高源 已提交
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
						}
					},
					error : function() {
						showRenameFolderAlert("提示:出现意外错误,可能未能重命名文件");
					}
				});
			} else {
				showRenameFolderAlert("提示:文件名中不应含有:空格 引号 / \ * | < > ");
			}
		} else {
			showRenameFolderAlert("提示:文件名称太长");
		}
	} else {
		showRenameFolderAlert("提示:文件名不能为空");
	}
}

// 显示重命名文件状态提示
function showRenameFolderAlert(txt) {
	$("#newFileNamealert").addClass("alert");
	$("#newFileNamealert").addClass("alert-danger");
	$("#filerenamebox").addClass("has-error");
	$("#newFileNamealert").text(txt);
}

// 取消上传
function abortUpload() {
青阳龙野's avatar
青阳龙野 已提交
1232
	isUpLoading=false;
高源 已提交
1233 1234
	if (xhr != null) {
		xhr.abort();
青阳龙野's avatar
青阳龙野 已提交
1235 1236 1237
		$("#umbutton").attr('disabled', false);
		$("#pros").width("0%");
		$("#filecount").text("");
高源 已提交
1238
	}
青阳龙野's avatar
青阳龙野 已提交
1239 1240 1241 1242
	$("#uploadfile").val("");
	$("#filepath").val("");
	$("#uploadstatus").html("");
	$("#selectcount").text("");
高源 已提交
1243
	$('#uploadFileModal').modal('hide');
青阳龙野's avatar
青阳龙野 已提交
1244
	showFolderView(locationpath);
1245 1246
}

1247
// 获取文件名的后缀名,以小写形式输出
1248 1249 1250 1251
function getSuffix(filename) {
	var index1 = filename.lastIndexOf(".");
	var index2 = filename.length;
	var suffix = filename.substring(index1 + 1, index2);
1252 1253 1254 1255 1256
	return suffix.toLowerCase();
}

// 播放指定格式的视频
function playVideo(fileId) {
青阳龙野's avatar
青阳龙野 已提交
1257
	window.open("quickview/video.html?fileId=" + fileId);
1258 1259 1260 1261 1262
}

// 预览PDF文档
function pdfView(fileId) {
	window.open("homeController/pdfView.do?fileId=" + fileId);
1263 1264
}

1265 1266
// 查看图片
function showPicture(fileId) {
青阳龙野's avatar
青阳龙野 已提交
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280
	$.ajax({
		url : "homeController/getPrePicture.ajax",
		data : {
			fileId : fileId
		},
		type : "POST",
		dataType : "text",
		success : function(result) {
			if (result != "ERROR") {
				var pvl = eval("(" + result + ")");
				// TODO 整合viewer.js插件
				var imageslist = document.createElement("ul");
				$.each(pvl.pictureViewList, function(n, val) {
					var image = new Image();
青阳龙野's avatar
青阳龙野 已提交
1281 1282 1283 1284 1285 1286
					// 判断直接显示原图还是请求压缩流
					if(val.filePath.startsWith("homeController")){
						image.src = val.filePath;
					}else{
						image.src = "fileblocks/"+val.filePath;
					}
青阳龙野's avatar
青阳龙野 已提交
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306
					image.alt = val.fileName;
					var imagerow = document.createElement("li");
					imagerow.appendChild(image);
					imageslist.appendChild(imagerow);
				});
				viewer = new Viewer(imageslist, {
					hidden : function() {
						viewer.destroy();
					}
				});
				viewer.view(pvl.index);
				viewer.show();
			} else {
				alert("错误:无法定位要预览的文件或该操作未被授权。");
			}
		},
		error : function() {
			alert("错误:请求失败,请刷新重试。");
		}
	});
青阳龙野's avatar
青阳龙野 已提交
1307 1308
}

青阳龙野's avatar
青阳龙野 已提交
1309
// 选中某一行文件,如果使用Shift点击则为多选
青阳龙野's avatar
青阳龙野 已提交
1310
function checkfile(fileId) {
青阳龙野's avatar
青阳龙野 已提交
1311 1312
	if (!window.event.shiftKey) {
		$(".filerow").removeClass("info");
青阳龙野's avatar
青阳龙野 已提交
1313
		$("#" + fileId).addClass("info");
青阳龙野's avatar
青阳龙野 已提交
1314 1315 1316 1317 1318 1319
	} else {
		if ($("#" + fileId).hasClass("info")) {
			$("#" + fileId).removeClass("info");
		} else {
			$("#" + fileId).addClass("info");
		}
青阳龙野's avatar
青阳龙野 已提交
1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335
	}
}

var checkAll = true;

// 切换全部文件行的选中或非选中
function checkallfile() {
	if (checkAll) {
		$(".filerow").addClass("info");
		checkAll = false;
	} else {
		$(".filerow").removeClass("info");
		checkAll = true;
	}
}

1336
// 显示打包下载模态框
青阳龙野's avatar
青阳龙野 已提交
1337
function showDownloadAllCheckedModel() {
1338 1339
	$("#downloadAllCheckedBox").html("");
	$("#downloadAllCheckedLoad").text("");
青阳龙野's avatar
青阳龙野 已提交
1340 1341
	var checkedfiles = $(".info").get();
	if (checkedfiles.length == 0) {
1342
		$("#downloadAllCheckedName")
青阳龙野's avatar
青阳龙野 已提交
1343
				.text(
青阳龙野's avatar
青阳龙野 已提交
1344
						"提示:您还未选择任何文件,请先选中一些文件后再执行本操作(点击某一文件行来选中单一文件;按住Shift并点击文件行选中多个文件;使用Shitf+A选中/取消选中所有文件)。");
青阳龙野's avatar
青阳龙野 已提交
1345
	} else {
1346
		$("#downloadAllCheckedName").text(
青阳龙野's avatar
青阳龙野 已提交
1347
				"提示:您确认要打包并下载这" + checkedfiles.length + "项么?");
1348
		$("#downloadAllCheckedBox")
青阳龙野's avatar
青阳龙野 已提交
1349
				.html(
1350 1351
						"<button id='dclmbutton' type='button' class='btn btn-primary' onclick='downloadAllChecked()'>开始下载</button>");
		$("#dclmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1352
	}
1353
	$("#downloadAllCheckedModal").modal('toggle');
青阳龙野's avatar
青阳龙野 已提交
1354 1355 1356 1357
}

// 下载选中的所有文件
function downloadAllChecked() {
1358
	$("#dclmbutton").attr('disabled', true);
青阳龙野's avatar
青阳龙野 已提交
1359 1360 1361 1362 1363 1364
	var checkedfiles = $(".info").get();
	var downloadIdArray = new Array();
	for (var i = 0; i < checkedfiles.length; i++) {
		downloadIdArray[i] = checkedfiles[i].id;
	}
	var strIdList = JSON.stringify(downloadIdArray);
1365
	$("#downloadAllCheckedName").text(
青阳龙野's avatar
青阳龙野 已提交
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394
			"提示:服务器正在对选中资源进行压缩(共" + checkedfiles.length
			+ "项),这可能需要一些时间(文件越大耗时越长),压缩完成将自动开始下载。");
	// 计算预计耗时
	$.ajax({
		url:'homeController/getPackTime.ajax',
		type:'POST',
		data:{
			strIdList:strIdList
		},
		dataType:'text',
		success:function(result){
			if(result!="0"){
				var count = 0;
				$("#downloadAllCheckedLoad").text("已耗时:"+count+"秒(预计耗时:"+result+"");
				zipTimer=setInterval(function() {
					count++;
					$("#downloadAllCheckedLoad").text("已耗时:"+count+"秒(预计耗时:"+result+"");
				},1000);
			}else{
				var count = 0;
				$("#downloadAllCheckedLoad").text("已耗时:"+count+"");
				zipTimer=setInterval(function() {
					count++;
					$("#downloadAllCheckedLoad").text("已耗时:"+count+"");
				},1000);
			}
		},
		error:function(){
			$("#downloadAllCheckedLoad").text("(无法获取预计耗时)");
1395
		}
青阳龙野's avatar
青阳龙野 已提交
1396 1397
	});
	// 同时发送压缩下载请求
1398 1399 1400 1401 1402 1403 1404 1405
	$.ajax({
		type : "POST",
		url : "homeController/downloadCheckedFiles.ajax",
		data : {
			strIdList : strIdList
		},
		dataType : "text",
		success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
1406 1407 1408
			if(zipTimer!=null){
				window.clearInterval(zipTimer);
			}
1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433
			if (result == "ERROR") {
				$("#downloadAllCheckedName")
						.text("提示:压缩过程出错。无法完成压缩,请重试或告知管理员。");
			} else {
				$("#downloadAllCheckedLoad").text("");
				$("#downloadAllCheckedName").text("提示:压缩完成!准备开始下载...");
				var t = setTimeout(
						"$('#downloadAllCheckedModal').modal('hide');", 800);
				// POST提交全部下载请求
				var temp = document.createElement("form");
				temp.action = 'homeController/downloadCheckedFilesZip.do';
				temp.method = "post";
				temp.style.display = "none";
				var sl = document.createElement("input");
				sl.name = 'zipId';
				sl.value = result;
				temp.appendChild(sl);
				document.body.appendChild(temp);
				temp.submit();
			}
		},
		error : function() {
			$("#downloadAllCheckedName").text("提示:请求失败。无法完成压缩,请重试或告知管理员。");
		}
	});
青阳龙野's avatar
青阳龙野 已提交
1434 1435 1436 1437 1438 1439 1440 1441 1442 1443
}

// 删除选中的所有文件
function showDeleteAllCheckedModel() {
	$('#deleteFileBox').html("");
	var checkedfiles = $(".info").get();
	$("#dfmbutton").attr('disabled', false);
	if (checkedfiles.length == 0) {
		$('#deleteFileMessage')
				.text(
青阳龙野's avatar
青阳龙野 已提交
1444
						"提示:您还未选择任何文件,请先选中一些文件后再执行本操作(点击某一文件行来选中单一文件;按住Shift并点击文件行选中多个文件;使用Shift+A选中/取消选中所有文件)。");
青阳龙野's avatar
青阳龙野 已提交
1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474
	} else {
		$('#deleteFileBox')
				.html(
						"<button id='dfmbutton' type='button' class='btn btn-danger' onclick='deleteAllChecked()'>全部删除</button>");
		$('#deleteFileMessage').text(
				"提示:确定要彻底删除这" + checkedfiles.length + "项么?该操作不可恢复");
	}
	$('#deleteFileModal').modal('toggle');
}

// 删除选中的所有文件
function deleteAllChecked() {
	// TODO 提交全部删除请求
	var checkedfiles = $(".info").get();
	var downloadIdArray = new Array();
	for (var i = 0; i < checkedfiles.length; i++) {
		downloadIdArray[i] = checkedfiles[i].id;
	}
	var strIdList = JSON.stringify(downloadIdArray);
	$("#dfmbutton").attr('disabled', true);
	$('#deleteFileMessage').text("提示:正在删除,请稍候...");
	$.ajax({
		type : "POST",
		dataType : "text",
		data : {
			strIdList : strIdList
		},
		url : "homeController/deleteCheckedFiles.ajax",
		success : function(result) {
			if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
1475
				window.location.href = "login.html";
青阳龙野's avatar
青阳龙野 已提交
1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499
			} else {
				if (result == "noAuthorized") {
					$('#deleteFileMessage').text("提示:您的操作未被授权,删除失败");
					$("#dfmbutton").attr('disabled', false);
				} else if (result == "errorParameter") {
					$('#deleteFileMessage').text("提示:参数不正确,未能全部删除文件");
					$("#dfmbutton").attr('disabled', false);
				} else if (result == "cannotDeleteFile") {
					$('#deleteFileMessage').text("提示:出现意外错误,可能未能删除全部文件");
					$("#dfmbutton").attr('disabled', false);
				} else if (result == "deleteFileSuccess") {
					$('#deleteFileModal').modal('hide');
					showFolderView(locationpath);
				} else {
					$('#deleteFileMessage').text("提示:出现意外错误,可能未能删除全部文件");
					$("#dfmbutton").attr('disabled', false);
				}
			}
		},
		error : function() {
			$('#deleteFileMessage').text("提示:出现意外错误,可能未能删除全部文件");
			$("#dfmbutton").attr('disabled', false);
		}
	});
青阳龙野's avatar
青阳龙野 已提交
1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581
}

// 播放音乐
function playAudio(fileId) {
	$('#audioPlayerModal').modal('show');
	if (ap == null) {
		ap = new APlayer({
			container : document.getElementById('aplayer'),
			lrcType : 3,
			mutex : true,
			volume : 0.7,
			theme:'#EDEDED',
			audio : []
		});
		ap.on('pause', function() {
			$("#playOrPause").html("<span class='glyphicon glyphicon-play' aria-hidden='true'></span>");
		});
		ap.on('play', function() {
			$("#playOrPause").html("<span class='glyphicon glyphicon-pause' aria-hidden='true'></span>");
		});
	}
	ap.list.clear();
	$.ajax({
		url:'homeController/playAudios.ajax',
		data:{
			fileId:fileId
		},
		type:'POST',
		dataType:'text',
		success:function(result){
			var ail=eval("("+result+")");
			ap.list.add(ail.as);
			ap.list.switch(ail.index);
			audio_play();
		},
		error:function(){
			alert("错误:无法获取音乐列表,请稍后再试");
			closeAudioPlayer();
		}
	});
}

// 关闭音乐播放器
function closeAudioPlayer() {
	$('#audioPlayerModal').modal('hide');
	ap.seek(0);
	ap.pause();
}

// 切换按钮状态与
function audio_playOrPause() {
	ap.toggle();
}

// 播放
function audio_play() {
	ap.play();
}

// 暂停
function audio_pasue() {
	ap.pause();
}

// 下一首
function audio_fw() {
	ap.skipForward();
}

// 上一首
function audio_bw() {
	ap.skipBack();
}

// 音量加大,每次10%
function audio_vulome_up(){
	ap.volume(ap.audio.volume+0.1,true);
}

// 音量减少,每次10%
function audio_vulome_down(){
	ap.volume(ap.audio.volume-0.1,true);
青阳龙野's avatar
青阳龙野 已提交
1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652
}

// 按文件名排序
function sortbyfn(){
	$("#sortByFN").addClass("glyphicon glyphicon-triangle-bottom");
	$("#sortByCD").removeClass();
	$("#sortByFS").removeClass();
	$("#sortByCN").removeClass();
	folderView.fileList.sort(function(v1,v2){
		return v1.fileName.localeCompare(v2.fileName,"zh");
	});
	folderView.folderList.sort(function(v1,v2){
		return v1.folderName.localeCompare(v2.folderName,"zh");
	});
	showFolderTable(folderView);
}

// 按创建日期排序
function sortbycd(){
	$("#sortByFN").removeClass();
	$("#sortByCD").addClass("glyphicon glyphicon-triangle-bottom");
	$("#sortByFS").removeClass();
	$("#sortByCN").removeClass();
	folderView.fileList.sort(function(v1,v2){
		var v1DateStr=v1.fileCreationDate.replace("","-").replace("","-").replace("","");
		var v2DateStr=v2.fileCreationDate.replace("","-").replace("","-").replace("","");
		var res=((new Date(Date.parse(v1DateStr)).getTime())-(new Date(Date.parse(v2DateStr)).getTime()));
		return -1*res;
	});
	folderView.folderList.sort(function(v1,v2){
		var v1DateStr=v1.folderCreationDate.replace("","-").replace("","-").replace("","");
		var v2DateStr=v2.folderCreationDate.replace("","-").replace("","-").replace("","");
		var res=((new Date(Date.parse(v1DateStr)).getTime())-(new Date(Date.parse(v2DateStr)).getTime()));
		return -1*res;
	});
	showFolderTable(folderView);
}

// 按文件大小排序
function sortbyfs(){
	$("#sortByFN").removeClass();
	$("#sortByCD").removeClass();
	$("#sortByFS").addClass("glyphicon glyphicon-triangle-bottom");
	$("#sortByCN").removeClass();
	folderView.fileList.sort(function(v1,v2){
		return v2.fileSize-v1.fileSize;
	});
	showFolderTable(folderView);
}

// 按创建者排序
function sortbycn(){
	$("#sortByFN").removeClass();
	$("#sortByCD").removeClass();
	$("#sortByFS").removeClass();
	$("#sortByCN").addClass("glyphicon glyphicon-triangle-bottom");
	folderView.fileList.sort(function(v1,v2){
		return v1.fileCreator.localeCompare(v2.fileCreator,"zh");
	});
	folderView.folderList.sort(function(v1,v2){
		return v1.folderCreator.localeCompare(v2.folderCreator,"zh");
	});
	showFolderTable(folderView);
}

// 显示原始的顺序
function showOriginFolderView(){
	$("#sortByFN").removeClass();
	$("#sortByCD").removeClass();
	$("#sortByFS").removeClass();
	$("#sortByCN").removeClass();
青阳龙野's avatar
青阳龙野 已提交
1653 1654 1655 1656 1657
	if(screenedFoldrView!=null){
		folderView=$.extend(true, {}, screenedFoldrView);
	}else{
		folderView=$.extend(true, {}, originFolderView);
	}
青阳龙野's avatar
青阳龙野 已提交
1658 1659 1660 1661 1662
	showFolderTable(folderView);
}

// 确认文件移动(剪切-粘贴)操作
function startMoveFile(){
青阳龙野's avatar
青阳龙野 已提交
1663
	if($("#cutSignTx").hasClass("cuted")&&checkedMovefiles!==undefined){
青阳龙野's avatar
青阳龙野 已提交
1664 1665 1666 1667 1668 1669 1670 1671 1672
		var moveIdArray = new Array();
		for (var i = 0; i < checkedMovefiles.length; i++) {
			moveIdArray[i] = checkedMovefiles[i].id;
		}
		var strIdList = JSON.stringify(moveIdArray);
		$('#moveFilesMessage').text("提示:确定将这"+checkedMovefiles.length+"项移动到当前位置么?");
		$('#moveFilesBox').html("<button id='dmvfbutton' type='button' class='btn btn-danger' onclick='doMoveFiles()'>全部移动</button>");
		$('#moveFilesModal').modal('show');
	}else{
青阳龙野's avatar
青阳龙野 已提交
1673
		checkedMovefiles = $("#foldertable .info").get();
青阳龙野's avatar
青阳龙野 已提交
1674 1675 1676 1677 1678
		if (checkedMovefiles==undefined||checkedMovefiles.length == 0) {
			$('#moveFilesMessage').text("提示:您还未选择任何文件,请先选中一些文件后再执行本操作(点击某一文件行来选中单一文件;按住Shift并点击文件行选中多个文件;使用Shift+A选中/取消选中所有文件)。");
			$('#moveFilesModal').modal('show');
		} else {
			$("#cutSignTx").text("粘贴("+checkedMovefiles.length+"");
青阳龙野's avatar
青阳龙野 已提交
1679
			$("#cutSignTx").addClass("cuted");
青阳龙野's avatar
青阳龙野 已提交
1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727
		}
	}
}

// 执行文件移动操作
function doMoveFiles(){
	var moveIdArray = new Array();
	for (var i = 0; i < checkedMovefiles.length; i++) {
		moveIdArray[i] = checkedMovefiles[i].id;
	}
	var strIdList = JSON.stringify(moveIdArray);
	$("#dmvfbutton").attr('disabled', true);
	$('#moveFilesMessage').text("提示:正在移动,请稍候...");
	$.ajax({
		type : "POST",
		dataType : "text",
		data : {
			strIdList : strIdList,
			locationpath:locationpath
		},
		url : "homeController/moveCheckedFiles.ajax",
		success : function(result) {
			if (result == "mustLogin") {
				window.location.href = "login.html";
			} else {
				if (result == "noAuthorized") {
					$('#moveFilesMessage').text("提示:您的操作未被授权,移动失败");
					$("#dmvfbutton").attr('disabled', false);
				} else if (result == "errorParameter") {
					$('#moveFilesMessage').text("提示:参数不正确,未能全部移动文件");
					$("#dmvfbutton").attr('disabled', false);
				} else if (result == "cannotMoveFiles") {
					$('#moveFilesMessage').text("提示:出现意外错误,可能未能移动全部文件");
					$("#dmvfbutton").attr('disabled', false);
				} else if (result == "moveFilesSuccess") {
					$('#moveFilesModal').modal('hide');
					showFolderView(locationpath);
				} else {
					$('#moveFilesMessage').text("提示:出现意外错误,可能未能移动全部文件");
					$("#dmvfbutton").attr('disabled', false);
				}
			}
		},
		error : function() {
			$('#moveFilesMessage').text("提示:出现意外错误,可能未能移动全部文件");
			$("#dmvfbutton").attr('disabled', false);
		}
	});
青阳龙野's avatar
青阳龙野 已提交
1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765
}

var screenedFoldrView;// 经过排序的文件视图

// 执行搜索功能
function doSearchFile(){
	startLoading();
	try{
		var keyworld=$("#sreachKeyWordIn").val();
		if(keyworld.length!=0){
			var reg=new RegExp(keyworld+"+");
			screenedFoldrView=$.extend(true, {}, originFolderView);
			screenedFoldrView.folderList=[];
			screenedFoldrView.fileList=[];
			for(var i=0,j=originFolderView.folderList.length;i<j;i++){
				if(reg.test(originFolderView.folderList[i].folderName)){
					screenedFoldrView.folderList.push(originFolderView.folderList[i]);
				}
			}
			for(var i=0,j=originFolderView.fileList.length;i<j;i++){
				if(reg.test(originFolderView.fileList[i].fileName)){
					screenedFoldrView.fileList.push(originFolderView.fileList[i]);
				}
			}
			$("#sortByFN").removeClass();
			$("#sortByCD").removeClass();
			$("#sortByFS").removeClass();
			$("#sortByCN").removeClass();
			folderView=$.extend(true, {}, screenedFoldrView);
			showFolderTable(folderView);
		}else{
			screenedFoldrView=null;
			showOriginFolderView();
		}
	}catch(e){
		alert("错误:搜索关键字有误。请在特殊符号(例如“*”)前加上“\\”进行转义。");
	}
	endLoading();
高源 已提交
1766
}