<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('classroom_id'=>$classroom_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:'username',title:'账号',width:100,align:'center',sortable:true,editor:{type:'validatebox',options:{required:true}}}, 
				{field:'fullname',title:'姓名',width:100,align:'center',sortable:false,editor:{type:'validatebox',options:{required:true}}}, 
				{field:'sex',title:'性别',width:50,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: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="resetpassword('+row.id+','+index+')">重置密码</a> ';
								var d = '<a href="#" onclick="displayPhoto('+row.id+','+index+')">查看照片</a> ';
								var f = '<a href="#" onclick="deleterow('+row.id+','+index+')">删除</a>';
								return e+d+f;
							}
						}
				}
			]],
            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 resetpassword(value,index){
		$.messager.confirm('确认','确定要重置密码吗？',function(r){
			if (r){

					$.ajax({
						type: 'POST',
						url: '<?php echo $this->createUrl("resetPwd")?>',
						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 displayPhoto(value,index)
	{
		$('#w').window('open');
		var myrow=$('#tt').datagrid('selectRow',index);
		var selected = $('#tt').datagrid('getSelected');

		var url=selected.photo; 

		$('#myform').html('<img src="'+url+'" style="width:640px;height:480px;"/>');
	}
	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('update').'/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
		});
	})
	function tt_add(){
		$('#w').window('open');
		var url='<?php echo $this->createUrl('create',array('classroom_id'=>$classroom_id));?>';
		$('#myform').html('<iframe scrolling="auto" frameborder="0" src="'+url+'" style="width:100%;height:100%;"></iframe>');
	}
	function tt_remove(){
		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');
									$('#btnOn').linkbutton('disable');
									$('#btnOff').linkbutton('disable');
									//$('#btnSave').linkbutton('disable');
								   //}else $.messager.alert('系统提示','更新失败!','info');
							   
							   },
							  dataType: "text"
						});	

				
				}
			});
	}
function my_query(){
	if($.trim($("#title").val())==""){
		$.messager.alert('系统提示','请输入姓名!','info');
		$("#title").focus();
		return ;
	}
	var fullname=$.trim($("#title").val());
	var queryParams = $('#tt').datagrid('options').queryParams; 
	queryParams.fullname = fullname;  
	$('#tt').datagrid('options').queryParams=queryParams;        
	$("#tt").datagrid('reload'); 
}	
function display_all(){
	$('#tt').datagrid('options').queryParams=[];  
	$("#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:663px;height:524px;padding:5px;">
	<div id="myform">

	</div>
</div>
<div id="tb" style="padding:5px;height:auto">
	<div style="margin-bottom:5px">
		<a href="javascript:tt_remove()" id="btnRemove" disabled="false" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
	</div>
	<div>
		标题: <input id="title" type="text" style="width:300px"/>
		<a href="javascript:my_query()" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
	</div>
</div>
