home.js 39.4 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;// 打包下载计时器
高源 已提交
9

青阳龙野's avatar
青阳龙野 已提交
10
// 页面初始化
高源 已提交
11
$(function() {
青阳龙野's avatar
青阳龙野 已提交
12 13 14 15 16 17
	getServerOS();// 得到服务器操作系统信息
	showFolderView(locationpath);// 显示根节点页面视图
	// 点击空白处取消选中文件(不支持火狐)
	$(document).click(function(e) {
		var filetable = $("#filetable")[0];
		if (e.target !== filetable && !$.contains(filetable, e.target)) {
青阳龙野's avatar
青阳龙野 已提交
18 19 20
			$(".filerow").removeClass("info");
		}
	});
青阳龙野's avatar
青阳龙野 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33
	// 关闭音乐播放模态框自动停止播放并将进度归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);
		}
	});
高源 已提交
34 35 36 37 38 39 40 41 42 43 44 45
});

// 获取服务器操作系统
function getServerOS() {
	$.ajax({
		type : "POST",
		dataType : "text",
		data : {

		},
		url : "homeController/getServerOS.ajax",
		success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
46
			if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
47
				window.location.href = "login.html";
青阳龙野's avatar
青阳龙野 已提交
48
			}
高源 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
			$("#serverOS").text(result);
		},
		error : function() {
			$("#serverOS").html("<a onclick='getServerOS()'>获取失败,点击重试</a>");
		}
	});
}

// 获取实时文件夹视图
function showFolderView(fid) {
	$.ajax({
		type : 'POST',
		dataType : 'text',
		data : {
			fid : fid
		},
		url : 'homeController/getFolderView.ajax',
		success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
67
			if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
68
				window.location.href = "login.html";
青阳龙野's avatar
青阳龙野 已提交
69 70 71 72 73 74 75 76 77
			} else {
				var folderView = eval("(" + result + ")");
				locationpath = folderView.folder.folderId;
				parentpath = folderView.folder.folderParent;
				showParentList(folderView);
				showAccountView(folderView);
				showPublishTime(folderView);
				showFolderTable(folderView);
			}
高源 已提交
78 79 80 81 82 83 84 85 86 87 88 89
		},
		error : function() {
			$("#tb").html("<span class='graytext'>获取失败,请尝试刷新</span>");
			$("#publishTime").html("<span class='graytext'>获取失败,请尝试刷新</span>");
			$("#parentlistbox")
					.html("<span class='graytext'>获取失败,请尝试刷新</span>");
		}
	});
}

// 登录操作
function dologin() {
青阳龙野's avatar
青阳龙野 已提交
90 91
	var accountId = $("#accountid").val();
	var accountPwd = $("#accountpwd").val();
高源 已提交
92
	var check = "y";
青阳龙野's avatar
青阳龙野 已提交
93
	if (accountId.length == 0) {
高源 已提交
94
		$("#accountidbox").addClass("has-error");
青阳龙野's avatar
青阳龙野 已提交
95
		check = "n";
高源 已提交
96 97 98
	} else {
		$("#accountidbox").removeClass("has-error");
	}
青阳龙野's avatar
青阳龙野 已提交
99
	if (accountPwd.length == 0) {
高源 已提交
100
		$("#accountpwdbox").addClass("has-error");
青阳龙野's avatar
青阳龙野 已提交
101
		check = "n";
高源 已提交
102 103 104 105
	} else {
		$("#accountpwdbox").removeClass("has-error");
	}
	if (check == "y") {
青阳龙野's avatar
青阳龙野 已提交
106
		// 加密认证-获取公钥并将请求加密发送给服务器,避免中途被窃取
高源 已提交
107
		$.ajax({
青阳龙野's avatar
青阳龙野 已提交
108 109 110 111
			url : 'homeController/getPublicKey.ajax',
			type : 'POST',
			data : {},
			dataType : 'text',
高源 已提交
112
			success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
113 114 115 116 117 118 119 120
				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);
高源 已提交
121 122 123 124 125 126 127 128 129 130
			},
			error : function() {
				$("#alertbox").addClass("alert");
				$("#alertbox").addClass("alert-danger");
				$("#alertbox").text("提示:登录请求失败,请检查网络或服务器运行状态");
			}
		});
	}
}

青阳龙野's avatar
青阳龙野 已提交
131 132 133 134 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 176 177 178 179 180 181 182 183
// 发送加密文本
function sendLoginInfo(encrypted) {
	$.ajax({
		type : "POST",
		dataType : "text",
		url : "homeController/doLogin.ajax",
		data : {
			encrypted : encrypted
		},
		success : function(result) {
			$("#alertbox").removeClass("alert");
			$("#alertbox").removeClass("alert-danger");
			$("#alertbox").text("");
			switch (result) {
			case "permitlogin":
				$("#accountidbox").removeClass("has-error");
				$("#accountpwdbox").removeClass("has-error");
				window.location.href = "home.html";
				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() {
			$("#alertbox").addClass("alert");
			$("#alertbox").addClass("alert-danger");
			$("#alertbox").text("提示:登录请求失败,请检查网络或服务器运行状态");
		}
	});
}

高源 已提交
184 185 186 187 188 189 190 191 192 193 194 195
// 注销操作
function dologout() {
	$('#logoutModal').modal('hide');
	window.location.href = "homeController/doLogout.do";
}

// 显示当前文件夹的父级路径
function showParentList(folderView) {
	$("#parentlistbox").html("");
	var f = folderView.folder;
	var index = 0;
	$.each(folderView.parentList, function(n, val) {
青阳龙野's avatar
青阳龙野 已提交
196
		if (index <= 3) {
高源 已提交
197 198 199 200 201 202 203 204
			$("#parentlistbox").append(
					"<button onclick='entryFolder(" + '"' + val.folderId + '"'
							+ ")' class='btn btn-link btn-xs'>"
							+ val.folderName + "</button> / ");
			index++;
		} else {
		}
	});
青阳龙野's avatar
青阳龙野 已提交
205
	if (index > 3) {
高源 已提交
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
		$("#parentlistbox").append("... / ");
	}
	$("#parentlistbox").append(f.folderName);
}

// 显示用户视图,包括文件列表、登录信息、操作权限接口等
function showAccountView(folderView) {
	$("#tb").html("");
	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;
	if (authList != null) {
		if (checkAuth(authList, "C")) {
			$("#parentlistbox")
					.append(
							"<button onclick='showNewFolderModel()' class='btn btn-link btn-xs rightbtn'><span class='glyphicon glyphicon-folder-open'></span> 新建文件夹</button>");
		}
		if (checkAuth(authList, "U")) {
			$("#parentlistbox")
					.append(
							"<button onclick='showUploadFileModel()' class='btn btn-link btn-xs rightbtn'><span class='glyphicon glyphicon-cloud-upload'></span> 上传文件</button>");
		}
青阳龙野's avatar
青阳龙野 已提交
239 240 241 242 243 244 245 246 247 248
		if (checkAuth(authList, "L")) {
			$("#parentlistbox")
					.append(
							"<button onclick='showDownloadAllCheckedModel()' class='btn btn-link btn-xs rightbtn'><span class='glyphicon glyphicon-cloud-download'></span> 打包下载</button>");
		}
		if (checkAuth(authList, "D")) {
			$("#parentlistbox")
					.append(
							"<button onclick='showDeleteAllCheckedModel()' class='btn btn-link btn-xs rightbtn'><span class='glyphicon glyphicon-trash'></span> 批量删除</button>");
		}
高源 已提交
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
	}
}

// 检查权限列表
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
青阳龙野 已提交
299
						"<tr onclick='returnPF()'><td><button onclick='returnPF()' class='btn btn-link btn-xs'>../</button></td><td>--</td><td>--</td><td>--</td><td>--</td></tr>");
高源 已提交
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
	}
	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
									+ '"'
									+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-wrench'></span> 重命名</button>";
						}
						if (!aR && !aD) {
							folderRow = folderRow + "--";
						}
						folderRow = folderRow + "</td></tr>";
						$("#foldertable").append(folderRow);
					});
	$
			.each(
					folderView.fileList,
					function(n, fi) {
青阳龙野's avatar
青阳龙野 已提交
355 356 357 358 359 360
						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>";
高源 已提交
361 362 363 364 365 366 367 368 369
						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>";
370 371 372
							// 对于各种特殊格式文件提供的预览和播放功能
							if (getSuffix(fi.fileName) == "mp4"
									|| getSuffix(fi.fileName) == "webm") {
373 374 375 376 377 378
								fileRow = fileRow
										+ "<button onclick='playVideo("
										+ '"'
										+ fi.fileId
										+ '"'
										+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-play'></span> 播放</button>";
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
							} 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
青阳龙野 已提交
397 398 399 400 401 402 403 404 405
							} 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>";
406
							}
高源 已提交
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
						}
						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);
					});
}

// 显示新建文件夹模态框
function showNewFolderModel() {
	$("#foldername").val("");
	$('#newFolderModal').modal('toggle');
}

// 创建新的文件夹
function createfolder() {
	var fn = $("#foldername").val();
	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,
				folderName : fn
			},
			url : "homeController/newFolder.ajax",
			success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
466
				if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
467
					window.location.href = "login.html";
高源 已提交
468
				} else {
青阳龙野's avatar
青阳龙野 已提交
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
					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);
					}
高源 已提交
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
				}
			},
			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
青阳龙野 已提交
532
			if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
533
				window.location.href = "login.html";
高源 已提交
534
			} else {
青阳龙野's avatar
青阳龙野 已提交
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
				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);
				}
高源 已提交
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
			}
		},
		error : function() {
			$('#deleteFolderMessage').text("提示:出现意外错误,可能未能删除文件夹");
			$("#dmbutton").attr('disabled', false);
		}
	});
}

// 显示重命名文件夹模态框
function showRenameFolderModel(folderId, folderName) {
	$("#newfolderalert").removeClass("alert");
	$("#newfolderalert").removeClass("alert-danger");
	$("#folderrenamebox").removeClass("has-error");
	$("#newfolderalert").text("");
	$("#renameFolderBox").html(
			"<button type='button' class='btn btn-primary' onclick='renameFolder("
					+ '"' + folderId + '"' + ")'>修改</button>");
	$("#newfoldername").val(folderName);
	$("#renameFolderModal").modal('toggle');
}

青阳龙野's avatar
青阳龙野 已提交
573
// 执行重命名文件夹
高源 已提交
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
function renameFolder(folderId) {
	var newName = $("#newfoldername").val();
	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,
				newName : newName
			},
			url : "homeController/renameFolder.ajax",
			success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
595
				if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
596
					window.location.href = "login.html";
高源 已提交
597
				} else {
青阳龙野's avatar
青阳龙野 已提交
598 599 600 601 602 603 604 605 606 607 608 609
					if (result == "noAuthorized") {
						showRenameFolderAlert("提示:您的操作未被授权,重命名失败");
					} else if (result == "errorParameter") {
						showRenameFolderAlert("提示:参数不正确,重命名失败");
					} else if (result == "cannotRenameFolder") {
						showRenameFolderAlert("提示:出现意外错误,可能未能重命名文件夹");
					} else if (result == "renameFolderSuccess") {
						$('#renameFolderModal').modal('hide');
						showFolderView(locationpath);
					} else {
						showRenameFolderAlert("提示:出现意外错误,可能未能重命名文件夹");
					}
高源 已提交
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
				}
			},
			error : function() {
				showRenameFolderAlert("提示:出现意外错误,可能未能重命名文件夹");
			}
		});
	} 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("");
	$('#uploadFileModal').modal('toggle');
}

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

// 文件选中后自动回填文件路径
function showfilepath() {
青阳龙野's avatar
青阳龙野 已提交
644 645 646 647 648 649 650 651 652 653 654 655 656 657
	var fs = $("#uploadfile").get(0).files;
	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);
高源 已提交
658 659 660 661 662 663 664 665 666 667 668
}

// 检查是否能够上传
function checkUploadFile() {

	$("#umbutton").attr('disabled', true);

	$("#uploadFileAlert").removeClass("alert");
	$("#uploadFileAlert").removeClass("alert-danger");
	$("#uploadFileAlert").text("");

青阳龙野's avatar
青阳龙野 已提交
669 670 671 672 673 674
	var fs = $("#uploadfile").get(0).files;
	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);
高源 已提交
675 676 677 678 679 680

	$.ajax({
		type : "POST",
		dataType : "text",
		data : {
			folderId : locationpath,
青阳龙野's avatar
青阳龙野 已提交
681
			namelist : namelist
高源 已提交
682 683 684
		},
		url : "homeController/checkUploadFile.ajax",
		success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
685
			if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
686
				window.location.href = "login.html";
高源 已提交
687
			} else {
青阳龙野's avatar
青阳龙野 已提交
688 689 690 691 692 693 694 695 696 697 698 699
				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("提示:出现意外错误,无法开始上传");
				}
高源 已提交
700 701 702 703 704 705 706 707 708 709 710
			}
		},
		error : function() {
			showUploadFileAlert("提示:出现意外错误,无法开始上传");
		}
	});
}

var xhr;

// 执行文件上传并实现上传进度显示
青阳龙野's avatar
青阳龙野 已提交
711
function doupload(count) {
高源 已提交
712

青阳龙野's avatar
青阳龙野 已提交
713 714
	var fs = $("#uploadfile").get(0).files;
	var fcount = fs.length;
高源 已提交
715
	$("#pros").width("0%");// 先将进度条置0
青阳龙野's avatar
青阳龙野 已提交
716
	var uploadfile = fs[count - 1];// 获取要上传的文件
高源 已提交
717
	if (uploadfile != null) {
青阳龙野's avatar
青阳龙野 已提交
718 719 720 721 722 723 724 725

		var fname = uploadfile.name;
		if (fcount > 1) {
			$("#filecount").text("" + count + "/" + fcount + "");// 显示当前进度
		}
		$("#uploadstatus").prepend(
				"<p>" + fname + "<span id='uls_" + count
						+ "'>[正在上传...]</span></p>");
高源 已提交
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
		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
青阳龙野 已提交
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
					$("#uls_" + count).text("[已完成]");
					if (count < fcount) {
						doupload(count + 1);
					} else {
						// 清空所有提示信息,还原上传窗口
						$("#uploadfile").val("");
						$("#filepath").val("");
						$("#pros").width("0%");
						$('#uploadFileModal').modal('hide');
						$("#umbutton").attr('disabled', false);
						showFolderView(locationpath);
						$("#filecount").text("");
						$("#uploadstatus").text("");
						$("#selectcount").text("");
					}
高源 已提交
761
				} else if (result == "uploaderror") {
青阳龙野's avatar
青阳龙野 已提交
762 763 764
					showUploadFileAlert("提示:出现意外错误,文件:[" + fname
							+ "]上传失败,上传被中断。");
					$("#uls_" + count).text("[失败]");
高源 已提交
765 766
				} else {
					$('#uploadFileModal').modal('hide');
青阳龙野's avatar
青阳龙野 已提交
767
					$("#uls_" + count).text("[失败]");
高源 已提交
768 769
				}
			} else {
青阳龙野's avatar
青阳龙野 已提交
770 771
				showUploadFileAlert("提示:出现意外错误,文件:[" + fname + "]上传失败,上传被中断。");
				$("#uls_" + count).text("[失败]");
高源 已提交
772 773 774
			}
		};
	} else {
青阳龙野's avatar
青阳龙野 已提交
775 776 777
		showUploadFileAlert("提示:要上传的文件不存在。");
		$("#uploadstatus").prepend(
				"<p>未找到要上传的文件<span id='uls_" + count + "'>[失败]</span></p>");
高源 已提交
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 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
	}
}

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) {
	$("#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
青阳龙野 已提交
840
			if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
841
				window.location.href = "login.html";
高源 已提交
842
			} else {
青阳龙野's avatar
青阳龙野 已提交
843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858
				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);
				}
高源 已提交
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896
			}
		},
		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
青阳龙野 已提交
897
						if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
898
							window.location.href = "login.html";
高源 已提交
899
						} else {
青阳龙野's avatar
青阳龙野 已提交
900 901 902 903 904 905 906 907 908 909 910 911
							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("提示:出现意外错误,可能未能重命名文件");
							}
高源 已提交
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940
						}
					},
					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() {
	if (xhr != null) {
		xhr.abort();
青阳龙野's avatar
青阳龙野 已提交
941 942 943
		$("#umbutton").attr('disabled', false);
		$("#pros").width("0%");
		$("#filecount").text("");
高源 已提交
944
	}
青阳龙野's avatar
青阳龙野 已提交
945 946 947 948
	$("#uploadfile").val("");
	$("#filepath").val("");
	$("#uploadstatus").html("");
	$("#selectcount").text("");
高源 已提交
949
	$('#uploadFileModal').modal('hide');
青阳龙野's avatar
青阳龙野 已提交
950
	showFolderView(locationpath);
951 952
}

953
// 获取文件名的后缀名,以小写形式输出
954 955 956 957
function getSuffix(filename) {
	var index1 = filename.lastIndexOf(".");
	var index2 = filename.length;
	var suffix = filename.substring(index1 + 1, index2);
958 959 960 961 962
	return suffix.toLowerCase();
}

// 播放指定格式的视频
function playVideo(fileId) {
青阳龙野's avatar
青阳龙野 已提交
963
	window.open("quickview/video.html?fileId=" + fileId);
964 965 966 967 968
}

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

971 972
// 查看图片
function showPicture(fileId) {
青阳龙野's avatar
青阳龙野 已提交
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
	$.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();
					image.src = "fileblocks/" + val.filePath;
					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
青阳龙野 已提交
1008 1009
}

青阳龙野's avatar
青阳龙野 已提交
1010
// 选中某一行文件,如果使用Shift点击则为多选
青阳龙野's avatar
青阳龙野 已提交
1011
function checkfile(fileId) {
青阳龙野's avatar
青阳龙野 已提交
1012 1013
	if (!window.event.shiftKey) {
		$(".filerow").removeClass("info");
青阳龙野's avatar
青阳龙野 已提交
1014
		$("#" + fileId).addClass("info");
青阳龙野's avatar
青阳龙野 已提交
1015 1016 1017 1018 1019 1020
	} else {
		if ($("#" + fileId).hasClass("info")) {
			$("#" + fileId).removeClass("info");
		} else {
			$("#" + fileId).addClass("info");
		}
青阳龙野's avatar
青阳龙野 已提交
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
	}
}

var checkAll = true;

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

1037
// 显示打包下载模态框
青阳龙野's avatar
青阳龙野 已提交
1038
function showDownloadAllCheckedModel() {
1039 1040
	$("#downloadAllCheckedBox").html("");
	$("#downloadAllCheckedLoad").text("");
青阳龙野's avatar
青阳龙野 已提交
1041 1042
	var checkedfiles = $(".info").get();
	if (checkedfiles.length == 0) {
1043
		$("#downloadAllCheckedName")
青阳龙野's avatar
青阳龙野 已提交
1044
				.text(
青阳龙野's avatar
青阳龙野 已提交
1045
						"提示:您还未选择任何文件,请先选中一些文件后再执行本操作(点击某一文件行来选中单一文件;按住Shift并点击文件行选中多个文件;点击列表的表头来选中/取消选中所有文件)。");
青阳龙野's avatar
青阳龙野 已提交
1046
	} else {
1047
		$("#downloadAllCheckedName").text(
青阳龙野's avatar
青阳龙野 已提交
1048
				"提示:您确认要打包并下载这" + checkedfiles.length + "项么?");
1049
		$("#downloadAllCheckedBox")
青阳龙野's avatar
青阳龙野 已提交
1050
				.html(
1051 1052
						"<button id='dclmbutton' type='button' class='btn btn-primary' onclick='downloadAllChecked()'>开始下载</button>");
		$("#dclmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1053
	}
1054
	$("#downloadAllCheckedModal").modal('toggle');
青阳龙野's avatar
青阳龙野 已提交
1055 1056 1057 1058
}

// 下载选中的所有文件
function downloadAllChecked() {
1059
	$("#dclmbutton").attr('disabled', true);
青阳龙野's avatar
青阳龙野 已提交
1060 1061 1062 1063 1064 1065
	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);
1066
	$("#downloadAllCheckedName").text(
青阳龙野's avatar
青阳龙野 已提交
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
			"提示:服务器正在对选中资源进行压缩(共" + 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("(无法获取预计耗时)");
1096
		}
青阳龙野's avatar
青阳龙野 已提交
1097 1098
	});
	// 同时发送压缩下载请求
1099 1100 1101 1102 1103 1104 1105 1106
	$.ajax({
		type : "POST",
		url : "homeController/downloadCheckedFiles.ajax",
		data : {
			strIdList : strIdList
		},
		dataType : "text",
		success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
1107 1108 1109
			if(zipTimer!=null){
				window.clearInterval(zipTimer);
			}
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134
			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
青阳龙野 已提交
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
}

// 删除选中的所有文件
function showDeleteAllCheckedModel() {
	$('#deleteFileBox').html("");
	var checkedfiles = $(".info").get();
	$("#dfmbutton").attr('disabled', false);
	if (checkedfiles.length == 0) {
		$('#deleteFileMessage')
				.text(
青阳龙野's avatar
青阳龙野 已提交
1145
						"提示:您还未选择任何文件,请先选中一些文件后再执行本操作(点击某一文件行来选中单一文件;按住Shift并点击文件行选中多个文件;点击列表的表头来选中/取消选中所有文件)。");
青阳龙野's avatar
青阳龙野 已提交
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
	} 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
青阳龙野 已提交
1176
				window.location.href = "login.html";
青阳龙野's avatar
青阳龙野 已提交
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
			} 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
青阳龙野 已提交
1201 1202 1203 1204 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 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
}

// 播放音乐
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);
高源 已提交
1283
}