<script language="javascript">
var atit;
$(function(){
	var np = Number('{$show_np}');
	var cw = $("#projectCon").width();
	var th = $(".top").height();
	th = 111-th;
	var wh = $(window).height()-th;
	var ch = $("body").height();
	var pr = '<?php echo $page_row ?>';
	var pn = false;
	if(pr>0){
		pn = true;
	}
	$("#Project").datagrid({
		//title:'项目列表',
		height:wh,
		autoRowHeight:false,
		singleSelect:true,
		striped:true,
		rownumbers:true,
		pagination:pn,
		showFooter:true,
		prototype:true,
		pageSize:pr,
		pageList:[30,50,80,100,100000000000],
		method:'get',
		url:'__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=<?php echo ACTION_NAME; ?>&json=1',
		fitColumns:Number('{$TC.config.DG_FIT_COLUMNS}'),
		nowrap:Number('{$TC.config.DATA_NOWRAP}'),
		selectOnCheck:false,
		checkOnSelect:true,
		onBeforeLoad: function(){  
			 if($("#ProjectCon .datagrid-toolbar table tr #sersSearchProjectItemtype").length==0){
				 var grid = $("#ProjectCon .datagrid-toolbar table tr");  
				 var ldata = '<td>'+$("#selectInputProject").html()+'</td>'; 
				 grid.append(ldata);
				 
				 $("#sersSearchProjectStatus").change(function(){
					var idd = $(this).val();
					$.post('__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=change&act=status', {val:idd}, function(data){
						$("#Project").datagrid('reload');
					});
				});
				
				$("#sersSearchProjectItemtype").change(function(){
					var idd = $(this).val();
					$.post('__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=change&act=itemtype', {val:idd}, function(data){
						$("#Project").datagrid('reload');
					});
				});
			 }
			 
			 if($("#ProjectCon .datagrid-toolbar #ProjectSearch").length==0){
				 var toolbar = $("#ProjectCon .datagrid-toolbar");
				 toolbar.css({
					 "overflow":"hidden"
				 });
				 var tooltable = $("#ProjectCon .datagrid-toolbar table");
				 tooltable.css({
					 "float":"left"
				 });
				 var tw = toolbar.width();
				 tooltable.addClass("tname");
				 var sw = $("#ProjectCon .datagrid-toolbar .tname").width();
				 //alert(sw);
				 
				 var ww = tw-sw-8;
				 var date = '<table cellspacing="0" cellpadding="0" style="width:'+ww+'px; height:28px; float: left;" class="pname"><tr><td align="right">'+$("#selectInputProject2").html()+'</td></tr></table>';    
				 toolbar.append(date); 
				 
				 $('#ProjectSearch').searchbox({   
					searcher:function(value,name){
						$.post('__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=change&act='+name+'&mode=like', {val:value}, function(data){
							$("#Project").datagrid('reload');
						});
					},   
					menu:'#ProjectSearchSon',   
					prompt:'请输入关键字'  
				 }); 
			 }
		},
		onHeaderContextMenu:function(e,f){
			if(f!='pro_progress'){
				$("#searchProject").dialog({
					title:'快速搜索',
					resizable:true,
					width:480,
					height:80,
					href:'__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=search&field='+f
				});
			}
			e.preventDefault();
		},
		onDblClickRow:function(e,rowIndex,rowData){
			//var se = $("#Project").datagrid('getSelected')
			var se = $("#Project").datagrid('getChecked');
			var se_len = se.length;
			var idd = se[0]['id'];
			var idn = se[0]['name'];
			//alert(idd);
			var ishas = $("#rightTabs").tabs('exists',atit);
			if(!ishas){
				$("#rightTabs").tabs('add',{
					id : -2,
					title : '项目-'+idn,
					href : '__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=detail&id='+idd,
					closable : true,
				});
				atit = '项目-'+idn;
			}else{
				if(idd!=atit){
					var tab = $("#rightTabs").tabs('getTab',atit);
					$("#rightTabs").tabs('update',{
						tab:tab,
						options:{
							title : '项目-'+idn,
							href : '__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=detail&id='+idd,
							closable : true,
						} 
					});
					atit = '项目-'+idn;
					$("#rightTabs").tabs('select',atit);
				}else{
					$("#rightTabs").tabs('select',atit);
				}
				
			}
		},
		onUncheck:function(i,d){
			$("#Project").datagrid('unselectRow',i);
		},
		toolbar:[{
		iconCls: 'icon-add',
			text : '新增',
			handler: function(){
				$("#addProject").dialog({
					title:'新增项目',
					resizable:true,
					width:920,
					height:430,
					href:'__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=add&act=add',
					onOpen:function(){
						cancel['Project'] = $(this);
					},
					onClose:function(){
						//$(this).dialog('destroy');
						//$("#Project").datagrid('reload');
						cancel['Project'] = null;
					}
				});
			}
		},'-',{
			iconCls: 'icon-edit',
			text : '编辑',
			handler: function(){
				//var se = $("#Project").datagrid('getSelected');
				var se = $("#Project").datagrid('getChecked');
				var se_len = se.length;
				var idd = se[0]['id'];
				if(se_len==1){
					$("#addProject").dialog({
						title:'编辑项目',
						resizable:true,
						width:920,
						height:430,
						href:'__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=add&act=edit&id='+idd,
						onOpen:function(){
							cancel['Project'] = $(this);
						},
						onClose:function(){
							//$(this).dialog('destroy');
							//$("#Project").datagrid('reload');
							cancel['Project'] = null;
						}
					});
				}else if(se_len>1){
					$.messager.alert('提示','不能同时编辑两行数据！','warning');
				}
			}
		},'-',{
			iconCls: 'icon-cancel',
			text : '删除',
			handler: function(){
				var se = $("#Project").datagrid('getChecked');
				var s = "";  
				for (var property in se) {  
					s = s + se[property]['id']+',' ;  
				}
				if(s){
					$.messager.confirm('提示','确定删除吗！',function(r){
						if(r==true){
							$.messager.progress();
							$.post('__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=del',{id:s}, function(data){
								$.messager.progress('close');
								if(data==1){
									$.messager.alert('提示','删除数据成功！','info',function(){
										$("#Project").datagrid('reload');
									});
								}else if(data==0){
									$.messager.alert('提示','删除数据失败！','warning');
								}else{
									$.messager.alert('提示','您没有删除权限','warning');
								}
							});
						}
					});
				}
			}
		},'-',{
			iconCls: 'icon-search',
			text : '高级搜索',
			handler: function(){
				$("#searchProject").dialog({
					title:'高级搜索',
					resizable:true,
					width:500,
					height:220,
					href:'__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=advsearch'
				});
			}
		},'-',{
			iconCls: 'icon-reload',
			text : '重载',
			handler: function(){
				$.get('__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=clear', function(data){
					$("#sersSearchProjectStatus").val(0);
					$("#ProjectSearch").searchbox('setValue','');
					$("#sersSearchProjectItemtype").val(0);
					$("#Project").datagrid('reload');
				});
			}
		}],
		frozenColumns:[[
			{checkbox:true},
			{field:'name',title:'<span class="tit-bl" title="单击右键，进入快速搜索">项目名称</span>',width:175,sortable:true}
		]],
		columns:[[  
			{field:'status',title:'<span class="tit-bl" title="单击右键，进入快速搜索">状态</span>',width:50,sortable:true},
			{field:'app_handler',title:'<span class="tit-bl" title="单击右键，进入快速搜索">负责人</span>',width:55,sortable:true},
			{field:'itemtype',title:'<span class="tit-bl" title="单击右键，进入快速搜索">类型</span>',width:100,sortable:true},
			{field:'description',title:'<span class="tit-bl" title="单击右键，进入快速搜索">说明</span>',width:290},
			{field:'pro_progress',title:'<span class="tit-bl" title="单击右键，进入快速搜索">完成进度</span>',width:280},
			{field:'pro_creator',title:'<span class="tit-bl" title="单击右键，进入快速搜索">创建人</span>',width:53,sortable:true},
			{field:'pro_creatdate',title:'<span class="tit-bl" title="单击右键，进入快速搜索">创建日期</span>',width:88,sortable:true}
		]]
	});
	
	
	 var dataview = '<?php echo C("DATAGRID_VIEW") ?>';
	 if(dataview!='0'){
		var pager = $('#Project').datagrid('getPager');
		pager.pagination({
			layout: 'list,sep,first,prev,sep,manual,sep,next,last,sep,refresh',
			displayMsg: '共{total}记录'
		});
	 }
	
	$("#rightTabs").tabs({
		onClose:function(t,i){
			$.ajaxSetup({  
				async : false  
			});
			if(t=='项目列表'){
				$.get('__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=clear', function(data){});
			}	
			$.ajaxSetup({  
				async : true  
			});
		}
	});
	
	$("#rightTabs").tabs('select','项目列表');
});
</script>
<div id="ProjectCon" class="con" onselectstart="return false;" style="-moz-user-select:none;">
 <if condition="C('DATAGRID_VIEW')!='0'">
 <table id="Project" data-options="view:<?php echo C("DATAGRID_VIEW") ?>"></table>
 <else />
 <table id="Project"></table>
 </if>
</div>
<div id="searchProject"></div>
<div id="addProject"></div>
<div id="selectInputProject" style="display:none">
 <span class="datagrid-btn-separator-nofloat"  style="margin-right:2px;"></span>
 <select id="sersSearchProjectItemtype" >
  <option value="0">所有类型</option> 
  <foreach name="iinfo" item="t">
   <option value="<?php echo $t->id ?>"><?php echo $t->text ?></option>
  </foreach>
 </select>
 <span class="datagrid-btn-separator-nofloat" style="margin-right:2px"></span>
 <select id="sersSearchProjectStatus" >
  <option value="0">所有状态</option> 
  <foreach name="sinfo" item="t">
   <option value="<?php echo $t->id ?>"><?php echo $t->text ?></option>
  </foreach>
 </select> 
</div>
<div id="selectInputProject2" style="display:none">
<input id="ProjectSearch" AUTOCOMPLETE="off" style="width:280px;"></input>  
<div id="ProjectSearchSon" style="width:120px">
	<div data-options="name:'name'">项目名称</div>  
    <div data-options="name:'app_handler'">负责人</div>
    <div data-options="name:'pro_creator'">创建人</div>  
</div> 
