Search in sources :

Example 11 with ResponseOptionBean

use of org.akaza.openclinica.bean.submit.ResponseOptionBean in project OpenClinica by OpenClinica.

the class FormBeanUtil method getNullValuesListAsOptionBeans.

public List<ResponseOptionBean> getNullValuesListAsOptionBeans(List<NullValue> nullValues) {
    List<ResponseOptionBean> responseOptionBeans = new ArrayList<ResponseOptionBean>();
    if (nullValues == null || nullValues.isEmpty()) {
        return responseOptionBeans;
    }
    ResponseOptionBean respBean;
    String name;
    for (NullValue nullVal : nullValues) {
        name = nullVal.getName();
        respBean = new ResponseOptionBean();
        respBean.setText(name);
        respBean.setValue(name);
        responseOptionBeans.add(respBean);
    }
    return responseOptionBeans;
}
Also used : NullValue(org.akaza.openclinica.bean.core.NullValue) ArrayList(java.util.ArrayList) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean)

Example 12 with ResponseOptionBean

use of org.akaza.openclinica.bean.submit.ResponseOptionBean in project OpenClinica by OpenClinica.

the class DataEntryInputGenerator method createRadioButtonTag.

/*
     * This method generates a radio button field for a cell inside an HTML
     * table. The options parameter contains ResponseOptionBeans, which provides
     * the "checked" value for the tag, as well as its accompanying text. Like
     * the other methods, the user passes in a reference to the Element object,
     * and the object receives new attributes and content. Then the method
     * returns the altered Element object.
     */
public Element createRadioButtonTag(Element tdCell, Integer itemId, List options, Integer tabNumber, boolean includeLabel, String dbValue, String defaultValue, boolean isHorizontal, boolean hasSavedData) {
    Element element;
    // For keeping track of whether a radio is the first of a group
    boolean isFirstInGroup;
    // so that the input elements will have unique IDs
    if (itemId == 0) {
        Random rand = new Random();
        itemId = rand.nextInt(10000) + 1;
    }
    int count = 0;
    // Do not use the default value if there is a valid database value
    boolean hasData = dbValue != null && dbValue.length() > 0;
    for (Object responseOptBean : options) {
        ++count;
        isFirstInGroup = count == 1;
        element = this.initializeInputElement("radio", itemId, tabNumber);
        String value = ((ResponseOptionBean) responseOptBean).getValue();
        String forDefVal = ((ResponseOptionBean) responseOptBean).getText();
        element.setAttribute("value", value);
        // It's checked if its value equals the DB value
        if (dbValue != null && dbValue.length() > 0 && value.equalsIgnoreCase(dbValue)) {
            element.setAttribute("checked", "checked");
        }
        if (!hasSavedData && defaultValue != null && (forDefVal.equalsIgnoreCase(defaultValue) || value.equalsIgnoreCase(defaultValue))) {
            element.setAttribute("checked", "checked");
        }
        // dealing with IE/repetition model library bug
        if (isHorizontal) {
            element.setAttribute("onclick", "if(detectIEWindows(navigator.userAgent)){this.checked=true; unCheckSiblings(this,'horizontal');}");
        } else {
            element.setAttribute("onclick", "if(detectIEWindows(navigator.userAgent)){this.checked=true; unCheckSiblings(this,'vertical');}");
        }
        // is first in a group of radio buttons
        if (!isHorizontal && isFirstInGroup) {
            tdCell.addContent(new Element("br"));
        }
        tdCell.addContent(element);
        tdCell.addContent(" ");
        if (includeLabel) {
            tdCell.addContent(((ResponseOptionBean) responseOptBean).getText());
        // tdCell.addContent(new Element("br"));
        }
        // <br> tag
        if (!isHorizontal) {
            tdCell.addContent(new Element("br"));
        }
    }
    return tdCell;
}
Also used : Random(java.util.Random) Element(org.jdom.Element) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean)

Example 13 with ResponseOptionBean

use of org.akaza.openclinica.bean.submit.ResponseOptionBean in project OpenClinica by OpenClinica.

the class DataEntryInputGenerator method createSingleSelectTag.

// YW 08-14-2007
/**
     * <p>
     * Combine default_value with options of single-selected response type.
     * <p>
     * If there is default_value, by default,
     * <ul>
     * <li>if default_value matches one of options, this option will be
     * selected.
     * <li>otherwise, the default_value will be listed at the top of options
     * </ul>
     * <p>
     * If there is no default_value, no modification to options required.<br/>
     * BWP added parameter databaseValue 09/13/2007
     */
public Element createSingleSelectTag(Element tdCell, Integer itemId, List options, Integer tabNumber, String defaultValue, String databaseValue, boolean hasSavedData) {
    if (databaseValue != null && databaseValue.length() > 0) {
        tdCell = createSingleSelectTag(tdCell, itemId, options, tabNumber);
        Element select = tdCell.getChild("select");
        if (select != null) {
            List<Element> optElements = select.getChildren("option");
            String optVal = "";
            for (Element opts : optElements) {
                optVal = opts.getAttribute("value").getValue();
                if (opts.getAttribute("selected") != null) {
                    opts.removeAttribute("selected");
                }
                if (optVal.equalsIgnoreCase(databaseValue)) {
                    opts.setAttribute("selected", "selected");
                }
            }
        }
        return tdCell;
    }
    int selectedOption = -1;
    boolean foundMatch = false;
    boolean printDefault = false;
    // check if an option has been selected
    for (int i = 0; i < options.size(); ++i) {
        ResponseOptionBean option = (ResponseOptionBean) options.get(i);
        if (option.isSelected()) {
            selectedOption = i;
            break;
        }
    }
    // handle default_value
    if (defaultValue.length() > 0 && !hasSavedData) {
        printDefault = true;
        for (int i = 0; i < options.size(); ++i) {
            ResponseOptionBean option = (ResponseOptionBean) options.get(i);
            if (defaultValue.equalsIgnoreCase(option.getText()) || defaultValue.equalsIgnoreCase(option.getValue())) {
                if (selectedOption == -1) {
                    selectedOption = i;
                }
                printDefault = false;
                foundMatch = true;
                break;
            }
        }
    }
    // modify options
    List<ResponseOptionBean> op = new ArrayList<ResponseOptionBean>();
    if (!foundMatch) {
        if (printDefault) {
            ResponseOptionBean ro = new ResponseOptionBean();
            ro.setText(defaultValue);
            ro.setValue("");
            op.add(ro);
            op.addAll(options);
        }
    } else {
        ((ResponseOptionBean) options.get(selectedOption)).setSelected(true);
    }
    if (op.size() > 0) {
        tdCell = createSingleSelectTag(tdCell, itemId, op, tabNumber);
    } else {
        tdCell = createSingleSelectTag(tdCell, itemId, options, tabNumber);
    }
    return tdCell;
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean)

Example 14 with ResponseOptionBean

use of org.akaza.openclinica.bean.submit.ResponseOptionBean in project OpenClinica by OpenClinica.

the class Select1Widget method getUserControl.

@Override
public UserControl getUserControl() {
    Select1 select1 = new Select1();
    Label label = new Label();
    label.setLabel(itemFormMetadataBean.getLeftItemText());
    select1.setLabel(label);
    // Hint hint = new Hint();
    // hint.setHint(item.getItemMeta().getLeftItemText());
    // select1.setHint(hint);
    select1.setRef("/" + version.getOid() + "/" + itemGroupBean.getOid() + "/" + item.getOid());
    select1.setAppearance(appearance);
    ArrayList<Item> itemList = new ArrayList<Item>();
    select1.setItem(itemList);
    ArrayList<ResponseOptionBean> options = itemFormMetadataBean.getResponseSet().getOptions();
    for (ResponseOptionBean option : options) {
        Item item = new Item();
        Label itemLabel = new Label();
        itemLabel.setLabel(option.getText());
        item.setValue(option.getValue());
        item.setLabel(itemLabel);
        itemList.add(item);
    }
    return select1;
}
Also used : Item(org.akaza.openclinica.web.pform.dto.Item) Select1(org.akaza.openclinica.web.pform.dto.Select1) Label(org.akaza.openclinica.web.pform.dto.Label) ArrayList(java.util.ArrayList) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean)

Example 15 with ResponseOptionBean

use of org.akaza.openclinica.bean.submit.ResponseOptionBean in project OpenClinica by OpenClinica.

the class SelectWidget method getUserControl.

@Override
public UserControl getUserControl() {
    Select select = new Select();
    Label label = new Label();
    label.setLabel(itemFormMetadataBean.getLeftItemText());
    select.setLabel(label);
    // Hint hint = new Hint();
    // hint.setHint(item.getItemMeta().getLeftItemText());
    // select.setHint(hint);
    select.setRef("/" + version.getOid() + "/" + itemGroupBean.getOid() + "/" + item.getOid());
    select.setAppearance(appearance);
    ArrayList<Item> itemList = new ArrayList<Item>();
    select.setItem(itemList);
    ArrayList<ResponseOptionBean> options = itemFormMetadataBean.getResponseSet().getOptions();
    for (ResponseOptionBean option : options) {
        Item item = new Item();
        Label itemLabel = new Label();
        itemLabel.setLabel(option.getText());
        item.setValue(option.getValue());
        item.setLabel(itemLabel);
        itemList.add(item);
    }
    return select;
}
Also used : Item(org.akaza.openclinica.web.pform.dto.Item) Select(org.akaza.openclinica.web.pform.dto.Select) Label(org.akaza.openclinica.web.pform.dto.Label) ArrayList(java.util.ArrayList) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean)

Aggregations

ResponseOptionBean (org.akaza.openclinica.bean.submit.ResponseOptionBean)31 ArrayList (java.util.ArrayList)20 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)9 Element (org.jdom.Element)8 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)7 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)7 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)7 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)5 HashMap (java.util.HashMap)4 NumberFormat (java.text.NumberFormat)3 Iterator (java.util.Iterator)3 NullValue (org.akaza.openclinica.bean.core.NullValue)3 DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)3 DisplayItemWithGroupBean (org.akaza.openclinica.bean.submit.DisplayItemWithGroupBean)3 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)3 Random (java.util.Random)2 HttpSession (javax.servlet.http.HttpSession)2 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)2 ResponseSetBean (org.akaza.openclinica.bean.submit.ResponseSetBean)2 DiscrepancyNoteDAO (org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO)2