Exemplo n.º 1
0
  // Submit button on Completion Variables pop-up
  protected void submit(Map<String, String> map, boolean assign) {
    String varString = "", outcomeString = "";
    if (map.get("Choose") != null) {
      outcomeString = "?outcome=" + map.get("Choose");
    } else if (map.get("mustChoose") != null) {
      SC.say("Please choose one of the available options before submitting.");
      return;
    }
    for (int i = 0; i < 5; i++) {
      String key = map.get("key" + i), value = map.get("value" + i);
      if (key != null && !key.equals("Note Name")) {
        // key = BpmServiceMain.xmlEncode(key);
        if (value == null || value == "Note or URL") {
          SC.say("The name for note #" + (i + 1) + " is filled in, but there is no value");
          return;
        }
        // value = BpmServiceMain.xmlEncode(value);
        varString += "&var=" + BpmServiceMain.urlEncode(key + ":" + value);
      } else if ((key == null || key.equals("Note Name"))
          && (value != null && !value.equals("Note or URL"))) {
        SC.say("The value for note #" + (i + 1) + " is filled in, but there is no name");
        return;
      }
    }
    if (outcomeString.equals("")) varString = varString.replaceFirst("&", "?");
    final String tempString = map.get("taskID") + outcomeString + varString;
    if (assign) {
      submitItem.disable();
      BpmServiceMain.sendPostNoLocation(
          "/tasks/active/" + map.get("taskID") + "?assignee=" + BpmServiceMain.getUser(),
          new AsyncCallback<Void>() {
            public void onFailure(Throwable arg0) {
              SC.say(
                  "Error. Please ensure that you are connected to the Internet, that the server is currently online, and that the task was not already assigned.");
              submitItem.enable();
            }

            public void onSuccess(Void arg0) {
              BpmServiceMain.sendDelete(
                  "/tasks/active/" + tempString,
                  true,
                  new AsyncCallback<Void>() {
                    public void onFailure(Throwable arg0) {
                      SC.say(
                          "Error. Please ensure that you are connected to the Internet, that the server is currently online, and that the task was not already completed.");
                      confirm.destroy();
                      updateTasks();
                    }

                    public void onSuccess(Void arg0) {
                      confirm.destroy();
                      updateTasks();
                    }
                  });
            }
          });
    } else {
      BpmServiceMain.sendDelete(
          "/tasks/active/" + tempString,
          true,
          new AsyncCallback<Void>() {
            public void onFailure(Throwable arg0) {
              SC.say(
                  "Error. Please ensure that you are connected to the Internet, that the server is currently online, and that the task was not already completed.");
            }

            public void onSuccess(Void arg0) {
              confirm.destroy();
              updateTasks();
            }
          });
    }
  }