Files
Orchard/src/Orchard.Web/Modules/Orchard.Roles/Forms/SelectRolesForms.cs
Sebastien Ros abac56cf58 #19987: Decoupling worfklows from other modules
Work Item: 19987
2013-08-16 17:23:41 -07:00

51 lines
1.6 KiB
C#

using System;
using System.Linq;
using System.Web.Mvc;
using Orchard.DisplayManagement;
using Orchard.Forms.Services;
using Orchard.Localization;
using Orchard.Roles.Services;
namespace Orchard.Roles.Forms {
public class SelectRolesForms : IFormProvider {
private readonly IRoleService _roleService;
protected dynamic Shape { get; set; }
public Localizer T { get; set; }
public SelectRolesForms(
IShapeFactory shapeFactory,
IRoleService roleService) {
_roleService = roleService;
Shape = shapeFactory;
T = NullLocalizer.Instance;
}
public void Describe(DescribeContext context) {
Func<IShapeFactory, dynamic> form =
shape => {
var f = Shape.Form(
Id: "AnyOfRoles",
_Parts: Shape.SelectList(
Id: "role", Name: "Roles",
Title: T("Roles"),
Description: T("Select some roles."),
Size: 10,
Multiple: true
)
);
f._Parts.Add(new SelectListItem { Value = "", Text = T("Any").Text });
foreach (var role in _roleService.GetRoles().OrderBy(x => x.Name)) {
f._Parts.Add(new SelectListItem { Value = role.Name, Text = role.Name });
}
return f;
};
context.Form("SelectRoles", form);
}
}
}