/// <summary> /// Handles the UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that throws event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void webpartGrid_OnAction(string actionName, object actionArgument) { int webpartId = Convert.ToInt32(actionArgument); switch (actionName) { case "delete": // Check 'Modify' permission if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.webpart", "Modify")) { RedirectToAccessDenied("cms.webpart", "Modify"); } // Check if webpart has widgets DataSet dsWidgets = WidgetInfoProvider.GetWidgets("WidgetWebPartID = " + webpartId, null, 0, "WidgetWebPartID"); if (!DataHelper.DataSourceIsEmpty(dsWidgets)) { string delPostback = ControlsHelper.GetPostBackEventReference(Page, webpartId.ToString()); delPostback = "if (confirm('" + GetString("webparts.deletewithwidgets") + "')) {\n " + delPostback + ";}\n"; ltlScript.Text = ScriptHelper.GetScript(delPostback); } else { // Delete PageTemplateInfo object from database WebPartInfoProvider.DeleteWebPartInfo(webpartId); // Refresh tree ltlScript.Text = ScriptHelper.GetScript("RefreshAdditionalContent();"); } break; } }
/// <summary> /// Gets and bulk updates widgets. Called when the "Get and bulk update widgets" button is pressed. /// Expects the CreateWidget method to be run first. /// </summary> private bool GetAndBulkUpdateWidgets() { // Prepare the parameters string where = "WidgetName LIKE N'MyNewWidget%'"; string orderBy = ""; int topN = 0; string columns = ""; // Get the data DataSet widgets = WidgetInfoProvider.GetWidgets(where, orderBy, topN, columns); if (!DataHelper.DataSourceIsEmpty(widgets)) { // Loop through the individual items foreach (DataRow widgetDr in widgets.Tables[0].Rows) { // Create object from DataRow WidgetInfo modifyWidget = new WidgetInfo(widgetDr); // Update the properties modifyWidget.WidgetDisplayName = modifyWidget.WidgetDisplayName.ToUpper(); // Save the changes WidgetInfoProvider.SetWidgetInfo(modifyWidget); } return(true); } return(false); }
/// <summary> /// Handles OnFieldCreated action and updates form definition of all widgets based on current webpart. /// Newly created field is set to be disabled in widget definition for security reasons. /// </summary> /// <param name="newField">Newly created field</param> protected void UpdateWidgetsDefinition(object sender, FormFieldInfo newField) { if ((webPartInfo != null) && (newField != null)) { // Get widgets based on this webpart DataSet ds = WidgetInfoProvider.GetWidgets() .WhereEquals("WidgetWebPartID", WebPartID) .Columns("WidgetID"); // Continue only if there are some widgets if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { int widgetId = ValidationHelper.GetInteger(dr["WidgetID"], 0); WidgetInfo widget = WidgetInfoProvider.GetWidgetInfo(widgetId); if (widget != null) { // Prepare disabled field definition string disabledField = String.Format("<form><field column=\"{0}\" visible=\"false\" /></form>", newField.Name); // Incorporate disabled field into original definition of widget widget.WidgetProperties = FormHelper.CombineFormDefinitions(widget.WidgetProperties, disabledField); // Update widget WidgetInfoProvider.SetWidgetInfo(widget); } } } } }
/// <summary> /// Update web part properties default values /// </summary> private static void UpdateWidgetProperties() { try { List <string> wpGuid = new List <string>() { "D6EC4B53-781E-4240-98F4-F4D64873A482", "09F5FF6C-F2A1-4322-AEA6-6B0D61CD1375", "1CEF5345-672E-4571-A0BD-BC7BD217B1A0", "90994364-454F-4457-98FE-6EB78D2B452C" }; // Get inherited webparts with properties stored in old way string where = "WidgetDefaultValues LIKE N'%field name=\"%' AND WidgetGUID NOT IN ('" + wpGuid.Join("','") + "')"; InfoDataSet <WidgetInfo> data = WidgetInfoProvider.GetWidgets().Where(where).TypedResult; if (!DataHelper.DataSourceIsEmpty(data)) { foreach (WidgetInfo info in data) { info.WidgetDefaultValues = ModifyProperties(info.WidgetDefaultValues); // Update widget info.Update(); } } } catch (Exception ex) { EventLogProvider.LogException("Upgrade - Widget properties", "Upgrade", ex); } }
void fieldEditor_AfterItemDeleted(object sender, FieldEditorEventArgs e) { if (e == null) { return; } // Remove deleted field or category from inherited web parts InfoDataSet <WebPartInfo> webParts = WebPartInfoProvider.GetWebParts() .WhereEquals("WebPartParentID", WebPartID).TypedResult; if (!DataHelper.DataSourceIsEmpty(webParts)) { foreach (WebPartInfo info in webParts) { switch (e.ItemType) { case FieldEditorSelectedItemEnum.Field: info.WebPartProperties = FormHelper.RemoveFieldFromAlternativeDefinition(info.WebPartProperties, e.ItemName, e.ItemOrder); break; case FieldEditorSelectedItemEnum.Category: info.WebPartProperties = FormHelper.RemoveCategoryFromAlternativeDefinition(info.WebPartProperties, e.ItemName, e.ItemOrder); break; } // Update web part info.Update(); } } // Remove deleted field or category from widgets based on this web part InfoDataSet <WidgetInfo> widgets = WidgetInfoProvider.GetWidgets() .WhereEquals("WidgetWebPartID", WebPartID).TypedResult; if (!DataHelper.DataSourceIsEmpty(widgets)) { foreach (WidgetInfo info in widgets) { switch (e.ItemType) { case FieldEditorSelectedItemEnum.Field: info.WidgetProperties = FormHelper.RemoveFieldFromAlternativeDefinition(info.WidgetProperties, e.ItemName, e.ItemOrder); break; case FieldEditorSelectedItemEnum.Category: info.WidgetProperties = FormHelper.RemoveCategoryFromAlternativeDefinition(info.WidgetProperties, e.ItemName, e.ItemOrder); break; } // Update widget info.Update(); } } }
protected void Page_Load(object sender, EventArgs e) { // Security test if (!CMSContext.CurrentUser.UserSiteManagerAdmin) { RedirectToAccessDenied(GetString("attach.actiondenied")); } // Add link to external stylesheet CSSHelper.RegisterCSSLink(this, "Default", "/CMSDesk.css"); // Get current resolver resolver = CMSContext.CurrentResolver.CreateContextChild(); DataSet ds = null; DataSet cds = null; // Check init settings bool allWidgets = QueryHelper.GetBoolean("allWidgets", false); bool allWebParts = QueryHelper.GetBoolean("allWebparts", false); // Get webpart (widget) from querystring - only if no allwidget or allwebparts set bool isWebpartInQuery = false; bool isWidgetInQuery = false; String webpartQueryParam = String.Empty; //If not show all widgets or webparts - check if any widget or webpart is present if ((!allWidgets) && (!allWebParts)) { webpartQueryParam = QueryHelper.GetString("webpart", ""); if (!string.IsNullOrEmpty(webpartQueryParam)) { isWebpartInQuery = true; } else { webpartQueryParam = QueryHelper.GetString("widget", ""); if (!string.IsNullOrEmpty(webpartQueryParam)) { isWidgetInQuery = true; } } } // Set development option if is required if (QueryHelper.GetString("details", "0") == "1") { development = true; } // Generate all webparts if (allWebParts) { // Get all webpart categories cds = WebPartCategoryInfoProvider.GetAllCategories(); } // Generate all widgets else if (allWidgets) { // Get all widget categories cds = WidgetCategoryInfoProvider.GetWidgetCategories(String.Empty, String.Empty, 0, String.Empty); } // Generate single webpart else if (isWebpartInQuery) { // Split weparts string[] webparts = webpartQueryParam.Split(';'); if (webparts.Length > 0) { string webpartWhere = SqlHelperClass.GetWhereCondition("WebpartName", webparts); ds = WebPartInfoProvider.GetWebParts(webpartWhere, null); // If any webparts found if (!DataHelper.DataSourceIsEmpty(ds)) { StringBuilder categoryWhere = new StringBuilder(""); foreach (DataRow dr in ds.Tables[0].Rows) { categoryWhere.Append(ValidationHelper.GetString(dr["WebpartCategoryID"], "NULL") + ","); } string ctWhere = "CategoryID IN (" + categoryWhere.ToString().TrimEnd(',') + ")"; cds = WebPartCategoryInfoProvider.GetCategories(ctWhere, null); } } } // Generate single widget else if (isWidgetInQuery) { string[] widgets = webpartQueryParam.Split(';'); if (widgets.Length > 0) { string widgetsWhere = SqlHelperClass.GetWhereCondition("WidgetName", widgets); ds = WidgetInfoProvider.GetWidgets(widgetsWhere, null, 0, String.Empty); } if (!DataHelper.DataSourceIsEmpty(ds)) { StringBuilder categoryWhere = new StringBuilder(""); foreach (DataRow dr in ds.Tables[0].Rows) { categoryWhere.Append(ValidationHelper.GetString(dr["WidgetCategoryID"], "NULL") + ","); } string ctWhere = "WidgetCategoryID IN (" + categoryWhere.ToString().TrimEnd(',') + ")"; cds = WidgetCategoryInfoProvider.GetWidgetCategories(ctWhere, null, 0, String.Empty); } } if (allWidgets || isWidgetInQuery) { documentationTitle = "Kentico CMS Widgets"; Page.Header.Title = "Widgets documentation"; } if (!allWebParts && !allWidgets && !isWebpartInQuery && !isWidgetInQuery) { pnlContent.Visible = false; pnlInfo.Visible = true; } // Check whether at least one category is present if (!DataHelper.DataSourceIsEmpty(cds)) { string namePrefix = ((isWidgetInQuery) || (allWidgets)) ? "Widget" : String.Empty; // Loop through all web part categories foreach (DataRow cdr in cds.Tables[0].Rows) { // Get all webpart in the categories if (allWebParts) { ds = WebPartInfoProvider.GetAllWebParts(Convert.ToInt32(cdr["CategoryId"])); } // Get all widgets in the category else if (allWidgets) { int categoryID = Convert.ToInt32(cdr["WidgetCategoryId"]); ds = WidgetInfoProvider.GetWidgets("WidgetCategoryID = " + categoryID.ToString(), null, 0, null); } // Check whether current category contains at least one webpart if (!DataHelper.DataSourceIsEmpty(ds)) { // Generate category name code menu += "<br /><strong>" + HTMLHelper.HTMLEncode(cdr[namePrefix + "CategoryDisplayName"].ToString()) + "</strong><br /><br />"; // Loop through all web web parts in categories foreach (DataRow dr in ds.Tables[0].Rows) { // Init isImagePresent = false; undocumentedProperties = 0; documentation = 0; // Webpart (Widget) information string itemDisplayName = String.Empty; string itemDescription = String.Empty; string itemDocumentation = String.Empty; string itemType = String.Empty; int itemID = 0; WebPartInfo wpi = null; WidgetInfo wi = null; // Set webpart info if ((isWebpartInQuery) || (allWebParts)) { wpi = new WebPartInfo(dr); if (wpi != null) { itemDisplayName = wpi.WebPartDisplayName; itemDescription = wpi.WebPartDescription; itemDocumentation = wpi.WebPartDocumentation; itemID = wpi.WebPartID; itemType = PortalObjectType.WEBPART; if (wpi.WebPartCategoryID != ValidationHelper.GetInteger(cdr["CategoryId"], 0)) { wpi = null; } } } // Set widget info else if ((isWidgetInQuery) || (allWidgets)) { wi = new WidgetInfo(dr); if (wi != null) { itemDisplayName = wi.WidgetDisplayName; itemDescription = wi.WidgetDescription; itemDocumentation = wi.WidgetDocumentation; itemType = PortalObjectType.WIDGET; itemID = wi.WidgetID; if (wi.WidgetCategoryID != ValidationHelper.GetInteger(cdr["WidgetCategoryId"], 0)) { wi = null; } } } // Check whether web part (widget) exists if ((wpi != null) || (wi != null)) { // Link GUID Guid mguid = Guid.NewGuid(); // Whether description is present in webpart bool isDescription = false; // Image url string wimgurl = GetItemImage(itemID, itemType); // Set description text string descriptionText = itemDescription; // Parent webpart info WebPartInfo pwpi = null; // If webpart look for parent's description and documentation if (wpi != null) { // Get parent description if webpart is inherited if (wpi.WebPartParentID > 0) { pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { if ((descriptionText == null || descriptionText.Trim() == "")) { // Set description from parent descriptionText = pwpi.WebPartDescription; } // Set documentation text from parent if WebPart is inherited if ((wpi.WebPartDocumentation == null) || (wpi.WebPartDocumentation.Trim() == "")) { itemDocumentation = pwpi.WebPartDocumentation; if (!String.IsNullOrEmpty(itemDocumentation)) { documentation = 2; } } } } } // Set description as present if (descriptionText.Trim().Length > 0) { isDescription = true; } // Generate HTML for menu and content menu += " <a href=\"#_" + mguid.ToString() + "\">" + HTMLHelper.HTMLEncode(itemDisplayName) + "</a> "; // Generate webpart header content += "<table style=\"width:100%;\"><tr><td><h1><a name=\"_" + mguid.ToString() + "\">" + HTMLHelper.HTMLEncode(cdr[namePrefix + "CategoryDisplayName"].ToString()) + " > " + HTMLHelper.HTMLEncode(itemDisplayName) + "</a></h1></td><td style=\"text-align:right;\"> <a href=\"#top\" class=\"noprint\">top</a></td></tr></table>"; // Generate WebPart content content += @"<table style=""width: 100%; height: 200px; border: solid 1px #DDDDDD;""> <tr> <td style=""width: 50%; text-align:center; border-right: solid 1px #DDDDDD; vertical-align: middle;margin-left: auto; margin-right:auto; text-align:center;""> <img src=""" + wimgurl + @""" alt=""imageTeaser""> </td> <td style=""width: 50%; vertical-align: center;text-align:center;"">" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(descriptionText)) + @" </td> </tr> </table>"; // Properties content content += "<div class=\"DocumentationWebPartsProperties\">"; // Generate content if (wpi != null) { GenerateDocContent(CreateFormInfo(wpi)); } else if (wi != null) { GenerateDocContent(CreateFormInfo(wi)); } // Close content area content += "</div>"; // Generate documentation text content content += "<br /><div style=\"border: solid 1px #dddddd;width: 100%;\">" + DataHelper.GetNotEmpty(HTMLHelper.ResolveUrls(itemDocumentation, null), "<strong>Additional documentation text is not provided.</strong>") + "</div>"; // Set page break tag for print content += "<br /><p style=\"page-break-after: always;width:100%\"> </p><hr class=\"noprint\" />"; // If development is required - highlight missing description, images and doc. text if (development) { // Check image if (!isImagePresent) { menu += "<span style=\"color:Brown;\">image </span>"; } // Check properties if (undocumentedProperties > 0) { menu += "<span style=\"color:Red;\">properties(" + undocumentedProperties + ") </span>"; } // Check properties if (!isDescription) { menu += "<span style=\"color:#37627F;\">description </span>"; } // Check documentation text if (String.IsNullOrEmpty(itemDocumentation)) { documentation = 1; } switch (documentation) { // Display information about missing documentation case 1: menu += "<span style=\"color:Green;\">documentation </span>"; break; // Display information about inherited documentation case 2: menu += "<span style=\"color:Green;\">documentation (inherited) </span>"; break; } } menu += "<br />"; } } } } } ltlContent.Text = menu + "<br /><p style=\"page-break-after: always;width:100%\"> </p><hr class=\"noprint\" />" + content; }
/// <summary> /// Handles delete action. /// </summary> /// <param name="eventArgument">Objecttype(widget or widgetcategory);objectid</param> public void RaisePostBackEvent(string eventArgument) { string[] values = eventArgument.Split(';'); if ((values != null) && (values.Length == 3)) { int id = ValidationHelper.GetInteger(values[1], 0); int parentId = ValidationHelper.GetInteger(values[2], 0); string script = String.Empty; bool stayOnWebpart = false; switch (values[0]) { case "webpart": // Check if webpart has widgets DataSet dsWidgets = WidgetInfoProvider.GetWidgets("WidgetWebPartID = " + id, null, 0, "WidgetWebPartID"); if (!DataHelper.DataSourceIsEmpty(dsWidgets)) { string delPostback = ControlsHelper.GetPostBackEventReference(Page, "##"); script = "if (confirm('" + GetString("webparts.deletewithwidgets") + "')) {\n " + delPostback.Replace("'##'", "'webpartwidget;'+" + id + "+';'+" + parentId + "") + ";}\n"; stayOnWebpart = true; break; } WebPartInfoProvider.DeleteWebPartInfo(id); break; case "webpartcategory": try { WebPartCategoryInfoProvider.DeleteCategoryInfo(id); } catch (Exception ex) { // Make alert with exception message, most probable cause is deleting category with subcategories script = String.Format("alert('{0}');\n", ex.Message); // Current node stays selected parentId = id; } break; case "webpartwidget": WebPartInfoProvider.DeleteWebPartInfo(id); break; } // Select parent node after delete WebPartCategoryInfo wci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(parentId); if (wci != null) { if (!stayOnWebpart) { // Select category script = SelectAtferLoad(wci.CategoryPath + "/", parentId, "webpartcategory", wci.CategoryParentID) + script; } else { // Stay on selected webpart script = SelectAtferLoad(wci.CategoryPath + "/", id, "webpart", wci.CategoryID) + script; } } ltlScript.Text += ScriptHelper.GetScript(script); treeElem.ReloadData(); treeWireframes.ReloadData(); } }