예제 #1
0
        protected internal virtual ModifiableEntity ExtractEntity(ControllerBase controller, string prefix)
        {
            NameValueCollection form = controller.ControllerContext.HttpContext.Request.Form;

            var state = form[TypeContextUtilities.Compose(prefix, EntityBaseKeys.EntityState)];

            if (state.HasText())
            {
                return(Navigator.Manager.DeserializeEntity(state));
            }


            var key = TypeContextUtilities.Compose(prefix, EntityBaseKeys.RuntimeInfo);

            RuntimeInfo runtimeInfo = RuntimeInfo.FromFormValue(form[key]);

            if (runtimeInfo == null)
            {
                throw new ArgumentNullException("{0} not found in form request".FormatWith(key));
            }

            if (runtimeInfo.EntityType.IsEntity() && !runtimeInfo.IsNew)
            {
                return(Database.Retrieve(runtimeInfo.EntityType, runtimeInfo.IdOrNull.Value));
            }
            else
            {
                return(new ConstructorContext(controller).ConstructUntyped(runtimeInfo.EntityType));
            }
        }
예제 #2
0
        public static MvcHtmlString TimePicker(this HtmlHelper helper, string name, bool formGroup, string value, string dateFormat, IDictionary <string, object> htmlProps = null)
        {
            if (dateFormat.Contains("f") || dateFormat.Contains("F"))
            {
                htmlProps["class"] += " form-control";
                return(helper.TextBox(TypeContextUtilities.Compose(name, "Time"), value, htmlProps));
            }

            var input = new HtmlTag("input")
                        .IdName(name)
                        .Attr("type", "text")
                        .Class("form-control")
                        .Attrs(htmlProps)
                        .Attr("value", value);

            if (!formGroup)
            {
                return(AttachTimePiceker(input, dateFormat));
            }

            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(AttachTimePiceker(new HtmlTag("div").Class("input-group time"), dateFormat)))
            {
                sb.Add(input);

                using (sb.SurroundLine(new HtmlTag("span").Class("input-group-addon")))
                    sb.Add(new HtmlTag("span").Class("glyphicon glyphicon-time"));
            }

            return(sb.ToHtml());
        }
예제 #3
0
        internal static IWidget CreateWidget(WidgetContext ctx)
        {
            var ident = ctx.Entity as Entity;

            if (ident == null || ident.IsNew)
            {
                return(null);
            }

            List <QuickLink> quicklinks = LinksClient.GetForEntity(ident.ToLiteFat(), ctx.PartialViewName, ctx.Prefix, null, ctx.Url);

            if (quicklinks == null || quicklinks.Count == 0)
            {
                return(null);
            }

            return(new Widget
            {
                Id = TypeContextUtilities.Compose(ctx.Prefix, "quicklinksWidget"),
                Class = "sf-quicklinks",
                Title = QuickLinkMessage.Quicklinks.NiceToString(),
                IconClass = "glyphicon glyphicon-star",
                Text = quicklinks.Count.ToString(),
                Items = quicklinks.OrderBy(a => a.Order).Cast <IMenuItem>().ToList(),
                Active = true,
            });
        }
예제 #4
0
        public override MvcHtmlString Execute()
        {
            JObject jsFindOptions = FindOptions.ToJS(TypeContextUtilities.Compose("New", Prefix));

            return(new HtmlTag("a")
                   .Attr("onclick", JsModule.Finder["explore"](jsFindOptions).ToString())
                   .InnerHtml(TextAndIcon()));
        }
예제 #5
0
        public SubContext <P> CreateSubContext(MappingContext <T> parent)
        {
            string        newPrefix = TypeContextUtilities.Compose(parent.Prefix, PropertyValidator.PropertyInfo.Name);
            PropertyRoute route     = parent.PropertyRoute.Add(this.PropertyValidator.PropertyInfo);

            SubContext <P> ctx = new SubContext <P>(newPrefix, PropertyValidator, route, parent);

            if (parent.Value != null)
            {
                ctx.Value = GetValue(parent.Value);
            }
            return(ctx);
        }
예제 #6
0
        public IEnumerable <MappingContext <S> > GenerateItemContexts(MappingContext <MList <S> > ctx)
        {
            PropertyRoute route = ctx.PropertyRoute.Add("Item");

            var indexPrefixes = ctx.Inputs.IndexPrefixes();

            foreach (var index in indexPrefixes.OrderBy(ip => (ctx.GlobalInputs.TryGetC(TypeContextUtilities.Compose(ctx.Prefix, ip, EntityListBaseKeys.Index)) ?? ip).ToInt()))
            {
                SubContext <S> itemCtx = new SubContext <S>(TypeContextUtilities.Compose(ctx.Prefix, index), null, route, ctx);

                yield return(itemCtx);
            }
        }
예제 #7
0
        protected internal virtual Lite <T> ExtractLite <T>(ControllerBase controller, string prefix)
            where T : class, IEntity
        {
            NameValueCollection form        = controller.ControllerContext.HttpContext.Request.Form;
            RuntimeInfo         runtimeInfo = RuntimeInfo.FromFormValue(form[TypeContextUtilities.Compose(prefix, EntityBaseKeys.RuntimeInfo)]);

            if (!runtimeInfo.IdOrNull.HasValue)
            {
                throw new ArgumentException("Could not create a Lite without an Id");
            }

            return((Lite <T>)runtimeInfo.ToLite());
        }
예제 #8
0
        public bool Parse <V>(string property, out V value)
        {
            var mapping = Mapping.ForValue <V>();

            if (mapping == null)
            {
                throw new InvalidOperationException("No mapping for value {0}".FormatWith(typeof(V).TypeName()));
            }

            var sc = new SubContext <V>(TypeContextUtilities.Compose(this.Prefix, property), null, null, this);

            value = mapping(sc);

            return(!sc.SupressChange);
        }
예제 #9
0
        public override MList <S> GetValue(MappingContext <MList <S> > ctx)
        {
            using (HeavyProfiler.LogNoStackTrace("GetValue", () => "MListDictionaryMapping<{0}>".FormatWith(typeof(S).TypeName())))
            {
                if (ctx.Empty())
                {
                    return(ctx.None());
                }

                MList <S> list = ctx.Value;

                var dic = (FilterElements == null ? list : list.Where(FilterElements)).ToDictionary(GetKey);

                PropertyRoute route = ctx.PropertyRoute.Add("Item").Continue(MemberList);

                string[] namesToAppend = MemberList.Select(MemberAccessGatherer.GetName).NotNull().ToArray();

                foreach (MappingContext <S> itemCtx in GenerateItemContexts(ctx))
                {
                    var tce = new TypeContextExpression(new PropertyInfo[0], typeof(S), itemCtx.PropertyRoute, itemCtx.Value);

                    SubContext <K> subContext = new SubContext <K>(TypeContextUtilities.Compose(itemCtx.Prefix, namesToAppend), null, route, itemCtx);

                    subContext.Value = KeyMapping(subContext);

                    if (!dic.ContainsKey(subContext.Value) && OnlyIfPossible)
                    {
                        continue;
                    }

                    itemCtx.Value = dic.GetOrThrow(subContext.Value);

                    itemCtx.Value = ElementMapping(itemCtx);

                    ctx.AddChild(itemCtx);
                }

                return(list);
            }
        }
예제 #10
0
        public static MvcHtmlString DateTimePicker(this HtmlHelper helper, string name, bool formGroup, DateTime?value, string dateTimeFormat, CultureInfo culture = null, IDictionary <string, object> htmlProps = null)
        {
            var dateFormat = SplitDateTimeFormat(dateTimeFormat, culture);

            if (dateFormat.TimeFormat == null)
            {
                return(helper.DatePicker(name, formGroup, value?.ToString(dateFormat.DateFormat, culture), ToJsDateFormat(dateFormat.DateFormat), culture, htmlProps));
            }

            if (dateFormat.DateFormat == null)
            {
                return(helper.TimePicker(name, formGroup, value?.ToString(dateFormat.TimeFormat, culture), dateFormat.TimeFormat, htmlProps));
            }

            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("div", name).Class("date-time")))
            {
                sb.Add(helper.DatePicker(TypeContextUtilities.Compose(name, "Date"), formGroup, value?.ToString(dateFormat.DateFormat, culture), ToJsDateFormat(dateFormat.DateFormat), culture, htmlProps));
                sb.Add(helper.TimePicker(TypeContextUtilities.Compose(name, "Time"), formGroup, value?.ToString(dateFormat.TimeFormat, culture), dateFormat.TimeFormat, htmlProps));
            }
            return(sb.ToHtml());
        }
예제 #11
0
 public ToolBarButton(string prefix, string idToAppend) : this(TypeContextUtilities.Compose(prefix, idToAppend))
 {
 }
예제 #12
0
 public MenuItem(string prefix, string idToAppend) : this(TypeContextUtilities.Compose(prefix, idToAppend))
 {
 }
예제 #13
0
 public JObject ToJS(string parentPrefix, string newPart)
 {
     return(ToJS(TypeContextUtilities.Compose(parentPrefix, newPart)));
 }