コード例 #1
0
        /// <summary>
        /// Retrieves form for creating or updating master page zone elements that will be created on form submission.
        /// </summary>
        /// <param name="context">Form context.</param>
        /// <returns>Form object.</returns>
        private Form GetMasterPageZoneElementNewForm(string context)
        {
            // Construct form data, consisting of master page zone element form action button labels
            MasterPageZoneElementFormData formData = new MasterPageZoneElementFormData { Labels = new Dictionary<string, string>() };
            formData.Labels.Add("update", MasterPageResource.UpdateZoneElementNewButtonLabel);
            formData.Labels.Add("create", MasterPageResource.CreateZoneElementNewButtonLabel);

            // Get all elements
            long tenantId = _authenticationService.TenantId;
            IEnumerable<ElementType> elementTypes = _elementService.ListTypes();

            // Construct form
            string data = JsonConvert.SerializeObject(formData);
            Form form = new Form { Fields = new Dictionary<string, IFormField>(), Id = FormId.ToString(), Context = context, Data = data };
            form.Fields.Add("elementType", new SelectListField<string>
            {
                Name = "elementType",
                Label = MasterPageResource.ElementTypeLabel,
                Items = GetElementTypeListFieldItems(elementTypes),
                Required = true,
                RequiredErrorMessage = MasterPageResource.ElementTypeRequiredMessage
            });
            form.Fields.Add("name", new TextField
            {
                Name = "name",
                Label = MasterPageResource.ElementNameLabel,
                Required = true,
                RequiredErrorMessage = MasterPageResource.ElementNameRequiredMessage,
                MaxLength = ElementLengths.NameMaxLength,
                MaxLengthErrorMessage = string.Format(MasterPageResource.ElementNameMaxLengthMessage, "name", ElementLengths.NameMaxLength)
            });
            form.Fields.Add("beginRender", new MultiLineTextField
            {
                Name = "beginRenderZoneElement",
                Label = MasterPageResource.ZoneElementBeginRenderLabel,
                Rows = 4
            });
            form.Fields.Add("endRender", new MultiLineTextField
            {
                Name = "endRenderZoneElement",
                Label = MasterPageResource.ZoneElementEndRenderLabel,
                Rows = 4
            });

            // Return result
            return form;
        }
コード例 #2
0
        public Form GetForm(string context)
        {
            // Check permissions
            _authorizationService.AuthorizeUserForFunction(Functions.UpdatePageElements);

            // Get tenant, page and page zone identifiers
            string[] parts      = context.Split('|');
            long     pageId     = Convert.ToInt64(parts[0]);
            long     pageZoneId = Convert.ToInt64(parts[1]);
            long     tenantId   = _authenticationService.TenantId;

            // Get page and master page zones
            Page           page           = _pageService.Read(tenantId, pageId);
            MasterPage     masterPage     = _masterPageService.Read(tenantId, page.MasterPageId);
            PageZone       pageZone       = page.PageZones.Where(pz => pz.PageZoneId == pageZoneId).First();
            MasterPageZone masterPageZone = masterPage.MasterPageZones.Where(mpz => mpz.MasterPageZoneId == pageZone.MasterPageZoneId).First();

            // Get all element types
            List <IElementSettings>        elements         = new List <IElementSettings>();
            IEnumerable <ElementType>      elementTypes     = _elementService.ListTypes();
            Dictionary <Guid, ElementType> elementTypesById = elementTypes.GroupBy(t => t.ElementTypeId).ToDictionary(t => t.Key, t => t.First());

            // Construct form
            Form form = new Form {
                Fields = new Dictionary <string, IFormField>(), Id = FormId.ToString(), Context = context
            };
            List <ElementType> availableElementTypes = new List <ElementType>();

            foreach (MasterPageZoneElementType masterPageZoneElementType in masterPageZone.MasterPageZoneElementTypes)
            {
                ElementType elementType = elementTypesById[masterPageZoneElementType.ElementTypeId];
                availableElementTypes.Add(elementType);
            }
            form.FieldSets      = GetFieldSets(elementTypesById, pageZone);
            form.NamedFieldSets = GetNamedFieldSets(availableElementTypes);
            form.SubmitLabel    = PageResource.PageZoneAdminButtonLabel;

            // Return result
            return(form);
        }