Example #1
0
  public void addListGroups(String groupID, List form, int errorFlag, Collection owningCollection)
      throws WingException, SQLException {

    if (isAdvancedFormEnabled) {
      // currently set group
      form.addLabel(T_groups);
      Select groupSelect = form.addItem().addSelect("group_id");
      groupSelect.setMultiple(false);

      java.util.List<Group> loadedGroups = null;

      // retrieve groups
      String name = ConfigurationManager.getProperty("webui.submission.restrictstep.groups");
      if (name != null) {
        Group uiGroup = groupService.findByName(context, name);
        if (uiGroup != null) loadedGroups = uiGroup.getMemberGroups();
      }
      if (loadedGroups == null || loadedGroups.size() == 0) {
        loadedGroups = groupService.findAll(context, GroupService.NAME);
      }

      // if no group selected for default set anonymous
      if (groupID == null || groupID.equals("")) groupID = "0";
      // when we're just loading the main step, also default to anonymous
      if (errorFlag == AccessStep.STATUS_COMPLETE) {
        groupID = "0";
      }
      for (Group group : loadedGroups) {
        boolean selectGroup = group.getID().toString().equals(groupID);
        groupSelect.addOption(selectGroup, group.getID().toString(), group.getName());
      }

      if (errorFlag == AccessStep.STATUS_DUPLICATED_POLICY
          || errorFlag == AccessStep.EDIT_POLICY_STATUS_DUPLICATED_POLICY
          || errorFlag == UploadWithEmbargoStep.STATUS_EDIT_POLICIES_DUPLICATED_POLICY
          || errorFlag == UploadWithEmbargoStep.STATUS_EDIT_POLICY_DUPLICATED_POLICY) {
        groupSelect.addError(T_error_duplicated_policy);
      }
    }
  }
  public void addBody(Body body)
      throws SAXException, WingException, UIException, SQLException, IOException,
          AuthorizeException {
    Request request = ObjectModelHelper.getRequest(objectModel);
    boolean help = false, error = false;
    if (request.getParameter("help") != null) {
      help = true;
    }
    if (request.getParameter("error") != null) {
      error = true;
    }

    Division div = body.addInteractiveDivision("test", "", "post", "primary");
    div.setHead("Inline form test");
    div.addPara(
        "There are two options you can use to control how this page is generated. First is the help parameter, if this is present then help text will be provided for all fields. Next is the error parameter, if it is provided then all fields will be generated in error conditions.");

    if (help) {
      div.addPara().addXref(makeURL(false, error), "Turn help OFF");
    } else {
      div.addPara().addXref(makeURL(true, error), "Turn help ON");
    }

    if (error) {
      div.addPara().addXref(makeURL(help, false), "Turn errors OFF");
    } else {
      div.addPara().addXref(makeURL(help, true), "Turn errors ON");
    }

    Division suited = body.addDivision("suited");
    suited.setHead("Fields suited towards being used inline");

    suited.addPara(
        "Below are a list of embedded fields that are normally considered usefully in an inline context.");

    // Text field
    Para p = suited.addPara();
    p.addContent("This is a plain 'Text' field, ");
    Text text = p.addText("text");
    text.setLabel("Text");
    if (help) {
      text.setHelp("This is helpfull text.");
    }
    if (error) {
      text.addError("This field is in error.");
    }
    text.setValue("Current raw value");
    p.addContent(", embedded in a paragraph.");

    // Single Checkbox field
    p = suited.addPara();
    p.addContent("This is a singe 'CheckBox' field, ");
    CheckBox checkBox = p.addCheckBox("yes-or-no");
    if (help) {
      checkBox.setHelp("Select either yes or no.");
    }
    if (error) {
      checkBox.addError("You are incorrect, try again.");
    }
    checkBox.setLabel("Yes or no");
    checkBox.addOption("yes");
    p.addContent(", embedded in a paragraph.");

    // File
    p = suited.addPara();
    p.addContent("This is a 'File' field, ");
    File file = p.addFile("file");
    file.setLabel("File");
    if (help) {
      file.setHelp("Upload a file.");
    }
    if (error) {
      file.addError("This field is in error.");
    }
    p.addContent(", embedded in a paragraph.");

    // Select (single)
    p = suited.addPara();
    p.addContent("This is single 'Select' (aka dropdown) field, ");
    Select select = p.addSelect("select");
    select.setLabel("Select (single)");
    if (help) {
      select.setHelp("Select one of the options");
    }
    if (error) {
      select.addError("This field is in error.");
    }
    select.addOption("one", "uno");
    select.addOption("two", "dos");
    select.addOption("three", "tres");
    select.addOption("four", "cuatro");
    select.addOption("five", "cinco");
    select.setOptionSelected("one");
    p.addContent(", embedded in a paragraph.");

    // Button
    p = suited.addPara();
    p.addContent("This is a 'Button' field, ");
    Button button = p.addButton("button");
    button.setLabel("Button");
    button.setValue("When you touch me I do things, lots of things");
    if (help) {
      button.setHelp("Submit buttons allow the user to submit the form.");
    }
    if (error) {
      button.addError("This button is in error.");
    }
    p.addContent(", embedded in a paragraph.");

    Division unsuited = body.addDivision("unsuited");
    unsuited.setHead("Fields typicaly unsuited towards being used inline");

    unsuited.addPara(
        "Below are a list of embedded fields that are normally considered useless in an inline context. This is because there widgets normally cross multiple lines making them hard to render inline. However these are all legal, but perhaps not advisable, and in some circumstances may be needed.");

    // Text Area Field
    p = unsuited.addPara();
    p.addContent("This is a 'Text Area' field, ");
    TextArea textArea = p.addTextArea("textarea");
    textArea.setLabel("Text Area");
    if (help) {
      textArea.setHelp("This is helpfull text.");
    }
    if (error) {
      textArea.addError("This field is in error.");
    }
    textArea.setValue("This is the raw value");
    p.addContent(", embedded in a paragraph.");

    // Multi-option Checkbox field
    p = unsuited.addPara();
    p.addContent("This is a multi-option 'CheckBox' field, ");
    checkBox = p.addCheckBox("fruit");
    if (help) {
      checkBox.setHelp("Select all the fruits that you like to eat");
    }
    if (error) {
      checkBox.addError("You are incorrect you actualy do like Tootse Rolls.");
    }
    checkBox.setLabel("fruits");
    checkBox.addOption("apple", "Apples");
    checkBox.addOption(true, "orange", "Oranges");
    checkBox.addOption("pear", "Pears");
    checkBox.addOption("tootsie", "Tootsie Roll");
    checkBox.addOption(true, "cherry", "Cherry");
    p.addContent(", embedded in a paragraph.");

    // multi-option Radio field
    p = unsuited.addPara();
    p.addContent("This is a multi-option 'Radio' field, ");
    Radio radio = p.addRadio("sex");
    radio.setLabel("Football colors");
    if (help) {
      radio.setHelp("Select the colors of the best (college) football team.");
    }
    if (error) {
      radio.addError("Error, Maroon & White is the only acceptable answer.");
    }
    radio.addOption("ut", "Burnt Orange & White");
    radio.addOption(true, "tamu", "Maroon & White");
    radio.addOption("ttu", "Tech Red & Black");
    radio.addOption("baylor", "Green & Gold");
    radio.addOption("rice", "Blue & Gray");
    radio.addOption("uh", "Scarlet Red & Albino White");
    p.addContent(", embedded in a paragraph.");

    // Select (multiple)
    p = unsuited.addPara();
    p.addContent("This is multiple 'Select' field, ");
    select = p.addSelect("multi-select");
    select.setLabel("Select (multiple)");
    select.setMultiple();
    select.setSize(4);
    if (help) {
      select.setHelp("Select one or more options");
    }
    if (error) {
      select.addError("This field is in error.");
    }
    select.addOption("one", "uno");
    select.addOption("two", "dos");
    select.addOption("three", "tres");
    select.addOption("four", "cuatro");
    select.addOption("five", "cinco");
    select.setOptionSelected("one");
    select.setOptionSelected("three");
    select.setOptionSelected("five");
    p.addContent(", embedded in a paragraph.");

    // Composite
    p = unsuited.addPara();
    p.addContent("This is a 'Composite' field of two text fields, ");
    Composite composite = p.addComposite("composite-2text");
    composite.setLabel("Composite (two text fields)");
    if (help) {
      composite.setHelp("I am the help for the entire composite");
    }
    if (error) {
      composite.addError("Just the composite is in error");
    }
    text = composite.addText("partA");
    text.setLabel("Part A");
    text.setValue("Value for part A");
    if (help) {
      text.setHelp("Part A");
    }
    text = composite.addText("partB");
    text.setLabel("Part B");
    text.setValue("Value for part B");
    if (help) {
      text.setHelp("Part B");
    }
    p.addContent(", embedded in a paragraph.");
  }