Пример #1
0
        public async Task <View> StartIFormAsync(string form, IDictionary <string, object> inputFieldValues = null, string submitAction = null)
        {
            var formMetadata   = this.GetFormMetadata(form);
            var formParameters = new FormParameter(formMetadata, inputFieldValues);
            var layout         = this.RenderForm(formParameters, submitAction);

            return(layout);
        }
Пример #2
0
        public View GetIForm(FormParameter formParameter, string submitAction = null)
        {
            if (formParameter?.Form == null)
            {
                Toast.MakeText(Application.Context, "You don't have access to this form", ToastLength.Long).Show();
                return(null);
            }
            var layout = this.RenderForm(formParameter, submitAction);

            return(layout);
        }
Пример #3
0
        public void RenderInputs(LinearLayout inputsLayout, FormParameter formParameter, List <FormInputManager> inputsManager)
        {
            var orderedInputs = formParameter.Form.InputFields.OrderBy(a => a.OrderIndex).ToList();

            inputsManager.Clear();

            foreach (var input in orderedInputs)
            {
                if (!input.Hidden)
                {
                    var label = new TextView(Application.Context)
                    {
                        Text             = input.Label.Humanize(LetterCasing.Sentence),
                        LayoutParameters = inputsLayout.MatchParentWrapContent()
                    };

                    this.ManagersCollection.StyleRegister.ApplyStyle("TextView", label);

                    inputsLayout.AddView(label);
                }

                var manager = this.ManagersCollection.InputManagerCollection.GetManager(input.Type);

                var view = manager.GetView(input.CustomProperties, this);
                if (view.LayoutParameters == null)
                {
                    view.LayoutParameters = inputsLayout.MatchParentWrapContent();
                }
                var value = formParameter.Parameters?.SingleOrDefault(a => a.Key.ToLower().Equals(input.Id.ToLower())).Value;
                if (value != null)
                {
                    manager.SetValue(value);
                }
                inputsManager.Add(new FormInputManager(input, manager, view));

                if (input.Hidden)
                {
                    view.Visibility = ViewStates.Gone;
                }
                inputsLayout.AddView(view);
            }
        }
Пример #4
0
        private View RenderForm(FormParameter formParameter, string submitAction)
        {
            var scroll       = new NestedScrollView(Application.Context);
            var linearLayout = new LinearLayout(Application.Context)
            {
                Orientation = Orientation.Vertical
            };

            if (formParameter != null)
            {
                InvokeForm.Response result = null;
                var inputsManager          = new List <FormInputManager>();
                var resultLayout           = new LinearLayout(Application.Context)
                {
                    Orientation      = Orientation.Vertical,
                    LayoutParameters = linearLayout.MatchParentWrapContent()
                };

                if (formParameter.Form.InputFields.Count > 0)
                {
                    var inputsLayout = new LinearLayout(Application.Context)
                    {
                        Orientation = Orientation.Vertical
                    };

                    this.RenderInputs(inputsLayout, formParameter, inputsManager);

                    if (formParameter.Form.InputFields.Count(a => !a.Hidden) > 0)
                    {
                        this.ManagersCollection.StyleRegister.ApplyStyle("FormLayout", inputsLayout);
                        var submitLabel       = "Submit";
                        var submitbuttonlabel = formParameter.Form.CustomProperties?.GetCustomProperty <string>("submitButtonLabel");

                        if (!string.IsNullOrEmpty(submitbuttonlabel))
                        {
                            submitLabel = submitbuttonlabel;
                        }
                        var btn = new Button(Application.Context)
                        {
                            Text             = submitLabel,
                            LayoutParameters = inputsLayout.MatchParentWrapContent()
                        };
                        this.ManagersCollection.StyleRegister.ApplyStyle("Button SubmitButton", btn);
                        inputsLayout.AddView(btn);

                        btn.Click += async(sender, args) =>
                        {
                            try
                            {
                                result = await this.SubmitFormAsync(resultLayout, formParameter.Form, inputsManager);

                                if (submitAction == FormLinkActions.OpenModal && result != null)
                                {
                                    this.FormWrapper.CloseForm();
                                }
                                else
                                {
                                    this.RenderOutput(resultLayout, result, formParameter.Form, inputsManager);
                                }
                            }
                            catch (Exception ex)
                            {
                                Toast.MakeText(Application.Context, ex.Message, ToastLength.Long).Show();
                            }
                        };
                    }
                    linearLayout.AddView(inputsLayout);
                }
                // run on response handled events
                EventsManager.OnFormLoadedEvent(formParameter);

                if (formParameter.Form.PostOnLoad || submitAction == FormLinkActions.Run)
                {
                    try
                    {
                        var taskToRun = Task.Run(() => this.SubmitFormAsync(resultLayout, formParameter.Form, inputsManager,
                                                                            formParameter.Form.PostOnLoadValidation));
                        result = taskToRun.Result;
                    }
                    catch (AggregateException ex)
                    {
                        ex.ThrowInnerException();
                    }

                    if (submitAction == FormLinkActions.Run)
                    {
                        this.FormWrapper.CloseForm();
                        return(null);
                    }
                    this.RenderOutput(resultLayout, result, formParameter.Form, inputsManager);
                }
                this.ManagersCollection.StyleRegister.ApplyStyle("ResultsLayout", resultLayout);

                linearLayout.AddView(resultLayout);
                scroll.AddView(linearLayout, scroll.MatchParentWrapContent());
            }
            return(scroll);
        }