<script type="text/javascript">
	$(function(){
		$('#tt').datagrid({  
			title:'此分类下知识点列表',
			striped:true,
			pagination:true,
			//queryParams:{pageSize:'10',page:'10'},
			remoteSort:true,
			sortName: 'id',
			sortOrder: 'asc',
			url:"<?php echo $this->createUrl('qq',array('category_id'=>$data)); ?>",  
			//idField:"id",
			//checkbox:false,
			toolbar:[{
                    id:'btnAdd',
					iconCls: 'icon-add',
					text:'增加',
					handler: function(){
					
						$('#w').window('open');
						var url='<?php echo $this->createUrl('create',array('category_id'=>$data));?>';
						$('#myform').html('<iframe scrolling="auto" frameborder="0" src="'+url+'" style="width:100%;height:100%;"></iframe>');
					
					}
					},'-',{
					id:'btnRemove',
					iconCls: 'icon-remove',
					text:'删除',
					disabled:true,
					handler: function(){
						var rows = $('#tt').datagrid('getSelections');
						var uprow = [];
							for(var i=0;i<rows.length;i++){
								uprow.push(rows[i]);
							}
						//alert(JSON.stringify(uprow));
						
								$.messager.confirm('确认','确定要删除吗？',function(r){
								if (r){


										$.ajax({
											  type: 'POST',
											  url: '<?php echo $this->createUrl('deleteall')?>',
											  data: {action:'deleteall',qq:JSON.stringify(uprow)},
											  success: function(data){//alert(data);
												   //if(data=="yes"){
													$.messager.alert('系统提示',data,'info');
													$('#tt').datagrid('reload');
													$('#btnRemove').linkbutton('disable');
													//$('#btnSave').linkbutton('disable');
												   //}else $.messager.alert('系统提示','更新失败!','info');
											   
											   },
											  dataType: "text"
										});	

								
								}
							});
						
						
						
						
						
					}
					}],
			
			columns:[[  
				{field:'ck',checkbox:'true'}, 
				{field:'id',title:'ID',width:50,align:'center',sortable:true},  
				{field:'title',title:'标题',width:300,align:'center',sortable:true,editor:{type:'validatebox',options:{required:true}}}, 
				{field:'created',title:'创建日期',width:150,align:'center',sortable:true,editor:{type:'validatebox',options:{required:true}}}, 
				{field:'modified',title:'最后修改日期',width:150,align:'center',sortable:true,editor:{type:'validatebox',options:{required:true}}}, 
				{field:'action',title:'动作',width:70,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> ';
								var d = '<a href="#" onclick="deleterow('+row.id+','+index+')">删除</a>';
								return e+d;
							}
						}
				}
			]],
            onSelect:function(index,row){
                $('#btnRemove').linkbutton('enable');
                },
			onUnselect:function(rowIndex, rowData){
				var rows = $('#tt').datagrid('getSelections');
				if(rows.length==0) $('#btnRemove').linkbutton('disable');
				},
            onSelectAll:function(index,row){
                $('#btnRemove').linkbutton('enable');
                },
            onUnselectAll:function(index,row){
                $('#btnRemove').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('editrow').'/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");}
		});
	})
</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:880px;height:650px;padding:5px;">
	<div id="myform">

	</div>
</div>
