@RequiresPermissions("cms:category:view") @RequestMapping(value = {"list", ""}) public String list(Model model) { List<Category> list = Lists.newArrayList(); List<Category> sourcelist = categoryService.findByUser(true, null); Category.sortList(list, sourcelist, "1"); model.addAttribute("list", list); return "modules/cms/categoryList"; }
@RequiresPermissions("cms:category:edit") @RequestMapping(value = "delete") public String delete( Category category, HttpServletRequest request, RedirectAttributes redirectAttributes) { if (Global.isDemoMode()) { addMessage(redirectAttributes, "演示模式,不允许操作!"); return "redirect:" + adminPath + "/cms/category/"; } if (Category.isRoot(category.getId())) { addMessage(redirectAttributes, "删除栏目失败, 不允许删除顶级栏目或编号为空"); } else { categoryService.delete(category); addMessage(redirectAttributes, "删除栏目成功"); } String no = request.getParameter("pageNum"); return "redirect:" + adminPath + "/cms/category/" + "?pageNum=" + no; }
@RequiresPermissions("cms:category:edit") @RequestMapping(value = "save") public String save(Category category, Model model, RedirectAttributes redirectAttributes) { if (Global.isDemoMode()) { addMessage(redirectAttributes, "演示模式,不允许操作!"); return "redirect:" + adminPath + "/cms/category/"; } if (!beanValidator(model, category)) { return form(category, model); } categoryService.save(category); addMessage(redirectAttributes, "保存栏目'" + category.getName() + "'成功"); return "redirect:" + adminPath + "/cms/category/"; }
@RequiresUser @ResponseBody @RequestMapping(value = "treeData") public List<Map<String, Object>> treeData( String module, @RequestParam(required = false) String extId, HttpServletResponse response) { response.setContentType("application/json; charset=UTF-8"); List<Map<String, Object>> mapList = Lists.newArrayList(); List<Category> list = categoryService.findByUser(true, module); for (int i = 0; i < list.size(); i++) { Category e = list.get(i); if (extId == null || (extId != null && !extId.equals(e.getId()) && e.getParentIds().indexOf("," + extId + ",") == -1)) { Map<String, Object> map = Maps.newHashMap(); map.put("id", e.getId()); map.put("pId", e.getParent() != null ? e.getParent().getId() : 0); map.put("name", e.getName()); map.put("module", e.getModule()); mapList.add(map); } } return mapList; }
@RequiresPermissions("cms:category:view") @RequestMapping(value = "form") public String form(Category category, Model model) { if (category.getParent() == null || category.getParent().getId() == null) { category.setParent(new Category("1")); } Category parent = categoryService.get(category.getParent().getId()); category.setParent(parent); if (category.getOffice() == null || category.getOffice().getId() == null) { category.setOffice(parent.getOffice()); } model.addAttribute("listViewList", getTplContent(Category.DEFAULT_TEMPLATE)); model.addAttribute("category_DEFAULT_TEMPLATE", Category.DEFAULT_TEMPLATE); model.addAttribute("contentViewList", getTplContent(Article.DEFAULT_TEMPLATE)); model.addAttribute("article_DEFAULT_TEMPLATE", Article.DEFAULT_TEMPLATE); model.addAttribute("office", category.getOffice()); model.addAttribute("category", category); return "modules/cms/categoryForm"; }