コード例 #1
0
        public void CreateFormWithHeaderAndFooter(Guid formId, string formName, string formTitle, string formSuccessMessage, IList <Control> formHeaderControls, IList <Control> formBodyControls, IList <Control> formFooterControls)
        {
            FormsManager formManager = FormsManager.GetManager();
            var          form        = formManager.GetForms().SingleOrDefault(f => f.Id == formId);

            if (form == null)
            {
                form                = formManager.CreateForm(formName, formId);
                form.Framework      = FormFramework.Mvc;
                form.Title          = formTitle;
                form.UrlName        = Regex.Replace(form.Name.ToLower(), ArrangementConstants.UrlNameCharsToReplace, ArrangementConstants.UrlNameReplaceString);
                form.SuccessMessage = formSuccessMessage;

                var culture = System.Globalization.CultureInfo.CurrentUICulture;
                var draft   = formManager.EditForm(form.Id);
                var master  = formManager.Lifecycle.CheckOut(draft, culture);

                if (master != null)
                {
                    this.AppendFormControlsToPlaceholder(formName, formBodyControls, formManager, master, "Body");
                    this.AppendFormControlsToPlaceholder(formName, formHeaderControls, formManager, master, "Header");
                    this.AppendFormControlsToPlaceholder(formName, formFooterControls, formManager, master, "Footer");

                    master = formManager.Lifecycle.CheckIn(master, culture);
                    formManager.Lifecycle.Publish(master, culture);

                    formManager.SaveChanges(true);
                }
            }
        }
コード例 #2
0
        public void CreateForm(Guid formId, string formName, string formTitle, string formSuccessMessage, IList <Control> formControls, bool publishForm = true)
        {
            FormsManager formManager = FormsManager.GetManager();
            var          form        = formManager.GetForms().SingleOrDefault(f => f.Id == formId);
            Guid         siblingId   = Guid.Empty;

            if (form == null)
            {
                form = formManager.CreateForm(formName, formId);

                form.Framework      = FormFramework.Mvc;
                form.Title          = formTitle;
                form.UrlName        = Regex.Replace(form.Name.ToLower(), ArrangementConstants.UrlNameCharsToReplace, ArrangementConstants.UrlNameReplaceString);
                form.SuccessMessage = formSuccessMessage;

                var culture = SystemManager.CurrentContext.AppSettings.DefaultFrontendLanguage;
                var draft   = formManager.EditForm(form.Id);
                var master  = formManager.Lifecycle.CheckOut(draft, culture);

                if (master != null)
                {
                    if (formControls != null && formControls.Any())
                    {
                        int controlsCounter = 0;
                        foreach (var control in formControls)
                        {
                            controlsCounter++;
                            control.ID = string.Format(CultureInfo.InvariantCulture, formName + "_C" + controlsCounter.ToString(CultureInfo.InvariantCulture).PadLeft(3, '0'));
                            var formControl = formManager.CreateControl <FormDraftControl>(control, "Body");

                            // Default value of BackwardCompatible does not translate ControllerName property which leads to unability to create forms in ML
                            formControl.GetType().GetProperty("Strategy", BindingFlags.Public | BindingFlags.Instance).SetValue(formControl, PropertyPersistenceStrategy.NotTranslatable);

                            formControl.SetPersistanceStrategy();
                            formControl.SiblingId = siblingId;
                            formControl.Caption   = ObjectFactory.Resolve <IControlBehaviorResolver>().GetBehaviorObject(control).GetType().Name;
                            siblingId             = formControl.Id;
                            master.Controls.Add(formControl);
                            formControl.SetPersistanceStrategy();
                        }
                    }

                    master = formManager.Lifecycle.CheckIn(master, culture);

                    if (publishForm)
                    {
                        formManager.Lifecycle.Publish(master, culture);
                    }

                    formManager.SaveChanges(true);
                }
            }
        }
コード例 #3
0
        private FormDescription Duplicate(FormDescription formDescription, string formName, FormsManager manager)
        {
            var duplicateForm  = manager.CreateForm(formName);
            var thisFormMaster = manager.Lifecycle.GetMaster(formDescription);

            // Form has been unpublished
            if (thisFormMaster == null)
            {
                this.CopyFormCommonData(formDescription, duplicateForm, manager);

                // Get permissions from ParentForm, because FormDraft is no ISecuredObject
                duplicateForm.CopySecurityFrom((ISecuredObject)formDescription, null, null);
            }
            else
            {
                this.CopyFormCommonData(thisFormMaster, duplicateForm, manager);

                // Get permissions from ParentForm, because FormDraft is no ISecuredObject
                duplicateForm.CopySecurityFrom((ISecuredObject)thisFormMaster.ParentForm, null, null);
            }

            return(duplicateForm);
        }