Пример #1
0
  @RequestMapping(value = "ajax/load")
  @PageableDefaults(sort = {"parentIds=asc", "weight=asc"})
  @ResponseBody
  public Object load(
      HttpServletRequest request,
      @RequestParam(value = "async", defaultValue = "true") boolean async,
      @RequestParam(value = "asyncLoadAll", defaultValue = "false") boolean asyncLoadAll,
      @RequestParam(value = "searchName", required = false) String searchName,
      @RequestParam(value = "id", required = false) ID parentId,
      @RequestParam(value = "excludeId", required = false) ID excludeId,
      @RequestParam(value = "onlyCheckLeaf", required = false, defaultValue = "false")
          boolean onlyCheckLeaf,
      Searchable searchable) {

    M excludeM = baseService.findOne(excludeId);

    List<M> models = null;

    if (!StringUtils.isEmpty(searchName)) { // 按name模糊查
      searchable.addSearchParam("name_like", searchName);
      models = baseService.findAllByName(searchable, excludeM);
      if (!async || asyncLoadAll) { // 非异步模式 查自己及子子孙孙 但排除
        searchable.removeSearchFilter("name_like");
        List<M> children = baseService.findChildren(models, searchable);
        models.removeAll(children);
        models.addAll(children);
      } else { // 异步模式 只查匹配的一级

      }
    } else { // 根据有没有parentId加载

      if (parentId != null) { // 只查某个节点下的 异步
        searchable.addSearchFilter("parentId", SearchOperator.eq, parentId);
      }

      if (async && !asyncLoadAll) { // 异步模式下 且非异步加载所有
        // 排除自己 及 子子孙孙
        baseService.addExcludeSearchFilter(searchable, excludeM);
      }

      if (parentId == null && !asyncLoadAll) {
        models = baseService.findRootAndChild(searchable);
      } else {
        models = baseService.findAllWithSort(searchable);
      }
    }

    return convertToZtreeList(
        request.getContextPath(),
        models,
        async && !asyncLoadAll && parentId != null,
        onlyCheckLeaf);
  }
  @RequestMapping("/load")
  @ResponseBody
  public Collection<Map> ajaxLoad(Searchable searchable, @CurrentUser User loginUser) {
    searchable.addSearchParam("userId_eq", loginUser.getId());
    List<Calendar> calendarList = calendarService.findAllWithNoPageNoSort(searchable);

    return Lists.<Calendar, Map>transform(
        calendarList,
        new Function<Calendar, Map>() {
          @Override
          public Map apply(Calendar c) {
            Map<String, Object> m = Maps.newHashMap();

            Date startDate = new Date(c.getStartDate().getTime());
            Date endDate = DateUtils.addDays(startDate, c.getLength() - 1);
            boolean allDays = c.getStartTime() == null && c.getEndTime() == null;

            if (!allDays) {
              startDate.setHours(c.getStartTime().getHours());
              startDate.setMinutes(c.getStartTime().getMinutes());
              startDate.setSeconds(c.getStartTime().getSeconds());
              endDate.setHours(c.getEndTime().getHours());
              endDate.setMinutes(c.getEndTime().getMinutes());
              endDate.setSeconds(c.getEndTime().getSeconds());
            }

            m.put("id", c.getId());
            m.put("start", DateFormatUtils.format(startDate, "yyyy-MM-dd HH:mm:ss"));
            m.put("end", DateFormatUtils.format(endDate, "yyyy-MM-dd HH:mm:ss"));
            m.put("allDay", allDays);
            m.put("title", c.getTitle());
            m.put("details", c.getDetails());
            if (StringUtils.isNotEmpty(c.getBackgroundColor())) {
              m.put("backgroundColor", c.getBackgroundColor());
              m.put("borderColor", c.getBackgroundColor());
            }
            if (StringUtils.isNotEmpty(c.getTextColor())) {
              m.put("textColor", c.getTextColor());
            }
            return m;
          }
        });
  }
Пример #3
0
  @RequestMapping(value = "tree", method = RequestMethod.GET)
  @PageableDefaults(sort = {"parentIds=asc", "weight=asc"})
  public String tree(
      HttpServletRequest request,
      @RequestParam(value = "searchName", required = false) String searchName,
      @RequestParam(value = "async", required = false, defaultValue = "false") boolean async,
      Searchable searchable,
      Model model) {

    if (permissionList != null) {
      permissionList.assertHasViewPermission();
    }

    List<M> models = null;

    if (!StringUtils.isEmpty(searchName)) {
      searchable.addSearchParam("name_like", searchName);
      models = baseService.findAllByName(searchable, null);
      if (!async) { // 非异步 查自己和子子孙孙
        searchable.removeSearchFilter("name_like");
        List<M> children = baseService.findChildren(models, searchable);
        models.removeAll(children);
        models.addAll(children);
      } else { // 异步模式只查自己

      }
    } else {
      if (!async) { // 非异步 查自己和子子孙孙
        models = baseService.findAllWithSort(searchable);
      } else { // 异步模式只查根 和 根一级节点
        models = baseService.findRootAndChild(searchable);
      }
    }

    model.addAttribute("trees", convertToZtreeList(request.getContextPath(), models, async, true));

    return viewName("tree");
  }