Пример #1
0
  public String getScript() {
    StringBuffer sb = new StringBuffer();

    sb.append(
        "$('"
            + this.ID
            + "').TagBody = \""
            + XString.htmlEncode(getTagBody().replaceAll("\\s+", " "))
            + "\";");
    Object[] ks = this.Params.keyArray();
    Object[] vs = this.Params.valueArray();
    for (int i = 0; i < this.Params.size(); i++) {
      Object key = ks[i];
      if ((key.equals("_SKY_TAGBODY"))
          || (key.toString().startsWith("Cookie."))
          || (key.toString().startsWith("Header."))
          || (vs[i] == null)) continue;
      sb.append(
          "Tree.setParam('"
              + this.ID
              + "','"
              + key
              + "',\""
              + XString.javaEncode(vs[i].toString())
              + "\");");
    }

    sb.append(
        "Tree.setParam('" + this.ID + "','" + "_SKY_TREE_STYLE" + "',\"" + this.style + "\");");
    sb.append("Tree.setParam('" + this.ID + "','" + "_SKY_TREE_LEVEL" + "'," + this.level + ");");
    sb.append("Tree.setParam('" + this.ID + "','" + "_SKY_TREE_LAZY" + "',\"" + this.lazy + "\");");
    sb.append(
        "Tree.setParam('" + this.ID + "','" + "_SKY_TREE_EXPAND" + "',\"" + this.expand + "\");");
    sb.append("Tree.init('" + this.ID + "'," + this.resizeable + ");");
    String content = sb.toString();
    Matcher matcher = Constant.PatternField.matcher(content);
    sb = new StringBuffer();
    int lastEndIndex = 0;
    while (matcher.find(lastEndIndex)) {
      sb.append(content.substring(lastEndIndex, matcher.start()));
      sb.append("$\\{");
      sb.append(matcher.group(1));
      sb.append("}");
      lastEndIndex = matcher.end();
    }
    sb.append(content.substring(lastEndIndex));

    return sb.toString();
  }
Пример #2
0
  private void bindData() throws Exception {
    if (this.DataSource == null) {
      throw new RuntimeException("必须在bindData方法中设定DataSource");
    }

    this.items.clear();

    this.root = new TreeItem();
    this.root.setID("_TreeRoot");
    this.root.setParentID("");
    this.root.setRoot(true);
    this.root.setText(this.rootText);
    this.root.setAction(this);
    this.root.setLevel(0);

    this.root.setAttribute("onMouseOver", this.onMouseOver);
    this.root.setAttribute("onContextMenu", this.onContextMenu);
    this.root.setAttribute("onClick", this.onClick);
    this.root.setAttribute("onMouseOut", this.onMouseOut);

    this.items.add(this.root);

    Mapx map = new Mapx();
    for (int i = 0; i < this.DataSource.getRowCount(); i++)
      map.put(
          this.DataSource.getString(i, this.IdentifierColumnName),
          this.DataSource.getString(i, this.ParentIdentifierColumnName));
    try {
      TreeItem last = null;
      for (int i = 0; i < this.DataSource.getRowCount(); i++) {
        DataRow dr = this.DataSource.getDataRow(i);
        String parentID = dr.getString(this.ParentIdentifierColumnName);
        if ((XString.isEmpty(parentID)) || (!map.containsKey(parentID))) {
          TreeItem item = new TreeItem();
          item.setData(dr);
          item.parseHtml(getItemInnerHtml(dr));
          item.setAction(this);
          item.setID(dr.getString(this.IdentifierColumnName));
          item.setParentID(parentID);
          if (this.lazyLoad) {
            item.setLevel(this.parentLevel + 1);
            item.setLevelStr((String) getParams().get("LevelStr"));
          } else {
            item.setLevel(1);
          }
          item.setParent(this.root);
          this.items.add(item);
          addChild(item);
          last = item;
        }
      }

      if (last != null) last.setLast(true);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #3
0
 public void changePassword() throws SQLException {
   String OldPassword = $V("OldPassword");
   String Password = $V("Password");
   QueryBuilder qb =
       new QueryBuilder("update ZDUser set Password=? where UserName=? and Password=?");
   qb.add(XString.md5Hex(Password));
   qb.add(User.getUserName());
   qb.add(XString.md5Hex(OldPassword));
   if (qb.executeNoQuery() > 0) {
     UserLogPage.log("User", "EditPassword", "修改密码成功", this.request.getClientIP());
     this.response.setMessage("修改密码成功");
     this.response.setStatus(1);
   } else {
     UserLogPage.log("User", "EditPassword", "修改密码失败", this.request.getClientIP());
     this.response.setStatus(0);
     this.response.setMessage("修改密码失败,旧密码不正确");
   }
 }
Пример #4
0
  public static long getCurrentSiteID() {
    String id = (String) User.getValue("_CurrentSiteID");
    if (XString.isEmpty(id)) {
      if ("admin".equals(User.getUserName())) {
        LogUtil.error("请在站点管理->站点列表下先创建站点");
        return 0L;
      }
      LogUtil.error("用户:" + User.getUserName() + "没有任何站点的浏览权限,请先设置权限再登陆");
      return 0L;
    }

    return Long.parseLong(id);
  }
Пример #5
0
  public String getHtml() {
    StringBuffer sb = new StringBuffer();
    String styleStr = "";
    if (XString.isNotEmpty(this.style)) {
      styleStr = styleStr + this.style;
    }
    if (!this.lazyLoad) {
      sb.append(
          "<div id='"
              + this.ID
              + "_container' class='treeContainer' style='-moz-user-select:none;"
              + styleStr
              + "'><div xtype='_Tree' onselectstart='stopEvent(event);' id='"
              + this.ID
              + "' method='"
              + this.method
              + "' class='treeItem'><table><tr><td>");
    }
    for (int i = 0; i < this.items.size(); i++) {
      if ((this.lazyLoad) && (getItem(i).getLevel() <= this.parentLevel)) {
        continue;
      }
      if ((i != 0) && (getItem(i).getLevel() > getItem(i - 1).getLevel())) {
        if ((getItem(i).getLevel() == this.level) && (!this.lazyLoad) && (!this.lazy))
          sb.append("<div style='display:none'>");
        else {
          sb.append("<div>");
        }
      }

      sb.append(((TreeItem) this.items.get(i)).getOuterHtml());
      if ((i != this.items.size() - 1) && (getItem(i).getLevel() > getItem(i + 1).getLevel())) {
        for (int j = 0; j < getItem(i).getLevel() - getItem(i + 1).getLevel(); j++) {
          sb.append("</div>");
        }
      }
      if (i == this.items.size() - 1) {
        for (int j = 0; j < getItem(i).getLevel() - this.parentLevel; j++) {
          sb.append("</div>");
        }
      }
    }
    if (!this.lazyLoad) {
      sb.append("</td></tr></table></div></div>\n\r");
      HtmlScript script = new HtmlScript();
      script.setInnerHTML(getScript());
      sb.append(script.getOuterHtml());
    }

    return sb.toString();
  }
Пример #6
0
 public void addChild(TreeItem parent) throws Exception {
   boolean childFlag = false;
   TreeItem last = null;
   int index = -1;
   for (int i = this.items.size() - 1; i >= 0; i--) {
     if (this.items.get(i) == parent) {
       index = i;
       break;
     }
   }
   ArrayList list = new ArrayList();
   for (int i = 0; i < this.DataSource.getRowCount(); i++) {
     DataRow dr = this.DataSource.getDataRow(i);
     String pid = dr.getString(this.ParentIdentifierColumnName);
     String id = dr.getString(this.IdentifierColumnName);
     if ((parent.getID().equals(pid)) && (!XString.isEmpty(id)) && (!id.equals(pid))) {
       childFlag = true;
       if ((parent.getLevel() >= this.level) && ((!this.lazyLoad) || (!this.expand))) {
         parent.setLazy(this.lazy);
         parent.setExpanded(false);
         parent.setBranch(childFlag);
         return;
       }
       TreeItem item = new TreeItem();
       item.setData(dr);
       item.parseHtml(getItemInnerHtml(dr));
       item.setAction(this);
       item.setID(dr.getString(this.IdentifierColumnName));
       item.setParentID(parent.getID());
       item.setLevel(parent.getLevel() + 1);
       item.setParent(parent);
       if (this.lazyLoad) {
         item.setLevelStr((String) getParams().get("LevelStr"));
       }
       list.add(item);
       this.items.add(index + list.size(), item);
       last = item;
     }
   }
   for (int i = 0; i < list.size(); i++) {
     addChild((TreeItem) list.get(i));
   }
   if (last != null) {
     last.setLast(true);
   }
   if ((!this.lazy) && (parent.getLevel() + 1 == this.level)) {
     parent.setExpanded(false);
   }
   parent.setBranch(childFlag);
 }
Пример #7
0
  public static Mapx init(Mapx params) {
    DataTable dt = null;
    dt = new QueryBuilder("select name,id from zcsite order by orderflag").executeDataTable();
    dt =
        dt.filter(
            new Filter() {
              public boolean filter(Object obj) {
                DataRow dr = (DataRow) obj;
                return Priv.getPriv(User.getUserName(), "site", dr.getString("ID"), "site_browse");
              }
            });
    if ((getCurrentSiteID() == 0L) && (dt.getRowCount() > 0)) {
      setCurrentSiteID(dt.getString(0, "ID"));
    }
    params.put("Sites", HtmlUtil.dataTableToOptions(dt, getCurrentSiteID()));
    DataTable dtsite =
        new QueryBuilder("select ID,Name from zcsite order by orderflag").executeDataTable();
    StringBuffer sitestb = new StringBuffer();
    for (int i = 0; i < dtsite.getRowCount(); i++) {
      if (dtsite.getString(i, "ID").equals(getCurrentSiteID())) {
        sitestb.append(
            "<a value=\""
                + dtsite.getString(i, "ID")
                + "\" class=\"ahover\" hidefocus href=\"javascript:void(0);\">"
                + dtsite.getString(i, "Name")
                + "</a>");
        params.put("CurrentSiteName", dtsite.getString(i, "Name"));
        params.put("CurrentSiteId", dtsite.getString(i, "ID"));
      } else {
        sitestb.append(
            "<a value=\""
                + dtsite.getString(i, "ID")
                + "\" hidefocus href=\"javascript:void(0);\">"
                + dtsite.getString(i, "Name")
                + "</a>");
      }
    }
    params.put("ZCSites", sitestb.toString());

    dt =
        new QueryBuilder(
                "select name,id from zdmenu where  visiable='Y' and parentID=0 order by OrderFlag")
            .executeDataTable();
    dt =
        dt.filter(
            new Filter() {
              public boolean filter(Object obj) {
                DataRow dr = (DataRow) obj;
                return Priv.getPriv(
                    User.getUserName(),
                    "menu",
                    ApplicationPage.getCurrentSiteID() + "-" + dr.getString("id"),
                    "menu_browse");
              }
            });
    boolean hasMenu = false;
    String template =
        "<a id='_Menu_${ID}' onclick='Application.onMainMenuClick(this);return false;' hidefocus='true'><b>${Name}</b></a>";
    String menuHtml = HtmlUtil.replaceWithDataTable(dt, template);
    if (dt.getRowCount() > 0) {
      hasMenu = true;
    }

    StringBuffer sb = new StringBuffer();

    template = "arr.push([${ID},\"${Name}\",\"${URL}\",\"${Icon}\"]);";
    sb.append("var arr;");
    for (int i = 0; i < dt.getRowCount(); i++) {
      String id = dt.getString(i, "ID");
      sb.append("arr = [];");
      DataTable dt2 =
          new QueryBuilder(
                  "select name,id,url,icon from zdmenu where visiable='Y' and parentID=? order by OrderFlag",
                  id)
              .executeDataTable();
      dt2 =
          dt2.filter(
              new Filter() {
                public boolean filter(Object obj) {
                  DataRow dr = (DataRow) obj;
                  return Priv.getPriv(
                      User.getUserName(),
                      "menu",
                      ApplicationPage.getCurrentSiteID() + "-" + dr.getString("id"),
                      "menu_browse");
                }
              });
      sb.append(HtmlUtil.replaceWithDataTable(dt2, template));
      sb.append("$('_Menu_" + id + "').ChildArray = arr;");
      if (dt2.getRowCount() > 0) {
        hasMenu = true;
      }
    }

    HtmlScript script = new HtmlScript();
    script.setInnerHTML(sb.toString());
    if (hasMenu) params.put("Menu", menuHtml + script.getOuterHtml());
    else {
      params.put("Menu", "<font color='yellow'>对不起,你没有任何菜单权限,请联系'管理员'分配菜单权限后再登陆!</font>");
    }

    DataCollection privDC = LoginPage.getAllPriv(new DataCollection());
    String priv = XString.htmlEncode(privDC.toXML().replaceAll("\\s+", " "));
    params.put("Privileges", priv);
    return params;
  }
Пример #8
0
 public static void setCurrentSiteID(String siteID) {
   if (XString.isEmpty(siteID)) User.setValue("_CurrentSiteID", "");
   else User.setValue("_CurrentSiteID", siteID);
 }