|
|
/**
|
|
|
* Created by frw on 2016/6/17.
|
|
|
*/
|
|
|
|
|
|
var selectedNodeId = null;
|
|
|
|
|
|
var treeData = [];
|
|
|
var nodeId2id = function (nodeid) {
|
|
|
if (nodeid == "#") {
|
|
|
return 0;
|
|
|
} else {
|
|
|
return nodeid.split("_")[1];
|
|
|
}
|
|
|
};
|
|
|
|
|
|
var getPath = function (nodeid) {
|
|
|
var paths = [];
|
|
|
var num = 0;
|
|
|
var currentId = nodeid;
|
|
|
while (currentId != "#") {
|
|
|
var node = $("#jstree").jstree().get_node(currentId);
|
|
|
paths.push(node.text);
|
|
|
num++;
|
|
|
currentId = node.parent;
|
|
|
}
|
|
|
|
|
|
var strPath = "";
|
|
|
for (var i = 0; i < num; i++) {
|
|
|
strPath += paths.pop() + "/";
|
|
|
}
|
|
|
return strPath;
|
|
|
}
|
|
|
|
|
|
var openTree = function (node_id, level) {
|
|
|
// console.log("open tree" + node_id);
|
|
|
try {
|
|
|
var node = $("#jstree").jstree().get_node(node_id);
|
|
|
$("#jstree").jstree("open_node", node);
|
|
|
var children = node.children;
|
|
|
} catch (e) {
|
|
|
console.warn(e);
|
|
|
return;
|
|
|
}
|
|
|
// console.log("open children" +children);
|
|
|
if (level <= 1)
|
|
|
return;
|
|
|
level--;
|
|
|
$.each(children, function (n, data) {
|
|
|
openTree(data, level);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
var addType = function (node) {
|
|
|
var rel = 0;
|
|
|
var pid;
|
|
|
var name;
|
|
|
var isleaf;
|
|
|
$('#modal_type_update').hide();
|
|
|
$('#modal_type_del').hide();
|
|
|
$('#modal_type_add').show();
|
|
|
$('#myModalLabel').html("添加类型");
|
|
|
$('#cb_new_type_isleaf').prop("checked", true);// 默认为子节点
|
|
|
$('#tx_new_type_name').val("");
|
|
|
$('#tx_type_id').val(nodeId2id(node.id));
|
|
|
$('#tx_type_action').val("add");
|
|
|
$('#tx_new_type_isleaf').val(1);
|
|
|
$('#tx_new_type_parent').val(getPath(node.id));
|
|
|
$('#myModal').modal({keyboard: true});
|
|
|
|
|
|
return rel;
|
|
|
};
|
|
|
|
|
|
var doAddType = function () {
|
|
|
var pid = $('#tx_type_id').val();
|
|
|
var name = $('#tx_new_type_name').val();
|
|
|
if (name == null || $('#tx_new_type_name').val() == "") {
|
|
|
$.toaster('输入类型名', '提示', 'warning');
|
|
|
return;
|
|
|
}
|
|
|
var isleaf = $('#cb_new_type_isleaf').prop("checked") == true ? 1 : 0;
|
|
|
$.get("type/add", {"pid": pid, "name": name, "isleaf": isleaf},
|
|
|
function (data, state) {
|
|
|
var repjson = JSON.parse(data);
|
|
|
if (state == "success" && repjson.code == 200) {
|
|
|
$.toaster('添加成功', '提示', 'info');
|
|
|
console.log(repjson.data);
|
|
|
var newNode = repjson.data;
|
|
|
$('#jstree').jstree().create_node("#node_" + newNode.typeParentId,
|
|
|
{
|
|
|
'id': "node_" + newNode.typeId,
|
|
|
'text': newNode.typeName,
|
|
|
'parent': "#node_" + newNode.typeParentId,
|
|
|
'data': newNode.typeIsLeaf
|
|
|
}, 'last');
|
|
|
$('#jstree').jstree().get_node("node_" + newNode.typeId).data = newNode.typeIsLeaf;
|
|
|
} else
|
|
|
$.toaster('添加失败' + repjson.code + " " + repjson.message, '提示', 'warning');
|
|
|
}
|
|
|
).fail(function () {
|
|
|
$.toaster('添加失败:', '提示', 'warning');
|
|
|
});
|
|
|
$('#myModal').dialog('hide');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取所有选择节点
|
|
|
* @param isleaf true:仅获取叶子节点;false:所有节点
|
|
|
* @returns {Array}
|
|
|
*/
|
|
|
var getSelectType = function (isleaf) {
|
|
|
var seltypes = [];
|
|
|
$.each($("#jstree").jstree('get_selected'), function (idx, nodeid) {
|
|
|
var node = $('#jstree').jstree().get_node(nodeid);
|
|
|
if (isleaf == true && node.data != 1)
|
|
|
return;
|
|
|
seltypes.push(nodeId2id(nodeid));
|
|
|
});
|
|
|
|
|
|
return seltypes;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 检查节点是否子节点
|
|
|
* @param nodeid
|
|
|
* @returns {boolean}
|
|
|
*/
|
|
|
var checkIsLeaf = function (nodeid) {
|
|
|
var node = $('#jstree').jstree().get_node(nodeid);
|
|
|
var isLeaf = node.data == 1 ? true : false;
|
|
|
return isLeaf;
|
|
|
}
|
|
|
|
|
|
|
|
|
$("#btn4type").click(function () {
|
|
|
console.log("frw");
|
|
|
if ($("#tx_type_action").val() == "add") {
|
|
|
doAddType();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
var curIp;
|
|
|
/**
|
|
|
* 根据选中的节点获取信息
|
|
|
*/
|
|
|
function searchType(ip, children, nodeId){
|
|
|
|
|
|
//非叶子节点不处理
|
|
|
if(children.length != 0) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//将原来选中的节点的背景颜色去掉
|
|
|
if(selectedNodeId != null) {
|
|
|
var nodeStyle = document.getElementById(selectedNodeId).style;
|
|
|
nodeStyle.backgroundColor="";
|
|
|
nodeStyle.color="black";
|
|
|
//document.getElementById(selectedNodeId).style.backgroundColor="";
|
|
|
}
|
|
|
|
|
|
//给选中的节点添加背景颜色
|
|
|
var nodeStyle = document.getElementById(nodeId).style;
|
|
|
nodeStyle.backgroundColor = "#3392e3";
|
|
|
nodeStyle.color = "#ffffff";
|
|
|
selectedNodeId = nodeId;
|
|
|
|
|
|
//新增按钮
|
|
|
curIp = ip;
|
|
|
$("#add_btn").css("display", "block");
|
|
|
|
|
|
$("#detailTable").hide();
|
|
|
$("#rootTable").table({
|
|
|
url: contextPath + "/zkTree/getRootConfigCenter?ip="+ip,
|
|
|
striped: true,
|
|
|
panelClass: "panel-success",
|
|
|
pagination: false,
|
|
|
loadFilter: function (data) {
|
|
|
return defaultLoadFilter(data);
|
|
|
},
|
|
|
columns: [{
|
|
|
title: "名称",
|
|
|
field: "name",
|
|
|
formatter: function (value, rowData, rowIndex) {
|
|
|
var div = $("<div>");
|
|
|
var input = $("<input type=\"button\">").addClass("form-control").attr({
|
|
|
id :"name",
|
|
|
name : "name",
|
|
|
style : "border: none;",
|
|
|
value : value
|
|
|
}).appendTo(div);
|
|
|
input.click(function () {
|
|
|
toDetail(rowData,ip);
|
|
|
});
|
|
|
return div;
|
|
|
}
|
|
|
}, {
|
|
|
title: "路径",
|
|
|
field: "root",
|
|
|
width: 200,
|
|
|
}, {
|
|
|
title: "操作",
|
|
|
formatter: function (value, rowData, rowIndex) {
|
|
|
var div = $("<div>");
|
|
|
|
|
|
//修改
|
|
|
var editBtn = $("<button data-target='#updateModal' data-toggle='modal'>").addClass("btn btn-xs btn-success").html("修改").appendTo(div);
|
|
|
editBtn.click(function () {
|
|
|
updateRoot(rowData,ip);
|
|
|
});
|
|
|
|
|
|
//导入
|
|
|
var importBtn = $("<button data-target='#importModal' data-toggle='modal' style='margin-left: 10px;'>").addClass("btn btn-xs btn-warning").html("导入").appendTo(div);
|
|
|
importBtn.click(function () {
|
|
|
importFile(rowData,ip);
|
|
|
});
|
|
|
return div;
|
|
|
}
|
|
|
}],
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function addRoot(){
|
|
|
var dialog0 = $("<div>").appendTo($("body"));
|
|
|
dialog0.dialog({
|
|
|
size : "modal-lg",
|
|
|
title : "新增根路径",
|
|
|
backdrop : "static",
|
|
|
href : contextPath +"/jsp/zkConfigCenter/zkRootAdd.jsp",
|
|
|
buttons : [{
|
|
|
text : "关闭",
|
|
|
className : "btn-danger",
|
|
|
onclick : function() {
|
|
|
$(dialog0).dialog("hide");
|
|
|
}
|
|
|
}, {
|
|
|
text : "提交",
|
|
|
className : "btn-success",
|
|
|
onclick : function() {
|
|
|
var btn = $(this);
|
|
|
$(dialog0).dialog("hide");
|
|
|
|
|
|
$("#zkRootInfoForm").form("submit", {
|
|
|
submitUrl : contextPath + "/zkTree/addRoot",
|
|
|
submitData : {
|
|
|
ip : curIp,
|
|
|
root : $("#zkRootInfoForm #zkRoot").val()
|
|
|
},
|
|
|
onBeforeSubmit : function() {
|
|
|
if (!$(this).form("validate")) {
|
|
|
btn.removeAttr("disabled");
|
|
|
return false;
|
|
|
}
|
|
|
},
|
|
|
success : function(data) {
|
|
|
var mes="";
|
|
|
if (data.data==1) {
|
|
|
mes="新增成功";
|
|
|
} else {
|
|
|
mes="新增失败!确认节点是否已存在!";
|
|
|
}
|
|
|
if(data.data==1){
|
|
|
var dialog = $("<div>").appendTo($("body"));
|
|
|
dialog.dialog({
|
|
|
title :mes,
|
|
|
backdrop : "static",
|
|
|
content : mes,
|
|
|
buttons : [{
|
|
|
text : "确定",
|
|
|
className : "btn-success",
|
|
|
onclick : function() {
|
|
|
$(dialog).dialog("hide");
|
|
|
$("#rootTable").table("load");
|
|
|
}
|
|
|
}]
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}]
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function importFile(rowData,ip){
|
|
|
paramObj.name = rowData.name;
|
|
|
paramObj.root = rowData.root;
|
|
|
var dialog0 = $("<div>").appendTo($("body"));
|
|
|
dialog0.dialog({
|
|
|
size : "modal-lg",
|
|
|
title : "批量导入",
|
|
|
backdrop : "static",
|
|
|
href : contextPath +"/jsp/zkConfigCenter/zkConfigCenterImport.jsp",
|
|
|
buttons : [{
|
|
|
text : "关闭",
|
|
|
className : "btn-danger",
|
|
|
onclick : function() {
|
|
|
$(dialog0).dialog("hide");
|
|
|
}
|
|
|
}, {
|
|
|
text : "提交",
|
|
|
className : "btn-success",
|
|
|
onclick : function() {
|
|
|
var filepath = $("#zkImportForm #filepath").val();
|
|
|
if (filepath == "") {
|
|
|
alert("请选择文件!");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (filepath.indexOf(".properties") == -1) {
|
|
|
alert("文件格式不对!");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
$("#ip").val(ip);
|
|
|
var formData = new FormData($("#zkImportForm")[0]);
|
|
|
$(dialog0).dialog("hide");
|
|
|
$.ajax({
|
|
|
url: contextPath + "/zkTree/batchImport",
|
|
|
type: 'POST',
|
|
|
data: formData,
|
|
|
async: false,
|
|
|
cache: false,
|
|
|
contentType: false,
|
|
|
processData: false,
|
|
|
success: function (data) {
|
|
|
var mes="";
|
|
|
if (data.data > 0) {
|
|
|
mes="修改成功";
|
|
|
} else {
|
|
|
mes="修改失败";
|
|
|
}
|
|
|
var dialog = $("<div>").appendTo($("body"));
|
|
|
dialog.dialog({
|
|
|
title :mes,
|
|
|
backdrop : "static",
|
|
|
content : mes,
|
|
|
buttons : [{
|
|
|
text : "确定",
|
|
|
className : "btn-success",
|
|
|
onclick : function() {
|
|
|
$(dialog).dialog("hide");
|
|
|
$("#rootTable").table("load");
|
|
|
}
|
|
|
}]
|
|
|
});
|
|
|
},
|
|
|
error: function (returndata) {
|
|
|
alert(returndata);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
}
|
|
|
}]
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function updateRoot(rowData,ip){
|
|
|
paramObj.name = rowData.name;
|
|
|
paramObj.root = rowData.root;
|
|
|
var dialog0 = $("<div>").appendTo($("body"));
|
|
|
dialog0.dialog({
|
|
|
size : "modal-lg",
|
|
|
title : "修改路径",
|
|
|
backdrop : "static",
|
|
|
href : contextPath +"/jsp/zkMonitor/zkRootEdit.jsp",
|
|
|
buttons : [{
|
|
|
text : "关闭",
|
|
|
className : "btn-danger",
|
|
|
onclick : function() {
|
|
|
$(dialog0).dialog("hide");
|
|
|
}
|
|
|
}, {
|
|
|
text : "提交",
|
|
|
className : "btn-success",
|
|
|
onclick : function() {
|
|
|
var btn = $(this);
|
|
|
$(dialog0).dialog("hide");
|
|
|
|
|
|
$("#zkRootInfoForm").form("submit", {
|
|
|
submitUrl : contextPath + "/zkTree/editRoot",
|
|
|
submitData : {
|
|
|
ip : ip,
|
|
|
name : $("#zkRootInfoForm #zkName").val(),
|
|
|
root : $("#zkRootInfoForm #zkRoot").val(),
|
|
|
oldRoot : rowData.root
|
|
|
},
|
|
|
onBeforeSubmit : function() {
|
|
|
|
|
|
if (!$(this).form("validate")) {
|
|
|
btn.removeAttr("disabled");
|
|
|
return false;
|
|
|
}
|
|
|
},
|
|
|
success : function(data) {
|
|
|
var mes="";
|
|
|
if(data.data==1){
|
|
|
mes="修改成功";
|
|
|
}else{
|
|
|
mes="修改失败";
|
|
|
}
|
|
|
if(data.data==1){
|
|
|
var dialog = $("<div>").appendTo($("body"));
|
|
|
dialog.dialog({
|
|
|
title :mes,
|
|
|
backdrop : "static",
|
|
|
content : mes,
|
|
|
buttons : [{
|
|
|
text : "确定",
|
|
|
className : "btn-success",
|
|
|
onclick : function() {
|
|
|
$(dialog).dialog("hide");
|
|
|
$("#rootTable").table("load");
|
|
|
}
|
|
|
}]
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}]
|
|
|
});
|
|
|
}
|
|
|
|
|
|
var refreshTypeTree = function () {
|
|
|
console.log("refresh tree");
|
|
|
treeData = []; //重置
|
|
|
$.get(contextPath+"type/zkTree", function (data, state) {
|
|
|
console.log(state)
|
|
|
var jsonData = JSON.parse(data);
|
|
|
$.each(jsonData.data, function (n, val) {
|
|
|
var treeNode = {};
|
|
|
treeNode.id = "node_" + val.typeId;
|
|
|
treeNode.parent = (val.typeParentId == 0 ? "#" : "node_" + val.typeParentId);
|
|
|
treeNode.text = val.typeName;
|
|
|
treeNode.data = val.typeIsLeaf;
|
|
|
treeData.push(treeNode)
|
|
|
});
|
|
|
$('#jstree').jstree(true).settings.core.data = treeData;
|
|
|
$('#jstree').jstree().refresh(true, true);
|
|
|
|
|
|
setTimeout("openTree('#', 3)", 300); //展开三层
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
$('#jstree').jstree({
|
|
|
"plugins": ["themes", "contextmenu", "ui", "types", "crrm", "core", "status"],
|
|
|
'core': {
|
|
|
"themes": {
|
|
|
name: 'proton',
|
|
|
dots: false,
|
|
|
icons: false
|
|
|
},
|
|
|
'data': treeData,
|
|
|
'check_callback': true
|
|
|
}
|
|
|
}).bind("changed.jstree",
|
|
|
function (e, data) {
|
|
|
console.log(data);
|
|
|
console.log("Checked: " + data.node.text);
|
|
|
searchType(data.node.text, data.node.children, data.node.a_attr.id);
|
|
|
});
|
|
|
refreshTypeTree(); |
...
|
...
|
|