コード例 #1
0
ファイル: FormEntryPrompt.cs プロジェクト: ryanbehr/csrosa
        public void expireDynamicChoices()
        {
            dynamicChoicesPopulated = false;
            ItemsetBinding itemset = getQuestion().getDynamicChoices();

            if (itemset != null)
            {
                itemset.clearChoices();
            }
        }
コード例 #2
0
ファイル: FormEntryPrompt.cs プロジェクト: ryanbehr/csrosa
        public List <SelectChoice> getSelectChoices()
        {
            QuestionDef q = getQuestion();

            ItemsetBinding itemset = q.getDynamicChoices();

            if (itemset != null)
            {
                if (!dynamicChoicesPopulated)
                {
                    form.populateDynamicChoices(itemset, mTreeElement.getRef());
                    dynamicChoicesPopulated = true;
                }
                return(itemset.getChoices());
            }
            else
            { //static choices
                return(q.getChoices());
            }
        }
コード例 #3
0
ファイル: FormEntryPrompt.cs プロジェクト: ryanbehr/csrosa
        //note: code overlap with FormDef.copyItemsetAnswer
        public IAnswerData getAnswerValue()
        {
            QuestionDef q = getQuestion();

            ItemsetBinding itemset = q.getDynamicChoices();

            if (itemset != null)
            {
                if (itemset.valueRef != null)
                {
                    List <SelectChoice> choices           = getSelectChoices();
                    List <String>       preselectedValues = new List <String>();

                    //determine which selections are already present in the answer
                    if (itemset.copyMode)
                    {
                        TreeReference        destRef  = itemset.getDestRef().contextualize(mTreeElement.getRef());
                        List <TreeReference> subNodes = form.Instance.expandReference(destRef);
                        for (int i = 0; i < subNodes.Count; i++)
                        {
                            TreeElement node  = form.Instance.resolveReference(subNodes[i]);
                            String      value = itemset.getRelativeValue().evalReadable(form.Instance, new EvaluationContext(form.exprEvalContext, node.getRef()));
                            preselectedValues.Add(value);
                        }
                    }
                    else
                    {
                        List <Selection> sels = new List <Selection>();
                        IAnswerData      data = mTreeElement.getValue();
                        if (data is SelectMultiData)
                        {
                            sels = (List <Selection>)data.Value;
                        }
                        else if (data is SelectOneData)
                        {
                            sels = new List <Selection>();
                            sels.Add((Selection)data.Value);
                        }
                        for (int i = 0; i < sels.Count; i++)
                        {
                            preselectedValues.Add(sels[i].xmlValue);
                        }
                    }

                    //populate 'selection' with the corresponding choices (matching 'value') from the dynamic choiceset
                    List <Selection> selection = new List <Selection>();
                    for (int i = 0; i < preselectedValues.Count; i++)
                    {
                        String       value  = preselectedValues[i];
                        SelectChoice choice = null;
                        for (int j = 0; j < choices.Count; j++)
                        {
                            SelectChoice ch = choices[j];
                            if (value.Equals(ch.Value))
                            {
                                choice = ch;
                                break;
                            }
                        }

                        selection.Add(choice.selection());
                    }

                    //convert to IAnswerData
                    if (selection.Count == 0)
                    {
                        return(null);
                    }
                    else if (q.ControlType == Constants.CONTROL_SELECT_MULTI)
                    {
                        return(new SelectMultiData(selection));
                    }
                    else if (q.ControlType == Constants.CONTROL_SELECT_ONE)
                    {
                        return(new SelectOneData(selection[0])); //do something if more than one selected?
                    }
                    else
                    {
                        throw new SystemException("can't happen");
                    }
                }
                else
                {
                    return(null); //cannot map up selections without <value>
                }
            }
            else
            { //static choices
                return(mTreeElement.getValue());
            }
        }