Esempio n. 1
0
        /// <summary>
        /// Generate help text for property
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="helper"></param>
        /// <param name="expression"></param>
        /// <param name="htmlAttributes"></param>
        /// <param name="position"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static MvcHtmlString HelpTextFor <TModel, TValue>(this HtmlHelper <TModel> helper,
                                                                 Expression <Func <TModel, TValue> > expression, object htmlAttributes,
                                                                 SlideInHelpPosition position = SlideInHelpPosition.Top, string text = "?")
        {
            ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, helper.ViewData);

            var tag = new TagBuilder("span");

            if (metadata != null)
            {
                string htmlFieldName = ExpressionHelper.GetExpressionText(expression);
                string labelText     = metadata.DisplayName ?? metadata.PropertyName ?? htmlFieldName.Split('.').Last();
                if (String.IsNullOrEmpty(labelText))
                {
                    return(MvcHtmlString.Empty);
                }

                if (!string.IsNullOrEmpty(metadata.PropertyName))
                {
                    MemberInfo property = metadata.ContainerType.GetProperty(metadata.PropertyName);

                    //Get localize attribute
                    var attribute =
                        property.GetCustomAttributes(typeof(LocalizedDisplayNameAttribute), true)
                        .Cast <LocalizedDisplayNameAttribute>()
                        .FirstOrDefault();
                    if (attribute != null)
                    {
                        return(HelpText(helper, attribute.Key, htmlAttributes, position, text));
                    }
                }
            }

            return(MvcHtmlString.Create(tag.ToString(TagRenderMode.Normal)));
        }
Esempio n. 2
0
        /// <summary>
        /// Generate help text with key
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="textKey"></param>
        /// <param name="htmlAttributes"></param>
        /// <param name="position"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static MvcHtmlString HelpText(this HtmlHelper helper, string textKey,
                                             object htmlAttributes, SlideInHelpPosition position = SlideInHelpPosition.Top, string text = "?")
        {
            var userService        = HostContainer.GetInstance <IUserService>();
            var slideInHelpService = HostContainer.GetInstance <ISlideInHelpService>();
            var siteSettingService = HostContainer.GetInstance <ISiteSettingService>();

            var tag = new TagBuilder("span");

            var slideInHelp = slideInHelpService.GetSlideInHelp(textKey);

            /*
             * There are some conditions to disable a slide in help
             *      Cannot find slide in help
             *      User has no permission to see no active slide in help
             *      If site is not disalbed slide in help service (it means that site is client site not the master site for setting up slide in hel), then we will disable the help
             */
            if (slideInHelp == null ||
                (string.IsNullOrEmpty(slideInHelp.HelpTitle) ||
                 string.IsNullOrEmpty(slideInHelp.MasterHelpContent) &&
                 !siteSettingService.LoadSetting <EzCMSHelpConfigurationSetting>().DisabledSlideInHelpService) ||
                (!userService.HasPermissions(WorkContext.CurrentUser.Id, Permission.ManageSlideInHelp) && !slideInHelp.Active))
            {
                return(MvcHtmlString.Create(""));
            }

            // Generate required attributes
            var htmlAttributeDictionary = new RouteValueDictionary(htmlAttributes)
            {
                { "data-id", slideInHelp.Id },
                { "data-placement", position.GetEnumName().ToLower() },
                { "data-trigger", "hover" },
                { "data-rel", "popover" },
                { "data-original-title", slideInHelp.HelpTitle }
            };

            // Place local content at top of help content then the master content
            var helpContent = slideInHelp.MasterHelpContent;

            if (!string.IsNullOrEmpty(slideInHelp.LocalHelpContent))
            {
                helpContent = string.Format("{0} <br/> {1}", slideInHelp.LocalHelpContent, slideInHelp.MasterHelpContent);
            }

            if (WorkContext.CurrentUser != null &&
                userService.HasPermissions(WorkContext.CurrentUser.Id,
                                           Permission.ManageSlideInHelp))
            {
                const string contentTemplate =
                    @"{0} <hr class='slide-in-help'/><div class='slide-in-help-edit-box'>
<a class='edit-slide-in-help' href='javascript:void(0)' data-id='{1}'><i class='fa fa-pencil'></i></a>
<a class='change-status-slide-in-help' href='javascript:void(0)' data-id='{1}' data-status='{2}'><i class='fa {3}'></i></a>
</div>";
                string className;
                string content;
                if (!slideInHelp.Active)
                {
                    className = "slide-in-help popover-hover popover-disabled";
                    content   = string.Format(contentTemplate, helpContent, slideInHelp.Id, slideInHelp.Active, "fa-check");
                }
                else
                {
                    className = "slide-in-help popover-hover";
                    content   = string.Format(contentTemplate, helpContent, slideInHelp.Id, slideInHelp.Active, "fa-power-off");
                }

                htmlAttributeDictionary.Append("data-content", content);

                htmlAttributeDictionary.Append("class", className);
            }
            else
            {
                htmlAttributeDictionary.Append("data-content", helpContent);
            }

            tag.SetInnerText(text);
            tag.MergeAttributes(htmlAttributeDictionary);

            return(MvcHtmlString.Create(tag.ToString(TagRenderMode.Normal)));
        }