|  | @ -10,7 +10,27 @@
 | 
	
		
			
				|  |  |             var me = this;
 | 
	
		
			
				|  |  |             $("#txtType").ligerComboBox({data:[{code:'mysql',value:'MySQL'},{code:'oracle',value:'Oracle'},{code:'sqlserver',value:'SQL Server'}]});
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             me.initData();
 | 
	
		
			
				|  |  |             $("#divForm").ligerAutoForm({
 | 
	
		
			
				|  |  |                 data:me.getModel(),
 | 
	
		
			
				|  |  |                 validate:{
 | 
	
		
			
				|  |  |                     name:"required",
 | 
	
		
			
				|  |  |                     type:"required",
 | 
	
		
			
				|  |  |                     ip:"required",
 | 
	
		
			
				|  |  |                     port:"required",
 | 
	
		
			
				|  |  |                     dbName:"required",
 | 
	
		
			
				|  |  |                     dbUser:"required",
 | 
	
		
			
				|  |  |                     dbPassword:"required"
 | 
	
		
			
				|  |  |                 },
 | 
	
		
			
				|  |  |                 message:{
 | 
	
		
			
				|  |  |                     name:"请输入数据源名称",
 | 
	
		
			
				|  |  |                     type:"请选择数据库类型",
 | 
	
		
			
				|  |  |                     ip:"请输入主机名或IP地址",
 | 
	
		
			
				|  |  |                     port:"请输入端口",
 | 
	
		
			
				|  |  |                     dbName:"请输入数据库名",
 | 
	
		
			
				|  |  |                     dbUser:"请输入用户名",
 | 
	
		
			
				|  |  |                     dbPassword:"请输入密码"
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             });
 | 
	
		
			
				|  |  |             me.initEven();
 | 
	
		
			
				|  |  |         },
 | 
	
		
			
				|  |  |         //绑定按钮事件
 | 
	
	
		
			
				|  | @ -25,130 +45,77 @@
 | 
	
		
			
				|  |  |             });
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             $("#btnCancel").click(function(){
 | 
	
		
			
				|  |  |                 me.initData();
 | 
	
		
			
				|  |  |                 var model = me.getModel();
 | 
	
		
			
				|  |  |                 $("#divForm").ligerAutoForm("setData",model);
 | 
	
		
			
				|  |  |             });
 | 
	
		
			
				|  |  |         },
 | 
	
		
			
				|  |  |         setConfigString:function(configStr){
 | 
	
		
			
				|  |  |             //反解析连接字符串
 | 
	
		
			
				|  |  |             if(configStr!=null && configStr.length>0)
 | 
	
		
			
				|  |  |             {
 | 
	
		
			
				|  |  |                 $("#txtType").ligerComboBox("setValue",(configStr.split("\/")[0]).split(":")[1]);
 | 
	
		
			
				|  |  |                 var type = $("#txtType").ligerComboBox("getValue");
 | 
	
		
			
				|  |  |                 if( type == "mysql" || type == "sqlserver"){
 | 
	
		
			
				|  |  |                     $("#txtIp").val((configStr.split("\/")[2]).split(":")[0]);
 | 
	
		
			
				|  |  |                     $("#txtPort").val((configStr.split("\/")[2]).split(":")[1]);
 | 
	
		
			
				|  |  |                     $("#txtDbName").val((configStr.split("\/")[3]).split("?")[0]);
 | 
	
		
			
				|  |  |                     $("#txtDbUser").val((configStr.split("\/")[3]).split("?")[1].split("&")[0].split("=")[1]);
 | 
	
		
			
				|  |  |                     $("#txtDbPassword").val((configStr.split("\/")[3]).split("?")[1].split("&")[1].split("=")[1]);
 | 
	
		
			
				|  |  |                 }else{
 | 
	
		
			
				|  |  |                     $("#txtIp").val(configStr.split("\/")[3].split(":")[0]);
 | 
	
		
			
				|  |  |                     $("#txtPort").val(configStr.split("\/")[3].split(":")[1]);
 | 
	
		
			
				|  |  |                     $("#txtDbName").val(configStr.split("\/")[4]);
 | 
	
		
			
				|  |  |                     $("#txtDbUser").val(configStr.split("\/")[0].split(":")[3]);
 | 
	
		
			
				|  |  |                     $("#txtDbPassword").val(configStr.split("\/")[1].split("@")[0]);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         },
 | 
	
		
			
				|  |  |         //生成数据库连接字符串
 | 
	
		
			
				|  |  |         getConfigString:function(){
 | 
	
		
			
				|  |  |         getConfigString:function(data){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             var resultStr="";
 | 
	
		
			
				|  |  |             var type = $("#txtType").ligerComboBox("getValue");
 | 
	
		
			
				|  |  |             var ip = $("#txtIp").val();
 | 
	
		
			
				|  |  |             var port = $("#txtPort").val();
 | 
	
		
			
				|  |  |             var dbName = $("#txtDbName").val();
 | 
	
		
			
				|  |  |             var dbUser = $("#txtDbUser").val();
 | 
	
		
			
				|  |  |             var dbPassword = $("#txtDbPassword").val();
 | 
	
		
			
				|  |  |             if(type=="mysql"){//mysql
 | 
	
		
			
				|  |  |                 resultStr ="jdbc:mysql://"+ ip +":"+ port +"/"+ dbName +"?user="+ dbUser +"&password="+ dbPassword;
 | 
	
		
			
				|  |  |             if(data.type=="mysql"){//mysql
 | 
	
		
			
				|  |  |                 resultStr ="jdbc:mysql://"+ data.ip +":"+ data.port +"/"+ data.dbName +"?user="+ data.dbUser +"&password="+ data.dbPassword;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             else if(type=="oracle"){//oracle
 | 
	
		
			
				|  |  |                 resultStr ="jdbc:oracle:thin:"+ dbUser +"/"+ dbPassword +"@//"+ ip +":"+ port +"/"+ dbName ;
 | 
	
		
			
				|  |  |             else if(data.type=="oracle"){//oracle
 | 
	
		
			
				|  |  |                 resultStr ="jdbc:oracle:thin:"+ data.dbUser +"/"+ data.dbPassword +"@//"+ data.ip +":"+ data.port +"/"+ data.dbName ;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             else{//sqlserver
 | 
	
		
			
				|  |  |                 resultStr ="jdbc:sqlserver://"+ip+":"+port+"/"+dbName+"?user="+dbUser+"&password="+dbPassword;
 | 
	
		
			
				|  |  |                 resultStr ="jdbc:sqlserver://"+data.ip+":"+data.port+"/"+data.dbName+"?user="+data.dbUser+"&password="+data.dbPassword;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             return resultStr;
 | 
	
		
			
				|  |  |         },
 | 
	
		
			
				|  |  |         //初始化值
 | 
	
		
			
				|  |  |         initData:function(){
 | 
	
		
			
				|  |  |             var me =this;
 | 
	
		
			
				|  |  |         //获取初始值
 | 
	
		
			
				|  |  |         getModel:function(){
 | 
	
		
			
				|  |  |             var model;
 | 
	
		
			
				|  |  |             if('${model.id}'.length>0) {
 | 
	
		
			
				|  |  |                 var model = {
 | 
	
		
			
				|  |  |                 var configStr = '${model.config}';
 | 
	
		
			
				|  |  |                 model = {
 | 
	
		
			
				|  |  |                     id : '${model.id}',
 | 
	
		
			
				|  |  |                     name : '${model.name}',
 | 
	
		
			
				|  |  |                     config : '${model.config}'
 | 
	
		
			
				|  |  |                     name : '${model.name}'
 | 
	
		
			
				|  |  |                 };
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 $('#txtId').val(model.id);
 | 
	
		
			
				|  |  |                 $('#txtName').val(model.name);
 | 
	
		
			
				|  |  |                 me.setConfigString(model.config);
 | 
	
		
			
				|  |  |                 //反解析连接字符串
 | 
	
		
			
				|  |  |                 if(configStr!=null && configStr.length>0)
 | 
	
		
			
				|  |  |                 {
 | 
	
		
			
				|  |  |                     var type = (configStr.split("\/")[0]).split(":")[1];
 | 
	
		
			
				|  |  |                     model.type = type;
 | 
	
		
			
				|  |  |                     if( type == "mysql" || type == "sqlserver"){
 | 
	
		
			
				|  |  |                         model.ip = (configStr.split("\/")[2]).split(":")[0];
 | 
	
		
			
				|  |  |                         model.port = (configStr.split("\/")[2]).split(":")[1];
 | 
	
		
			
				|  |  |                         model.dbName = (configStr.split("\/")[3]).split("?")[0];
 | 
	
		
			
				|  |  |                         model.dbUser = (configStr.split("\/")[3]).split("?")[1].split("&")[0].split("=")[1];
 | 
	
		
			
				|  |  |                         model.dbPassword = (configStr.split("\/")[3]).split("?")[1].split("&")[1].split("=")[1];
 | 
	
		
			
				|  |  |                     }else{
 | 
	
		
			
				|  |  |                         model.ip = (configStr.split("\/")[3]).split(":")[0];
 | 
	
		
			
				|  |  |                         model.port = (configStr.split("\/")[3]).split(":")[1];
 | 
	
		
			
				|  |  |                         model.dbName = configStr.split("\/")[4];
 | 
	
		
			
				|  |  |                         model.dbUser = (configStr.split("\/")[0]).split(":")[3];
 | 
	
		
			
				|  |  |                         model.dbPassword = (configStr.split("\/")[1]).split("@")[0];
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             else{
 | 
	
		
			
				|  |  |                 $('#dataSourceInfo').show();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         },
 | 
	
		
			
				|  |  |         //校验
 | 
	
		
			
				|  |  |         validata:function(){
 | 
	
		
			
				|  |  |             var me = this;
 | 
	
		
			
				|  |  |             var name = $('#txtName').val();
 | 
	
		
			
				|  |  |             var type = $('#txtType').ligerComboBox("getValue");
 | 
	
		
			
				|  |  |             var ip = $("#txtIp").val();
 | 
	
		
			
				|  |  |             var port = $("#txtPort").val();
 | 
	
		
			
				|  |  |             var dbName = $("#txtDbName").val();
 | 
	
		
			
				|  |  |             var dbUser = $("#txtDbUser").val();
 | 
	
		
			
				|  |  |             var dbPassword = $("#txtDbPassword").val();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if(name.length==0)
 | 
	
		
			
				|  |  |             {
 | 
	
		
			
				|  |  |                 $.ligerDialog.error("请输入数据源名称!");
 | 
	
		
			
				|  |  |                 return false;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if(type.length==0)
 | 
	
		
			
				|  |  |             {
 | 
	
		
			
				|  |  |                 $.ligerDialog.error("请选择数据库类型!");
 | 
	
		
			
				|  |  |                 return false;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if(ip.length==0)
 | 
	
		
			
				|  |  |             {
 | 
	
		
			
				|  |  |                 $.ligerDialog.error("请输入主机名或IP地址!");
 | 
	
		
			
				|  |  |                 return false;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if(port.length==0)
 | 
	
		
			
				|  |  |             {
 | 
	
		
			
				|  |  |                 $.ligerDialog.error("请输入端口!");
 | 
	
		
			
				|  |  |                 return false;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if(dbName.length==0)
 | 
	
		
			
				|  |  |             {
 | 
	
		
			
				|  |  |                 $.ligerDialog.error("请输入数据库名!");
 | 
	
		
			
				|  |  |                 return false;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if(dbUser.length==0)
 | 
	
		
			
				|  |  |             {
 | 
	
		
			
				|  |  |                 $.ligerDialog.error("请输入用户名!");
 | 
	
		
			
				|  |  |                 return false;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if(dbPassword.length==0)
 | 
	
		
			
				|  |  |             {
 | 
	
		
			
				|  |  |                 $.ligerDialog.error("请输入密码!");
 | 
	
		
			
				|  |  |                 return false;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             return true;
 | 
	
		
			
				|  |  |             return model;
 | 
	
		
			
				|  |  |         },
 | 
	
		
			
				|  |  |         //测试数据库连接
 | 
	
		
			
				|  |  |         test:function(){
 | 
	
		
			
				|  |  |             var me = this;
 | 
	
		
			
				|  |  |             if(!me.validata()) return;
 | 
	
		
			
				|  |  |             if(!$("#divForm").ligerAutoForm("validate"))
 | 
	
		
			
				|  |  |             {
 | 
	
		
			
				|  |  |                 return;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             var data = $("#divForm").ligerAutoForm("getData");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             $.ajax({
 | 
	
		
			
				|  |  |                 type: "POST",
 | 
	
		
			
				|  |  |                 url : "${contextRoot}/system/testDataSource",
 | 
	
		
			
				|  |  |                 dataType : "json",
 | 
	
		
			
				|  |  |                 data:{config:me.getConfigString()},
 | 
	
		
			
				|  |  |                 data:{config:me.getConfigString(data)},
 | 
	
		
			
				|  |  |                 cache:false,
 | 
	
		
			
				|  |  |                 success :function(data){
 | 
	
		
			
				|  |  |                     if(data.successFlg) {
 | 
	
	
		
			
				|  | @ -157,26 +124,23 @@
 | 
	
		
			
				|  |  |                     else{
 | 
	
		
			
				|  |  |                         $.ligerDialog.error(data.message);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 },
 | 
	
		
			
				|  |  |                 error :function(data){
 | 
	
		
			
				|  |  |                     $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             });
 | 
	
		
			
				|  |  |         },
 | 
	
		
			
				|  |  |         //保存操作
 | 
	
		
			
				|  |  |         save:function(){
 | 
	
		
			
				|  |  |             var me = this;
 | 
	
		
			
				|  |  |             if(!me.validata()) return;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             var id = $('#txtId').val();
 | 
	
		
			
				|  |  |             var name = $('#txtName').val();
 | 
	
		
			
				|  |  |             var config = me.getConfigString();
 | 
	
		
			
				|  |  |             if(!$("#divForm").ligerAutoForm("validate"))
 | 
	
		
			
				|  |  |             {
 | 
	
		
			
				|  |  |                 return;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             var data = $("#divForm").ligerAutoForm("getData");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             $.ajax({
 | 
	
		
			
				|  |  |                 type: "POST",
 | 
	
		
			
				|  |  |                 url : "${contextRoot}/system/saveDataSource",
 | 
	
		
			
				|  |  |                 dataType : "json",
 | 
	
		
			
				|  |  |                 data:{id:id,name:name,config:config},
 | 
	
		
			
				|  |  |                 data:{id:data.id,name:data.name,config:me.getConfigString(data)},
 | 
	
		
			
				|  |  |                 cache:false,
 | 
	
		
			
				|  |  |                 success :function(data){
 | 
	
		
			
				|  |  |                     if(data.successFlg) {
 | 
	
	
		
			
				|  | @ -186,9 +150,6 @@
 | 
	
		
			
				|  |  |                     else{
 | 
	
		
			
				|  |  |                         $.ligerDialog.error(data.message);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 },
 | 
	
		
			
				|  |  |                 error :function(data){
 | 
	
		
			
				|  |  |                     $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             });
 | 
	
		
			
				|  |  |         }
 |