Exemplo n.º 1
0
 private boolean contain(Perf perf, List<RolePerf> rpl) {
   for (RolePerf rp : rpl) {
     Perf perf2 = rp.getPerf();
     if (perf2 != null & perf2.getId() == perf.getId()) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 2
0
  public String c_editUnderRole() throws NoSuchFieldException, IllegalAccessException {
    if ("1".equals(isPage)) {
      StringBuilder permissionTree = new StringBuilder();
      Role role = baseDao.get(Role.class, String.valueOf(idField.get(bean)));
      permissionTree.append(
          "<div  style='width:30%;float:left;'>"
              + "角色:"
              + role.getDescr()
              + "<a class='easyui-linkbutton' onclick='getChecked()'>保存功能配置</a> <a class='easyui-linkbutton' onclick='collapse()'>收起</a> "
              + "<ul id='roletree' class=\"easyui-tree\" data-options=\"url:'cfg_c_Role_editUnder.sg?isPage=tree&bean.id="
              + role.getId()
              + "',checkbox:true,cascadeCheck:false, "
              + // cascadeCheck:false,
              "onClick: function(node){ $.post('cfg_c_Role_editUnder.sg?isPage=perf&bean.id="
              + role.getId()
              + "&id='+node.id,function(data){$('#perf').html(data);});}"
              +
              // ",onCheck:function(node, checked){alert(node.text+checked);}"
              // +
              " \"></ul>"
              + "</div><div id='perf' style='width:70%;float:right;'></div>");
      // permissionTree.append("<script>$(function(){$('#roletree').tree({onLoadSuccess:function(node, data){ $('#roletree').tree({onCheck:function(node, checked){alert(node.text+checked);}});}});});function tr(){}</script>");
      // permissionTree.append("<script>$(function(){setTimeout('tr()',5000);});function
      // tr(){$('.tree-checkbox').click(function(){alert(1)});}</script>");
      permissionTree.append(
          "<script>function collapse(){$('#roletree').tree('collapseAll');} function getChecked(){var nodes = $('#roletree').tree('getChecked');var s = '';	"
              + "for(var i=0; i<nodes.length; i++){if (s != '') s += ',';"
              + "s += nodes[i].id;}"
              + "$.post('cfg_c_Role_editUnder.sg?isPage=permissionSub',{'id':s,'bean.id':"
              + role.getId()
              + "},function(data){alert(data);});}</script>");

      setBodyHtml(permissionTree.toString());
      return "page";
    } else if ("tree".equals(isPage)) {
      DetachedCriteria dc = DetachedCriteria.forClass(RolePermission.class);
      dc.add(Restrictions.eq("role", bean));
      List<RolePermission> rpl = baseDao.find(dc);
      List<String> mpl = new ArrayList<String>();
      for (RolePermission rp : rpl) {
        mpl.add(rp.getPermission().getId());
      }
      treeValue = new ArrayList<AsyncTree>();
      List<AsyncTree> findTreeValue =
          Util.findCheckedTreeValue(mpl, new Permission(), null, baseDao);
      treeValue.addAll(findTreeValue);

      return "tree";
    } else if ("perf".equals(isPage)) {
      Permission p = baseDao.get(Permission.class, Integer.valueOf(id));
      DetachedCriteria dc = DetachedCriteria.forClass(Perf.class);
      dc.add(Restrictions.eq("permission", p));
      List<Perf> pl = baseDao.find(dc);
      Role role = baseDao.get(Role.class, String.valueOf(idField.get(bean)));
      dc = DetachedCriteria.forClass(RolePerf.class);
      dc.add(Restrictions.eq("role", role));
      List<RolePerf> rpl = baseDao.find(dc);
      // if pl de p in rpl ,then checked
      StringBuilder res = new StringBuilder();
      res.append("表现:(不选则以ord小的)<p>");
      for (Perf perf : pl) {
        String pod = perf.getId();
        res.append(
                "<input type='checkbox' "
                    + (contain(perf, rpl) ? "checked='checked'" : "")
                    + " name='' value='perf:"
                    + pod
                    + "' /><a target='_blank' href='cfg_detailPerf.sg?bean.id="
                    + pod
                    + "'>")
            .append(perf.getDescr() + "(" + perf.getOrd() + ")</a><p>");
      }
      dc = DetachedCriteria.forClass(Filter.class);
      dc.add(Restrictions.eq("permission", p));
      List<Filter> fl = baseDao.find(dc);
      dc = DetachedCriteria.forClass(RoleFilter.class);
      dc.add(Restrictions.eq("role", role));
      List<RoleFilter> rfl = baseDao.find(dc);
      // if pl de p in rpl ,then checked
      res.append("数据过滤:(不选则无过滤)<p>");
      for (Filter filter : fl) {
        String pod = filter.getId();
        res.append(
                "<input type='checkbox' "
                    + (contain(filter, rfl) ? "checked='checked'" : "")
                    + " name='' value='filter:"
                    + pod
                    + "' /><a target='_blank' href='cfg_detailFilter.sg?bean.id="
                    + pod
                    + "'>")
            .append(filter.getDescr() + "(" + filter.getOrd() + ")</a><p>");
      }
      res.append(
          "<script>$(function(){if ($.browser.msie) "
              + "{ $('input:checkbox').click(function () "
              + "{ this.blur(); this.focus(); }); }  $('input:checkbox').change(function(){"
              + "$.post('cfg_c_Role_editUnder.sg?isPage=perfSub',{'id':$(this).val(),'check':$(this).attr('checked'),'bean.id':"
              + role.getId()
              + "},"
              + "function(data){alert(data)}); "
              + "});});</script>");
      setBodyHtml(res.toString());
      return "perf";
    }
    // 提交Permission修正
    else if ("permissionSub".equals(isPage)) {
      bean = baseDao.get(Role.class, String.valueOf(idField.get(bean)));
      id = "," + id + ",";
      DetachedCriteria dc = DetachedCriteria.forClass(RolePermission.class);
      dc.add(Restrictions.eq("role", bean));
      List<RolePermission> rpl = baseDao.find(dc);
      for (RolePermission rp : rpl) {
        String pid = rp.getPermission().getId();
        if (!id.contains("," + pid + ",")) {
          baseDao.delete(rp);
        } else {
          id = id.replace("," + pid + ",", ",");
        }
      }
      if (id.length() > 1) {
        String[] split = id.split(",");
        for (String s : split) {
          if (Util.notEmptyString(s)) {
            RolePermission rp = new RolePermission();
            Permission one = new Permission();
            one.setId(s);
            rp.setPermission(one);
            rp.setRole((Role) bean);
            baseDao.save(rp);
          }
        }
      }

      setBodyHtml(Constant.UPDATE_SUCCESS);
      return SUCCESS;
    }
    // 提交Perf或者Filter
    else if ("perfSub".equals(isPage)) {
      bean = baseDao.get(Role.class, String.valueOf(idField.get(bean)));
      if (Util.notEmptyString(id)) {
        if (id.startsWith("perf:")) {
          String idStr = id.replace("perf:", "");
          Perf perf = baseDao.get(Perf.class, Integer.valueOf(idStr));
          if (perf != null) {
            if ("checked".equals(check)) {
              RolePerf rp = new RolePerf();
              rp.setPerf(perf);
              rp.setRole((Role) bean);
              baseDao.save(rp);
            } else {
              DetachedCriteria dc = DetachedCriteria.forClass(RolePerf.class);
              dc.add(Restrictions.eq("perf", perf));
              dc.add(Restrictions.eq("role", bean));
              RolePerf findBean = baseDao.findBean(dc);
              if (findBean != null) {
                baseDao.delete(findBean);
              }
            }
          }

        } else if (id.startsWith("filter:")) {
          String idStr = id.replace("filter:", "");
          Filter perf = baseDao.get(Filter.class, Integer.valueOf(idStr));
          if (perf != null) {
            if ("checked".equals(check)) {
              RoleFilter rp = new RoleFilter();
              rp.setFilter(perf);
              rp.setRole((Role) bean);
              baseDao.save(rp);
            } else {
              DetachedCriteria dc = DetachedCriteria.forClass(RoleFilter.class);
              dc.add(Restrictions.eq("filter", perf));
              dc.add(Restrictions.eq("role", bean));
              RoleFilter findBean = baseDao.findBean(dc);
              if (findBean != null) {
                baseDao.delete(findBean);
              }
            }
          }
        }
        setBodyHtml(Constant.UPDATE_SUCCESS);
        return SUCCESS;
      }
    }
    return SUCCESS;
  }