public virtual ActionResult EditObject(ObjectAndControlData controlData, FormCollection form) { Decrypt(form); controlData.Form = form; INakedObject nakedObject = controlData.GetNakedObject(NakedObjectsContext); SetExistingCollectionFormats(nakedObject, form); if (nakedObject.IsNotPersistent()) { RefreshTransient(nakedObject, form); } switch (controlData.SubAction) { case (ObjectAndControlData.SubActionType.Action): SetNewCollectionFormats(controlData); return(ActionOnNotPersistentObject(controlData)); case (ObjectAndControlData.SubActionType.None): AddAttemptedValues(nakedObject, controlData); return(View("ObjectEdit", nakedObject.Object)); case (ObjectAndControlData.SubActionType.Pager): SetNewCollectionFormats(controlData); return(AppropriateView(controlData, nakedObject)); case (ObjectAndControlData.SubActionType.Redisplay): return(Redisplay(controlData)); } Log.ErrorFormat("SubAction handling not implemented in EditObject for {0}", controlData.SubAction.ToString()); throw new NotImplementedException(controlData.SubAction.ToString()); }
internal ActionResult AppropriateView(ObjectAndControlData controlData, INakedObject nakedObject, INakedObjectAction action = null, string propertyName = null) { if (nakedObject == null) { // no object to go to // if action on object go to that object. // if action on collection go to collection // if action on service go to last object nakedObject = controlData.GetNakedObject(); if (nakedObject.Specification.IsService) { object lastObject = Session.LastObject(ObjectCache.ObjectFlag.BreadCrumb); if (lastObject == null) { TempData[IdHelper.NofMessages] = NakedObjectsContext.MessageBroker.Messages; TempData[IdHelper.NofWarnings] = NakedObjectsContext.MessageBroker.Warnings; return RedirectToAction(IdHelper.IndexAction, IdHelper.HomeName); } nakedObject = FrameworkHelper.GetNakedObject(lastObject); } } if (nakedObject.Specification.IsCollection && !nakedObject.Specification.IsParseable) { var collection = nakedObject.GetAsQueryable(); int collectionSize = collection.Count(); if (collectionSize == 1) { // remove any paging data - to catch case where custom page has embedded standalone collection as paging data will confuse rendering ViewData.Remove(IdHelper.PagingData); return View("ObjectView", collection.First()); } nakedObject = Page(nakedObject, collectionSize, controlData, nakedObject.IsNotQueryable()); action = action ?? ((CollectionMemento)nakedObject.Oid).Action; int page, pageSize; CurrentlyPaging(controlData, collectionSize, out page, out pageSize); var format = ViewData["NofCollectionFormat"] as string; return View("StandaloneTable", ActionResultModel.Create(action, nakedObject, page, pageSize, format)); } // remove any paging data - to catch case where custom page has embedded standalone collection as paging data will confuse rendering ViewData.Remove(IdHelper.PagingData); if (controlData.DataDict.Values.Contains("max")) { // maximizing an inline object - do not update history ViewData.Add("updateHistory", false); } return propertyName == null ? View(nakedObject.IsNotPersistent() ? "ObjectView" : "ViewNameSetAfterTransaction", nakedObject.Object) : View(nakedObject.IsNotPersistent() ? "PropertyView" : "ViewNameSetAfterTransaction", new PropertyViewModel(nakedObject.Object, propertyName)); }
/// <summary> /// Indicate if object is a not persistent object /// </summary> public static bool ObjectIsNotPersistent(this HtmlHelper html, object domainObject) { INakedObject nakedObject = html.Framework().GetNakedObject(domainObject); return(nakedObject.IsNotPersistent()); }
internal static MvcHtmlString BuildViewContainer(this HtmlHelper html, INakedObject nakedObject, IEnumerable<ElementDescriptor> elements, string cls, string id, bool anyEditableFields) { TagBuilder fieldSet = AddClassAndIdToElementSet(elements, cls, id); if (nakedObject.IsNotPersistent()) { fieldSet.InnerHtml += ElementDescriptor.BuildElementSet(html.EditObjectFields(nakedObject, null, x => false, null)); if (anyEditableFields && !nakedObject.Specification.IsAlwaysImmutable()) { fieldSet.InnerHtml += GetSubmitButton(IdHelper.EditButtonClass, MvcUi.Edit, string.Empty, new RouteValueDictionary()); } } else { fieldSet.InnerHtml += html.GetEditButtonIfRequired(anyEditableFields, nakedObject); } return MvcHtmlString.Create(fieldSet.ToString()); }