<script type="text/javascript">
	$(function(){
		$('#tt').datagrid({  
			title:'我的承包列表',
			striped:true,
			pagination:true,
			//queryParams:{exam_id:$("#title").val()},
			remoteSort:true,
			sortName: 'id',
			sortOrder: 'asc',
			url:"<?php echo $this->createUrl('qq',array('exam_id'=>$exam_id)); ?>",  
			//idField:"id",
			//checkbox:false,
			fitColumns:true,
			//toolbar:"#tb",			
			columns:[[  
				{field:'ck',checkbox:'true'}, 
				{field:'id',title:'ID',width:50,align:'center',sortable:true},  
				{field:'fullname',title:'姓名',width:100,align:'center',sortable:false,editor:{type:'validatebox',options:{required:true}}}, 
				{field:'score_id',title:'试卷编号',width:100,align:'center',sortable:true,editor:{type:'validatebox',options:{required:true}}}, 
				{field:'score_state',title:'试卷状态',width:100,align:'center',sortable:true,editor:{type:'validatebox',options:{required:true}}}, 
	
				{field:'action',title:'动作',width:100,align:'center',
						formatter:function(value,row,index){
							if (row.editing){
								var s = '<a href="#" onclick="saverow('+index+')">保存</a> ';
								var c = '<a href="#" onclick="cancelrow('+index+')">取消</a>';
								return s+c;
							} else {
								var e = '<a href="#" onclick="editrow('+row.id+','+index+')">开始评卷</a> ';
								return e;
							}
						}
				}
				
			]],
            onSelect:function(index,row){
                $('#btnRemove').linkbutton('enable');
				$('#btnOn').linkbutton('enable');
				$('#btnOff').linkbutton('enable');
                },
			onUnselect:function(rowIndex, rowData){
				var rows = $('#tt').datagrid('getSelections');
				if(rows.length==0) {
					$('#btnRemove').linkbutton('disable');
					$('#btnOn').linkbutton('disable');
					$('#btnOff').linkbutton('disable');
				}
				},
            onSelectAll:function(index,row){
                $('#btnRemove').linkbutton('enable');
				$('#btnOn').linkbutton('enable');
				$('#btnOff').linkbutton('enable');
                },
            onUnselectAll:function(index,row){
                $('#btnRemove').linkbutton('disable');
				$('#btnOn').linkbutton('disable');
				$('#btnOff').linkbutton('disable');
                } 			
		}); 
	});

	function editrow(value,index){
		//alert(value);
		//$('#ff').form('load',value);
		$('#w').window('open');
		//$('#ff').form('load','<?php echo $this->createUrl('editrow').'/id/';?>'+value);
		var url='<?php echo $this->createUrl('pingjuan').'/exam_id/'.$exam_id.'/id/';?>'+value;
		$('#myform').html('<iframe scrolling="auto" frameborder="0" src="'+url+'" style="width:100%;height:100%;"></iframe>');
		//$('#tt').datagrid('beginEdit', index);
	}	
	function deleterow(value,index){
		$.messager.confirm('确认','确定要删除吗？',function(r){
			if (r){
				if(typeof(value)=='undefined'){
					$('#tt').datagrid('deleteRow',index);
				}else{
					$.ajax({
						type: 'POST',
						url: '<?php echo $this->createUrl("deleterow")?>',
						data: {id:value},
						success: function(data){if(data=="yes"){
						$.messager.alert('系统提示','删除成功!','info');
						$('#tt').datagrid('deleteRow',index);
						$('#tt').datagrid('reload');
						//updateActions();
						$("#tt").datagrid("acceptChanges");
					   }else $.messager.alert('系统提示','删除失败!'+'<br />'+data,'info');},
					  dataType: "text"
					});	
				}
			
			}
		});
	}

	
	function saverow(index){
		$('#tt').datagrid('endEdit', index);
	}
	function cancelrow(index){
		$('#tt').datagrid('cancelEdit', index);
	}
	function close1(){
		$('#w').window('close');
	}
	function open1(){
		$('#w').window('open');
	}
	$(function(){
		$("#w").window({
			onClose:function(){$("#tt").datagrid("reload");}//这是查看图片，不需要更新datagrid
		});
	})
</script>
<div data-options="region:'center',border:false">
	<table id="tt">  
	</table>
</div>
<div id="w" class="easyui-window" data-options="title:'评卷',closed:true,shadow:true,modal:true,iconCls:'icon-save'" style="width:1200px;height:600px;padding:5px;">
	<div id="myform">

	</div>
</div>
