using System; using System.Web.UI.WebControls; using System.Data; using CMS.CMSHelper; using CMS.GlobalHelper; using CMS.PortalEngine; using CMS.SettingsProvider; using CMS.UIControls; public partial class CMSModules_Widgets_UI_Widget_List : SiteManagerPage { #region "Variables" protected int categoryId = 0; #endregion #region "Page events" /// /// Handles the Load event of the Page control. /// protected void Page_Load(object sender, EventArgs e) { categoryId = QueryHelper.GetInteger("categoryid", 0); // Register script for refresh tree after delete/destroy string script = @"function RefreshAdditionalContent() { if (parent.parent.frames['widgettree']) { parent.parent.frames['widgettree'].location.href = '" + URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/WidgetTree.aspx?categoryid=" + categoryId) + @"'; } }"; ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "RefreshTree", ScriptHelper.GetScript(script)); // Used for delete calls int widgetId = QueryHelper.GetInteger("widgetid", 0); // Configure the UniGrid WidgetCategoryInfo categoryInfo = WidgetCategoryInfoProvider.GetWidgetCategoryInfo(categoryId); if (categoryInfo != null) { string categoryPath = categoryInfo.WidgetCategoryPath; // Add the slash character at the end of the categoryPath if (!categoryPath.EndsWithCSafe("/")) { categoryPath += "/"; } widgetGrid.WhereCondition = "ObjectPath LIKE '" + SqlHelperClass.GetSafeQueryString(categoryPath, false) + "%' AND ObjectType = 'widget'"; } widgetGrid.OnAction += pageTemplatesGrid_OnAction; widgetGrid.ZeroRowsText = GetString("general.nodatafound"); InitializeMasterPage(); } #endregion #region "UniGrid events" /// /// Handles the UniGrid's OnAction event. /// /// Name of item (button) that throws event /// ID (value of Primary key) of corresponding data row protected void pageTemplatesGrid_OnAction(string actionName, object actionArgument) { int widgetId = Convert.ToInt32(actionArgument); switch (actionName) { case "delete": // Check 'Modify' permission if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.widget", "Modify")) { RedirectToAccessDenied("cms.widget", "Modify"); } // delete PageTemplateInfo object from database WidgetInfoProvider.DeleteWidgetInfo(widgetId); // Refresh tree ltlScript.Text = ScriptHelper.GetScript("RefreshAdditionalContent();"); break; } } #endregion #region "Other methods" /// /// Initializes Master Page. /// protected void InitializeMasterPage() { Title = "Widget list"; } #endregion }