/// <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.Framework().NakedObjectManager.CreateAdapter(target, null, null).Spec is IObjectSpec ? target : null; } // if target is transient cancel back to history if (domainObject != null && html.Framework().NakedObjectManager.CreateAdapter(domainObject, null, null).ResolveState.IsTransient()) { domainObject = null; } string nextUrl = domainObject == null ? "" : html.Tab(html.ObjectTitle(domainObject).ToString(), IdHelper.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())); }
/// <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 = !PersistorUtils.CreateAdapter(target).Specification.IsService ? target : null; } // if target is transient cancel back to history if (domainObject != null && PersistorUtils.CreateAdapter(domainObject).ResolveState.IsTransient()) { domainObject = null; } string nextUrl = domainObject == null ? "" : html.Tab(html.ObjectTitle(domainObject).ToString(), IdHelper.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()); }