/**
* home.jsp
*/
var locationpath = "root";
var parentpath = "null";
$(function() {
getServerOS();
showFolderView('root');
});
// 获取服务器操作系统
function getServerOS() {
$.ajax({
type : "POST",
dataType : "text",
data : {
},
url : "homeController/getServerOS.ajax",
success : function(result) {
$("#serverOS").text(result);
},
error : function() {
$("#serverOS").html("获取失败,点击重试");
}
});
}
// 获取实时文件夹视图
function showFolderView(fid) {
$.ajax({
type : 'POST',
dataType : 'text',
data : {
fid : fid
},
url : 'homeController/getFolderView.ajax',
success : function(result) {
var folderView = eval("(" + result + ")");
locationpath = folderView.folder.folderId;
parentpath = folderView.folder.folderParent;
showParentList(folderView);
showAccountView(folderView);
showPublishTime(folderView);
showFolderTable(folderView);
},
error : function() {
$("#tb").html("获取失败,请尝试刷新");
$("#publishTime").html("获取失败,请尝试刷新");
$("#parentlistbox")
.html("获取失败,请尝试刷新");
}
});
}
// 登录操作
function dologin() {
var accountid = $("#accountid").val();
var accountpwd = $("#accountpwd").val();
var check = "y";
if (accountid.length == 0) {
$("#accountidbox").addClass("has-error");
check = "n"
} else {
$("#accountidbox").removeClass("has-error");
}
if (accountpwd.length == 0) {
$("#accountpwdbox").addClass("has-error");
check = "n"
} else {
$("#accountpwdbox").removeClass("has-error");
}
if (check == "y") {
$.ajax({
type : "POST",
dataType : "text",
url : "homeController/doLogin.ajax",
data : {
accountid : accountid,
accountpwd : accountpwd
},
success : function(result) {
$("#alertbox").removeClass("alert");
$("#alertbox").removeClass("alert-danger");
$("#alertbox").text("");
if (result == "permitlogin") {
$("#accountidbox").removeClass("has-error");
$("#accountpwdbox").removeClass("has-error");
window.location.href = "home.jsp";
} else if (result == "accountnotfound") {
$("#accountidbox").addClass("has-error");
$("#accountpwdbox").removeClass("has-error");
$("#alertbox").addClass("alert");
$("#alertbox").addClass("alert-danger");
$("#alertbox").text("提示:登录失败,账户不存在或未设置");
} else if (result == "accountpwderror") {
$("#accountpwdbox").addClass("has-error");
$("#accountidbox").removeClass("has-error");
$("#alertbox").addClass("alert");
$("#alertbox").addClass("alert-danger");
$("#alertbox").text("提示:登录失败,密码错误或未设置");
} else {
$("#alertbox").addClass("alert");
$("#alertbox").addClass("alert-danger");
$("#alertbox").text("提示:无法登录,未知错误");
}
},
error : function() {
$("#alertbox").addClass("alert");
$("#alertbox").addClass("alert-danger");
$("#alertbox").text("提示:登录请求失败,请检查网络或服务器运行状态");
}
});
}
}
// 注销操作
function dologout() {
$('#logoutModal').modal('hide');
window.location.href = "homeController/doLogout.do";
}
// 显示当前文件夹的父级路径
function showParentList(folderView) {
$("#parentlistbox").html("");
var f = folderView.folder;
var index = 0;
$.each(folderView.parentList, function(n, val) {
if (index <= 6) {
$("#parentlistbox").append(
" / ");
index++;
} else {
}
});
if (index > 6) {
$("#parentlistbox").append("... / ");
}
$("#parentlistbox").append(f.folderName);
}
// 显示用户视图,包括文件列表、登录信息、操作权限接口等
function showAccountView(folderView) {
$("#tb").html("");
if (folderView.account != null) {
// 说明已经等陆,显示注销按钮
$("#tb")
.append(
"");
} else {
// 说明用户未登录,显示登录按钮
$("#tb")
.append(
"");
}
var authList = folderView.authList;
console.log(folderView);
if (authList != null) {
if (checkAuth(authList, "C")) {
$("#parentlistbox")
.append(
"");
}
if (checkAuth(authList, "U")) {
$("#parentlistbox")
.append(
"");
}
}
}
// 检查权限列表
function checkAuth(authList, auth) {
var k = false;
$.each(authList, function(n, a) {
if (a == auth) {
k = true;
}
});
return k;
}
// 显示视图更新时间
function showPublishTime(folderView) {
$("#publishTime").html("");
var pt = "";
if (folderView.publishTime != null) {
pt = folderView.publishTime;
} else {
pt = "--";
}
$("#publishTime").text(pt);
}
// 刷新文件夹视图
function refreshFolderView() {
if (locationpath != null && locationpath.length > 0) {
showFolderView(locationpath);
} else {
showFolderView('root');
}
}
// 返回上一级文件夹
function returnPF() {
if (parentpath != null && parentpath != "null") {
showFolderView(parentpath);
} else {
showFolderView('root');
}
}
// 显示文件夹内容
function showFolderTable(folderView) {
$("#foldertable").html("");
if (parentpath != null && parentpath != "null") {
$("#foldertable")
.append(
"
--
--
--
--
");
}
var authList = folderView.authList;
var aD = false;
var aR = false;
var aL = false;
if (checkAuth(authList, "D")) {
aD = true;
}
if (checkAuth(authList, "R")) {
aR = true;
}
if (checkAuth(authList, "L")) {
aL = true;
}
$
.each(
folderView.folderList,
function(n, f) {
var folderRow = "