Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(JsId))
            {
                JsId = "groupSelector_" + _selectorID;
            }

            Page.ClientScript.RegisterClientScriptInclude(typeof(string), "groupselector_script", WebPath.GetPath("usercontrols/users/groupselector/js/groupselector.js"));
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "groupselector_style", "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + WebSkin.GetUserSkin().GetAbsoluteWebPath("usercontrols/users/groupselector/css/<theme_folder>/groupselector.css") + "\">", false);

            var sb = new StringBuilder();

            sb.AppendFormat(" var {0} = new ASC.Controls.GroupSelector('{1}', {2});",
                            JsId,
                            _selectorID,
                            IsMobileVersion.ToString().ToLower());

            var strAppendGroup = "{0}.Groups.push({{Id : '{1}', Name : '{2}'}});";

            if (IsMobileVersion)
            {
                sb.AppendFormat(strAppendGroup, JsId, -1, Resources.UserControlsCommonResource.LblSelect.HtmlEncode().ReplaceSingleQuote());
            }
            if (WithGroupEveryone)
            {
                sb.AppendFormat(strAppendGroup, JsId, ASC.Core.Users.Constants.GroupEveryone.ID, Resources.UserControlsCommonResource.Everyone.HtmlEncode().ReplaceSingleQuote());
            }
            if (WithGroupAdmin)
            {
                sb.AppendFormat(strAppendGroup, JsId, ASC.Core.Users.Constants.GroupAdmin.ID, Resources.UserControlsCommonResource.Admin.HtmlEncode().ReplaceSingleQuote());
            }

            foreach (var grp in CoreContext.GroupManager.GetGroups().OrderBy(g => g.Name))
            {
                sb.AppendFormat(strAppendGroup, JsId, grp.ID, grp.Name.HtmlEncode().ReplaceSingleQuote());
            }

            Page.ClientScript.RegisterClientScriptBlock(GetType(), "group_selector_script_" + _selectorID, sb.ToString(), true);

            var str = IsMobileVersion ?
                      @"<script id=""groupSelectorListTemplate"" type=""text/x-jquery-tmpl"">
                                            {{each(i, gpr) Groups}} 
                                                 <option value=""${gpr.Id}"" style='max-width:300px;'>
                                                     ${gpr.Name}
                                                 </option>
                                            {{/each}}
                                        </script>"
                          : @"<script id=""groupSelectorListTemplate"" type=""text/x-jquery-tmpl"">
                                {{each(i, gpr) Groups}} 
                                     <div class=""group"" data=""${gpr.Id}"" title=""${gpr.Name}"">
                                         ${gpr.Name}
                                     </div>
                                {{/each}}
                            </script>";

            Page.ClientScript.RegisterClientScriptBlock(GetType(), "group_selector_tmpl_script", str, false);
        }
Exemplo n.º 2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnInit(e);
            _jsObjName = String.IsNullOrEmpty(ID) ? "advancedUserSelector" + UniqueID.Replace('$', '_') : ID;

            if (!Page.ClientScript.IsClientScriptIncludeRegistered(GetType(), "ASC_Controls_AdvUserSelector_Script"))
            {
                Page.ClientScript.RegisterClientScriptInclude("ASC_Controls_AdvUserSelector_Script",
                                                              Page.ClientScript.GetWebResourceUrl(GetType(), "ASC.Web.Controls.AdvancedUserSelector.js.AdvUserSelectorScript.js"));
            }

            if (!Page.ClientScript.IsClientScriptBlockRegistered("ASC_Controls_AdvUserSelector_Style"))
            {
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "ASC_Controls_AdvUserSelector_Style",
                                                            "<link href=\"" + Page.ClientScript.GetWebResourceUrl(GetType(), "ASC.Web.Controls.AdvancedUserSelector.css.default.css") + "\" type=\"text/css\" rel=\"stylesheet\"/>", false);
            }


            var scriptInit = new StringBuilder();

            scriptInit.AppendFormat("\nASC.Controls.AdvancedUserSelector._profiles = '{0}';\n", new Api.ApiServer().GetApiResponse("api/1.0/people.json?fields=id,displayname,avatarsmall,groups", "GET"));
            scriptInit.AppendFormat("\nASC.Controls.AdvancedUserSelector._groups = '{0}';\n", new Api.ApiServer().GetApiResponse("api/1.0/group.json", "GET"));
            scriptInit.AppendFormat("\nASC.Controls.AdvancedUserSelector.UserNameFormat = {0};\n", (int)UserFormatter.GetUserDisplayDefaultOrder());


            if (!Page.ClientScript.IsClientScriptBlockRegistered(GetType(), "ASC_Controls_AdvUserSelector_ScriptInit"))
            {
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "ASC_Controls_AdvUserSelector_ScriptInit", scriptInit.ToString(), true);
            }


            var script = new StringBuilder();

            script.AppendFormat("var {0} = new ASC.Controls.AdvancedUserSelector.UserSelectorPrototype('{1}', '{0}', '&lt;{2}&gt;', '{3}', {4}, {5}, '{6}');\n",
                                _jsObjName,
                                _selectorID,
                                Resources.AdvancedUserSelectorResource.EmptyList,
                                Resources.AdvancedUserSelectorResource.ClearFilter,
                                IsMobileVersion.ToString().ToLower(),
                                IsLinkView.ToString().ToLower(),
                                IsMobileVersion ? _linkText.HtmlEncode().ReplaceSingleQuote() : "");


            if (UserList != null && UserList.Count > 0)
            {
                if (DisabledUsers != null && DisabledUsers.Count > 0)
                {
                    UserList.RemoveAll(ui => (DisabledUsers.Find(dui => dui.Equals(ui.ID)) != Guid.Empty));
                }

                script.AppendFormat("\n{0}.UserIDs = [", _jsObjName);
                foreach (var u in UserList.SortByUserName())
                {
                    script.AppendFormat("'{0}',", u.ID);
                }
                if (UserList.Count > 0)
                {
                    script.Remove(script.Length - 1, 1);
                }

                script.Append("];\n");
            }

            if (DisabledUsers != null && DisabledUsers.Count > 0)
            {
                script.AppendFormat("\n{0}.DisabledUserIDs = [", _jsObjName);
                foreach (var u in DisabledUsers)
                {
                    script.AppendFormat("'{0}',", u);
                }
                script.Remove(script.Length - 1, 1);
                script.Append("];\n");
            }

            Page.ClientScript.RegisterClientScriptBlock(GetType(), Guid.NewGuid().ToString(), script.ToString(), true);

            script = new StringBuilder();

            script.AppendFormat("{0}.AllDepartmentsGroupName = '{1}';\n", _jsObjName, Resources.AdvancedUserSelectorResource.AllDepartments.HtmlEncode().ReplaceSingleQuote());

            if (!String.IsNullOrEmpty(AdditionalFunction))
            {
                script.AppendFormat("{0}.AdditionalFunction = {1};", _jsObjName, AdditionalFunction);
            }


            if (!Guid.Empty.Equals(SelectedUserId))
            {
                script.AppendFormat("{0}.SelectedUserId = '{1}';\n", _jsObjName, SelectedUserId);
            }
            else if (IsMobileVersion)
            {
                script.AppendFormat("{0}.SelectedUserId = {0}.Me().find('option:first').attr('selected', 'selected').val();", _jsObjName);
            }

            script.Append("jq(function(){jq(document).click(function(event){\n");
            script.Append(_jsObjName + ".dropdownRegAutoHide(event);\n");
            script.Append("}); });\n");

            Page.ClientScript.RegisterStartupScript(GetType(), Guid.NewGuid().ToString(), script.ToString(), true);
        }