Пример #1
0
        public static MvcHtmlString AuthorizedButton(this HtmlHelper html, string Id, string value, string type = "button", object htmlAttributes = null, EnumFeatures feature = EnumFeatures.All, EnumActions action = EnumActions.All)
        {
            bool isVisible  = true;
            bool isEditable = true;

            //TODO: Check for access control
            if (action != EnumActions.All)
            {
                isVisible = AccessControl.IsActionAccessible(html.ViewContext.HttpContext.User as SmartPrincipal, feature, action);
                //Visable then check readonly
                // if Readonly then isEditable =false.
            }

            TagBuilder builder = new TagBuilder("input");

            builder.GenerateId(Id);
            builder.MergeAttribute("value", value);
            builder.MergeAttribute("type", type);
            builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));

            if (!isVisible)
            {
                builder.MergeAttribute("style", "display: none;");
            }
            if (!isEditable)
            {
                builder.MergeAttribute("disabled", "disabled");
            }
            builder.MergeAttribute("background-image", "url('/Content/Images/weighing.png')");

            // Render tag
            return(MvcHtmlString.Create(builder.ToString(TagRenderMode.SelfClosing)));
        }
Пример #2
0
        //Created By SK.
        public static GridBuilder <T> BuildGrid <T>(
            this GridBuilder <T> gridbuilder,
            string gridName,
            string ajaxController,
            string action,
            object routedValue,
            string indexID,
            string[] hiddenColumns = null, bool allowInsert = true, bool allowEdit = true, bool allowDelete = true, EnumFeatures feature = EnumFeatures.Exempt) where T : class
        {
            bool isEditable = true;
            bool isVisible  = true;

            allowEdit   &= (feature == EnumFeatures.Exempt) ? true : AccessControl.IsActionAccessible(HttpContext.Current.User, feature, EnumActions.Edit);
            allowInsert &= (feature == EnumFeatures.Exempt) ? true : AccessControl.IsActionAccessible(HttpContext.Current.User, feature, EnumActions.Add);
            allowDelete &= (feature == EnumFeatures.Exempt) ? true : AccessControl.IsActionAccessible(HttpContext.Current.User, feature, EnumActions.Delete);

            GridBuilder <T> retVal = gridbuilder.Name(gridName).DataKeys(k => k.Add("ID"))
                                     .Scrollable(sc => sc.Height("*"))
                                     .Resizable(rs => rs.Columns(true))
                                     .EnableCustomBinding(true)
                                     .Pageable(paging => paging.PageSize(ConfigurationHelper.GetsmARTDetailGridPageSize())
                                               .Style(Telerik.Web.Mvc.UI.GridPagerStyles.NextPreviousAndNumeric)
                                               .Total(100))
                                     .DataBinding(bindings => bindings.Ajax()
                                                  .Select(action, ajaxController, routedValue)
                                                  .Insert("_Insert", ajaxController, new { isNew = (indexID.Equals("0") ? true : false) })
                                                  .Update("_Update", ajaxController, new { isNew = (indexID.Equals("0") ? true : false) })
                                                  .Delete("_Delete", ajaxController, new { MasterID = indexID, isNew = (indexID.Equals("0") ? true : false) })
                                                  );


            if (isEditable && isVisible)
            {
                if (allowInsert)
                {
                    retVal.Editable(editing => editing.Enabled(isEditable).Mode(Telerik.Web.Mvc.UI.GridEditMode.PopUp).Window(w => w.Modal(true))).ToolBar(commands => commands.Insert());
                }
                retVal.Editable(editing => editing.Enabled(isEditable).Mode(Telerik.Web.Mvc.UI.GridEditMode.PopUp).Window(w => w.Modal(true)));
            }
            else
            {
                retVal.Editable(editing => editing.Enabled(false));
            }

            Type typeT = typeof(T);

            PropertyInfo[] properties = typeT.GetProperties();

            //// Add keys
            //GridDataKeyFactory<T> dataKeys = new GridDataKeyFactory<T>(retVal);
            //foreach (PropertyInfo property in properties)
            //  if (IsAttributePresent<KeyAttribute>(property))
            //    dataKeys.Add(property.Name);

            // Add Columns
            GridColumnFactory <T> columns = new GridColumnFactory <T>(retVal);

            foreach (PropertyInfo property in properties)
            {
                bool IsColumnVisible = !IsAttributePresent <HiddenInputAttribute>(property);
                if (hiddenColumns != null && hiddenColumns.Contains(property.Name))
                {
                    continue;
                }
                GridBoundColumnBuilder <T> gridBoundBuilder = columns.Bound(property.Name).Visible(IsColumnVisible);

                //Set numeric column to right align.
                if (property.PropertyType == typeof(decimal) || property.PropertyType == typeof(double))
                {
                    gridBoundBuilder.HtmlAttributes(new { style = "text-align: right;" }).Format("{0:0.00}");
                }

                if (IsAttributePresent <ClientTemplateHtmlAttribute>(property))
                {
                    gridBoundBuilder.ClientTemplate(property.TemplateHtmlForProperty());
                }
            }


            if (isEditable && isVisible)
            {
                columns.Command(commands => {
                    if (allowEdit)
                    {
                        commands.Edit().ButtonType(Telerik.Web.Mvc.UI.GridButtonType.Image);
                    }
                    if (allowDelete)
                    {
                        commands.Delete().ButtonType(Telerik.Web.Mvc.UI.GridButtonType.Image);
                    }
                }
                                );
            }

            return(retVal);
        }