/// <summary>
        ///     Get the object id
        /// </summary>
        public static MvcHtmlString GetObjectId(this HtmlHelper html, object model)
        {
            Debug.Assert(!(model is IObjectFacade), "Cannot get Adapter for Adapter");
            var nakedObject = html.Facade().GetObject(model);

            return(MvcHtmlString.Create(html.Facade().OidTranslator.GetOidTranslation(nakedObject).Encode()));
        }
        /// <summary>
        ///  Display identified property of the domain object in edit fields, with action dialog or collection view
        /// </summary>
        /// <param name="html">Html helper</param>
        /// <param name="contextObject">domain object to be displayed</param>
        /// <param name="targetObject">owning object of targetAction</param>
        /// <param name="targetAction">action to display as dialog - may be null</param>
        /// <param name="propertyName">property to be decorated with action dialog or selection view</param>
        /// <param name="actionResult">collection of objects to display in selection view - may be null</param>
        /// <returns></returns>
        public static MvcHtmlString PropertyListEditWith(this HtmlHelper html, object contextObject, object targetObject, IActionFacade targetAction, string propertyName, IEnumerable actionResult)
        {
            var nakedObject = html.Facade().GetObject(contextObject);
            var target      = html.Facade().GetObject(targetObject);

            return(html.BuildEditContainer(nakedObject,
                                           html.EditObjectFields(contextObject, new ActionContext(html.IdHelper(), true, target, targetAction), propertyName, actionResult, false),
                                           IdConstants.FieldContainerName,
                                           html.IdHelper().GetFieldContainerId(nakedObject)));
        }
Example #3
0
        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
            });
        }
Example #4
0
        public static MvcHtmlString History(this HtmlHelper html, int count, object domainObject = null, bool clearAll = false)
        {
            if (domainObject != null && !(domainObject is FindViewModel))
            {
                string url = html.Object(html.ObjectTitle(domainObject).ToString(), IdConstants.ViewAction, domainObject).ToString();
                html.ViewContext.HttpContext.Session.AddToCache(html.Facade(), domainObject, url, ObjectCache.ObjectFlag.BreadCrumb);
            }

            List <string> urls      = html.ViewContext.HttpContext.Session.AllCachedUrls(ObjectCache.ObjectFlag.BreadCrumb).ToList();
            int           sizeCache = urls.Count();
            int           skip      = sizeCache > count ? sizeCache - count : 0;

            urls = urls.Skip(skip).ToList();

            var tag = new TagBuilder("div");

            tag.AddCssClass(IdConstants.HistoryContainerName);

            foreach (string url in urls)
            {
                tag.InnerHtml += url;
            }

            if (urls.Any())
            {
                tag.InnerHtml += html.ControllerAction(MvcUi.Clear, IdConstants.ClearHistoryAction, IdConstants.HomeName, IdConstants.ClearButtonClass, "", new RouteValueDictionary(new { clearAll }));
            }

            return(MvcHtmlString.Create(tag.ToString()));
        }
Example #5
0
        private static MvcHtmlString ObjectMenu(this HtmlHelper html, object domainObject, bool isEdit)
        {
            var nakedObject = html.Facade().GetObject(domainObject);
            var objectMenu  = nakedObject.Specification.Menu;

            return(html.MenuAsHtml(objectMenu, nakedObject, isEdit, true));
        }
        /// <summary>
        /// Display the identified property on the model parameter
        /// </summary>
        public static MvcHtmlString ObjectPropertyView(this HtmlHelper html, object model, string propertyId)
        {
            var nakedObject = html.Facade().GetObject(model);
            var property    = nakedObject.Specification.Properties.Where(a => a.Id == propertyId).SingleOrDefault(a => a.IsVisible(nakedObject));

            return(property == null?MvcHtmlString.Create("") : html.ObjectPropertyView(new PropertyContext(html.IdHelper(), nakedObject, property, false)));
        }
        /// <summary>
        /// include all the properties of the domain object as hidden fields
        /// </summary>
        public static MvcHtmlString PropertyListEditHidden(this HtmlHelper html, object domainObject)
        {
            var nakedObject = html.Facade().GetObject(domainObject);
            var fields      = html.EditObjectFields(nakedObject, null, x => false, null);

            return(MvcHtmlString.Create(ElementDescriptor.BuildElementSet(fields).ToString()));
        }
        /// <summary>
        /// List all the properties of the domain object with only collections
        /// </summary>
        /// <example>
        /// html.PropertyList(obj)
        /// </example>
        public static MvcHtmlString[] PropertiesListOnlyCollections(this HtmlHelper html, object domainObject)
        {
            var nakedObject = html.Facade().GetObject(domainObject);
            IEnumerable <string> collections = nakedObject.Specification.Properties.Where(p => p.IsCollection && p.IsVisible(nakedObject)).Select(p => p.Id);

            return(collections.Select(c => html.PropertyListWith(domainObject, c)).ToArray());
        }
        public static MvcHtmlString[] Collections(this HtmlHelper html, object domainObject, string defaultTo = IdConstants.ListDisplayFormat)
        {
            var adapter = html.Facade().GetObject(domainObject);
            IEnumerable <IObjectFacade> collections = adapter.Specification.Properties.Where(p => p.IsCollection).Select(a => a.GetValue(adapter));

            return(collections.Select(c => html.Collection(c.ToEnumerable(), null, defaultTo)).ToArray());
        }
        public static string[] CollectionTitles(this HtmlHelper html, object domainObject, string format)
        {
            var adapter     = html.Facade().GetObject(domainObject);
            var collections = adapter.Specification.Properties.Where(obj => obj.Specification.IsCollection && obj.IsVisible(adapter)).Select(a => new { assoc = a, val = a.GetValue(adapter) });

            return(collections.Select(coll => string.Format(format, coll.assoc.Name, coll.val.TitleString)).ToArray());
        }
        /// <summary>
        ///     Indicate if object has any visible fields
        /// </summary>
        public static bool ObjectHasVisibleFields(this HtmlHelper html, object domainObject)
        {
            var nakedObject = html.Facade().GetObject(domainObject);
            var objectSpec  = nakedObject.Specification;

            return(objectSpec != null && objectSpec.Properties.Any(p => p.IsVisible(nakedObject)));
        }
        /// <summary>
        /// Display all the properties of the domain object in edit fields
        /// </summary>
        public static MvcHtmlString PropertyListEdit(this HtmlHelper html, object domainObject)
        {
            var nakedObject = html.Facade().GetObject(domainObject);

            return(html.BuildEditContainer(nakedObject, html.EditObjectFields(nakedObject, null, x => true, null),
                                           IdConstants.FieldContainerName,
                                           html.IdHelper().GetFieldContainerId(nakedObject)));
        }
        public static MvcHtmlString ActionResult(this HtmlHelper html, ActionResultModel model)
        {
            var    nakedObject = html.Facade().GetObject(model.Result);
            string title       = GetCollectionTitle(nakedObject, html);

            title = model.Action.Name + ": " + (string.IsNullOrWhiteSpace(title) ? nakedObject.Specification.UntitledName : title);
            return(CommonHtmlHelper.WrapInDiv(title, IdConstants.ObjectName));
        }
Example #14
0
        //TODO: Mark obsolete when Menus refactoring complete
        //[Obsolete("Add CustomMenuItems into an IMenu directly when constructing menus")]
        public static MvcHtmlString Service(this HtmlHelper html, object service, params CustomMenuItem[] menuItems)
        {
            var nakedObject = html.Facade().GetObject(service);

            return(CommonHtmlHelper.BuildMenuContainer(html.ObjectActions(nakedObject, false, menuItems),
                                                       IdConstants.MenuContainerName,
                                                       html.IdHelper().GetServiceContainerId(nakedObject),
                                                       nakedObject.TitleString));
        }
        /// <summary>
        ///     Display name of object with icon
        /// </summary>
        public static MvcHtmlString Object(this HtmlHelper html, object model)
        {
            var nakedObject = html.Facade().GetObject(model);

            string title = nakedObject.Specification.IsCollection ? GetCollectionTitle(nakedObject, html) : nakedObject.TitleString;

            title = string.IsNullOrWhiteSpace(title) ? nakedObject.Specification.UntitledName : title;
            return(CommonHtmlHelper.WrapInDiv(html.ObjectIcon(nakedObject) + title, IdConstants.ObjectName));
        }
        /// <summary>
        /// Display ViewData Model as a collection including only columns identified by the includingColumns parameters
        /// </summary>
        /// <example>
        /// html.CollectionTableWithout(obj, "TestCollectionOne", "TestInt")
        /// </example>
        public static MvcHtmlString CollectionListWith(this HtmlHelper html, IEnumerable domainObject, params string[] includingColumns)
        {
            var    nakedObject = html.Facade().GetObject(domainObject);
            string displayType = DefaultFormat(html, IdConstants.ListDisplayFormat);

            return(displayType == IdConstants.TableDisplayFormat ?
                   html.GetStandaloneCollection(nakedObject, x => includingColumns.Any(s => s == x.Id), x => Array.IndexOf(includingColumns, x.Id), true) :
                   html.GetStandaloneList(nakedObject, null));
        }
        /// <summary>
        /// List all the properties of the domain object with only collections
        /// </summary>
        /// <example>
        /// html.PropertyList(obj)
        /// </example>
        public static MvcHtmlString PropertyListOnlyCollections(this HtmlHelper html, object domainObject, CollectionFormat format)
        {
            var nakedObject = html.Facade().GetObject(domainObject);
            IEnumerable <string> collections = nakedObject.Specification.Properties.Where(p => p.IsCollection).Select(p => p.Id);

            collections.ForEach(t => html.ViewData[t] = format);
            Func <IAssociationFacade, bool> f = x => x.IsCollection;

            return(html.PropertyListWithFilter(domainObject, f, null));
        }
Example #18
0
        public static MvcHtmlString ModelWithoutCollection <TModel>(this HtmlHelper helper, TModel model)
        {
            string htmlString   = string.Empty;
            var    objectFacade = helper.Facade().GetObject(model);

            if (objectFacade.Specification.Properties.Any(p => !p.IsCollection))
            {
                htmlString = string.Format("<div class='propertyDisplay'>{0}</div>", RemoveButtonText(helper.PropertyListWithoutCollections(model)));
            }

            return(new MvcHtmlString(htmlString));
        }
Example #19
0
        public static MvcHtmlString ModelCollectionsAsProperties <TModel>(this HtmlHelper helper, TModel model)
        {
            var htmlString = new StringBuilder();

            htmlString.Append("<div class='collectionsAsProperties'>");

            MvcHtmlString[] properties = helper.PropertiesListOnlyCollections(model);

            var objectFacade = helper.Facade().GetObject(model);

            string[] titles = objectFacade.Specification.Properties.Where(p => !p.IsCollection).Select(p => p.Name).ToArray();

            //*************************************************************************
            // Remove any title from titles collection if the corresponding properties
            // do not exist due to the [Hidden] tag.
            //
            // WITEM #55476 - Collections are being displayed under the wrong headings
            //*************************************************************************
            var titlesList = titles.ToList();

            foreach (
                var title in
                titles.Where(
                    title =>
                    !properties.Any(t => t.ToString().Contains("<div class=\"nof-label\">" + title + ":</div>")))
                )
            {
                titlesList.Remove(title);
            }
            titles = titlesList.ToArray();

            //*************************************************************************


            var zip = properties.Zip(titles, (c, t) => new { propString = c, titleString = t });

            //for each collection property create a table for the collection
            foreach (var pt in zip.ToArray())
            {
                htmlString.Append("<div class='collectionDisplay'><fieldset><legend>");
                htmlString.Append(pt.titleString);
                htmlString.Append("</legend>");

                htmlString.Append(RemoveButtonText(pt.propString));
                htmlString.Append("</fieldset></div>");
            }

            htmlString.Append("</div>");

            return(new MvcHtmlString(htmlString.ToString()));
        }
Example #20
0
        /// <summary>
        /// Return to view the last object in the history. If the history is empty return to the home page.
        /// </summary>
        public static MvcHtmlString CancelButton(this HtmlHelper html, object domainObject)
        {
            var fvm = domainObject as FindViewModel;

            if (fvm != null)
            {
                // if dialog return to target - unless it's a service
                object target = fvm.ContextObject;
                domainObject = html.Facade().GetObject(target).Specification.IsService ? null : target;
            }

            // if target is transient  cancel back to history
            if (domainObject != null && html.Facade().GetObject(domainObject).IsTransient)
            {
                domainObject = null;
            }

            string nextUrl = domainObject == null ? "" : html.Tab(html.ObjectTitle(domainObject).ToString(), IdConstants.ViewAction, domainObject).ToString();

            UrlData nextEntry;

            if (string.IsNullOrEmpty(nextUrl))
            {
                List <string> existingUrls    = html.ViewContext.HttpContext.Session.AllCachedUrls(ObjectCache.ObjectFlag.BreadCrumb).ToList();
                var           existingEntries = existingUrls.Select(u => new UrlData(u)).ToArray();
                nextEntry = GetLastEntry(existingEntries);
            }
            else
            {
                nextEntry = new UrlData(nextUrl);
            }

            var cancelForm = new UrlData("");

            cancelForm.AddCancel(html, nextEntry);

            return(MvcHtmlString.Create(cancelForm.ToString()));
        }
Example #21
0
        public static MvcHtmlString MainMenusWithHome(this HtmlHelper html)
        {
            var tag = new TagBuilder("div");

            tag.AddCssClass(IdConstants.ServicesContainerName);

            /***
             * Add Home button to service div
             ***/
            tag.InnerHtml += html.HomeMenuItem();
            var menus = html.Facade().GetMainMenus();

            html.AddMainMenusIntoTag(menus, tag);
            return(MvcHtmlString.Create(tag.ToString()));
        }
Example #22
0
        public static MvcHtmlString TabbedHistory(this HtmlHelper html, int count, object domainObject = null)
        {
            List <string> existingUrls = html.ViewContext.HttpContext.Session.AllCachedUrls(ObjectCache.ObjectFlag.BreadCrumb).ToList();
            string        newUrl       = "";

            if (domainObject != null)
            {
                newUrl = html.Tab(html.ObjectTitle(domainObject).ToString(), IdConstants.ViewAction, domainObject).ToString();
                if (!(domainObject is FindViewModel) && !existingUrls.Contains(newUrl))
                {
                    html.ViewContext.HttpContext.Session.AddOrUpdateInCache(html.Facade(), domainObject, newUrl, ObjectCache.ObjectFlag.BreadCrumb);
                }
            }

            List <string> urls = html.ViewContext.HttpContext.Session.AllCachedUrls(ObjectCache.ObjectFlag.BreadCrumb).ToList();

            int sizeCache = urls.Count();
            int skip      = sizeCache > count ? sizeCache - count : 0;

            urls = urls.Skip(skip).ToList();

            var tag = new TagBuilder("div");

            tag.AddCssClass(IdConstants.TabbedHistoryContainerName);

            UrlData[] entries  = urls.Select(u => new UrlData(u)).ToArray();
            var       newEntry = new UrlData(newUrl);

            foreach (UrlData currentEntry in entries)
            {
                if (currentEntry.Equals(newEntry))
                {
                    currentEntry.SetActive();
                }

                UrlData nextEntry = GetNextEntry(entries, currentEntry);
                currentEntry.AddCloseThis(html, nextEntry);

                if (urls.Count > 1)
                {
                    currentEntry.AddCloseOthers(html);
                }

                currentEntry.AddCloseAll(html);
                tag.InnerHtml += currentEntry.ToString();
            }
            return(MvcHtmlString.Create(tag.ToString()));
        }
        internal static MvcHtmlString CollectionTableInternal(this HtmlHelper html, IEnumerable collection, IActionFacade action = null)
        {
            var nakedObject = html.Facade().GetObject(collection);

            Func <IAssociationFacade, bool> filterFunc;
            Func <IAssociationFacade, int>  orderFunc;
            bool withTitle;

            if (action == null || action.ReturnType.IsVoid)
            {
                // todo investigate other ways to do this
                action = nakedObject.MementoAction;
            }

            CommonHtmlHelper.GetTableColumnInfo(action, out filterFunc, out orderFunc, out withTitle);

            return(html.GetStandaloneCollection(nakedObject, filterFunc, orderFunc, withTitle));
        }
Example #24
0
        /// <summary>
        /// Create main menus for all menus in ViewData
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        public static MvcHtmlString MainMenus(this HtmlHelper html)
        {
            const string key = "NofCachedMenus";

            var session     = html.ViewContext.HttpContext.Session;
            var cachedmenus = session == null ? null : session[key] as string;

            if (!string.IsNullOrEmpty(cachedmenus))
            {
                return(new MvcHtmlString(cachedmenus));
            }

            var mainMenus = html.Facade().GetMainMenus();
            var menus     = RenderMainMenus(html, mainMenus);

            if (session != null)
            {
                session.Add(key, menus.ToString());
            }

            return(menus);
        }
        private static MvcHtmlString GetStandalone(HtmlHelper html, IObjectFacade collectionNakedObject, Func<IAssociationFacade, bool> filter, Func<IAssociationFacade, int> order, TagBuilder tag, bool withTitle) {
            Func<IObjectFacade, string> linkFunc = item => html.Object(html.ObjectTitle(item).ToString(), IdConstants.ViewAction, item.Object).ToString();

            string menu = collectionNakedObject.Specification.IsQueryable ? html.MenuOnTransient(collectionNakedObject.GetDomainObject()).ToString() : "";
            string id = collectionNakedObject.Oid == null ? "" : Encode(html.Facade().OidTranslator.GetOidTranslation(collectionNakedObject));

            // can only be standalone and hence page if we have an id 
            tag.InnerHtml += html.CollectionTable(collectionNakedObject, linkFunc, filter, order, !String.IsNullOrEmpty(id), collectionNakedObject.Specification.IsQueryable, withTitle);

            return html.WrapInForm(IdConstants.EditObjectAction,
                html.Facade().GetObjectTypeShortName(collectionNakedObject.GetDomainObject()),
                menu + tag,
                IdConstants.ActionName,
                new RouteValueDictionary(new { id }));
        }
        public static MvcHtmlString TypeName <TModel>(this HtmlHelper html, TModel model, string propertyId)
        {
            var nakedObject = html.Facade().GetObject(model);

            return(MvcHtmlString.Create(nakedObject.Specification.Properties.Single(p => p.Id == propertyId).Specification.ShortName));
        }
 private static IMenuFacade GetMenu(HtmlHelper html, object service) {
     return html.Facade().GetObject(service).Specification.Menu;
 }
        /// <summary>
        ///     Indicate if object is a not persistent  object
        /// </summary>
        public static bool ObjectIsNotPersistent(this HtmlHelper html, object domainObject)
        {
            var nakedObject = html.Facade().GetObject(domainObject);

            return(nakedObject.IsNotPersistent);
        }
        /// <summary>
        /// Display the contents of the identified property on model parameter
        /// </summary>
        public static MvcHtmlString Contents <TModel>(this HtmlHelper html, TModel model, string propertyId)
        {
            var nakedObject = html.Facade().GetObject(model);

            return(MvcHtmlString.Create(nakedObject.Specification.Properties.Single(p => p.Id == propertyId).GetValue(nakedObject).TitleString));
        }
        internal static MvcHtmlString CollectionListInternal(this HtmlHelper html, IEnumerable collection, IActionFacade action = null)
        {
            var nakedObject = html.Facade().GetObject(collection);

            return(html.GetStandaloneList(nakedObject, null));
        }
Example #31
0
 public static IFrameworkFacade GetFacade(this HtmlHelper html)
 {
     return(html.Facade());
 }
Example #32
0
 private static IMenuFacade GetMenu(HtmlHelper html, object service)
 {
     return(html.Facade().GetObject(service).Specification.Menu);
 }