コード例 #1
0
ファイル: FormEntryModel.cs プロジェクト: amasasi/DotNetRosa
        /// <summary> This method does a recursive check of whether there are any repeat guesses
        /// in the element or its subtree. This is a necessary step when initializing
        /// the model to be able to identify whether new repeats can be used.
        ///
        /// </summary>
        /// <param name="parent">The form element to begin checking
        /// </param>
        /// <returns> true if the element or any of its descendants is a repeat
        /// which has a count guess, false otherwise.
        /// </returns>
        private bool containsRepeatGuesses(IFormElement parent)
        {
            if (parent is GroupDef)
            {
                GroupDef g = (GroupDef)parent;
                if (g.Repeat && g.CountReference != null)
                {
                    return(true);
                }
            }


            if (children == null)
            {
                return(false);
            }
            //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
            for (System.Collections.IEnumerator en = children.elements(); en.MoveNext();)
            {
                //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
                if (containsRepeatGuesses((IFormElement)en.Current))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
        private static void RenderAreaItem(
            HtmlHelper html,
            ContentAreaItem contentAreaItem,
            BootstrapAwareContentAreaRenderer renderer,
            IFormElement element)
        {
            if (contentAreaItem != null)
            {
                var cssClasses = renderer.GetItemCssClass(html, contentAreaItem);
                html.ViewContext.Writer.Write($"<div class=\"{cssClasses}\">");
            }

            var sourceContent = element.SourceContent;

            if (sourceContent != null && !sourceContent.IsDeleted)
            {
                if (sourceContent is ISubmissionAwareElement)
                {
                    var contentData = (sourceContent as IReadOnly).CreateWritableClone() as IContent;
                    (contentData as ISubmissionAwareElement).FormSubmissionId = (string)html.ViewBag.FormSubmissionId;
                    html.RenderContentData(contentData, false);
                }
                else
                {
                    html.RenderContentData(sourceContent, false);
                }
            }

            if (contentAreaItem != null)
            {
                html.ViewContext.Writer.Write("</div>");
            }
        }
コード例 #3
0
ファイル: FormEntryModel.cs プロジェクト: amasasi/DotNetRosa
        /// <summary> Returns a hierarchical list of FormEntryCaption objects for the given
        /// FormIndex
        ///
        /// </summary>
        /// <param name="index">
        /// </param>
        /// <returns> list of FormEntryCaptions in hierarchical order
        /// </returns>
        public virtual FormEntryCaption[] getCaptionHierarchy(FormIndex index)
        {
            List <FormEntryCaption> captions = new List <FormEntryCaption>();
            FormIndex remaining = index;

            while (remaining != null)
            {
                remaining = remaining.NextLevel;
                FormIndex    localIndex = index.diff(remaining);
                IFormElement element    = form.getChild(localIndex);
                if (element != null)
                {
                    FormEntryCaption caption = null;
                    if (element is GroupDef)
                    {
                        caption = new FormEntryCaption(Form, localIndex);
                    }
                    else if (element is QuestionDef)
                    {
                        caption = new FormEntryPrompt(Form, localIndex);
                    }

                    if (caption != null)
                    {
                        captions.addElement(caption);
                    }
                }
            }
            FormEntryCaption[] captionArray = new FormEntryCaption[captions.size()];
            captions.copyInto(captionArray);
            return(captionArray);
        }
コード例 #4
0
        /**
         * This method does a recursive check of whether there are any repeat guesses
         * in the element or its subtree. This is a necessary step when initializing
         * the model to be able to identify whether new repeats can be used.
         *
         * @param parent The form element to begin checking
         * @return true if the element or any of its descendants is a repeat
         * which has a count guess, false otherwise.
         */
        private Boolean containsRepeatGuesses(IFormElement parent)
        {
            if (parent is GroupDef)
            {
                GroupDef g = (GroupDef)parent;
                if (g.Repeat && g.CountReference != null)
                {
                    return(true);
                }
            }

            List <IFormElement> children = parent.Children;

            if (children == null)
            {
                return(false);
            }
            for (IEnumerator en = children.GetEnumerator(); en.MoveNext();)
            {
                if (containsRepeatGuesses((IFormElement)en.Current))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #5
0
        /**
         * Returns a hierarchical list of FormEntryCaption objects for the given
         * FormIndex
         *
         * @param index
         * @return list of FormEntryCaptions in hierarchical order
         */
        public FormEntryCaption[] getCaptionHierarchy(FormIndex index)
        {
            List <FormEntryCaption> captions = new List <FormEntryCaption>();
            FormIndex remaining = index;

            while (remaining != null)
            {
                remaining = remaining.getNextLevel();
                FormIndex    localIndex = index.diff(remaining);
                IFormElement element    = form.getChild(localIndex);
                if (element != null)
                {
                    FormEntryCaption caption = null;
                    if (element is GroupDef)
                    {
                        caption = new FormEntryCaption(getForm(), localIndex);
                    }
                    else if (element is QuestionDef)
                    {
                        caption = new FormEntryPrompt(getForm(), localIndex);
                    }

                    if (caption != null)
                    {
                        captions.Add(caption);
                    }
                }
            }
            FormEntryCaption[] captionArray = new FormEntryCaption[captions.Count];
            captions.CopyTo(captionArray);
            return(captionArray);
        }
コード例 #6
0
        private void decrementHelper(ArrayList indexes, ArrayList multiplicities, ArrayList elements)
        {
            int i = indexes.Count - 1;

            if (i != -1)
            {
                int curIndex = ((int)indexes[i]);
                int curMult  = ((int)multiplicities[i]);

                if (repeatStructure == REPEAT_STRUCTURE_NON_LINEAR &&
                    elements[elements.Count - 1] is GroupDef && ((GroupDef)elements[elements.Count - 1]).Repeat &&
                    ((int)multiplicities[elements.Count - 1]) != TreeReference.INDEX_REPEAT_JUNCTURE)
                {
                    multiplicities[TreeReference.INDEX_REPEAT_JUNCTURE] = i;
                    return;
                }
                else if (repeatStructure != REPEAT_STRUCTURE_NON_LINEAR && curMult > 0)
                {
                    multiplicities[curMult - 1] = i;
                }
                else if (curIndex > 0)
                {
                    // set node to previous element
                    indexes[curIndex - 1] = i;
                    multiplicities[0]     = i;
                    elements[i]           = (i == 0 ? form : (IFormElement)elements[i - 1]).getChild(curIndex - 1);

                    if (setRepeatNextMultiplicity(elements, multiplicities))
                    {
                        return;
                    }
                }
                else
                {
                    // at absolute beginning of current level; index to parent
                    indexes.RemoveAt(i);
                    multiplicities.RemoveAt(i);
                    elements.RemoveAt(i);
                    return;
                }
            }

            IFormElement element = (i < 0 ? form : (IFormElement)elements[i]);

            while (!(element is QuestionDef))
            {
                int subIndex = element.Children.Count - 1;
                element = element.getChild(subIndex);

                indexes.Add(subIndex);
                multiplicities.Add(0);
                elements.Add(element);

                if (setRepeatNextMultiplicity(elements, multiplicities))
                {
                    return;
                }
            }
        }
コード例 #7
0
 /**
  * Creates a FormEntryCaption for the element at the given index in the form.
  *
  * @param form
  * @param index
  */
 public FormEntryCaption(FormDef form, FormIndex index)
 {
     this.form       = form;
     this.index      = index;
     this.element    = form.getChild(index);
     this.viewWidget = null;
     this.textID     = this.element.TextID;
 }
コード例 #8
0
        public void AddElement(IFormElement formElement)
        {
            AINum aINum = new AINum();
            var   error = formElement.SetValidator(aINum);

            errorlist.Add(error);
            if (error == "")
            {
                elements.Add(formElement);
            }
        }
コード例 #9
0
 public virtual void  formElementStateChanged(IFormElement element, int changeFlags)
 {
     if (this.element != element)
     {
         throw new System.SystemException("Widget received event from foreign question");
     }
     if (viewWidget != null)
     {
         viewWidget.refreshWidget(changeFlags);
     }
 }
コード例 #10
0
 public bool Equals(IFormElement other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (other.GetType() != this.GetType())
     {
         return(false);
     }
     return(Equals((BlockTimeElement)other));
 }
コード例 #11
0
        /**
         * Given a FormIndex, returns the event this FormIndex represents.
         *
         * @see FormEntryController
         */
        public int getEvent(FormIndex index)
        {
            if (index.isBeginningOfFormIndex())
            {
                return(FormEntryController.EVENT_BEGINNING_OF_FORM);
            }
            else if (index.isEndOfFormIndex())
            {
                return(FormEntryController.EVENT_END_OF_FORM);
            }

            // This came from chatterbox, and is unclear how correct it is,
            // commented out for now.
            // DELETEME: If things work fine
            // Vector defs = form.explodeIndex(index);
            // IFormElement last = (defs.size() == 0 ? null : (IFormElement)
            // defs.lastElement());
            IFormElement element = form.getChild(index);

            if (element is GroupDef)
            {
                if (((GroupDef)element).Repeat)
                {
                    if (repeatStructure != REPEAT_STRUCTURE_NON_LINEAR && form.Instance.resolveReference(form.getChildInstanceRef(index)) == null)
                    {
                        return(FormEntryController.EVENT_PROMPT_NEW_REPEAT);
                    }
                    else if (repeatStructure == REPEAT_STRUCTURE_NON_LINEAR && index.getElementMultiplicity() == TreeReference.INDEX_REPEAT_JUNCTURE)
                    {
                        return(FormEntryController.EVENT_REPEAT_JUNCTURE);
                    }
                    else
                    {
                        return(FormEntryController.EVENT_REPEAT);
                    }
                }
                else
                {
                    return(FormEntryController.EVENT_GROUP);
                }
            }
            else
            {
                return(FormEntryController.EVENT_QUESTION);
            }
        }
コード例 #12
0
        private void RenderForm(List <FormElementItem> formElementItems)
        {
            foreach (var formElementItem in formElementItems)
            {
                if (Attributes.ContainsKey("ElementBackgroundColor"))
                {
                    formElementItem.ElementBackgroundColor = Attributes["ElementBackgroundColor"];
                }

                if (Attributes.ContainsKey("ElementTextColor"))
                {
                    formElementItem.ElementTextColor = Attributes["ElementTextColor"];
                }

                IFormElement formElement = formElementItem.Render();
                formElements.Add(formElement);
                formLayout.Children.Add(formElement.View);
                formElement.PostBack += FormElement_PostBack;
            }
        }
コード例 #13
0
ファイル: FormEntryModel.cs プロジェクト: amasasi/DotNetRosa
 /// <summary> For the current index: Checks whether the index represents a node which
 /// should exist given a non-interactive repeat, along with a count for that
 /// repeat which is beneath the dynamic level specified.
 ///
 /// If this index does represent such a node, the new model for the repeat is
 /// created behind the scenes and the index for the initial question is
 /// returned.
 ///
 /// Note: This method will not prevent the addition of new repeat elements in
 /// the interface, it will merely use the xforms repeat hint to create new
 /// nodes that are assumed to exist
 ///
 /// </summary>
 /// <param name="index">The index to be evaluated as to whether the underlying model is
 /// hinted to exist
 /// </param>
 private void  createModelIfNecessary(FormIndex index)
 {
     if (index.InForm)
     {
         IFormElement e = Form.getChild(index);
         if (e is GroupDef)
         {
             GroupDef g = (GroupDef)e;
             if (g.Repeat && g.CountReference != null)
             {
                 // Lu Gram: repeat count XPath needs to be contextualized for nested repeat groups
                 TreeReference countRef       = FormInstance.unpackReference(g.CountReference);
                 TreeReference contextualized = countRef.contextualize(index.Reference);
                 IAnswerData   count          = Form.MainInstance.resolveReference(contextualized).getValue();
                 if (count != null)
                 {
                     long          fullcount   = ((System.Int32)count.Value);
                     TreeReference ref_Renamed = Form.getChildInstanceRef(index);
                     TreeElement   element     = Form.MainInstance.resolveReference(ref_Renamed);
                     if (element == null)
                     {
                         if (index.getTerminal().InstanceIndex < fullcount)
                         {
                             try
                             {
                                 Form.createNewRepeat(index);
                             }
                             catch (InvalidReferenceException ire)
                             {
                                 SupportClass.WriteStackTrace(ire, Console.Error);
                                 //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                                 throw new System.SystemException("Invalid Reference while creting new repeat!" + ire.Message);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #14
0
 /**
  * For the current index: Checks whether the index represents a node which
  * should exist given a non-interactive repeat, along with a count for that
  * repeat which is beneath the dynamic level specified.
  *
  * If this index does represent such a node, the new model for the repeat is
  * created behind the scenes and the index for the initial question is
  * returned.
  *
  * Note: This method will not prevent the addition of new repeat elements in
  * the interface, it will merely use the xforms repeat hint to create new
  * nodes that are assumed to exist
  *
  * @param The index to be evaluated as to whether the underlying model is
  *        hinted to exist
  */
 private void createModelIfNecessary(FormIndex index)
 {
     if (index.isInForm())
     {
         IFormElement e = getForm().getChild(index);
         if (e is GroupDef)
         {
             GroupDef g = (GroupDef)e;
             if (g.Repeat && g.CountReference != null)
             {
                 IAnswerData count = getForm().Instance.getDataValue(g.CountReference);
                 if (count != null)
                 {
                     long          fullcount = ((int)count.Value);
                     TreeReference ref_      = getForm().getChildInstanceRef(index);
                     TreeElement   element   = getForm().Instance.resolveReference(ref_);
                     if (element == null)
                     {
                         if (index.getInstanceIndex() < fullcount)
                         {
                             try
                             {
                                 getForm().createNewRepeat(index);
                             }
                             catch (InvalidReferenceException ire)
                             {
                                 Console.WriteLine(ire.StackTrace);
                                 throw new SystemException("Invalid Reference while creting new repeat!" + ire.Message);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #15
0
 static string GetValue(IFormElement elt) =>
 elt is HtmlInputElement input && input.Type == "checkbox" ? input.Checked ? "true" : "false"
コード例 #16
0
 public void AddElement(IFormElement element)
 {
     this.elements.Add(element);
 }
コード例 #17
0
ファイル: FormEntryModel.cs プロジェクト: amasasi/DotNetRosa
        private void  decrementHelper(System.Collections.ArrayList indexes, System.Collections.ArrayList multiplicities, System.Collections.ArrayList elements)
        {
            int i = indexes.Count - 1;

            if (i != -1)
            {
                int curIndex = ((System.Int32)indexes[i]);
                int curMult  = ((System.Int32)multiplicities[i]);

                if (repeatStructure == REPEAT_STRUCTURE_NON_LINEAR && elements[elements.Count - 1] is GroupDef && ((GroupDef)elements[elements.Count - 1]).Repeat && ((System.Int32)multiplicities[multiplicities.Count - 1]) != TreeReference.INDEX_REPEAT_JUNCTURE)
                {
                    multiplicities[i] = (System.Int32)TreeReference.INDEX_REPEAT_JUNCTURE;
                    return;
                }
                else if (repeatStructure != REPEAT_STRUCTURE_NON_LINEAR && curMult > 0)
                {
                    multiplicities[i] = (System.Int32)(curMult - 1);
                }
                else if (curIndex > 0)
                {
                    // set node to previous element
                    indexes[i]        = (System.Int32)(curIndex - 1);
                    multiplicities[i] = 0;
                    elements[i]       = (i == 0?form:(IFormElement)elements[i - 1]).getChild(curIndex - 1);

                    if (setRepeatNextMultiplicity(elements, multiplicities))
                    {
                        return;
                    }
                }
                else
                {
                    // at absolute beginning of current level; index to parent
                    indexes.RemoveAt(i);
                    multiplicities.RemoveAt(i);
                    elements.RemoveAt(i);
                    return;
                }
            }

            IFormElement element = (i < 0?form:(IFormElement)elements[i]);

            while (!(element is QuestionDef))
            {
                if (element.getChildren() == null || element.getChildren().size() == 0)
                {
                    //if there are no children we just return the current index (the group itself)
                    return;
                }
                int subIndex = element.getChildren().size() - 1;
                element = element.getChild(subIndex);

                indexes.Add((System.Int32)subIndex);
                multiplicities.Add(0);
                elements.Add(element);

                if (setRepeatNextMultiplicity(elements, multiplicities))
                {
                    return;
                }
            }
        }
コード例 #18
0
 public void AddElement(IFormElement el)
 {
     elements.Add(el);
 }
コード例 #19
0
 protected override void OnParametersSet()
 {
     base.OnParametersSet();
     _formElement = Elements.FirstOrDefault(e => e.Name == ElementName);
 }
コード例 #20
0
        private void incrementHelper(ArrayList indexes, ArrayList multiplicities, ArrayList elements, Boolean descend)
        {
            int     i          = indexes.Count - 1;
            Boolean exitRepeat = false; //if exiting a repetition? (i.e., go to next repetition instead of one level up)

            if (i == -1 || elements[i] is GroupDef)
            {
                // current index is group or repeat or the top-level form

                if (i >= 0)
                {
                    // find out whether we're on a repeat, and if so, whether the
                    // specified instance actually exists
                    GroupDef group = (GroupDef)elements[i];
                    if (group.Repeat)
                    {
                        if (repeatStructure == REPEAT_STRUCTURE_NON_LINEAR)
                        {
                            if (((System.Int32)multiplicities[multiplicities.Count - 1]) == TreeReference.INDEX_REPEAT_JUNCTURE)
                            {
                                descend    = false;
                                exitRepeat = true;
                            }
                        }
                        else
                        {
                            if (form.Instance.resolveReference(form.getChildInstanceRef(elements, multiplicities)) == null)
                            {
                                descend    = false; // repeat instance does not exist; do not descend into it
                                exitRepeat = true;
                            }
                        }
                    }
                }

                if (descend)
                {
                    indexes.Add(0);
                    multiplicities.Add(0);
                    elements.Add((i == -1 ? form : (IFormElement)elements[i]).getChild(0));

                    if (repeatStructure == REPEAT_STRUCTURE_NON_LINEAR)
                    {
                        if (elements[elements.Count - 1] is GroupDef && ((GroupDef)elements[elements.Count - 1]).Repeat)
                        {
                            multiplicities[multiplicities.Count - 1] = (System.Int32)TreeReference.INDEX_REPEAT_JUNCTURE;
                        }
                    }

                    return;
                }
            }

            while (i >= 0)
            {
                // if on repeat, increment to next repeat EXCEPT when we're on a
                // repeat instance that does not exist and was not created
                // (repeat-not-existing can only happen at lowest level; exitRepeat
                // will be true)
                if (!exitRepeat && elements[i] is GroupDef && ((GroupDef)elements[i]).Repeat)
                {
                    if (repeatStructure == REPEAT_STRUCTURE_NON_LINEAR)
                    {
                        multiplicities[i] = (System.Int32)TreeReference.INDEX_REPEAT_JUNCTURE;
                    }
                    else
                    {
                        multiplicities[i] = (System.Int32)(((System.Int32)multiplicities[i]) + 1);
                    }
                    return;
                }

                IFormElement parent   = (i == 0 ? form : (IFormElement)elements[i - 1]);
                int          curIndex = ((System.Int32)indexes[i]);

                // increment to the next element on the current level
                if (curIndex + 1 >= parent.Children.Count)
                {
                    // at the end of the current level; move up one level and start
                    // over
                    indexes.RemoveAt(i);
                    multiplicities.RemoveAt(i);
                    elements.RemoveAt(i);
                    i--;
                    exitRepeat = false;
                }
                else
                {
                    indexes[i]        = (System.Int32)(curIndex + 1);
                    multiplicities[i] = 0;
                    elements[i]       = parent.getChild(curIndex + 1);

                    if (repeatStructure == REPEAT_STRUCTURE_NON_LINEAR)
                    {
                        if (elements[elements.Count - 1] is GroupDef && ((GroupDef)elements[elements.Count - 1]).Repeat)
                        {
                            multiplicities[multiplicities.Count - 1] = (System.Int32)TreeReference.INDEX_REPEAT_JUNCTURE;
                        }
                    }

                    return;
                }
            }
        }
コード例 #21
0
ファイル: GroupDef.cs プロジェクト: amasasi/DotNetRosa
 public virtual void  addChild(IFormElement fe)
 {
     children.Add(fe);
 }
コード例 #22
0
 public virtual void addChild(IFormElement fe)
 {
     throw new System.SystemException("Can't add children to question def");
 }