Authored by zhengyouwei

Merge branch 'master' of http://git.yoho.cn/ops/monitor-ui

# Conflicts:
#	monitor-ui-web/src/main/webapp/index.jsp
... ... @@ -19,5 +19,17 @@ public class HttpUriContants {
public static String TYPE_ADD = "/type/add";
public static String TYPE_DEL = "/type/delete";
public static String TYPE_UPDATE = "/type/update";
public static String TYPE_QUERY_NODE = "/type/queryNode";
/*** 主机信息 ****/
public static final String GET_HOST_INFOS = "/hostInfo/getHostInfos";
public static final String SAVE_HOST_INFOS = "/hostInfo/saveHostInfo";
public static final String DEL_HOST_INFOS = "/hostInfo/delHostInfo";
public static final String GET_HOST_INFO_BY_ID = "/hostInfo/getHostInfoById";
/*** 主机信息 ****/
}
... ...
... ... @@ -7,8 +7,8 @@ import lombok.Data;
* Created by yoho on 2016/6/16.
*/
@Data
public class MObjectModel {
private int moId;
public class MObjectModel {
private int moId = 0;
private String moName;
... ...
... ... @@ -8,6 +8,24 @@ import lombok.Data;
@Data
public class MObjectInfoReq extends PageRequest {
private int moId = 0;
private String moName;
private String moHostIp;
private String moTypeName;
private String moStatus;
private int moHostId;
private int moTypeId;
private String moTags;
private String moUrl;
String typeIds = "0";
String hostIds = "0";
... ...
... ... @@ -69,6 +69,5 @@ public class HostGroupCtrl {
}
}
... ...
package com.ui.ctrl;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.req.HostInfoReq;
... ... @@ -28,7 +29,7 @@ public class HostInfoCtrl {
@RequestMapping("/getHostInfos")
@ResponseBody
public BaseResponse getHostInfos(HostInfoReq req) throws Exception {
BaseResponse response=httpRestClient.defaultPost("/hostInfo/getHostInfos", req, BaseResponse.class);
BaseResponse response=httpRestClient.defaultPost(HttpUriContants.GET_HOST_INFOS, req, BaseResponse.class);
return response;
}
... ... @@ -36,7 +37,7 @@ public class HostInfoCtrl {
@RequestMapping("/saveHostInfo")
@ResponseBody
public BaseResponse saveHostInfo(HostInfoReq req) throws Exception {
BaseResponse response=httpRestClient.defaultPost("/hostInfo/saveHostInfo", req, BaseResponse.class);
BaseResponse response=httpRestClient.defaultPost(HttpUriContants.SAVE_HOST_INFOS, req, BaseResponse.class);
return response;
}
... ... @@ -44,14 +45,14 @@ public class HostInfoCtrl {
@RequestMapping("/delHostInfo")
@ResponseBody
public BaseResponse<Integer> delHostInfo(int id ) throws Exception {
BaseResponse response=httpRestClient.defaultGet("/hostInfo/delHostInfo?id=" + id, BaseResponse.class);
BaseResponse response=httpRestClient.defaultGet(HttpUriContants.DEL_HOST_INFOS+"?id=" + id, BaseResponse.class);
return response;
}
@RequestMapping("/getHostInfoById")
@ResponseBody
public BaseResponse getHostInfoById(int id) throws Exception {
BaseResponse response=httpRestClient.defaultGet("/hostInfo/getHostInfoById?id="+id, BaseResponse.class);
BaseResponse response=httpRestClient.defaultGet(HttpUriContants.GET_HOST_INFO_BY_ID+"?id="+id, BaseResponse.class);
return response;
}
... ...
... ... @@ -3,8 +3,6 @@ package com.ui.ctrl;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.req.MObjectInfoReq;
import com.ui.model.req.PageRequest;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
... ... @@ -18,6 +16,7 @@ public class MObjectInfoCtrl {
@Autowired
HttpRestClient httpRestClient;
//前台提供currentpage,pagesize,isType,typeIds,hostIps
@RequestMapping(value = "/query", method = RequestMethod.POST)
public BaseResponse queryAllMObjectInfo(MObjectInfoReq request) {
... ... @@ -27,4 +26,32 @@ public class MObjectInfoCtrl {
}
//前台提供mo_id
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public BaseResponse deleteMObjectInfo(MObjectInfoReq request) {
BaseResponse response = httpRestClient.defaultPost("/mobject/delete", request, BaseResponse.class);
return response;
}
//前台提供 mo_id,mo_name,mo_typeId,mo_hostIP,mo_tags,mo_url
@RequestMapping(value = "/update", method = RequestMethod.POST)
public BaseResponse updateMObjectInfo(MObjectInfoReq request) {
BaseResponse response = httpRestClient.defaultPost("/mobject/update", request, BaseResponse.class);
return response;
}
//前台提供 mo_name,mo_typeId,mo_hostIp,mo_tags,mo_url
@RequestMapping(value = "/add", method = RequestMethod.POST)
public BaseResponse addMObjectInfo(MObjectInfoReq request) {
BaseResponse response = httpRestClient.defaultPost("/mobject/add", request, BaseResponse.class);
return response;
}
}
... ...
... ... @@ -3,6 +3,7 @@ package com.ui.ctrl;
import com.alibaba.fastjson.JSONObject;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -88,4 +89,11 @@ public class TypeCtrl {
return rel;
}
@RequestMapping("/queryNode")
@ResponseBody
public BaseResponse queryNode() throws Exception {
BaseResponse response=httpClient.defaultGet(HttpUriContants.TYPE_QUERY_NODE, BaseResponse.class);
return response;
}
}
... ...
... ... @@ -36,7 +36,7 @@
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.validate.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.form.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/layer/layer.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.select.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/jstree/jstree.min.js"></script>
<script src="<%=basePath %>js/jquery.toaster.js"></script>
<script>
... ...
... ... @@ -29,18 +29,16 @@
<div class="form-group" >
<label class="col-sm-2 control-label"> <span style="color:red">*</span>主机组:</label>
<div class="col-sm-8">
<select id="groupId" name="groupId" class="form-control">
<option value="1">AWS</option>
<option value="2">腾讯云</option>
<option value="3">其他</option>
<select id="groupId" name="groupId">
</select>
</div>
</div>
<div class="form-group" >
<label class="col-sm-2 control-label"> <span style="color:red">*</span>安装软件:</label>
<div class="col-sm-8">
<input type="checkbox" name="appName" value="JAVA"> JAVA <input type="checkbox" name="appName" value="Redis" > Redis
<div class="col-sm-8" id="appNameContent">
</div>
</div>
... ... @@ -50,8 +48,39 @@
<script>
$(function () {
if(paramObj.hoseInfoId > 0){
$("#groupId").select({
valueField : "id",
textField : "groupName",
firstText : "请选择主机组类型",
firstValue : 0,
className : "form-control",
url : contextPath + "/hostGroup/getAllGroups",
loadFilter : function(data) {
return defaultLoadFilter(data);
},
value : 0
});
$.ajax({
url : contextPath +"/type/queryNode",
type : 'post',
async : false,
dataType : "json",
success : function(data) {
var contentHtml='';
$.each(data.data,function(n,value) {
if(n%6==0){
contentHtml+='</br>';
}
contentHtml+='<input type="checkbox" name="appName" value="'+value.typeName+'">' +value.typeName+'&nbsp;&nbsp;';
});
$("#appNameContent").html(contentHtml);
}
});
if(paramObj.hoseInfoId > 0){
//加载form
$("#hostInfoForm").form({
loadUrl : contextPath + "/hostInfo/getHostInfoById.do",
... ... @@ -72,18 +101,5 @@
});
}
$("#groupId").select({
firstText : "请选择分组类型",
firstValue : 0,
className : "form-control",
url : contextPath + "/NoFilterController.do?method=getEnumForSelect",
queryParams : {
className : "GroupTypeEnum"
},
loadFilter : function(data) {
return defaultLoadFilter(data);
},
value : 0
});
});
</script>
\ No newline at end of file
... ...
... ... @@ -156,7 +156,7 @@
}]
});
}
$("#smsListTable").table("load");
$("#hostInfoTable").table("load");
}
});
}
... ...
... ... @@ -49,7 +49,9 @@
</div>
<button id="submit" class="btn btn-default">搜索</button>
</div>
<button id="addBtn" class="btn btn-primary" style="margin-top: 12px;margin-left: 500px;" data-target="#myModal" data-toggle="modal">新增</button>
<button id="addBtn" class="btn btn-primary" style="margin-top: 12px;margin-left: 500px;"
data-target="#addModal" data-toggle="modal">新增
</button>
</div>
</div>
<div id="table"></div>
... ... @@ -58,8 +60,7 @@
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
... ... @@ -75,31 +76,31 @@
<div class="control-group">
<label class="control-label" style="float: left;">名称</label>
<div class="controls">
<input type="text" />
<input type="text" id="moName"/>
</div>
</div>
<div class="control-group">
<label class="control-label" style="float: left;">所属主机</label>
<div class="controls">
<input type="text" placeholder="请填写主机IP" />
<input type="text" placeholder="请填写主机IP" id="moHostIp"/>
</div>
</div>
<div class="control-group">
<label class="control-label" style="float: left;">类型</label>
<div class="controls">
<input type="text" value="" readonly="readonly" />
<input type="text" value="" readonly="readonly" id=""/>
</div>
</div>
<div class="control-group">
<label class="control-label" style="float: left;">标签</label>
<div class="controls">
<input type="text" />
<input type="text"/>
</div>
</div>
<div class="control-group">
<label class="control-label" style="float: left;">域名</label>
<div class="controls">
<input type="text" />
<input type="text"/>
</div>
</div>
</form>
... ... @@ -118,6 +119,104 @@
<!-- /.modal -->
</div>
</div>
<div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">修改</h4>
</div>
<div class="modal-body">
<div class="row-fluid">
<div class="span12">
<div class="widget-content nopadding">
<form action="#" method="post" class="form-horizontal" id="updateForm">
<div class="control-group" typeof="hidden" id="moId">
</div>
<div class="control-group" typeof="hidden" id="moTypeId">
</div>
<div class="control-group">
<label class="control-label" style="float: left;">名称</label>
<div class="controls">
<input type="text" id="moName"/>
</div>
</div>
<div class="control-group">
<label class="control-label" style="float: left;">所属主机</label>
<div class="controls">
<input type="text" placeholder="请填写主机IP" id="moHostIp"/>
</div>
</div>
<div class="control-group">
<label class="control-label" style="float: left;">类型</label>
<div class="controls">
<input type="text" readonly="readonly" id="moTypeName"/>
</div>
</div>
<div class="control-group">
<label class="control-label" style="float: left;">标签</label>
<div class="controls">
<input type="text" id="moTags"/>
</div>
</div>
<div class="control-group">
<label class="control-label" style="float: left;">域名</label>
<div class="controls">
<input type="text" id="moUrl"/>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭
</button>
<button type="submit" class="btn btn-primary" value="Validate" id="updateSubmit">提交</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal -->
</div>
</div>
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">确定删除?</h4>
</div>
<div class="modal-body">
<div class="row-fluid">
<div class="span12">
<div class="widget-content nopadding">
<form action="#" method="post" class="form-horizontal" id="deleteForm">
<div class="control-group" typeof="hidden" id="moId">
</div>
</form>
</div>
</div>
</div>
<button type="button" class="btn btn-default" style="margin-right: auto" data-dismiss="modal">取消
</button>
<button type="submit" class="btn btn-primary" style="margin-left: auto" id="deleteSubmit">确认</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal -->
</div>
</div>
<script>
$(function () {
$("#table").table({
... ... @@ -145,22 +244,29 @@
title: "标签",
field: "moTags"
}, {
title: "操作",
formatter: function (value, rowData, rowIndex) {
var div = $("<div>");
var editBtn = $("<button data-target='#myModal' data-toggle='modal'>").addClass("btn btn-inverse btn-mini").html("修改").appendTo(div);
//修改
editBtn.click(function () {
});
div.append("&nbsp;");
var delBtn = $("<button>").addClass("btn btn-danger btn-mini").html("删除").appendTo(div);
delBtn.click(function () {
});
return div;
}
}],
title: "操作",
formatter: function (value, rowData, rowIndex) {
var div = $("<div>");
//修改
var editBtn = $("<button data-target='#updateModal' data-toggle='modal'>").addClass("btn btn-primary btn-mini").html("修改").appendTo(div);
editBtn.click(function () {
updateMObject(rowData);
});
div.append("&nbsp;");
div.append("&nbsp;");
div.append("&nbsp;");
//删除
var delBtn = $("<button data-target='#deleteModal' data-toggle='modal'>").addClass("btn btn-danger btn-mini").html("删除").appendTo(div);
delBtn.click(function () {
deleteMObject(rowData);
}
);
return div;
}
}],
/* data: data*/
});
... ... @@ -225,15 +331,96 @@
alert(2);
}
function deleteMObject(rowData) {
$("#deleteModal #moId").val(rowData.moId);
}
</script>
function updateMObject(rowData) {
$("#updateModal #moName").val(rowData.moName);
$("#updateModal #moHostIp").val(rowData.moHostIp);
$("#updateModal #moTypeName").val(rowData.moTypeName);
$("#updateModal #moTags").val(rowData.moTags);
$("#updateModal #moUrl").val(rowData.moUrl);
<script src="js/jquery.min.js"></script>
<script src="js/jquery.ui.custom.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.uniform.js"></script>
<script src="js/select2.min.js"></script>
<script src="js/jquery.validate.js"></script>
<script src="js/unicorn.js"></script>
<script src="js/unicorn.form_validation.js"></script>
$("#updateModal #moId").val(rowData.moId);
$("#updateModal #moTypeId").val(rowData.moTypeId);
}
$("#updateModal #updateSubmit").click(function () {
if(!validEmpty($("#updateModal #moName").val()))
{
alert("必须填写监控对象名称!");
return;
}
if (!validIp($("#updateModal #moHostIp").val())) {
alert("Ip 填写错误!");
return;
}
$.ajax({
url: contextPath + "/mobject/update",
type: "post",
dataType: "json",
data: {
moId: $("#updateModal #moId").val(),
moName: $("#updateModal #moName").val(),
moHostIp: $("#updateModal #moHostIp").val(),
moTypeId: $("#updateModal #moTypeId").val(),
moTypeName: $("#updateModal #moTypeName").val(),
moTags: $("#updateModal #moTags").val(),
moUrl: $("#updateModal #moUrl").val()
},
success: function () {
var div = document.getElementById("updateModal");
div.style.display = "none";
},
error: function () {
}
});
});
function validIp(ip) {
var iPattern = /^([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$/;
if ("" != ip && iPattern.test(ip)) {
return true;
}
else {
return false;
}
}
function validEmpty(str) {
if ("" != str) {
return true;
}
else {
return false;
}
}
$("#deleteModal #deleteSubmit").click(function () {
$.ajax({
url: contextPath + "/mobject/delete",
type: "post",
dataType: "json",
data: {
moId: $("#deleteModal #moId").val()
}
});
});
function addMObject() {
}
</script>
 
\ No newline at end of file
... ...
... ... @@ -98,220 +98,9 @@
</script>
<script>
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);
console.log(node);
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);
var node = $("#jstree").jstree().get_node(node_id);
$("#jstree").jstree("open_node", node)
var children = node.children;
// 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("添加类型");
$('#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});
<script type="text/javascript" src="<%=basePath %>/script/yoho.type.tree.js"></script>
return rel;
};
var delType = function (id) {
var rel = 0;
$('#myModalLabel').html("确认删除?");
$('#tx_type_action').val("del");
$('#modal_type_update').hide();
$('#modal_type_add').hide();
$('#modal_type_del').show();
$('#tx_type_id').val(nodeId2id(id));
$('#myModal').modal({keyboard: true});
return rel;
};
var updateType = function (id, oldName) {
var rel = 0;
$('#myModalLabel').html("更新类型");
$('#tx_type_action').val("update");
$('#tx_type_id').val(nodeId2id(id));
$('#tx_update_type_name_old').val(oldName);
$('#modal_type_update').show();
$('#modal_type_add').hide();
$('#modal_type_del').hide();
$('#myModal').modal({keyboard: true});
return rel;
};
var doAddType = function () {
var pid = $('#tx_type_id').val();
var name = $('#tx_new_type_name').val();
var isleaf = 1;
$.get("type/add", {"pid": pid, "name": name, "isleaf": isleaf},
function (data, state) {
$.toaster('添加成功', '添加', 'info');
refreshTypeTree();
}
);
}
var doUpdateType = function () {
var id = $('#tx_type_id').val();
var name = $('#tx_update_type_name_new').val();
console.log("update " + id + " name " + name);
$.get("type/update", {"id": id, "name": name},
function (data, state) {
$.toaster('更新成功', '更新', 'info');
refreshTypeTree();
}
);
}
var doDelType = function () {
var id = $('#tx_type_id').val();
console.log("delete " + id);
$.get("type/del", {"id": id},
function (data, state) {
$('#jstree').jstree("delete_node", $("#" + id));
}
);
}
$("#btn4type").click(function () {
console.log("frw");
if ($("#tx_type_action").val() == "add") {
doAddType();
}
else if ($("#tx_type_action").val() == "update") {
doUpdateType();
} else if ($("#tx_type_action").val() == "del") {
doDelType();
}
$('#myModal').dialog('hide');
});
var refreshTypeTree = function () {
console.log("refresh tree");
treeData = []; //重置
$.get("type/all", 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);
setInterval("openTree('#', 3)", 300); //展开三层
});
}
$(function () {
$('#jstree').jstree({
"plugins": ["themes", "checkbox", "contextmenu", "ui", "types", "crrm", "core", "status"],
'core': {
"themes": {
"icons": false
},
'data': treeData,
'check_callback': true
},
'contextmenu': {
"select_node": false,
"items": {
"ADD": {
"label": "添加类型",
"action": function (obj) {
var inst = jQuery.jstree.reference(obj.reference);
var clickedNode = inst.get_node(obj.reference);
console.log(obj);
console.log(clickedNode);
console.log("add operation--clickedNode's id is:" + clickedNode.id);
addType(clickedNode);
}
}, "UPDATE": {
"label": "修改类型",
"action": function (obj) {
var inst = jQuery.jstree.reference(obj.reference);
var clickedNode = inst.get_node(obj.reference);
updateType(clickedNode.id, clickedNode.text);
}
}, "DEL": {
"label": "删除类型",
"action": function (obj) {
var inst = jQuery.jstree.reference(obj.reference);
var clickedNode = inst.get_node(obj.reference);
console.log("del operation--clickedNode's id is:" + clickedNode.id);
delType(clickedNode.id);
}
}, "ADDM": {
"label": "添加服务对象",
"action": function (obj) {
var inst = jQuery.jstree.reference(obj.reference);
var clickedNode = inst.get_node(obj.reference);
console.log(obj);
addMObjType(clickedNode);
}
}
}
}
}).bind("loaded.jstree", function (event, data) {
openTree("#", 3); //展开三层
});
refreshTypeTree();
});
</script>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
... ... @@ -362,4 +151,4 @@
</div>
</div>
</div>
</div>
\ No newline at end of file
</div>
... ...
/**
* Created by frw on 2016/6/17.
*/
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);
console.log(node);
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);
var node = $("#jstree").jstree().get_node(node_id);
$("#jstree").jstree("open_node", node)
var children = node.children;
// 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("添加类型");
$('#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 delType = function (id) {
var rel = 0;
$('#myModalLabel').html("确认删除?");
$('#tx_type_action').val("del");
$('#modal_type_update').hide();
$('#modal_type_add').hide();
$('#modal_type_del').show();
$('#tx_type_id').val(nodeId2id(id));
$('#myModal').modal({keyboard: true});
return rel;
};
var updateType = function (id, oldName) {
var rel = 0;
$('#myModalLabel').html("更新类型");
$('#tx_type_action').val("update");
$('#tx_type_id').val(nodeId2id(id));
$('#tx_update_type_name_old').val(oldName);
$('#modal_type_update').show();
$('#modal_type_add').hide();
$('#modal_type_del').hide();
$('#myModal').modal({keyboard: true});
return rel;
};
var addMObjType = function (nodeid, name) {
var id = nodeId2id(nodeid); //服务对象id
var path = getPath(nodeid); //服务对象完整类型路径
console.log("id: " + id + " path: " + path + " name :" + name);
//TODO 打开新增服务对象对话框
}
var doAddType = function () {
var pid = $('#tx_type_id').val();
var name = $('#tx_new_type_name').val();
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');
} else
$.toaster('添加失败' + repjson.code, '提示', 'warning');
}
).fail(function () {
$.toaster('添加失败:', '提示', 'warning');
});
}
var doUpdateType = function () {
var id = $('#tx_type_id').val();
var name = $('#tx_update_type_name_new').val();
console.log("update " + id + " name " + name);
$.get("type/update", {"id": id, "name": name},
function (data, state) {
$.toaster('更新成功', '更新', 'info');
$("#jstree").jstree('set_text', '#node_' + id, name);
}
).fail(function () {
$.toaster('更新失败:', '提示', 'warning');
});
;
}
var doDelType = function () {
var id = $('#tx_type_id').val();
console.log("delete " + id);
$.get("type/del", {"id": id},
function (data, state) {
$('#jstree').jstree("delete_node", $("#" + id));
}
).fail(function () {
$.toaster('删除失败:', '提示', 'warning');
});
;
}
/**
* 获取所有选择节点
* @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();
}
else if ($("#tx_type_action").val() == "update") {
doUpdateType();
} else if ($("#tx_type_action").val() == "del") {
doDelType();
}
$('#myModal').dialog('hide');
});
var refreshTypeTree = function () {
console.log("refresh tree");
treeData = []; //重置
$.get("type/all", 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);
setInterval("openTree('#', 3)", 300); //展开三层
});
}
$(function () {
$('#jstree').jstree({
"plugins": ["themes", "checkbox", "contextmenu", "ui", "types", "crrm", "core", "status"],
'core': {
"themes": {
"theme": "proton",
"icons": false
},
'data': treeData,
'check_callback': true
},
'contextmenu': {
"select_node": false,
"items": {
"ADD": {
"label": "添加类型",
"action": function (obj) {
var inst = jQuery.jstree.reference(obj.reference);
var clickedNode = inst.get_node(obj.reference);
console.log("add operation--clickedNode's id is:" + clickedNode.id + " " + clickedNode);
if (clickedNode.data != 0) {
$.toaster('叶子节点无法添加子类型', '提示', 'info');
return;
}
addType(clickedNode);
}
}, "UPDATE": {
"label": "修改类型",
"action": function (obj) {
var inst = jQuery.jstree.reference(obj.reference);
var clickedNode = inst.get_node(obj.reference);
updateType(clickedNode.id, clickedNode.text);
}
}, "DEL": {
"label": "删除类型",
"action": function (obj) {
var inst = jQuery.jstree.reference(obj.reference);
var clickedNode = inst.get_node(obj.reference);
console.log("del operation--clickedNode's id is:" + clickedNode.id);
console.log(clickedNode.children);
if (clickedNode.children.length > 0) {
$.toaster('无法直接删除还有子类型的节点', '提示', 'info');
return;
}
delType(clickedNode.id);
}
}, "ADDM": {
"label": "添加服务对象",
"action": function (obj) {
var inst = jQuery.jstree.reference(obj.reference);
var clickedNode = inst.get_node(obj.reference);
console.log("add minfo--clickedNode's id is : " + clickedNode.id);
if (clickedNode.data != 1) {
$.toaster('非叶子节点无法添加子类型', '提示', 'info');
return;
}
addMObjType(clickedNode.id, clickedNode.text);
}
}
}
}
}).bind("loaded.jstree", function (event, data) {
openTree("#", 3); //展开三层
});
refreshTypeTree();
});
\ No newline at end of file
... ...