private static IObjectFacade GetExistingValue(this HtmlHelper html, string id, PropertyContext propertyContext) {
            ModelState modelState;
            string rawExistingValue = html.ViewData.ModelState.TryGetValue(id, out modelState) ? (string)modelState.Value.RawValue : null;

            IObjectFacade existingValue;
            if (String.IsNullOrEmpty(rawExistingValue)) {
                existingValue = propertyContext.GetValue(html.Facade());
            } else {
                existingValue = propertyContext.Property.Specification.IsParseable ? html.Facade().GetObject(propertyContext.Property.Specification, rawExistingValue) :
                    html.Facade().GetObject(html.Facade().OidTranslator.GetOidTranslation((string)modelState.Value.RawValue)).Target;
            }
            return existingValue;
        }
        private static string GetReferenceField(this HtmlHelper html,
                                                PropertyContext propertyContext,
                                                string id,
                                                string tooltip,
                                                IList<ElementDescriptor> childElements,
                                                bool addToThis,
                                                bool readOnly,
                                                bool noFinder) {
            var tag = new TagBuilder("div");
            tag.AddCssClass(IdConstants.ObjectName);

            if (!propertyContext.Property.IsVisible(propertyContext.Target)) {
                var existingValue = propertyContext.GetValue(html.Facade());
                string value = existingValue == null ? String.Empty : Encode(html.Facade().OidTranslator.GetOidTranslation(existingValue));
                tag.InnerHtml += html.Encrypted(id, value).ToString();
                propertyContext.IsPropertyEdit = false;
            } else {
                if (readOnly) {
                    var valueNakedObject = propertyContext.GetValue(html.Facade());
                    string valueId = valueNakedObject == null ? String.Empty : Encode(html.Facade().OidTranslator.GetOidTranslation(valueNakedObject));

                    tag.InnerHtml += html.ObjectIcon(propertyContext.Property.GetValue(propertyContext.Target)) +
                                     html.GetFieldValue(propertyContext) +
                                     html.CustomEncrypted(id, valueId);
                    propertyContext.IsPropertyEdit = false;
                } else if (propertyContext.Property.IsChoicesEnabled != Choices.NotEnabled) {
                    IEnumerable<SelectListItem> items = html.GetItems(id, propertyContext);

                    tag.InnerHtml += html.ObjectIcon(propertyContext.Property.GetValue(propertyContext.Target)) +
                                     html.DropDownList(id, items, new { title = tooltip }) +
                                     html.GetMandatoryIndicator(propertyContext) +
                                     html.ValidationMessage(id);
                } else {
                    var valueNakedObject = html.GetExistingValue(id, propertyContext);
                    var suggestedItem = html.GetSuggestedItem(id, valueNakedObject);
                    string valueId = suggestedItem == null ? String.Empty : Encode(html.Facade().OidTranslator.GetOidTranslation(suggestedItem));

                    if (!propertyContext.Target.IsTransient) {
                        // do not only allow drag and drop onto transients - otherwise  attempt to validate 
                        // may depend on missing fields/data. cf check at top of AjaxControllerImpl:ValidateProperty

                        string url = html.GenerateUrl("ValidateProperty", "Ajax", new RouteValueDictionary(new {
                            id = Encode(html.Facade().OidTranslator.GetOidTranslation(propertyContext.Target)),
                            propertyName = propertyContext.Property.Id
                        }));
                        tag.MergeAttribute("data-validate", url);
                    }
                    //Translates to: Only render finder if the Context is FindMenu enabled AND 
                    //calling code has not overridden it by setting noFinder to true.
                    noFinder = noFinder || !propertyContext.IsFindMenuEnabled();

                    tag.InnerHtml += html.ObjectIcon(suggestedItem) +
                                     html.GetFieldValue(propertyContext, suggestedItem, noFinder) +
                                     html.GetMandatoryIndicator(propertyContext) +
                                     html.ValidationMessage(propertyContext.Property.IsAutoCompleteEnabled ? propertyContext.GetAutoCompleteFieldId() : id) +
                                     html.CustomEncrypted(id, valueId);
                    propertyContext.IsPropertyEdit = false;
                }
            }
            AddInsertedElements(childElements, addToThis, tag);
            return tag.ToString();
        }
        private static string GetRawValue(this HtmlHelper html, PropertyContext propertyContext) {
            var valueNakedObject = propertyContext.GetValue(html.Facade());

            if (valueNakedObject == null) {
                return String.Empty;
            }

            if (valueNakedObject.Specification.IsEnum) {
                return valueNakedObject.Object.ToString();
            }

            return valueNakedObject.TitleString;
        }
        private static string GetObjectDisplayLinks(this HtmlHelper html, PropertyContext propertyContext) {
            IDictionary<string, object> objectDisplayStatuses = GetDisplayStatuses(html);

            string actionName = propertyContext.IsEdit ? IdConstants.EditObjectAction : IdConstants.ViewAction;

            if (propertyContext.IsEdit || propertyContext.Target.IsTransient) {
                // for the moment no expand and delete on editable views 
                return "";
            }
            var formTag = new TagBuilder("form");
            formTag.MergeAttribute("method", "post");

            object objectToView;
            string objectId;
            //for ajax use the property 
            if (html.ViewContext.RequestContext.HttpContext.Request.IsAjaxRequest()) {
                objectId = "";
                objectToView = propertyContext.GetValue(html.Facade()).Object;
            } else {
                objectToView = propertyContext.OriginalTarget.Object;
                objectId = propertyContext.GetFieldId();
            }

            formTag.MergeAttribute("action", html.GenerateUrl(actionName, objectToView));

            formTag.InnerHtml += html.Hidden(html.IdHelper().GetDisplayFormatId(objectId), ToNameValuePairs(objectDisplayStatuses));

            formTag.InnerHtml += GetSubmitButton(IdConstants.MinButtonClass, MvcUi.Collapse, IdConstants.RedisplayAction, new RouteValueDictionary { { objectId, IdConstants.MinDisplayFormat }, { "editMode", propertyContext.IsEdit } });
            formTag.InnerHtml += GetSubmitButton(IdConstants.MaxButtonClass, MvcUi.Expand, IdConstants.RedisplayAction, new RouteValueDictionary { { objectId, IdConstants.MaxDisplayFormat }, { "editMode", propertyContext.IsEdit } });

            formTag.InnerHtml = formTag.InnerHtml.WrapInDivTag();
            return formTag.ToString();
        }
        private static string GetEditValue(this HtmlHelper html,
                                           PropertyContext propertyContext,
                                           IList<ElementDescriptor> childElements,
                                           bool addToThis,
                                           bool noFinder) {
            string tooltip = propertyContext.Property.Description;
            string id = propertyContext.GetFieldInputId();
            if (propertyContext.Property.IsCollection) {
                propertyContext.IsPropertyEdit = false;
                return html.GetChildCollection(propertyContext);
            }
            var consent = propertyContext.Property.IsUsable(propertyContext.Target);
            if (consent.IsVetoed && !propertyContext.Target.IsTransient) {
                propertyContext.IsPropertyEdit = false;
                return html.GetViewField(propertyContext, consent.Reason);
            }

            bool readOnly = consent.IsVetoed && propertyContext.Target.IsTransient;

            // for the moment do not allow file properties to be edited 
            if (propertyContext.Property.Specification.IsFileAttachment) {
                // return html.GetFileProperty(propertyContext, id, tooltip);
                readOnly = true;
            }

            if (propertyContext.Property.Specification.IsParseable) {
                return html.GetTextField(propertyContext, id, tooltip, readOnly);
            }

            if (propertyContext.Property.IsInline) {
                var inlineNakedObject = propertyContext.GetValue(html.Facade());
                TagBuilder elementSet = ElementDescriptor.BuildElementSet(html.EditObjectFields(inlineNakedObject, propertyContext, x => true, null, true));
                html.AddAjaxDataUrlsToElementSet(inlineNakedObject, elementSet, propertyContext);

                return elementSet.ToString();
            }

            return html.GetReferenceField(propertyContext, id, tooltip, childElements, addToThis, readOnly, noFinder);
        }
예제 #6
0
        private static string GetInvariantValue(PropertyContext propertyContext) {
            INakedObject valueNakedObject = propertyContext.GetValue();

            if (valueNakedObject == null) {
                return string.Empty;
            }

            return valueNakedObject.InvariantString();
        }
예제 #7
0
        private static string GetHiddenValue(this HtmlHelper html, PropertyContext propertyContext, string id, bool invariant) {
            var tag = new TagBuilder("div");
            string value;

            if (propertyContext.Property.Specification.IsParseable) {
                tag.AddCssClass(IdHelper.ValueName);
                value = invariant ? GetInvariantValue(propertyContext) : GetRawValue(propertyContext);
            }
            else {
                tag.AddCssClass(IdHelper.ObjectName);
                INakedObject existingValue = propertyContext.GetValue();
                value = existingValue == null ? string.Empty : FrameworkHelper.GetObjectId(existingValue);
            }
            tag.InnerHtml += html.Encrypted(id, value).ToString();
            return tag.ToString();
        }
 private static string GetPropertyValue(this HtmlHelper html, PropertyContext propertyContext) {
     var valueNakedObject = propertyContext.GetValue(html.Facade());
     string value = propertyContext.Property.GetMaskedValue(valueNakedObject);
     value = html.ZeroValueIfTransientAndNotSet(propertyContext, value);
     return value;
 }
예제 #9
0
 private static string GetPropertyValue(PropertyContext propertyContext) {
     var mask = propertyContext.Property.GetFacet<IMaskFacet>();
     INakedObject valueNakedObject = propertyContext.GetValue();
     string value = GetMaskedValue(valueNakedObject, mask);
     value = ZeroValueIfTransientAndNotSet(propertyContext, value);
     return value;
 }
예제 #10
0
 private static string ZeroValueIfTransientAndNotSet(PropertyContext propertyContext, string value) {
     if (propertyContext.Target.ResolveState.IsTransient() && !string.IsNullOrEmpty(value)) {
         INakedObject valueNakedObject = propertyContext.GetValue();
         if (propertyContext.Property.GetDefaultType(propertyContext.Target) == TypeOfDefaultValue.Implicit && ShouldClearValue(valueNakedObject.Object)) {
             value = null;
         }
     }
     return value;
 }
예제 #11
0
        private static string GetReferenceField(this HtmlHelper html,
                                                PropertyContext propertyContext,
                                                string id,
                                                string tooltip,
                                                IList<ElementDescriptor> childElements,
                                                bool addToThis,
                                                bool readOnly,
                                                bool noFinder) {
            var tag = new TagBuilder("div");
            tag.AddCssClass(IdHelper.ObjectName);

            if (!propertyContext.Property.IsVisible(NakedObjectsContext.Session, propertyContext.Target)) {
                INakedObject existingValue = propertyContext.GetValue();
                string value = existingValue == null ? string.Empty : FrameworkHelper.GetObjectId(existingValue);
                tag.InnerHtml += html.Encrypted(id, value).ToString();
                propertyContext.IsPropertyEdit = false;
            }
            else {
                if (readOnly) {
                    INakedObject valueNakedObject = propertyContext.GetValue();
                    string valueId = valueNakedObject == null ? string.Empty : FrameworkHelper.GetObjectId(valueNakedObject);

                    tag.InnerHtml += html.ObjectIcon(propertyContext.Property.GetNakedObject(propertyContext.Target)) +
                                     html.GetFieldValue(propertyContext) +
                                     html.CustomEncrypted(id, valueId);
                    propertyContext.IsPropertyEdit = false;
                }
                else if (((IOneToOneAssociation) propertyContext.Property).IsChoicesEnabled) {
                    IEnumerable<SelectListItem> items = html.GetItems(id, propertyContext);

                    tag.InnerHtml += html.ObjectIcon(propertyContext.Property.GetNakedObject(propertyContext.Target)) +
                                     html.DropDownList(id, items, new {title = tooltip}) +
                                     GetMandatoryIndicator(propertyContext) +
                                     html.ValidationMessage(id);
                }
                else {
                    INakedObject valueNakedObject = html.GetExistingValue(id, propertyContext);
                    INakedObject suggestedItem = html.GetSuggestedItem(id, valueNakedObject);
                    string valueId = suggestedItem == null ? string.Empty : FrameworkHelper.GetObjectId(suggestedItem);

                    if (!propertyContext.Target.ResolveState.IsTransient() || MvcIdentityAdapterHashMap.StoringTransientsInSession) {
                        // only allow drag and drop onto transients if they are stored in session - otherwise  attempt to validate 
                        // may depend on missing fields/data. cf check at top of AjaxControllerImpl:ValidateProperty

                        string url = html.GenerateUrl("ValidateProperty", "Ajax", new RouteValueDictionary(new {
                            id = FrameworkHelper.GetObjectId(propertyContext.Target),
                            propertyName = propertyContext.Property.Id
                        }));
                        tag.MergeAttribute("data-validate", url);
                    }

                    tag.InnerHtml += html.ObjectIcon(suggestedItem) +
                                     html.GetFieldValue(propertyContext, suggestedItem) +
                                     (noFinder ? string.Empty : html.FinderActions(propertyContext.Property.Specification, new ActionContext(propertyContext.Target, null), propertyContext.Property.Id)) +
                                     GetMandatoryIndicator(propertyContext) +
                                     html.ValidationMessage(((IOneToOneAssociation) propertyContext.Property).IsAutoCompleteEnabled ? propertyContext.GetAutoCompleteFieldId() : id) +
                                     html.CustomEncrypted(id, valueId);
                    propertyContext.IsPropertyEdit = false;
                }
            }
            AddInsertedElements(childElements, addToThis, tag);
            return tag.ToString();
        }
예제 #12
0
        private static INakedObject GetExistingValue(this HtmlHelper html, string id, PropertyContext propertyContext) {
            ModelState modelState;
            string rawExistingValue = html.ViewData.ModelState.TryGetValue(id, out modelState) ? (string) modelState.Value.RawValue : null;

            INakedObject existingValue;
            if (rawExistingValue == null) {
                existingValue = propertyContext.GetValue();
            }
            else {
                existingValue = propertyContext.Property.Specification.IsParseable ? FrameworkHelper.GetNakedObject(rawExistingValue) :
                                    FrameworkHelper.GetNakedObjectFromId((string) modelState.Value.RawValue);
            }
            return existingValue;
        }
예제 #13
0
        private static string GetRawValue(PropertyContext propertyContext) {
            INakedObject valueNakedObject = propertyContext.GetValue();

            if (valueNakedObject == null) {
                return string.Empty;
            }

            if (valueNakedObject.Specification.ContainsFacet<IEnumValueFacet>()) {
                return valueNakedObject.Object.ToString();
            }

            return valueNakedObject.TitleString();
        }
        private static string GetCollectionAsTable(this HtmlHelper html, PropertyContext propertyContext) {
            var collectionNakedObject = propertyContext.GetValue(html.Facade());
            bool any = collectionNakedObject.ToEnumerable().Any();
            Func<IObjectFacade, string> linkFunc = item => html.Object(html.ObjectTitle(item).ToString(), IdConstants.ViewAction, item.Object).ToString();

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

            GetTableColumnInfo(propertyContext.Property, out filterFunc, out orderFunc, out withTitle);

            return (any ? html.GetCollectionDisplayLinks(propertyContext) : GetCollectionTitle(propertyContext, 0)) +
                   html.CollectionTable(collectionNakedObject, linkFunc, filterFunc, orderFunc, false, false, withTitle);
        }
        private static string GetFieldValue(this HtmlHelper html, PropertyContext propertyContext, bool inTable = false) {
            var valueNakedObject = propertyContext.GetValue(html.Facade());

            if (valueNakedObject == null) {
                return String.Empty;
            }

            if (propertyContext.Property.IsFile) {
                return html.GetFileFieldValue(propertyContext);
            }

            if (propertyContext.Property.Specification.IsBoolean) {
                return html.GetBooleanFieldValue(valueNakedObject);
            }

            if (propertyContext.Property.IsEnum) {
                return GetEnumFieldValue(propertyContext.Property, valueNakedObject);
            }

            return html.GetTextOrRefFieldValue(propertyContext, valueNakedObject, inTable);
        }
 private static string GetCollectionAsList(this HtmlHelper html, PropertyContext propertyContext) {
     var collectionNakedObject = propertyContext.GetValue(html.Facade());
     bool any = collectionNakedObject.ToEnumerable().Any();
     Func<IObjectFacade, string> linkFunc = item => html.Object(html.ObjectTitle(item).ToString(), IdConstants.ViewAction, item.Object).ToString();
     return (any ? html.GetCollectionDisplayLinks(propertyContext) : GetCollectionTitle(propertyContext, 0)) +
            html.CollectionTable(collectionNakedObject, linkFunc, x => false, null, false, false, true);
 }
        private static string GetTextOrRefFieldValue(this HtmlHelper html, PropertyContext propertyContext, IObjectFacade valueNakedObject, bool inTable = false) {
            if (valueNakedObject.Specification.IsCollection) {
                valueNakedObject.Resolve();
            }

            string link = "{0}";

            if (!propertyContext.Property.Specification.IsParseable && !propertyContext.Property.IsCollection) {
                string displayType = html.ViewData.ContainsKey(propertyContext.GetFieldId()) ? (string)html.ViewData[propertyContext.GetFieldId()] : String.Empty;
                bool renderEagerly = RenderEagerly(propertyContext.Property);

                link = html.ObjectLink(link, IdConstants.ViewAction, valueNakedObject.Object) + (inTable ? "" : html.GetObjectDisplayLinks(propertyContext));

                if (displayType == IdConstants.MaxDisplayFormat || renderEagerly) {
                    var inlineNakedObject = propertyContext.GetValue(html.Facade());
                    bool anyEditableFields;
                    TagBuilder elementSet = ElementDescriptor.BuildElementSet(html.ViewObjectFields(inlineNakedObject, propertyContext, x => true, null, out anyEditableFields));

                    html.AddAjaxDataUrlsToElementSet(inlineNakedObject, elementSet, propertyContext);
                    elementSet.AddCssClass(IdConstants.FieldContainerName);
                    elementSet.GenerateId(html.IdHelper().GetFieldContainerId(inlineNakedObject));

                    link = link + html.GetEditButtonIfRequired(anyEditableFields, inlineNakedObject) + elementSet;
                }
            }

            string title = html.GetDisplayTitle(propertyContext.Property, valueNakedObject);

            if (propertyContext.Property.NumberOfLines > 1) {
                int typicalLength = propertyContext.Property.TypicalLength;
                int width = propertyContext.Property.Width;

                typicalLength = typicalLength == 0 ? 20 : typicalLength;
                width = width == 0 ? typicalLength : width;

                if (inTable) {
                    // truncate to width 
                    if (title.Length > width) {
                        const string elipsis = "...";
                        int length = width - elipsis.Length;
                        title = title.Substring(0, length > 0 ? length : 1) + elipsis;
                    }
                }
            }

            return String.Format(link, title);
        }
        private static string ZeroValueIfTransientAndNotSet(this HtmlHelper html, PropertyContext propertyContext, string value) {
            if (propertyContext.Target.IsTransient && !String.IsNullOrEmpty(value)) {
                var valueNakedObject = propertyContext.GetValue(html.Facade());

                if (!propertyContext.Property.DefaultTypeIsExplicit(propertyContext.Target) && ShouldClearValue(valueNakedObject.Object)) {
                    value = null;
                }
            }
            return value;
        }
        private static string GetInvariantValue(this HtmlHelper html, PropertyContext propertyContext) {
            var valueNakedObject = propertyContext.GetValue(html.Facade());

            if (valueNakedObject == null) {
                return String.Empty;
            }
            return valueNakedObject.InvariantString;
        }
        private static string GetHiddenValue(this HtmlHelper html, PropertyContext propertyContext, string id, bool invariant) {
            var tag = new TagBuilder("div");
            string value;

            if (propertyContext.Property.Specification.IsParseable) {
                tag.AddCssClass(IdConstants.ValueName);
                value = invariant ? html.GetInvariantValue(propertyContext) : html.GetRawValue(propertyContext);
            } else {
                tag.AddCssClass(IdConstants.ObjectName);
                var existingValue = propertyContext.GetValue(html.Facade());
                value = existingValue == null ? String.Empty : Encode(html.Facade().OidTranslator.GetOidTranslation(existingValue));
            }
            tag.InnerHtml += html.Encrypted(id, value).ToString();
            return tag.ToString();
        }
예제 #21
0
        private static string GetFieldValue(this HtmlHelper html, PropertyContext propertyContext, bool inTable = false) {
            INakedObject valueNakedObject = propertyContext.GetValue();

            if (valueNakedObject == null) {
                return string.Empty;
            }

            if (propertyContext.Property.IsFile()) {
                return html.GetFileFieldValue(propertyContext);
            }

            if (propertyContext.Property.Specification.ContainsFacet<IBooleanValueFacet>()) {
                return html.GetBooleanFieldValue(valueNakedObject);
            }

            if (propertyContext.Property.ContainsFacet<IEnumFacet>()) {
                return GetEnumFieldValue(propertyContext.Property, valueNakedObject);
            }

            return html.GetTextOrRefFieldValue(propertyContext, valueNakedObject, inTable);
        }