📄 systemmenuaction.java
字号:
package com.easyjf.news.action;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.easyjf.news.business.ActiveUser;
import com.easyjf.news.business.NewsUtil;
import com.easyjf.news.business.NewsDir;
import com.easyjf.news.business.SystemMenu;
import com.easyjf.news.business.SystemUtil;
import com.easyjf.news.business.UserUtil;
import com.easyjf.util.CommUtil;
import com.easyjf.web.Module;
import com.easyjf.web.Page;
import com.easyjf.web.WebForm;
import com.easyjf.web.tools.DbPageList;
import com.easyjf.web.tools.IPageList;
public class SystemMenuAction extends BaseAction {
private SystemMenu parent;
public Object doBefore(WebForm form, Module module) {
//检测用户是否登录
if(this.getCurrentUser(form)==null){
form.addResult("msg","您没有登录,或者登录信息已经超时,请重新登录!");
return new Page("popedomError","/nologin.htm","page");
}
String pcid=CommUtil.null2String(form.get("pcid"));
parent=SystemMenu.read(pcid);
if(parent!=null)
{
if(parent.getTypes()!=null && ("NewsContent".equals(parent.getTypes().trim())))return new Page("newsDir","/news-dir.ejf","html");//网站内容管理直接跳到目录管理
form.addResult("parent",parent);
}
else form.addResult("parent",SystemUtil.getRootMenu());
return super.doBefore(form,module);
}
public IPageList doQuery(WebForm form, int currentPage, int pageSize) {
String scope="1=1";
Collection paras=new ArrayList();
if(parent!=null){
scope+=" and parentSn=?";
paras.add(parent.getSn());
}
else
{
SystemMenu rootMenu=SystemUtil.getRootMenu();
if(rootMenu!=null){
scope+=" and parentSn=?";
paras.add(rootMenu.getSn());
}
}
String orderType=CommUtil.null2String(form.get("orderType"));
String orderField=CommUtil.null2String(form.get("orderField"));
if(orderField.equals(""))
{
orderField="sequence";
orderType="asc";
}
if(!orderField.equals(""))
{
scope +=" order by "+orderField;
if(!orderType.equals(""))scope+=" "+orderType;
}
DbPageList pList=new DbPageList(SystemMenu.class,scope,paras);
pList.doList(currentPage,pageSize);
return pList;
}
public Object form2Obj(WebForm form) {
String cid=CommUtil.null2String(form.get("cid"));
SystemMenu obj=null;
if(cid.equals(""))
{
obj=(SystemMenu)form.toPo(SystemMenu.class);
obj.setStatus(new Integer(0));
}
else
{
obj=SystemMenu.read(cid);
form.toPo(obj);
}
return obj;
}
public void doAfter(WebForm form, Module module) {
// TODO Auto-generated method stub
super.doAfter(form, module);
String method=this.getCommand();
if("new".equals(method)||"edit".equals(method))
{
form.addResult("statusOptions",CommUtil.getSelectOptions(NewsDir.statusTitle,""+form.get("status")));
form.addResult("typesOptions",CommUtil.getSelectOptions(NewsDir.typesTitle,""+form.get("types")));
List allDir=SystemMenu.query("status>=0");
if(allDir!=null)
{
String[][] dirs =new String[allDir.size()][2];
for(int i=0;i<allDir.size();i++)
{
dirs[i][0]=((SystemMenu)allDir.get(i)).getSn().trim();
dirs[i][1]=((SystemMenu)allDir.get(i)).getTitle().trim();
}
String sn=CommUtil.null2String(form.get("parentSn")).trim();
if(sn.equals("")&&(parent!=null))sn=parent.getSn().trim();
form.addResult("allDirOptions",CommUtil.getSelectOptions(dirs,sn));
}
}
}
public Page doInitMenu(WebForm form, Module module)
{
String title=(String)form.get("title");
if(title==null)
{
form.addResult("initDir","true");
return new Page("initMenu","/manage/systemMenuEdit.html","template");
}
else//保存
{
NewsDir obj=(NewsDir)form2Obj(form);
obj.setParentSn("SiteRoot");
obj.save();
form.addResult("js","top.location.reload();");
return new Page("javascript","/manage/javascript.html","template");
}
}
public Page doGoto(WebForm form, Module module)
{
String sn=CommUtil.null2String(form.get("sn"));
if(SystemUtil.isNewsDir(sn)){
NewsDir dir=NewsDir.readBySn(SystemUtil.getNewsDirSn(sn));
return new Page("t","/news-doc.ejf?dirSn="+dir.getSn(),"html");
}
else
{
SystemMenu menu=SystemMenu.readBySn(sn);
if(menu!=null && menu.getUrl()!=null && (!"".equals(menu.getUrl())))
{
return new Page(sn,menu.getUrl(),"html");
}
return null;
}
}
public Page doMain(WebForm form, Module module)
{
// form.addResult("js","top.mainFrame.leftMenu.location.replace('/menu.ejf?easyJWebCommand=listMenu');");
// return new Page("javascript","/manage/javascript.html","template");
return module.findPage("main");
}
public Page doListMenu(WebForm form, Module module)
{
ActiveUser user=(ActiveUser)this.getCurrentUser(form);
if(UserUtil.checkAdmin(user))
{
form.addResult("administrator","true");
}
if(UserUtil.checkManager(user))
{
form.addResult("manager","true");
}
NewsDir rootDir=NewsUtil.getRootDir();
if(rootDir==null)
{
form.addResult("noDir","true");
}
else
{
form.addResult("topDirs",rootDir.children());
form.addResult("rootDirSn",rootDir.getSn().trim());
}
return module.findPage("leftMenu");
}
public Page doGetMenu(WebForm form, Module module)
{
String sn=CommUtil.null2String(form.get("sn"));
SystemMenu menu;
if("".equals(sn))
{
menu=SystemUtil.getRootMenu();
if(menu!=null)form.addResult("list",menu.children());
}
else if(SystemUtil.isNewsDir(sn))
{
NewsDir dir=NewsDir.readBySn(SystemUtil.getNewsDirSn(sn));
if(dir!=null)form.addResult("list",SystemUtil.getDirChildMenu(dir));
}
else
{
menu=SystemMenu.readBySn(sn);
if(menu!=null)form.addResult("list",menu.children());
}
return module.findPage("xmlMenu");
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -