示例#1
0
  @Override
  public void renderHTML() throws Exception {
    Server fed = ServerStore.getInstance().loadFederation();

    if (!fed.isChannelEnabled(Channel.VOICE)) {
      // To prevent guided setup from getting stuck
      progressGuidedSetup();

      throw new PageNotFoundException();
    }

    if (isParameter("send")) {
      if (!this.isFormException()) {
        renderEnterCode();
      } else {
        renderSendCode();
      }
    } else if (isParameter("enter")) {
      if (!this.isFormException()) {
        renderSendCode();
      } else {
        renderEnterPhone();
      }
    } else if (isParameter("verify")) {
      if (!this.isFormException()) {
        // Should not reach here
        throw new PageNotFoundException();
      } else {
        renderEnterCode();
      }
    } else {
      renderEnterPhone();
    }
  }
示例#2
0
  @Override
  public void commit() throws Exception {
    Set<UUID> userIDs = new HashSet<UUID>();

    // Users
    Integer userCount = getParameterInteger("users");
    for (int i = 0; i < userCount; i++) {
      Pair<String, String> kvp = getParameterTypeAhead("user_" + i);
      if (kvp != null && !Util.isEmpty(kvp.getKey())) {
        User u = UserStore.getInstance().loadByLoginName(kvp.getKey());
        if (u != null) {
          userIDs.add(u.getID());
        }
      }
    }

    // Groups
    Integer groupCount = getParameterInteger("groups");
    for (int i = 0; i < groupCount; i++) {
      Pair<String, String> kvp = getParameterTypeAhead("group_" + i);
      if (kvp != null && !Util.isEmpty(kvp.getKey())) {
        UserGroup lg = UserGroupStore.getInstance().loadByName(kvp.getKey());
        if (lg != null) {
          userIDs.addAll(UserUserGroupLinkStore.getInstance().getUsersForGroup(lg.getID()));
        }
      }
    }

    // Content
    String subject = getParameterString("subject");
    String body = getParameterString("body");
    Map<String, String> notifParams =
        new ParameterMap(AdHocNotif.PARAM_SUBJECT, subject).plus(AdHocNotif.PARAM_BODY, body);

    // Send
    Server fed = ServerStore.getInstance().loadFederation();
    Date date = getParameterDate("date");

    this.messageCount = new HashMap<String, Integer>();
    for (String channel : Channel.getPush()) {
      if (isParameter(channel) == true && fed.isChannelEnabled(channel) == true) {
        for (UUID userID : userIDs) {
          Notifier.send(channel, date, userID, null, AdHocNotif.COMMAND, notifParams);

          // !$! Consider delayed schedule

          Integer count = this.messageCount.get(channel);
          if (count == null) {
            this.messageCount.put(channel, 1);
          } else {
            this.messageCount.put(channel, (1 + count));
          }
        }
      }
    }
  }
示例#3
0
  @Override
  public void renderHTML() throws Exception {
    if (this.messageCount != null && this.messageCount.size() > 0) {
      for (String channel : this.messageCount.keySet()) {
        writeEncode(
            getString(
                "admin:AdHocMessage.MessagesSent",
                this.messageCount.get(channel),
                Channel.getDescription(channel, getLocale())));
        write("<br>");
      }
      return;
    }

    writeFormOpen();

    TwoColFormControl twoCol = new TwoColFormControl(this);

    // Users
    twoCol.writeRow(getString("admin:AdHocMessage.Users"));
    new ControlArray<Object>(twoCol, "users", null) {
      @Override
      public void renderRow(int rowNum, Object nothing) {
        writeTypeAheadInput(
            "user_" + rowNum,
            null,
            null,
            40,
            User.MAXSIZE_LOGINNAME,
            getPageURL(UserTypeAhead.COMMAND));
      }
    }.render();

    twoCol.writeSpaceRow();

    // Groups
    twoCol.writeRow(getString("admin:AdHocMessage.Groups"));
    new ControlArray<Object>(twoCol, "groups", null) {
      @Override
      public void renderRow(int rowNum, Object nothing) {
        writeTypeAheadInput(
            "group_" + rowNum,
            null,
            null,
            40,
            UserGroup.MAXSIZE_NAME,
            getPageURL(UserGroupTypeAhead.COMMAND));
      }
    }.render();

    twoCol.writeSpaceRow();

    // Channels
    Server fed = ServerStore.getInstance().loadFederation();

    twoCol.writeRow(getString("admin:AdHocMessage.Channels"));
    for (String channel : Channel.getPush()) {
      if (fed.isChannelEnabled(channel) == true) {
        twoCol.writeCheckbox(channel, Channel.getDescription(channel, getLocale()), false);
        twoCol.write(" ");
      }
    }

    twoCol.writeSpaceRow();

    // Subject
    twoCol.writeRow(getString("admin:AdHocMessage.Subject"));
    twoCol.writeTextInput("subject", null, 80, 128);

    // Body
    twoCol.writeRow(getString("admin:AdHocMessage.Body"));
    twoCol.writeRichEditField("body", null, 80, 10);

    twoCol.writeSpaceRow();

    // Schedule
    twoCol.writeRow(getString("admin:AdHocMessage.Schedule"));
    twoCol.writeDateTimeInput("date", new Date());

    twoCol.render();

    write("<br>");
    writeButton("send", getString("admin:AdHocMessage.Send"));

    writeFormClose();
  }