easyUI treegrid的使用

前段时间,实习时候接到一个任务,将原有后台处理留言的的所有的一级分类改版成一级分类二级分类,在试验了大半个月之后,终于用treetable勉强的实现了,上面的一章节已经说过了,但是项目经理说我那个实现的不能拖动排序,哎,人为刀俎,我为鱼肉,没办法,硬着头皮换,幸好组里有一个项目经理的帮忙实现了easyUI treegrid 现在将流程大致的步骤记录在案,以防遗忘。公司的项目是ssh三层框架,现在我对这个业务流程还是不太熟悉,准备这几天系统的看看怎么样实现的这个框架,然后再结合实际的案例做一个简单的demo,时间过的太快了,马上研究生就要开题了,我现在什么都没准备,要看看自然语言处理的一些方面的内容了,现在真是会的东西太少,要学的东西太多 首先我们改动的是后台处理分类的catalogAction 代码如下

/*
 * CatalogAction.java created on Apr 10, 2014 3:05:43 AM by Martin
 */

package com.trs.space.comment.web.action.admin;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.junit.runners.Parameterized.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.trs.space.comment.ThreadContext;
import com.trs.space.comment.domain.AdminUser;
import com.trs.space.comment.domain.Catalog;
import com.trs.space.comment.domain.CatalogFilter;
import com.trs.space.comment.domain.Template;
import com.trs.space.comment.manager.CatalogManager;
import com.trs.space.comment.service.RightException;
import com.trs.space.comment.service.RightService;
import com.trs.space.comment.service.RightService.Right;
import com.trs.space.comment.util.RequestUtil;


/**
 * 总理留言分类管理
 * 
 * @author		Martin
 */
@Controller
public class CatalogAction {

	RightService rightService;

	CatalogManager catalogManager;

	@Autowired
	public void setRightService(RightService rightService) {
		this.rightService = rightService;
	}

	@Autowired
	public void setCatalogManager(CatalogManager catalogManager) {
		this.catalogManager = catalogManager;
	}	
	
	@RequestMapping(value = "/catalogList",method = RequestMethod.GET)
	public ModelAndView view() throws RightException {
		
		rightService.assertRight(Right.SUGGEST_ADMIN);
		ModelAndView mav = new ModelAndView("catalogList");//取得所有留言分类的视图层
		return mav;  
	}
	
	@RequestMapping(value = "/catalogListItem",method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	//得到所有的分类集合
	public String catalogList(
			HttpServletRequest request,HttpServletResponse response) throws RightException {
		
		rightService.assertRight(Right.SUGGEST_ADMIN);
		CatalogFilter filter = new CatalogFilter();
		filter.setLevel(0);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		filter.sortBySortid(false);
		List list = catalogManager.listCatalog(filter);
//		int sum=list.size();
//		System.out.println(sum);
		for (Catalog catalog : list) {
			catalog.setCreatedTime(sdf.format(catalog.getCreateTime()));//将时间格式化
			catalog.setCreateTime(null);//原有的时间转化成json时设置为null
		}
		for (Catalog catalog : list) {
			if(catalog.getParentId()==null){     //	得到所有的父类节点			
				CatalogFilter filter1 = new CatalogFilter();
				filter1.setParentId(catalog.getId());
				//System.out.println(catalog.getId());
				filter1.sortBySortid(false);
				List childrenlist = catalogManager.listCatalog(filter1);//根据父类节点得到所有的子类节点
				if(childrenlist.size()>0){
					for (Catalog catalog1 : childrenlist) {
						catalog1.setCreatedTime(sdf.format(catalog1.getCreateTime()));
						catalog1.setCreateTime(null);
					}
					catalog.setState("closed");//与前台的easyUI一致性保持
				}
				else {
					catalog.setState("open");
				}
				catalog.setChildren(childrenlist);
			}				
		}
		List result=new ArrayList();
		for (Catalog catalog : list) {
			if(catalog.getParentId()==null){
				result.add(catalog);
			}				
		}
//		Map jsonResult = new HashMap();
//		jsonResult.put("total", sum);
//		jsonResult.put("rows", result);
//		Map foot = new HashMap(){
//			{
//				put("name","Total Persons:");
//				put("persons",7);
//				put("iconCls","icon-sum");
//			}
//		};
//		jsonResult.put("footer",foot);
		
		
		JSONArray jsonArray= JSONArray.fromObject(result);//将父类节点全部转换成json格式的

		response.setContentType("text/html;charset=UTF-8");
		try {
			response.getWriter().print(jsonArray);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@RequestMapping(value = "/catalogGet", method = RequestMethod.POST)
	@ResponseBody
	public String Getcatalog(@RequestParam(value = "id", required = true) Long id,HttpServletResponse response) throws RightException {
		rightService.assertRight(Right.SUGGEST_ADMIN);

		Catalog catalog = null;
		if (id != null) {
			catalog = catalogManager.getCatalog(id);
			
		} else {
			catalog = new Catalog();
		}	
		try {
			response.getWriter().print(JSONArray.fromObject(catalog).toString());//子类节点转换成json格式的
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@RequestMapping(value = "/catalogEdit", method = RequestMethod.POST)
	@ResponseBody
	public String catalogEdit( 			
			@RequestParam(value = "title" ,required =true) String title,
			@RequestParam(value = "sortid", required = true) String sortid,
			@RequestParam(value = "id", required = false) Long id,
			@RequestParam(value = "parentId",required=false) Long parentId,
			HttpServletRequest request) throws RightException {

		rightService.assertRight(Right.SUGGEST_ADMIN);

		Catalog catalog = null;
		//catalog = catalogManager.getCatalog(id);
		if (id != null && id.longValue() > 0) {
			catalog = catalogManager.getCatalog(id);
		} else {
			AdminUser adminUser = ThreadContext.getUser().getAdminUser();
			catalog = new Catalog();
			//catalog.setParentId(parentId);
			if (parentId != -1 && parentId.longValue() > 0) {
				catalog.setLevel(Integer.valueOf(1));
				catalog.setParentId(parentId);
			} 
			else {
				catalog.setLevel(Integer.valueOf(0));
			}
			catalog.setCreateTime(new Date());
			catalog.setCreatorNick(adminUser.getNickName());
			catalog.setCreatorId(adminUser.getId());
			catalog.setStatus(Template.STATUS_NORMAL);
		}

		//System.out.println(title+","+id+","+sortid);
		catalog.setTitle(title);

		Integer sortId = RequestUtil.getParameterAsInt(request, "sortid", Integer.MIN_VALUE);
		if (Integer.MIN_VALUE == sortId) {
			sortId = getSecondFrom2014();
		}
		catalog.setSortid(sortId);
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        catalog.setModifyTime(new Date());
        
       
		try {
			catalogManager.saveCatalog(catalog);
			return "{\"result\": \"true\"}";			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "{\"result\": \"true\"}";	
		
	}

	
	/* 删除节点*/
	@RequestMapping(value = "/catalogDelete",method=RequestMethod.POST)
	@ResponseBody
	public String catalogDelete(@RequestParam(value = "id", required = true) Long id) throws RightException {
		rightService.assertRight(Right.SUGGEST_ADMIN);
		CatalogFilter filter = new CatalogFilter();		
		if (id != null) {
			filter.setParentId(id);
			//SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			filter.sortBySortid(false);
			List list = catalogManager.listCatalog(filter);
			
			//System.out.println(","+list.get(0).getId());
			
			
			if(list.size()>0){
				long[] ids= new long[list.size()];
				ids[list.size()-1] = id;
				for (int i=0;i childrenlist = catalogManager.listCatalog(filter1);
					{
						childrenlist.remove(Begin);
						Integer sortid=0;
						for(Catalog catalog:childrenlist)
						{
							System.out.println(catalog.getSortid());
						//	sortid=catalog.getSortid();
							if(catalog.getSortid()==End.getSortid()){								
								sortid=catalog.getSortid()+1;
								Begin.setSortid(sortid);
								catalogManager.saveCatalog(Begin);
								sortid++;
							}
							else {
								catalog.setSortid(sortid);
								catalogManager.saveCatalog(catalog);
								sortid= sortid+1;
							}
						}
					}
					return "{\"result\": \"true\"}";
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				//return "{\"result\": \"true\"}";	
			//}
//			else {
//				
//			}
//			
		}
		else {
			//靓机电节点的移动
		}
		return "{\"result\": \"false\"}";	
				
	}
	private int getSecondFrom2014() {
		Calendar cal = Calendar.getInstance();
		long now = cal.getTimeInMillis();

		cal.set(Calendar.YEAR, 2014);
		cal.set(Calendar.MONTH, 0);
		cal.set(Calendar.DATE, 1);
		cal.set(Calendar.HOUR_OF_DAY, 2014);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);
		long org = cal.getTimeInMillis();

		long sec = (now - org) / 1000;
		return (int) sec;
	}

}

前台方面我们引入了easyUI treegrid 包,然后在此基础上改动 下面是 catalogList.jsp 页面

 

<%@page import="com.trs.space.comment.Constants"%>
<%@page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/include/taglibs.jsp"%>



















留言分类浏览


分类名称:

排序值:

后台管理 >> 留言分类浏览 <%UserInfo info = (UserInfo) request.getSession().getAttribute(Constants.BIND_USER_INFO); %><%=info.getAdminUser().getNickName() %>
<%@include file="include/left_navigate.jsp" %>
留言分类浏览
浏览所有的留言分类。
<%@include file="include/tips_warn_err.jsp" %>
<%@include file="include/foot_version.jsp/" %>


其中还有一个编辑的页面的实现 catalogEdit.jsp

 

 

<%@page import="com.trs.space.comment.Constants"%>
<%@page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/include/taglibs.jsp"%>







添加/修改留言分类


后台管理 >> 添加/修改留言分类 <%UserInfo info = (UserInfo) request.getSession().getAttribute(Constants.BIND_USER_INFO); %><%=info.getAdminUser().getNickName() %>
<%@include file="include/left_navigate.jsp" %>
添加/修改留言分类
添加一个新的留言分类或者修改一个已有的留言分类。
<%@include file="include/tips_warn_err.jsp" %>
分类名称*
${titleError}
排序值
${sortidError}
<%@include file="include/foot_version.jsp/" %>



 

能够实现一级拖拽 二级隐藏一级二级拖拽了

 

 

 

你可能感兴趣的:(easyUI treegrid的使用)