Ejemplo n.º 1
0
        private bool TouchProperty(DotvvmProperty prop, object?value, ref RenderState r)
        {
            if (prop == TextProperty)
            {
                r.Text = value;
            }
            else if (prop == RenderSpanElementProperty)
            {
                r.RenderSpanElement = (bool)EvalPropertyValue(RenderSpanElementProperty, value) !;
            }
#pragma warning disable CS0618
            else if (prop == FormatStringProperty || prop == ValueTypeProperty)
#pragma warning restore CS0618
            {
                r.HasFormattingStuff = true;
            }
            else if (base.TouchProperty(prop, value, ref r.HtmlState))
            {
            }
            else if (DotvvmControl.TouchProperty(prop, value, ref r.BaseState))
            {
            }
            else
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public static void AddKnockoutDataBind(this IHtmlWriter writer, string name, DotvvmControl control, DotvvmProperty property, Action nullBindingAction = null,
                                               string valueUpdate = null, bool renderEvenInServerRenderingMode = false, bool setValueBack = false)
        {
            var expression = control.GetValueBinding(property);

            if (expression != null && (!control.RenderOnServer || renderEvenInServerRenderingMode))
            {
                writer.AddAttribute("data-bind", name + ": " + expression.GetKnockoutBindingExpression(), true, ", ");
                if (valueUpdate != null)
                {
                    writer.AddAttribute("data-bind", "valueUpdate: '" + valueUpdate + "'", true, ", ");
                }
            }
            else
            {
                if (nullBindingAction != null)
                {
                    nullBindingAction();
                }
                if (setValueBack && expression != null)
                {
                    control.SetValue(property, expression.Evaluate(control, property));
                }
            }
        }
Ejemplo n.º 3
0
        public void BuildContent(IDotvvmRequestContext context, DotvvmControl container)
        {
            var controlBuilderFactory = context.Configuration.ServiceLocator.GetService <IControlBuilderFactory>();
            var control = BuildContentBody(controlBuilderFactory);

            container.Children.Add(control);
        }
Ejemplo n.º 4
0
 protected bool TouchProperty(DotvvmProperty prop, object value, ref RenderState r)
 {
     if (prop == TextProperty)
     {
         r.Text = value;
     }
     else if (prop == RenderSpanElementProperty)
     {
         r.RenderSpanElement = (bool)EvalPropertyValue(RenderSpanElementProperty, value);
     }
     else if (prop == FormatStringProperty || prop == ValueTypeProperty)
     {
         r.HasFormattingStuff = true;
     }
     else if (base.TouchProperty(prop, value, ref r.HtmlState))
     {
     }
     else if (DotvvmControl.TouchProperty(prop, value, ref r.BaseState))
     {
     }
     else
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 5
0
 public override void CreateEditControls(IDotvvmRequestContext context, DotvvmControl container)
 {
     if (EditTemplate == null)
     {
         throw new DotvvmControlException(this, "EditTemplate must be set, when editting is allowed in a GridView.");
     }
     EditTemplate.BuildContent(context, container);
 }
Ejemplo n.º 6
0
        public override void CreateEditControls(IDotvvmRequestContext context, DotvvmControl container)
        {
            var textBox = new TextBox();

            textBox.SetBinding(TextBox.TextProperty, GetValueBinding(ValueBindingProperty));

            container.Children.Add(textBox);
        }
Ejemplo n.º 7
0
        public override void CreateControls(IDotvvmRequestContext context, DotvvmControl container)
        {
            var literal = new Literal();

            literal.FormatString = FormatString;
            literal.SetBinding(Literal.TextProperty, GetValueBinding(ValueBindingProperty));

            container.Children.Add(literal);
        }
Ejemplo n.º 8
0
        public override void CreateEditControls(IDotvvmRequestContext context, DotvvmControl container)
        {
            var checkBox = new CheckBox {
                Enabled = true
            };

            checkBox.SetBinding(CheckableControlBase.CheckedProperty, GetValueBinding(ValueBindingProperty));
            container.Children.Add(checkBox);
        }
Ejemplo n.º 9
0
        public override void CreateEditControls(IDotvvmRequestContext context, DotvvmControl container)
        {
            var textBox = new TextBox();

            textBox.FormatString = FormatString;
            textBox.ValueType    = ValueType;
            textBox.SetBinding(TextBox.TextProperty, ValueBinding);

            container.Children.Add(textBox);
        }
Ejemplo n.º 10
0
        private void CreateControlsCore(DotvvmControl container, bool enabled)
        {
            var checkBox = new CheckBox {
                Enabled = enabled
            };
            var valueBinding = GetValueBinding(ValueBindingProperty);

            checkBox.SetBinding(CheckBox.CheckedProperty, valueBinding);
            Validator.Place(checkBox, container.Children, valueBinding, ValidatorPlacement);
            container.Children.Add(checkBox);
        }
Ejemplo n.º 11
0
        public override void CreateControls(IDotvvmRequestContext context, DotvvmControl container)
        {
            var literal = new Literal();

            literal.FormatString = FormatString;
            #pragma warning disable
            literal.ValueType = ValueType;
            #pragma warning restore
            literal.SetBinding(Literal.TextProperty, ValueBinding);
            Validator.Place(literal, container.Children, ValueBinding, ValidatorPlacement);
            container.Children.Add(literal);
        }
Ejemplo n.º 12
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)));
     }
 }
Ejemplo n.º 13
0
        public override void CreateEditControls(IDotvvmRequestContext context, DotvvmControl container)
        {
            var textBox = new TextBox();

            textBox.FormatString = FormatString;
            #pragma warning disable
            textBox.ValueType = ValueType;
            #pragma warning restore

            textBox.SetBinding(TextBox.TextProperty, ValueBinding);
            textBox.SetBinding(TextBox.ChangedProperty, ChangedBinding);
            Validator.Place(textBox, container.Children, ValueBinding, ValidatorPlacement);
            container.Children.Add(textBox);
        }
Ejemplo n.º 14
0
        public void Add(string name, DotvvmControl control, DotvvmProperty property, Action nullBindingAction)
        {
            var binding = control.GetValueBinding(property);

            if (binding == null)
            {
                nullBindingAction();
            }
            else
            {
                entries.Add(new KnockoutBindingInfo()
                {
                    Name = name, Expression = control.GetValueBinding(property).GetKnockoutBindingExpression()
                });
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Finds the control by its unique ID.
        /// </summary>
        public DotvvmControl FindControlByUniqueId(string controlUniqueId)
        {
            var           parts  = controlUniqueId.Split('_');
            DotvvmControl result = this;

            for (var i = 0; i < parts.Length; i++)
            {
                result = result.GetAllDescendants(c => !IsNamingContainer(c))
                         .SingleOrDefault(c => c.GetValue(Internal.UniqueIDProperty).Equals(parts[i]));
                if (result == null)
                {
                    return(null);
                }
            }
            return(result);
        }
Ejemplo n.º 16
0
        private void CreateRow(IDotvvmRequestContext context, DataItemContainer placeholder)
        {
            var row = new HtmlGenericControl("tr");

            DotvvmControl container = row;

            foreach (var decorator in RowDecorators)
            {
                var decoratorInstance = decorator.Clone();
                decoratorInstance.Children.Add(container);
                container = decoratorInstance;
            }
            placeholder.Children.Add(container);

            var isEdit = false;

            if (InlineEditing == true)
            {
                // if gridviewdataset is missing throw exception
                if (!(DataSource is IGridViewDataSet))
                {
                    throw new ArgumentException("You have to use GridViewDataSet with InlineEditing enabled.");
                }
                //checks if row is being edited
                isEdit = IsEditedRow(placeholder);
            }

            // create cells
            foreach (var column in Columns)
            {
                var cell = new HtmlGenericControl("td");
                SetCellAttributes(column, cell, false);
                row.Children.Add(cell);

                if (isEdit && column.IsEditable)
                {
                    column.CreateEditControls(context, cell);
                }
                else
                {
                    column.CreateControls(context, cell);
                }
            }
        }
Ejemplo n.º 17
0
        private HtmlGenericControl CreateRow(DataItemContainer placeholder, bool isInEditMode)
        {
            var row = new HtmlGenericControl("tr");

            DotvvmControl container  = row;
            var           decorators = isInEditMode ? EditRowDecorators : RowDecorators;

            if (decorators != null)
            {
                foreach (var decorator in decorators)
                {
                    var decoratorInstance = decorator.Clone();
                    decoratorInstance.Children.Add(container);
                    container = decoratorInstance;
                }
            }
            placeholder.Children.Add(container);
            return(row);
        }
Ejemplo n.º 18
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());
        }
Ejemplo n.º 19
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;
     }
 }
Ejemplo n.º 20
0
        public void DataBindItem(DotvvmControl parent, IHierarchyItem item, IDotvvmRequestContext context)
        {
            // render item template
            var templatePlaceholder = new PlaceHolder();

            templatePlaceholder.DataContext = item;
            parent.Children.Add(templatePlaceholder);

            ItemTemplate.BuildContent(context, templatePlaceholder);
            if (item.Children.Any())
            {
                // wrap children in div
                var childContainer = new HtmlGenericControl("div");
                childContainer.Attributes["class"] = "child-container";
                foreach (var child in item.Children)
                {
                    DataBindItem(childContainer, child, context);
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Performs the data-binding and builds the controls inside the <see cref="Repeater"/>.
        /// </summary>
        private void SetChildren(IDotvvmRequestContext context, bool renderClientTemplate, bool memoizeReferences)
        {
            Children.Clear();
            emptyDataContainer = null;
            clientSeparator    = null;
            clientSideTemplate = null;

            if (DataSource != null)
            {
                var itemBinding = GetItemBinding();
                var index       = 0;
                foreach (var item in GetIEnumerableFromDataSource())
                {
                    if (SeparatorTemplate != null && index > 0)
                    {
                        Children.Add(GetSeparator(context));
                    }
                    Children.Add(GetItem(context, item, index,
                                         allowMemoizationRetrive: context.IsPostBack && !memoizeReferences, // on GET request we are not initializing the Repeater twice
                                         allowMemoizationStore: memoizeReferences
                                         ));
                    index++;
                }
            }

            if (renderClientTemplate)
            {
                if (SeparatorTemplate != null)
                {
                    Children.Add(clientSeparator = GetSeparator(context));
                }

                Children.Add(clientSideTemplate = GetItem(context));
            }

            if (EmptyDataTemplate != null)
            {
                Children.Add(GetEmptyItem(context));
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Performs the data-binding and builds the controls inside the <see cref="Repeater"/>.
        /// </summary>
        private void SetChildren(IDotvvmRequestContext context, bool useServerTemplate)
        {
            Children.Clear();
            emptyDataContainer = null;
            clientSeparator    = null;

            if (useServerTemplate)
            {
                if (DataSource != null)
                {
                    var itemBinding = GetItemBinding();
                    var index       = 0;
                    foreach (var item in GetIEnumerableFromDataSource())
                    {
                        if (SeparatorTemplate != null && index > 0)
                        {
                            Children.Add(GetSeparator(context));
                        }
                        Children.Add(GetItem(context, item, index));
                        index++;
                    }
                }
            }
            else
            {
                if (SeparatorTemplate != null)
                {
                    Children.Add(clientSeparator = GetSeparator(context));
                }

                Children.Add(GetItem(context));
            }

            if (EmptyDataTemplate != null)
            {
                Children.Add(GetEmptyItem(context));
            }
        }
Ejemplo n.º 23
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)
                });
            }
        }
Ejemplo n.º 24
0
        private void CreateTemplates(IDotvvmRequestContext context, DataItemContainer placeholder, bool createEditTemplates = false)
        {
            var row = new HtmlGenericControl("tr");

            DotvvmControl container = row;

            placeholder.Children.Add(container);


            // create cells
            foreach (var column in Columns)
            {
                var cell = new HtmlGenericControl("td");
                row.Children.Add(cell);
                if (createEditTemplates && column.IsEditable)
                {
                    column.CreateEditControls(context, cell);
                }
                else
                {
                    column.CreateControls(context, cell);
                }
            }
        }
Ejemplo n.º 25
0
        public static string GenerateClientPostBackScript(string propertyName, ICommandBinding expression, DotvvmControl control, PostbackScriptOptions options)
        {
            object uniqueControlId = null;

            if (expression is ControlCommandBindingExpression)
            {
                var target = (DotvvmControl)control.GetClosestControlBindingTarget();
                uniqueControlId = target.GetDotvvmUniqueId();
            }

            var arguments = new List <string>()
            {
                "'root'",
                options.ElementAccessor,
                "[" + String.Join(", ", GetContextPath(control).Reverse().Select(p => '"' + p + '"')) + "]",
                (uniqueControlId is IValueBinding ? "{ expr: " + JsonConvert.ToString(((IValueBinding)uniqueControlId).GetKnockoutBindingExpression(), '\'', StringEscapeHandling.Default) + "}" : "'" + (string)uniqueControlId + "'"),
                options.UseWindowSetTimeout ? "true" : "false",
                JsonConvert.SerializeObject(GetValidationTargetExpression(control)),
                "null",
                GetPostBackHandlersScript(control, propertyName)
            };

            // return the script
            var condition       = options.IsOnChange ? "if (!dotvvm.isViewModelUpdating) " : null;
            var returnStatement = options.ReturnValue != null ? $";return {options.ReturnValue.ToString().ToLower()};" : "";

            // call the function returned from binding js with runtime arguments
            var postBackCall = $"{expression.GetCommandJavascript()}({String.Join(", ", arguments)})";

            return(condition + postBackCall + returnStatement);
        }
Ejemplo n.º 26
0
 public static string GenerateClientPostBackScript(string propertyName, ICommandBinding expression, DotvvmControl control, bool useWindowSetTimeout = false,
                                                   bool?returnValue = false, bool isOnChange = false, string elementAccessor = "this")
 {
     return(GenerateClientPostBackScript(propertyName, expression, control, new PostbackScriptOptions(useWindowSetTimeout, returnValue, isOnChange, elementAccessor)));
 }
Ejemplo n.º 27
0
 public static void WriteKnockoutDataBindComment(this IHtmlWriter writer, string name, DotvvmControl control, DotvvmProperty property)
 {
     writer.WriteUnencodedText($"<!-- ko { name }: { control.GetValueBinding(property).GetKnockoutBindingExpression() } -->");
 }
Ejemplo n.º 28
0
 public static void AddKnockoutDataBind(this IHtmlWriter writer, string name, IEnumerable <KeyValuePair <string, IValueBinding> > expressions, DotvvmControl control, DotvvmProperty property)
 {
     writer.AddAttribute("data-bind", name + ": {" + String.Join(",", expressions.Select(e => "'" + e.Key + "': " + e.Value.GetKnockoutBindingExpression())) + "}", true, ", ");
 }
Ejemplo n.º 29
0
        public void BuildContent(IDotvvmRequestContext context, DotvvmControl container)
        {
            var controlBuilderFactory = context.Services.GetRequiredService <IControlBuilderFactory>();

            BuildContentBody.Invoke(controlBuilderFactory, context.Services, container);
        }
Ejemplo n.º 30
0
 public abstract void CreateEditControls(IDotvvmRequestContext context, DotvvmControl container);