//-----------------------------------------------------------------------
// <copyright file="SelectItemsAction.cs" company="motion10">
// Copyright (c) motion10. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
using System.Globalization;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace Motion10.SharePoint2007 { public class SelectItemsAction : MenuItemTemplate { /// <summary>
/// Initializes a new instance of the <see cref="DownloadViewAsZipAction"/> class.
/// </summary>
public SelectItemsAction()
: base("Enable item selection", "/_layouts/images/motion10/ListItemSelection.gif") { base.Description = "Enable the selection of items.";
}
/// <summary>
/// Raises an event after the control is loaded but prior to rendering.
/// </summary>
/// <param name="args">An <see cref="T:System.EventArgs"></see> object that contains the event data.</param>
[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
protected override void OnPreRender(System.EventArgs args) { base.OnPreRender(args);
if (this.ListViewWebPart == null) { return;
}
if (!Page.ClientScript.IsClientScriptIncludeRegistered("ListItemSelection")) { Page.ClientScript.RegisterClientScriptInclude("ListItemSelection", "/_layouts/ListItemSelection.js"); }
string startupScript = string.Format(CultureInfo.InvariantCulture,
"$(function(){{ListItemSelection_Init('{0}', 'WebPart{1}');}});", this.ClientID,
this.ListViewWebPart.Qualifier);
Page.ClientScript.RegisterStartupScript(typeof(SelectItemsAction), this.ClientID, startupScript, true);
}
/// <summary>
/// Sends the content of the control to the specified <see cref="T:System.Web.UI.HtmlTextWriter"></see> object, which writes the content that is rendered on the client.
/// </summary>
/// <param name="output">The HtmlTextWriter object that receives the server control content.</param>
[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
protected override void Render(System.Web.UI.HtmlTextWriter output) { if (this.ListViewWebPart == null || this.ListViewWebPart.ViewType != ViewType.Html) { this.Visible = false;
}
if (this.Visible) { string clientScript = string.Format(CultureInfo.InvariantCulture,
"ListItemSelection_ButtonClick('{0}', 'WebPart{1}')", this.ClientID,
listViewWebPart.Qualifier);
this.ClientOnClickScript = clientScript;
}
base.Render(output);
}
private bool searchedForListView = false;
private ListViewWebPart listViewWebPart;
private ListViewWebPart ListViewWebPart { get { if (!searchedForListView) { listViewWebPart = FindListView(this.Parent);
}
return listViewWebPart;
}
}
private static ListViewWebPart FindListView(Control parent) { ListViewWebPart retVal = parent as ListViewWebPart;
if (retVal != null) { return retVal;
}
if (parent.Parent == null) return null;
return FindListView(parent.Parent);
}
}
}