Ejemplo n.º 1
0
        /// <summary>
        /// 输出多用户选择器
        /// </summary>
        /// <param name="htmlHelper">被扩展的htmlHelper</param>
        /// <param name="name">控件表单名</param>
        /// <param name="selectionLimit">限制选中的用户数</param>
        /// <param name="selectedUserIds">初始选中用户Id集合</param>
        /// <param name="searchScope">搜索范围</param>
        /// <param name="showDropDownMenu">是否显示下拉菜单</param>
        /// <param name="widthType">宽度</param>
        /// <param name="selectionAddedCallBack">添加成功事件回调方法</param>
        /// <remarks>仅限登录用户使用</remarks>
        /// <returns>MvcHtmlString</returns>
        public static MvcHtmlString UserSelector(this HtmlHelper htmlHelper, string name, int selectionLimit, IEnumerable <long> selectedUserIds = null, SelectorWidthType widthType = SelectorWidthType.Long, UserSelectorSearchScope searchScope = UserSelectorSearchScope.FollowedUser, bool showDropDownMenu = true, string selectionAddedCallBack = null)
        {
            if (selectedUserIds == null)
            {
                selectedUserIds = new List <long>();
            }

            IUserService userService = DIContainer.Resolve <IUserService>();

            var selectedUsers = userService.GetFullUsers(selectedUserIds)
                                .Select(n => new
            {
                userId        = n.UserId,
                displayName   = n.DisplayName,
                trueName      = n.TrueName,
                nickName      = n.NickName,
                userAvatarUrl = SiteUrls.Instance().UserAvatarUrl(n, AvatarSizeType.Small)
            });
            string followGroupsJSON = "[]";

            if (showDropDownMenu)
            {
                var followGroups = new CategoryService().GetOwnerCategories(UserContext.CurrentUser.UserId, TenantTypeIds.Instance().User()).Select(n => new
                {
                    name  = n.CategoryName.Length > 15 ? n.CategoryName.Substring(0, 15): n.CategoryName,
                    value = n.CategoryId
                });
                followGroupsJSON = Json.Encode(followGroups);
            }

            string widthClass = "tn-longer";

            switch (widthType)
            {
            case SelectorWidthType.Short:
                widthClass = "tn-short";
                break;

            case SelectorWidthType.Medium:
                widthClass = "tn-medium";
                break;

            case SelectorWidthType.Long:
                widthClass = "tn-long";
                break;

            case SelectorWidthType.Longer:
                widthClass = "tn-longer";
                break;

            case SelectorWidthType.Longest:
                widthClass = "tn-longest";
                break;

            default:
                widthClass = "tn-longer";
                break;
            }

            htmlHelper.ViewData["controlName"]            = name;
            htmlHelper.ViewData["widthClass"]             = widthClass;
            htmlHelper.ViewData["selectionLimit"]         = selectionLimit;
            htmlHelper.ViewData["searchScope"]            = searchScope;
            htmlHelper.ViewData["showDropDownMenu"]       = showDropDownMenu;
            htmlHelper.ViewData["selectionAddedCallBack"] = selectionAddedCallBack;
            return(htmlHelper.EditorForModel("UserSelector", new { selectedUsers = Json.Encode(selectedUsers), followGroups = followGroupsJSON }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 输出多用户选择器
        /// </summary>
        /// <param name="htmlHelper">被扩展的htmlHelper</param>
        /// <param name="name">控件表单名</param>
        /// <param name="selectionLimit">限制选中的用户数</param>
        /// <param name="selectedUserIds">初始选中用户Id集合</param>
        /// <param name="searchScope">搜索范围</param>
        /// <param name="showDropDownMenu">是否显示下拉菜单</param>
        /// <param name="widthType">宽度</param>
        /// <param name="selectionAddedCallBack">添加成功事件回调方法</param>
        /// <remarks>仅限登录用户使用</remarks>
        /// <returns>MvcHtmlString</returns>
        public static MvcHtmlString UserSelector(this HtmlHelper htmlHelper, string name, int selectionLimit, IEnumerable<long> selectedUserIds = null, SelectorWidthType widthType = SelectorWidthType.Long, UserSelectorSearchScope searchScope = UserSelectorSearchScope.FollowedUser, bool showDropDownMenu = true, string selectionAddedCallBack = null)
        {
            if (selectedUserIds == null)
                selectedUserIds = new List<long>();

            IUserService userService = DIContainer.Resolve<IUserService>();

            var selectedUsers = userService.GetFullUsers(selectedUserIds)
             .Select(n => new
            {
                userId = n.UserId,
                displayName = n.DisplayName,
                trueName = n.TrueName,
                nickName = n.NickName,
                userAvatarUrl = SiteUrls.Instance().UserAvatarUrl(n, AvatarSizeType.Small)
            });
            string followGroupsJSON = "[]";
            if (showDropDownMenu)
            {
                var followGroups = new CategoryService().GetOwnerCategories(UserContext.CurrentUser.UserId, TenantTypeIds.Instance().User()).Select(n => new
                {
                    name = n.CategoryName.Length > 15 ? n.CategoryName.Substring(0,15): n.CategoryName,
                    value = n.CategoryId
                });
                followGroupsJSON = Json.Encode(followGroups);
            }

            string widthClass = "tn-longer";
            switch (widthType)
            {
                case SelectorWidthType.Short:
                    widthClass = "tn-short";
                    break;
                case SelectorWidthType.Medium:
                    widthClass = "tn-medium";
                    break;
                case SelectorWidthType.Long:
                    widthClass = "tn-long";
                    break;
                case SelectorWidthType.Longer:
                    widthClass = "tn-longer";
                    break;
                case SelectorWidthType.Longest:
                    widthClass = "tn-longest";
                    break;
                default:
                    widthClass = "tn-longer";
                    break;
            }

            htmlHelper.ViewData["controlName"] = name;
            htmlHelper.ViewData["widthClass"] = widthClass;
            htmlHelper.ViewData["selectionLimit"] = selectionLimit;
            htmlHelper.ViewData["searchScope"] = searchScope;
            htmlHelper.ViewData["showDropDownMenu"] = showDropDownMenu;
            htmlHelper.ViewData["selectionAddedCallBack"] = selectionAddedCallBack;
            return htmlHelper.EditorForModel("UserSelector", new { selectedUsers = Json.Encode(selectedUsers), followGroups = followGroupsJSON });
        }