예제 #1
0
        public async Task <IActionResult> Display(string alias)
        {
            if (String.IsNullOrWhiteSpace(alias))
            {
                await Index();
            }

            var contentItemId = await _contentAliasManager.GetContentItemIdAsync("slug:AdvancedForms/" + alias);

            var contentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.Published);

            if (contentItem == null)
            {
                return(NotFound());
            }

            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ViewContent, contentItem))
            {
                return(Unauthorized());
            }

            var model = new AdvancedFormViewModel
            {
                Id           = contentItemId,
                Title        = contentItem.Content.AdvancedForm.Title,
                Container    = contentItem.Content.AdvancedForm.Container.Html,
                Description  = contentItem.Content.AdvancedForm.Description.Html,
                Instructions = contentItem.Content.AdvancedForm.Instructions.Html
            };

            return(View(model));
        }
예제 #2
0
        public async Task <FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, TemplateContext ctx)
        {
            var latest = arguments["latest"].ToBooleanValue();
            var mode   = arguments["mode"].Or(arguments.At(0));

            if (mode.IsNil() || mode.ToStringValue() == "id")
            {
                var contentItemId = input.ToStringValue();
                var contentItem   = await _contentManager.GetAsync(contentItemId, latest?VersionOptions.Latest : VersionOptions.Published);

                return(FluidValue.Create(contentItem));
            }
            if (mode.ToStringValue() == "alias")
            {
                var contentItemId = await _contentAliasManager.GetContentItemIdAsync(input.ToStringValue());

                if (contentItemId != null)
                {
                    var contentItem = await _contentManager.GetAsync(contentItemId, latest?VersionOptions.Latest : VersionOptions.Published);

                    return(FluidValue.Create(contentItem));
                }
            }
            else if (mode.ToStringValue() == "version")
            {
                var contentItemVersionId = input.ToStringValue();
                var contentItem          = await _contentManager.GetVersionAsync(contentItemVersionId);

                return(FluidValue.Create(contentItem));
            }

            return(FluidValue.Create(null));
        }
예제 #3
0
        public async Task <AdvancedFormViewModel> ReturnView(string alias, string id, EntryType entryType)
        {
            var contentItemId = await _contentAliasManager.GetContentItemIdAsync("slug:AdvancedForms/" + alias);

            var contentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.Published);

            var subContentItem = await _contentManager.GetAsync(id, VersionOptions.Published);

            if (subContentItem == null)
            {
                subContentItem = await _contentManager.GetAsync(id, VersionOptions.DraftRequired);
            }

            var selectedContent = await _contentManager.GetAsync(subContentItem.Content.AdvancedFormSubmissions.Status.Text.ToString(), VersionOptions.Published);

            if (selectedContent == null)
            {
                selectedContent = await _contentManager.GetAsync(subContentItem.Content.AdvancedFormSubmissions.Status.Text.ToString(), VersionOptions.DraftRequired);
            }
            string statusText = string.Empty;

            if (selectedContent != null)
            {
                statusText = selectedContent.DisplayText;
            }
            return(new AdvancedFormViewModel
            {
                Id = contentItem.ContentItemId,
                Owner = subContentItem.Owner,
                Title = contentItem.DisplayText,
                Type = contentItem.Content.AdvancedForm.Type.Text,
                Group = contentItem.Content.AdvancedForm.Group.Text,
                Header = contentItem.Content.AdvancedForm.Header.Html,
                Footer = contentItem.Content.AdvancedForm.Footer.Html,
                Container = contentItem.Content.AdvancedForm.Container.Html != null?JsonConvert.SerializeObject(contentItem.Content.AdvancedForm.Container.Html) : String.Empty,
                                FormFields = contentItem.Content.AdvancedForm.FormFields != null && contentItem.Content.AdvancedForm.FormFields.Html != null?JsonConvert.SerializeObject(contentItem.Content.AdvancedForm.FormFields.Html) : String.Empty,
                                                 AdminContainer = contentItem.Content.AdvancedForm.AdminContainer.Html != null?JsonConvert.SerializeObject(contentItem.Content.AdvancedForm.AdminContainer.Html) : String.Empty,
                                                                      Description = contentItem.Content.AdvancedForm.Description.Html,
                                                                      Instructions = contentItem.Content.AdvancedForm.Instructions.Html,
                                                                      SubmissionId = subContentItem.ContentItemId,
                                                                      AdvancedFormId = contentItem.ContentItemId,
                                                                      Submission = subContentItem.Content.AdvancedFormSubmissions.Submission.Html != null?JsonConvert.SerializeObject(subContentItem.Content.AdvancedFormSubmissions.Submission.Html) : String.Empty,
                                                                                       AdminSubmission = subContentItem.Content.AdvancedFormSubmissions.AdminSubmission.Html != null?JsonConvert.SerializeObject(subContentItem.Content.AdvancedFormSubmissions.AdminSubmission.Html) : String.Empty,
                                                                                                             EntryType = entryType,
                                                                                                             Status = subContentItem.Content.AdvancedFormSubmissions.Status.Text,
                                                                                                             StatusText = statusText,
                                                                                                             PublicEditor = new HTMLFieldViewModel()
                {
                    ID = "PublicComment"
                },
                HideFromListing = contentItem.Content.AdvancedForm.HideFromListing.Value,
                IsGlobalHeader = contentItem.Content.AdvancedForm.IsGlobalHeader.Value,
                IsGlobalFooter = contentItem.Content.AdvancedForm.IsGlobalFooter.Value
            });
        }
예제 #4
0
        public async Task <IActionResult> Display(string alias)
        {
            if (String.IsNullOrWhiteSpace(alias))
            {
                return(Redirect("/"));
            }

            var contentItemId = await _contentAliasManager.GetContentItemIdAsync("slug:AdvancedForms/" + alias);

            var contentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.Published);

            if (contentItem == null)
            {
                return(NotFound());
            }

            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ViewContent, contentItem))
            {
                return(Unauthorized());
            }

            var model = new AdvancedFormViewModel
            {
                Id        = contentItemId,
                Title     = contentItem.DisplayText,
                Type      = contentItem.Content.AdvancedForm.Type.Text,
                Group     = contentItem.Content.AdvancedForm.Group.Text,
                Container = contentItem.Content.AdvancedForm.Container.Html != null?JsonConvert.SerializeObject(contentItem.Content.AdvancedForm.Container.Html) : String.Empty,
                                FormFields = contentItem.Content.AdvancedForm.FormFields != null && contentItem.Content.AdvancedForm.FormFields.Html != null?JsonConvert.SerializeObject(contentItem.Content.AdvancedForm.FormFields.Html) : String.Empty,
                                                 Description     = contentItem.Content.AdvancedForm.Description.Html,
                                                 Instructions    = contentItem.Content.AdvancedForm.Instructions.Html,
                                                 Header          = contentItem.Content.AdvancedForm.Header.Html,
                                                 AdvancedFormId  = contentItemId,
                                                 Footer          = contentItem.Content.AdvancedForm.Footer.Html,
                                                 CaseID          = "",
                                                 HideFromListing = contentItem.Content.AdvancedForm.HideFromListing.Value,
                                                 IsGlobalHeader  = contentItem.Content.AdvancedForm.IsGlobalHeader.Value,
                                                 IsGlobalFooter  = contentItem.Content.AdvancedForm.IsGlobalFooter.Value,
            };

            return(View(model));
        }
예제 #5
0
        public async Task <IActionResult> Render()
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageTemplates))
            {
                return(this.ChallengeOrForbid());
            }

            // Mark request as a `Preview` request so that drivers / handlers or underlying services can be aware of an active preview mode.
            HttpContext.Features.Set(new ContentPreviewFeature());

            var name    = Request.Form["Name"];
            var content = Request.Form["Content"];

            if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(content))
            {
                HttpContext.Items["OrchardCore.PreviewTemplate"] = new TemplateViewModel {
                    Name = name, Content = content
                };
            }

            var alias = Request.Form["Alias"].ToString();

            string contentItemId;

            if (string.IsNullOrEmpty(alias) || alias == _homeUrl)
            {
                var homeRoute = (await _siteService.GetSiteSettingsAsync()).HomeRoute;
                contentItemId = homeRoute["contentItemId"]?.ToString();
            }
            else
            {
                var index = alias.IndexOf(_homeUrl, StringComparison.Ordinal);
                alias         = (index < 0) ? alias : alias.Substring(_homeUrl.Length);
                contentItemId = await _contentAliasManager.GetContentItemIdAsync("slug:" + alias);
            }

            if (string.IsNullOrEmpty(contentItemId))
            {
                return(NotFound());
            }

            var contentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.Published);

            if (contentItem == null)
            {
                return(NotFound());
            }

            var model = await _contentItemDisplayManager.BuildDisplayAsync(contentItem, _updateModelAccessor.ModelUpdater, "Detail");

            return(View(model));
        }
예제 #6
0
        private async Task <FluidValue> GetContentByAlias(string alias, bool latest = false)
        {
            var contentItemId = await _contentAliasManager.GetContentItemIdAsync(alias);

            if (contentItemId == null)
            {
                return(NilValue.Instance);
            }

            var contentItem = await _contentManager.GetAsync(contentItemId, latest?VersionOptions.Latest : VersionOptions.Published);

            return(FluidValue.Create(contentItem));
        }
예제 #7
0
        public async Task <IActionResult> Render()
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageTemplates))
            {
                return(Unauthorized());
            }

            var name    = Request.Form["Name"];
            var content = Request.Form["Content"];

            if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(content))
            {
                HttpContext.Items["OrchardCore.PreviewTemplate"] = new TemplateViewModel {
                    Name = name, Content = content
                };
            }

            var alias = Request.Form["Alias"].ToString();

            string contentItemId = string.Empty;

            if (string.IsNullOrEmpty(alias) || alias == _homeUrl)
            {
                var homeRoute = (await _siteService.GetSiteSettingsAsync()).HomeRoute;
                contentItemId = homeRoute["contentItemId"]?.ToString();
            }
            else
            {
                var index = alias.IndexOf(_homeUrl);
                alias         = (index < 0) ? alias : alias.Substring(_homeUrl.Length);
                contentItemId = await _contentAliasManager.GetContentItemIdAsync("slug:" + alias);
            }

            if (string.IsNullOrEmpty(contentItemId))
            {
                return(NotFound());
            }

            var contentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.Published);

            if (contentItem == null)
            {
                return(NotFound());
            }

            var model = await _contentItemDisplayManager.BuildDisplayAsync(contentItem, this, "Detail");

            return(View(model));
        }
        public async Task <ContentItem> GetByIdOrAliasAsync(string idOrAlias)
        {
            if (string.IsNullOrEmpty(idOrAlias))
            {
                return(null);
            }

            ContentItem contentItem = null;

            if (idOrAlias.Length == Common.IdLength)
            {
                contentItem = await _contentManager.GetAsync(idOrAlias);
            }
            if (contentItem == null)
            {
                var id = await _aliasManager.GetContentItemIdAsync("alias:" + idOrAlias);

                if (id != null)
                {
                    contentItem = await _contentManager.GetAsync(id);
                }
            }
            return(contentItem);
        }
예제 #9
0
        public async Task <IActionResult> Submission(string alias, string id)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdvancedForms))
            {
                return(Unauthorized());
            }

            if (String.IsNullOrWhiteSpace(alias))
            {
                return(Redirect("/"));
            }
            else if (String.IsNullOrWhiteSpace(id))
            {
                return(NotFound());
            }

            var contentItemId = await _contentAliasManager.GetContentItemIdAsync("slug:AdvancedForms/" + alias);

            var contentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.Published);

            var subContentItem = await _contentManager.GetAsync(id, VersionOptions.Published);

            if (subContentItem == null)
            {
                subContentItem = await _contentManager.GetAsync(id, VersionOptions.Draft);
            }

            if (subContentItem == null)
            {
                return(NotFound());
            }

            var selectedContent = await _contentManager.GetAsync(subContentItem.Content.AdvancedFormSubmissions.Status.Text.ToString(), VersionOptions.Published);

            if (selectedContent == null)
            {
                selectedContent = await _contentManager.GetAsync(subContentItem.Content.AdvancedFormSubmissions.Status.Text.ToString(), VersionOptions.DraftRequired);
            }

            List <ContentPickerItemViewModel> lst = new List <ContentPickerItemViewModel>();

            if (selectedContent != null)
            {
                ContentPickerItemViewModel contentPick = new ContentPickerItemViewModel();
                contentPick.ContentItemId = selectedContent.ContentItemId;
                contentPick.DisplayText   = selectedContent.DisplayText;
                contentPick.HasPublished  = selectedContent.Published;
                //contentPick.HideFromListing = selectedContent.Content.AdvancedFormTypes.HideFromListing.Value;
                lst.Add(contentPick);
            }

            List <RolesViewModel> roles = new List <RolesViewModel>();
            string        groups        = contentItem.Content.AdvancedForm.Group.Text;
            List <string> lstGroups     = groups.Split(",").ToList();

            foreach (var item in lstGroups)
            {
                roles.Add(new RolesViewModel()
                {
                    Name = item
                });
            }

            var model = new AdvancedFormViewModel
            {
                Id             = contentItem.ContentItemId,
                AdvancedFormId = contentItem.ContentItemId,
                Owner          = contentItem.Owner,
                ModifiedUtc    = subContentItem.ModifiedUtc,
                CreatedUtc     = subContentItem.CreatedUtc,
                Title          = contentItem.DisplayText,
                Type           = contentItem.Content.AdvancedForm.Type.Text,
                Group          = contentItem.Content.AdvancedForm.Group.Text,
                Header         = contentItem.Content.AdvancedForm.Header.Html,
                Footer         = contentItem.Content.AdvancedForm.Footer.Html,
                Container      = contentItem.Content.AdvancedForm.Container.Html != null?JsonConvert.SerializeObject(contentItem.Content.AdvancedForm.Container.Html) : String.Empty,
                                     AdminContainer = contentItem.Content.AdvancedForm.AdminContainer.Html != null?JsonConvert.SerializeObject(contentItem.Content.AdvancedForm.AdminContainer.Html) : String.Empty,
                                                          Description     = contentItem.Content.AdvancedForm.Description.Html,
                                                          Instructions    = contentItem.Content.AdvancedForm.Instructions.Html,
                                                          HideFromListing = contentItem.Content.AdvancedForm.HideFromListing.Value,
                                                          IsGlobalHeader  = contentItem.Content.AdvancedForm.IsGlobalHeader.Value,
                                                          IsGlobalFooter  = contentItem.Content.AdvancedForm.IsGlobalFooter.Value,
                                                          SubmissionId    = subContentItem.ContentItemId,
                                                          Submission      = subContentItem.Content.AdvancedFormSubmissions.Submission.Html != null?JsonConvert.SerializeObject(subContentItem.Content.AdvancedFormSubmissions.Submission.Html) : String.Empty,
                                                                                AdminSubmission = subContentItem.Content.AdvancedFormSubmissions.AdminSubmission.Html != null?JsonConvert.SerializeObject(subContentItem.Content.AdvancedFormSubmissions.AdminSubmission.Html) : String.Empty,
                                                                                                      Metadata = subContentItem.Content.AdvancedFormSubmissions.Metadata.Html != null?JsonConvert.SerializeObject(subContentItem.Content.AdvancedFormSubmissions.Metadata.Html) : String.Empty,
                                                                                                                     FormFields = contentItem.Content.AdvancedForm.FormFields != null?JsonConvert.SerializeObject(contentItem.Content.AdvancedForm.FormFields.Html) : String.Empty,
                                                                                                                                      Status         = subContentItem.Content.AdvancedFormSubmissions.Status.Text,
                                                                                                                                      SelectedItems  = lst,
                                                                                                                                      SelectedGroups = roles,
                                                                                                                                      AdminEditor    = new HTMLFieldViewModel()
                {
                    ID = "AdminComment"
                },
                PublicEditor = new HTMLFieldViewModel()
                {
                    ID = "PublicComment"
                },
                ApplicationLocation = subContentItem.Content.AdvancedFormSubmissions.ApplicationLocation.Text
            };

            return(View("Submission", model));
        }