Adding drop down list to select the blog for BLogArchiveWidget

--HG--
branch : dev
extra : transplant_source : %3AAU%C1%80%07%8E72%83%5B%E4Yj%A0%DF._%91%80
This commit is contained in:
Sebastien Ros
2011-01-27 15:16:15 -08:00
parent 3c00aa7813
commit fc261cdb3a
4 changed files with 40 additions and 7 deletions

View File

@@ -1,5 +1,7 @@
using Orchard.Blogs.Models;
using System.Linq;
using Orchard.Blogs.Models;
using Orchard.Blogs.Services;
using Orchard.Blogs.ViewModels;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
@@ -28,12 +30,21 @@ namespace Orchard.Blogs.Drivers {
}
protected override DriverResult Editor(BlogArchivesPart part, dynamic shapeHelper) {
var viewModel = new BlogArchivesViewModel {
Slug = part.ForBlog,
Blogs = _blogService.Get().ToList().OrderBy(b => b.Name)
};
return ContentShape("Parts_Blogs_BlogArchives_Edit",
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Blogs.BlogArchives", Model: part, Prefix: Prefix));
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Blogs.BlogArchives", Model: viewModel, Prefix: Prefix));
}
protected override DriverResult Editor(BlogArchivesPart part, IUpdateModel updater, dynamic shapeHelper) {
updater.TryUpdateModel(part, Prefix, null, null);
var viewModel = new BlogArchivesViewModel();
if (updater.TryUpdateModel(viewModel, Prefix, null, null)) {
part.ForBlog = viewModel.Slug;
}
return Editor(part, shapeHelper);
}
}

View File

@@ -96,6 +96,7 @@
<Compile Include="Services\IBlogPostService.cs" />
<Compile Include="Services\IBlogService.cs" />
<Compile Include="Services\XmlRpcHandler.cs" />
<Compile Include="ViewModels\BlogArchivesViewModel.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Content\Admin\images\draft.gif" />

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.Blogs.Models;
namespace Orchard.Blogs.ViewModels {
public class BlogArchivesViewModel {
public string Slug { get; set; }
public IEnumerable<BlogPart> Blogs { get; set; }
}
}

View File

@@ -1,8 +1,17 @@
@model Orchard.Blogs.Models.BlogArchivesPart
@model Orchard.Blogs.ViewModels.BlogArchivesViewModel
@using Orchard.Blogs.Models;
@using Orchard.Core.Routable.Models;
@using Orchard.ContentManagement;
<fieldset>
<div>
@Html.LabelFor(m => m.ForBlog, T("For Blog"))
@Html.TextBoxFor(m => m.ForBlog)
<span class="hint">@T("Show the archives for which blog? Note: specify the blog's slug.")</span>
@Html.LabelFor(m => m.Slug, T("For Blog"))
<select id="@Html.FieldIdFor(m => m.Slug)" name="@Html.FieldNameFor(m => m.Slug)">
@foreach(BlogPart blog in Model.Blogs) {
@Html.SelectOption(Model.Slug, blog.As<RoutePart>().Slug, blog.Name)
}
</select>
<span class="hint">@T("Select which blog you want to display the archives for")</span>
</div>
</fieldset>