javascript sharepoint-2010 mysite

javascript - SharePoint 2010: cree un botón de marcador que agregue una página a Mis enlaces



sharepoint-2010 mysite (2)

Intento crear un enlace / botón en mi página maestra que, al hacer clic, agrega la página actual a la lista Mis enlaces del usuario. Esto es simplemente un atajo para evitar que el usuario tenga que navegar a Mi sitio y agregar el enlace manualmente.

[Esta publicación de blog] brinda una solución a este problema, pero aparece un error de JavaScript en la segunda línea del cuadro de diálogo "Agregar enlace" (QuickLinksDialog2.aspx) porque la propiedad frameElement es nula:

<script language="Javascript"> var form = document.forms[0]; var args = window.parent.frameElement.dialogArgs;

De todos modos, Portal.js parece contener todas las funciones que la página Mis enlaces (_layouts / MyQuickLinks.aspx) usa para agregar enlaces a esta lista.

¿Alguien puede sugerir cómo puedo llamar a una / algunas de estas funciones de mi página principal para que el cuadro de diálogo "Agregar enlace" se abra con los campos de título y URL pre-pulados?


Terminé usando el modelo de objetos para crear Mis enlaces (como se apuntó al diálogo emergente).

Lo bueno de esto es que agregar un enlace ahora es solo un proceso de 1 clic, la desventaja es que el usuario no tiene la oportunidad de cambiar el nombre del enlace o asignarlo a un grupo (personalmente, he ocultado los grupos del UI de todos modos, ya que no los necesitamos, así que esto no fue un problema para mí).

Para los interesados, creé un pequeño control de usuario que solo alberga un botón ajaxificado que puedes colocar en tu página maestra / diseño de página. Mi código para esto es el siguiente:

HTML

<script type="text/javascript"> function FavouriteImageButton_AddMyLink_Clicked() { SP.UI.Notify.addNotification("Bookmark generated successfully."); } function FavouriteImageButton_RemoveMyLink_Clicked() { SP.UI.Notify.addNotification("Bookmark deleted successfully."); } </script> <asp:UpdatePanel ID="UpdatePanel" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional"> <ContentTemplate> <asp:ImageButton ID="FavouriteImageButon" runat="server" OnCommand="FavouriteImageButton_Command" /> </ContentTemplate> </asp:UpdatePanel>

DO#

private struct FavouriteButtonCommandNames { public const string AddMyLink = "AddMyLink"; public const string RemoveMyLink = "RemoveMyLink"; } protected void Page_PreRender(object sender, EventArgs e) { // Initialise the favourites button according to whether or not the page already exists in the My Links list. this.FavouriteImageButon.ImageUrl = "/_layouts/images/favourite_add.png"; this.FavouriteImageButon.AlternateText = "Add to My Links"; this.FavouriteImageButon.CommandName = FavouriteButtonCommandNames.AddMyLink; this.FavouriteImageButon.CommandArgument = null; UserProfileManager userProfileManager = new UserProfileManager(SPServiceContext.Current); UserProfile currentUser = userProfileManager.GetUserProfile(false); foreach (QuickLink quickLink in currentUser.QuickLinks.GetItems()) { if (quickLink.Url.ToLower() == this.Page.Request.Url.ToString().ToLower()) { this.FavouriteImageButon.ImageUrl = "/_layouts/images/favourite_delete.png"; this.FavouriteImageButon.AlternateText = "Remove from My Links"; this.FavouriteImageButon.CommandName = FavouriteButtonCommandNames.RemoveMyLink; this.FavouriteImageButon.CommandArgument = quickLink.ID.ToString(); break; } } } protected void FavouriteImageButton_Command(object sender, CommandEventArgs e) { UserProfileManager userProfileManager = new UserProfileManager(SPServiceContext.Current); UserProfile currentUser = userProfileManager.GetUserProfile(false); switch (e.CommandName) { case FavouriteButtonCommandNames.AddMyLink: // Create the link. currentUser.QuickLinks.Create( SPContext.Current.File.Title, this.Page.Request.Url.ToString(), QuickLinkGroupType.General, null, Privacy.Private); // Display a notification message. ScriptManager.RegisterStartupScript(this.UpdatePanel, this.UpdatePanel.GetType(), e.CommandName, "ExecuteOrDelayUntilScriptLoaded(FavouriteImageButton_AddMyLink_Clicked, /"sp.js/");", true); break; case FavouriteButtonCommandNames.RemoveMyLink: long id; if (long.TryParse((string)e.CommandArgument, out id)) { // Delete the link. QuickLink quickLink = currentUser.QuickLinks[long.Parse((string)e.CommandArgument)]; quickLink.Delete(); // Display a notification message. ScriptManager.RegisterStartupScript(this.UpdatePanel, this.UpdatePanel.GetType(), e.CommandName, "ExecuteOrDelayUntilScriptLoaded(FavouriteImageButton_RemoveMyLink_Clicked, /"sp.js/");", true); } else { throw new ArgumentNullException("e.CommandArgument", "/"{0}/" is not a valid QuickLink ID. The QuickLink could not be removed from the list."); } break; } }


Agregue la siguiente función a su página maestra:

function addlink(){ t=document.title; u=escape(location.href); var q = window.location.protocol + "//" + window.location.host + "/_vti_bin/portalapi.aspx?cmd=PinToMyPage&ListViewURL=" + u + "&ListTitle=" + t + "&IsDlg-1"; // + "&ReturnUrl=" + u; location.href = q; }

A continuación, agregue su etiqueta de anclaje:

<a href=''javascript:addlink()''>Add this Page</a>