if($ == undefined){
$ = jQuery;
}
function initdsourcetable(){
if($("#dsourcetable").size() > 0){
$("#dsourcetable").datagrid("load", {t:Math.random()});
return;
}
var ctx = "
";
$("#optarea").html(ctx);
$("#dsourcetable").datagrid({
singleSelect:true,
collapsible:false,
pagination:false,
border:false,
fit:true,
url:'listDataSource.action',
toolbar:[{
text:'新增',
iconCls:'icon-add',
handler:function(){
newdsource(false);
}
},{
text:'修改',
iconCls:'icon-edit',
handler:function(){
var row = $("#dsourcetable").datagrid("getChecked");
if(row == null || row.length == 0){
$.messager.alert("出错了。","您还未勾选数据。", "error");
return;
}
newdsource(true, row[0].dsid);
}
},{
text:'删除',
iconCls:'icon-cancel',
handler:function(){
var row = $("#dsourcetable").datagrid("getChecked");
if(row == null || row.length == 0){
$.messager.alert("出错了。","您还未勾选数据。", "error");
return;
}
delDsource(row[0].dsid);
}
}]
});
}
function delDsource(dsid){
if(confirm("是否确认删除?")){
$.ajax({
url:'deleteDataSource.action',
data: {dsid:dsid},
type:'POST',
dataType:'JSON',
success:function(){
$("#dsourcetable").datagrid("reload", {t:Math.random});
},
error:function(){
msginfo("系统出错,请查看后台日志。");
}
});
}
}
function newdsource(isupdate, dsid){
var ds;
if(isupdate){
$.ajax({
type:'GET',
url:'getDataSource.action',
dataType:'JSON',
data:{dsid:dsid},
async:false,
success: function(resp){
ds = resp;
}
});
}
var ctx = "";
$('#pdailog').dialog({
title: isupdate ? "编辑数据源" : '创建数据源',
width: 540,
height: 300,
closed: false,
cache: false,
modal: true,
toolbar:null,
content:ctx,
buttons:[{
text:"测试连接",
handler:function(){
var tab = $('#dsource_tab').tabs('getSelected');
var index = $('#dsource_tab').tabs('getTabIndex',tab);
if(index == 0){
var param = $("#datasourceform").serialize();
$.ajax({
type: "POST",
url: "testDataSource.action",
dataType:"json",
data: param,
success: function(resp){
if(resp.result == 1){
msginfo("测试成功!", "suc");
$("#datasourceform #connstate").val("y");
}else{
msginfo("测试失败!
"+resp.msg);
}
},
error:function(){
msginfo("测试失败!");
}
});
}else if(index == 1){
var param = {"jndiName":$("#dsource_tab #jndiName").val()};
$.ajax({
type: "POST",
url: "testJndi.action",
dataType:"json",
data: param,
success: function(resp){
if(resp.result == 1){
msginfo("测试成功!", "suc");
$("#datasourceform #connstate").val("y");
}else{
msginfo("测试失败!
"+resp.msg);
}
},
error:function(){
msginfo("测试失败!");
}
});
}
}
},{
text:'确定',
iconCls:"icon-ok",
handler:function(){
var tab = $('#dsource_tab').tabs('getSelected');
var index = $('#dsource_tab').tabs('getTabIndex',tab);
if(index == 0){
if($("#datasourceform #dsname").val() == ''){
msginfo("请输入数据源名称!");
$("#datasourceform #dsname").focus();
return;
}
if($("#datasourceform #connstate").val() != "y"){
msginfo("请先测试连接正常再确定!");
return;
}
if(isupdate == false){
var ds = {"linkType":$("#linkType").val(), "linkName":$("#linkName").val(), "linkPwd":$("#linkPwd").val(), "linkUrl":$("#linkUrl").val(),"dsname":$("#datasourceform #dsname").val(),"dsid":newGuid(),"use":"jdbc"};
$.ajax({
url:'saveDataSource.action',
data: $.param(ds),
type:'POST',
dataType:'JSON',
success:function(){
$("#dsourcetable").datagrid("reload", {t:Math.random});
},
error:function(){
msginfo("系统出错,请查看后台日志。");
}
});
}else{
var nds = {"linkType":$("#linkType").val(), "linkName":$("#linkName").val(), "linkPwd":$("#linkPwd").val(), "linkUrl":$("#linkUrl").val(),"dsname":$("#datasourceform #dsname").val(),"dsid":dsid,"use":"jdbc"};
$.ajax({
url:'updateDataSource.action',
data:nds,
type:'POST',
dataType:'JSON',
success:function(){
$("#dsourcetable").datagrid("reload", {t:Math.random});
},
error:function(){
msginfo("系统出错,请查看后台日志。");
}
});
}
}else if(index == 1){
if($("#dsource_tab #jndiName").val() == ''){
msginfo("请输入JNDI名称!");
$("#dsource_tab #jndiName").focus();
return;
}
if($("#datasourceform #connstate").val() != "y"){
msginfo("请先测试连接正常再确定!");
return;
}
if(isupdate == false){
var ds = {"dsname":$("#dsource_tab #jndiName").val(),"linkType":$("#dsource_tab #jndilinktype").val(),"dsid":newGuid(),"use":"jndi"};
$.ajax({
url:'saveDataSource.action',
data: ds,
type:'POST',
dataType:'html',
success:function(){
$("#dsourcetable").datagrid("reload", {t:Math.random});
},
error:function(){
msginfo("系统出错,请查看后台日志。");
}
});
}else{
var ds = {"dsname":$("#dsource_tab #jndiname").val(),"linkType":$("#dsource_tab #jndilinktype").val(),"dsid":dsid,"use":"jndi"};
$.ajax({
url:'updateDataSource.action',
data:ds,
type:'POST',
dataType:'html',
success:function(){
$("#dsourcetable").datagrid("reload", {t:Math.random});
},
error:function(){
msginfo("系统出错,请查看后台日志。");
}
});
}
}
$('#pdailog').dialog('close');
}
},{
text:'取消',
iconCls:"icon-cancel",
handler:function(){
$('#pdailog').dialog('close');
}
}]
});
$("#pdailog #dsource_tab").tabs({
fit:true,border:false
});
$("#pdailog #linkType").change(function(){
var val = $(this).val();
if(val == "mysql"){
$("#pdailog #linkUrl").val("jdbc:mysql://ip/database?useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2B8");
}else if(val == "oracle"){
$("#pdailog #linkUrl").val("jdbc:oracle:thin:@ip:1521/sid");
}else if(val == "sqlser"){
$("#pdailog #linkUrl").val("jdbc:jtds:sqlserver://ip:1433/database");
}else if(val == "db2"){
$("#pdailog #linkUrl").val("jdbc:db2://ip:50000/database");
}else if(val == "postgresql"){
$("#pdailog #linkUrl").val("jdbc:postgresql://ip:5432/database");
}else if(val == "hive"){
$("#pdailog #linkUrl").val("jdbc:hive2://ip:10000/default");
}else if(val == "kylin"){
$("#pdailog #linkUrl").val("jdbc:kylin://ip:7070/kylin_project_name");
}
});
}