예제 #1
0
 private static string GetActionSet(ActionContext actionContext, out string value, out RouteValueDictionary attributes) {
     value = WrapInDiv(actionContext.Action.Name, IdHelper.MenuNameLabel).ToString();
     attributes = new RouteValueDictionary(new {
         id = actionContext.GetSubMenuId(),
         @class = IdHelper.SubMenuName
     });
     return "div";
 }
        private static string FinderActions(this HtmlHelper html, ITypeFacade spec, ActionContext actionContext, string propertyName) {
            if (spec.IsCollection) {
                return String.Empty; // We don't want Finder menu rendered on any collection field
            }
            var allActions = new List<ElementDescriptor> {
                RemoveAction(propertyName),
                html.RecentlyViewedAction(spec, actionContext, propertyName)
            };
            allActions.AddRange(html.FinderActionsForField(actionContext, spec, propertyName));

            if (allActions.Any()) {
                return BuildMenuContainer(allActions,
                    IdConstants.MenuContainerName,
                    actionContext.GetFindMenuId(propertyName),
                    MvcUi.Find).ToString();
            }

            return String.Empty;
        }
예제 #3
0
 public ActionContext(ActionContext otherContext)
     : base(otherContext) {
     EmbeddedInObject = otherContext.EmbeddedInObject;
     Action = otherContext.Action;
 }
        internal static string GetActionAsForm(this HtmlHelper html, ActionContext actionContext, string controllerName, object routeValues, out string value, out RouteValueDictionary attributes) {
            const string tagType = "form";

            IEnumerable<ElementDescriptor> concurrencyElements = html.GetConcurrencyElements(actionContext.Target, actionContext.GetConcurrencyActionInputId);

            string elements = concurrencyElements.Aggregate(String.Empty, (s, t) => s + t.BuildElement());

            RouteValueDictionary routeValueDictionary;
            if (actionContext.ParameterValues != null && actionContext.ParameterValues.Any()) {
                // custom values have been set so push the values into view data 
                // fields will be hidden and action will be 'none' so that action goes straight through and doesn't prompt for 
                // parameters 

                foreach (var pc in actionContext.GetParameterContexts(html.Facade())) {
                    if (pc.CustomValue != null) {
                        html.ViewData[html.IdHelper().GetParameterInputId((actionContext.Action), (pc.Parameter))] = pc.CustomValue.Specification.IsParseable ? pc.CustomValue.GetDomainObject() : pc.CustomValue;
                    }
                }

                List<ElementDescriptor> paramElements = html.ActionParameterFields(actionContext).ToList();
                elements = paramElements.Aggregate(String.Empty, (s, t) => s + t.BuildElement());
                routeValueDictionary = new RouteValueDictionary();
            } else {
                routeValueDictionary = new RouteValueDictionary(new { action = "action" });
            }

            value = (elements + GetSubmitButton(null, actionContext.Action.Name, IdConstants.ActionInvokeAction, routeValueDictionary)).WrapInDivTag();

            attributes = new RouteValueDictionary(new {
                action = html.GenerateUrl(Action(actionContext.Action.Id), controllerName, new RouteValueDictionary(routeValues)),
                method = "post",
                id = actionContext.GetActionId(),
                @class = actionContext.GetActionClass()
            });
            return tagType;
        }
        private static ElementDescriptor GetActionDialog(this HtmlHelper html,
                                                         ActionContext targetActionContext,
                                                         ActionContext actionContext,
                                                         IList<ElementDescriptor> paramElements,
                                                         string propertyName) {
            if (!paramElements.Any()) {
                return null;
            }

            var nameTag = new TagBuilder("div");
            nameTag.AddCssClass(IdConstants.ActionNameLabel);
            nameTag.SetInnerText(targetActionContext.Action.Name);

            TagBuilder parms = ElementDescriptor.BuildElementSet(paramElements);
            parms.AddCssClass(IdConstants.ParamContainerName);

            html.AddAjaxDataUrlsToElementSet(targetActionContext.Target, targetActionContext.Action, parms);

            return new ElementDescriptor {
                TagType = "div",
                Value = nameTag.ToString() + parms + GetSubmitButton(IdConstants.OkButtonClass,
                    MvcUi.OK,
                    IdConstants.InvokeFindAction,
                    html.GetButtonNameValues(targetActionContext, actionContext, null, propertyName)),
                Attributes = new RouteValueDictionary(new {
                    @class = IdConstants.ActionDialogName,
                    id = targetActionContext.GetActionDialogId()
                })
            };
        }
        private static List<ElementDescriptor> GetChildElements(this HtmlHelper html, IEnumerable actionResult, ActionContext targetActionContext, ActionContext actionContext, string propertyName, Func<object, bool> actionResultFilter) {
            List<ElementDescriptor> childElements;

            if (actionResult == null) {
                List<ElementDescriptor> paramElements = html.ActionParameterFields(targetActionContext).ToList();
                childElements = html.GetActionDialog(targetActionContext, actionContext, paramElements, propertyName).InList();
            } else {
                List<object> result = actionResult.Cast<object>().ToList();
                if (result.Count() == 1 && actionResultFilter(result.First())) {
                    childElements = html.GetSubEditObject(targetActionContext, actionContext, result.First(), propertyName).InList();
                } else {
                    childElements = html.SelectionView(actionContext.Target.GetDomainObject(), propertyName, actionResult).InList();
                }
            }
            return childElements;
        }
 internal static string GetDuplicateAction(this HtmlHelper html, ActionContext actionContext, string reason, out string value, out RouteValueDictionary attributes) {
     value = actionContext.Action.Name;
     attributes = new RouteValueDictionary(new {
         id = actionContext.GetActionId(),
         @class = actionContext.GetActionClass(),
         title = reason
     });
     return "div";
 }
        private static RouteValueDictionary GetActionAttributes(this HtmlHelper html,
                                                                string name,
                                                                ActionContext targetActionContext,
                                                                ActionContext actionContext,
                                                                string propertyName) {
            var actionContextAction = actionContext.Action;
            var actionContextTarget = actionContext.Target;
            var targetActionContextTarget = targetActionContext.Target;
            var targetActionContextAction = targetActionContext.Action;

            return new RouteValueDictionary(new {
                @class = targetActionContext.GetActionClass(),
                id = html.IdHelper().GetActionId(propertyName, actionContextAction, actionContextTarget, targetActionContextTarget, targetActionContextAction),
                name,
                type = "submit",
                value = html.GetButtonNameValues(targetActionContext, actionContext, null, propertyName)
            });
        }
        private static ElementDescriptor GetActionInstanceElementDescriptor(this HtmlHelper html,
                                                                            ActionContext targetActionContext,
                                                                            ActionContext actionContext,
                                                                            string propertyName,
                                                                            Tuple<bool, string> disabled = null) {
            if (disabled != null && disabled.Item1) {
                string value;
                RouteValueDictionary attributes;
                string tagType = html.GetDuplicateAction(actionContext, disabled.Item2, out value, out attributes);

                return new ElementDescriptor {
                    TagType = tagType,
                    Value = value,
                    Attributes = attributes
                };
            }

            return new ElementDescriptor {
                TagType = "button",
                Value = targetActionContext.Action.Name,
                Attributes = html.GetActionAttributes(IdConstants.ActionFindAction, targetActionContext, actionContext, propertyName)
            };
        }
        internal static MvcHtmlString BuildParamContainer(this HtmlHelper html, ActionContext actionContext, IEnumerable<ElementDescriptor> elements, string cls, string id) {
            if (actionContext.Action.IsQueryOnly) {
                cls += (" " + IdConstants.QueryOnlyClass);
            } else if (actionContext.Action.IsIdempotent) {
                cls += (" " + IdConstants.IdempotentClass);
            }

            TagBuilder fieldSet = AddClassAndIdToElementSet(elements, cls, id);

            AddAjaxDataUrlsToElementSet(html, actionContext.Target, actionContext.Action, fieldSet);

            var data = new RouteValueDictionary();
            UpdatePagingValues(html, data);

            fieldSet.InnerHtml += GetSubmitButton(IdConstants.OkButtonClass, MvcUi.OK, "None", data);
            return MvcHtmlString.Create(fieldSet.ToString());
        }
        private static string GetButtonNameValues(this HtmlHelper html,
                                                  ActionContext targetActionContext,
                                                  ActionContext actionContext,
                                                  IObjectFacade subEditNakedObject,
                                                  string propertyName) {
            var data = new RouteValueDictionary(new {
                targetActionId = targetActionContext.Action.Id, //e.g.  FindEmployeeByName
                targetObjectId = Encode(html.Facade().OidTranslator.GetOidTranslation(targetActionContext.Target)), //e.g. Expenses.ExpenseEmployees.EmployeeRepository;1;System.Int32;0;False;;0
                contextObjectId = Encode(html.Facade().OidTranslator.GetOidTranslation(actionContext.Target)), //e.g. Expenses.ExpenseClaims.Claim;1;System.Int32;1;False;;0
                contextActionId = actionContext.Action == null ? "" : actionContext.Action.Id, //e.g. Approver
                propertyName
            });

            if (subEditNakedObject != null) {
                data.Add("subEditObjectId", Encode(html.Facade().OidTranslator.GetOidTranslation(subEditNakedObject)));
            }

            UpdatePagingValues(html, data);

            return ToNameValuePairs(data);
        }
 private static ElementDescriptor RecentlyViewedAction(this HtmlHelper html, ITypeFacade spec, ActionContext actionContext, string propertyName) {
     return new ElementDescriptor {
         TagType = "button",
         Value = MvcUi.RecentlyViewed,
         Attributes = new RouteValueDictionary(new {
             title = MvcUi.RecentlyViewed,
             name = IdConstants.FindAction,
             type = "submit",
             @class = actionContext.GetActionClass(),
             value = ToNameValuePairs(new {
                 spec = spec.FullName,
                 contextObjectId = Encode(html.Facade().OidTranslator.GetOidTranslation(actionContext.Target)),
                 contextActionId = actionContext.Action == null ? "" : actionContext.Action.Id,
                 propertyName
             })
         })
     };
 }
예제 #13
0
        private static string FinderActions(this HtmlHelper html, INakedObjectSpecification spec, ActionContext actionContext, string propertyName) {
            if (spec.IsCollection) {
                // no finder menu on collection parameters 
                return string.Empty;
            }

            IEnumerable<ElementDescriptor> actions = GetServices().Select(service => new ElementDescriptor {
                TagType = "div",
                Value = WrapInDiv(service.TitleString(), IdHelper.MenuNameLabel).ToString(),
                Children = html.ObjectActionsThatReturn(service, actionContext, spec, propertyName),
                Attributes = new RouteValueDictionary(new {
                    @class = IdHelper.SubMenuName,
                    id = IdHelper.GetSubMenuId(actionContext.Target, service)
                })
            }).Where(ed => ed.Children.Any());

            List<ElementDescriptor> allActions = RemoveAction(propertyName).InList();
            allActions.Add(RecentlyViewedAction(spec, actionContext, propertyName));
            allActions.AddRange(actions);

            if (allActions.Any()) {
                return BuildMenuContainer(allActions,
                                          IdHelper.MenuContainerName,
                                          actionContext.GetFindMenuId(propertyName),
                                          MvcUi.Find).ToString();
            }

            return string.Empty;
        }
예제 #14
0
        internal static ElementDescriptor ObjectActionAsElementDescriptor(this HtmlHelper html,
                                                                          ActionContext actionContext,
                                                                          object routeValues,
                                                                          bool isEdit,
                                                                          Tuple<bool, string> disabled = null) {
            RouteValueDictionary attributes;
            string tagType;
            string value;

            IConsent consent = actionContext.Action.IsUsable(NakedObjectsContext.Session, actionContext.Target);
            if (consent.IsVetoed) {
                tagType = GetVetoedAction(actionContext, consent, out value, out attributes);
            }
            else if (disabled != null && disabled.Item1) {
                tagType = GetDuplicateAction(actionContext, disabled.Item2, out value, out attributes);
            }
            else if (actionContext.Action is NakedObjectActionSet) {
                tagType = GetActionSet(actionContext, out value, out attributes);
            }
            else if (isEdit) {
                tagType = html.GetActionAsButton(actionContext, out value, out attributes);
            }
            else {
                tagType = html.GetActionAsForm(actionContext, FrameworkHelper.GetObjectTypeName(actionContext.Target.Object), routeValues, out value, out attributes);
            }

            IEnumerable<INakedObjectAction> childActions = FrameworkHelper.GetChildActions(actionContext).ToList();

            return new ElementDescriptor {
                TagType = tagType,
                Value = value,
                Attributes = attributes,
                Children = childActions.
                    Select(subaction => html.ObjectActionAsElementDescriptor(new ActionContext(false, actionContext.Target, subaction),
                                                                             new {id = FrameworkHelper.GetObjectId(actionContext.Target)},
                                                                             isEdit,
                                                                             IsDuplicate(childActions, subaction))).
                    WrapInCollection("div", new {@class = IdHelper.SubMenuItemsName})
            };
        }
 internal static IEnumerable<ElementDescriptor> EditObjectFields(this HtmlHelper html, object contextObject, ActionContext targetActionContext, string propertyName, IEnumerable actionResult, bool all) {
     var contextNakedObject = html.Facade().GetObject(contextObject);
     var actionContext = new ActionContext(html.IdHelper(), false, contextNakedObject, null);
     List<ElementDescriptor> childElements = html.GetChildElements(actionResult, targetActionContext, actionContext, propertyName, x => html.Facade().GetObject(x).IsTransient);
     return html.EditObjectFields(contextNakedObject, null, x => all || x.Id == propertyName, null, false, childElements, propertyName);
 }
 private static ElementDescriptor GetActionElementDescriptor(this HtmlHelper html,
                                                             ActionContext targetActionContext,
                                                             ActionContext actionContext,
                                                             ITypeFacade spec,
                                                             string propertyName,
                                                             Tuple<bool, string> disabled = null) {
     return html.GetActionInstanceElementDescriptor(targetActionContext, actionContext, propertyName, disabled);
 }
 internal static IEnumerable<ElementDescriptor> ActionParameterFields(this HtmlHelper html, ActionContext actionContext, ActionContext targetActionContext, string propertyName, IEnumerable actionResult) {
     List<ElementDescriptor> childElements = html.GetChildElements(actionResult, targetActionContext, actionContext, propertyName, x => (html.Facade().GetObject(x).IsTransient && !html.Facade().GetObject(x).Specification.IsCollection));
     return html.ActionParameterFields(actionContext, childElements, propertyName);
 }
 private static IList<ElementDescriptor> FinderActionsForField(this HtmlHelper html,
                                                               ActionContext actionContext,
                                                               ITypeFacade fieldSpec,
                                                               string propertyName) {
     var finderActions = fieldSpec.GetFinderActions();
     var descriptors = new List<ElementDescriptor>();
     foreach (var finderAction in finderActions) {
         var serviceSpec = finderAction.OnType;
         var service = html.Facade().GetServices().List.Single(s => s.Specification.Equals(serviceSpec));
         var targetActionContext = new ActionContext(html.IdHelper(), service, finderAction);
         if (targetActionContext.Action.IsVisible(actionContext.Target)) {
             var ed = html.GetActionElementDescriptor(targetActionContext, actionContext, fieldSpec, propertyName, html.IsDuplicate(finderActions, finderAction));
             descriptors.Add(ed);
         }
     }
     return descriptors;
 }
 internal static string GetVetoedAction(this HtmlHelper html, ActionContext actionContext, IConsentFacade consent, out string value, out RouteValueDictionary attributes) {
     value = actionContext.Action.Name;
     attributes = new RouteValueDictionary(new {
         id = actionContext.GetActionId(),
         @class = actionContext.GetActionClass(),
         title = consent.Reason
     });
     return "div";
 }
 private static MvcHtmlString ObjectAction(this HtmlHelper html, ActionContext actionContext, bool isEdit) {
     return MvcHtmlString.Create(html.ObjectActionAsElementDescriptor(actionContext, new { id = Encode(html.Facade().OidTranslator.GetOidTranslation(actionContext.Target)) }, isEdit).BuildElement());
 }
        internal static ElementDescriptor ObjectActionAsElementDescriptor(this HtmlHelper html,
                                                                          ActionContext actionContext,
                                                                          object routeValues,
                                                                          bool isEdit,
                                                                          Tuple<bool, string> disabled = null) {
            RouteValueDictionary attributes;
            string tagType;
            string value;

            var consent = actionContext.Action.IsUsable(actionContext.Target);
            if (consent.IsVetoed) {
                tagType = html.GetVetoedAction(actionContext, consent, out value, out attributes);
            } else if (disabled != null && disabled.Item1) {
                tagType = html.GetDuplicateAction(actionContext, disabled.Item2, out value, out attributes);
            } else if (isEdit) {
                tagType = html.GetActionAsButton(actionContext, out value, out attributes);
            } else {
                tagType = html.GetActionAsForm(actionContext, html.Facade().GetObjectTypeShortName(actionContext.Target.GetDomainObject()), routeValues, out value, out attributes);
            }

            return new ElementDescriptor {
                TagType = tagType,
                Value = value,
                Attributes = attributes
            };
        }
 internal static MvcHtmlString ObjectAction(this HtmlHelper html, ActionContext actionContext) {
     return html.ObjectAction(actionContext, false);
 }
        internal static string GetActionAsButton(this HtmlHelper html, ActionContext actionContext, out string value, out RouteValueDictionary attributes) {
            const string tagType = "button";

            value = actionContext.Action.Name;
            attributes = html.GetActionAttributes(IdConstants.ActionInvokeAction, actionContext, new ActionContext(html.IdHelper(), actionContext.Target, null), String.Empty);

            return tagType;
        }
 internal static MvcHtmlString ObjectActionOnTransient(this HtmlHelper html, ActionContext actionContext) {
     return html.ObjectAction(actionContext, true);
 }
        private static ElementDescriptor GetSubEditObject(this HtmlHelper html,
                                                          ActionContext targetActionContext,
                                                          ActionContext actionContext,
                                                          object subEditObject,
                                                          string propertyName) {
            var nakedObject = html.Facade().GetObject(subEditObject);

            Func<IAssociationFacade, bool> filterCollections = x => !x.IsCollection;

            TagBuilder elementSet = AddClassAndIdToElementSet(html.EditObjectFields(nakedObject, null, filterCollections, null, true),
                IdConstants.FieldContainerName,
                html.IdHelper().GetFieldContainerId((nakedObject)));
            html.AddAjaxDataUrlsToElementSet(nakedObject, elementSet);

            return new ElementDescriptor {
                TagType = "div",
                Value = html.Object(html.ObjectTitle(nakedObject.Object).ToString(), IdConstants.ViewAction, nakedObject.GetDomainObject()).ToString()
                        + elementSet
                        + GetSubmitButton(IdConstants.SaveButtonClass,
                            MvcUi.Save,
                            IdConstants.InvokeSaveAction,
                            html.GetButtonNameValues(targetActionContext, actionContext, nakedObject, propertyName)),
                Attributes = new RouteValueDictionary(new {
                    @class = html.ObjectEditClass(nakedObject.GetDomainObject()),
                    id = GetObjectType(nakedObject.GetDomainObject())
                })
            };
        }
        internal static MvcHtmlString ObjectActionAsDialog(this HtmlHelper html, ActionContext actionContext) {
            bool allowed = actionContext.Action.IsUsable(actionContext.Target).IsAllowed;

            if (allowed) {
                return html.WrapInForm(Action(actionContext.Action.Id),
                    html.Facade().GetObjectTypeShortName(actionContext.Target.Object),
                    html.ParameterList(actionContext).ToString(),
                    actionContext.GetActionClass(),
                    new RouteValueDictionary(new { id = Encode(html.Facade().OidTranslator.GetOidTranslation(actionContext.Target)) }));
            }
            return html.ObjectAction(actionContext);
        }
예제 #27
0
        internal static string GetActionId(ActionContext targetActionContext, ActionContext actionContext, string propertyName) {
            string contextActionName = actionContext.Action == null ? "" : actionContext.Action.Id + sep;
            string contextNakedObjectId = actionContext.Target == null || actionContext.Target == targetActionContext.Target ? "" : GetObjectId(actionContext.Target) + sep;
            string propertyId = string.IsNullOrEmpty(propertyName) ? "" : NameUtils.CapitalizeName(propertyName) + sep;

            return contextNakedObjectId + contextActionName + propertyId + GetObjectId(targetActionContext.Target) + sep + targetActionContext.Action.Id;
        }
        internal static IEnumerable<ElementDescriptor> ActionParameterFields(this HtmlHelper html,
                                                                             ActionContext actionContext,
                                                                             IList<ElementDescriptor> childElements = null,
                                                                             string propertyName = null) {
            IEnumerable<ElementDescriptor> concurrencyElements = html.GetConcurrencyElements(actionContext.Target, actionContext.GetConcurrencyActionInputId);
            IEnumerable<ElementDescriptor> collectionFilterElements = html.GetCollectionSelectedElements(actionContext.Target);

            return (from parameterContext in actionContext.GetParameterContexts(html.Facade())
                    let parmValue = html.GetParameter(parameterContext, childElements, propertyName)
                    select new ElementDescriptor {
                        TagType = "div",
                        Label = html.GetLabel(parameterContext),
                        Value = parmValue,
                        Attributes = new RouteValueDictionary(new {
                            id = parameterContext.GetParameterId(),
                            @class = parameterContext.GetParameterClass()
                        })
                    }).Union(concurrencyElements).Union(collectionFilterElements);
        }
        private static ElementDescriptor MenuActionAsElementDescriptor(this HtmlHelper html, IMenuActionFacade menuAction, IObjectFacade nakedObject, bool isEdit) {
            var actionIm = menuAction.Action;
            var actionSpec = actionIm.ReturnType;
            if (nakedObject == null) {
                var serviceIm = actionIm.OnType;

                if (serviceIm == null) {
                    throw new Exception("Action is not on a known service");
                }
                nakedObject = html.Facade().GetServices().List.SingleOrDefault(s => s.Specification.Equals(serviceIm));
            }

            if (nakedObject == null) {
                // service may not be visible 
                return null;
            }

            var actionContext = new ActionContext(html.IdHelper(), false, nakedObject, actionIm);

            RouteValueDictionary attributes;
            string tagType;
            string value;
            if (!actionContext.Action.IsVisible(actionContext.Target)) {
                return null;
            }
            var 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.Facade().GetObjectTypeShortName(actionContext.Target.GetDomainObject()), new {id = html.Facade().OidTranslator.GetOidTranslation(actionContext.Target).Encode()}, out value, out attributes);
            }

            return new ElementDescriptor {
                TagType = tagType,
                Value = value,
                Attributes = attributes
            };
        }
예제 #30
0
 private static string GetVetoedAction(ActionContext actionContext, IConsent consent, out string value, out RouteValueDictionary attributes) {
     value = actionContext.Action.Name;
     attributes = new RouteValueDictionary(new {
         id = actionContext.GetActionId(),
         @class =  actionContext.GetActionClass(), 
         title = consent.Reason
     });
     return "div";
 }