예제 #1
0
        public BsControlPanelBuilder(ViewContext viewContext, HtmlHelper helper)
            : base(viewContext)
        {
            ActionsFactory = new BsControlPanelActionsFactory();
            TabsFactory    = new BsControlPanelTabsFactory(helper);

            PanelTheme = BsTheme.Default;

            this.renderer = new BsControlPanelBaseRenderer(this);
        }
예제 #2
0
        public FormBuilder(ViewContext viewContext, HtmlHelper helper)
            : base(viewContext)
        {
            ViewContext = viewContext;

            renderer = new FormEditorBaseRenderer(this, helper);

            EditorTheme       = BsTheme.Default;
            AvailableControls = GetDefaultControls();
            TabsFactory       = new FormBuilderTabsFactory();
            ControlsFactory   = new FormBuilderControlsFactory(AvailableControls, DefaultTabId);
            ActionsFactory    = new FormBuilderControlActionsFactory();
        }
예제 #3
0
        private string GetColorClass(BsTheme theme)
        {
            switch (theme)
            {
            case BsTheme.Black:
            {
                return("bg-black");
            }

            case BsTheme.Blue:
            {
                return("bg-blue");
            }

            case BsTheme.Default:
            {
                return("bg-turquoise");
            }

            case BsTheme.Green:
            {
                return("bg-green");
            }

            case BsTheme.Orange:
            {
                return("bg-orange");
            }

            case BsTheme.Red:
            {
                return("bg-red");
            }

            case BsTheme.Purple:
            {
                return("bg-purple");
            }
            }

            return(String.Empty);
        }
예제 #4
0
        private void Add <TEditor, TRow>(BsEditorTabAttribute attr, BsEditorTabModel <TRow> model, List <TabGroupConnection> connections, object[] groupIds, BsTheme theme)
            where TEditor : IBsEditorTabModel
            where TRow : BsItemModel
        {
            var tab =
                new BsEditorTabBuilder <TEditor>(model, this.viewContext, connections).ConnectsWith(groupIds)
                .DisplayName(attr.Name)
                .Id(attr.Id)
                .Selected(attr.Selected);

            if (attr.Editable)
            {
                tab.Editable();
            }

            tab.InitRenderer <TRow>(theme);

            if (attr.Selected)
            {
                navBuilder.Selected(attr.Id);
            }

            InsertTab <TEditor, TRow>(attr.Id, tab);
        }
예제 #5
0
 /// <summary>
 /// Sets the global theme
 /// </summary>
 /// <param name="theme"></param>
 public static void Theme(BsTheme theme)
 {
     globalTheme = theme;
 }
예제 #6
0
 /// <summary>
 /// Renders a form suitable for BForms fields
 /// </summary>
 public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, BsTheme theme)
 {
     var routeValues = htmlHelper.ExtractRouteValues();
     return BsBeginForm(htmlHelper, routeValues["action"].ToString(), routeValues["controller"].ToString(), routeValues, FormMethod.Post, new RouteValueDictionary(), theme);
 }
예제 #7
0
 /// <summary>
 /// Renders a form suitable for BForms fields
 /// </summary>
 public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, object routeValues, FormMethod method, object htmlAttributes, BsTheme theme)
 {
     return BsBeginForm(htmlHelper, actionName, controllerName, new RouteValueDictionary(routeValues), method, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes), theme);
 }
예제 #8
0
 /// <summary>
 /// Renders a form suitable for BForms fields
 /// </summary>
 public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, RouteValueDictionary routeValues, FormMethod method, BsTheme theme)
 {
     return BsBeginForm(htmlHelper, actionName, controllerName, routeValues, method, new RouteValueDictionary(), theme);
 }
예제 #9
0
 /// <summary>
 /// Renders a form suitable for BForms fields
 /// </summary>
 public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, RouteValueDictionary routeValues, BsTheme theme)
 {
     return BsBeginForm(htmlHelper, null, null, routeValues, FormMethod.Post, new RouteValueDictionary(), theme);
 }
예제 #10
0
 /// <summary>
 /// Renders a form suitable for BForms fields
 /// </summary>
 public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, BsTheme theme, object htmlAttributes)
 {
     var routeValues = htmlHelper.ExtractRouteValues();
     return BsBeginForm(htmlHelper, routeValues["action"].ToString(), routeValues["controller"].ToString(), routeValues, FormMethod.Post, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes), theme);
 }
예제 #11
0
 /// <summary>
 /// Renders a form suitable for BForms fields
 /// </summary>
 public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method, IDictionary <string, object> htmlAttributes, BsTheme theme)
 {
     return(BsBeginForm(htmlHelper, actionName, controllerName, new RouteValueDictionary(), method, htmlAttributes, theme));
 }
예제 #12
0
 /// <summary>
 /// Renders a form suitable for BForms fields
 /// </summary>
 public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, RouteValueDictionary routeValues, FormMethod method, BsTheme theme)
 {
     return(BsBeginForm(htmlHelper, actionName, controllerName, routeValues, method, new RouteValueDictionary(), theme));
 }
예제 #13
0
 /// <summary>
 /// Renders a form suitable for BForms fields
 /// </summary>
 public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, object routeValues, BsTheme theme)
 {
     return(BsBeginForm(htmlHelper, actionName, controllerName, new RouteValueDictionary(routeValues), FormMethod.Post, new RouteValueDictionary(), theme));
 }
예제 #14
0
        public string RenderForm <TFormModel>(TFormModel formModel, BsTheme theme = BsTheme.Default, bool wrapInForm = true, string propertyName = null) where TFormModel : class
        {
            if (formModel == null)
            {
                throw new Exception("The form model passed as an argument cannot be null");
            }

            var formString        = String.Empty;
            var formButtonsString = String.Empty;

            var formBuilder          = new TagBuilder("form");
            var formContainerBuilder = new TagBuilder("div");

            formBuilder.MergeAttribute("novalidate", "novalidate");
            formContainerBuilder.AddCssClass("form_container " + theme.GetDescription());

            var properties = formModel.GetType().GetProperties();

            var bsControlProperties = from prop in formModel.GetType().GetProperties()
                                      let bsControl = prop.GetCustomAttributes(typeof(BsControlAttribute), true)
                                                      let required = prop.GetCustomAttributes(typeof(RequiredAttribute), true)
                                                                     let display = prop.GetCustomAttributes(typeof(DisplayAttribute), true)
                                                                                   let formGroup = prop.GetCustomAttributes(typeof(FormGroup), true)
                                                                                                   where bsControl.Length == 1
                                                                                                   select new FormControlPropertyMetadata
            {
                PropertyInfo       = prop,
                FormGroupAttribute = formGroup.FirstOrDefault() as FormGroup,
                RequiredAttribute  = required.FirstOrDefault() as RequiredAttribute,
                DisplayAttribute   = display.FirstOrDefault() as DisplayAttribute,
                BsControlAttribute = bsControl.FirstOrDefault() as BsControlAttribute
            };

            foreach (var property in bsControlProperties)
            {
                formString += RenderFormGroup(property, formModel);
            }

            var buttonsProperties = from prop in formModel.GetType().GetProperties()
                                    where prop.GetCustomAttributes(typeof(FormButtons), true).Any()
                                    select prop;

            var buttons = buttonsProperties.Select(prop => prop.GetValue(formModel)).FirstOrDefault();

            if (buttons != null)
            {
                var buttonsList = buttons as IEnumerable <BsButtonModel>;

                if (buttonsList == null)
                {
                    throw new Exception("Properties decorated with the BsButtonModel attribute must be of type IEnumerable<BsButtonModel>");
                }

                formButtonsString = RenderFormButtons(buttonsList);
            }

            formContainerBuilder.InnerHtml = formString + formButtonsString;

            if (wrapInForm)
            {
                formBuilder.InnerHtml = formContainerBuilder.ToString();

                formBuilder.MergeAttribute("data-property-name", propertyName);

                return(formBuilder.ToString());
            }

            return(formContainerBuilder.ToString());
        }
예제 #15
0
        public BsControlPanelBuilder Theme(BsTheme theme)
        {
            PanelTheme = theme;

            return(this);
        }
예제 #16
0
 /// <summary>
 /// Renders a form suitable for BForms fields
 /// </summary>
 public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, object routeValues, FormMethod method, object htmlAttributes, BsTheme theme)
 {
     return(BsBeginForm(htmlHelper, actionName, controllerName, new RouteValueDictionary(routeValues), method, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes), theme));
 }
예제 #17
0
        /// <summary>
        /// Renders a form suitable for BForms fields
        /// </summary>
        public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, RouteValueDictionary routeValues, FormMethod method, IDictionary <string, object> htmlAttributes, BsTheme theme)
        {
            var form = htmlHelper.BeginForm(actionName, controllerName, routeValues, method, htmlAttributes);

            var tag = new TagBuilder("div");

            tag.AddCssClass("row");
            tag.AddCssClass("form_container");
            tag.AddCssClass("loading");
            tag.AddCssClass(theme.GetDescription());

            var myForm = new BsMvcForm(htmlHelper.ViewContext, form, tag.ToString(TagRenderMode.StartTag), tag.ToString(TagRenderMode.EndTag));

            return(myForm);
        }
예제 #18
0
 /// <summary>
 /// Renders a form suitable for BForms fields
 /// </summary>
 public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, BsTheme theme, IDictionary<string, object> htmlAttributes)
 {
     var routeValues = htmlHelper.ExtractRouteValues();
     return BsBeginForm(htmlHelper, routeValues["action"].ToString(), routeValues["controller"].ToString(), routeValues, FormMethod.Post, htmlAttributes, theme);
 }
예제 #19
0
        /// <summary>
        /// Renders a form suitable for BForms fields
        /// </summary>
        public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, BsTheme theme)
        {
            var routeValues = htmlHelper.ExtractRouteValues();

            return(BsBeginForm(htmlHelper, routeValues["action"].ToString(), routeValues["controller"].ToString(), routeValues, FormMethod.Post, new RouteValueDictionary(), theme));
        }
예제 #20
0
 /// <summary>
 /// Renders a form suitable for BForms fields
 /// </summary>
 public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, object routeValues, BsTheme theme)
 {
     return BsBeginForm(htmlHelper, actionName, controllerName, new RouteValueDictionary(routeValues), FormMethod.Post, new RouteValueDictionary(), theme);
 }
예제 #21
0
        /// <summary>
        /// Renders a form suitable for BForms fields
        /// </summary>
        public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, BsTheme theme, object htmlAttributes)
        {
            var routeValues = htmlHelper.ExtractRouteValues();

            return(BsBeginForm(htmlHelper, routeValues["action"].ToString(), routeValues["controller"].ToString(), routeValues, FormMethod.Post, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes), theme));
        }
예제 #22
0
 /// <summary>
 /// Renders a form suitable for BForms fields
 /// </summary>
 public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method, IDictionary<string, object> htmlAttributes, BsTheme theme)
 {
     return BsBeginForm(htmlHelper, actionName, controllerName, new RouteValueDictionary(), method, htmlAttributes, theme);
 }
예제 #23
0
        /// <summary>
        /// Renders a form suitable for BForms fields
        /// </summary>
        public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, BsTheme theme, IDictionary <string, object> htmlAttributes)
        {
            var routeValues = htmlHelper.ExtractRouteValues();

            return(BsBeginForm(htmlHelper, routeValues["action"].ToString(), routeValues["controller"].ToString(), routeValues, FormMethod.Post, htmlAttributes, theme));
        }
예제 #24
0
        /// <summary>
        /// Renders a form suitable for BForms fields
        /// </summary>
        public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, RouteValueDictionary routeValues, FormMethod method, IDictionary<string, object> htmlAttributes, BsTheme theme)
        {
            var form = htmlHelper.BeginForm(actionName, controllerName, routeValues, method, htmlAttributes);

            var tag = new TagBuilder("div");
            tag.AddCssClass("row");
            tag.AddCssClass("form_container");
            tag.AddCssClass("loading");
            tag.AddCssClass(theme.GetDescription());

            var myForm = new BsMvcForm(htmlHelper.ViewContext, form, tag.ToString(TagRenderMode.StartTag), tag.ToString(TagRenderMode.EndTag));
            return myForm;
        }
예제 #25
0
 /// <summary>
 /// Renders a form suitable for BForms fields
 /// </summary>
 public static BsMvcForm BsBeginForm(this HtmlHelper htmlHelper, RouteValueDictionary routeValues, BsTheme theme)
 {
     return(BsBeginForm(htmlHelper, null, null, routeValues, FormMethod.Post, new RouteValueDictionary(), theme));
 }
예제 #26
0
 /// <summary>
 /// Sets the global theme
 /// </summary>
 /// <param name="theme"></param>
 public static void Theme(BsTheme theme)
 {
     globalTheme = theme;
 }
예제 #27
0
        public virtual TComponent SetTheme(BsTheme theme)
        {
            this.Theme = theme;

            return((TComponent)this);
        }