<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head> 
   <%@ include file="../../include/lib.jsp" %>
   <%@ include file="../../include/editor.jsp"%>
  </head>
  <body style="margin-top:14px;"><div id="articleList"></div>
  	   
<script type="text/javascript">
		//使用js来控制列表数据
			function loadData(_url) {	
				$('#articleList').datagrid( {
					url:_url, 
					//fit: true,//自动大小  
					singleSelect:true,//单选
					showFooter:true,
					//collapsible:false,//是否可折叠的 
					rownumbers:true,
					pagination:true,
					onLoadSuccess:function(data){  
		       			$('#articleType').combotree({
							url:'${base_url}/admin/treeArticleType?type=json'
						});
				    },
					toolbar: [{
						iconCls: 'icon-add',
						text:'新增',
						handler: function(){
						var content = '<iframe scrolling="yes" frameborder="0"  src="${base_url}/articleSave" style="width:100%;height:100%;"></iframe>'; 
						$parent("#tabs").tabs('add',{ 
							id: 'addArtcileTab',
							title: '增加文章',
							content: content,  
							closable: true
						});
						}
					},'-',{
						iconCls: 'icon-edit',
						text:'编辑',
						handler: function(){
						editArticle()
						}
					},'-',{
						iconCls: 'icon-search',
						text:'查看',
						handler: function(){
						articleShow()
						}
					},'-',{
						iconCls: 'icon-no',
						text:'删除',
						handler: function(){
							articleDel()
						}
					},{
						iconCls: 'icon-reload',
						text:'刷新',
						handler: function(){
							loadData("${base_url}/admin/articleList?type=json")
						}
					},{
						text:'请选择栏目:<select id="articleType" style="width: 200px ;" class="easyui-combotree"></select>'
					},{
						text: '关键字:<input type="text" style="width:150px" value="" id="titleSearch"/><input type="button" onclick="searchArticle();" value="搜索">'
					}], 
					columns : [ [  {
						field : 'article',
						title : '文章编号',
						checkbox:true,
						width : 50
					}, {
						field : 'articleId',
						title : 'ID',
						align : 'left',
						width : 100
					}, {
						field : 'articleTitle',
						title : '文章标题',
						width : 180
					},{
						field : 'articleFlag',
						title : '文章类型',
						align : 'left',
						width : 120,formatter: function(value,row,index){
							if(value == 1){
								return '<font color="red">' + '[推荐]' + '</font>';
							}else if(value == 2){
								return '<font color="green">' + '[幻灯]' + '</font>';
							}else{
								return '<font color="gray">' + '[普通]' + '</font>';
							}
						 }
					}, {
						field : 'text',
						title : '所在栏目',
						width : 130,
						formatter: function(value,row,index){
							return row.articleTypes.text;
						}		
					}, {
						field : 'articleAuthor',
						title : '文章作者',
						width : 120,
						align : 'left'
					}, {
						field : 'articleSource',
						title : '文章来源',
						width : 180,
						align : 'left'
					}, {
						field : 'articleDate',
						title : '更新时间',
						width : 180,
						align : 'left'
					}]]
				});

			}
			loadData("${base_url}/admin/articleList?type=json");

			//过滤查询 
			function searchArticle() {
				var value = $('#titleSearch').val();
				var art = $('#articleType').combotree('getValue'); 
				$('#articleType').combotree({
									url:'${base_url}/admin/treeArticleType?type=json'
								});
				if(value==""&&art==""){	
					showFormMsg(SYSTEM_TITLE,"请您先进行相应的选择性查找！");
				}else{
					loadData("${base_url}/articleSearch?"+"title="+value+"&"+"art="+art);
					$('#titleSearch').val(value);
				}
			}

			
		//确认要操作下一步 true 确定删除执行删除操作
		function articleDel(){
			var article = $('#articleList').datagrid('getSelected');
			if(article!=null){
				$.messager.confirm('铭飞文章管理系统', '是否继续操作 ?', function(r){
					if (r){
						$.ajax({
				 	  	type: "POST",
				   		url:"${base_url}/articleDelete",
				   		data: "articleId="+article.articleId
						});
						$('#articleList').datagrid('reload');
						showFormMsg(SYSTEM_TITLE,"删除成功！");
						
					}
				});
			}else{
				alert1();
			}
		} 
	
		//弹出信息框 询问是否进行下一步操作
		function alert1(){
			$.messager.alert('铭飞文章管理系统','您未选择操作对象!');
		}

		//框架的分页功能
 		$(function(){
			var pager = $('#articleList').datagrid('getPager');	// get the pager of datagrid
			 $(pager).pagination({  
      		  pageSize: 10,   //每页显示的记录条数，默认为10  
      		  pageList: [10,20,30,40,50],  //可以设置每页记录条数的列表  
      		  beforePageText: '第',//页数文本框前显示的汉字  
	      	  afterPageText: '页    共 {pages} 页',  
	       	  displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'  
   			 }); 
		})
		
		//点击修改文章按钮  	
		function editArticle(){
			var article = $('#articleList').datagrid('getSelected');
			if(article!=null){
				var content = '<iframe scrolling="yes" frameborder="0"  src="${base_url}/admin/articleBuffer?articleId='+article.articleId+'" style="width:100%;height:100%;"></iframe>'; 
				$parent("#tabs").tabs('add',{
					title: '修改文章', 
					content:content,
					closable: true,
					cache:false	
				});	
			}else{
				alert1();
			}
		}
		//查看文章 
		function articleShow(){
				var article = $('#articleList').datagrid('getSelected');
			if(article!=null){
				window.open('${base_url}/articleShow?aid='+article.articleId);
			}else{
				alert1();
			}
		}
		</script>
  </body>
</html>  