Ejemplo n.º 1
0
        private static IEnumerable<SelectListItem> GetItems(this HtmlHelper html, string id, ParameterContext context) {
            INakedObject existingValue = html.GetParmExistingValue(id, context, true); /*remove from viewdata as it confuses dropdown helper*/

            var facet = context.Parameter.GetFacet<IActionChoicesFacet>();
            var values = new Dictionary<string, INakedObject>();
            if (facet != null) {
                values = context.Action.Parameters.
                                 Where(p => facet.ParameterNamesAndTypes.Select(pnt => pnt.Item1).Contains(p.Id.ToLower())).
                                 ToDictionary(p => p.Id.ToLower(),
                                              p => html.GetParmExistingValue(IdHelper.GetParameterInputId(context.Action, p), new ParameterContext(context) {Parameter = p}, false));
            }


            return GetChoicesSet(context, existingValue, values);
        }
        private static string GetParameterValue(this HtmlHelper html, ParameterContext context, IObjectFacade valueNakedObject, bool noFinder) {
            string value = "";

            // Even if not autocomplete add autocomplete menu if no finder and then handle with recently viewed in ajax controller
            if (context.Parameter.IsAutoCompleteEnabled || (noFinder && !context.Parameter.Specification.IsCollection && !context.IsContributed())) {
                var htmlAttributes = new RouteValueDictionary(new { title = context.Parameter.Description });

                html.AddClientValidationAttributes(context, htmlAttributes);
                value += html.GetAutoCompleteTextBox(context, htmlAttributes, valueNakedObject);
            } else if (valueNakedObject != null) {
                string link = "{0}";

                if (context.Parameter.Specification.IsCollection) {
                    link = html.CollectionLink(link, IdConstants.ViewAction, valueNakedObject.Object);
                } else if (!context.Parameter.Specification.IsParseable && !context.Parameter.Specification.IsCollection) {
                    link = html.ObjectLink(link, IdConstants.ViewAction, valueNakedObject.Object);
                }

                string title = html.GetDisplayTitle(context.Parameter, valueNakedObject);
                value += String.Format(link, title);
            }

            if (!noFinder) {
                // append finder meu
                value += html.FinderActions(context.Parameter.Specification, context, context.Parameter.Id);
            }

            return value;
        }
 public ParameterContext(IIdHelper idhelper, ParameterContext otherContext) : base(idhelper, otherContext)
 {
     Parameter = otherContext.Parameter;
 }
        private static void AddTextControl(this HtmlHelper html, TagBuilder tag, RouteValueDictionary htmlAttributes, ParameterContext context, string id, string value) {
            var typicalLength = context.Parameter.TypicalLength;
            var maxLength = context.Parameter.MaxLength.GetValueOrDefault(0);
            int numberOfLines = context.Parameter.NumberOfLines;
            int width = context.Parameter.Width;

            width = width == 0 ? (typicalLength == 0 ? 20 : typicalLength) / numberOfLines : width;

            string textBox = html.GetTextControl(id, numberOfLines, width, maxLength, value, htmlAttributes);
            tag.InnerHtml += textBox + html.GetMandatoryIndicator(context) + html.ValidationMessage(id);
        }
 private static void AddDateTimeControl(this HtmlHelper html, TagBuilder tag, RouteValueDictionary htmlAttributes, ParameterContext context, string id, string value) {
     var typicalLengthFacet = context.Parameter.TypicalLength;
     htmlAttributes["size"] = typicalLengthFacet == 0 ? 20 : typicalLengthFacet;
     htmlAttributes["class"] = "datetime";
     tag.InnerHtml += html.TextBox(id, value, htmlAttributes) + html.GetMandatoryIndicator(context) + html.ValidationMessage(id);
 }
        private static string GetFileParameter(this HtmlHelper html, ParameterContext context, string id, string tooltip) {
            var tag = new TagBuilder("div");
            tag.AddCssClass(IdConstants.ValueName);

            var fileInput = new TagBuilder("input");

            fileInput.MergeAttribute("type", "file");
            fileInput.MergeAttribute("id", id);
            fileInput.MergeAttribute("name", id);
            fileInput.MergeAttribute("title", tooltip);

            string input = fileInput.ToString();

            tag.InnerHtml += input +
                             html.GetMandatoryIndicator(context) +
                             html.ValidationMessage(id);

            return tag.ToString();
        }
 private static string GetFieldValue(this HtmlHelper html, ParameterContext context, string id) {
     var valueNakedObject = html.GetParameterDefaultValue(id, context);
     return context.Parameter.GetMaskedValue(valueNakedObject);
 }
Ejemplo n.º 8
0
 private static bool IsMandatory(ParameterContext parameterContext) {
     return (parameterContext.Parameter.IsMandatory && parameterContext.Parameter.IsUsable(NakedObjectsContext.Session, parameterContext.Target).IsAllowed);
 }
 private static string GetAutoCompleteTextBox(this HtmlHelper html, ParameterContext context, RouteValueDictionary htmlAttributes, IObjectFacade valueNakedObject) {
     string completionAjaxUrl = html.GenerateUrl("GetActionCompletions", "Ajax", new RouteValueDictionary(new { id = Encode(html.Facade().OidTranslator.GetOidTranslation(context.Target)), actionName = context.Action.Id, parameterIndex = context.Parameter.Number }));
     RouteValueDictionary attrs = CreateAutoCompleteAttributes(context.Parameter, completionAjaxUrl);
     attrs.ForEach(kvp => htmlAttributes.Add(kvp.Key, kvp.Value));
     string title = valueNakedObject == null ? "" : html.GetDisplayTitle(context.Parameter, valueNakedObject);
     return html.TextBox(context.GetParameterAutoCompleteId(), title, htmlAttributes).ToHtmlString();
 }
Ejemplo n.º 10
0
        private static string GetReferenceParameter(this HtmlHelper html, ParameterContext context, string id, string tooltip, IList<ElementDescriptor> childElements, bool addToThis) {
            var tag = new TagBuilder("div");
            tag.AddCssClass(IdHelper.ObjectName);

            if (context.IsHidden) {
                INakedObject suggestedItem = html.GetSuggestedItem(id, null);
                string valueId = suggestedItem == null ? string.Empty : FrameworkHelper.GetObjectId(suggestedItem);
                tag.InnerHtml += html.CustomEncrypted(id, valueId);
            }
            else if (context.Parameter.IsChoicesEnabled) {
                var htmlAttributes = new RouteValueDictionary(new {title = tooltip});
                html.AddDropDownControl(tag, htmlAttributes, context, id);
            }
            else if (context.Parameter.IsMultipleChoicesEnabled) {
                var htmlAttributes = new RouteValueDictionary(new {title = tooltip});
                html.AddListBoxControl(tag, htmlAttributes, context, id);
            }
            else {
                INakedObject existingValue = html.GetParameterExistingValue(id, context);
                INakedObject suggestedItem = html.GetSuggestedItem(id, existingValue);
                string valueId = suggestedItem == null ? string.Empty : FrameworkHelper.GetObjectId(suggestedItem);

                string url = html.GenerateUrl("ValidateParameter", "Ajax", new RouteValueDictionary(new {
                    id = FrameworkHelper.GetObjectId(context.Target),
                    actionName = context.Action.Id,
                    parameterName = context.Parameter.Id,
                }));

                tag.MergeAttribute("data-validate", url);

                tag.InnerHtml += html.ObjectIcon(suggestedItem) +
                                 html.GetFieldValue(context, suggestedItem) +
                                 (context.EmbeddedInObject ? string.Empty : html.FinderActions(context.Parameter.Specification, context, context.Parameter.Id)) +
                                 GetMandatoryIndicator(context) +
                                 html.ValidationMessage(context.Parameter.IsAutoCompleteEnabled ? context.GetParameterAutoCompleteId() : id) +
                                 html.CustomEncrypted(id, valueId);
                context.IsParameterEdit = false;
            }
            AddInsertedElements(childElements, addToThis, tag);
            return tag.ToString();
        }
Ejemplo n.º 11
0
 private static string GetFieldValue(this HtmlHelper html, ParameterContext context, string id) {
     INakedObject valueNakedObject = html.GetParameterDefaultValue(id, context);
     var mask = context.Parameter.GetFacet<IMaskFacet>();
     return GetMaskedValue(valueNakedObject, mask);
 }
Ejemplo n.º 12
0
 private static IEnumerable<SelectListItem> GetChoicesSet(ParameterContext parameterContext,
                                                          INakedObject existingNakedObject,
                                                          IDictionary<string, INakedObject> values) {
     List<INakedObject> nakedObjects = parameterContext.Parameter.GetChoices(parameterContext.Target, values).ToList();
     return GetChoicesSet(nakedObjects, existingNakedObject);
 }
Ejemplo n.º 13
0
        private static INakedObject GetParameterExistingValue(this HtmlHelper html, string id, ParameterContext context, bool clear = false) {
            ModelState modelState = html.ViewData.ModelState.TryGetValue(id, out modelState) ? modelState : null;

            if (modelState != null && modelState.Value != null) {
                object rawvalue = modelState.Value.RawValue;
                if (clear) {
                    // only clear the value and keep any error 
                    ModelErrorCollection errors = modelState.Errors;
                    html.ViewData.ModelState.Remove(id);

                    if (errors.Any()) {
                        errors.ForEach(e => html.ViewData.ModelState.AddModelError(id, e.ErrorMessage));
                    }
                }

                if (context.Parameter.IsObject) {
                    return (INakedObject) rawvalue;
                }
                if (context.Parameter.Specification.IsParseable) {
                    return GetAndParseValueAsNakedObject(context, rawvalue);
                }
                if (context.Parameter.IsCollection) {
                    var facet = context.Parameter.Specification.GetFacet<ITypeOfFacet>();
                    INakedObjectSpecification itemSpec = facet.ValueSpec;

                    if (itemSpec.IsParseable) {
                        var collection = (INakedObject) rawvalue;
                        List<object> parsedCollection = collection.GetCollectionFacetFromSpec().AsEnumerable(collection).Select(no => GetAndParseValueAsNakedObject(itemSpec, no.Object).GetDomainObject()).ToList();
                        return PersistorUtils.CreateAdapter(parsedCollection);
                    }

                    return (INakedObject) rawvalue;
                }

                return context.Parameter.Specification.IsParseable ? GetAndParseValueAsNakedObject(context, rawvalue) : (INakedObject) rawvalue;
            }
            return null;
        }
Ejemplo n.º 14
0
 private static INakedObject GetAndParseValueAsNakedObject(ParameterContext context, object value) {
     return GetAndParseValueAsNakedObject(context.Parameter.Specification, value);
 }
        private static string GetParameter(this HtmlHelper html, ParameterContext context, IList<ElementDescriptor> childElements, string propertyName) {
            string id = context.GetParameterInputId();
            string tooltip = context.Parameter.Description;

            if (context.Parameter.Specification.IsFile) {
                return html.GetFileParameter(context, id, tooltip);
            }

            if (context.Parameter.Specification.IsParseable) {
                return html.GetTextParameter(context, id, tooltip);
            }

            return html.GetReferenceParameter(context, id, tooltip, childElements, context.Parameter.Id == propertyName);
        }
        private static IEnumerable<SelectListItem> GetItems(this HtmlHelper html, string id, ParameterContext context) {
            var existingValue = html.GetParmExistingValue(id, context, true); /*remove from viewdata as it confuses dropdown helper*/

            var choices = context.Parameter.GetChoicesParameters();
            var values = new Dictionary<string, IObjectFacade>();
            if (choices.Any()) {
                values = context.Action.Parameters.
                    Where(p => choices.Select(pnt => pnt.Item1).Contains(p.Id.ToLower())).
                    ToDictionary(p => p.Id.ToLower(),
                        p => html.GetParmExistingValue(html.IdHelper().GetParameterInputId(context.Action, p), new ParameterContext(html.IdHelper(), context) { Parameter = p }, false));
            }

            return html.GetChoicesSet(context, existingValue, values);
        }
        private static string GetReferenceParameter(this HtmlHelper html, ParameterContext context, string id, string tooltip, IList<ElementDescriptor> childElements, bool addToThis) {
            var tag = new TagBuilder("div");
            tag.AddCssClass(IdConstants.ObjectName);

            if (context.IsHidden) {
                var suggestedItem = html.GetSuggestedItem(id, null);
                string valueId = suggestedItem == null ? String.Empty : Encode(html.Facade().OidTranslator.GetOidTranslation(suggestedItem));
                tag.InnerHtml += html.CustomEncrypted(id, valueId);
            } else if (context.Parameter.IsChoicesEnabled == Choices.Single) {
                var htmlAttributes = new RouteValueDictionary(new { title = tooltip });
                html.AddDropDownControl(tag, htmlAttributes, context, id);
            } else if (context.Parameter.IsChoicesEnabled == Choices.Multiple) {
                var htmlAttributes = new RouteValueDictionary(new { title = tooltip });
                html.AddListBoxControl(tag, htmlAttributes, context, id);
            } else {
                var existingValue = html.GetParameterExistingValue(id, context);
                var suggestedItem = html.GetSuggestedItem(id, existingValue);
                string valueId = suggestedItem == null ? String.Empty : Encode(html.Facade().OidTranslator.GetOidTranslation(suggestedItem));

                string url = html.GenerateUrl("ValidateParameter", "Ajax", new RouteValueDictionary(new {
                    id = Encode(html.Facade().OidTranslator.GetOidTranslation(context.Target)),
                    actionName = context.Action.Id,
                    parameterName = context.Parameter.Id
                }));

                tag.MergeAttribute("data-validate", url);

                bool noFinder = context.EmbeddedInObject || !context.IsFindMenuEnabled();

                tag.InnerHtml += html.ObjectIcon(suggestedItem) +
                                 html.GetParameterValue(context, suggestedItem, noFinder) +
                                 html.GetMandatoryIndicator(context) +
                                 html.ValidationMessage(context.Parameter.IsAutoCompleteEnabled ? context.GetParameterAutoCompleteId() : id) +
                                 html.CustomEncrypted(id, valueId);
                context.IsParameterEdit = false;
            }
            AddInsertedElements(childElements, addToThis, tag);
            return tag.ToString();
        }
 private static IObjectFacade GetParmExistingValue(this HtmlHelper html, string id, ParameterContext context, bool clear) {
     return html.GetParameterExistingValue(id, context, clear) ?? html.GetParameterDefaultValue(id, context, clear);
 }
        private static string GetTextParameter(this HtmlHelper html, ParameterContext context, string id, string tooltip) {
            var tag = new TagBuilder("div");
            tag.AddCssClass(IdConstants.ValueName);
            var htmlAttributes = new RouteValueDictionary(new { title = tooltip });

            html.AddClientValidationAttributes(context, htmlAttributes);

            if (context.IsHidden) {
                object obj = html.ViewData[id];
                tag.InnerHtml += html.Encrypted(id, obj.ToString());
            } else if (context.Parameter.Specification.IsBoolean) {
                if (context.Parameter.IsNullable) {
                    html.AddTriState(tag, htmlAttributes, id, null);
                } else {
                    html.AddCheckBox(tag, htmlAttributes, id, null);
                }
            } else if (context.Parameter.Specification.IsDateTime) {
                html.AddDateTimeControl(tag, htmlAttributes, context, id, html.GetFieldValue(context, id));
            } else if (context.Parameter.IsPassword) {
                html.AddPasswordControl(tag, htmlAttributes, context, id, html.GetFieldValue(context, id));
            } else if (context.Parameter.IsChoicesEnabled == Choices.Single) {
                html.AddDropDownControl(tag, htmlAttributes, context, id);
            } else if (context.Parameter.IsChoicesEnabled == Choices.Multiple) {
                html.AddListBoxControl(tag, htmlAttributes, context, id);
            } else if (context.Parameter.IsAutoCompleteEnabled) {
                html.AddAutoCompleteControl(tag, htmlAttributes, context, html.GetParameterDefaultValue(id, context));
            } else {
                html.AddTextControl(tag, htmlAttributes, context, id, null);
            }
            return tag.ToString();
        }
 private static IObjectFacade GetAndParseValueAsNakedObject(this HtmlHelper html, ParameterContext context, object value) {
     return html.GetAndParseValueAsNakedObject(context.Parameter.Specification, value);
 }
 private static bool IsMandatory(this HtmlHelper html, ParameterContext parameterContext) {
     return (parameterContext.Parameter.IsMandatory /*&& parameterContext.Parameter.IsUsable(parameterContext.Target).IsAllowed*/);
 }
        private static IObjectFacade GetParameterExistingValue(this HtmlHelper html, string id, ParameterContext context, bool clear = false) {
            ModelState modelState = html.ViewData.ModelState.TryGetValue(id, out modelState) ? modelState : null;

            if (modelState != null && modelState.Value != null) {
                var modelValue = modelState.Value.RawValue as IObjectFacade;
                object rawvalue = modelValue == null ? modelState.Value.RawValue : modelValue.GetDomainObject<object>();
                if (clear) {
                    // only clear the value and keep any error 
                    ModelErrorCollection errors = modelState.Errors;
                    html.ViewData.ModelState.Remove(id);

                    if (errors.Any()) {
                        errors.ForEach(e => html.ViewData.ModelState.AddModelError(id, e.ErrorMessage));
                        return null;
                    }
                }
                if (context.Parameter.Specification.IsParseable) {
                    return html.GetAndParseValueAsNakedObject(context, rawvalue);
                }

                if (!context.Parameter.Specification.IsCollection) {
                    return modelValue;
                }

                if (context.Parameter.Specification.IsCollection) {
                    var itemSpec = context.Parameter.ElementType;

                    if (itemSpec.IsParseable) {
                        return html.GetAndParseValueAsNakedObject(context, rawvalue);
                    }

                    return modelValue;
                }

                return context.Parameter.Specification.IsParseable ? html.GetAndParseValueAsNakedObject(context, rawvalue) : modelValue;
            }
            return null;
        }
 private static void AddAutoCompleteControl(this HtmlHelper html, TagBuilder tag, RouteValueDictionary htmlAttributes, ParameterContext context, IObjectFacade valueNakedObject) {
     tag.InnerHtml += html.GetAutoCompleteTextBox(context, htmlAttributes, valueNakedObject) + html.GetMandatoryIndicator(context) + html.ValidationMessage(context.GetParameterAutoCompleteId());
 }
        private static IObjectFacade GetParameterDefaultValue(this HtmlHelper html, string id, ParameterContext context, bool clear = false) {
            object value = html.ViewData.TryGetValue(id, out value) ? value : null;

            if (value != null) {
                if (clear) {
                    html.ViewData.Remove(id);
                }
                return context.Parameter.Specification.IsParseable ? html.GetAndParseValueAsNakedObject(context, value) : (IObjectFacade)value;
            }
            return null;
        }
 private static void AddPasswordControl(this HtmlHelper html, TagBuilder tag, RouteValueDictionary htmlAttributes, ParameterContext context, string id, string value) {
     var length = context.Parameter.TypicalLength;
     htmlAttributes["size"] = length == 0 ? 20 : length;
     tag.InnerHtml += html.Password(id, value, htmlAttributes) + html.GetMandatoryIndicator(context) + html.ValidationMessage(id);
 }
 private static IEnumerable<SelectListItem> GetChoicesSet(this HtmlHelper html,
                                                          ParameterContext parameterContext,
                                                          IObjectFacade existingNakedObject,
                                                          IDictionary<string, IObjectFacade> values) {
     var nakedObjects = parameterContext.Parameter.GetChoices(parameterContext.Target, values.ToDictionary(kvp => kvp.Key, kvp => kvp.Value == null ? null : kvp.Value.Object)).ToList();
     return html.GetChoicesSet(nakedObjects, existingNakedObject);
 }
Ejemplo n.º 27
0
 public ParameterContext(ParameterContext otherContext) : base(otherContext) {
     Parameter = otherContext.Parameter;
 }
 private static string GetLabel(this HtmlHelper html, ParameterContext parameterContext) {
     if (parameterContext.IsHidden) {
         return "";
     }
     bool isAutoComplete = parameterContext.Parameter.IsAutoCompleteEnabled;
     Func<string> parmId = isAutoComplete ? (Func<string>)parameterContext.GetParameterAutoCompleteId : parameterContext.GetParameterInputId;
     return GetLabelTag(parameterContext.IsParameterEdit || isAutoComplete, parameterContext.Parameter.Name, parmId);
 }
Ejemplo n.º 29
0
 public ParameterContext(ParameterContext otherContext) : base(otherContext)
 {
     Parameter = otherContext.Parameter;
 }
Ejemplo n.º 30
0
        private static string GetFieldValue(this HtmlHelper html, ParameterContext context, INakedObject valueNakedObject) {
            string value = "";

            if (context.Parameter.IsAutoCompleteEnabled) {
                var htmlAttributes = new RouteValueDictionary(new {title = context.Parameter.Description});

                html.AddClientValidationAttributes(context, htmlAttributes);
                value += html.GetAutoCompleteTextBox(context, htmlAttributes, valueNakedObject);
            }
            else if (valueNakedObject != null) {
                string link = "{0}";

                if (context.Parameter.Specification.IsCollection) {
                    link = html.CollectionLink(link, IdHelper.ViewAction, valueNakedObject.Object);
                }
                else if (!context.Parameter.Specification.IsParseable && context.Parameter.IsObject) {
                    link = html.ObjectLink(link, IdHelper.ViewAction, valueNakedObject.Object);
                }

                string title = GetDisplayTitle(context.Parameter, valueNakedObject);
                value += string.Format(link, title);
            }

            return value;
        }