<script language="javascript">
$(function(){
	var th = $(".top").height();
	th = 111-th;
	var wh = $(window).height()-th;
	
	$("#Comy").datagrid({
		//title:'公司列表',	
		height:wh,
		autoRowHeight:false,
		singleSelect:true,
		striped:true,
		rownumbers:true,
		method:'get',
		url:'__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=<?php echo ACTION_NAME; ?>&json=1',
		fitColumns:true,
		nowrap:Number('{$TC.config.DATA_NOWRAP}'),
		onBeforeLoad: function () {  
			
		},
		onDblClickRow:function(e,rowIndex,rowData){
			var se = $(this).datagrid('getSelected');
			var idd = se['id'];
			$("#addComy").dialog({
				title:'编辑公司',
				resizable:true,
				width:450,
				height:306,
				href:'__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=add&act=edit&id='+idd,
				onOpen:function(){
					cancel['Comy'] = $(this);
				},
				onClose:function(){
					//$(this).dialog('destroy');
					//$("#Comy").datagrid('reload');
					cancel['Comy'] = null;
				}
			});
		},
		toolbar:[{
		iconCls: 'icon-add',
			text : '新增',
			handler: function(){
				$("#addComy").dialog({
					title:'新增公司',
					resizable:true,
					width:450,
					height:306,
					href:'__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=add&act=add',
					onOpen:function(){
						cancel['Comy'] = $(this);
					},
					onClose:function(){
						//$(this).dialog('destroy');
						//$("#Comy").datagrid('reload');
						cancel['Comy'] = null;
					}
				});
			}
		},'-',{
			iconCls: 'icon-edit',
			text : '编辑',
			handler: function(){
				var se = $("#Comy").datagrid('getSelected');
				var idd = se['id'];
				$("#addComy").dialog({
					title:'编辑公司',
					resizable:true,
					width:450,
					  height:306,
					href:'__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=add&act=edit&id='+idd,
					onOpen:function(){
						cancel['Comy'] = $(this);
					},
					onClose:function(){
						//$(this).dialog('destroy');
						//$("#Comy").datagrid('reload');
						cancel['Comy'] = null;
					}
				});
			}
		},'-',{
			iconCls: 'icon-cancel',
			text : '删除',
			handler: function(){
				var se = $("#Comy").datagrid('getSelected');
				var idd = se['id'];
				$.messager.confirm('提示','确定删除吗！',function(r){
					if(r==true){
						$.messager.progress();
						$.get('__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=del&id='+idd, function(data){
							$.messager.progress('close');
							if(data==1){
								$.messager.alert('提示','删除数据成功！','info',function(){
									$("#Comy").datagrid('reload');
								});
							}else if(data==0){
								$.messager.alert('提示','删除数据失败！','warning');
							}else{
								$.messager.alert('提示','您没有删除权限！','warning');
							}
						});
					}
				});	
			}
		},'-',{
			iconCls: 'icon-json',
			text : '生成JSON',
			handler: function(){
				$.get('__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=json', function(data){
					if(data==1){
						$.messager.alert('提示','生成json数据成功！','info');
					}else{
						$.messager.alert('提示',data,'warning');
					}
				});
			}
		},'-',{
			iconCls: 'icon-reload',
			text : '重载',
			handler: function(){
				$("#Comy").datagrid('reload');
			}
		}
		],
		columns:[[   
			{field:'name',title:'公司名称',width:160},
			{field:'access',title:'权限值',width:80},   
			{field:'comment',title:'备注',width:90},
			{field:'smtp',title:'SMTP服务器',width:220},
			{field:'ssl',title:'安全链接（SSL）',width:120},
			{field:'port',title:'服务器端口',width:100},
			{field:'status',title:'状态',width:70}
		]]
	});
});
</script>
<div class="con" id="ComyCon" onselectstart="return false;" style="-moz-user-select:none;">
	<table id="Comy"></table>
</div>
<div id="addComy"></div>