Beispiel #1
0
        public static MvcHtmlString Employee <TModel>(this HtmlHelper <TModel> htmlHelper, string id, string value, string searchUrl, IDictionary <string, object> htmlAttributes)
        {
            // Register the dependency
            BsHelper.AddDependency(Dependency.TypeAhead);
            BsHelper.AddCssDependency("    <link href='~/EmployeeHelper/Css/Employee.helper.css' rel='stylesheet' />");
            BsHelper.AddJsDependency("    <script src='~/EmployeeHelper/Script/employee.helper.js'></script>");

            // make sure that htmlAttributes is not null, or we won't be able to add it
            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }

            // get the field name for use with bootstrap
            string htmlFieldName = id;
            string labelText     = id;

            if (labelText == null)
            {
                labelText = (id ?? htmlFieldName.Split('.').Last()).SplitCamelCase();
            }

            // add a placeholder if it isn't already there
            if (!String.IsNullOrEmpty(labelText))
            {
                if (!htmlAttributes.ContainsKey("placeholder"))
                {
                    htmlAttributes["placeholder"] = labelText;
                }
            }

            // add form-control
            if (htmlAttributes.ContainsKey("class"))
            {
                htmlAttributes["class"] += " form-control";
            }
            else
            {
                htmlAttributes["class"] = "form-control";
            }

            htmlAttributes["name"] = htmlAttributes["id"] = id;

            string htmlId    = GenerateIdFromName(htmlFieldName);
            string searchBox = htmlHelper.TextBox(id, null, htmlAttributes).ToString();

            searchBox = searchBox.Replace(htmlFieldName, htmlFieldName + "_search");
            if (htmlFieldName != htmlId)
            {
                searchBox = searchBox.Replace(htmlId, htmlId + "_search");
            }

            string hiddenField = htmlHelper.Hidden(id, value).ToString();

            string employees = "<span class=\"employee-badge\">Employee</span>";

            string extras = $@"<script>$(function() {{ employeeInit('{searchUrl}', '{htmlId}'); }})</script>";

            return(new MvcHtmlString("<div class=\"employee-wrap\">" + searchBox + hiddenField + employees + extras + "</div>"));
        }
Beispiel #2
0
        protected void Application_Start()
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            ConfigureViewEngines();

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            //BundleConfig.RegisterBundles(BundleTable.Bundles);
            MiniProfiler.Settings.PopupRenderPosition = RenderPosition.BottomRight;
            Config.SetDbConfigVals();

            // changing default helper path for chose css
            BsHelper.SetDependencyPrimaryCss(Dependency.Chosen, "~/Content/bootstrap-chosen.css");
            ConfigureAntiForgeryTokens();

            AntiForgeryConfig.SuppressXFrameOptionsHeader = true;
            IdentityModelEventSource.ShowPII = true;
        }
Beispiel #3
0
        public string ToHtmlString()
        {
            // make it shorter
            var c = _component;
            var i = Input;

            if (c.NameAsPlaceholder)
            {
                i = i.Replace("{placeholder}", c.DisplayName);
            }
            else
            {
                i = i.Replace("{placeholder}", c.Format);
            }

            if (Value.HasValue)
            {
                i = i.Replace("{value}", Value.Value.ToString(c.Format.Replace('m', 'M')));
            }

            StringBuilder output = new StringBuilder();

            if (c.AsComponent)
            {
                output.Append("<div class=\"input-group date\">");
                output.Append(i);
                output.Append("<span class=\"input-group-addon\"><i class=\"fa fa-calendar\"></i></span>");
                output.Append("</div>");
                output.AppendLine();
                output.AppendFormat("<script>$(document).ready(function () {{ $('#{0}').closest('.input-group').datepicker({{", c.Name);
            }
            else
            {
                output.AppendLine(i);
                output.AppendFormat("<script>$(document).ready(function () {{ $('#{0}').datepicker({{", c.Name);
            }

            output.AppendFormat(" orientation: '{0}', ", BsHelper.SplitCamelCase(c.Orientation.ToString()).ToLower());
            output.AppendFormat("format: '{0}', ", c.Format);
            if (c.WeekStart != DayOfWeek.Sunday)
            {
                output.AppendFormat("weekStart: {0}", (int)c.WeekStart);
            }
            if (c.StartDate != DateTime.MinValue)
            {
                output.AppendFormat("startDate: '{0}', ", c.StartDate.ToString("MM/dd/yyyy"));
            }
            if (c.EndDate != DateTime.MaxValue)
            {
                output.AppendFormat("endDate: '{0}', ", c.EndDate.ToString("MM/dd/yyyy"));
            }

            if (c.StartView != DPStartView.Month)
            {
                output.AppendFormat("startView: {0}, ", (int)c.StartView);
            }

            if (c.TodayButton)
            {
                output.Append("todayBtn: 'linked', ");
            }

            if (c.ClearButton)
            {
                output.Append("clearBtn: true, ");
            }

            if (c.TodayHighlight)
            {
                output.Append("todayHighlight: true, ");
            }

            if (c.ToggleActive)
            {
                output.Append("toggleActive: true, ");
            }

            output.AppendLine("}); })</script>");

            return(output.ToString());
        }
Beispiel #4
0
        public static MvcHtmlString EmployeeFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, string searchUrl, IDictionary <string, object> htmlAttributes)
        {
            string buildstamp = Inl.MvcHelper.BsHelper.GetBuildStamp().ToString();

            // Register the dependency
            BsHelper.AddDependency(Dependency.TypeAhead);
            BsHelper.AddCssDependency($"    <link href='~/EmployeeHelper/Css/Employee.helper.css?s={buildstamp}' rel='stylesheet' />");
            BsHelper.AddJsDependency($"    <script src='~/EmployeeHelper/Script/employee.helper.js?s={buildstamp}'></script>");

            // make sure that htmlAttributes is not null, or we won't be able to add it
            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }

            // get the field name for use with bootstrap
            ModelMetadata metadata      = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
            string        htmlFieldName = ExpressionHelper.GetExpressionText(expression);
            string        labelText     = metadata.DisplayName;

            if (labelText == null)
            {
                labelText = (metadata.PropertyName ?? htmlFieldName.Split('.').Last()).SplitCamelCase();
            }

            // add a placeholder if it isn't already there
            if (!String.IsNullOrEmpty(labelText))
            {
                if (!htmlAttributes.ContainsKey("placeholder"))
                {
                    htmlAttributes["placeholder"] = labelText;
                }
            }

            // add form-control
            if (htmlAttributes.ContainsKey("class"))
            {
                htmlAttributes["class"] += " form-control";
            }
            else
            {
                htmlAttributes["class"] = "form-control";
            }

            string htmlId    = GenerateIdFromName(htmlFieldName);
            string searchBox = htmlHelper.TextBoxFor(expression, htmlAttributes).ToString();

            searchBox = searchBox.Replace(htmlFieldName, htmlFieldName + "_search");
            searchBox = searchBox.Replace($"placeholder=\"{htmlFieldName}_search\"", $"placeholder=\"{htmlFieldName}\"");
            if (htmlFieldName != htmlId)
            {
                searchBox = searchBox.Replace(htmlId, htmlId + "_search");
            }
            string hiddenField = htmlHelper.HiddenFor(expression).ToString();

            string employees = "<span class=\"employee-badge\">Employee</span>";

            string extras = $@"<script>$(function() {{ employeeInit('{searchUrl}', '{htmlId}'); }})</script>";

            return(new MvcHtmlString("<div class=\"employee-wrap\">" + searchBox + hiddenField + employees + extras + "</div>"));
        }
Beispiel #5
0
        public static MvcHtmlString EmployeesFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, string searchUrl, string getUrl, IDictionary <string, object> htmlAttributes)
        {
            string buildstamp = Inl.MvcHelper.BsHelper.GetBuildStamp().ToString();

            // Register the dependency
            BsHelper.AddDependency(Dependency.TypeAhead);
            BsHelper.AddCssDependency($"    <link href='~/EmployeeHelper/Css/Employees.helper.css?s={buildstamp}' rel='stylesheet' />");
            BsHelper.AddJsDependency($"    <script src='~/EmployeeHelper/Script/employees.helper.js?s={buildstamp}'></script>");

            // make sure that htmlAttributes is not null, or we won't be able to add it
            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }

            // get the field name for use with bootstrap
            ModelMetadata metadata      = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
            string        htmlFieldName = ExpressionHelper.GetExpressionText(expression);
            string        labelText     = metadata.DisplayName;

            if (labelText == null)
            {
                labelText = (metadata.PropertyName ?? htmlFieldName.Split('.').Last()).SplitCamelCase();
            }

            // add a placeholder if it isn't already there
            if (!String.IsNullOrEmpty(labelText))
            {
                if (!htmlAttributes.ContainsKey("placeholder"))
                {
                    htmlAttributes["placeholder"] = "Search Employees to Add...";
                }
            }

            // add form-control
            if (htmlAttributes.ContainsKey("class"))
            {
                htmlAttributes["class"] += " form-control";
            }
            else
            {
                htmlAttributes["class"] = "form-control";
            }

            // DS: Since we always need a List<string> to check contains, we need to convert whatever we have
            List <string> values = new List <string>();

            if (metadata.Model == null)
            {
                // do nothing
            }
            else if (metadata.ModelType == typeof(IEnumerable <SelectListItem>))
            {
                values = ((IEnumerable <SelectListItem>)metadata.Model).Select(x => x.Value).ToList();
            }
            else if (typeof(IEnumerable).IsAssignableFrom(metadata.ModelType))
            {
                IEnumerable enumerable = (IEnumerable)metadata.Model;
                foreach (object item in enumerable)
                {
                    values.Add(item.ToString());
                }
            }

            string searchBox     = htmlHelper.TextBox(htmlFieldName + "_search", string.Join(",", values), htmlAttributes).ToString();
            string employeeBadge = "<span class=\"employee-badge\">Employees</span>";
            string extras        = $@"<script>$(function() {{ employeesInit('{searchUrl}', '{getUrl}', '{GenerateIdFromName(htmlFieldName)}', '{htmlFieldName}'); }})</script>";

            return(new MvcHtmlString("<div class='employee-wrap'>" + searchBox + employeeBadge + "</div>" + extras));
        }
Beispiel #6
0
 public SelectList ViewModes() => BsHelper.GetEnumSelectList <ViewModeOptionEnum>();