public SingleControlTests()
        {
            context = new TestDotvvmRequestContext()
            {
                Configuration = configuration
            };
            writer = new HtmlWriter(new StringWriter(output), context);
            Internal.MarkupFileNameProperty.SetValue(rootView, "some_fake_path");
            Internal.RequestContextProperty.SetValue(rootView, "some_fake_path");

            var bcs         = context.Services.GetService <BindingCompilationService>();
            var dataContext = DataContextStack.Create(typeof(TestViewModel));

            Internal.DataContextTypeProperty.SetValue(rootView, dataContext);
            DotvvmBindableObject.DataContextProperty.SetValue(rootView, viewModel);

            testValueBinding = ValueBindingExpression.CreateBinding(bcs, h => ((TestViewModel)h[0]).Property, dataContext);
            boolValueBinding = ValueBindingExpression.CreateBinding(bcs, h => ((TestViewModel)h[0]).Property == 0, dataContext);

            basicHtmlElement = new HtmlGenericControl("div");
            richHtmlElement  = new HtmlGenericControl("div");
            HtmlGenericControl.IncludeInPageProperty.SetValue(richHtmlElement, boolValueBinding);
            HtmlGenericControl.CssClassesGroupDescriptor.GetDotvvmProperty("my-class").SetValue(richHtmlElement, boolValueBinding);
            HtmlGenericControl.CssStylesGroupDescriptor.GetDotvvmProperty("width").SetValue(richHtmlElement, testValueBinding);
            richHtmlElement.Attributes.Add("data-my-attr", "HELLO");
            richHtmlElement.Attributes.Add("title", new(testValueBinding));

            Internal.UniqueIDProperty.SetValue(basicHtmlElement, "c1");
            Internal.UniqueIDProperty.SetValue(richHtmlElement, "c1");
        }
        protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            context.ResourceManager.AddCurrentCultureGlobalizationResource();

            IValueBinding dateBinding = null;

            foreach (var item in properties)
            {
                if (item.Key == DateProperty)
                {
                    dateBinding = item.Value as IValueBinding;
                }
            }

            if (dateBinding == null)
            {
                var expression = dateBinding.GetKnockoutBindingExpression(this);
                expression = "dotvvm.globalize.formatString(" + JsonConvert.ToString("d.M.yyyy") + ", " + expression + ")";
                writer.AddKnockoutDataBind("dotvvm-contrib-BootstrapDatepicker", expression);
            }
            else
            {
                writer.AddKnockoutDataBind("dotvvm-contrib-BootstrapDatepicker", this, DateProperty, renderEvenInServerRenderingMode: true);
            }

            if (!string.IsNullOrWhiteSpace(Language))
            {
                writer.AddAttribute("data-date-language", Language);
            }

            base.AddAttributesToRender(writer, context);
        }
Exemple #3
0
        public static DotvvmControl GetContents(
            IValueBinding <IEnumerable <object> > dataSource,

            [ControlPropertyBindingDataContextChange("DataSource")]
            [CollectionElementDataContextChange(1)]
            IValueBinding <string> itemTextBinding,

            [ControlPropertyBindingDataContextChange("DataSource")]
            [CollectionElementDataContextChange(1)]
            IValueBinding <string> itemValueBinding,

            IValueBinding <string> selectedValue
            )
        {
            return(new Repeater()
            {
                WrapperTagName = "fluent-select",
                ItemTemplate = new DelegateTemplate(_ =>
                                                    new HtmlGenericControl("fluent-option")
                                                    .WithAttribute("value", itemValueBinding)
                                                    .WithProperty(HtmlGenericControl.InnerTextProperty, itemTextBinding))
            }
                   .WithProperty(Fast.BindGroupDescriptor.GetDotvvmProperty("value"), selectedValue)
                   .SetBinding(r => r.DataSource, dataSource));
        }
Exemple #4
0
        public static bool NeedsFormatting(IValueBinding binding)
        {
            bool isFormattedType(Type type) =>
            type != null && (type == typeof(float) || type == typeof(double) || type == typeof(decimal) || type == typeof(DateTime) || isFormattedType(Nullable.GetUnderlyingType(type)));

            bool isFormattedTypeOrObj(Type type) => type == typeof(object) || isFormattedType(type);

            return(isFormattedType(binding?.ResultType) && isFormattedTypeOrObj(binding?.GetProperty <ExpectedTypeBindingProperty>(ErrorHandlingMode.ReturnNull)?.Type));
        }
 public static DotvvmControl GetContents(
     [DefaultValue(null)] ValueOrBinding <string> text,
     [DefaultValue(null)] ITemplate contentTemplate,
     IValueBinding <bool> @checked
     )
 {
     return(new HtmlGenericControl("fluent-checkbox")
            .WithProperty(Fast.BindGroupDescriptor.GetDotvvmProperty("checked"), @checked)
            .WithInnerTextOrContent(text, contentTemplate));
 }
        public ListItemBinding(int itemIndex, IList parentObj, IValueBinding valueBinding)
        {
            Argument.Invariant(() => itemIndex, () => itemIndex >= 0);
            Argument.NotNull(() => parentObj);
            Argument.NotNull(() => valueBinding);

            this.ItemIndex = itemIndex;
            this.ValueBinding = valueBinding;

            this.parentList = parentObj;
        }
Exemple #7
0
        public ListItemBinding(int itemIndex, IList parentObj, IValueBinding valueBinding)
        {
            Argument.Invariant(() => itemIndex, () => itemIndex >= 0);
            Argument.NotNull(() => parentObj);
            Argument.NotNull(() => valueBinding);

            this.ItemIndex    = itemIndex;
            this.ValueBinding = valueBinding;

            this.parentList = parentObj;
        }
        public ObjectPropertyBinding(string propertyName, Type propertyType, object parentObj, IValueBinding valueBinding)
        {
            Argument.StringNotNullOrEmpty(() => propertyName);
            Argument.NotNull(() => propertyType);
            Argument.NotNull(() => parentObj);
            Argument.NotNull(() => valueBinding);

            this.PropertyName = propertyName;
            this.propertyType = propertyType;
            this.ValueBinding = valueBinding;

            // Don't need to connect, the value binding will already be connected.
            this.parentObject = parentObj;
        }
        public ArrayItemBinding(int itemIndex, Array parentArray, IValueBinding valueBinding)
        {
            Argument.Invariant(() => itemIndex, () => itemIndex >= 0);
            Argument.NotNull(() => parentArray);
            Argument.NotNull(() => valueBinding);


            if (itemIndex < 0)
            {
                throw new ArgumentException("Item index can't be less than 0.", "itemIndex");
            }

            this.ItemIndex    = itemIndex;
            this.ValueBinding = valueBinding;

            // Don't need to connect, the value binding will already be connected.
            this.parentArray = parentArray;
        }
Exemple #10
0
        public static bool NeedsFormatting(IValueBinding binding)
        {
            // bool isFormattedType(Type type) =>
            //     type != null && (type.IsNumericType() || type == typeof(DateTime) || isFormattedType(Nullable.GetUnderlyingType(type)));

            // bool isFormattedTypeOrObj(Type type) => type == typeof(object) || isFormattedType(type);

            // return isFormattedType(binding?.ResultType) && isFormattedTypeOrObj(binding?.GetProperty<ExpectedTypeBindingProperty>(ErrorHandlingMode.ReturnNull)?.Type);
            bool formatType(Type t) => !(t == null) && (t == typeof(DateTime) || t == typeof(float) || t == typeof(double) || t == typeof(decimal));

            if (binding == null)
            {
                return(true);
            }
            var rt = binding.ResultType;

            return(formatType(rt) || formatType(Nullable.GetUnderlyingType(rt)));
        }
Exemple #11
0
        public SelectorItemBindingProperty GetItemLambda(ParsedExpressionBindingProperty expression, DataContextStack dataContext, IValueBinding binding)
        {
            var argument = Expression.Parameter(dataContext.DataContextType, "i");

            return(new SelectorItemBindingProperty(binding.DeriveBinding(
                                                       dataContext.Parent,
                                                       Expression.Lambda(expression.Expression.ReplaceAll(e =>
                                                                                                          e.GetParameterAnnotation() is BindingParameterAnnotation annotation &&
                                                                                                          annotation.DataContext == dataContext &&
                                                                                                          annotation.ExtensionParameter == null ?
                                                                                                          argument :
                                                                                                          e), argument)
                                                       )));
        }
Exemple #12
0
 public static bool NeedsFormatting(IValueBinding binding) => binding != null && (binding.ResultType == typeof(DateTime) || binding.ResultType == typeof(DateTime?) ||
                                                                                  binding.ResultType.IsNumericType() || Nullable.GetUnderlyingType(binding.ResultType).IsNumericType());
 public SelectorItemBindingProperty(IValueBinding expression)
 {
     this.Expression = expression;
 }
Exemple #14
0
 protected virtual void WriteEnabledBinding(IHtmlWriter writer, IValueBinding binding)
 {
     writer.AddKnockoutDataBind("dotvvmEnable", binding.GetKnockoutBindingExpression(this));
 }
Exemple #15
0
 protected virtual void WriteEnabledBinding(IHtmlWriter writer, IValueBinding binding)
 {
     writer.AddKnockoutDataBind("dotvvmEnable", binding.GetKnockoutBindingExpression(this));
     writer.AddAttribute("onclick", "return !this.hasAttribute('disabled');");
 }
Exemple #16
0
        private void SetUpServerItem(IDotvvmRequestContext context, object item, int index, IValueBinding itemBinding, DataItemContainer container)
        {
            container.DataItemIndex = index;
            var bindingService = context.Configuration.ServiceLocator.GetService <BindingCompilationService>();

            container.SetBinding(DataContextProperty, ValueBindingExpression.CreateBinding(
                                     bindingService.WithoutInitialization(),
                                     j => item,
                                     itemBinding.KnockoutExpression.AssignParameters(p =>
                                                                                     p == JavascriptTranslator.CurrentIndexParameter ? new CodeParameterAssignment(index.ToString(), OperatorPrecedence.Max) :
                                                                                     default(CodeParameterAssignment))));
            container.SetValue(Internal.PathFragmentProperty, GetPathFragmentExpression() + "/[" + index + "]");
            container.ID = index.ToString();
        }
Exemple #17
0
 public static ParametrizedCode GetParametrizedKnockoutExpression(this IValueBinding binding, DotvvmBindableObject currentControl, bool unwrapped = false) =>
 JavascriptTranslator.AdjustKnockoutScriptContext(unwrapped ? binding.UnwrappedKnockoutExpression : binding.KnockoutExpression, dataContextLevel: FindDataContextTarget(binding, currentControl).stepsUp);
Exemple #18
0
        private DotvvmControl GetItem(IDotvvmRequestContext context, object item = null, int index = -1, IValueBinding itemBinding = null)
        {
            var container = new DataItemContainer();

            container.SetDataContextTypeFromDataSource(GetBinding(DataSourceProperty));
            if (item == null && index == -1)
            {
                SetUpClientItem(container);
            }
            else
            {
                SetUpServerItem(context, item, index, itemBinding, container);
            }

            ItemTemplate.BuildContent(context, container);
            return(container);
        }
Exemple #19
0
 public static void AddKnockoutDataBind(this IHtmlWriter writer, string name, IValueBinding valueBinding)
 {
     writer.AddKnockoutDataBind(name, valueBinding.GetKnockoutBindingExpression());
 }
Exemple #20
0
 private void SetUpServerItem(IDotvvmRequestContext context, object item, int index, IValueBinding itemBinding, DataItemContainer container)
 {
     container.DataItemIndex = index;
     container.SetDataContextForItem(itemBinding, index, item);
     container.SetValue(Internal.PathFragmentProperty, GetPathFragmentExpression() + "/[" + index + "]");
     container.ID = index.ToString();
 }
Exemple #21
0
 public static void AddKnockoutDataBind(this IHtmlWriter writer, string name, IValueBinding valueBinding)
 {
     writer.AddKnockoutDataBind(name, valueBinding.GetKnockoutBindingExpression());
 }
Exemple #22
0
 protected virtual string GetKnockoutBindingExpression(DotvvmBindableObject obj, IValueBinding valueBinding)
 {
     return(valueBinding.GetKnockoutBindingExpression(obj));
 }
Exemple #23
0
 public static string GetKnockoutBindingExpression(this IValueBinding binding) =>
 JavascriptTranslator.FormatKnockoutScript(binding.KnockoutExpression);
Exemple #24
0
 public static string GetKnockoutBindingExpression(this IValueBinding binding, DotvvmBindableObject currentControl, bool unwrapped = false) =>
 (unwrapped ? binding.UnwrappedKnockoutExpression : binding.KnockoutExpression)
 .FormatKnockoutScript(currentControl, binding);
Exemple #25
0
 protected virtual void WriteEnabledBinding(IHtmlWriter writer, IValueBinding binding)
 {
     writer.AddKnockoutDataBind("dotvvmEnable", binding);
     writer.AddAttribute("onclick", "return !this.hasAttribute('disabled');");
 }
Exemple #26
0
 public static bool NeedsFormatting(IValueBinding binding) => binding != null && (binding.ResultType == typeof(DateTime) || ReflectionUtils.IsNumericType(binding.ResultType));
Exemple #27
0
        private DotvvmControl GetItem(IDotvvmRequestContext context, object item = null, int index = -1, IValueBinding itemBinding = null)
        {
            var container = new DataItemContainer();

            if (item == null)
            {
                SetUpClientItem(container);
            }
            else
            {
                SetUpServerItem(context, item, index, itemBinding, container);
            }

            ItemTemplate.BuildContent(context, container);
            return(container);
        }
Exemple #28
0
 public static void AddKnockoutDataBind(this IHtmlWriter writer, string name, IValueBinding valueBinding, DotvvmBindableObject control)
 {
     writer.AddKnockoutDataBind(name, valueBinding.GetKnockoutBindingExpression(control));
 }
        public ObjectPropertyBinding(string propertyName, Type propertyType, object parentObj, IValueBinding valueBinding)
        {
            Argument.StringNotNullOrEmpty(() => propertyName);
            Argument.NotNull(() => propertyType);
            Argument.NotNull(() => parentObj);
            Argument.NotNull(() => valueBinding);

            this.PropertyName = propertyName;
            this.propertyType = propertyType;
            this.ValueBinding = valueBinding;

            // Don't need to connect, the value binding will already be connected.
            this.parentObject = parentObj;
        }