Пример #1
0
        protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            var binding = new KnockoutBindingGroup();

            binding.Add("component", (string)GetValue(NameProperty));
            binding.Add("props", CreateProps().ToString());
            writer.AddKnockoutDataBind("dotvvm-contrib-ReactBridge", binding);
            Attributes.Clear();
        }
Пример #2
0
        protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            var knockoutBindingGroup = new KnockoutBindingGroup();

            {
                knockoutBindingGroup.Add("swPath", this, ServiceWorkerPathProperty);
                knockoutBindingGroup.Add("scope", this, ScopeProperty);
            }
            writer.AddKnockoutDataBind("dotvvm-pwa-registerServiceWorker", knockoutBindingGroup);
        }
Пример #3
0
        private KnockoutBindingGroup BuildKnockoutBindingsInputAttributes()
        {
            var bindings = new KnockoutBindingGroup();

            bindings.Add("id", this, NameProperty, () =>
            {
                bindings.Add("id", Name, true);
            });

            return(bindings);
        }
        public static void AddNegation(this KnockoutBindingGroup group, string name, DotvvmControl control, DotvvmProperty property, Func <bool> nullBindingAction)
        {
            var binding = control.GetValueBinding(property);

            if (binding == null)
            {
                group.Add(name, (!nullBindingAction()).ToString().ToLower());
            }
            else
            {
                string expression = control.GetValueBinding(property).GetKnockoutBindingExpression();
                group.Add(name, $"!{expression}()");
            }
        }
        public static void AddSimpleBinding(this KnockoutBindingGroup group, string name, DotvvmControl control, DotvvmProperty property)
        {
            var binding = control.GetValueBinding(property);

            if (binding == null)
            {
                string value = JsonConvert.ToString(property.GetValue(control));
                group.Add(name, value, false);
            }
            else
            {
                string expression = control.GetValueBinding(property).GetKnockoutBindingExpression();
                group.Add(name, $"{expression}");
            }
        }
Пример #6
0
        KnockoutBindingGroup CreateProps()
        {
            var props = new KnockoutBindingGroup();

            foreach (var attr in Attributes)
            {
                props.Add(attr.Key,
                          attr.Value is IValueBinding binding ? $"dotvvm.serialization.serialize({binding.GetKnockoutBindingExpression()})" :
                          (attr.Value is IStaticValueBinding staticBinding ? staticBinding.Evaluate(this) : attr.Value).Apply(JsonConvert.SerializeObject)
                          );
            }
            foreach (var update in this.Update)
            {
                props.Add(update.Key, "function (a) {(" + update.Value.GetKnockoutBindingExpression() + ")(a)}");
            }
            return(props);
        }
        private static void AddBindProperty(IHtmlWriter writer, IDotvvmRequestContext context, DotvvmPropertyGroup group, DotvvmControl control, IEnumerable <DotvvmProperty> properties)
        {
            var bindingGroup = new KnockoutBindingGroup();

            foreach (var prop in properties)
            {
                bindingGroup.Add(prop.Name.Split(':')[1], control, prop);
            }
            writer.AddKnockoutDataBind("fast-attr", bindingGroup);
        }
Пример #8
0
        protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            this.AddDotvvmUniqueIdAttribute();
            base.AddAttributesToRender(writer, context);

            var group = new KnockoutBindingGroup();

            group.Add("html", this, HtmlProperty);

            writer.AddKnockoutDataBind("dotvvm-contrib-CkEditorMinimal", group);
        }
Пример #9
0
        private KnockoutBindingGroup BuildKnockoutBidningLabelAttributes()
        {
            var bindings = new KnockoutBindingGroup();

            bindings.Add("for", this, NameProperty, () =>
            {
                bindings.Add("for", Name);
            });
            bindings.Add("style",
                         "'background-image:url(\"'+"
                         + GetValueBinding(IconProperty).GetKnockoutBindingExpression()
                         + "()"
                         + "+'\");"
                         + "color: black;"
                         + "text-shadow: 2px 0 0 #fff, -2px 0 0 #fff, 0 2px 0 #fff, 0 -2px 0 #fff, 1px 1px #fff, -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff;"
                         + "width:150px;"
                         + "height:150px;"
                         + "display:inline-block;"
                         + "background-size:150px, 150px'");
            return(bindings);
        }
        protected KnockoutBindingGroup BuildControlKnockoutBinding()
        {
            var binding = new KnockoutBindingGroup();

            binding.Add("maxItemsCount", this, MaxItemsCountProperty, () =>
            {
                binding.Add("maxItemsCount", MaxItemsCount.ToString());
            });

            binding.Add("groupName", this, GroupNameProperty, () =>
            {
                binding.Add("groupName", KnockoutHelper.MakeStringLiteral(GroupName));
            });

            binding.Add("allowedOperations", KnockoutHelper.MakeStringLiteral(AllowedOperations.ToString()));

            if (HasBinding(ItemDroppedProperty))
            {
                var tempContainer = GetDataContextTarget(this, ItemDroppedProperty);
                var function      = KnockoutHelper.GenerateClientPostBackExpression(nameof(ItemDropped), GetCommandBinding(ItemDroppedProperty), tempContainer, new PostbackScriptOptions()
                {
                    ElementAccessor = CodeParameterAssignment.FromIdentifier("target")
                });
                binding.Add("onItemDropped", $"function (target) {{ {function} }}");
            }

            return(binding);
        }
        public static void AddExtender(this KnockoutBindingGroup group, string name, DotvvmControl control, DotvvmProperty property, string extenderName)
        {
            var binding = control.GetValueBinding(property);

            if (binding == null)
            {
                throw new NotSupportedException();
                //group.Add(name, (!nullBindingAction()).ToString().ToLower());
            }
            else
            {
                string expression = control.GetValueBinding(property).GetKnockoutBindingExpression();
                group.Add(name, $"{expression}.{extenderName}");
            }
        }
        public static void WriteRouteLinkHrefAttribute(RouteLink control, IHtmlWriter writer, IDotvvmRequestContext context)
        {
            // Render client-side knockout expression only if there exists a parameter with value binding
            var containsBindingParam = control.Params.RawValues.Any(p => p.Value is IValueBinding);

            if (containsBindingParam)
            {
                var group = new KnockoutBindingGroup();
                group.Add("href", GenerateKnockoutHrefExpression(control.RouteName, control, context));
                writer.AddKnockoutDataBind("attr", group);
            }

            if (control.RenderOnServer || !containsBindingParam)
            {
                writer.AddAttribute("href", EvaluateRouteUrl(control.RouteName, control, context));
            }
        }