public MenuActionFacade(IMenuActionImmutable wrapped, IFrameworkFacade facade, INakedObjectsFramework framework) { Wrapped = wrapped; Name = wrapped.Name; Id = wrapped.Id; var action = framework.MetamodelManager.GetActionSpec(wrapped.Action); Action = new ActionFacade(action, facade, framework, ""); }
private static ElementDescriptor MenuActionAsElementDescriptor(this HtmlHelper html, IMenuActionImmutable menuAction, INakedObject nakedObject, bool isEdit) { IActionSpecImmutable actionIm = menuAction.Action; IActionSpec actionSpec = html.Framework().MetamodelManager.GetActionSpec(actionIm); if (nakedObject == null) { IObjectSpecImmutable objectIm = actionIm.OwnerSpec; //This is the spec for the service if (!objectIm.Service) { throw new Exception("Action is not on a known object or service"); } //TODO: Add method to IServicesManager to get a service by its IObjectSpec (or IObjectSpecImmutable) ITypeSpec objectSpec = html.Framework().MetamodelManager.GetSpecification(objectIm); nakedObject = html.Framework().ServicesManager.GetServices().Single(s => s.Spec == objectSpec); } var actionContext = new ActionContext(false, nakedObject, actionSpec); RouteValueDictionary attributes; string tagType; string value; if (!actionContext.Action.IsVisible(actionContext.Target)) { return(null); } IConsent consent = actionContext.Action.IsUsable(actionContext.Target); if (consent.IsVetoed) { tagType = html.GetVetoedAction(actionContext, consent, out value, out attributes); } else if (isEdit) { tagType = html.GetActionAsButton(actionContext, out value, out attributes); } else { tagType = html.GetActionAsForm(actionContext, html.Framework().GetObjectTypeName(actionContext.Target.Object), new { id = html.Framework().GetObjectId(actionContext.Target) }, out value, out attributes); } return(new ElementDescriptor { TagType = tagType, Value = value, Attributes = attributes }); }