Пример #1
0
 public virtual void Add(string name, DotvvmControl control, DotvvmProperty property, Action? nullBindingAction = null)
 {
     var binding = control.GetValueBinding(property);
     if (binding == null)
     {
         if (nullBindingAction != null) nullBindingAction();
         else Add(name, JsonConvert.SerializeObject(control.GetValue(property), DefaultViewModelSerializer.CreateDefaultSettings()));
     }
     else
     {
         entries.Add(new KnockoutBindingInfo(name, GetKnockoutBindingExpression(control, binding)));
     }
 }
Пример #2
0
        private static void AddValidatedValue(IHtmlWriter writer, IDotvvmRequestContext context, DotvvmProperty prop, DotvvmControl control)
        {
            writer.AddKnockoutDataBind("dotvvmValidation", control, ValueProperty, renderEvenInServerRenderingMode: true);

            // render options
            var bindingGroup = new KnockoutBindingGroup();

            foreach (var property in ValidationOptionProperties)
            {
                var javascriptName = KnockoutHelper.ConvertToCamelCase(property.Name);
                var optionValue    = control.GetValue(property);
                if (!object.Equals(optionValue, property.DefaultValue))
                {
                    bindingGroup.Add(javascriptName, JsonConvert.SerializeObject(optionValue, DefaultViewModelSerializer.CreateDefaultSettings()));
                }
            }
            writer.AddKnockoutDataBind("dotvvmValidationOptions", bindingGroup);
        }
Пример #3
0
        private static void AddValidatedValue(IHtmlWriter writer, RenderContext context, object value, DotvvmControl control)
        {
            writer.AddKnockoutDataBind("dotvvmValidation", control, ValidatedValueProperty);

            // render options
            var bindingGroup = new KnockoutBindingGroup();

            foreach (var property in ValidationOptionProperties)
            {
                var javascriptName = property.Name.Substring(0, 1).ToLower() + property.Name.Substring(1);
                var optionValue    = control.GetValue(property);
                if (!object.Equals(optionValue, property.DefaultValue))
                {
                    bindingGroup.Add(javascriptName, JsonConvert.SerializeObject(optionValue));
                }
            }
            writer.AddKnockoutDataBind("dotvvmValidationOptions", bindingGroup);
        }
Пример #4
0
        /// <summary>
        /// Generates a list of postback update handlers.
        /// </summary>
        private static string GetPostBackHandlersScript(DotvvmControl control, string eventName)
        {
            var handlers = (List <PostBackHandler>)control.GetValue(PostBack.HandlersProperty);

            if (handlers == null)
            {
                return("null");
            }

            var effectiveHandlers = handlers.Where(h => string.IsNullOrEmpty(h.EventName) || h.EventName == eventName);
            var sb = new StringBuilder();

            sb.Append("[");
            foreach (var handler in effectiveHandlers)
            {
                if (sb.Length > 1)
                {
                    sb.Append(",");
                }
                sb.Append("{name:'");
                sb.Append(handler.ClientHandlerName);
                sb.Append("',options:function(){return {");

                var isFirst = true;
                var options = handler.GetHandlerOptionClientExpressions();
                options.Add("enabled", handler.TranslateValueOrBinding(PostBackHandler.EnabledProperty));
                foreach (var option in options)
                {
                    if (!isFirst)
                    {
                        sb.Append(',');
                    }
                    isFirst = false;

                    sb.Append(option.Key);
                    sb.Append(":");
                    sb.Append(option.Value);
                }
                sb.Append("};}}");
            }
            sb.Append("]");
            return(sb.ToString());
        }
Пример #5
0
 public static IEnumerable <string> GetContextPath(DotvvmControl control)
 {
     while (control != null)
     {
         var pathFragment = control.GetValue(Internal.PathFragmentProperty, false) as string;
         if (pathFragment != null)
         {
             yield return(pathFragment);
         }
         else
         {
             var dataContextBinding = control.GetBinding(DotvvmBindableObject.DataContextProperty, false) as IValueBinding;
             if (dataContextBinding != null)
             {
                 yield return(dataContextBinding.GetKnockoutBindingExpression());
             }
         }
         control = control.Parent;
     }
 }
Пример #6
0
        public void Add(string name, DotvvmControl control, DotvvmProperty property, Action nullBindingAction = null)
        {
            var binding = control.GetValueBinding(property);

            if (binding == null)
            {
                if (nullBindingAction != null)
                {
                    nullBindingAction();
                }
                else
                {
                    Add(name, JsonConvert.SerializeObject(control.GetValue(property)));
                }
            }
            else
            {
                entries.Add(new KnockoutBindingInfo()
                {
                    Name = name, Expression = control.GetValueBinding(property).GetKnockoutBindingExpression(control)
                });
            }
        }
Пример #7
0
 /// <summary>
 /// Determines whether the specified control is a naming container.
 /// </summary>
 public static bool IsNamingContainer(DotvvmControl control)
 {
     return((bool)control.GetValue(Internal.IsNamingContainerProperty));
 }