コード例 #1
0
ファイル: MyFormHandler.cs プロジェクト: UNOPS/uimf-ios
        public Layout StartIForm(string form, IDictionary <string, object> inputFieldValues = null, string submitAction = null)
        {
            var formMetadata   = this.GetFormMetadataAsync(form);
            var formParameters = new FormParameter(formMetadata, inputFieldValues);
            var layout         = this.RenderFormAsync(formParameters, submitAction);

            return(layout);
        }
コード例 #2
0
ファイル: MyFormHandler.cs プロジェクト: UNOPS/uimf-ios
        public void RenderInputs(UIScrollView layout, FormParameter formParameters, List <FormInputManager> inputsManager)
        {
            var orderedInputs = formParameters.Form.InputFields.OrderBy(a => a.OrderIndex).ToList();

            inputsManager.Clear();

            var size  = new CGSize(UIScreen.MainScreen.Bounds.Width - 40, 45);
            var frame = layout.Frame;

            foreach (var input in orderedInputs)
            {
                if (!input.Hidden)
                {
                    var label = new UITextView {
                        Text = input.Label
                    };

                    var labelSize = new CGSize(UIScreen.MainScreen.Bounds.Width - 40, 30);
                    label.Frame = new CGRect(new CGPoint(20, this.YAxis), labelSize);

                    //layout.InsertSubviewBelow(label, _parentViewController.View);

                    layout.AddSubview(label);
                    this.YAxis += 35;
                }

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

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

                view.Hidden = input.Hidden;
                if (!input.Hidden)
                {
                    frame.Height      += 35 + view.Frame.Height;
                    layout.ContentSize = frame.Size;
                    view.Frame         = new CGRect(new CGPoint(20, this.YAxis), size);
                }
                layout.AddSubview(view);
                this.YAxis += (int)view.Frame.Height + 10;
            }
        }
コード例 #3
0
ファイル: MyFormHandler.cs プロジェクト: UNOPS/uimf-ios
 public Layout GetIFormAsync(FormParameter formParameter, string submitAction = null)
 {
     if (formParameter.Form == null)
     {
         this.ShowToast("You don't have access to this form");
         return(null);
     }
     try
     {
         var layout = this.RenderFormAsync(formParameter, submitAction);
         return(layout);
     }
     catch (Exception ex)
     {
         this.ShowToast(ex.Message);
         return(null);
     }
 }
コード例 #4
0
ファイル: MyFormHandler.cs プロジェクト: UNOPS/uimf-ios
        private Layout RenderFormAsync(FormParameter formParameters, string submitAction = null)
        {
            this.YAxis = 10;
            var scrollView = new UIScrollView {
                BackgroundColor = UIColor.White
            };
            var frame = scrollView.Frame;

            if (formParameters.Form != null)
            {
                InvokeForm.Response result = null;
                var resultLayout           = new UIView();
                resultLayout.AddSubview(new UIView());
                var inputsManager = new List <FormInputManager>();
                if (formParameters.Form.InputFields.Count > 0)
                {
                    this.RenderInputs(scrollView, formParameters, inputsManager);
                    frame.Height          += this.YAxis + 20;
                    scrollView.ContentSize = frame.Size;

                    if (formParameters.Form.InputFields.Count(a => !a.Hidden) > 0)
                    {
                        var submitLabel       = "Submit";
                        var submitbuttonlabel = formParameters.Form.CustomProperties?.GetCustomProperty <string>("submitButtonLabel");

                        if (!string.IsNullOrEmpty(submitbuttonlabel))
                        {
                            submitLabel = submitbuttonlabel;
                        }
                        var btn = new UIButton();
                        btn.SetTitle(submitLabel, UIControlState.Normal);
                        var btnSize = new CGSize(UIScreen.MainScreen.Bounds.Width - 40, 40);
                        btn.Frame           = new CGRect(new CGPoint(20, this.YAxis), btnSize);
                        btn.BackgroundColor = UIColor.Gray;
                        this.YAxis         += 45;
                        btn.TouchUpInside  += async(sender, args) =>
                        {
                            result = await this.SubmitFormAsync(resultLayout, formParameters.Form, inputsManager);

                            if (submitAction == FormLinkActions.OpenModal && result != null)
                            {
                                this.FormWrapper.CloseForm();
                            }
                            else
                            {
                                this.RenderOutput(resultLayout, result, formParameters.Form, inputsManager);
                            }
                        };
                        scrollView.AddSubview(btn);
                    }
                }

                // run on response handled events
                EventsManager.OnFormLoadedEvent(formParameters);

                if (formParameters.Form.PostOnLoad || submitAction == FormLinkActions.Run)
                {
                    try
                    {
                        result = this.SubmitForm(resultLayout, formParameters.Form, inputsManager,
                                                 formParameters.Form.PostOnLoadValidation);
                    }
                    catch (AggregateException ex)
                    {
                        ex.ThrowInnerException();
                    }

                    if (submitAction == FormLinkActions.Run)
                    {
                        this.FormWrapper.CloseForm();
                        return(null);
                    }
                    this.RenderOutput(resultLayout, result, formParameters.Form, inputsManager);
                }

                resultLayout.UserInteractionEnabled = true;
                var resSize = new CGSize(UIScreen.MainScreen.Bounds.Width, this.ResultYAxis + 10);
                resultLayout.Frame = new CGRect(new CGPoint(0, this.YAxis), resSize);
                scrollView.AddSubview(resultLayout);

                frame.Height          += resultLayout.Frame.Height;
                scrollView.ContentSize = frame.Size;
            }
            return(new Layout(scrollView, null));
        }