Exemplo n.º 1
0
        protected override void BuildControl(System.Web.Mvc.TagBuilder builder, CustomFieldDefinition field, string value, object htmlAttributes, System.Web.Mvc.ViewContext viewContext)
        {
            builder.AddCssClass("form-list");

            var itemsHtml = new StringBuilder();
            var i = 0;

            foreach (var item in field.SelectionItems)
            {
                itemsHtml.AppendLine("<li>");

                var checkboxId = field.Name + "_" + i;
                var checkbox = new TagBuilder("input");
                checkbox.MergeAttribute("id", checkboxId);
                checkbox.MergeAttribute("type", "checkbox");
                checkbox.MergeAttribute("name", field.Name);
                checkbox.MergeAttribute("value", item.Value);

                var label = new TagBuilder("label");
                label.InnerHtml = item.Text;
                label.AddCssClass("inline");
                label.MergeAttribute("for", checkboxId);

                itemsHtml.AppendLine(checkbox.ToString(TagRenderMode.SelfClosing));
                itemsHtml.AppendLine(label.ToString());

                itemsHtml.AppendLine("</li>");

                i++;
            }

            builder.InnerHtml = itemsHtml.ToString();

            base.BuildControl(builder, field, value, htmlAttributes, viewContext);
        }
Exemplo n.º 2
0
 protected virtual void BuildControl(TagBuilder builder, CustomFieldDefinition fieldDefinition, string fieldValue, object htmlAttributes, ViewContext viewContext)
 {
     if (htmlAttributes != null)
     {
         builder.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes), true);
     }
 }
Exemplo n.º 3
0
 private void OnCustomFieldAdded(CustomFieldDefinition field)
 {
     InternalCustomFieldDefinitions.Add(new ProductTypeCustomFieldDefinition
     {
         CustomField = field,
         Sequence    = InternalCustomFieldDefinitions.Count == 0 ? 0 : InternalCustomFieldDefinitions.Max(f => f.Sequence) + 1
     });
 }
Exemplo n.º 4
0
 public IEnumerable<System.Web.Mvc.ModelClientValidationRule> GetClientValidationRules(CustomFieldDefinition field, FieldValidationRule rule)
 {
     yield return new ModelClientValidationRule
     {
         ValidationType = "uniquefield",
         ErrorMessage = rule.ErrorMessage
     };
 }
Exemplo n.º 5
0
        private void OnCustomFieldRemoved(CustomFieldDefinition field)
        {
            var internalField = InternalCustomFieldDefinitions.FirstOrDefault(f => f.CustomField.Name == field.Name);

            if (internalField != null)
            {
                InternalCustomFieldDefinitions.Remove(internalField);
            }
        }
Exemplo n.º 6
0
        protected override void BuildControl(TagBuilder builder, CustomFieldDefinition field, string value, object htmlAttributes, ViewContext viewContext)
        {
            builder.MergeAttribute("type", Type, true);

            if (Type == "text")
            {
                builder.MergeAttribute("value", value, true);
            }

            base.BuildControl(builder, field, value, htmlAttributes, viewContext);
        }
Exemplo n.º 7
0
        public IHtmlString Render(CustomFieldDefinition field, string value, object htmlAttributes, System.Web.Mvc.ViewContext viewContext)
        {
            var input = new TagBuilder("input");
            input.Attributes.Add("type", "hidden");
            input.Attributes.Add("name", field.Name);

            var text = new TagBuilder("span");
            text.InnerHtml = field.DefaultValue;

            var html = new StringBuilder();
            html.AppendLine(input.ToString(TagRenderMode.SelfClosing));
            html.AppendLine(text.ToString());

            return new HtmlString(html.ToString());
        }
Exemplo n.º 8
0
        protected override void BuildControl(System.Web.Mvc.TagBuilder builder, CustomFieldDefinition field, string value, object htmlAttributes, System.Web.Mvc.ViewContext viewContext)
        {
            base.BuildControl(builder, field, value, htmlAttributes, viewContext);

            var html = new StringBuilder();
            html.Append("<option value=\"\"></option>");

            foreach (var item in field.SelectionItems)
            {
                html.AppendFormat("<option value=\"{0}\">{1}</option>", item.Value, item.Text)
                    .AppendLine();
            }

            builder.InnerHtml = html.ToString();
        }
Exemplo n.º 9
0
        public virtual IHtmlString Render(CustomFieldDefinition fieldDefinition, string fieldValue, object htmlAttributes, ViewContext viewContext)
        {
            var builder = new TagBuilder(TagName);

            builder.MergeAttribute("name", fieldDefinition.Name);

            var validationAttributes = fieldDefinition.GetUnobtrusiveValidationAtributes();
            if (validationAttributes != null && validationAttributes.Count > 0)
            {
                builder.MergeAttributes(validationAttributes, true);
            }

            BuildControl(builder, fieldDefinition, fieldValue, htmlAttributes, viewContext);

            return new HtmlString(builder.ToString(TagRenderMode));
        }
Exemplo n.º 10
0
        public void UpdateFrom(CustomFieldDefinition field)
        {
            // Do not update IsPredefined and Id
            Name           = field.Name;
            Label          = field.Label;
            Tooltip        = field.Tooltip;
            ControlType    = field.ControlType;
            DefaultValue   = field.DefaultValue;
            Sequence       = field.Sequence;
            SelectionItems = field.SelectionItems;

            ValidationRules.Update(
                from: field.ValidationRules,
                by: r => r.Id,
                onUpdateItem: (oldItem, newItem) => oldItem.UpdateFrom(newItem));
        }
Exemplo n.º 11
0
        public IHtmlString Render(CustomFieldDefinition field, string value, object htmlAttributes, System.Web.Mvc.ViewContext viewContext)
        {
            var container = new TagBuilder("div");
            container.AddCssClass("custom-file");
            container.Attributes.Add("data-toggle", "fileupload");

            var textbox = new TagBuilder("input");
            textbox.Attributes.Add("type", "text");
            textbox.Attributes.Add("name", field.Name);
            textbox.MergeAttributes(field.GetUnobtrusiveValidationAtributes());

            RouteValueDictionary additionHtmlAttributes = null;

            if (htmlAttributes != null)
            {
                additionHtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

                var databind = additionHtmlAttributes["data-bind"];
                if (databind != null)
                {
                    additionHtmlAttributes.Remove("data-bind");
                    textbox.MergeAttribute("data-bind", databind.ToString());
                }

                container.MergeAttributes(additionHtmlAttributes);
            }

            var button = new TagBuilder("a");
            button.AddCssClass("button");

            var span = new TagBuilder("span");

            var fileInput = new TagBuilder("input");
            fileInput.Attributes.Add("type", "file");
            fileInput.Attributes.Add("id", field.Name);
            fileInput.Attributes.Add("name", field.Name);

            span.InnerHtml = fileInput.ToString(TagRenderMode.SelfClosing);
            button.InnerHtml = "Browse..." + span.ToString();

            container.InnerHtml = String.Concat(textbox.ToString(TagRenderMode.SelfClosing), button.ToString());

            return new HtmlString(container.ToString());
        }
Exemplo n.º 12
0
 public virtual string GetFieldDisplayText(CustomFieldDefinition fieldDefinition, string fieldValue)
 {
     return fieldValue;
 }
Exemplo n.º 13
0
        private void UpdateFieldTranslation(CustomFieldDefinition original, CustomFieldDefinitionModel translated, string prefix, List<PropertyTranslation> translations)
        {
            translations.Add(new PropertyTranslation(prefix + "Label", original.Label, translated.Label));
            translations.Add(new PropertyTranslation(prefix + "DefaultValue", original.DefaultValue, translated.DefaultValue));

            foreach (var item in translated.SelectionItems)
            {
                var originalItem = original.SelectionItems.FirstOrDefault(i => i.Value == item.Value);
                translations.Add(new PropertyTranslation(prefix + "SelectionItems[" + item.Value + "]", originalItem.Text, item.Text));
            }
        }
Exemplo n.º 14
0
 public override string GetFieldDisplayText(CustomFieldDefinition fieldDefinition, string fieldValue)
 {
     var item = fieldDefinition.SelectionItems.FirstOrDefault(i => i.Value == fieldValue);
     return item == null ? fieldValue : item.Text;
 }
 public void Update(CustomFieldDefinition field)
 {
     _repository.Update(field);
 }
 public void Delete(CustomFieldDefinition field)
 {
     _repository.Delete(field);
 }
 public void Create(CustomFieldDefinition field)
 {
     _repository.Insert(field);
 }
Exemplo n.º 18
0
 public IEnumerable<System.Web.Mvc.ModelClientValidationRule> GetClientValidationRules(CustomFieldDefinition field, FieldValidationRule rule)
 {
     yield return new ModelClientValidationRequiredRule(rule.ErrorMessage);
 }
Exemplo n.º 19
0
 protected override void BuildControl(System.Web.Mvc.TagBuilder builder, CustomFieldDefinition field, string value, object htmlAttributes, System.Web.Mvc.ViewContext viewContext)
 {
     base.BuildControl(builder, field, value, htmlAttributes, viewContext);
     builder.InnerHtml = value;
 }
 public void Create(CustomFieldDefinition field)
 {
     _repository.Insert(field);
 }
 public void Delete(CustomFieldDefinition field)
 {
     _repository.Delete(field);
 }
 public void Update(CustomFieldDefinition field)
 {
     _repository.Update(field);
 }
 protected override void InsertItem(int index, Kooboo.Commerce.Products.CustomFieldDefinition item)
 {
     base.InsertItem(index, item);
     OnAdded(item);
 }
Exemplo n.º 24
0
        public void UpdateFrom(CustomFieldDefinition field)
        {
            // Do not update IsPredefined and Id
            Name = field.Name;
            Label = field.Label;
            Tooltip = field.Tooltip;
            ControlType = field.ControlType;
            DefaultValue = field.DefaultValue;
            Sequence = field.Sequence;
            SelectionItems = field.SelectionItems;

            ValidationRules.Update(
                from: field.ValidationRules,
                by: r => r.Id,
                onUpdateItem: (oldItem, newItem) => oldItem.UpdateFrom(newItem));
        }