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

青阳龙野's avatar
青阳龙野 已提交
5
// 所用val名称列表,注意不要冲突,其中一些参数能够设定界面行为。
青阳龙野's avatar
青阳龙野 已提交
6 7 8 9
var locationpath = "root";// 记录当前文件路径
var parentpath = "null";// 记录当前文件路径的父级目录
var ap;// 音乐播放器对象
var zipTimer;// 打包下载计时器
青阳龙野's avatar
青阳龙野 已提交
10 11 12
var folderView;// 返回的文件系统视图对象
var originFolderView;// 保存原始的文件视图对象
var fs;// 选中的要上传的文件列表
青阳龙野's avatar
青阳龙野 已提交
13
var ifs;// 选中的要上传的文件夹内的文件列表
青阳龙野's avatar
青阳龙野 已提交
14
var checkedMovefiles;// 移动文件的存储列表
青阳龙野's avatar
青阳龙野 已提交
15 16 17 18
var isCopy;// 移动文件是否为复制模式,如果是,则“复制”,否则“剪切”
var repeMap;// 移动文件时,保存用户对每个冲突项目的处理操作
var strMoveOptMap;// 移动(或复制)操作导致文件名冲突的项目
var mRepeSize;// 移动(或复制)操作导致文件名冲突的项目数
青阳龙野's avatar
青阳龙野 已提交
19
var constraintLevel;// 当前文件夹限制等级
青阳龙野's avatar
青阳龙野 已提交
20
var account;// 用户账户
青阳龙野's avatar
青阳龙野 已提交
21 22 23
var isUpLoading = false;// 是否正在执行上传操作
var isImporting = false;// 是否正在执行上传文件夹操作
var isChangingPassword = false;// 是否正在执行修改密码操作
青阳龙野's avatar
青阳龙野 已提交
24 25
var importFolderName;// 上传文件夹时保存文件夹名称
var xhr;// 文件或文件夹上传请求对象
青阳龙野's avatar
青阳龙野 已提交
26 27 28 29
var viewerPageSize = 15; // 显示图片页的最大长度,注意最好是奇数
var viewer; // viewer对象,用于预览图片功能
var viewerPageIndex; // 分页预览图片——已浏览图片页号
var viewerTotal; // 分页预览图片——总页码数
青阳龙野's avatar
青阳龙野 已提交
30
var pvl;// 预览图片列表的JSON格式对象
青阳龙野's avatar
青阳龙野 已提交
31
var checkFilesTip = "提示:您还未选择任何文件,请先选中一些文件后再执行本操作:<br /><br /><kbd>单击</kbd>:选中某一文件<br /><br /><kbd><kbd>Shift</kbd>+<kbd>单击</kbd></kbd>:选中多个文件<br /><br /><kbd><kbd>Shift</kbd>+<kbd>双击</kbd></kbd>:选中连续的文件<br /><br /><kbd><kbd>Shitf</kbd>+<kbd>A</kbd></kbd>:选中/取消选中所有文件";// 选取文件提示
青阳龙野's avatar
青阳龙野 已提交
32
var winHeight;// 窗口高度
青阳龙野's avatar
青阳龙野 已提交
33
var pingInt;// 定时应答器的定时装置
青阳龙野's avatar
青阳龙野 已提交
34
var noticeInited = false;// 公告信息的md5标识
青阳龙野's avatar
青阳龙野 已提交
35 36 37 38 39
var loadingComplete;// 判断文件夹视图是否加载完成
var totalFoldersOffset;// 记录文件夹原始的查询偏移量,便于计算加载进度
var totalFilesOffset;// 记录文件原始的查询偏移量,便于计算加载进度
var remainingLoadingRequest;// 后续数据加载请求的索引,便于中途取消
var loadingFolderView;// 是否正在加载文件夹视图的判断,避免重复操作
高源 已提交
40

青阳龙野's avatar
青阳龙野 已提交
41
// 界面功能方法定义
青阳龙野's avatar
青阳龙野 已提交
42
// 页面初始化
高源 已提交
43
$(function() {
青阳龙野's avatar
青阳龙野 已提交
44
	window.onresize = function() {
青阳龙野's avatar
青阳龙野 已提交
45
		changeFilesTableStyle();
青阳龙野's avatar
青阳龙野 已提交
46
		updateWinHeight();
青阳龙野's avatar
青阳龙野 已提交
47
	}
青阳龙野's avatar
青阳龙野 已提交
48
	changeFilesTableStyle();
青阳龙野's avatar
青阳龙野 已提交
49
	getServerOS();// 得到服务器操作系统信息
青阳龙野's avatar
青阳龙野 已提交
50
	subscribeNotice();// 加载公告MD5,以判断是否需要显示最新公告
青阳龙野's avatar
青阳龙野 已提交
51 52
	// 查询是否存在记忆路径,若有,则直接显示记忆路径的内容,否则显示ROOT根路径
	var arr = document.cookie.match(new RegExp("(^| )folder_id=([^;]*)(;|$)"));
青阳龙野's avatar
青阳龙野 已提交
53 54 55 56 57
	if (arr != null) {
		showFolderView(unescape(arr[2]));// 显示记忆路径页面视图
	} else {
		showFolderView("root");// 显示根节点页面视图
	}
青阳龙野's avatar
青阳龙野 已提交
58
	// 点击空白处取消选中文件(已尝试兼容火狐,请期待用户反馈,如不好使再改)
青阳龙野's avatar
青阳龙野 已提交
59 60
	$(document).click(function(e) {
		var filetable = $("#filetable")[0];
青阳龙野's avatar
青阳龙野 已提交
61 62 63 64 65
		var srcElement = e.srcElement;
		if (!srcElement) {
			srcElement = e.target;
		}
		if (srcElement !== filetable && !$.contains(filetable, e.target)) {
青阳龙野's avatar
青阳龙野 已提交
66 67 68
			$(".filerow").removeClass("info");
		}
	});
青阳龙野's avatar
青阳龙野 已提交
69 70 71 72 73 74
	// 关闭音乐播放模态框自动停止播放并将进度归0
	$('#audioPlayerModal').on('hidden.bs.modal', function(e) {
		if (ap != null) {
			ap.seek(0);
			ap.pause();
		}
青阳龙野's avatar
青阳龙野 已提交
75
		if (pingInt != null) {
青阳龙野's avatar
青阳龙野 已提交
76 77 78
			window.clearInterval(pingInt);
			pingInt = null;
		}
青阳龙野's avatar
青阳龙野 已提交
79 80 81
	});
	// 关闭打包下载模态框自动停止计时
	$('#downloadAllCheckedModal').on('hidden.bs.modal', function(e) {
青阳龙野's avatar
青阳龙野 已提交
82
		if (zipTimer != null) {
青阳龙野's avatar
青阳龙野 已提交
83 84 85
			window.clearInterval(zipTimer);
		}
	});
青阳龙野's avatar
青阳龙野 已提交
86 87
	// 关闭登陆模态框自动清空输入数据
	$('#loginModal').on('hidden.bs.modal', function(e) {
青阳龙野's avatar
青阳龙野 已提交
88
		if ($("#dologinButton").attr('disabled') !== 'disabled') {
青阳龙野's avatar
青阳龙野 已提交
89 90 91
			$("#accountid").val('');
			$("#accountpwd").val('');
		}
青阳龙野's avatar
青阳龙野 已提交
92 93 94 95 96 97 98 99
		$("#accountidbox").removeClass("has-error");
		$("#accountpwdbox").removeClass("has-error");
		$("#alertbox").removeClass("alert");
		$("#alertbox").removeClass("alert-danger");
		$("#alertbox").text("");
		$("#vercodebox").html("");
		$("#vercodebox").removeClass("show");
		$("#vercodebox").addClass("hidden");
青阳龙野's avatar
青阳龙野 已提交
100
	});
青阳龙野's avatar
青阳龙野 已提交
101
	// 各个模态框的打开判定及回车响应功能。该功能仅对“首选”的按钮有效,对其他按钮无效,以避免用户误操作。
青阳龙野's avatar
青阳龙野 已提交
102 103 104 105 106 107 108
	$('.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
青阳龙野 已提交
109
		var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
青阳龙野's avatar
青阳龙野 已提交
110 111
		if (keyCode == 13) {
			if ("sreachKeyWordIn" === document.activeElement.id) {
青阳龙野's avatar
青阳龙野 已提交
112
				doSearchFile();
青阳龙野's avatar
青阳龙野 已提交
113 114 115
			} else {
				var g = $(".shown .btn-primary");
				if (g.get(0) != null && g.prop("disabled") == false) {
青阳龙野's avatar
青阳龙野 已提交
116 117
					g.click();
				}
青阳龙野's avatar
青阳龙野 已提交
118 119
			}
			return false;
青阳龙野's avatar
青阳龙野 已提交
120 121
		}
	});
青阳龙野's avatar
青阳龙野 已提交
122 123 124 125 126
	// 开启登陆模态框自动聚焦账户输入框
	$('#loginModal').on('shown.bs.modal', function(e) {
		$("#accountid").focus();
	});
	// 开启新建文件夹框自动初始化状态
青阳龙野's avatar
青阳龙野 已提交
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
	$('#newFolderModal')
			.on(
					'show.bs.modal',
					function(e) {
						$("#folderalert").removeClass("alert");
						$("#folderalert").removeClass("alert-danger");
						$("#foldernamebox").removeClass("has-error");
						$("#folderalert").text("");
						$("#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
青阳龙野 已提交
154 155 156 157
	// 开启新建文件夹模态框自动聚焦文件名输入框
	$('#newFolderModal').on('shown.bs.modal', function(e) {
		$("#foldername").focus();
	});
青阳龙野's avatar
青阳龙野 已提交
158
	// 关闭上传模态框时自动提示如何查看上传进度
青阳龙野's avatar
青阳龙野 已提交
159
	$('#uploadFileModal,#importFolderModal').on('hidden.bs.modal', function(e) {
青阳龙野's avatar
青阳龙野 已提交
160
		if (isUpLoading || isImporting) {
青阳龙野's avatar
青阳龙野 已提交
161 162 163 164 165 166
			$('#operationMenuBox').attr("data-placement", "top");
			$('#operationMenuBox').attr("data-trigger", "focus");
			$('#operationMenuBox').attr("data-title", "上传中");
			$('#operationMenuBox').attr("data-content", "您可以重新打开上传窗口查看上传进度。");
			$('#operationMenuBox').popover();
			$('#operationMenuBox').popover('show');
青阳龙野's avatar
青阳龙野 已提交
167 168 169 170 171 172
			// 2秒后消失提示框
			var closeUploadTips = setTimeout(function() {
				$('#operationMenuBox').attr("data-title", "");
				$('#operationMenuBox').attr("data-content", "");
				$('#operationMenuBox').popover('destroy');
			}, 2000);
青阳龙野's avatar
青阳龙野 已提交
173 174
		}
	});
青阳龙野's avatar
青阳龙野 已提交
175
	// 开启编辑文件夹框自动初始化状态
青阳龙野's avatar
青阳龙野 已提交
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
	$('#renameFolderModal')
			.on(
					'show.bs.modal',
					function(e) {
						$("#editfolderalert").removeClass("alert");
						$("#editfolderalert").removeClass("alert-danger");
						$("#folderrenamebox").removeClass("has-error");
						$("#editfolderalert").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
青阳龙野 已提交
198 199
	// 响应拖动上传文件
	document.ondragover = function(e) {
青阳龙野's avatar
青阳龙野 已提交
200
		if (e.preventDefault) {
青阳龙野's avatar
青阳龙野 已提交
201 202
			e.preventDefault();
			e.stopPropagation();
青阳龙野's avatar
青阳龙野 已提交
203 204 205
		} else {
			window.event.cancelBubble = true;
			window.event.returnValue = false;
青阳龙野's avatar
青阳龙野 已提交
206
		}
青阳龙野's avatar
青阳龙野 已提交
207 208
	}
	document.ondrop = function(e) {
青阳龙野's avatar
青阳龙野 已提交
209
		if (e.preventDefault) {
青阳龙野's avatar
青阳龙野 已提交
210 211
			e.preventDefault();
			e.stopPropagation();
青阳龙野's avatar
青阳龙野 已提交
212 213 214
		} else {
			window.event.cancelBubble = true;
			window.event.returnValue = false;
青阳龙野's avatar
青阳龙野 已提交
215
		}
青阳龙野's avatar
青阳龙野 已提交
216
		if (folderView.authList != null) {
青阳龙野's avatar
青阳龙野 已提交
217
			if (checkAuth(folderView.authList, "U")) {// 如果有上传权限且未进行其他上传
青阳龙野's avatar
青阳龙野 已提交
218 219 220 221
				if (isUpLoading || isImporting) {
					alert("提示:您正在执行另一项上传任务,请在上传完成后再试。");
				} else {
					if (!(window.ActiveXObject || "ActiveXObject" in window)) {// 判断是否为IE
青阳龙野's avatar
青阳龙野 已提交
222
						var dt;
青阳龙野's avatar
青阳龙野 已提交
223
						if (e.dataTransfer != null) {
青阳龙野's avatar
青阳龙野 已提交
224
							dt = e.dataTransfer; // 获取到拖入上传的文件对象
青阳龙野's avatar
青阳龙野 已提交
225
						} else {
青阳龙野's avatar
青阳龙野 已提交
226
							dt = window.event.dataTransfer;
青阳龙野's avatar
青阳龙野 已提交
227
						}
青阳龙野's avatar
青阳龙野 已提交
228 229 230
						var testFile = true;
						if (dt.items !== undefined) {
							for (var i = 0; i < dt.items.length; i++) {
青阳龙野's avatar
青阳龙野 已提交
231
								var item = dt.items[i];
青阳龙野's avatar
青阳龙野 已提交
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
								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;
									}
青阳龙野's avatar
青阳龙野 已提交
260 261 262
								}
							}
						}
青阳龙野's avatar
青阳龙野 已提交
263
						if (testFile) {
青阳龙野's avatar
青阳龙野 已提交
264 265
							fs = e.dataTransfer.files; // 获取到拖入上传的文件对象
							showUploadFileModel();
青阳龙野's avatar
青阳龙野 已提交
266
							showfilepath();
青阳龙野's avatar
青阳龙野 已提交
267
							checkUploadFile();
青阳龙野's avatar
青阳龙野 已提交
268
						} else {
青阳龙野's avatar
青阳龙野 已提交
269 270
							alert("提示:您拖入的文件中包含了一个或多个文件夹,无法进行上传。");
						}
青阳龙野's avatar
青阳龙野 已提交
271
					} else {
青阳龙野's avatar
青阳龙野 已提交
272
						alert("提示:IE浏览器不支持拖拽上传。您可以使用现代浏览器或将浏览模式切换为“极速模式”来体验该功能。");
青阳龙野's avatar
青阳龙野 已提交
273 274
					}
				}
青阳龙野's avatar
青阳龙野 已提交
275
			} else {
青阳龙野's avatar
青阳龙野 已提交
276
				alert("提示:您不具备上传权限,无法上传文件。");
青阳龙野's avatar
青阳龙野 已提交
277
			}
青阳龙野's avatar
青阳龙野 已提交
278
		} else {
青阳龙野's avatar
青阳龙野 已提交
279
			alert("提示:您不具备上传权限,无法上传文件。");
青阳龙野's avatar
青阳龙野 已提交
280 281
		}
	}
青阳龙野's avatar
青阳龙野 已提交
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 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
	// 各种快捷键绑定
	$(document).keypress(
			function(e) {
				if ($('.modal.shown').length == 0
						|| ($('.modal.shown').length == 1 && $('.modal.shown')
								.attr('id') == 'loadingModal')) {
					var keyCode = e.keyCode ? e.keyCode : e.which ? e.which
							: e.charCode;
					if (isShift(e)
							&& document.activeElement.id != "sreachKeyWordIn") {// 在按住shift的情况下……
						switch (keyCode) {
						case 65:// shift+a 全选
							checkallfile();
							break;
						case 78:// shift+n 新建文件夹
							$('#createFolderButtonLi a').click();
							break;
						case 85:// shift+u 上传文件
							$('#uploadFileButtonLi a').click();
							break;
						case 68:// shift+d 删除
							$('#deleteSeelectFileButtonLi a').click();
							break;
						case 70:// shift+f 上传文件夹
							$('#uploadFolderButtonLi a').click();
							break;
						case 67:// shift+c 复制
							if (checkedMovefiles == undefined
									|| checkedMovefiles.size == 0) {
								$('#copyFileButtonLi a').click();
							}
							break;
						case 88:// shift+x 剪切
							if (checkedMovefiles == undefined
									|| checkedMovefiles.size == 0) {
								$('#cutFileButtonLi a').click();
							}
							break;
						case 86:// shift+v 粘贴
							if (checkedMovefiles !== undefined
									&& checkedMovefiles.size > 0) {
								$('#stickFileButtonLi a').click();
							}
							break;
						default:
							return true;
						}
						return false;
青阳龙野's avatar
青阳龙野 已提交
330 331
					}
				}
青阳龙野's avatar
青阳龙野 已提交
332
			});
青阳龙野's avatar
青阳龙野 已提交
333 334
	// 关闭移动提示框自动取消移动
	$('#moveFilesModal').on('hidden.bs.modal', function(e) {
青阳龙野's avatar
青阳龙野 已提交
335 336 337 338 339 340 341 342
		checkedMovefiles = undefined;
		$("#copyFileButtonLi").removeClass("hidden");
		$("#copyFileButtonLi").addClass("show");
		$("#cutFileButtonLi").removeClass("hidden");
		$("#cutFileButtonLi").addClass("show");
		$("#stickFileButtonLi").removeClass("show");
		$("#stickFileButtonLi").addClass("hidden");
		$("#stickFilesCount").text("");
青阳龙野's avatar
青阳龙野 已提交
343 344 345
		$('#moveFilesBox').html("");
	});
	// IE内核浏览器内的startsWith方法的自实现
青阳龙野's avatar
青阳龙野 已提交
346
	if (typeof String.prototype.startsWith != 'function') {
青阳龙野's avatar
青阳龙野 已提交
347 348 349 350
		String.prototype.startsWith = function(prefix) {
			return this.slice(0, prefix.length) === prefix;
		};
	}
青阳龙野's avatar
青阳龙野 已提交
351
	if (typeof String.prototype.endsWith != 'function') {
青阳龙野's avatar
青阳龙野 已提交
352 353 354 355
		String.prototype.endsWith = function(suffix) {
			return this.indexOf(suffix, this.length - suffix.length) !== -1;
		};
	}
青阳龙野's avatar
青阳龙野 已提交
356 357 358 359
	// 关闭下载提示模态框自动隐藏下载链接
	$('#downloadModal').on('hidden.bs.modal', function(e) {
		$('#downloadURLCollapse').collapse('hide');
	});
青阳龙野's avatar
青阳龙野 已提交
360
	// 获取窗口高度
青阳龙野's avatar
青阳龙野 已提交
361
	updateWinHeight();
青阳龙野's avatar
青阳龙野 已提交
362
	// 根据屏幕下拉程度自动显示、隐藏“返回顶部”按钮
青阳龙野's avatar
青阳龙野 已提交
363 364
	$(window).scroll(function() {
		if ($(this).scrollTop() > 2 * winHeight) {
青阳龙野's avatar
青阳龙野 已提交
365
			$('#gobacktotopbox').removeClass("hidden");
青阳龙野's avatar
青阳龙野 已提交
366
		} else {
青阳龙野's avatar
青阳龙野 已提交
367 368 369
			$('#gobacktotopbox').addClass("hidden");
		}
	});
青阳龙野's avatar
青阳龙野 已提交
370

青阳龙野's avatar
青阳龙野 已提交
371
	// 打开查看下载链接时,向后台生成/获取下载链接
青阳龙野's avatar
青阳龙野 已提交
372
	$('#downloadURLCollapse').on('shown.bs.collapse', function() {
青阳龙野's avatar
青阳龙野 已提交
373 374
		getDownloadURL();
	});
青阳龙野's avatar
青阳龙野 已提交
375

青阳龙野's avatar
青阳龙野 已提交
376
	// 开启修改密码模态框时初始化状态
青阳龙野's avatar
青阳龙野 已提交
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
	$('#changePasswordModal')
			.on(
					'show.bs.modal',
					function(e) {
						if (!isChangingPassword) {
							$(
									"#changepassword_oldpwd,#changepassword_newpwd,#changepassword_reqnewpwd,#changePasswordButton,#changepassword_vercode")
									.attr('disabled', false);
							$(
									"#changepassword_oldepwdbox,#changepassword_newpwdbox,#changepassword_reqnewpwdbox")
									.removeClass("has-error");
							$(
									"#changepassword_oldpwd,#changepassword_newpwd,#changepassword_reqnewpwd")
									.val("");
							$(
									"#changepasswordalertbox,#changepassword_vccodebox")
									.hide();
						}
					});
青阳龙野's avatar
青阳龙野 已提交
396 397
	// 并自动聚焦旧密码输入框
	$('#changePasswordModal').on('shown.bs.modal', function(e) {
青阳龙野's avatar
青阳龙野 已提交
398
		if (!isChangingPassword) {
青阳龙野's avatar
青阳龙野 已提交
399 400 401
			$("#changepassword_oldpwd").focus();
		}
	});
青阳龙野's avatar
青阳龙野 已提交
402
	// 开启公告信息模态框前自动判断是否已经勾选“30天不再显示”
青阳龙野's avatar
青阳龙野 已提交
403 404 405 406 407 408 409 410 411 412 413
	$('#noticeModal').on(
			'show.bs.modal',
			function(e) {
				var cookieMd530 = document.cookie.match(new RegExp(
						"(^| )notice_md5_30=([^;]*)(;|$)"));
				if (cookieMd530) {
					$("#dontShowSomeNoticeAt30Day").attr("checked", "checked");
				} else {
					$("#dontShowSomeNoticeAt30Day").attr("checked", false);
				}
			});
青阳龙野's avatar
青阳龙野 已提交
414
	// 关闭公告信息模态框后根据是否已经勾选“30天不再显示”设置cookie
青阳龙野's avatar
青阳龙野 已提交
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
	$('#noticeModal').on(
			'hidden.bs.modal',
			function(e) {
				var noticed = new Date();
				if ($("#dontShowSomeNoticeAt30Day").prop("checked")) {
					noticed.setTime(noticed.getTime()
							+ (30 * 24 * 60 * 60 * 1000));
					var cookieMd5 = document.cookie.match(new RegExp(
							"(^| )notice_md5=([^;]*)(;|$)"));
					if (cookieMd5) {
						document.cookie = "notice_md5_30="
								+ escape(unescape(cookieMd5[2])) + ";expires="
								+ noticed.toUTCString();
					} else {
						cookieMd5 = document.cookie.match(new RegExp(
								"(^| )notice_md5_30=([^;]*)(;|$)"));
						if (cookieMd5) {
							document.cookie = "notice_md5_30="
									+ escape(unescape(cookieMd5[2]))
									+ ";expires=" + noticed.toUTCString();
						}
					}
				} else {
					noticed.setTime(0);
					var cookieMd530 = document.cookie.match(new RegExp(
							"(^| )notice_md5_30=([^;]*)(;|$)"));
					if (cookieMd530) {
						document.cookie = "notice_md5_30=0;expires="
								+ noticed.toUTCString();
					}
青阳龙野's avatar
青阳龙野 已提交
445
				}
青阳龙野's avatar
青阳龙野 已提交
446
			});
高源 已提交
447 448
});

青阳龙野's avatar
青阳龙野 已提交
449
// 更新页面高度
青阳龙野's avatar
青阳龙野 已提交
450 451
function updateWinHeight() {
	if (window.innerHeight) {
青阳龙野's avatar
青阳龙野 已提交
452
		winHeight = window.innerHeight;
青阳龙野's avatar
青阳龙野 已提交
453
	} else if ((document.body) && (document.body.clientHeight)) {
青阳龙野's avatar
青阳龙野 已提交
454 455 456 457
		winHeight = document.body.clientHeight;
	}
}

青阳龙野's avatar
青阳龙野 已提交
458
// 根据屏幕大小增删表格显示内容
青阳龙野's avatar
青阳龙野 已提交
459
function changeFilesTableStyle() {
青阳龙野's avatar
青阳龙野 已提交
460
	var win = $(window).width();
青阳龙野's avatar
青阳龙野 已提交
461 462 463 464 465 466 467 468 469 470 471
	if (win < 768) {
		$('#filetableheadera').addClass('filetableheaderstyle');
		$('#filetableheadera').attr('data-toggle', 'collapse');
		$('#filetableheadera').attr('data-target', '#filetableoptmenu');
		$('#mdropdownicon').html('(点击展开/折叠菜单)');
	} else {
		$('#filetableheadera').removeClass('filetableheaderstyle');
		$('#filetableheadera').attr('data-toggle', 'modal');
		$('#filetableheadera').attr('data-target', '#folderInfoModal');
		$('#mdropdownicon').html('');
	}
青阳龙野's avatar
青阳龙野 已提交
472 473
}

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

高源 已提交
479 480 481 482 483
// 获取服务器操作系统
function getServerOS() {
	$.ajax({
		type : "POST",
		dataType : "text",
青阳龙野's avatar
青阳龙野 已提交
484
		data : {},
高源 已提交
485 486
		url : "homeController/getServerOS.ajax",
		success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
487
			if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
488 489
				window.location.href = "prv/login.html";
				return;
青阳龙野's avatar
青阳龙野 已提交
490
			}
高源 已提交
491 492 493 494 495 496 497 498 499
			$("#serverOS").text(result);
		},
		error : function() {
			$("#serverOS").html("<a onclick='getServerOS()'>获取失败,点击重试</a>");
		}
	});
}

// 获取实时文件夹视图
青阳龙野's avatar
青阳龙野 已提交
500
function showFolderView(fid, targetId) {
青阳龙野's avatar
青阳龙野 已提交
501
	// 判断是否正在进行另一个相同的请求,如果是则取消本次操作
青阳龙野's avatar
青阳龙野 已提交
502
	if (loadingFolderView) {
青阳龙野's avatar
青阳龙野 已提交
503 504
		return;
	}
青阳龙野's avatar
青阳龙野 已提交
505
	startLoading();
青阳龙野's avatar
青阳龙野 已提交
506
	if (remainingLoadingRequest) {
青阳龙野's avatar
青阳龙野 已提交
507 508
		remainingLoadingRequest.abort();
	}
高源 已提交
509 510 511 512 513 514 515 516
	$.ajax({
		type : 'POST',
		dataType : 'text',
		data : {
			fid : fid
		},
		url : 'homeController/getFolderView.ajax',
		success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
517
			endLoading();
青阳龙野's avatar
青阳龙野 已提交
518 519 520
			switch (result) {
			case "ERROR":
				// 获取错误直接弹出提示框并将相关内容填为提示信息
青阳龙野's avatar
青阳龙野 已提交
521 522
				doAlert();
				$("#tb").html("<span class='graytext'>获取失败,请尝试刷新</span>");
青阳龙野's avatar
青阳龙野 已提交
523 524 525 526
				$("#publishTime").html(
						"<span class='graytext'>获取失败,请尝试刷新</span>");
				$("#parentlistbox").html(
						"<span class='graytext'>获取失败,请尝试刷新</span>");
青阳龙野's avatar
青阳龙野 已提交
527 528 529 530 531 532 533
				break;
			case "NOT_FOUND":
			case "notAccess":
				// 对于各种不能访问的情况,要先将记忆路径重置再跳转至根路径下
				document.cookie = "folder_id=" + escape("root");
			case "mustLogin":
				// 如果服务器说必须登录,那么也跳转至根路径下(从而进入登录页面)
青阳龙野's avatar
青阳龙野 已提交
534
				window.location.href = "/";
青阳龙野's avatar
青阳龙野 已提交
535 536 537
				break;
			default:
				// 上述情况都不是,则返回的应该是文件夹视图数据,接下来对其进行解析
青阳龙野's avatar
青阳龙野 已提交
538
				folderView = eval("(" + result + ")");
青阳龙野's avatar
青阳龙野 已提交
539
				// 记录当前获取的文件夹视图的ID号,便于其他操作使用
青阳龙野's avatar
青阳龙野 已提交
540
				locationpath = folderView.folder.folderId;
青阳龙野's avatar
青阳龙野 已提交
541 542
				// 存储打开的文件夹路径至Cookie中,以便下次打开时直接显示
				document.cookie = "folder_id=" + escape(locationpath);
青阳龙野's avatar
青阳龙野 已提交
543
				// 记录上级目录ID,方便返回上一级
青阳龙野's avatar
青阳龙野 已提交
544
				parentpath = folderView.folder.folderParent;
青阳龙野's avatar
青阳龙野 已提交
545
				// 记录本文件夹的访问级别,便于在新建文件夹时判断应该从哪一个级别开始供用户选择
青阳龙野's avatar
青阳龙野 已提交
546 547
				constraintLevel = folderView.folder.folderConstraint;
				screenedFoldrView = null;
青阳龙野's avatar
青阳龙野 已提交
548
				// 备份一份原始的文件夹视图数据,同时也记录下原始的查询偏移量
青阳龙野's avatar
青阳龙野 已提交
549
				originFolderView = $.extend(true, {}, folderView);
青阳龙野's avatar
青阳龙野 已提交
550 551 552
				totalFoldersOffset = folderView.foldersOffset;
				totalFilesOffset = folderView.filesOffset;
				// 搜索输入框重置
青阳龙野's avatar
青阳龙野 已提交
553
				$("#sreachKeyWordIn").val("");
青阳龙野's avatar
青阳龙野 已提交
554
				// 各项基于文件夹视图返回数据的解析操作……
青阳龙野's avatar
青阳龙野 已提交
555 556 557
				showParentList(folderView);
				showAccountView(folderView);
				showPublishTime(folderView);
青阳龙野's avatar
青阳龙野 已提交
558 559 560 561
				$("#sortByFN").removeClass();
				$("#sortByCD").removeClass();
				$("#sortByFS").removeClass();
				$("#sortByCN").removeClass();
青阳龙野's avatar
青阳龙野 已提交
562
				$("#sortByOR").removeClass();
青阳龙野's avatar
青阳龙野 已提交
563
				showFolderTable(folderView);
青阳龙野's avatar
青阳龙野 已提交
564 565 566
				// 更新文件夹信息至信息模态框
				$("#fim_name").text(folderView.folder.folderName);
				$("#fim_creator").text(folderView.folder.folderCreator);
青阳龙野's avatar
青阳龙野 已提交
567 568
				$("#fim_folderCreationDate").text(
						folderView.folder.folderCreationDate);
青阳龙野's avatar
青阳龙野 已提交
569 570 571
				$("#fim_folderId").text(folderView.folder.folderId);
				updateTheFolderInfo();
				// 判断是否还需要加载后续数据
青阳龙野's avatar
青阳龙野 已提交
572 573
				if (folderView.foldersOffset > folderView.selectStep
						|| folderView.filesOffset > folderView.selectStep) {
青阳龙野's avatar
青阳龙野 已提交
574 575 576
					// 如果文件夹偏移量或文件偏移量大于查询步进长度,则说明一定还有后续数据需要加载,那么继续加载后续数据
					showLoadingRemaininngBox();
					loadingRemainingFolderView(targetId);
青阳龙野's avatar
青阳龙野 已提交
577
				} else {
青阳龙野's avatar
青阳龙野 已提交
578 579 580
					// 否则,说明文件夹视图加载完成,进行定位工作即可
					hiddenLoadingRemaininngBox();
					doFixedRow(targetId);
青阳龙野's avatar
青阳龙野 已提交
581
				}
青阳龙野's avatar
青阳龙野 已提交
582
				break;
青阳龙野's avatar
青阳龙野 已提交
583
			}
高源 已提交
584
		},
青阳龙野's avatar
青阳龙野 已提交
585
		error : function(XMLHttpRequest, textStatus, errorThrown) {
青阳龙野's avatar
青阳龙野 已提交
586 587
			endLoading();
			doAlert();
高源 已提交
588 589
			$("#tb").html("<span class='graytext'>获取失败,请尝试刷新</span>");
			$("#publishTime").html("<span class='graytext'>获取失败,请尝试刷新</span>");
青阳龙野's avatar
青阳龙野 已提交
590 591
			$("#parentlistbox")
					.html("<span class='graytext'>获取失败,请尝试刷新</span>");
高源 已提交
592 593 594 595
		}
	});
}

青阳龙野's avatar
青阳龙野 已提交
596
// 开始文件视图加载动画
青阳龙野's avatar
青阳龙野 已提交
597
function startLoading() {
青阳龙野's avatar
青阳龙野 已提交
598
	loadingFolderView = true;
青阳龙野's avatar
青阳龙野 已提交
599 600 601 602
	$('#loadingModal').modal({
		backdrop : 'static',
		keyboard : false
	});
青阳龙野's avatar
青阳龙野 已提交
603
	$('#loadingModal').modal('show');
青阳龙野's avatar
青阳龙野 已提交
604
	$('#loadingModal').addClass("shown");
青阳龙野's avatar
青阳龙野 已提交
605 606
}

青阳龙野's avatar
青阳龙野 已提交
607
// 结束文件视图加载动画
青阳龙野's avatar
青阳龙野 已提交
608
function endLoading() {
青阳龙野's avatar
青阳龙野 已提交
609
	loadingFolderView = false;
青阳龙野's avatar
青阳龙野 已提交
610
	$('#loadingModal').modal('hide');
青阳龙野's avatar
青阳龙野 已提交
611
	$('#loadingModal').removeClass("shown");
青阳龙野's avatar
青阳龙野 已提交
612 613
}

青阳龙野's avatar
青阳龙野 已提交
614
// 开始登陆加载动画
青阳龙野's avatar
青阳龙野 已提交
615 616 617 618 619
function startLogin() {
	$("#accountid").attr('disabled', 'disabled');
	$("#accountpwd").attr('disabled', 'disabled');
	$("#dologinButton").attr('disabled', 'disabled');
	$("#vercode").attr('disabled', 'disabled');
青阳龙野's avatar
青阳龙野 已提交
620 621
}

青阳龙野's avatar
青阳龙野 已提交
622
// 结束登陆加载动画
青阳龙野's avatar
青阳龙野 已提交
623
function finishLogin() {
青阳龙野's avatar
青阳龙野 已提交
624 625 626 627
	$("#accountid").removeAttr('disabled');
	$("#accountpwd").removeAttr('disabled');
	$("#dologinButton").removeAttr('disabled');
	$("#vercode").removeAttr('disabled');
青阳龙野's avatar
青阳龙野 已提交
628 629
}

高源 已提交
630 631
// 登录操作
function dologin() {
青阳龙野's avatar
青阳龙野 已提交
632 633
	var accountId = $("#accountid").val();
	var accountPwd = $("#accountpwd").val();
高源 已提交
634
	var check = "y";
青阳龙野's avatar
青阳龙野 已提交
635
	if (accountId.length == 0) {
高源 已提交
636
		$("#accountidbox").addClass("has-error");
青阳龙野's avatar
青阳龙野 已提交
637
		check = "n";
高源 已提交
638 639 640
	} else {
		$("#accountidbox").removeClass("has-error");
	}
青阳龙野's avatar
青阳龙野 已提交
641
	if (accountPwd.length == 0) {
高源 已提交
642
		$("#accountpwdbox").addClass("has-error");
青阳龙野's avatar
青阳龙野 已提交
643
		check = "n";
高源 已提交
644 645 646 647
	} else {
		$("#accountpwdbox").removeClass("has-error");
	}
	if (check == "y") {
青阳龙野's avatar
青阳龙野 已提交
648
		startLogin();
青阳龙野's avatar
青阳龙野 已提交
649
		// 加密认证-获取公钥并将请求加密发送给服务器,避免中途被窃取
高源 已提交
650
		$.ajax({
青阳龙野's avatar
青阳龙野 已提交
651 652 653 654
			url : 'homeController/getPublicKey.ajax',
			type : 'POST',
			data : {},
			dataType : 'text',
高源 已提交
655
			success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
656
				var publicKeyInfo = eval("(" + result + ")");
青阳龙野's avatar
青阳龙野 已提交
657 658 659 660 661 662 663
				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);
高源 已提交
664 665
			},
			error : function() {
青阳龙野's avatar
青阳龙野 已提交
666
				finishLogin();
高源 已提交
667 668 669 670 671 672 673 674
				$("#alertbox").addClass("alert");
				$("#alertbox").addClass("alert-danger");
				$("#alertbox").text("提示:登录请求失败,请检查网络或服务器运行状态");
			}
		});
	}
}

青阳龙野's avatar
青阳龙野 已提交
675 676
// 发送加密文本
function sendLoginInfo(encrypted) {
青阳龙野's avatar
青阳龙野 已提交
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 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
	$
			.ajax({
				type : "POST",
				dataType : "text",
				url : "homeController/doLogin.ajax",
				data : {
					encrypted : encrypted,
					vercode : $("#vercode").val()
				},
				success : function(result) {
					finishLogin();
					$("#alertbox").removeClass("alert");
					$("#alertbox").removeClass("alert-danger");
					$("#alertbox").text("");
					$("#vercodebox").html("");
					$("#vercodebox").removeClass("show");
					$("#vercodebox").addClass("hidden");
					switch (result) {
					case "permitlogin":
						$("#accountidbox").removeClass("has-error");
						$("#accountpwdbox").removeClass("has-error");
						$('#loginModal').modal('hide');
						showFolderView(locationpath);
						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 "needsubmitvercode":
						$("#vercodebox")
								.html(
										"<label id='vercodetitle' class='col-sm-7'><img id='showvercode' class='vercodeimg' alt='点击获取验证码' src='homeController/getNewVerCode.do?s="
												+ (new Date()).getTime()
												+ "' onclick='getNewVerCode()'></label><div class='col-sm-5'><input type='text' class='form-control' id='vercode' placeholder='验证码……'></div>");
						$("#vercodebox").removeClass("hidden");
						$("#vercodebox").addClass("show");
						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() {
					finishLogin();
					$("#alertbox").addClass("alert");
					$("#alertbox").addClass("alert-danger");
					$("#alertbox").text("提示:登录请求失败,请检查网络或服务器运行状态");
				}
			});
青阳龙野's avatar
青阳龙野 已提交
744 745
}

青阳龙野's avatar
青阳龙野 已提交
746
// 获取一个新的验证码
青阳龙野's avatar
青阳龙野 已提交
747 748 749
function getNewVerCode() {
	$("#showvercode").attr("src",
			"homeController/getNewVerCode.do?s=" + (new Date()).getTime());
青阳龙野's avatar
青阳龙野 已提交
750 751
}

高源 已提交
752 753 754
// 注销操作
function dologout() {
	$('#logoutModal').modal('hide');
青阳龙野's avatar
青阳龙野 已提交
755
	$.ajax({
青阳龙野's avatar
青阳龙野 已提交
756 757 758 759 760 761
		url : 'homeController/doLogout.ajax',
		type : 'POST',
		data : {},
		dataType : 'text',
		success : function(result) {
			if (result == "SUCCESS") {
青阳龙野's avatar
青阳龙野 已提交
762 763 764
				showFolderView(locationpath);
			}
		},
青阳龙野's avatar
青阳龙野 已提交
765
		error : function() {
青阳龙野's avatar
青阳龙野 已提交
766 767 768
			doAlert();
		}
	});
高源 已提交
769 770 771 772
}

// 显示当前文件夹的父级路径
function showParentList(folderView) {
青阳龙野's avatar
青阳龙野 已提交
773
	$("#parentFolderList").html("");
高源 已提交
774
	var f = folderView.folder;
青阳龙野's avatar
青阳龙野 已提交
775
	if (folderView.parentList.length > 0) {
青阳龙野's avatar
青阳龙野 已提交
776
		$.each(folderView.parentList, function(n, val) {
青阳龙野's avatar
青阳龙野 已提交
777 778 779 780
			$("#parentFolderList").append(
					"<li><a href='javascript:void(0);' onclick='entryFolder("
							+ '"' + val.folderId + '"' + ")'>" + val.folderName
							+ "</a></li>");
青阳龙野's avatar
青阳龙野 已提交
781
		});
青阳龙野's avatar
青阳龙野 已提交
782
	} else {
青阳龙野's avatar
青阳龙野 已提交
783 784
		$("#parentFolderList").html("<li class='disabled'><a>无</a></li>");
	}
青阳龙野's avatar
青阳龙野 已提交
785 786 787
	if (f.folderName.length > 6) {
		$("#currentFolderName").text(f.folderName.substr(0, 6) + "...");
	} else {
青阳龙野's avatar
青阳龙野 已提交
788 789
		$("#currentFolderName").text(f.folderName);
	}
青阳龙野's avatar
青阳龙野 已提交
790
	if (f.folderName == "ROOT") {
青阳龙野's avatar
青阳龙野 已提交
791
		$("#folderIconSpan").removeClass("glyphicon-folder-close");
青阳龙野's avatar
青阳龙野 已提交
792
		$("#folderIconSpan").removeClass("glyphicon-search");
青阳龙野's avatar
青阳龙野 已提交
793
		$("#folderIconSpan").addClass("glyphicon-home");
青阳龙野's avatar
青阳龙野 已提交
794
	} else if (folderView.keyWorld != null) {
青阳龙野's avatar
青阳龙野 已提交
795 796 797
		$("#folderIconSpan").removeClass("glyphicon-folder-close");
		$("#folderIconSpan").removeClass("glyphicon-home");
		$("#folderIconSpan").addClass("glyphicon-search");
青阳龙野's avatar
青阳龙野 已提交
798
	} else {
青阳龙野's avatar
青阳龙野 已提交
799
		$("#folderIconSpan").removeClass("glyphicon-home");
青阳龙野's avatar
青阳龙野 已提交
800
		$("#folderIconSpan").removeClass("glyphicon-search");
青阳龙野's avatar
青阳龙野 已提交
801
		$("#folderIconSpan").addClass("glyphicon-folder-close");
高源 已提交
802 803 804 805 806
	}
}

// 显示用户视图,包括文件列表、登录信息、操作权限接口等
function showAccountView(folderView) {
青阳龙野's avatar
青阳龙野 已提交
807
	$("#tb,#tb2").html("");
青阳龙野's avatar
青阳龙野 已提交
808
	account = folderView.account;
高源 已提交
809
	if (folderView.account != null) {
青阳龙野's avatar
青阳龙野 已提交
810
		// 说明已经登录,显示注销按钮
高源 已提交
811 812
		$("#tb")
				.append(
青阳龙野's avatar
青阳龙野 已提交
813
						"<button class='btn btn-link rightbtn hidden-xs' data-toggle='modal' data-target='#logoutModal'>注销 ["
高源 已提交
814 815
								+ folderView.account
								+ "] <span class='glyphicon glyphicon-off' aria-hidden='true'></span></button>");
青阳龙野's avatar
青阳龙野 已提交
816 817 818 819 820
		$("#tb2")
				.append(
						"<button class='btn btn-link' data-toggle='modal' data-target='#logoutModal'>注销 ["
								+ folderView.account
								+ "] <span class='glyphicon glyphicon-off' aria-hidden='true'></span></button>");
青阳龙野's avatar
青阳龙野 已提交
821
		if (folderView.allowChangePassword == 'true') {
青阳龙野's avatar
青阳龙野 已提交
822
			$("#tb")
青阳龙野's avatar
青阳龙野 已提交
823 824
					.append(
							" <button class='btn btn-link rightbtn hidden-xs' data-toggle='modal' data-target='#changePasswordModal'>修改密码 <span class='glyphicon glyphicon-edit' aria-hidden='true'></span></button>");
青阳龙野's avatar
青阳龙野 已提交
825
			$("#tb2")
青阳龙野's avatar
青阳龙野 已提交
826 827
					.append(
							" <button class='btn btn-link' data-toggle='modal' data-target='#changePasswordModal'>修改密码 <span class='glyphicon glyphicon-edit' aria-hidden='true'></span></button>");
青阳龙野's avatar
青阳龙野 已提交
828
		}
高源 已提交
829 830 831 832
	} else {
		// 说明用户未登录,显示登录按钮
		$("#tb")
				.append(
青阳龙野's avatar
青阳龙野 已提交
833
						"<button class='btn btn-link rightbtn hidden-xs' data-toggle='modal' data-target='#loginModal'>登入 <span class='glyphicon glyphicon-user' aria-hidden='true'></span></button>");
青阳龙野's avatar
青阳龙野 已提交
834 835 836
		$("#tb2")
				.append(
						"<button class='btn btn-link' data-toggle='modal' data-target='#loginModal'>登入 <span class='glyphicon glyphicon-user' aria-hidden='true'></span></button>");
青阳龙野's avatar
青阳龙野 已提交
837
		if (folderView.allowSignUp == 'true') {
青阳龙野's avatar
青阳龙野 已提交
838
			$("#tb")
青阳龙野's avatar
青阳龙野 已提交
839 840
					.append(
							" <button class='btn btn-link rightbtn hidden-xs' onclick='window.location.href = \"/prv/signup.html\"'>立即注册 <span class='glyphicon glyphicon-log-in' aria-hidden='true'></span></button>");
青阳龙野's avatar
青阳龙野 已提交
841
			$("#tb2")
青阳龙野's avatar
青阳龙野 已提交
842 843
					.append(
							" <button class='btn btn-link' onclick='window.location.href = \"prv/signup.html\"'>立即注册 <span class='glyphicon glyphicon-log-in' aria-hidden='true'></span></button>");
青阳龙野's avatar
青阳龙野 已提交
844
		}
高源 已提交
845 846
	}
	var authList = folderView.authList;
青阳龙野's avatar
青阳龙野 已提交
847 848
	// 对操作菜单进行初始化,根据权限显示可操作的按钮(并非约束)。
	$("#fileListDropDown li").addClass("disabled");
青阳龙野's avatar
青阳龙野 已提交
849
	$("#fileListDropDown li a").attr("onclick", "");
高源 已提交
850 851
	if (authList != null) {
		if (checkAuth(authList, "C")) {
青阳龙野's avatar
青阳龙野 已提交
852
			$("#createFolderButtonLi").removeClass("disabled");
青阳龙野's avatar
青阳龙野 已提交
853 854
			$("#createFolderButtonLi a")
					.attr("onclick", "showNewFolderModel()");
高源 已提交
855 856
		}
		if (checkAuth(authList, "U")) {
青阳龙野's avatar
青阳龙野 已提交
857
			$("#uploadFileButtonLi").removeClass("disabled");
青阳龙野's avatar
青阳龙野 已提交
858 859
			$("#uploadFileButtonLi a").attr("onclick", "showUploadFileModel()");
			if (checkAuth(authList, "C") && isSupportWebkitdirectory()) {// 若浏览器支持文件夹选择,且具备新建文件夹权限,则允许进行文件夹上传
青阳龙野's avatar
青阳龙野 已提交
860
				$("#uploadFolderButtonLi").removeClass("disabled");
青阳龙野's avatar
青阳龙野 已提交
861 862
				$("#uploadFolderButtonLi a").attr("onclick",
						"showUploadFolderModel()");
青阳龙野's avatar
青阳龙野 已提交
863
			}
高源 已提交
864
		}
青阳龙野's avatar
青阳龙野 已提交
865
		if (folderView.enableDownloadZip && checkAuth(authList, "L")) {
青阳龙野's avatar
青阳龙野 已提交
866 867 868
			$("#packageDownloadBox")
					.html(
							"<button class='btn btn-link navbar-btn' onclick='showDownloadAllCheckedModel()'><span class='glyphicon glyphicon-briefcase'></span> 打包下载</button>");
青阳龙野's avatar
青阳龙野 已提交
869
		} else {
青阳龙野's avatar
青阳龙野 已提交
870
			$("#packageDownloadBox").html("");
青阳龙野's avatar
青阳龙野 已提交
871 872
		}
		if (checkAuth(authList, "D")) {
青阳龙野's avatar
青阳龙野 已提交
873
			$("#deleteSeelectFileButtonLi").removeClass("disabled");
青阳龙野's avatar
青阳龙野 已提交
874 875
			$("#deleteSeelectFileButtonLi a").attr("onclick",
					"showDeleteAllCheckedModel()");
青阳龙野's avatar
青阳龙野 已提交
876
		}
青阳龙野's avatar
青阳龙野 已提交
877
		if (checkAuth(authList, "M")) {
青阳龙野's avatar
青阳龙野 已提交
878
			$("#cutFileButtonLi").removeClass("disabled");
青阳龙野's avatar
青阳龙野 已提交
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904
			$("#stickFileButtonLi").removeClass("disabled");
			$("#copyFileButtonLi").removeClass("disabled");
			$("#cutFileButtonLi a").attr("onclick", "cutFile()");
			$("#copyFileButtonLi a").attr("onclick", "copyFile()");
			$("#stickFileButtonLi a").attr("onclick", "stickFile()");
			if (checkedMovefiles !== undefined && checkedMovefiles.size > 0) {
				if (checkedMovefiles.size < 100) {
					$("#stickFilesCount").text(
							"" + checkedMovefiles.size + "");
				} else {
					$("#stickFilesCount").text("(99+)");
				}
				$("#copyFileButtonLi").removeClass("show");
				$("#copyFileButtonLi").addClass("hidden");
				$("#cutFileButtonLi").removeClass("show");
				$("#cutFileButtonLi").addClass("hidden");
				$("#stickFileButtonLi").removeClass("hidden");
				$("#stickFileButtonLi").addClass("show");
			} else {
				$("#copyFileButtonLi").removeClass("hidden");
				$("#copyFileButtonLi").addClass("show");
				$("#cutFileButtonLi").removeClass("hidden");
				$("#cutFileButtonLi").addClass("show");
				$("#stickFileButtonLi").removeClass("show");
				$("#stickFileButtonLi").addClass("hidden");
				$("#stickFilesCount").text("");
青阳龙野's avatar
青阳龙野 已提交
905 906
			}
		}
高源 已提交
907 908 909 910 911 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
	}
}

// 检查权限列表
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');
	}
青阳龙野's avatar
青阳龙野 已提交
940
	subscribeNotice();// 刷新时也判断是否有新公告需要显示
高源 已提交
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
}

// 返回上一级文件夹
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
青阳龙野 已提交
958
						"<tr onclick='returnPF()'><td><button onclick='' class='btn btn-link btn-xs'>../</button></td><td class='hidden-xs'>--</td><td>--</td><td class='hidden-xs'>--</td><td>--</td></tr>");
高源 已提交
959 960 961 962 963
	}
	var authList = folderView.authList;
	var aD = false;
	var aR = false;
	var aL = false;
青阳龙野's avatar
青阳龙野 已提交
964
	var aO = false;
高源 已提交
965 966 967 968 969 970 971 972 973
	if (checkAuth(authList, "D")) {
		aD = true;
	}
	if (checkAuth(authList, "R")) {
		aR = true;
	}
	if (checkAuth(authList, "L")) {
		aL = true;
	}
青阳龙野's avatar
青阳龙野 已提交
974
	if (checkAuth(authList, "O")) {
青阳龙野's avatar
青阳龙野 已提交
975 976
		aO = true;
	}
青阳龙野's avatar
青阳龙野 已提交
977
	// 遍历并倒序显示文件夹列表
青阳龙野's avatar
青阳龙野 已提交
978 979 980
	for (var i1 = folderView.folderList.length; i1 > 0; i1--) {
		var f = folderView.folderList[i1 - 1];
		$("#foldertable").append(createNewFolderRow(f, aD, aR, aO));
青阳龙野's avatar
青阳龙野 已提交
981 982
	}
	// 遍历并倒序显示文件列表
青阳龙野's avatar
青阳龙野 已提交
983 984 985
	for (var i2 = folderView.fileList.length; i2 > 0; i2--) {
		var fi = folderView.fileList[i2 - 1];
		$("#foldertable").append(createFileRow(fi, aL, aD, aR, aO));
青阳龙野's avatar
青阳龙野 已提交
986 987 988 989
	}
}

// 根据一个文件对象生成对应的文件行的HTML内容
青阳龙野's avatar
青阳龙野 已提交
990 991 992
function createFileRow(fi, aL, aD, aR, aO) {
	fi.fileName = fi.fileName.replace(/\'/g, '&#39;').replace(/</g, '&lt;')
			.replace(/>/g, '&gt;');
青阳龙野's avatar
青阳龙野 已提交
993
	var fileRow = "<tr id=" + fi.fileId + " onclick='checkfile(event," + '"'
青阳龙野's avatar
青阳龙野 已提交
994 995
			+ fi.fileId + '"' + ")' ondblclick='checkConsFile(event," + '"'
			+ fi.fileId + '"' + ")' id='" + fi.fileId
青阳龙野's avatar
青阳龙野 已提交
996 997
			+ "' class='filerow'><td>" + fi.fileName
			+ "</td><td class='hidden-xs'>" + fi.fileCreationDate + "</td>";
青阳龙野's avatar
青阳龙野 已提交
998 999 1000 1001
	if (fi.fileSize == "0") {
		fileRow = fileRow + "<td>&lt;1MB</td>";
	} else {
		fileRow = fileRow + "<td>" + fi.fileSize + "MB</td>";
青阳龙野's avatar
青阳龙野 已提交
1002
	}
青阳龙野's avatar
青阳龙野 已提交
1003
	fileRow = fileRow + "<td class='hidden-xs'>" + fi.fileCreator + "</td><td>";
青阳龙野's avatar
青阳龙野 已提交
1004 1005 1006 1007 1008 1009
	if (aL) {
		fileRow = fileRow
				+ "<button onclick='showDownloadModel("
				+ '"'
				+ fi.fileId
				+ '","'
青阳龙野's avatar
青阳龙野 已提交
1010
				+ replaceAllQuotationMarks(fi.fileName)
青阳龙野's avatar
青阳龙野 已提交
1011 1012 1013
				+ '"'
				+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-cloud-download'></span> 下载</button>";
		// 对于各种特殊格式文件提供的预览和播放功能
青阳龙野's avatar
青阳龙野 已提交
1014
		var suffix = getSuffix(fi.fileName);
青阳龙野's avatar
青阳龙野 已提交
1015 1016
		switch (suffix) {
		case "mp4":
青阳龙野's avatar
青阳龙野 已提交
1017
			fileRow = fileRow
青阳龙野's avatar
青阳龙野 已提交
1018 1019 1020 1021 1022
					+ "<button onclick='playVideo("
					+ '"'
					+ fi.fileId
					+ '"'
					+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-play'></span> 播放</button>";
青阳龙野's avatar
青阳龙野 已提交
1023 1024 1025 1026 1027 1028 1029
			break;
		case "webm":
		case "mov":
		case "avi":
		case "wmv":
		case "mkv":
		case "flv":
青阳龙野's avatar
青阳龙野 已提交
1030
			if (folderView.enableFFMPEG) {
青阳龙野's avatar
青阳龙野 已提交
1031
				fileRow = fileRow
青阳龙野's avatar
青阳龙野 已提交
1032 1033 1034 1035 1036
						+ "<button onclick='playVideo("
						+ '"'
						+ fi.fileId
						+ '"'
						+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-play'></span> 播放</button>";
青阳龙野's avatar
青阳龙野 已提交
1037 1038 1039 1040
			}
			break;
		case "pdf":
			fileRow = fileRow
青阳龙野's avatar
青阳龙野 已提交
1041 1042 1043 1044 1045
					+ "<button onclick='pdfView("
					+ '"'
					+ fi.fileId
					+ '"'
					+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-eye-open'></span> 预览</button>";
青阳龙野's avatar
青阳龙野 已提交
1046 1047 1048 1049 1050 1051 1052
			break;
		case "jpg":
		case "jpeg":
		case "gif":
		case "png":
		case "bmp":
			fileRow = fileRow
青阳龙野's avatar
青阳龙野 已提交
1053 1054 1055 1056 1057
					+ "<button onclick='showPicture("
					+ '"'
					+ fi.fileId
					+ '"'
					+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-picture'></span> 查看</button>";
青阳龙野's avatar
青阳龙野 已提交
1058 1059 1060 1061 1062
			break;
		case "mp3":
		case "wav":
		case "ogg":
			fileRow = fileRow
青阳龙野's avatar
青阳龙野 已提交
1063 1064 1065 1066 1067
					+ "<button onclick='playAudio("
					+ '"'
					+ fi.fileId
					+ '"'
					+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-play'></span> 播放</button>";
青阳龙野's avatar
青阳龙野 已提交
1068 1069 1070
			break;
		case "docx":
			fileRow = fileRow
青阳龙野's avatar
青阳龙野 已提交
1071 1072 1073 1074 1075
					+ "<button onclick='docxView("
					+ '"'
					+ fi.fileId
					+ '"'
					+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-eye-open'></span> 预览</button>";
青阳龙野's avatar
青阳龙野 已提交
1076 1077 1078
			break;
		case "txt":
			fileRow = fileRow
青阳龙野's avatar
青阳龙野 已提交
1079 1080 1081 1082 1083
					+ "<button onclick='txtView("
					+ '"'
					+ fi.fileId
					+ '"'
					+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-eye-open'></span> 预览</button>";
青阳龙野's avatar
青阳龙野 已提交
1084 1085 1086 1087
			break;
		case "ppt":
		case "pptx":
			fileRow = fileRow
青阳龙野's avatar
青阳龙野 已提交
1088 1089 1090 1091 1092
					+ "<button onclick='pptView("
					+ '"'
					+ fi.fileId
					+ '"'
					+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-eye-open'></span> 预览</button>";
青阳龙野's avatar
青阳龙野 已提交
1093 1094 1095 1096 1097 1098 1099 1100
			break;
		default:
			break;
		}
	}
	if (aD) {
		fileRow = fileRow
				+ "<button onclick='showDeleteFileModel("
青阳龙野's avatar
青阳龙野 已提交
1101
				+ '"'
青阳龙野's avatar
青阳龙野 已提交
1102 1103
				+ fi.fileId
				+ '","'
青阳龙野's avatar
青阳龙野 已提交
1104
				+ replaceAllQuotationMarks(fi.fileName)
青阳龙野's avatar
青阳龙野 已提交
1105
				+ '"'
青阳龙野's avatar
青阳龙野 已提交
1106 1107 1108 1109 1110
				+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-remove'></span> 删除</button>";
	}
	if (aR) {
		fileRow = fileRow
				+ "<button onclick='showRenameFileModel("
青阳龙野's avatar
青阳龙野 已提交
1111 1112 1113
				+ '"'
				+ fi.fileId
				+ '"'
青阳龙野's avatar
青阳龙野 已提交
1114
				+ ","
青阳龙野's avatar
青阳龙野 已提交
1115
				+ '"'
青阳龙野's avatar
青阳龙野 已提交
1116
				+ replaceAllQuotationMarks(fi.fileName)
青阳龙野's avatar
青阳龙野 已提交
1117
				+ '"'
青阳龙野's avatar
青阳龙野 已提交
1118 1119 1120 1121 1122
				+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-wrench'></span> 重命名</button>";
	}
	if (aO) {
		fileRow = fileRow
				+ "<button onclick='showFolderView("
青阳龙野's avatar
青阳龙野 已提交
1123
				+ '"'
青阳龙野's avatar
青阳龙野 已提交
1124 1125
				+ fi.fileParentFolder
				+ '","'
青阳龙野's avatar
青阳龙野 已提交
1126 1127
				+ fi.fileId
				+ '"'
青阳龙野's avatar
青阳龙野 已提交
1128 1129 1130 1131
				+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-sunglasses'></span> 定位</button>";
	}
	if (aL && folderView.showFileChain == 'true') {
		fileRow = fileRow
青阳龙野's avatar
青阳龙野 已提交
1132 1133 1134 1135
				+ "<button onclick='getFileChain("
				+ '"'
				+ fi.fileId
				+ '","'
青阳龙野's avatar
青阳龙野 已提交
1136
				+ replaceAllQuotationMarks(fi.fileName)
青阳龙野's avatar
青阳龙野 已提交
1137 1138
				+ '"'
				+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-link'></span> 链接</button>";
青阳龙野's avatar
青阳龙野 已提交
1139 1140 1141 1142 1143 1144 1145 1146 1147
	}
	if (!aR && !aD && !aL && !aO) {
		fileRow = fileRow + "--";
	}
	fileRow = fileRow + "</td></tr>";
	return fileRow;
}

// 根据一个文件夹对象生成对应的文件行的HTML内容
青阳龙野's avatar
青阳龙野 已提交
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
function createNewFolderRow(f, aD, aR, aO) {
	f.folderName = f.folderName.replace(/\'/g, '&#39;').replace(/</g, '&lt;')
			.replace(/>/g, '&gt;');
	var folderRow = "<tr id='"
			+ f.folderId
			+ "' onclick='checkfile(event,"
			+ '"'
			+ f.folderId
			+ '"'
			+ ")' ondblclick='checkConsFile(event,"
			+ '"'
			+ f.folderId
			+ '"'
			+ ")' class='filerow' iskfolder='true' ><td><button onclick='entryFolder("
			+ '"' + f.folderId + '"' + ")' class='btn btn-link btn-xs'>/"
青阳龙野's avatar
青阳龙野 已提交
1163 1164 1165 1166 1167 1168
			+ f.folderName + "</button></td><td class='hidden-xs'>"
			+ f.folderCreationDate + "</td><td>--</td><td class='hidden-xs'>"
			+ f.folderCreator + "</td><td>";
	if (aD) {
		folderRow = folderRow
				+ "<button onclick='showDeleteFolderModel("
青阳龙野's avatar
青阳龙野 已提交
1169
				+ '"'
青阳龙野's avatar
青阳龙野 已提交
1170 1171
				+ f.folderId
				+ '","'
青阳龙野's avatar
青阳龙野 已提交
1172
				+ replaceAllQuotationMarks(f.folderName)
青阳龙野's avatar
青阳龙野 已提交
1173
				+ '"'
青阳龙野's avatar
青阳龙野 已提交
1174 1175 1176 1177 1178
				+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-remove'></span> 删除</button>";
	}
	if (aR) {
		folderRow = folderRow
				+ "<button onclick='showRenameFolderModel("
青阳龙野's avatar
青阳龙野 已提交
1179
				+ '"'
青阳龙野's avatar
青阳龙野 已提交
1180 1181
				+ f.folderId
				+ '","'
青阳龙野's avatar
青阳龙野 已提交
1182
				+ replaceAllQuotationMarks(f.folderName)
青阳龙野's avatar
青阳龙野 已提交
1183 1184 1185 1186 1187 1188 1189
				+ '",'
				+ f.folderConstraint
				+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-wrench'></span> 编辑</button>";
	}
	if (aO) {
		folderRow = folderRow
				+ "<button onclick='showFolderView("
青阳龙野's avatar
青阳龙野 已提交
1190
				+ '"'
青阳龙野's avatar
青阳龙野 已提交
1191 1192 1193 1194 1195
				+ f.folderParent
				+ '","'
				+ f.folderId
				+ '"'
				+ ")' class='btn btn-link btn-xs'><span class='glyphicon glyphicon-sunglasses'></span> 定位</button>";
青阳龙野's avatar
青阳龙野 已提交
1196
	}
青阳龙野's avatar
青阳龙野 已提交
1197 1198 1199 1200 1201
	if (!aR && !aD && !aO) {
		folderRow = folderRow + "--";
	}
	folderRow = folderRow + "</td></tr>";
	return folderRow;
高源 已提交
1202 1203
}

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

高源 已提交
1206 1207
// 显示新建文件夹模态框
function showNewFolderModel() {
青阳龙野's avatar
青阳龙野 已提交
1208 1209 1210 1211
	$('#newFolderModal').modal('show');
}

// 修改新建文件夹约束等级
青阳龙野's avatar
青阳龙野 已提交
1212
function changeNewFolderType(type) {
青阳龙野's avatar
青阳龙野 已提交
1213
	$("#newfoldertype").text(folderTypes[type]);
青阳龙野's avatar
青阳龙野 已提交
1214
	$("#foldername").attr("folderConstraintLevel", type + "");
高源 已提交
1215 1216 1217 1218 1219
}

// 创建新的文件夹
function createfolder() {
	var fn = $("#foldername").val();
青阳龙野's avatar
青阳龙野 已提交
1220
	var fc = $("#foldername").attr("folderConstraintLevel");
青阳龙野's avatar
青阳龙野 已提交
1221
	var reg = new RegExp("[\/\|\\\\\*\\<\\>\\?\\:\\&\\$" + '"' + "]+", "g");
高源 已提交
1222 1223
	if (fn.length == 0) {
		showFolderAlert("提示:文件夹名称不能为空。");
青阳龙野's avatar
青阳龙野 已提交
1224
	} else if (fn.length > 128) {
高源 已提交
1225
		showFolderAlert("提示:文件夹名称太长。");
青阳龙野's avatar
青阳龙野 已提交
1226
	} else if (!reg.test(fn) && fn.indexOf(".") != 0) {
高源 已提交
1227 1228 1229 1230 1231 1232 1233 1234 1235
		$("#folderalert").removeClass("alert");
		$("#folderalert").removeClass("alert-danger");
		$("#foldernamebox").removeClass("has-error");
		$("#folderalert").text("");
		$.ajax({
			type : "POST",
			dataType : "text",
			data : {
				parentId : locationpath,
青阳龙野's avatar
青阳龙野 已提交
1236 1237
				folderName : fn,
				folderConstraint : fc
高源 已提交
1238 1239 1240
			},
			url : "homeController/newFolder.ajax",
			success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
1241
				if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
1242
					window.location.href = "prv/login.html";
高源 已提交
1243
				} else {
青阳龙野's avatar
青阳龙野 已提交
1244 1245
					switch (result) {
					case "noAuthorized":
青阳龙野's avatar
青阳龙野 已提交
1246
						showFolderAlert("提示:您的操作未被授权,创建文件夹失败。");
青阳龙野's avatar
青阳龙野 已提交
1247 1248
						break;
					case "errorParameter":
青阳龙野's avatar
青阳龙野 已提交
1249
						showFolderAlert("提示:参数不正确,创建文件夹失败。");
青阳龙野's avatar
青阳龙野 已提交
1250 1251
						break;
					case "cannotCreateFolder":
青阳龙野's avatar
青阳龙野 已提交
1252
						showFolderAlert("提示:出现意外错误,可能未能创建文件夹。");
青阳龙野's avatar
青阳龙野 已提交
1253 1254
						break;
					case "nameOccupied":
青阳龙野's avatar
青阳龙野 已提交
1255
						showFolderAlert("提示:该名称已被占用,请选取其他名称。");
青阳龙野's avatar
青阳龙野 已提交
1256 1257 1258 1259 1260
						break;
					case "foldersTotalOutOfLimit":
						showFolderAlert("提示:该文件夹内存储的文件夹数量已达上限,无法在其中创建更多文件夹。");
						break;
					case "createFolderSuccess":
青阳龙野's avatar
青阳龙野 已提交
1261 1262
						$('#newFolderModal').modal('hide');
						showFolderView(locationpath);
青阳龙野's avatar
青阳龙野 已提交
1263 1264
						break;
					default:
青阳龙野's avatar
青阳龙野 已提交
1265
						showFolderAlert("提示:出现意外错误,可能未能创建文件夹。");
青阳龙野's avatar
青阳龙野 已提交
1266
						break;
青阳龙野's avatar
青阳龙野 已提交
1267
					}
高源 已提交
1268 1269 1270 1271 1272 1273 1274
				}
			},
			error : function() {
				showFolderAlert("提示:出现意外错误,可能未能创建文件夹");
			}
		});
	} else {
青阳龙野's avatar
青阳龙野 已提交
1275
		showFolderAlert("提示:文件夹名中不应含有:引号 / \\ * | < > & $ : ? 且不能以“.”开头。");
高源 已提交
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298
	}
}

// 显示新建文件夹状态提示
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);
青阳龙野's avatar
青阳龙野 已提交
1299
	$("#cancelDeleteFolderBtn").attr('disabled', false);
高源 已提交
1300 1301 1302 1303 1304 1305 1306 1307
	$('#deleteFolderMessage').text(
			"提示:确定要彻底删除文件夹:[" + folderName + "]及其全部内容么?该操作不可恢复");
	$('#deleteFolderModal').modal('toggle');
}

// 执行删除文件夹
function deleteFolder(folderId) {
	$("#dmbutton").attr('disabled', true);
青阳龙野's avatar
青阳龙野 已提交
1308
	$("#cancelDeleteFolderBtn").attr('disabled', true);
高源 已提交
1309 1310 1311 1312 1313 1314 1315 1316 1317
	$('#deleteFolderMessage').text("提示:正在删除,请稍候...");
	$.ajax({
		type : "POST",
		dataType : "text",
		data : {
			folderId : folderId
		},
		url : "homeController/deleteFolder.ajax",
		success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
1318
			if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
1319
				window.location.href = "prv/login.html";
高源 已提交
1320
			} else {
青阳龙野's avatar
青阳龙野 已提交
1321 1322 1323
				if (result == "noAuthorized") {
					$('#deleteFolderMessage').text("提示:您的操作未被授权,删除文件夹失败");
					$("#dmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1324
					$("#cancelDeleteFolderBtn").attr('disabled', true);
青阳龙野's avatar
青阳龙野 已提交
1325 1326 1327
				} else if (result == "errorParameter") {
					$('#deleteFolderMessage').text("提示:参数不正确,删除文件夹失败");
					$("#dmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1328
					$("#cancelDeleteFolderBtn").attr('disabled', true);
青阳龙野's avatar
青阳龙野 已提交
1329 1330 1331
				} else if (result == "cannotDeleteFolder") {
					$('#deleteFolderMessage').text("提示:出现意外错误,可能未能删除文件夹");
					$("#dmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1332
					$("#cancelDeleteFolderBtn").attr('disabled', true);
青阳龙野's avatar
青阳龙野 已提交
1333 1334 1335 1336 1337 1338
				} else if (result == "deleteFolderSuccess") {
					$('#deleteFolderModal').modal('hide');
					showFolderView(locationpath);
				} else {
					$('#deleteFolderMessage').text("提示:出现意外错误,可能未能删除文件夹");
					$("#dmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1339
					$("#cancelDeleteFolderBtn").attr('disabled', true);
青阳龙野's avatar
青阳龙野 已提交
1340
				}
高源 已提交
1341 1342 1343 1344 1345
			}
		},
		error : function() {
			$('#deleteFolderMessage').text("提示:出现意外错误,可能未能删除文件夹");
			$("#dmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1346
			$("#cancelDeleteFolderBtn").attr('disabled', true);
高源 已提交
1347 1348 1349 1350 1351
		}
	});
}

// 显示重命名文件夹模态框
青阳龙野's avatar
青阳龙野 已提交
1352
function showRenameFolderModel(folderId, folderName, type) {
高源 已提交
1353 1354 1355 1356
	$("#renameFolderBox").html(
			"<button type='button' class='btn btn-primary' onclick='renameFolder("
					+ '"' + folderId + '"' + ")'>修改</button>");
	$("#newfoldername").val(folderName);
青阳龙野's avatar
青阳龙野 已提交
1357 1358 1359 1360
	changeEditFolderType(type);
	$("#renameFolderModal").modal('show');
}

青阳龙野's avatar
青阳龙野 已提交
1361
// 修改编辑文件夹的约束等级
青阳龙野's avatar
青阳龙野 已提交
1362
function changeEditFolderType(type) {
青阳龙野's avatar
青阳龙野 已提交
1363
	$("#editfoldertype").text(folderTypes[type]);
青阳龙野's avatar
青阳龙野 已提交
1364
	$("#newfoldername").attr("folderConstraintLevel", type + "");
高源 已提交
1365 1366
}

青阳龙野's avatar
青阳龙野 已提交
1367
// 执行重命名文件夹
高源 已提交
1368 1369
function renameFolder(folderId) {
	var newName = $("#newfoldername").val();
青阳龙野's avatar
青阳龙野 已提交
1370
	var fc = $("#newfoldername").attr("folderConstraintLevel");
青阳龙野's avatar
青阳龙野 已提交
1371
	var reg = new RegExp("[\/\|\\\\\*\\<\\>\\?\\:\\&\\$" + '"' + "]+", "g");
高源 已提交
1372
	if (newName.length == 0) {
青阳龙野's avatar
青阳龙野 已提交
1373
		showRFolderAlert("提示:文件夹名称不能为空。");
青阳龙野's avatar
青阳龙野 已提交
1374
	} else if (newName.length > 128) {
青阳龙野's avatar
青阳龙野 已提交
1375
		showRFolderAlert("提示:文件夹名称太长。");
青阳龙野's avatar
青阳龙野 已提交
1376
	} else if (!reg.test(newName) && newName.indexOf(".") != 0) {
高源 已提交
1377 1378 1379 1380 1381 1382 1383 1384 1385
		$("#newfolderalert").removeClass("alert");
		$("#newfolderalert").removeClass("alert-danger");
		$("#folderrenamebox").removeClass("has-error");
		$("#newfolderalert").text("");
		$.ajax({
			type : "POST",
			dataType : "text",
			data : {
				folderId : folderId,
青阳龙野's avatar
青阳龙野 已提交
1386 1387
				newName : newName,
				folderConstraint : fc
高源 已提交
1388 1389 1390
			},
			url : "homeController/renameFolder.ajax",
			success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
1391
				if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
1392
					window.location.href = "prv/login.html";
高源 已提交
1393
				} else {
青阳龙野's avatar
青阳龙野 已提交
1394
					if (result == "noAuthorized") {
青阳龙野's avatar
青阳龙野 已提交
1395
						showRFolderAlert("提示:您的操作未被授权,编辑失败。");
青阳龙野's avatar
青阳龙野 已提交
1396
					} else if (result == "errorParameter") {
青阳龙野's avatar
青阳龙野 已提交
1397 1398 1399
						showRFolderAlert("提示:参数不正确,编辑失败,请刷新后重试。");
					} else if (result == "nameOccupied") {
						showRFolderAlert("提示:该名称已被占用,请选取其他名称。");
青阳龙野's avatar
青阳龙野 已提交
1400 1401 1402 1403
					} else if (result == "renameFolderSuccess") {
						$('#renameFolderModal').modal('hide');
						showFolderView(locationpath);
					} else {
青阳龙野's avatar
青阳龙野 已提交
1404
						showRFolderAlert("提示:出现意外错误,可能未能编辑文件夹,请刷新后重试。");
青阳龙野's avatar
青阳龙野 已提交
1405
					}
高源 已提交
1406 1407 1408
				}
			},
			error : function() {
青阳龙野's avatar
青阳龙野 已提交
1409
				showRFolderAlert("提示:出现意外错误,可能未能编辑文件夹,请刷新后重试。");
高源 已提交
1410 1411 1412
			}
		});
	} else {
青阳龙野's avatar
青阳龙野 已提交
1413
		showRFolderAlert("提示:文件夹名中不应含有:引号 / \\ * | < > & $ : ? 且不能以“.”开头。");
高源 已提交
1414 1415 1416 1417
	}
}

// 显示重命名文件夹状态提示
青阳龙野's avatar
青阳龙野 已提交
1418
function showRFolderAlert(txt) {
青阳龙野's avatar
青阳龙野 已提交
1419 1420
	$("#editfolderalert").addClass("alert");
	$("#editfolderalert").addClass("alert-danger");
高源 已提交
1421
	$("#folderrenamebox").addClass("has-error");
青阳龙野's avatar
青阳龙野 已提交
1422
	$("#editfolderalert").text(txt);
高源 已提交
1423 1424 1425 1426
}

// 显示上传文件模态框
function showUploadFileModel() {
青阳龙野's avatar
青阳龙野 已提交
1427
	$("#uploadFileAlert").hide();
高源 已提交
1428
	$("#uploadFileAlert").text("");
青阳龙野's avatar
青阳龙野 已提交
1429
	if (isUpLoading == false) {
青阳龙野's avatar
青阳龙野 已提交
1430
		$("#filepath").removeAttr("disabled");
青阳龙野's avatar
青阳龙野 已提交
1431 1432 1433
		$("#uploadfile").val("");
		$("#filepath").val("");
		$("#pros").width("0%");
青阳龙野's avatar
青阳龙野 已提交
1434
		$("#pros").attr('aria-valuenow', '0');
青阳龙野's avatar
青阳龙野 已提交
1435 1436
		$("#umbutton").attr('disabled', false);
		$("#filecount").text("");
青阳龙野's avatar
青阳龙野 已提交
1437
		$("#uploadstatus").html("");
青阳龙野's avatar
青阳龙野 已提交
1438
		$("#selectcount").text("");
青阳龙野's avatar
青阳龙野 已提交
1439
		$("#selectFileUpLoadModelAsAll").removeAttr("checked");
青阳龙野's avatar
青阳龙野 已提交
1440
		$("#selectFileUpLoadModelAlert").hide();
青阳龙野's avatar
青阳龙野 已提交
1441 1442
	}
	$('#uploadFileModal').modal('show');
高源 已提交
1443 1444 1445 1446 1447 1448 1449
}

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

青阳龙野's avatar
青阳龙野 已提交
1450
// 获取选中文件
青阳龙野's avatar
青阳龙野 已提交
1451
function getInputUpload() {
青阳龙野's avatar
青阳龙野 已提交
1452 1453 1454 1455
	fs = $("#uploadfile").get(0).files;
	showfilepath();
}

高源 已提交
1456 1457
// 文件选中后自动回填文件路径
function showfilepath() {
青阳龙野's avatar
青阳龙野 已提交
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470
	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);
高源 已提交
1471 1472
}

青阳龙野's avatar
青阳龙野 已提交
1473
// 检查文件是否能够上传
高源 已提交
1474
function checkUploadFile() {
青阳龙野's avatar
青阳龙野 已提交
1475 1476 1477
	if (isUpLoading == false && isImporting == false) {
		if (fs != null && fs.length > 0) {
			$("#filepath").attr("disabled", "disabled");
青阳龙野's avatar
青阳龙野 已提交
1478
			$("#umbutton").attr('disabled', true);
青阳龙野's avatar
青阳龙野 已提交
1479 1480
			isUpLoading = true;
			repeModelList = null;
青阳龙野's avatar
青阳龙野 已提交
1481
			$("#uploadFileAlert").hide();
青阳龙野's avatar
青阳龙野 已提交
1482 1483
			$("#uploadFileAlert").text("");
			var filenames = new Array();
青阳龙野's avatar
青阳龙野 已提交
1484 1485
			var maxSize = 0;
			var maxFileIndex = 0;
青阳龙野's avatar
青阳龙野 已提交
1486
			for (var i = 0; i < fs.length; i++) {
青阳龙野's avatar
青阳龙野 已提交
1487
				filenames[i] = fs[i].name;
青阳龙野's avatar
青阳龙野 已提交
1488
				if (fs[i].size > maxSize) {
青阳龙野's avatar
青阳龙野 已提交
1489 1490 1491
					maxSize = fs[i].size;
					maxFileIndex = i;
				}
青阳龙野's avatar
青阳龙野 已提交
1492 1493
			}
			var namelist = JSON.stringify(filenames);
青阳龙野's avatar
青阳龙野 已提交
1494 1495 1496 1497 1498 1499 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

			$
					.ajax({
						type : "POST",
						dataType : "text",
						data : {
							folderId : locationpath,
							namelist : namelist,
							maxSize : maxSize,
							maxFileIndex : maxFileIndex
						},
						url : "homeController/checkUploadFile.ajax",
						success : function(result) {
							if (result == "mustLogin") {
								window.location.href = "prv/login.html";
							} else {
								switch (result) {
								case "errorParameter":
									showUploadFileAlert("提示:参数不正确,无法开始上传");
									break;
								case "noAuthorized":
									showUploadFileAlert("提示:您的操作未被授权,无法开始上传");
									break;
								case "filesTotalOutOfLimit":
									showUploadFileAlert("提示:该文件夹内存储的文件数量已达上限,无法在其中上传更多文件。您可以尝试将其上传至其他文件夹内。");
									break;
								default:
									var resp = eval("(" + result + ")");
									if (resp.checkResult == "fileTooLarge") {
										showUploadFileAlert("提示:文件["
												+ resp.overSizeFile
												+ "]的体积超过最大限制("
												+ resp.maxUploadFileSize
												+ "),无法开始上传");
									} else if (resp.checkResult == "hasExistsNames") {
										repeList = resp.pereFileNameList;
										repeIndex = 0;
										selectFileUpLoadModelStart();
									} else if (resp.checkResult == "permitUpload") {
										doupload(1);
									} else {
										showUploadFileAlert("提示:出现意外错误,无法开始上传");
									}
									break;
								}
青阳龙野's avatar
青阳龙野 已提交
1539
							}
青阳龙野's avatar
青阳龙野 已提交
1540 1541 1542
						},
						error : function() {
							showUploadFileAlert("提示:出现意外错误,无法开始上传");
青阳龙野's avatar
青阳龙野 已提交
1543
						}
青阳龙野's avatar
青阳龙野 已提交
1544 1545
					});
		} else {
青阳龙野's avatar
青阳龙野 已提交
1546
			showUploadFileAlert("提示:您未选择任何文件,无法开始上传");
高源 已提交
1547
		}
青阳龙野's avatar
青阳龙野 已提交
1548
	} else {
青阳龙野's avatar
青阳龙野 已提交
1549
		showUploadFileAlert("提示:另一项上传文件或文件夹的任务尚未完成,无法开始上传");
青阳龙野's avatar
青阳龙野 已提交
1550
	}
高源 已提交
1551 1552
}

青阳龙野's avatar
青阳龙野 已提交
1553 1554 1555
var repeList;// 这个是重复文件名的列表,型如['xxx','ooo',...]
var repeIndex;// 当前设定上传模式的文件序号
var repeModelList;// 这个是对每一个重复文件选取的上传模式,型如{'xxx':'skip','ooo':'both',...}
青阳龙野's avatar
青阳龙野 已提交
1556 1557

// 针对同名文件,选择上传的模式:跳过(skip)、覆盖(cover)和保留两者(both)
青阳龙野's avatar
青阳龙野 已提交
1558
function selectFileUpLoadModelStart() {
青阳龙野's avatar
青阳龙野 已提交
1559
	var authList = originFolderView.authList;
青阳龙野's avatar
青阳龙野 已提交
1560
	if (checkAuth(authList, "D")) {
青阳龙野's avatar
青阳龙野 已提交
1561
		$("#uploadcoverbtn").show();
青阳龙野's avatar
青阳龙野 已提交
1562
	} else {
青阳龙野's avatar
青阳龙野 已提交
1563 1564
		$("#uploadcoverbtn").hide();
	}
青阳龙野's avatar
青阳龙野 已提交
1565 1566 1567 1568
	$("#selectFileUpLoadModelAlert").show();
	$("#repeFileName").text(repeList[repeIndex]);
}

青阳龙野's avatar
青阳龙野 已提交
1569
// 设定重名文件的处理方法
青阳龙野's avatar
青阳龙野 已提交
1570 1571 1572
function selectFileUpLoadModelEnd(t) {
	if (repeModelList == null) {
		repeModelList = {};
青阳龙野's avatar
青阳龙野 已提交
1573
	}
青阳龙野's avatar
青阳龙野 已提交
1574
	repeModelList[$("#repeFileName").text()] = t;
青阳龙野's avatar
青阳龙野 已提交
1575
	$("#selectFileUpLoadModelAlert").hide();
青阳龙野's avatar
青阳龙野 已提交
1576 1577 1578
	if ($('#selectFileUpLoadModelAsAll').prop('checked')) {
		for (var i = repeIndex; i < repeList.length; i++) {
			repeModelList[repeList[i]] = t;
青阳龙野's avatar
青阳龙野 已提交
1579 1580
		}
		doupload(1);
青阳龙野's avatar
青阳龙野 已提交
1581
	} else {
青阳龙野's avatar
青阳龙野 已提交
1582
		repeIndex++;
青阳龙野's avatar
青阳龙野 已提交
1583
		if (repeIndex < repeList.length) {
青阳龙野's avatar
青阳龙野 已提交
1584
			selectFileUpLoadModelStart();
青阳龙野's avatar
青阳龙野 已提交
1585
		} else {
青阳龙野's avatar
青阳龙野 已提交
1586 1587 1588 1589 1590
			doupload(1);
		}
	}
}

高源 已提交
1591
// 执行文件上传并实现上传进度显示
青阳龙野's avatar
青阳龙野 已提交
1592 1593
function doupload(count) {
	var fcount = fs.length;
高源 已提交
1594
	$("#pros").width("0%");// 先将进度条置0
青阳龙野's avatar
青阳龙野 已提交
1595
	$("#pros").attr('aria-valuenow', "0");
青阳龙野's avatar
青阳龙野 已提交
1596
	var uploadfile = fs[count - 1];// 获取要上传的文件
高源 已提交
1597
	if (uploadfile != null) {
青阳龙野's avatar
青阳龙野 已提交
1598 1599 1600 1601 1602
		var fname = uploadfile.name;
		if (fcount > 1) {
			$("#filecount").text("" + count + "/" + fcount + "");// 显示当前进度
		}
		$("#uploadstatus").prepend(
青阳龙野's avatar
青阳龙野 已提交
1603 1604 1605 1606
				"<p>"
						+ fname.replace(/\'/g, '&#39;').replace(/</g, '&lt;')
								.replace(/>/g, '&gt;') + "<span id='uls_"
						+ count + "'>[正在上传...]</span></p>");
高源 已提交
1607 1608 1609 1610
		xhr = new XMLHttpRequest();// 这东西类似于servlet里面的request

		var fd = new FormData();// 用于封装文件数据的对象
		fd.append("file", uploadfile);// 将文件对象添加到FormData对象中,字段名为uploadfile
青阳龙野's avatar
青阳龙野 已提交
1611
		fd.append("fname", fname);
高源 已提交
1612
		fd.append("folderId", locationpath);
青阳龙野's avatar
青阳龙野 已提交
1613 1614
		if (repeModelList != null && repeModelList[fname] != null) {
			if (repeModelList[fname] == 'skip') {
青阳龙野's avatar
青阳龙野 已提交
1615 1616 1617
				$("#uls_" + count).text("[已完成]");
				if (count < fcount) {
					doupload(count + 1);
青阳龙野's avatar
青阳龙野 已提交
1618
					return;
青阳龙野's avatar
青阳龙野 已提交
1619 1620
				} else {
					// 清空所有提示信息,还原上传窗口
青阳龙野's avatar
青阳龙野 已提交
1621
					isUpLoading = false;
青阳龙野's avatar
青阳龙野 已提交
1622 1623 1624 1625
					$("#filepath").removeAttr("disabled");
					$("#uploadfile").val("");
					$("#filepath").val("");
					$("#pros").width("0%");
青阳龙野's avatar
青阳龙野 已提交
1626
					$("#pros").attr('aria-valuenow', "0");
青阳龙野's avatar
青阳龙野 已提交
1627 1628 1629 1630 1631 1632
					$("#umbutton").attr('disabled', false);
					$("#filecount").text("");
					$("#uploadstatus").text("");
					$("#selectcount").text("");
					$('#uploadFileModal').modal('hide');
					showFolderView(locationpath);
青阳龙野's avatar
青阳龙野 已提交
1633
					return;
青阳龙野's avatar
青阳龙野 已提交
1634 1635 1636 1637
				}
			}
			fd.append("repeType", repeModelList[fname]);
		}
高源 已提交
1638 1639 1640 1641 1642 1643
		xhr.open("POST", "homeController/douploadFile.ajax", true);// 上传目标

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

		xhr.send(fd);// 上传FormData对象
青阳龙野's avatar
青阳龙野 已提交
1644 1645 1646

		if (pingInt == null) {
			pingInt = setInterval("ping()", 60000);// 上传中开始计时应答
青阳龙野's avatar
青阳龙野 已提交
1647
		}
高源 已提交
1648 1649 1650

		// 上传结束后执行的回调函数
		xhr.onloadend = function() {
青阳龙野's avatar
青阳龙野 已提交
1651
			// 停止应答计时
青阳龙野's avatar
青阳龙野 已提交
1652
			if (pingInt != null) {
青阳龙野's avatar
青阳龙野 已提交
1653 1654 1655
				window.clearInterval(pingInt);
				pingInt = null;
			}
高源 已提交
1656 1657 1658 1659
			if (xhr.status === 200) {
				// TODO 上传成功
				var result = xhr.responseText;
				if (result == "uploadsuccess") {
青阳龙野's avatar
青阳龙野 已提交
1660 1661 1662 1663 1664
					$("#uls_" + count).text("[已完成]");
					if (count < fcount) {
						doupload(count + 1);
					} else {
						// 清空所有提示信息,还原上传窗口
青阳龙野's avatar
青阳龙野 已提交
1665
						isUpLoading = false;
青阳龙野's avatar
青阳龙野 已提交
1666
						$("#filepath").removeAttr("disabled");
青阳龙野's avatar
青阳龙野 已提交
1667 1668 1669
						$("#uploadfile").val("");
						$("#filepath").val("");
						$("#pros").width("0%");
青阳龙野's avatar
青阳龙野 已提交
1670
						$("#pros").attr('aria-valuenow', "0");
青阳龙野's avatar
青阳龙野 已提交
1671 1672 1673 1674
						$("#umbutton").attr('disabled', false);
						$("#filecount").text("");
						$("#uploadstatus").text("");
						$("#selectcount").text("");
青阳龙野's avatar
青阳龙野 已提交
1675 1676
						$('#uploadFileModal').modal('hide');
						showFolderView(locationpath);
青阳龙野's avatar
青阳龙野 已提交
1677
					}
高源 已提交
1678
				} else if (result == "uploaderror") {
青阳龙野's avatar
青阳龙野 已提交
1679 1680 1681
					showUploadFileAlert("提示:出现意外错误,文件:[" + fname
							+ "]上传失败,上传被中断。");
					$("#uls_" + count).text("[失败]");
青阳龙野's avatar
青阳龙野 已提交
1682
				} else if (result == 'filesTotalOutOfLimit') {
青阳龙野's avatar
青阳龙野 已提交
1683 1684 1685
					showUploadFileAlert("提示:该文件夹内存储的文件数量已达上限,文件:[" + fname
							+ "]上传失败。您可以尝试将其上传至其他文件夹内。");
					$("#uls_" + count).text("[失败]");
高源 已提交
1686
				} else {
青阳龙野's avatar
青阳龙野 已提交
1687 1688
					showUploadFileAlert("提示:出现意外错误,文件:[" + fname
							+ "]上传失败,上传被中断。");
青阳龙野's avatar
青阳龙野 已提交
1689
					$("#uls_" + count).text("[失败]");
高源 已提交
1690 1691
				}
			} else {
青阳龙野's avatar
青阳龙野 已提交
1692 1693
				showUploadFileAlert("提示:出现意外错误,文件:[" + fname + "]上传失败,上传被中断。");
				$("#uls_" + count).text("[失败]");
高源 已提交
1694 1695 1696
			}
		};
	} else {
青阳龙野's avatar
青阳龙野 已提交
1697 1698 1699
		showUploadFileAlert("提示:要上传的文件不存在。");
		$("#uploadstatus").prepend(
				"<p>未找到要上传的文件<span id='uls_" + count + "'>[失败]</span></p>");
高源 已提交
1700 1701 1702
	}
}

青阳龙野's avatar
青阳龙野 已提交
1703
// 显示上传文件进度
高源 已提交
1704 1705 1706 1707 1708 1709
function uploadProgress(evt) {
	if (evt.lengthComputable) {
		// evt.loaded:文件上传的大小 evt.total:文件总的大小
		var percentComplete = Math.round((evt.loaded) * 100 / evt.total);
		// 加载进度条,同时显示信息
		$("#pros").width(percentComplete + "%");
青阳龙野's avatar
青阳龙野 已提交
1710
		$("#pros").attr('aria-valuenow', "" + percentComplete);
高源 已提交
1711 1712 1713
	}
}

青阳龙野's avatar
青阳龙野 已提交
1714
// 显示上传文件错误提示
高源 已提交
1715
function showUploadFileAlert(txt) {
青阳龙野's avatar
青阳龙野 已提交
1716
	isUpLoading = false;
青阳龙野's avatar
青阳龙野 已提交
1717
	$("#filepath").removeAttr("disabled");
青阳龙野's avatar
青阳龙野 已提交
1718
	$("#uploadFileAlert").show();
高源 已提交
1719 1720 1721 1722
	$("#uploadFileAlert").text(txt);
	$("#umbutton").attr('disabled', false);
}

青阳龙野's avatar
青阳龙野 已提交
1723 1724
// 取消上传文件
function abortUpload() {
青阳龙野's avatar
青阳龙野 已提交
1725 1726 1727 1728 1729
	if (isUpLoading) {
		isUpLoading = false;
		if (xhr != null) {
			xhr.abort();
		}
青阳龙野's avatar
青阳龙野 已提交
1730 1731 1732 1733 1734
	}
	$('#uploadFileModal').modal('hide');
	showFolderView(locationpath);
}

高源 已提交
1735 1736 1737
// 显示下载文件模态框
function showDownloadModel(fileId, fileName) {
	$("#downloadFileName").text("提示:您确认要下载文件:[" + fileName + "]么?");
青阳龙野's avatar
青阳龙野 已提交
1738
	$("#downloadHrefBox").html("<span class='text-muted'>正在生成...</span>");
青阳龙野's avatar
青阳龙野 已提交
1739 1740
	getDownloadFileId = fileId;
	getDownloadFileName = fileName;
高源 已提交
1741 1742 1743 1744 1745
	$("#downloadFileBox")
			.html(
					"<button id='dlmbutton' type='button' class='btn btn-primary' onclick='dodownload("
							+ '"' + fileId + '"' + ")'>开始下载</button>");
	$("#dlmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1746
	$("#downloadModal").modal('show');
高源 已提交
1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763
}

// 执行下载操作
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);
青阳龙野's avatar
青阳龙野 已提交
1764
	$("#cancelDeleteFileBox").attr('disabled', false);
高源 已提交
1765 1766 1767 1768 1769 1770 1771
	$('#deleteFileMessage').text("提示:确定要彻底删除文件:[" + fileName + "]么?该操作不可恢复");
	$('#deleteFileModal').modal('toggle');
}

// 执行删除文件操作
function deleteFile(fileId) {
	$("#dfmbutton").attr('disabled', true);
青阳龙野's avatar
青阳龙野 已提交
1772
	$("#cancelDeleteFileBox").attr('disabled', true);
高源 已提交
1773 1774 1775 1776 1777 1778 1779 1780 1781
	$('#deleteFileMessage').text("提示:正在删除,请稍候...");
	$.ajax({
		type : "POST",
		dataType : "text",
		data : {
			fileId : fileId
		},
		url : "homeController/deleteFile.ajax",
		success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
1782
			if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
1783
				window.location.href = "prv/login.html";
高源 已提交
1784
			} else {
青阳龙野's avatar
青阳龙野 已提交
1785 1786 1787
				if (result == "noAuthorized") {
					$('#deleteFileMessage').text("提示:您的操作未被授权,删除失败");
					$("#dfmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1788
					$("#cancelDeleteFileBox").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1789 1790 1791
				} else if (result == "errorParameter") {
					$('#deleteFileMessage').text("提示:参数不正确,删除失败");
					$("#dfmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1792
					$("#cancelDeleteFileBox").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1793 1794 1795
				} else if (result == "cannotDeleteFile") {
					$('#deleteFileMessage').text("提示:出现意外错误,可能未能删除文件");
					$("#dfmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1796
					$("#cancelDeleteFileBox").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1797 1798 1799 1800 1801 1802
				} else if (result == "deleteFileSuccess") {
					$('#deleteFileModal').modal('hide');
					showFolderView(locationpath);
				} else {
					$('#deleteFileMessage').text("提示:出现意外错误,可能未能删除文件");
					$("#dfmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1803
					$("#cancelDeleteFileBox").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1804
				}
高源 已提交
1805 1806 1807 1808 1809
			}
		},
		error : function() {
			$('#deleteFileMessage').text("提示:出现意外错误,可能未能删除文件");
			$("#dfmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
1810
			$("#cancelDeleteFileBox").attr('disabled', false);
高源 已提交
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829
		}
	});
}

// 显示重命名文件模态框
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) {
青阳龙野's avatar
青阳龙野 已提交
1830
	var reg = new RegExp("[\/\|\\\\\*\\<\\>\\?\\:\\&\\$" + '"' + "]+", "g");
高源 已提交
1831 1832 1833
	var newFileName = $("#newfilename").val();
	if (newFileName.length > 0) {
		if (newFileName.length < 128) {
青阳龙野's avatar
青阳龙野 已提交
1834
			if (!reg.test(newFileName) && newFileName.indexOf(".") != 0) {
高源 已提交
1835 1836 1837 1838 1839 1840 1841 1842 1843
				$.ajax({
					type : "POST",
					dataType : "text",
					data : {
						fileId : fileId,
						newFileName : newFileName
					},
					url : "homeController/renameFile.ajax",
					success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
1844
						if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
1845
							window.location.href = "prv/login.html";
高源 已提交
1846
						} else {
青阳龙野's avatar
青阳龙野 已提交
1847
							if (result == "cannotRenameFile") {
青阳龙野's avatar
青阳龙野 已提交
1848
								showRFileAlert("提示:出现意外错误,可能未能重命名文件,请刷新后重试。");
青阳龙野's avatar
青阳龙野 已提交
1849 1850 1851 1852
							} else if (result == "renameFileSuccess") {
								$('#renameFileModal').modal('hide');
								showFolderView(locationpath);
							} else if (result == "errorParameter") {
青阳龙野's avatar
青阳龙野 已提交
1853 1854 1855
								showRFileAlert("提示:参数错误,重命名失败,请刷新后重试。");
							} else if (result == "nameOccupied") {
								showRFileAlert("提示:该名称已被占用,请选取其他名称。");
青阳龙野's avatar
青阳龙野 已提交
1856
							} else if (result == "noAuthorized") {
青阳龙野's avatar
青阳龙野 已提交
1857
								showRFileAlert("提示:您的操作未被授权,重命名失败,请刷新后重试。");
青阳龙野's avatar
青阳龙野 已提交
1858
							} else {
青阳龙野's avatar
青阳龙野 已提交
1859
								showRFileAlert("提示:出现意外错误,可能未能重命名文件,请刷新后重试。");
青阳龙野's avatar
青阳龙野 已提交
1860
							}
高源 已提交
1861 1862 1863
						}
					},
					error : function() {
青阳龙野's avatar
青阳龙野 已提交
1864
						showRFileAlert("提示:出现意外错误,可能未能重命名文件。");
高源 已提交
1865 1866 1867
					}
				});
			} else {
青阳龙野's avatar
青阳龙野 已提交
1868
				showRFileAlert("提示:文件名中不应含有:引号 / \\ * | < > & $ : ? 且不能以“.”开头。");
高源 已提交
1869 1870
			}
		} else {
青阳龙野's avatar
青阳龙野 已提交
1871
			showRFileAlert("提示:文件名称太长。");
高源 已提交
1872 1873
		}
	} else {
青阳龙野's avatar
青阳龙野 已提交
1874
		showRFileAlert("提示:文件名不能为空。");
高源 已提交
1875 1876 1877 1878
	}
}

// 显示重命名文件状态提示
青阳龙野's avatar
青阳龙野 已提交
1879
function showRFileAlert(txt) {
高源 已提交
1880 1881 1882 1883 1884 1885
	$("#newFileNamealert").addClass("alert");
	$("#newFileNamealert").addClass("alert-danger");
	$("#filerenamebox").addClass("has-error");
	$("#newFileNamealert").text(txt);
}

1886
// 获取文件名的后缀名,以小写形式输出
1887 1888 1889 1890
function getSuffix(filename) {
	var index1 = filename.lastIndexOf(".");
	var index2 = filename.length;
	var suffix = filename.substring(index1 + 1, index2);
1891 1892 1893 1894 1895
	return suffix.toLowerCase();
}

// 播放指定格式的视频
function playVideo(fileId) {
青阳龙野's avatar
青阳龙野 已提交
1896
	window.open("quickview/video.html?fileId=" + fileId);
1897 1898 1899
}

// 预览PDF文档
青阳龙野's avatar
青阳龙野 已提交
1900 1901 1902 1903
function pdfView(fileId) {
	window
			.open("/pdfview/web/viewer.html?file=/resourceController/getResource/"
					+ fileId);
1904 1905
}

青阳龙野's avatar
青阳龙野 已提交
1906
// 预览Docx文档
青阳龙野's avatar
青阳龙野 已提交
1907 1908 1909 1910
function docxView(fileId) {
	window
			.open("/pdfview/web/viewer.html?file=/resourceController/getWordView/"
					+ fileId);
青阳龙野's avatar
青阳龙野 已提交
1911 1912
}

青阳龙野's avatar
青阳龙野 已提交
1913
// 预览TXT文档
青阳龙野's avatar
青阳龙野 已提交
1914 1915 1916
function txtView(fileId) {
	window.open("/pdfview/web/viewer.html?file=/resourceController/getTxtView/"
			+ fileId);
青阳龙野's avatar
青阳龙野 已提交
1917 1918
}

青阳龙野's avatar
青阳龙野 已提交
1919
// 预览PPT文档
青阳龙野's avatar
青阳龙野 已提交
1920 1921 1922
function pptView(fileId) {
	window.open("/pdfview/web/viewer.html?file=/resourceController/getPPTView/"
			+ fileId);
青阳龙野's avatar
青阳龙野 已提交
1923 1924
}

1925 1926
// 查看图片
function showPicture(fileId) {
青阳龙野's avatar
青阳龙野 已提交
1927 1928 1929 1930 1931 1932 1933 1934 1935
	$.ajax({
		url : "homeController/getPrePicture.ajax",
		data : {
			fileId : fileId
		},
		type : "POST",
		dataType : "text",
		success : function(result) {
			if (result != "ERROR") {
青阳龙野's avatar
青阳龙野 已提交
1936
				pvl = eval("(" + result + ")");
青阳龙野's avatar
青阳龙野 已提交
1937
				// TODO 整合viewer.js插件
青阳龙野's avatar
青阳龙野 已提交
1938
				if (pvl.pictureViewList.length <= viewerPageSize) {
青阳龙野's avatar
青阳龙野 已提交
1939 1940 1941
					createViewList();// 以全列方式显示图片列表
				} else {
					// 以分页方式显示图片列表
青阳龙野's avatar
青阳龙野 已提交
1942 1943 1944 1945
					viewerPageIndex = Math.ceil((pvl.index + 1)
							/ viewerPageSize);
					viewerTotal = Math.ceil(pvl.pictureViewList.length
							/ viewerPageSize);
青阳龙野's avatar
青阳龙野 已提交
1946
					createViewListByPage();
青阳龙野's avatar
青阳龙野 已提交
1947 1948 1949
					var innerIndex = pvl.index
							- ((viewerPageIndex - 1) * viewerPageSize);
					if (viewerPageIndex > 1) {
青阳龙野's avatar
青阳龙野 已提交
1950
						innerIndex++;
青阳龙野's avatar
青阳龙野 已提交
1951
					}
青阳龙野's avatar
青阳龙野 已提交
1952 1953 1954 1955
					viewer.viewer('view', innerIndex);
					viewer.viewer('show', true);
				}
				// end
青阳龙野's avatar
青阳龙野 已提交
1956 1957 1958 1959 1960 1961 1962 1963
			} else {
				alert("错误:无法定位要预览的文件或该操作未被授权。");
			}
		},
		error : function() {
			alert("错误:请求失败,请刷新重试。");
		}
	});
青阳龙野's avatar
青阳龙野 已提交
1964 1965
}

青阳龙野's avatar
青阳龙野 已提交
1966 1967
// 用于创建并显示小于2*limit+1长度的图片列表
function createViewList() {
青阳龙野's avatar
青阳龙野 已提交
1968
	if (viewer == null) {
青阳龙野's avatar
青阳龙野 已提交
1969
		var images = document.createElement("ul");
青阳龙野's avatar
青阳龙野 已提交
1970 1971 1972 1973
		for (var i = 0; i < pvl.pictureViewList.length; i++) {
			$(images).append(
					"<li><img src='" + pvl.pictureViewList[i].url + "' alt='"
							+ pvl.pictureViewList[i].fileName + "' /></li>");
青阳龙野's avatar
青阳龙野 已提交
1974 1975 1976
		}
		viewer = $(images);
		viewer.viewer({
青阳龙野's avatar
青阳龙野 已提交
1977 1978
			loop : false,
			hidden : function() {
青阳龙野's avatar
青阳龙野 已提交
1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990
				viewer.data('viewer').destroy();
				viewer = null;
			}
		});
	}
	viewer.viewer('view', pvl.index);
	viewer.viewer('show', true);
}

// 用于创建长于2*limit+1长度的图片分页列表
function createViewListByPage() {
	// 初始化分页结构
青阳龙野's avatar
青阳龙野 已提交
1991
	if (viewer == null) {
青阳龙野's avatar
青阳龙野 已提交
1992 1993
		var images = document.createElement("ul");
		var startIndex = (viewerPageIndex - 1) * viewerPageSize;
青阳龙野's avatar
青阳龙野 已提交
1994
		if (viewerPageIndex > 1) {
青阳龙野's avatar
青阳龙野 已提交
1995 1996
			$(images).append("<li><img src='css/left.png' alt='上一页' /></li>");
		}
青阳龙野's avatar
青阳龙野 已提交
1997 1998 1999 2000 2001 2002 2003 2004
		for (var i = 0; i < viewerPageSize
				&& i < (pvl.pictureViewList.length - (viewerPageIndex - 1)
						* viewerPageSize); i++) {
			$(images).append(
					"<li><img src='" + pvl.pictureViewList[startIndex + i].url
							+ "' alt='"
							+ pvl.pictureViewList[startIndex + i].fileName
							+ "' /></li>");
青阳龙野's avatar
青阳龙野 已提交
2005
		}
青阳龙野's avatar
青阳龙野 已提交
2006
		if (viewerPageIndex < viewerTotal) {
青阳龙野's avatar
青阳龙野 已提交
2007 2008 2009
			$(images).append("<li><img src='css/right.png' alt='下一页' /></li>");
		}
		viewer = $(images);
青阳龙野's avatar
青阳龙野 已提交
2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039
		viewer
				.viewer({
					loop : false,
					view : function(event) {
						// 点击的计数为event.detail.index;
						if (event.detail.index == 0 && viewerPageIndex != 1) {
							viewerPageIndex--;
							viewer.data('viewer').destroy();
							viewer.empty();
							viewer = null;
							createViewListByPage();
							if (viewerPageIndex > 1) {
								viewer.viewer('view', viewerPageSize);
							} else {
								viewer.viewer('view', viewerPageSize - 1);
							}
						} else if (event.detail.index == viewerPageSize + 1
								|| (event.detail.index == viewerPageSize && viewerPageIndex == 1)) {
							viewerPageIndex++;
							viewer.data('viewer').destroy();
							viewer.empty();
							viewer = null;
							createViewListByPage();
							viewer.viewer('view', 1);
						}
					},
					hidden : function() {
						viewer.data('viewer').destroy();
						viewer.empty();
						viewer = null;
青阳龙野's avatar
青阳龙野 已提交
2040
					}
青阳龙野's avatar
青阳龙野 已提交
2041
				});
青阳龙野's avatar
青阳龙野 已提交
2042 2043 2044
	}
}

青阳龙野's avatar
青阳龙野 已提交
2045
// 兼容Chrome、IE、FF的Shift判定
青阳龙野's avatar
青阳龙野 已提交
2046 2047 2048
function isShift(event) {
	var e = window.event || event;
	if (e.shiftKey) {
青阳龙野's avatar
青阳龙野 已提交
2049
		return true;
青阳龙野's avatar
青阳龙野 已提交
2050
	} else {
青阳龙野's avatar
青阳龙野 已提交
2051 2052 2053 2054
		return false;
	}
}

青阳龙野's avatar
青阳龙野 已提交
2055
// 选中某一行文件,如果使用Shift点击则为多选
青阳龙野's avatar
青阳龙野 已提交
2056 2057
function checkfile(event, fileId) {
	if (!isShift(event)) {
青阳龙野's avatar
青阳龙野 已提交
2058
		$(".filerow").removeClass("info");
青阳龙野's avatar
青阳龙野 已提交
2059
		$("#" + fileId).addClass("info");
青阳龙野's avatar
青阳龙野 已提交
2060
	} else {
青阳龙野's avatar
青阳龙野 已提交
2061 2062 2063 2064 2065
		if ($("#" + fileId).hasClass("info")) {
			$("#" + fileId).removeClass("info");
		} else {
			$("#" + fileId).addClass("info");
		}
青阳龙野's avatar
青阳龙野 已提交
2066 2067 2068
	}
}

青阳龙野's avatar
青阳龙野 已提交
2069
// 连续选中若干行文件:Shift+双击,选中规则为:前有选前,后有选后,全有也选后。
青阳龙野's avatar
青阳龙野 已提交
2070 2071 2072 2073 2074 2075 2076 2077
function checkConsFile(event, fileId) {
	if (isShift(event)) {
		var endRow = $("#" + fileId);
		var endRowIndex = endRow.index();
		var startRowIndex = $('.filerow.info:last').index();
		if (startRowIndex != -1) {
			if (startRowIndex < endRowIndex) {
				while (endRow[0] && !endRow.hasClass("info")) {
青阳龙野's avatar
青阳龙野 已提交
2078
					endRow.addClass("info");
青阳龙野's avatar
青阳龙野 已提交
2079
					endRow = endRow.prev();
青阳龙野's avatar
青阳龙野 已提交
2080
				}
青阳龙野's avatar
青阳龙野 已提交
2081 2082
			} else {
				while (endRow[0] && !endRow.hasClass("info")) {
青阳龙野's avatar
青阳龙野 已提交
2083
					endRow.addClass("info");
青阳龙野's avatar
青阳龙野 已提交
2084
					endRow = endRow.next();
青阳龙野's avatar
青阳龙野 已提交
2085 2086 2087 2088 2089 2090
				}
			}
		}
	}
}

青阳龙野's avatar
青阳龙野 已提交
2091 2092
// 用于获取全部选中的文件夹和文件ID,该function返回一个对象。
// 该对象中,filesId属性为文件ID,foldersId属性为文件夹ID。两个属性均为JSON数组形式的字符串,可直接发送至服务器。此外还有size,包含了元素的总数。
青阳龙野's avatar
青阳龙野 已提交
2093 2094 2095 2096 2097
function getCheckedFilesAndFolders() {
	var filesAndFolders = new Object();
	filesAndFolders.size = 0;
	var filesId = new Array();
	var foldersId = new Array();
青阳龙野's avatar
青阳龙野 已提交
2098 2099
	var checkedfiles = $(".info").get();
	for (var i = 0; i < checkedfiles.length; i++) {
青阳龙野's avatar
青阳龙野 已提交
2100
		if (checkedfiles[i].getAttribute("iskfolder") == "true") {
青阳龙野's avatar
青阳龙野 已提交
2101
			foldersId.push(checkedfiles[i].id);
青阳龙野's avatar
青阳龙野 已提交
2102
		} else {
青阳龙野's avatar
青阳龙野 已提交
2103 2104 2105 2106 2107 2108 2109 2110
			filesId.push(checkedfiles[i].id);
		}
		filesAndFolders.size++;
	}
	filesAndFolders.filesId = JSON.stringify(filesId);
	filesAndFolders.foldersId = JSON.stringify(foldersId);
	return filesAndFolders;
}
青阳龙野's avatar
青阳龙野 已提交
2111 2112 2113

// 切换全部文件行的选中或非选中
function checkallfile() {
青阳龙野's avatar
青阳龙野 已提交
2114
	if ($(".filerow.info").length == $(".filerow").length) {
青阳龙野's avatar
青阳龙野 已提交
2115
		$(".filerow").removeClass("info");
青阳龙野's avatar
青阳龙野 已提交
2116 2117
	} else {
		$(".filerow").addClass("info");
青阳龙野's avatar
青阳龙野 已提交
2118 2119 2120
	}
}

2121
// 显示打包下载模态框
青阳龙野's avatar
青阳龙野 已提交
2122
function showDownloadAllCheckedModel() {
青阳龙野's avatar
青阳龙野 已提交
2123
	if (!folderView.enableDownloadZip) {
青阳龙野's avatar
青阳龙野 已提交
2124 2125
		return;
	}
2126 2127
	$("#downloadAllCheckedBox").html("");
	$("#downloadAllCheckedLoad").text("");
青阳龙野's avatar
青阳龙野 已提交
2128
	var faf = getCheckedFilesAndFolders();
青阳龙野's avatar
青阳龙野 已提交
2129
	if (faf.size == 0) {
青阳龙野's avatar
青阳龙野 已提交
2130
		$("#downloadAllCheckedName").html(checkFilesTip);
青阳龙野's avatar
青阳龙野 已提交
2131
	} else {
青阳龙野's avatar
青阳龙野 已提交
2132
		$("#downloadAllCheckedName").text("提示:您确认要打包并下载这" + faf.size + "项么?");
2133
		$("#downloadAllCheckedBox")
青阳龙野's avatar
青阳龙野 已提交
2134
				.html(
2135 2136
						"<button id='dclmbutton' type='button' class='btn btn-primary' onclick='downloadAllChecked()'>开始下载</button>");
		$("#dclmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
2137
	}
青阳龙野's avatar
青阳龙野 已提交
2138
	$("#cancelDownloadAllCheckedBtn").attr('disabled', false);
2139
	$("#downloadAllCheckedModal").modal('toggle');
青阳龙野's avatar
青阳龙野 已提交
2140 2141 2142 2143
}

// 下载选中的所有文件
function downloadAllChecked() {
2144
	$("#dclmbutton").attr('disabled', true);
青阳龙野's avatar
青阳龙野 已提交
2145 2146
	$("#cancelDownloadAllCheckedBtn").attr('disabled', true);
	var faf = getCheckedFilesAndFolders();
2147
	$("#downloadAllCheckedName").text(
青阳龙野's avatar
青阳龙野 已提交
2148
			"提示:服务器正在对选中资源进行压缩(共" + faf.size
青阳龙野's avatar
青阳龙野 已提交
2149
					+ "项),这可能需要一些时间(文件越大耗时越长),压缩完成将自动开始下载。");
青阳龙野's avatar
青阳龙野 已提交
2150 2151
	// 计算预计耗时
	$.ajax({
青阳龙野's avatar
青阳龙野 已提交
2152 2153 2154 2155 2156
		url : 'homeController/getPackTime.ajax',
		type : 'POST',
		data : {
			strIdList : faf.filesId,
			strFidList : faf.foldersId
青阳龙野's avatar
青阳龙野 已提交
2157
		},
青阳龙野's avatar
青阳龙野 已提交
2158 2159 2160
		dataType : 'text',
		success : function(result) {
			if (result != "0") {
青阳龙野's avatar
青阳龙野 已提交
2161
				var count = 0;
青阳龙野's avatar
青阳龙野 已提交
2162 2163 2164
				$("#downloadAllCheckedLoad").text(
						"已耗时:" + count + "秒(预计耗时:" + result + "");
				zipTimer = setInterval(function() {
青阳龙野's avatar
青阳龙野 已提交
2165
					count++;
青阳龙野's avatar
青阳龙野 已提交
2166 2167 2168 2169
					$("#downloadAllCheckedLoad").text(
							"已耗时:" + count + "秒(预计耗时:" + result + "");
				}, 1000);
			} else {
青阳龙野's avatar
青阳龙野 已提交
2170
				var count = 0;
青阳龙野's avatar
青阳龙野 已提交
2171 2172
				$("#downloadAllCheckedLoad").text("已耗时:" + count + "");
				zipTimer = setInterval(function() {
青阳龙野's avatar
青阳龙野 已提交
2173
					count++;
青阳龙野's avatar
青阳龙野 已提交
2174 2175
					$("#downloadAllCheckedLoad").text("已耗时:" + count + "");
				}, 1000);
青阳龙野's avatar
青阳龙野 已提交
2176 2177
			}
		},
青阳龙野's avatar
青阳龙野 已提交
2178
		error : function() {
青阳龙野's avatar
青阳龙野 已提交
2179
			$("#downloadAllCheckedLoad").text("(无法获取预计耗时)");
2180
		}
青阳龙野's avatar
青阳龙野 已提交
2181 2182
	});
	// 同时发送压缩下载请求
2183 2184 2185 2186
	$.ajax({
		type : "POST",
		url : "homeController/downloadCheckedFiles.ajax",
		data : {
青阳龙野's avatar
青阳龙野 已提交
2187 2188
			strIdList : faf.filesId,
			strFidList : faf.foldersId
2189 2190 2191
		},
		dataType : "text",
		success : function(result) {
青阳龙野's avatar
青阳龙野 已提交
2192
			if (zipTimer != null) {
青阳龙野's avatar
青阳龙野 已提交
2193 2194
				window.clearInterval(zipTimer);
			}
2195 2196 2197
			if (result == "ERROR") {
				$("#downloadAllCheckedName")
						.text("提示:压缩过程出错。无法完成压缩,请重试或告知管理员。");
青阳龙野's avatar
青阳龙野 已提交
2198 2199
				$("#dclmbutton").attr('disabled', false);
				$("#cancelDownloadAllCheckedBtn").attr('disabled', false);
2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219
			} 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
青阳龙野 已提交
2220 2221
			$("#dclmbutton").attr('disabled', false);
			$("#cancelDownloadAllCheckedBtn").attr('disabled', false);
2222 2223
		}
	});
青阳龙野's avatar
青阳龙野 已提交
2224 2225 2226 2227 2228
}

// 删除选中的所有文件
function showDeleteAllCheckedModel() {
	$('#deleteFileBox').html("");
青阳龙野's avatar
青阳龙野 已提交
2229
	var faf = getCheckedFilesAndFolders();
青阳龙野's avatar
青阳龙野 已提交
2230
	$("#dfmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
2231
	$("#cancelDeleteFileBox").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
2232
	if (faf.size == 0) {
青阳龙野's avatar
青阳龙野 已提交
2233
		$('#deleteFileMessage').html(checkFilesTip);
青阳龙野's avatar
青阳龙野 已提交
2234 2235 2236 2237
	} else {
		$('#deleteFileBox')
				.html(
						"<button id='dfmbutton' type='button' class='btn btn-danger' onclick='deleteAllChecked()'>全部删除</button>");
青阳龙野's avatar
青阳龙野 已提交
2238
		$('#deleteFileMessage').text("提示:确定要彻底删除这" + faf.size + "项么?该操作不可恢复!");
青阳龙野's avatar
青阳龙野 已提交
2239 2240 2241 2242 2243 2244 2245
	}
	$('#deleteFileModal').modal('toggle');
}

// 删除选中的所有文件
function deleteAllChecked() {
	// TODO 提交全部删除请求
青阳龙野's avatar
青阳龙野 已提交
2246
	var faf = getCheckedFilesAndFolders();
青阳龙野's avatar
青阳龙野 已提交
2247
	$("#dfmbutton").attr('disabled', true);
青阳龙野's avatar
青阳龙野 已提交
2248
	$("#cancelDeleteFileBox").attr('disabled', true);
青阳龙野's avatar
青阳龙野 已提交
2249 2250 2251 2252 2253
	$('#deleteFileMessage').text("提示:正在删除,请稍候...");
	$.ajax({
		type : "POST",
		dataType : "text",
		data : {
青阳龙野's avatar
青阳龙野 已提交
2254 2255
			strIdList : faf.filesId,
			strFidList : faf.foldersId
青阳龙野's avatar
青阳龙野 已提交
2256 2257 2258 2259
		},
		url : "homeController/deleteCheckedFiles.ajax",
		success : function(result) {
			if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
2260
				window.location.href = "prv/login.html";
青阳龙野's avatar
青阳龙野 已提交
2261 2262 2263 2264
			} else {
				if (result == "noAuthorized") {
					$('#deleteFileMessage').text("提示:您的操作未被授权,删除失败");
					$("#dfmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
2265
					$("#cancelDeleteFileBox").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
2266 2267 2268
				} else if (result == "errorParameter") {
					$('#deleteFileMessage').text("提示:参数不正确,未能全部删除文件");
					$("#dfmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
2269
					$("#cancelDeleteFileBox").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
2270 2271 2272
				} else if (result == "cannotDeleteFile") {
					$('#deleteFileMessage').text("提示:出现意外错误,可能未能删除全部文件");
					$("#dfmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
2273
					$("#cancelDeleteFileBox").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
2274 2275 2276 2277 2278 2279
				} else if (result == "deleteFileSuccess") {
					$('#deleteFileModal').modal('hide');
					showFolderView(locationpath);
				} else {
					$('#deleteFileMessage').text("提示:出现意外错误,可能未能删除全部文件");
					$("#dfmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
2280
					$("#cancelDeleteFileBox").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
2281 2282 2283 2284 2285 2286
				}
			}
		},
		error : function() {
			$('#deleteFileMessage').text("提示:出现意外错误,可能未能删除全部文件");
			$("#dfmbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
2287
			$("#cancelDeleteFileBox").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
2288 2289
		}
	});
青阳龙野's avatar
青阳龙野 已提交
2290 2291 2292 2293 2294
}

// 播放音乐
function playAudio(fileId) {
	$('#audioPlayerModal').modal('show');
青阳龙野's avatar
青阳龙野 已提交
2295 2296
	if (pingInt == null) {
		pingInt = setInterval("ping()", 60000);// 播放中开始计时应答
青阳龙野's avatar
青阳龙野 已提交
2297
	}
青阳龙野's avatar
青阳龙野 已提交
2298 2299 2300 2301 2302 2303
	if (ap == null) {
		ap = new APlayer({
			container : document.getElementById('aplayer'),
			lrcType : 3,
			mutex : true,
			volume : 0.7,
青阳龙野's avatar
青阳龙野 已提交
2304
			theme : '#EDEDED',
青阳龙野's avatar
青阳龙野 已提交
2305 2306
			audio : []
		});
青阳龙野's avatar
青阳龙野 已提交
2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322
		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>");
						});
青阳龙野's avatar
青阳龙野 已提交
2323 2324 2325
	}
	ap.list.clear();
	$.ajax({
青阳龙野's avatar
青阳龙野 已提交
2326 2327 2328
		url : 'homeController/playAudios.ajax',
		data : {
			fileId : fileId
青阳龙野's avatar
青阳龙野 已提交
2329
		},
青阳龙野's avatar
青阳龙野 已提交
2330 2331 2332 2333
		type : 'POST',
		dataType : 'text',
		success : function(result) {
			var ail = eval("(" + result + ")");
青阳龙野's avatar
青阳龙野 已提交
2334
			// 避免存在恶意标签注入在文件名中
青阳龙野's avatar
青阳龙野 已提交
2335 2336 2337 2338 2339 2340 2341 2342 2343
			for (var i = ail.index; i < ail.as.length; i++) {
				ail.as[i].name = ail.as[i].name.replace('\'', '&#39;').replace(
						'<', '&lt;').replace('>', '&gt;');
				ap.list.add(ail.as[i]);
			}
			for (var i = 0; i < ail.index; i++) {
				ail.as[i].name = ail.as[i].name.replace('\'', '&#39;').replace(
						'<', '&lt;').replace('>', '&gt;');
				ap.list.add(ail.as[i]);
青阳龙野's avatar
青阳龙野 已提交
2344
			}
青阳龙野's avatar
青阳龙野 已提交
2345 2346
			audio_play();
		},
青阳龙野's avatar
青阳龙野 已提交
2347
		error : function() {
青阳龙野's avatar
青阳龙野 已提交
2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384
			alert("错误:无法获取音乐列表,请稍后再试");
			closeAudioPlayer();
		}
	});
}

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

// 切换按钮状态与
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%
青阳龙野's avatar
青阳龙野 已提交
2385 2386
function audio_vulome_up() {
	ap.volume(ap.audio.volume + 0.1, true);
青阳龙野's avatar
青阳龙野 已提交
2387 2388 2389
}

// 音量减少,每次10%
青阳龙野's avatar
青阳龙野 已提交
2390 2391
function audio_vulome_down() {
	ap.volume(ap.audio.volume - 0.1, true);
青阳龙野's avatar
青阳龙野 已提交
2392 2393 2394
}

// 按文件名排序
青阳龙野's avatar
青阳龙野 已提交
2395 2396
function sortbyfn() {
	if (!loadingComplete) {
青阳龙野's avatar
青阳龙野 已提交
2397 2398
		return;
	}
青阳龙野's avatar
青阳龙野 已提交
2399 2400
	if ($("#sortByCD,#sortByFS,#sortByCN,#sortByOR").hasClass(
			"glyphicon glyphicon-hourglass")) {
青阳龙野's avatar
青阳龙野 已提交
2401 2402
		return;
	}
青阳龙野's avatar
青阳龙野 已提交
2403 2404 2405
	$("#sortByCD").removeClass();
	$("#sortByFS").removeClass();
	$("#sortByCN").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2406
	$("#sortByOR").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2407 2408 2409
	var order = 1;
	if ($("#sortByFN").hasClass('glyphicon-triangle-bottom')) {
		order = -1;
青阳龙野's avatar
青阳龙野 已提交
2410
	}
青阳龙野's avatar
青阳龙野 已提交
2411 2412 2413
	$("#sortByFN").removeClass();
	$("#sortByFN").addClass("glyphicon glyphicon-hourglass");
	// 另开一个计时器进行排序操作,避免因卡死导致加载动画无法显示
青阳龙野's avatar
青阳龙野 已提交
2414 2415 2416
	setTimeout(function() {
		folderView.fileList.sort(function(v1, v2) {
			return order * v2.fileName.localeCompare(v1.fileName, "zh");
青阳龙野's avatar
青阳龙野 已提交
2417
		});
青阳龙野's avatar
青阳龙野 已提交
2418 2419
		folderView.folderList.sort(function(v1, v2) {
			return order * v2.folderName.localeCompare(v1.folderName, "zh");
青阳龙野's avatar
青阳龙野 已提交
2420 2421 2422
		});
		showFolderTable(folderView);
		$("#sortByFN").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2423
		if (order == -1) {
青阳龙野's avatar
青阳龙野 已提交
2424
			$("#sortByFN").addClass("glyphicon glyphicon-triangle-top");
青阳龙野's avatar
青阳龙野 已提交
2425
		} else {
青阳龙野's avatar
青阳龙野 已提交
2426 2427 2428
			$("#sortByFN").addClass("glyphicon glyphicon-triangle-bottom");
		}
	}, 0);
青阳龙野's avatar
青阳龙野 已提交
2429 2430 2431
}

// 按创建日期排序
青阳龙野's avatar
青阳龙野 已提交
2432 2433
function sortbycd() {
	if (!loadingComplete) {
青阳龙野's avatar
青阳龙野 已提交
2434 2435
		return;
	}
青阳龙野's avatar
青阳龙野 已提交
2436 2437
	if ($("#sortByFN,#sortByFS,#sortByCN,#sortByOR").hasClass(
			"glyphicon glyphicon-hourglass")) {
青阳龙野's avatar
青阳龙野 已提交
2438 2439
		return;
	}
青阳龙野's avatar
青阳龙野 已提交
2440 2441 2442
	$("#sortByFN").removeClass();
	$("#sortByFS").removeClass();
	$("#sortByCN").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2443
	$("#sortByOR").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2444 2445 2446
	var order = 1;
	if ($("#sortByCD").hasClass('glyphicon-triangle-bottom')) {
		order = -1;
青阳龙野's avatar
青阳龙野 已提交
2447
	}
青阳龙野's avatar
青阳龙野 已提交
2448 2449
	$("#sortByCD").removeClass();
	$("#sortByCD").addClass("glyphicon glyphicon-hourglass");
青阳龙野's avatar
青阳龙野 已提交
2450 2451 2452 2453 2454 2455 2456 2457
	setTimeout(function() {
		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()));
青阳龙野's avatar
青阳龙野 已提交
2458 2459
			return order * res;
		});
青阳龙野's avatar
青阳龙野 已提交
2460 2461 2462 2463 2464 2465 2466
		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()));
青阳龙野's avatar
青阳龙野 已提交
2467 2468 2469 2470
			return order * res;
		});
		showFolderTable(folderView);
		$("#sortByCD").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2471
		if (order == -1) {
青阳龙野's avatar
青阳龙野 已提交
2472
			$("#sortByCD").addClass("glyphicon glyphicon-triangle-top");
青阳龙野's avatar
青阳龙野 已提交
2473
		} else {
青阳龙野's avatar
青阳龙野 已提交
2474 2475 2476
			$("#sortByCD").addClass("glyphicon glyphicon-triangle-bottom");
		}
	}, 0);
青阳龙野's avatar
青阳龙野 已提交
2477 2478 2479
}

// 按文件大小排序
青阳龙野's avatar
青阳龙野 已提交
2480 2481
function sortbyfs() {
	if (!loadingComplete) {
青阳龙野's avatar
青阳龙野 已提交
2482 2483
		return;
	}
青阳龙野's avatar
青阳龙野 已提交
2484 2485
	if ($("#sortByFN,#sortByCD,#sortByCN,#sortByOR").hasClass(
			"glyphicon glyphicon-hourglass")) {
青阳龙野's avatar
青阳龙野 已提交
2486 2487
		return;
	}
青阳龙野's avatar
青阳龙野 已提交
2488 2489 2490
	$("#sortByFN").removeClass();
	$("#sortByCD").removeClass();
	$("#sortByCN").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2491
	$("#sortByOR").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2492 2493 2494
	var order = 1;
	if ($("#sortByFS").hasClass("glyphicon-triangle-bottom")) {
		order = -1;
青阳龙野's avatar
青阳龙野 已提交
2495 2496 2497
	}
	$("#sortByFS").removeClass();
	$("#sortByFS").addClass("glyphicon glyphicon-hourglass");
青阳龙野's avatar
青阳龙野 已提交
2498 2499
	setTimeout(function() {
		folderView.fileList.sort(function(v1, v2) {
青阳龙野's avatar
青阳龙野 已提交
2500
			return order * (v1.fileSize - v2.fileSize);
青阳龙野's avatar
青阳龙野 已提交
2501
		});
青阳龙野's avatar
青阳龙野 已提交
2502
		showFolderTable(folderView);
青阳龙野's avatar
青阳龙野 已提交
2503
		$("#sortByFS").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2504
		if (order == -1) {
青阳龙野's avatar
青阳龙野 已提交
2505
			$("#sortByFS").addClass("glyphicon glyphicon-triangle-top");
青阳龙野's avatar
青阳龙野 已提交
2506
		} else {
青阳龙野's avatar
青阳龙野 已提交
2507 2508 2509
			$("#sortByFS").addClass("glyphicon glyphicon-triangle-bottom");
		}
	}, 0);
青阳龙野's avatar
青阳龙野 已提交
2510 2511 2512
}

// 按创建者排序
青阳龙野's avatar
青阳龙野 已提交
2513 2514
function sortbycn() {
	if (!loadingComplete) {
青阳龙野's avatar
青阳龙野 已提交
2515 2516
		return;
	}
青阳龙野's avatar
青阳龙野 已提交
2517 2518
	if ($("#sortByFN,#sortByCD,#sortByFS,#sortByOR").hasClass(
			"glyphicon glyphicon-hourglass")) {
青阳龙野's avatar
青阳龙野 已提交
2519 2520
		return;
	}
青阳龙野's avatar
青阳龙野 已提交
2521 2522 2523
	$("#sortByFN").removeClass();
	$("#sortByCD").removeClass();
	$("#sortByFS").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2524
	$("#sortByOR").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2525 2526 2527
	var order = 1;
	if ($("#sortByCN").hasClass('glyphicon-triangle-bottom')) {
		order = -1;
青阳龙野's avatar
青阳龙野 已提交
2528
	}
青阳龙野's avatar
青阳龙野 已提交
2529 2530
	$("#sortByCN").removeClass();
	$("#sortByCN").addClass("glyphicon glyphicon-hourglass");
青阳龙野's avatar
青阳龙野 已提交
2531 2532 2533
	setTimeout(function() {
		folderView.fileList.sort(function(v1, v2) {
			return order * v2.fileCreator.localeCompare(v1.fileCreator, "zh");
青阳龙野's avatar
青阳龙野 已提交
2534
		});
青阳龙野's avatar
青阳龙野 已提交
2535 2536 2537
		folderView.folderList.sort(function(v1, v2) {
			return order
					* v2.folderCreator.localeCompare(v1.folderCreator, "zh");
青阳龙野's avatar
青阳龙野 已提交
2538 2539 2540
		});
		showFolderTable(folderView);
		$("#sortByCN").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2541
		if (order == -1) {
青阳龙野's avatar
青阳龙野 已提交
2542
			$("#sortByCN").addClass("glyphicon glyphicon-triangle-top");
青阳龙野's avatar
青阳龙野 已提交
2543
		} else {
青阳龙野's avatar
青阳龙野 已提交
2544 2545 2546
			$("#sortByCN").addClass("glyphicon glyphicon-triangle-bottom");
		}
	}, 0);
青阳龙野's avatar
青阳龙野 已提交
2547 2548 2549
}

// 显示原始的顺序
青阳龙野's avatar
青阳龙野 已提交
2550 2551
function showOriginFolderView() {
	if (!loadingComplete) {
青阳龙野's avatar
青阳龙野 已提交
2552 2553
		return;
	}
青阳龙野's avatar
青阳龙野 已提交
2554 2555
	if ($("#sortByFN,#sortByCD,#sortByFS,#sortByCN").hasClass(
			"glyphicon glyphicon-hourglass")) {
青阳龙野's avatar
青阳龙野 已提交
2556 2557
		return;
	}
青阳龙野's avatar
青阳龙野 已提交
2558 2559 2560 2561
	$("#sortByFN").removeClass();
	$("#sortByCD").removeClass();
	$("#sortByFS").removeClass();
	$("#sortByCN").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2562
	$("#sortByOR").addClass("glyphicon glyphicon-hourglass");
青阳龙野's avatar
青阳龙野 已提交
2563 2564 2565 2566 2567
	setTimeout(function() {
		if (screenedFoldrView != null) {
			folderView = $.extend(true, {}, screenedFoldrView);
		} else {
			folderView = $.extend(true, {}, originFolderView);
青阳龙野's avatar
青阳龙野 已提交
2568 2569 2570 2571
		}
		showFolderTable(folderView);
		$("#sortByOR").removeClass();
	}, 0);
青阳龙野's avatar
青阳龙野 已提交
2572 2573
}

青阳龙野's avatar
青阳龙野 已提交
2574 2575 2576 2577 2578 2579
// 执行“剪切”操作
function cutFile() {
	checkedMovefiles = getCheckedFilesAndFolders();
	if (checkedMovefiles == undefined || checkedMovefiles.size == 0) {
		// 如果未选中任何文件,则提示用户要先选
		$('#moveFilesMessage').html(checkFilesTip);
青阳龙野's avatar
青阳龙野 已提交
2580 2581
		$("#selectFileMoveModelAsAll").removeAttr("checked");
		$("#selectFileMoveModelAlert").hide();
青阳龙野's avatar
青阳龙野 已提交
2582
		$('#moveFilesModal').modal('show');
青阳龙野's avatar
青阳龙野 已提交
2583 2584 2585 2586
	} else {
		// 否则,隐藏“剪切”和“复制”按钮,显示“粘贴”按钮
		if (checkedMovefiles.size < 100) {
			$("#stickFilesCount").text("" + checkedMovefiles.size + "");
青阳龙野's avatar
青阳龙野 已提交
2587
		} else {
青阳龙野's avatar
青阳龙野 已提交
2588
			$("#stickFilesCount").text("(99+)");
青阳龙野's avatar
青阳龙野 已提交
2589
		}
青阳龙野's avatar
青阳龙野 已提交
2590 2591 2592 2593 2594 2595 2596
		$("#copyFileButtonLi").removeClass("show");
		$("#copyFileButtonLi").addClass("hidden");
		$("#cutFileButtonLi").removeClass("show");
		$("#cutFileButtonLi").addClass("hidden");
		$("#stickFileButtonLi").removeClass("hidden");
		$("#stickFileButtonLi").addClass("show");
		isCopy = false;
青阳龙野's avatar
青阳龙野 已提交
2597 2598 2599
	}
}

青阳龙野's avatar
青阳龙野 已提交
2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624
// 执行“复制”操作
function copyFile() {
	checkedMovefiles = getCheckedFilesAndFolders();
	if (checkedMovefiles == undefined || checkedMovefiles.size == 0) {
		// 如果未选中任何文件,则提示用户要先选
		$('#moveFilesMessage').html(checkFilesTip);
		$("#selectFileMoveModelAsAll").removeAttr("checked");
		$("#selectFileMoveModelAlert").hide();
		$('#moveFilesModal').modal('show');
	} else {
		// 否则,隐藏“剪切”和“复制”按钮,显示“粘贴”按钮
		if (checkedMovefiles.size < 100) {
			$("#stickFilesCount").text("" + checkedMovefiles.size + "");
		} else {
			$("#stickFilesCount").text("(99+)");
		}
		$("#copyFileButtonLi").removeClass("show");
		$("#copyFileButtonLi").addClass("hidden");
		$("#cutFileButtonLi").removeClass("show");
		$("#cutFileButtonLi").addClass("hidden");
		$("#stickFileButtonLi").removeClass("hidden");
		$("#stickFileButtonLi").addClass("show");
		isCopy = true;
	}
}
青阳龙野's avatar
青阳龙野 已提交
2625

青阳龙野's avatar
青阳龙野 已提交
2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674
// 执行“粘贴”操作
function stickFile() {
	if (checkedMovefiles !== undefined && checkedMovefiles.size > 0) {
		if (isCopy) {
			$('#moveFilesMessage').text(
					"提示:确定将这" + checkedMovefiles.size + "项复制到当前位置么?");
			$('#moveFilesBox')
					.html(
							"<button id='dmvfbutton' type='button' class='btn btn-primary' onclick='doMoveFiles()'>全部复制</button>");
		} else {
			$('#moveFilesMessage').text(
					"提示:确定将这" + checkedMovefiles.size + "项移动到当前位置么?");
			$('#moveFilesBox')
					.html(
							"<button id='dmvfbutton' type='button' class='btn btn-danger' onclick='doMoveFiles()'>全部移动</button>");
		}
		$("#selectFileMoveModelAsAll").removeAttr("checked");
		$("#cancelMoveFilesBtn").attr('disabled', false);
		$("#selectFileMoveModelAlert").hide();
		$('#moveFilesModal').modal('show');
	}
}

// 先行确认文件移动操作
function doMoveFiles() {
	$("#dmvfbutton").attr('disabled', true);
	$("#cancelMoveFilesBtn").attr('disabled', true);
	var method = "MOVE";
	if (isCopy) {
		$('#moveFilesMessage').text("提示:正在复制,请稍候...");
		method = "COPY";
	} else {
		$('#moveFilesMessage').text("提示:正在移动,请稍候...");
	}
	// 确认移动目标位置
	$
			.ajax({
				type : "POST",
				dataType : "text",
				data : {
					strIdList : checkedMovefiles.filesId,
					strFidList : checkedMovefiles.foldersId,
					locationpath : locationpath,
					method : method
				},
				url : "homeController/confirmMoveFiles.ajax",
				success : function(result) {
					if (result == "mustLogin") {
						window.location.href = "prv/login.html";
青阳龙野's avatar
青阳龙野 已提交
2675
					} else {
青阳龙野's avatar
青阳龙野 已提交
2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746
						switch (result) {
						case "noAuthorized":
							$('#moveFilesMessage').text("提示:您的操作未被授权,操作失败");
							$("#dmvfbutton").attr('disabled', false);
							$("#cancelMoveFilesBtn").attr('disabled', false);
							break;
						case "errorParameter":
							$('#moveFilesMessage').text(
									"提示:参数不正确,无法完成此操作,请刷新后重试");
							$("#dmvfbutton").attr('disabled', false);
							$("#cancelMoveFilesBtn").attr('disabled', false);
							break;
						case "cannotMoveFiles":
							$('#moveFilesMessage').text(
									"提示:出现意外错误,可能未能完成此操作,请刷新后重试");
							$("#dmvfbutton").attr('disabled', false);
							$("#cancelMoveFilesBtn").attr('disabled', false);
							break;
						case "filesTotalOutOfLimit":
							$('#moveFilesMessage').text(
									"提示:该文件夹内存储的文件数量已达上限,无法添加更多文件");
							$("#dmvfbutton").attr('disabled', false);
							$("#cancelMoveFilesBtn").attr('disabled', false);
							break;
						case "foldersTotalOutOfLimit":
							$('#moveFilesMessage').text(
									"提示:该文件夹内存储的文件夹数量已达上限,无法添加更多文件夹");
							$("#dmvfbutton").attr('disabled', false);
							$("#cancelMoveFilesBtn").attr('disabled', false);
							break;
						case "confirmMoveFiles":
							strMoveOptMap = {};
							sendMoveFilesReq();
							break;
						default:
							if (result.startsWith("duplicationFileName:")) {
								repeMap = eval("(" + result.substring(20) + ")");
								repeIndex = 0;
								strMoveOptMap = {};
								mRepeSize = repeMap.repeFolders.length
										+ repeMap.repeNodes.length;
								if (repeMap.repeFolders.length > 0) {
									$("#mrepeFileName")
											.text(
													repeMap.repeFolders[repeIndex].folderName);
								} else {
									$("#mrepeFileName")
											.text(
													repeMap.repeNodes[repeIndex].fileName);
								}
								var authList = originFolderView.authList;
								if (checkAuth(authList, "D")) {
									$("#movecoverbtn").show();
								} else {
									$("#movecoverbtn").hide();
								}
								$("#selectFileMoveModelAlert").show();
							} else if (result
									.startsWith("CANT_MOVE_TO_INSIDE:")) {
								$('#moveFilesMessage').text(
										"错误:不能将一个文件夹移动到其自身内部:"
												+ result.substring(20));
							} else {
								$('#moveFilesMessage').text(
										"提示:出现意外错误,可能未能完成此操作,请刷新后重试");
								$("#dmvfbutton").attr('disabled', false);
								$("#cancelMoveFilesBtn")
										.attr('disabled', false);
							}
							break;
						}
青阳龙野's avatar
青阳龙野 已提交
2747
					}
青阳龙野's avatar
青阳龙野 已提交
2748 2749 2750 2751 2752
				},
				error : function() {
					$('#moveFilesMessage').text("提示:出现意外错误,可能未能完成此操作,请刷新后重试");
					$("#dmvfbutton").attr('disabled', false);
					$("#cancelMoveFilesBtn").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
2753
				}
青阳龙野's avatar
青阳龙野 已提交
2754
			});
青阳龙野's avatar
青阳龙野 已提交
2755 2756
}

青阳龙野's avatar
青阳龙野 已提交
2757 2758 2759 2760 2761 2762 2763 2764 2765
// 移动或复制——对冲突的文件进行依次询问
function selectFileMoveModel(t) {
	if ($("#selectFileMoveModelAsAll").prop("checked")) {
		while (repeIndex < mRepeSize) {
			if (repeIndex < repeMap.repeFolders.length) {
				strMoveOptMap[repeMap.repeFolders[repeIndex].folderId] = t;
			} else {
				strMoveOptMap[repeMap.repeNodes[repeIndex
						- repeMap.repeFolders.length].fileId] = t;
青阳龙野's avatar
青阳龙野 已提交
2766 2767 2768 2769 2770 2771
			}
			repeIndex++;
		}
		$("#selectFileMoveModelAlert").hide();
		sendMoveFilesReq();
	}
青阳龙野's avatar
青阳龙野 已提交
2772 2773 2774 2775
	if (repeIndex < repeMap.repeFolders.length) {
		strMoveOptMap[repeMap.repeFolders[repeIndex].folderId] = t;
	} else {
		strMoveOptMap[repeMap.repeNodes[repeIndex - repeMap.repeFolders.length].fileId] = t;
青阳龙野's avatar
青阳龙野 已提交
2776 2777
	}
	repeIndex++;
青阳龙野's avatar
青阳龙野 已提交
2778 2779
	if (repeIndex < mRepeSize) {
		if (repeIndex < repeMap.repeFolders.length) {
青阳龙野's avatar
青阳龙野 已提交
2780
			$("#mrepeFileName").text(repeMap.repeFolders[repeIndex].folderName);
青阳龙野's avatar
青阳龙野 已提交
2781 2782 2783 2784 2785
		} else {
			$("#mrepeFileName")
					.text(
							repeMap.repeNodes[repeIndex
									- repeMap.repeFolders.length].fileName);
青阳龙野's avatar
青阳龙野 已提交
2786
		}
青阳龙野's avatar
青阳龙野 已提交
2787
	} else {
青阳龙野's avatar
青阳龙野 已提交
2788 2789 2790 2791 2792
		$("#selectFileMoveModelAlert").hide();
		sendMoveFilesReq();
	}
}

青阳龙野's avatar
青阳龙野 已提交
2793 2794 2795
// 正式执行移动或复制文件操作
function sendMoveFilesReq() {
	// 取到对冲突文件的操作列表
青阳龙野's avatar
青阳龙野 已提交
2796
	var strOptMap = JSON.stringify(strMoveOptMap);
青阳龙野's avatar
青阳龙野 已提交
2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862
	// 取到操作类型,是移动还是复制
	var method = "MOVE";
	if (isCopy) {
		method = "COPY";
	}
	$
			.ajax({
				type : "POST",
				dataType : "text",
				data : {
					strIdList : checkedMovefiles.filesId,
					strFidList : checkedMovefiles.foldersId,
					strOptMap : strOptMap,
					locationpath : locationpath,
					method : method
				},
				url : "homeController/moveCheckedFiles.ajax",
				success : function(result) {
					if (result == "mustLogin") {
						window.location.href = "prv/login.html";
					} else {
						switch (result) {
						case "noAuthorized":
							$('#moveFilesMessage').text("提示:您的操作未被授权,操作失败");
							$("#dmvfbutton").attr('disabled', false);
							$("#cancelMoveFilesBtn").attr('disabled', false);
							break;
						case "errorParameter":
							$('#moveFilesMessage').text(
									"提示:参数不正确,无法完成此操作,请刷新后重试");
							$("#dmvfbutton").attr('disabled', false);
							$("#cancelMoveFilesBtn").attr('disabled', false);
							break;
						case "filesTotalOutOfLimit":
							$('#moveFilesMessage').text(
									"提示:该文件夹内存储的文件数量已达上限,无法添加更多文件");
							$("#dmvfbutton").attr('disabled', false);
							$("#cancelMoveFilesBtn").attr('disabled', false);
							break;
						case "foldersTotalOutOfLimit":
							$('#moveFilesMessage').text(
									"提示:该文件夹内存储的文件夹数量已达上限,无法添加更多文件夹");
							$("#dmvfbutton").attr('disabled', false);
							$("#cancelMoveFilesBtn").attr('disabled', false);
							break;
						case "cannotMoveFiles":
							$('#moveFilesMessage').text(
									"提示:出现意外错误,可能未能完成此操作,请刷新后重试");
							$("#dmvfbutton").attr('disabled', false);
							$("#cancelMoveFilesBtn").attr('disabled', false);
							break;
						case "moveFilesSuccess":
							$('#moveFilesModal').modal('hide');
							showFolderView(locationpath);
							break;
						default:
							$('#moveFilesMessage').text(
									"提示:出现意外错误,可能未能完成此操作,请刷新后重试");
							$("#dmvfbutton").attr('disabled', false);
							$("#cancelMoveFilesBtn").attr('disabled', false);
							break;
						}
					}
				},
				error : function() {
					$('#moveFilesMessage').text("提示:出现意外错误,可能未能完成此操作,请刷新后重试");
青阳龙野's avatar
青阳龙野 已提交
2863
					$("#dmvfbutton").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
2864
					$("#cancelMoveFilesBtn").attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
2865
				}
青阳龙野's avatar
青阳龙野 已提交
2866
			});
青阳龙野's avatar
青阳龙野 已提交
2867 2868 2869 2870 2871
}

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

// 执行搜索功能
青阳龙野's avatar
青阳龙野 已提交
2872 2873 2874
function doSearchFile() {
	var keyworld = $("#sreachKeyWordIn").val();
	if (keyworld.length != 0) {
青阳龙野's avatar
青阳龙野 已提交
2875
		// 如果用户在搜索字段中声明了全局搜索
青阳龙野's avatar
青阳龙野 已提交
2876
		if (keyworld.startsWith("all:") || keyworld.startsWith("all:")) {
青阳龙野's avatar
青阳龙野 已提交
2877
			selectInCompletePath(keyworld.substring(4));
青阳龙野's avatar
青阳龙野 已提交
2878
		} else {
青阳龙野's avatar
青阳龙野 已提交
2879 2880 2881 2882
			startLoading();
			selectInThisPath(keyworld);// 否则,均在本级下搜索
			endLoading();
		}
青阳龙野's avatar
青阳龙野 已提交
2883 2884
	} else {
		if (folderView.keyWorld != null) {
青阳龙野's avatar
青阳龙野 已提交
2885
			showFolderView(locationpath);
青阳龙野's avatar
青阳龙野 已提交
2886 2887
		} else {
			screenedFoldrView = null;
青阳龙野's avatar
青阳龙野 已提交
2888 2889
			showOriginFolderView();
		}
青阳龙野's avatar
青阳龙野 已提交
2890 2891 2892 2893
	}
}

// 在本级内搜索
青阳龙野's avatar
青阳龙野 已提交
2894 2895 2896 2897 2898 2899 2900 2901 2902 2903
function selectInThisPath(keyworld) {
	try {
		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]);
青阳龙野's avatar
青阳龙野 已提交
2904 2905
			}
		}
青阳龙野's avatar
青阳龙野 已提交
2906 2907
		for (var i = 0, j = originFolderView.fileList.length; i < j; i++) {
			if (reg.test(originFolderView.fileList[i].fileName)) {
青阳龙野's avatar
青阳龙野 已提交
2908 2909 2910 2911 2912 2913 2914
				screenedFoldrView.fileList.push(originFolderView.fileList[i]);
			}
		}
		$("#sortByFN").removeClass();
		$("#sortByCD").removeClass();
		$("#sortByFS").removeClass();
		$("#sortByCN").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2915
		$("#sortByOR").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2916
		folderView = $.extend(true, {}, screenedFoldrView);
青阳龙野's avatar
青阳龙野 已提交
2917
		showFolderTable(folderView);
青阳龙野's avatar
青阳龙野 已提交
2918
	} catch (e) {
青阳龙野's avatar
青阳龙野 已提交
2919 2920
		alert("错误:搜索关键字有误。请在特殊符号(例如“*”)前加上“\\”进行转义。");
	}
青阳龙野's avatar
青阳龙野 已提交
2921 2922 2923
}

// 全路径查找
青阳龙野's avatar
青阳龙野 已提交
2924 2925
function selectInCompletePath(keyworld) {
	if (keyworld.length == 0) {
青阳龙野's avatar
青阳龙野 已提交
2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939
		showFolderView(locationpath);
		return;
	}
	startLoading();
	$.ajax({
		type : 'POST',
		dataType : 'text',
		data : {
			fid : locationpath,
			keyworld : keyworld
		},
		url : 'homeController/sreachInCompletePath.ajax',
		success : function(result) {
			endLoading();
青阳龙野's avatar
青阳龙野 已提交
2940
			if (result == "ERROR") {
青阳龙野's avatar
青阳龙野 已提交
2941 2942
				doAlert();
				$("#tb").html("<span class='graytext'>获取失败,请尝试刷新</span>");
青阳龙野's avatar
青阳龙野 已提交
2943 2944 2945 2946
				$("#publishTime").html(
						"<span class='graytext'>获取失败,请尝试刷新</span>");
				$("#parentlistbox").html(
						"<span class='graytext'>获取失败,请尝试刷新</span>");
青阳龙野's avatar
青阳龙野 已提交
2947
			} else if (result == "mustLogin") {
青阳龙野's avatar
青阳龙野 已提交
2948
				window.location.href = "prv/login.html";
青阳龙野's avatar
青阳龙野 已提交
2949
			} else if (result == "notAccess") {
青阳龙野's avatar
青阳龙野 已提交
2950
				document.cookie = "folder_id=" + escape("root");
青阳龙野's avatar
青阳龙野 已提交
2951
				window.location.href = "/";
青阳龙野's avatar
青阳龙野 已提交
2952 2953 2954 2955
			} else {
				folderView = eval("(" + result + ")");
				locationpath = folderView.folder.folderId;
				parentpath = folderView.folder.folderParent;
青阳龙野's avatar
青阳龙野 已提交
2956 2957
				constraintLevel = folderView.folder.folderConstraint;
				screenedFoldrView = null;
青阳龙野's avatar
青阳龙野 已提交
2958 2959 2960 2961
				$("#sreachKeyWordIn").val("all:" + folderView.keyWorld);
				showParentList(folderView);
				showAccountView(folderView);
				showPublishTime(folderView);
青阳龙野's avatar
青阳龙野 已提交
2962
				originFolderView = $.extend(true, {}, folderView);
青阳龙野's avatar
青阳龙野 已提交
2963 2964 2965 2966
				$("#sortByFN").removeClass();
				$("#sortByCD").removeClass();
				$("#sortByFS").removeClass();
				$("#sortByCN").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2967
				$("#sortByOR").removeClass();
青阳龙野's avatar
青阳龙野 已提交
2968
				showFolderTable(folderView);
青阳龙野's avatar
青阳龙野 已提交
2969 2970 2971 2972 2973
				$("#fim_name").text(folderView.folder.folderName);
				$("#fim_creator").text("--");
				$("#fim_folderCreationDate").text("--");
				$("#fim_folderId").text("--");
				updateTheFolderInfo();
青阳龙野's avatar
青阳龙野 已提交
2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987
			}
		},
		error : function() {
			endLoading();
			doAlert();
			$("#tb").html("<span class='graytext'>获取失败,请尝试刷新</span>");
			$("#publishTime").html("<span class='graytext'>获取失败,请尝试刷新</span>");
			$("#parentlistbox")
					.html("<span class='graytext'>获取失败,请尝试刷新</span>");
		}
	});
}

// 返回顶部实现
青阳龙野's avatar
青阳龙野 已提交
2988 2989 2990 2991
function goBackToTop() {
	$('html,body').animate({
		scrollTop : 0
	}, 'slow');
青阳龙野's avatar
青阳龙野 已提交
2992 2993 2994 2995 2996 2997
}

var getDownloadFileId;// 下载链接的文件ID
var getDownloadFileName;// 下载链接的文件名(便于下载工具识别)

// 获取某一文件的下载链接
青阳龙野's avatar
青阳龙野 已提交
2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013
function getDownloadURL() {
	$
			.ajax({
				url : 'externalLinksController/getDownloadKey.ajax',
				type : 'POST',
				dataType : 'text',
				data : {
					fId : getDownloadFileId
				},
				success : function(result) {
					// 获取链接
					var dlurl = window.location.protocol
							+ "//"
							+ window.location.host
							+ "/externalLinksController/downloadFileByKey/"
							+ encodeURIComponent(getDownloadFileName.replace(
青阳龙野's avatar
青阳龙野 已提交
3014 3015
									/\'/g, '').replace(/\r/g, "").replace(
									/\n/g, "")) + "?dkey=" + result;
青阳龙野's avatar
青阳龙野 已提交
3016 3017 3018 3019 3020 3021 3022 3023 3024 3025
					// 显示链接内容
					$("#downloadHrefBox").html(
							"<a href='" + dlurl + "'>" + dlurl + "</a>");
				},
				error : function() {
					$("#downloadHrefBox")
							.html(
									"<span class='text-muted'>获取失败,请检查网络状态或<a href='javascript:void(0);' onclick='getDownloadURL()'>点此</a>重新获取。</span>");
				}
			});
青阳龙野's avatar
青阳龙野 已提交
3026 3027 3028
}

// 防止长耗时待机时会话超时的应答器,每分钟应答一次
青阳龙野's avatar
青阳龙野 已提交
3029
function ping() {
青阳龙野's avatar
青阳龙野 已提交
3030
	$.ajax({
青阳龙野's avatar
青阳龙野 已提交
3031 3032 3033 3034 3035 3036 3037
		url : "homeController/ping.ajax",
		type : "POST",
		dataType : "text",
		data : {},
		success : function(result) {
			if (result != 'pong') {
				if (pingInt != null) {
青阳龙野's avatar
青阳龙野 已提交
3038 3039 3040 3041 3042
					window.clearInterval(pingInt);
					pingInt = null;
				}
			}
		},
青阳龙野's avatar
青阳龙野 已提交
3043 3044
		error : function() {
			if (pingInt != null) {
青阳龙野's avatar
青阳龙野 已提交
3045 3046 3047 3048 3049
				window.clearInterval(pingInt);
				pingInt = null;
			}
		}
	});
青阳龙野's avatar
青阳龙野 已提交
3050 3051 3052 3053 3054
}

// 判断浏览器是否支持webkitdirectory属性且不为ios系统(判断是否能进行文件夹上传)
function isSupportWebkitdirectory() {
	var testWebkitdirectory = document.createElement("input");
青阳龙野's avatar
青阳龙野 已提交
3055 3056
	if ("webkitdirectory" in testWebkitdirectory
			&& !(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent))) {
青阳龙野's avatar
青阳龙野 已提交
3057 3058 3059 3060 3061 3062 3063
		return true;
	} else {
		return false;
	}
};

// 显示上传文件夹模态框
青阳龙野's avatar
青阳龙野 已提交
3064
function showUploadFolderModel() {
青阳龙野's avatar
青阳龙野 已提交
3065 3066
	$("#importFolderAlert").hide();
	$("#importFolderAlert").text("");
青阳龙野's avatar
青阳龙野 已提交
3067
	if (isImporting == false) {// 如果未进行上传,则还原上传文件夹的基本状态
青阳龙野's avatar
青阳龙野 已提交
3068 3069 3070
		$("#folderpath").val("");
		$("#importfolder").val("");
		$("#importpros").width("0%");
青阳龙野's avatar
青阳龙野 已提交
3071
		$("#importpros").attr('aria-valuenow', '0');
青阳龙野's avatar
青阳龙野 已提交
3072
		$("#importstatus").html("");
青阳龙野's avatar
青阳龙野 已提交
3073 3074
		$("#folderpath").attr("disabled", false);
		$("#importFolderLevelBtn").attr("disabled", false);
青阳龙野's avatar
青阳龙野 已提交
3075 3076 3077 3078
		$("#importcount").text("");
		$("#importbutton").attr('disabled', false);
		$("#importfoldertypelist").html("");
		$("#selectFolderImportModelAlert").hide();
青阳龙野's avatar
青阳龙野 已提交
3079 3080 3081
		if (account != null) {
			$("#folderpath")
					.attr("folderConstraintLevel", constraintLevel + "");
青阳龙野's avatar
青阳龙野 已提交
3082
			$("#importfoldertype").text(folderTypes[constraintLevel]);
青阳龙野's avatar
青阳龙野 已提交
3083 3084 3085 3086
			for (var i = constraintLevel; i < folderTypes.length; i++) {
				$("#importfoldertypelist").append(
						"<li><a onclick='changeImportFolderType(" + i + ")'>"
								+ folderTypes[i] + "</a></li>");
青阳龙野's avatar
青阳龙野 已提交
3087
			}
青阳龙野's avatar
青阳龙野 已提交
3088 3089 3090 3091
		} else {
			$("#importfoldertypelist").append(
					"<li><a onclick='changeImportFolderType(0)'>"
							+ folderTypes[0] + "</a></li>");
青阳龙野's avatar
青阳龙野 已提交
3092 3093 3094 3095 3096 3097
		}
	}
	$("#importFolderModal").modal('show');
}

// 点击上传路径文本框时弹出文件夹选择窗口
青阳龙野's avatar
青阳龙野 已提交
3098
function checkimportpath() {
青阳龙野's avatar
青阳龙野 已提交
3099 3100 3101 3102
	$('#importfolder').click();
}

// 用户选择文件夹后回填路径
青阳龙野's avatar
青阳龙野 已提交
3103
function getInputImport() {
青阳龙野's avatar
青阳龙野 已提交
3104
	ifs = $("#importfolder")[0].files;
青阳龙野's avatar
青阳龙野 已提交
3105 3106 3107
	if (ifs.length > 0) {
		importFolderName = ifs[0].webkitRelativePath.substring(0,
				ifs[0].webkitRelativePath.indexOf("/"));
青阳龙野's avatar
青阳龙野 已提交
3108 3109 3110 3111 3112
		$("#folderpath").val(importFolderName);
	}
}

// 检查文件夹是否能够上传
青阳龙野's avatar
青阳龙野 已提交
3113 3114 3115 3116 3117
function checkImportFolder() {
	if (isUpLoading == false && isImporting == false) {
		if (ifs != null && ifs.length > 0) {// 必须选中文件
			$("#folderpath").attr("disabled", true);
			$("#importFolderLevelBtn").attr("disabled", true);
青阳龙野's avatar
青阳龙野 已提交
3118 3119 3120 3121 3122 3123
			$("#importbutton").attr('disabled', true);
			$("#importFolderAlert").hide();
			$("#importFolderAlert").text("");
			isImporting = true;
			var maxSize = 0;
			var maxFileIndex = 0;
青阳龙野's avatar
青阳龙野 已提交
3124
			// 找出最大体积的文件以便服务器进行效验
青阳龙野's avatar
青阳龙野 已提交
3125
			for (var i = 0; i < ifs.length; i++) {
青阳龙野's avatar
青阳龙野 已提交
3126
				if (ifs[i].size > maxSize) {
青阳龙野's avatar
青阳龙野 已提交
3127 3128 3129 3130 3131
					maxSize = ifs[i].size;
					maxFileIndex = i;
				}
			}
			// 发送合法性检查请求
青阳龙野's avatar
青阳龙野 已提交
3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185
			$
					.ajax({
						url : 'homeController/checkImportFolder.ajax',
						type : 'POST',
						dataType : 'text',
						data : {
							folderName : importFolderName,
							maxSize : maxSize,
							folderId : locationpath
						},
						success : function(result) {
							var resJson = eval("(" + result + ")");
							switch (resJson.result) {
							case 'noAuthorized':
								showImportFolderAlert("提示:您的操作未被授权,无法开始上传");
								break;
							case 'errorParameter':
								showImportFolderAlert("提示:参数不正确,无法开始上传。必须选择一个文件夹");
								break;
							case 'mustLogin':
								window.location.href = "prv/login.html";
								break;
							case 'fileOverSize':
								showImportFolderAlert("提示:文件["
										+ ifs[maxFileIndex].webkitRelativePath
										+ "]的体积超过最大限制(" + resJson.maxSize
										+ "),无法开始上传");
								break;
							case 'foldersTotalOutOfLimit':
								showImportFolderAlert("提示:该文件夹内存储的文件夹数量已达上限,无法在其中上传更多文件夹。您可以尝试将其上传至其他文件夹内。");
								break;
							case 'repeatFolder_Both':
								$("#repeFolderName").text(importFolderName);
								$("#importcoverbtn").hide();
								$("#selectFolderImportModelAlert").show();
								break;
							case 'repeatFolder_coverOrBoth':
								$("#repeFolderName").text(importFolderName);
								$("#importcoverbtn").show();
								$("#selectFolderImportModelAlert").show();
								break;
							case 'permitUpload':
								iteratorImport(0);// 直接允许上传
								break;
							default:
								showImportFolderAlert("提示:出现意外错误,无法开始上传");
								break;
							}
						},
						error : function() {
							showImportFolderAlert("提示:出现意外错误,无法开始上传");
						}
					});
		} else {
青阳龙野's avatar
青阳龙野 已提交
3186 3187
			showImportFolderAlert("提示:您未选择任何文件夹,无法开始上传");
		}
青阳龙野's avatar
青阳龙野 已提交
3188
	} else {
青阳龙野's avatar
青阳龙野 已提交
3189 3190 3191 3192 3193 3194
		showImportFolderAlert("提示:另一项上传文件或文件夹的任务尚未完成,无法开始上传");
	}
}

// 显示上传文件夹错误提示
function showImportFolderAlert(txt) {
青阳龙野's avatar
青阳龙野 已提交
3195 3196 3197
	isImporting = false;
	$("#folderpath").attr("disabled", false);
	$("#importFolderLevelBtn").attr("disabled", false);
青阳龙野's avatar
青阳龙野 已提交
3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209
	$("#importFolderAlert").show();
	$("#importFolderAlert").text(txt);
	$("#importbutton").attr('disabled', false);
}

// 显示上传文件夹进度
function importProgress(evt) {
	if (evt.lengthComputable) {
		// evt.loaded:文件上传的大小 evt.total:文件总的大小
		var percentComplete = Math.round((evt.loaded) * 100 / evt.total);
		// 加载进度条,同时显示信息
		$("#importpros").width(percentComplete + "%");
青阳龙野's avatar
青阳龙野 已提交
3210
		$("#importpros").attr('aria-valuenow', "" + percentComplete);
青阳龙野's avatar
青阳龙野 已提交
3211 3212 3213 3214 3215 3216 3217
	}
}

// 覆盖并上传文件夹
function importAndCover() {
	$("#selectFolderImportModelAlert").hide();
	$.ajax({
青阳龙野's avatar
青阳龙野 已提交
3218 3219 3220
		url : 'homeController/deleteFolderByName.ajax',
		type : 'POST',
		data : {
青阳龙野's avatar
青阳龙野 已提交
3221 3222 3223
			parentId : locationpath,
			folderName : importFolderName
		},
青阳龙野's avatar
青阳龙野 已提交
3224 3225 3226
		dataType : 'text',
		success : function(result) {
			if (result == 'deleteSuccess') {
青阳龙野's avatar
青阳龙野 已提交
3227
				iteratorImport(0);// 若覆盖成功,则开始上传
青阳龙野's avatar
青阳龙野 已提交
3228
			} else {
青阳龙野's avatar
青阳龙野 已提交
3229 3230 3231
				showImportFolderAlert("提示:无法覆盖原文件夹,上传失败");
			}
		},
青阳龙野's avatar
青阳龙野 已提交
3232
		error : function() {
青阳龙野's avatar
青阳龙野 已提交
3233 3234 3235 3236 3237 3238 3239 3240
			showImportFolderAlert("提示:无法覆盖原文件夹,上传失败");
		}
	});
}

// 保留两者并上传文件夹
function importAndBoth() {
	$("#selectFolderImportModelAlert").hide();
青阳龙野's avatar
青阳龙野 已提交
3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265
	var fc = $("#folderpath").attr("folderConstraintLevel");// 文件夹访问级别
	$
			.ajax({
				url : 'homeController/createNewFolderByName.ajax',
				type : 'POST',
				data : {
					parentId : locationpath,
					folderName : importFolderName,
					folderConstraint : fc
				},
				dataType : 'text',
				success : function(result) {
					var resJson = eval("(" + result + ")");
					if (resJson.result == 'success') {
						iteratorImport(0, resJson.newName);// 若新建成功,则使用新文件夹名称开始上传
					} else if (resJson.result == 'foldersTotalOutOfLimit') {
						showImportFolderAlert("提示:该文件夹内存储的文件夹数量已达上限,无法上传同名文件夹并保留两者。您可以尝试将其上传至其他文件夹内。");
					} else {
						showImportFolderAlert("提示:生成新文件夹名称失败,无法开始上传");
					}
				},
				error : function() {
					showImportFolderAlert("提示:生成新文件夹名称失败,无法开始上传");
				}
			});
青阳龙野's avatar
青阳龙野 已提交
3266 3267 3268
}

// 迭代上传文件夹内的文件(直接上传)
青阳龙野's avatar
青阳龙野 已提交
3269
function iteratorImport(i, newFolderName) {
青阳龙野's avatar
青阳龙野 已提交
3270
	$("#importpros").width("0%");// 先将进度条置0
青阳龙野's avatar
青阳龙野 已提交
3271
	$("#importpros").attr('aria-valuenow', "0");
青阳龙野's avatar
青阳龙野 已提交
3272 3273
	var uploadfile = ifs[i];// 获取要上传的文件
	var fcount = ifs.length;
青阳龙野's avatar
青阳龙野 已提交
3274
	var fc = $("#folderpath").attr("folderConstraintLevel");// 文件夹访问级别
青阳龙野's avatar
青阳龙野 已提交
3275 3276 3277
	if (uploadfile != null) {
		var fname = uploadfile.webkitRelativePath;
		if (fcount > 1) {
青阳龙野's avatar
青阳龙野 已提交
3278
			$("#importcount").text("" + (i + 1) + "/" + fcount + "");// 显示当前进度
青阳龙野's avatar
青阳龙野 已提交
3279
		}
青阳龙野's avatar
青阳龙野 已提交
3280 3281 3282 3283 3284
		$("#importstatus").prepend(
				"<p>"
						+ fname.replace(/\'/g, '&#39;').replace(/</g, '&lt;')
								.replace(/>/g, '&gt;') + "<span id='ils_" + i
						+ "'>[正在上传...]</span></p>");
青阳龙野's avatar
青阳龙野 已提交
3285
		xhr = new XMLHttpRequest();// 这东西类似于servlet里面的request
青阳龙野's avatar
青阳龙野 已提交
3286

青阳龙野's avatar
青阳龙野 已提交
3287
		var fd = new FormData();// 用于封装文件数据的对象
青阳龙野's avatar
青阳龙野 已提交
3288

青阳龙野's avatar
青阳龙野 已提交
3289 3290
		fd.append("file", uploadfile);// 将文件对象添加到FormData对象中,字段名为uploadfile
		fd.append("folderId", locationpath);
青阳龙野's avatar
青阳龙野 已提交
3291 3292 3293 3294
		fd.append("folderConstraint", fc);
		fd.append("originalFileName", fname);
		if (!!newFolderName) {
			fd.append("newFolderName", newFolderName);
青阳龙野's avatar
青阳龙野 已提交
3295 3296
		}
		xhr.open("POST", "homeController/doImportFolder.ajax", true);// 上传目标
青阳龙野's avatar
青阳龙野 已提交
3297

青阳龙野's avatar
青阳龙野 已提交
3298 3299
		xhr.upload.addEventListener("progress", importProgress, false);// 这个是对上传进度的监听
		// 上面的三个参数分别是:事件名(指定名称)、回调函数、是否冒泡(一般是false即可)
青阳龙野's avatar
青阳龙野 已提交
3300

青阳龙野's avatar
青阳龙野 已提交
3301
		xhr.send(fd);// 上传FormData对象
青阳龙野's avatar
青阳龙野 已提交
3302 3303 3304

		if (pingInt == null) {
			pingInt = setInterval("ping()", 60000);// 上传中开始计时应答
青阳龙野's avatar
青阳龙野 已提交
3305
		}
青阳龙野's avatar
青阳龙野 已提交
3306

青阳龙野's avatar
青阳龙野 已提交
3307 3308 3309
		// 上传结束后执行的回调函数
		xhr.onloadend = function() {
			// 停止应答计时
青阳龙野's avatar
青阳龙野 已提交
3310
			if (pingInt != null) {
青阳龙野's avatar
青阳龙野 已提交
3311 3312 3313 3314 3315 3316 3317 3318
				window.clearInterval(pingInt);
				pingInt = null;
			}
			if (xhr.status === 200) {
				// TODO 上传成功
				var result = xhr.responseText;
				if (result == "uploadsuccess") {
					$("#ils_" + i).text("[已完成]");
青阳龙野's avatar
青阳龙野 已提交
3319 3320 3321 3322
					var ni = i + 1;
					if (ni < fcount) {
						iteratorImport(ni, newFolderName);
					} else {
青阳龙野's avatar
青阳龙野 已提交
3323
						// 完成全部上传后,清空所有提示信息,并还原上传窗口
青阳龙野's avatar
青阳龙野 已提交
3324
						isImporting = false;
青阳龙野's avatar
青阳龙野 已提交
3325 3326 3327 3328 3329
						$("#folderpath").removeAttr("disabled");
						$("#importFolderLevelBtn").removeAttr("disabled");
						$("#importfolder").val("");
						$("#folderpath").val("");
						$("#importpros").width("0%");
青阳龙野's avatar
青阳龙野 已提交
3330
						$("#importpros").attr('aria-valuenow', "0");
青阳龙野's avatar
青阳龙野 已提交
3331 3332 3333 3334 3335 3336 3337 3338 3339 3340
						$("#importbutton").attr('disabled', false);
						$("#importcount").text("");
						$("#importstatus").text("");
						$('#importFolderModal').modal('hide');
						showFolderView(locationpath);
					}
				} else if (result == "uploaderror") {
					showImportFolderAlert("提示:出现意外错误,文件:[" + fname
							+ "]上传失败,上传被中断。");
					$("#ils_" + i).text("[失败]");
青阳龙野's avatar
青阳龙野 已提交
3341
				} else if (result == "foldersTotalOutOfLimit") {
青阳龙野's avatar
青阳龙野 已提交
3342 3343 3344
					showImportFolderAlert("提示:该文件夹内存储的文件夹数量已达上限,文件:[" + fname
							+ "]上传失败,上传被中断。");
					$("#ils_" + i).text("[失败]");
青阳龙野's avatar
青阳龙野 已提交
3345
				} else if (result == "filesTotalOutOfLimit") {
青阳龙野's avatar
青阳龙野 已提交
3346 3347 3348
					showImportFolderAlert("提示:该文件夹内存储的文件数量已达上限,文件:[" + fname
							+ "]上传失败,上传被中断。");
					$("#ils_" + i).text("[失败]");
青阳龙野's avatar
青阳龙野 已提交
3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366
				} else {
					showImportFolderAlert("提示:出现意外错误,文件:[" + fname
							+ "]上传失败,上传被中断。");
					$("#ils_" + i).text("[失败]");
				}
			} else {
				showImportFolderAlert("提示:出现意外错误,文件:[" + fname + "]上传失败,上传被中断。");
				$("#ils_" + i).text("[失败]");
			}
		};
	} else {
		showImportFolderAlert("提示:要上传的文件不存在。");
		$("#importstatus").prepend(
				"<p>未找到要上传的文件<span id='ils_" + i + "'>[失败]</span></p>");
	}
}

// 取消文件夹上传
青阳龙野's avatar
青阳龙野 已提交
3367 3368 3369 3370 3371 3372
function abortImport() {
	if (isImporting) {
		isImporting = false;
		if (xhr != null) {
			xhr.abort();
		}
青阳龙野's avatar
青阳龙野 已提交
3373 3374 3375 3376 3377 3378
	}
	$('#importFolderModal').modal('hide');
	showFolderView(locationpath);
}

// 修改上传文件夹约束等级
青阳龙野's avatar
青阳龙野 已提交
3379
function changeImportFolderType(type) {
青阳龙野's avatar
青阳龙野 已提交
3380
	$("#importfoldertype").text(folderTypes[type]);
青阳龙野's avatar
青阳龙野 已提交
3381
	$("#folderpath").attr("folderConstraintLevel", type + "");
青阳龙野's avatar
青阳龙野 已提交
3382 3383 3384
}

// 修改密码
青阳龙野's avatar
青阳龙野 已提交
3385
function doChangePassword() {
青阳龙野's avatar
青阳龙野 已提交
3386
	// 还原提示状态
青阳龙野's avatar
青阳龙野 已提交
3387 3388 3389
	$(
			"#changepassword_oldepwdbox,#changepassword_newpwdbox,#changepassword_reqnewpwdbox")
			.removeClass("has-error");
青阳龙野's avatar
青阳龙野 已提交
3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410
	$("#changepasswordalertbox").hide();
	var change_oldPassword = $("#changepassword_oldpwd").val();
	var change_newPassword = $("#changepassword_newpwd").val();
	var change_reqNewPassword = $("#changepassword_reqnewpwd").val();
	// 输入非空检查
	if (change_oldPassword.length == 0) {
		$("#changepassword_oldepwdbox").addClass("has-error");
		$("#changepassword_oldpwd").focus();
		return;
	}
	if (change_newPassword.length == 0) {
		$("#changepassword_newpwdbox").addClass("has-error");
		$("#changepassword_newpwd").focus();
		return;
	}
	if (change_reqNewPassword.length == 0) {
		$("#changepassword_reqnewpwdbox").addClass("has-error");
		$("#changepassword_reqnewpwd").focus();
		return;
	}
	// 确认密码检查
青阳龙野's avatar
青阳龙野 已提交
3411 3412 3413 3414 3415
	isChangingPassword = true;
	$(
			"#changepassword_oldpwd,#changepassword_newpwd,#changepassword_reqnewpwd,#changePasswordButton,#changepassword_vercode")
			.attr('disabled', true);
	if (change_newPassword + "" != change_reqNewPassword + "") {
青阳龙野's avatar
青阳龙野 已提交
3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428
		showChangePasswordAlert("提示:两次输入的新密码不一致,请检查确认");
		$("#changepassword_newpwdbox").addClass("has-error");
		$("#changepassword_reqnewpwdbox").addClass("has-error");
		return;
	}
	// 以加密方式发送修改密码请求
	$.ajax({
		url : 'homeController/getPublicKey.ajax',
		type : 'POST',
		data : {},
		dataType : 'text',
		success : function(result) {
			// 获取公钥
青阳龙野's avatar
青阳龙野 已提交
3429
			var changepwd_publicKeyInfo = eval("(" + result + ")");
青阳龙野's avatar
青阳龙野 已提交
3430
			// 生成JSON对象格式的信息
青阳龙野's avatar
青阳龙野 已提交
3431 3432 3433
			var changePasswordInfo = '{oldPwd:"' + change_oldPassword
					+ '",newPwd:"' + change_newPassword + '",time:"'
					+ changepwd_publicKeyInfo.time + '"}';
青阳龙野's avatar
青阳龙野 已提交
3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445
			var encrypt = new JSEncrypt();// 加密插件对象
			encrypt.setPublicKey(changepwd_publicKeyInfo.publicKey);// 设置公钥
			var encrypted = encrypt.encrypt(changePasswordInfo);// 进行加密
			sendChangePasswordInfo(encrypted);
		},
		error : function() {
			showChangePasswordAlert("提示:密码修改失败,请检查网络链接或服务器运行状态");
		}
	});
}

// 将加密数据发送至服务器并显示操作结果
青阳龙野's avatar
青阳龙野 已提交
3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502
function sendChangePasswordInfo(encrypted) {
	$
			.ajax({
				type : "POST",
				dataType : "text",
				url : "homeController/doChangePassword.ajax",
				data : {
					encrypted : encrypted,
					vercode : $("#changepassword_vercode").val()
				},
				success : function(result) {
					$("#changepassword_vccodebox").hide();
					isChangingPassword = false;
					switch (result) {
					case "success":
						$('#changePasswordModal').modal('hide');
						break;
					case "mustlogin":
						showChangePasswordAlert("提示:登录已失效或尚未登录账户,请刷新并登陆账户");
						break;
					case "illegal":
						showChangePasswordAlert("提示:用户修改密码功能已被禁用,请求被拒绝");
						break;
					case "oldpwderror":
						showChangePasswordAlert("提示:旧密码输入错误,请求被拒绝");
						$("#changepassword_oldepwdbox").addClass("has-error");
						break;
					case "needsubmitvercode":
						$(
								"#changepassword_oldpwd,#changepassword_newpwd,#changepassword_reqnewpwd,#changePasswordButton")
								.attr('disabled', false);
						$("#changepassword_vccodebox")
								.html(
										"<label id='changepassword_vercodetitle' class='col-sm-5'><img id='changepassword_showvercode' class='vercodeimg' alt='点击获取验证码' src='homeController/getNewVerCode.do?s="
												+ (new Date()).getTime()
												+ "' onclick='changePasswordGetNewVerCode()'></label><div class='col-sm-7'><input type='text' class='form-control' id='changepassword_vercode' placeholder='验证码……'></div>");
						$("#changepassword_vccodebox").show();
						isChangingPassword = false;
						break;
					case "invalidnewpwd":
						showChangePasswordAlert("提示:密码修改失败,新密码不合法。新密码的长度需为3-32个字符,且仅支持ISO-8859-1中的字符(推荐使用英文字母、英文符号及阿拉伯数字)。");
						break;
					case "error":
						showChangePasswordAlert("提示:密码修改失败,修改请求无法通过加密效验(可能是请求耗时过长导致的)");
						break;
					case "cannotchangepwd":
						showChangePasswordAlert("提示:密码修改失败,发生意外错误,请稍后重试或联系管理员");
						break;
					default:
						showChangePasswordAlert("提示:密码修改失败,发生未知错误");
						break;
					}
				},
				error : function() {
					showChangePasswordAlert("提示:密码修改失败,请检查网络链接或服务器运行状态");
				}
			});
青阳龙野's avatar
青阳龙野 已提交
3503 3504 3505 3506
}

// 显示修改密码错误提示
function showChangePasswordAlert(txt) {
青阳龙野's avatar
青阳龙野 已提交
3507 3508 3509 3510
	isChangingPassword = false;
	$(
			"#changepassword_oldpwd,#changepassword_newpwd,#changepassword_reqnewpwd,#changePasswordButton,#changepassword_vercode")
			.attr('disabled', false);
青阳龙野's avatar
青阳龙野 已提交
3511 3512 3513 3514 3515
	$("#changepasswordalertbox").show();
	$("#changepasswordalertbox").text(txt);
}

// (修改密码版本的)获取一个新的验证码
青阳龙野's avatar
青阳龙野 已提交
3516 3517 3518
function changePasswordGetNewVerCode() {
	$("#changepassword_showvercode").attr("src",
			"homeController/getNewVerCode.do?s=" + (new Date()).getTime());
青阳龙野's avatar
青阳龙野 已提交
3519 3520 3521
}

// 获取永久资源链接
青阳龙野's avatar
青阳龙野 已提交
3522
function getFileChain(fileId, fileName) {
青阳龙野's avatar
青阳龙野 已提交
3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541
	$("#fileChainTextarea").text("正在获取……");
	$("#copyChainBtn").attr('disabled', true);
	$('#fileChainModal').modal('show');
	$.ajax({
		type : "POST",
		dataType : "text",
		url : "homeController/getFileChainKey.ajax",
		data : {
			fid : fileId
		},
		success : function(result) {
			switch (result) {
			case "ERROR":
				$("#fileChainTextarea").text("提示:获取失败,请刷新页面或稍后再试。");
				break;
			case "mustlogin":
				window.location.href = "prv/login.html";
				break;
			default:
青阳龙野's avatar
青阳龙野 已提交
3542
				$("#fileChainTextarea").text(
青阳龙野's avatar
青阳龙野 已提交
3543 3544
						window.location.protocol
								+ "//"
青阳龙野's avatar
青阳龙野 已提交
3545 3546
								+ window.location.host
								+ "/externalLinksController/chain/"
青阳龙野's avatar
青阳龙野 已提交
3547 3548 3549
								+ encodeURIComponent(fileName
										.replace(/\'/g, '').replace(/\r/g, "")
										.replace(/\n/g, "")) + "?ckey="
青阳龙野's avatar
青阳龙野 已提交
3550
								+ encodeURIComponent(result));
青阳龙野's avatar
青阳龙野 已提交
3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561
				$("#copyChainBtn").attr('disabled', false);
				break;
			}
		},
		error : function() {
			$("#fileChainTextarea").text("提示:获取失败,无法连接服务器。");
		}
	});
}

// 复制链接内容
青阳龙野's avatar
青阳龙野 已提交
3562
function copyFileChain() {
青阳龙野's avatar
青阳龙野 已提交
3563
	let node = document.getElementById('fileChainTextarea');// input框
青阳龙野's avatar
青阳龙野 已提交
3564
	node.select();
青阳龙野's avatar
青阳龙野 已提交
3565
	document.execCommand('copy');
青阳龙野's avatar
青阳龙野 已提交
3566 3567 3568
}

// 显示公告模态框
青阳龙野's avatar
青阳龙野 已提交
3569
function showNoticeModal() {
青阳龙野's avatar
青阳龙野 已提交
3570 3571 3572 3573
	$('#noticeModal').modal('show');
}

// 加载公告内容并初始化公告模态框
青阳龙野's avatar
青阳龙野 已提交
3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588
function initNoticeModal() {
	$("#noticeModalBody").load(
			"resourceController/getNoticeContext.do",
			function() {
				$('#noticeModalBody img').css("max-width", "100%");
				if (winHeight >= 300) {
					$('#noticeModalBody').css("max-height",
							(winHeight - 180) + "px");
				} else {
					$('#noticeModalBody').css("max-height", "300px");
				}
				noticeInited = true;
				showNoticeModal();
				showNoticeBtn();
			});
青阳龙野's avatar
青阳龙野 已提交
3589 3590 3591
}

// 打开主页时自动订阅未阅读过的公告信息并显示,如果该公告已经阅读过则不会显示。
青阳龙野's avatar
青阳龙野 已提交
3592
function subscribeNotice() {
青阳龙野's avatar
青阳龙野 已提交
3593
	$.ajax({
青阳龙野's avatar
青阳龙野 已提交
3594 3595 3596 3597 3598 3599 3600 3601 3602 3603
		url : 'resourceController/getNoticeMD5.ajax',
		data : {},
		type : 'POST',
		dataType : 'text',
		success : function(result) {
			if (result != "") {
				var cookieMd5 = document.cookie.match(new RegExp(
						"(^| )notice_md5=([^;]*)(;|$)"));
				if (cookieMd5) {
					if (result == unescape(cookieMd5[2])) {
青阳龙野's avatar
青阳龙野 已提交
3604 3605 3606
						showNoticeBtn();
						return;
					}
青阳龙野's avatar
青阳龙野 已提交
3607 3608 3609 3610 3611
				} else {
					cookieMd5 = document.cookie.match(new RegExp(
							"(^| )notice_md5_30=([^;]*)(;|$)"));
					if (cookieMd5) {
						if (result == unescape(cookieMd5[2])) {
青阳龙野's avatar
青阳龙野 已提交
3612 3613 3614 3615 3616 3617 3618 3619 3620
							showNoticeBtn();
							return;
						}
					}
				}
				initNoticeModal();
				document.cookie = "notice_md5=" + escape(result);
			}
		},
青阳龙野's avatar
青阳龙野 已提交
3621
		error : function() {
青阳龙野's avatar
青阳龙野 已提交
3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634
			alert("错误:无法从服务器获取公告信息,请尝试刷新页面。");
		}
	});
}

// 显示“公告”浮动按钮,方便用户手动打开公告
function showNoticeBtn() {
	$("#shownoticebox").removeClass("hidden");
	$("#shownoticebox").addClass("show");
}

// 手动显示公告
function showNotice() {
青阳龙野's avatar
青阳龙野 已提交
3635
	if (noticeInited) {
青阳龙野's avatar
青阳龙野 已提交
3636
		showNoticeModal();
青阳龙野's avatar
青阳龙野 已提交
3637
	} else {
青阳龙野's avatar
青阳龙野 已提交
3638 3639 3640 3641 3642
		initNoticeModal();
	}
}

// 该方法用于请求并继续加载文件夹视图的后续数据(可能会被迭代调用)
青阳龙野's avatar
青阳龙野 已提交
3643
function loadingRemainingFolderView(targetId) {
青阳龙野's avatar
青阳龙野 已提交
3644
	// 判断是否正在执行另一个相同的请求,避免重复操作
青阳龙野's avatar
青阳龙野 已提交
3645
	if (remainingLoadingRequest) {
青阳龙野's avatar
青阳龙野 已提交
3646 3647 3648
		return;
	}
	// 计算新的查询偏移量
青阳龙野's avatar
青阳龙野 已提交
3649 3650 3651
	var newfoldersOffset = 0;
	var newfilesOffset = 0;
	if ((folderView.foldersOffset - folderView.selectStep) > 0) {
青阳龙野's avatar
青阳龙野 已提交
3652 3653
		newfoldersOffset = folderView.foldersOffset - folderView.selectStep;
	}
青阳龙野's avatar
青阳龙野 已提交
3654
	if ((folderView.filesOffset - folderView.selectStep) > 0) {
青阳龙野's avatar
青阳龙野 已提交
3655 3656
		newfilesOffset = folderView.filesOffset - folderView.selectStep;
	}
青阳龙野's avatar
青阳龙野 已提交
3657 3658
	if (newfoldersOffset <= 0 && newfilesOffset <= 0) {
		originFolderView = $.extend(true, {}, folderView);
青阳龙野's avatar
青阳龙野 已提交
3659 3660 3661 3662 3663 3664
		hiddenLoadingRemaininngBox();
		doFixedRow(targetId);
		return;
	}
	var loadingRemainingRate_folders = 1;
	var loadingRemainingRate_files = 1;
青阳龙野's avatar
青阳龙野 已提交
3665 3666 3667
	if (totalFoldersOffset > 0) {
		loadingRemainingRate_folders = (totalFoldersOffset - newfoldersOffset)
				/ totalFoldersOffset;
青阳龙野's avatar
青阳龙野 已提交
3668
	}
青阳龙野's avatar
青阳龙野 已提交
3669 3670 3671
	if (totalFilesOffset > 0) {
		loadingRemainingRate_files = (totalFilesOffset - newfilesOffset)
				/ totalFilesOffset;
青阳龙野's avatar
青阳龙野 已提交
3672
	}
青阳龙野's avatar
青阳龙野 已提交
3673
	var loadingRemainingRate = (loadingRemainingRate_folders + loadingRemainingRate_files) / 2;
青阳龙野's avatar
青阳龙野 已提交
3674
	$("#loadingrate").text(parseInt(loadingRemainingRate * 100) + "%");
青阳龙野's avatar
青阳龙野 已提交
3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717
	remainingLoadingRequest = $
			.ajax({
				url : 'homeController/getRemainingFolderView.ajax',
				data : {
					fid : locationpath,
					foldersOffset : newfoldersOffset,
					filesOffset : newfilesOffset
				},
				type : 'POST',
				dataType : 'text',
				success : function(result) {
					remainingLoadingRequest = null;
					switch (result) {
					case "ERROR":
						alert("错误:无法加载剩余文件列表,文件数据可能未显示完全,请刷新重试!");
						hiddenLoadingRemaininngBox();
						doFixedRow();
						break;
					case "NOT_FOUND":
					case "notAccess":
						document.cookie = "folder_id=" + escape("root");// 归位记忆路径
					case "mustLogin":
						window.location.href = "/";
						break;
					default:
						folderView.foldersOffset = newfoldersOffset;
						folderView.filesOffset = newfilesOffset;
						var remainingFV = eval("(" + result + ")");
						updateFolderTable(remainingFV);
						updateTheFolderInfo();
						if (folderView.foldersOffset > 0
								|| folderView.filesOffset > 0) {
							loadingRemainingFolderView(targetId);
						} else {
							originFolderView = $.extend(true, {}, folderView);
							hiddenLoadingRemaininngBox();
							doFixedRow(targetId);
						}
						break;
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					remainingLoadingRequest = null;
青阳龙野's avatar
青阳龙野 已提交
3718
					hiddenLoadingRemaininngBox();
青阳龙野's avatar
青阳龙野 已提交
3719 3720 3721
					if ('abort' != textStatus) {
						alert("错误:无法连接服务器,文件列表加载被中断。请刷新重试!");
					}
青阳龙野's avatar
青阳龙野 已提交
3722
				}
青阳龙野's avatar
青阳龙野 已提交
3723
			});
青阳龙野's avatar
青阳龙野 已提交
3724 3725 3726
}

// 定位指定文件所在行
青阳龙野's avatar
青阳龙野 已提交
3727 3728 3729 3730 3731 3732
function doFixedRow(targetId) {
	if (targetId && targetId.length > 0) {
		$("#" + targetId).addClass("info");
		$("html,body").animate({
			scrollTop : $("#" + targetId).offset().top - $(window).height() / 2
		}, 'slow');
青阳龙野's avatar
青阳龙野 已提交
3733 3734 3735 3736
	}
}

// 显示“正在加载文件列表”提示栏
青阳龙野's avatar
青阳龙野 已提交
3737
function showLoadingRemaininngBox() {
青阳龙野's avatar
青阳龙野 已提交
3738 3739 3740
	loadingComplete = false;
	$("#loadingremaininngbox").addClass("show");
	$("#loadingremaininngbox").removeClass("hidden");
青阳龙野's avatar
青阳龙野 已提交
3741
	$("#searchbtn").attr('disabled', 'disabled');
青阳龙野's avatar
青阳龙野 已提交
3742 3743 3744
}

// 隐藏“正在加载文件列表”提示栏
青阳龙野's avatar
青阳龙野 已提交
3745
function hiddenLoadingRemaininngBox() {
青阳龙野's avatar
青阳龙野 已提交
3746 3747 3748 3749 3750 3751 3752
	loadingComplete = true;
	$("#loadingremaininngbox").removeClass("show");
	$("#loadingremaininngbox").addClass("hidden");
	$("#searchbtn").removeAttr('disabled');
}

// 将加载的后续文件夹视图数据更新至页面上显示
青阳龙野's avatar
青阳龙野 已提交
3753
function updateFolderTable(remainingFV) {
青阳龙野's avatar
青阳龙野 已提交
3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767
	var authList = folderView.authList;
	var aD = false;
	var aR = false;
	var aL = false;
	var aO = false;
	if (checkAuth(authList, "D")) {
		aD = true;
	}
	if (checkAuth(authList, "R")) {
		aR = true;
	}
	if (checkAuth(authList, "L")) {
		aL = true;
	}
青阳龙野's avatar
青阳龙野 已提交
3768
	if (checkAuth(authList, "O")) {
青阳龙野's avatar
青阳龙野 已提交
3769 3770
		aO = true;
	}
青阳龙野's avatar
青阳龙野 已提交
3771 3772 3773 3774 3775
	if (remainingFV.folderList) {
		if (remainingFV.folderList.length > 0) {
			for (var i1 = remainingFV.folderList.length; i1 > 0; i1--) {
				var f = remainingFV.folderList[i1 - 1];
				if (!folderContains(folderView.folderList, f.folderId)) {
青阳龙野's avatar
青阳龙野 已提交
3776
					folderView.folderList.unshift(f);
青阳龙野's avatar
青阳龙野 已提交
3777 3778
					$("[iskfolder=true]:last").after(
							createNewFolderRow(f, aD, aR, aO));
青阳龙野's avatar
青阳龙野 已提交
3779 3780 3781 3782
				}
			}
		}
	}
青阳龙野's avatar
青阳龙野 已提交
3783 3784 3785 3786 3787
	if (remainingFV.fileList) {
		if (remainingFV.fileList.length > 0) {
			for (var i2 = remainingFV.fileList.length; i2 > 0; i2--) {
				var fi = remainingFV.fileList[i2 - 1];
				if (!fileContains(folderView.fileList, fi.fileId)) {
青阳龙野's avatar
青阳龙野 已提交
3788
					folderView.fileList.unshift(fi);
青阳龙野's avatar
青阳龙野 已提交
3789
					$("#foldertable").append(createFileRow(fi, aL, aD, aR, aO));
青阳龙野's avatar
青阳龙野 已提交
3790 3791 3792 3793 3794 3795 3796
				}
			}
		}
	}
}

// 判断文件夹数组中是否存已在ID相同的某个文件夹
青阳龙野's avatar
青阳龙野 已提交
3797 3798 3799
function folderContains(folderList, targetFolderId) {
	for (var i = folderList.length; i > 0; i--) {
		if (folderList[i - 1].folderId == targetFolderId) {
青阳龙野's avatar
青阳龙野 已提交
3800 3801 3802
			return true;
		}
	}
青阳龙野's avatar
青阳龙野 已提交
3803
	return false;
青阳龙野's avatar
青阳龙野 已提交
3804 3805 3806
}

// 判断文件数组中是否存已在ID相同的某个文件
青阳龙野's avatar
青阳龙野 已提交
3807 3808 3809
function fileContains(fileList, targetFileId) {
	for (var i = fileList.length; i > 0; i--) {
		if (fileList[i - 1].fileId == targetFileId) {
青阳龙野's avatar
青阳龙野 已提交
3810 3811 3812 3813 3814 3815 3816
			return true;
		}
	}
	return false;
}

// 更新文件夹视图信息
青阳龙野's avatar
青阳龙野 已提交
3817 3818 3819 3820
function updateTheFolderInfo() {
	$("#fim_statistics").text(
			"共包含 " + folderView.folderList.length + " 个文件夹, "
					+ folderView.fileList.length + " 个文件。");
青阳龙野's avatar
青阳龙野 已提交
3821 3822 3823 3824 3825
}

// 替换所有引号,将其进一步转义,主要用于传递带引号的文件名
function replaceAllQuotationMarks(txt) {
	return txt.replace(/\"/g, "\\\"");
高源 已提交
3826
}