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 += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"#_" + mguid.ToString() + "\">" + HTMLHelper.HTMLEncode(itemDisplayName) + "</a>&nbsp;";

                            // Generate webpart header
                            content += "<table style=\"width:100%;\"><tr><td><h1><a name=\"_" + mguid.ToString() + "\">" + HTMLHelper.HTMLEncode(cdr[namePrefix + "CategoryDisplayName"].ToString()) + "&nbsp;>&nbsp;" + HTMLHelper.HTMLEncode(itemDisplayName) + "</a></h1></td><td style=\"text-align:right;\">&nbsp;<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%\">&nbsp;</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&nbsp;</span>";
                                }

                                // Check properties
                                if (undocumentedProperties > 0)
                                {
                                    menu += "<span style=\"color:Red;\">properties(" + undocumentedProperties + ")&nbsp;</span>";
                                }

                                // Check properties
                                if (!isDescription)
                                {
                                    menu += "<span style=\"color:#37627F;\">description&nbsp;</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&nbsp;</span>";
                                    break;

                                // Display information about inherited documentation
                                case 2:
                                    menu += "<span style=\"color:Green;\">documentation (inherited)&nbsp;</span>";
                                    break;
                                }
                            }

                            menu += "<br />";
                        }
                    }
                }
            }
        }

        ltlContent.Text = menu + "<br /><p style=\"page-break-after: always;width:100%\">&nbsp;</p><hr class=\"noprint\" />" + content;
    }
    /// <summary>
    /// Reloads the data.
    /// </summary>
    /// <param name="forceReload">If true, the data is reloaded even when already loaded</param>
    public void ReloadData(bool forceReload)
    {
        if (!dataLoaded || forceReload)
        {
            drpWebpart.Items.Clear();

            // Do not retrieve webparts
            WhereCondition condition = new WhereCondition(WhereCondition);
            if (!ShowWebparts)
            {
                condition.WhereEquals("ObjectType", "webpartcategory");
            }

            if (!ShowInheritedWebparts)
            {
                condition.WhereNull("WebPartParentID");
            }

            if (!String.IsNullOrEmpty(RootPath))
            {
                string rootPath = RootPath.TrimEnd('/');
                condition.Where(new WhereCondition().WhereEquals("ObjectPath", rootPath).Or().WhereStartsWith("ObjectPath", rootPath + "/"));
            }

            ds = WebPartCategoryInfoProvider.GetCategoriesAndWebparts(condition.ToString(true), "DisplayName", 0, "ObjectID, DisplayName, ParentID, ObjectType");

            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                int counter = 0;

                // Make special collection for "tree mapping"
                Dictionary <int, SortedList <string, object[]> > categories = new Dictionary <int, SortedList <string, object[]> >();

                // Fill collection from dataset
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int    parentId = ValidationHelper.GetInteger(dr["ParentID"], 0);
                    int    id       = ValidationHelper.GetInteger(dr["ObjectID"], 0);
                    string name     = ResHelper.LocalizeString(ValidationHelper.GetString(dr["DisplayName"], String.Empty));
                    string type     = ValidationHelper.GetString(dr["ObjectType"], String.Empty);

                    // Skip webpart, take only WebpartCategory
                    if (type == "webpart")
                    {
                        continue;
                    }

                    SortedList <string, object[]> list;
                    categories.TryGetValue(parentId, out list);

                    // Sub categories list not created yet
                    if (list == null)
                    {
                        list = new SortedList <string, object[]>();
                        categories.Add(parentId, list);
                    }

                    list.Add(name + "_" + counter, new object[] { id, name });

                    counter++;
                }

                // Start filling the dropdown from the root(parentId = 0)
                int level = 0;

                // Root is not shown, start indentation later
                if (!ShowRoot)
                {
                    level = -1;
                }

                AddSubCategories(categories, 0, level);
            }

            dataLoaded = true;
        }
    }
Пример #3
0
    /// <summary>
    /// Reloads the web part list.
    /// </summary>
    /// <param name="forceLoad">if set to <c>true</c>, reload the control even if the control has been already loaded</param>
    protected void LoadWebParts(bool forceLoad)
    {
        if (!dataLoaded || forceLoad)
        {
            var repeaterWhere = new WhereCondition();

            /* The order is category driven => first level category display name is used for all nodes incl. sub-nodes */
            string categoryOrder = @"
(SELECT CMS_WebPartCategory.CategoryDisplayName FROM CMS_WebPartCategory 
WHERE CMS_WebPartCategory.CategoryPath = (CASE WHEN (CHARINDEX('/', ObjectPath, 0) > 0) AND (CHARINDEX('/', ObjectPath, CHARINDEX('/', ObjectPath, 0) + 1) = 0) 
THEN ObjectPath 
ELSE SUBSTRING(ObjectPath, 0, LEN(ObjectPath) - (LEN(ObjectPath) - CHARINDEX('/', ObjectPath, CHARINDEX('/', ObjectPath, 0) + 1)))
END))
";

            // Set query repeater
            repItems.SelectedColumns = " ObjectID, DisplayName, ObjectType, ParentID, ThumbnailGUID, IconClass, ObjectLevel, WebPartDescription, WebPartSkipInsertProperties";
            repItems.OrderBy         = categoryOrder + ", ObjectType  DESC, DisplayName";

            // Setup the where condition
            if (SelectedCategory == CATEGORY_RECENTLY_USED)
            {
                // Recently used category
                RenderRecentlyUsedWebParts(true);
            }
            else
            {
                // Specific web part category
                int selectedCategoryId = ValidationHelper.GetInteger(SelectedCategory, 0);
                if (selectedCategoryId > 0)
                {
                    WebPartCategoryInfo categoryInfo = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(selectedCategoryId);
                    if (categoryInfo != null)
                    {
                        string firstLevelCategoryPath = String.Empty;

                        // Select also all subcategories (using "/%")
                        string categoryPath = categoryInfo.CategoryPath;
                        if (!categoryPath.EndsWith("/", StringComparison.Ordinal))
                        {
                            categoryPath += "/";
                        }

                        // Do not limit items if not root category is selected
                        if (!categoryInfo.CategoryPath.EqualsCSafe("/"))
                        {
                            limitItems = false;
                        }

                        // Get all web parts for the selected category and its subcategories
                        if (categoryPath.EqualsCSafe("/"))
                        {
                            repeaterWhere.Where(repItems.WhereCondition).Where(w => w
                                                                               .WhereEquals("ObjectType", "webpart")
                                                                               .Or()
                                                                               .WhereEquals("ObjectLevel", 1)
                                                                               ).Where(w => w
                                                                                       .WhereEquals("ParentID", selectedCategoryId)
                                                                                       .Or()
                                                                                       .WhereIn("ParentID", WebPartCategoryInfoProvider.GetCategories().WhereStartsWith("CategoryPath", categoryPath))
                                                                                       );

                            // Set caching for query repeater
                            repItems.ForceCacheMinutes = true;
                            repItems.CacheMinutes      = 24 * 60;
                            repItems.CacheDependencies = "cms.webpart|all\ncms.webpartcategory|all";

                            // Show Recently used category
                            RenderRecentlyUsedWebParts(false);
                        }
                        else
                        {
                            // Prepare where condition -- the part that restricts web parts
                            repeaterWhere.WhereEquals("ObjectType", "webpart")
                            .Where(w => w
                                   .WhereEquals("ParentID", selectedCategoryId)
                                   .Or()
                                   .WhereIn("ParentID", WebPartCategoryInfoProvider.GetCategories().WhereStartsWith("CategoryPath", categoryPath))
                                   );

                            // Get first level category path
                            firstLevelCategoryPath = categoryPath.Substring(0, categoryPath.IndexOf('/', 2));

                            var selectedCategoryWhere = new WhereCondition();

                            // Distinguish special categories
                            if (categoryPath.StartsWithCSafe(CATEGORY_UIWEBPARTS, true))
                            {
                                if (!categoryPath.EqualsCSafe(firstLevelCategoryPath + "/", true))
                                {
                                    // Currently selected category is one of subcategories
                                    string specialCategoryPath = firstLevelCategoryPath;
                                    firstLevelCategoryPath = categoryPath.Substring(CATEGORY_UIWEBPARTS.Length + 1).TrimEnd('/');
                                    selectedCategoryWhere.WhereEquals("ObjectPath", specialCategoryPath + "/" + firstLevelCategoryPath);
                                }
                                else
                                {
                                    // Currently selected category is root category
                                    selectedCategoryWhere.WhereStartsWith("ObjectPath", firstLevelCategoryPath);
                                }
                            }
                            else
                            {
                                // All web part category
                                selectedCategoryWhere.WhereEquals("ObjectPath", firstLevelCategoryPath);
                            }

                            repeaterWhere.Or().Where(w => w
                                                     .WhereEquals("ObjectType", "webpartcategory")
                                                     .WhereEquals("ObjectLevel", 1)
                                                     .Where(selectedCategoryWhere)
                                                     );

                            // Set caching for query repeater
                            repItems.CacheMinutes      = 0;
                            repItems.ForceCacheMinutes = true;
                        }
                    }
                }

                // Do not display "Widget only" web parts in the toolbar
                repItems.WhereCondition = new WhereCondition()
                                          .Where(repeaterWhere)
                                          .Where(w => w
                                                 .WhereNull("WebPartType")
                                                 .Or()
                                                 .WhereNotEquals("WebPartType", (int)WebPartTypeEnum.WidgetOnly)
                                                 )
                                          .ToString(true);

                // Limit items if required
                if (limitItems)
                {
                    repItems.SelectTopN = DEFAULT_WEBPART_COUNT;
                }

                repItems.ReloadData(false);
                repItems.DataBind();
            }

            dataLoaded = true;
        }
    }
Пример #4
0
    /// <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();
        }
    }
Пример #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Register scripts
        ScriptHelper.RegisterJQuery(Page);
        RegisterExportScript();

        treeElem.UseGlobalSettings       = true;
        treeWireframes.UseGlobalSettings = true;

        // Images
        imgNewCategory.ImageUrl  = GetImageUrl("Objects/CMS_WebPartCategory/add.png");
        imgNewWebPart.ImageUrl   = GetImageUrl("Objects/CMS_WebPart/add.png");
        imgDeleteItem.ImageUrl   = GetImageUrl("Objects/CMS_WebPart/delete.png");
        imgExportObject.ImageUrl = GetImageUrl("Objects/CMS_WebPart/export.png");
        imgCloneWebpart.ImageUrl = GetImageUrl("CMSModules/CMS_WebParts/clone.png");

        // Resource strings
        lnkDeleteItem.Text   = GetString("Development-WebPart_Tree.DeleteItem");
        lnkNewCategory.Text  = GetString("Development-WebPart_Tree.NewCategory");
        lnkNewWebPart.Text   = GetString("Development-WebPart_Tree.NewWebPart");
        lnkExportObject.Text = GetString("Development-WebPart_Tree.ExportObject");
        lnkCloneWebPart.Text = GetString("Development-WebPart_Tree.CloneWebpart");

        // Setup menu action scripts
        lnkNewWebPart.Attributes.Add("onclick", "NewItem('webpart');");
        lnkNewCategory.Attributes.Add("onclick", "NewItem('webpartcategory');");
        lnkDeleteItem.Attributes.Add("onclick", "DeleteItem();");
        lnkExportObject.Attributes.Add("onclick", "ExportObject();");
        lnkCloneWebPart.Attributes.Add("onclick", "CloneWebPart();");

        // Tooltips
        lnkDeleteItem.ToolTip   = GetString("Development-WebPart_Tree.DeleteItem");
        lnkNewCategory.ToolTip  = GetString("Development-WebPart_Tree.NewCategory");
        lnkNewWebPart.ToolTip   = GetString("Development-WebPart_Tree.NewWebPart");
        lnkExportObject.ToolTip = GetString("Development-WebPart_Tree.ExportObject");
        lnkCloneWebPart.ToolTip = GetString("Development-WebPart_Tree.CloneWebpart");

        string script = "var doNotReloadContent = false;\n";

        // URLs for menu actions
        script += "var categoryURL = '" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/Category_Frameset.aspx") + "';\n";
        script += "var categoryNewURL = '" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Category.aspx") + "';\n";
        script += "var webpartURL = '" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Edit_Frameset.aspx") + "';\n";
        script += "var newWebpartURL = '" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_New.aspx") + "';\n";
        script += "var cloneURL = '" + URLHelper.ResolveUrl("~/CMSModules/Objects/Dialogs/CloneObjectDialog.aspx?objecttype=cms.webpart") + "';\n";
        script += "var doNotReloadContent = false;\n";

        // Script for deleting widget or category
        string delPostback  = ControlsHelper.GetPostBackEventReference(Page, "##");
        string deleteScript = "function DeleteItem() { \n" +
                              " if ((selectedItemId > 0) && (selectedItemParent > 0) && " +
                              " confirm('" + GetString("general.deleteconfirmation") + "')) {\n " +
                              delPostback.Replace("'##'", "selectedItemType+';'+selectedItemId+';'+selectedItemParent") + ";\n" +
                              "}\n" +
                              "}\n";

        script += deleteScript;


        // Preselect tree item
        if (!RequestHelper.IsPostBack())
        {
            int  categoryId = QueryHelper.GetInteger("categoryid", 0);
            int  webpartId  = QueryHelper.GetInteger("webpartid", 0);
            bool reload     = QueryHelper.GetBoolean("reload", false);

            // Select category
            if (categoryId > 0)
            {
                WebPartCategoryInfo wci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(categoryId);
                if (wci != null)
                {
                    // If not set explicitly stop reloading of right frame
                    if (!reload)
                    {
                        script += "doNotReloadContent = true;";
                    }
                    script += SelectAtferLoad(wci.CategoryPath, categoryId, "webpartcategory", wci.CategoryParentID);
                }
            }
            // Select webpart
            else if (webpartId > 0)
            {
                WebPartInfo wi = WebPartInfoProvider.GetWebPartInfo(webpartId);
                if (wi != null)
                {
                    WebPartCategoryInfo wci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(wi.WebPartCategoryID);
                    if (wci != null)
                    {
                        // If not set explicitly stop reloading of right frame
                        if (!reload)
                        {
                            script += "doNotReloadContent = true;";
                        }
                        string path = wci.CategoryPath + "/" + wi.WebPartName;
                        script += SelectAtferLoad(path, webpartId, "webpart", wi.WebPartCategoryID);
                    }
                }
            }
            // Select root by default
            else
            {
                WebPartCategoryInfo wci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("/");
                if (wci != null)
                {
                    script += SelectAtferLoad("/", wci.CategoryID, "webpartcategory", 0);
                }
            }
        }

        ltlScript.Text += ScriptHelper.GetScript(script);

        // Special browser class for RTL scrollbars correction
        pnlSubBox.CssClass = BrowserHelper.GetBrowserClass();
    }
Пример #6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Initialize
        lblCategoryName.Text        = GetString("General.CategoryName");
        lblCategoryDisplayName.Text = GetString("General.CategoryDisplayName");
        btnOk.Text = GetString("general.ok");
        rfvCategoryName.ErrorMessage        = GetString("General.RequiresCodeName");
        rfvCategoryDisplayName.ErrorMessage = GetString("General.RequiresDisplayName");

        pageTitleTabs[0, 0] = GetString("Development-WebPart_Category.Category");
        pageTitleTabs[0, 1] = URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Frameset.aspx");
        pageTitleTabs[0, 2] = "_parent";

        pageTitleTabs[1, 0] = GetString("Development-WebPart_Category.New");
        pageTitleTabs[1, 1] = "";
        pageTitleTabs[1, 2] = "";

        // Get category id
        categoryId       = QueryHelper.GetInteger("categoryid", 0);
        parentCategoryId = QueryHelper.GetInteger("parentid", 0);

        string categoryName               = "";
        string categoryDisplayName        = "";
        string currentWebPartCategoryName = GetString("objecttype.cms_webpartcategory");
        string categoryImagePath          = "";
        string pageTitleText              = "";
        string pageTitleImage             = "";

        if (categoryId > 0)
        {
            // Existing category

            // Hide breadcrumbs and title
            this.CurrentMaster.Title.TitleText   = "";
            this.CurrentMaster.Title.Breadcrumbs = null;

            WebPartCategoryInfo ci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(categoryId);
            if (ci != null)
            {
                categoryName               = ci.CategoryName;
                categoryDisplayName        = ci.CategoryDisplayName;
                categoryImagePath          = ci.CategoryImagePath;
                parentCategoryId           = ci.CategoryParentID;
                currentWebPartCategoryName = ci.CategoryName;

                // If it's root category hide category name textbox
                if (parentCategoryId == 0)
                {
                    plcCategoryName.Visible = false;
                }

                pageTitleTabs[1, 0] = HTMLHelper.HTMLEncode(ci.CategoryDisplayName);
                pageTitleText       = GetString("Development-WebPart_Category.Title");
                pageTitleImage      = GetImageUrl("Objects/CMS_WebPartCategory/object.png");
            }
        }
        else
        {
            // New category
            this.CurrentMaster.Title.HelpName      = "helpTopic";
            this.CurrentMaster.Title.HelpTopicName = "web_part_category_general";

            // Load parent category name
            WebPartCategoryInfo parentCategoryInfo = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(parentCategoryId);
            string parentCategoryName = GetString("development-webpart_header.webparttitle");
            if (parentCategoryInfo != null)
            {
                parentCategoryName = parentCategoryInfo.CategoryDisplayName;
            }

            // Initializes breadcrumbs
            string[,] tabs = new string[3, 4];

            tabs[0, 0] = GetString("development-webpart_header.webparttitle");
            tabs[0, 1] = URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/Category_Frameset.aspx");
            tabs[0, 2] = "";
            tabs[0, 3] = "if (parent.frames['webparttree']) { parent.frames['webparttree'].location.href = 'WebPart_Tree.aspx'; }";

            tabs[1, 0] = HTMLHelper.HTMLEncode(parentCategoryName);
            tabs[1, 1] = URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/Category_Frameset.aspx?categoryid=" + parentCategoryId);
            tabs[1, 2] = "";

            tabs[2, 0] = GetString("development-webpart_category.titlenew");
            tabs[2, 1] = "";
            tabs[2, 2] = "";

            // Set master page
            this.CurrentMaster.Title.Breadcrumbs = tabs;
            this.CurrentMaster.Title.TitleText   = HTMLHelper.HTMLEncode(currentWebPartCategoryName);
            this.CurrentMaster.Title.TitleImage  = GetImageUrl("Objects/CMS_WebPartCategory/new.png");
        }

        if (!RequestHelper.IsPostBack())
        {
            txtCategoryDisplayName.Text = HTMLHelper.HTMLEncode(categoryDisplayName);
            txtCategoryName.Text        = HTMLHelper.HTMLEncode(categoryName);
            txtCategoryImagePath.Text   = HTMLHelper.HTMLEncode(categoryImagePath);
        }
    }
Пример #7
0
    /// <summary>
    /// Button OK click handler.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Trim text values
        txtWebPartName.Text        = txtWebPartName.Text.Trim();
        txtWebPartDisplayName.Text = txtWebPartDisplayName.Text.Trim();
        txtWebPartFileName.Text    = txtWebPartFileName.Text.Trim();

        // Validate the text box fields
        string errorMessage = new Validator()
                              .NotEmpty(txtWebPartName.Text, rfvWebPartName.ErrorMessage)
                              .NotEmpty(txtWebPartDisplayName.Text, rfvWebPartDisplayName.ErrorMessage)
                              .IsCodeName(txtWebPartName.Text, GetString("WebPart_Clone.InvalidCodeName"))
                              .Result;

        // Validate file name
        if (string.IsNullOrEmpty(errorMessage) && chckCloneWebPartFiles.Checked)
        {
            errorMessage = new Validator()
                           .NotEmpty(txtWebPartFileName.Text, rfvWebPartFileName.ErrorMessage)
                           .IsFileName(Path.GetFileName(txtWebPartFileName.Text.Trim('~')), GetString("WebPart_Clone.InvalidFileName")).Result;
        }

        // Check if webpart with same name exists
        if (WebPartInfoProvider.GetWebPartInfo(txtWebPartName.Text) != null)
        {
            errorMessage = GetString(String.Format("Development-WebPart_Clone.WebPartExists", txtWebPartName.Text));
        }

        // Check if webpart is not cloned to the root category
        WebPartCategoryInfo wci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("/");

        if (wci.CategoryID == ValidationHelper.GetInteger(drpWebPartCategories.SelectedValue, -1))
        {
            errorMessage = GetString("Development-WebPart_Clone.cannotclonetoroot");
        }

        if (errorMessage != "")
        {
            lblError.Text    = errorMessage;
            lblError.Visible = true;
            return;
        }

        // get web part info object
        WebPartInfo wi = WebPartInfoProvider.GetWebPartInfo(webPartId);

        if (wi == null)
        {
            lblError.Text    = GetString("WebPart_Clone.InvalidWebPartID");
            lblError.Visible = true;
            return;
        }

        // Create new webpart with all properties from source webpart
        WebPartInfo nwpi = new WebPartInfo(wi, false);

        nwpi.WebPartID   = 0;
        nwpi.WebPartGUID = Guid.NewGuid();

        // Modify clone info
        nwpi.WebPartName        = txtWebPartName.Text;
        nwpi.WebPartDisplayName = txtWebPartDisplayName.Text;
        nwpi.WebPartCategoryID  = ValidationHelper.GetInteger(drpWebPartCategories.SelectedValue, -1);

        if (nwpi.WebPartParentID <= 0)
        {
            nwpi.WebPartFileName = txtWebPartFileName.Text;
        }

        string path     = String.Empty;
        string filename = String.Empty;
        string inher    = String.Empty;

        try
        {
            // Copy file if needed and webpart is not ihnerited
            if (chckCloneWebPartFiles.Checked && (wi.WebPartParentID == 0))
            {
                // Get source file path
                string srcFile = GetWebPartPhysicalPath(wi.WebPartFileName);

                // Get destination file path
                string dstFile = GetWebPartPhysicalPath(nwpi.WebPartFileName);

                // Ensure directory
                DirectoryHelper.EnsureDiskPath(Path.GetDirectoryName(DirectoryHelper.EnsurePathBackSlash(dstFile)), URLHelper.WebApplicationPhysicalPath);

                // Check if source and target file path are different
                if (File.Exists(dstFile))
                {
                    throw new Exception(GetString("general.fileexists"));
                }

                // Get file name
                filename = Path.GetFileName(dstFile);
                // Get path to the partial class name replace
                string wpPath = nwpi.WebPartFileName;

                if (!wpPath.StartsWith("~/"))
                {
                    wpPath = WebPartInfoProvider.WebPartsDirectory + "/" + wpPath.TrimStart('/');
                }
                path = Path.GetDirectoryName(wpPath);

                inher = path.Replace('\\', '_').Replace('/', '_') + "_" + Path.GetFileNameWithoutExtension(filename).Replace('.', '_');
                inher = inher.Trim('~');
                inher = inher.Trim('_');

                // Read .aspx file, replace classname and save as new file
                string text = File.ReadAllText(srcFile);
                File.WriteAllText(dstFile, ReplaceASCX(text, DirectoryHelper.CombinePath(path, filename), inher));

                // Read .aspx file, replace classname and save as new file
                if (File.Exists(srcFile + ".cs"))
                {
                    text = File.ReadAllText(srcFile + ".cs");
                    File.WriteAllText(dstFile + ".cs", ReplaceASCXCS(text, inher));
                }

                if (File.Exists(srcFile + ".vb"))
                {
                    text = File.ReadAllText(srcFile + ".vb");
                    File.WriteAllText(dstFile + ".vb", ReplaceASCXVB(text, inher));
                }

                // Copy web part subfolder
                string srcDirectory = srcFile.Remove(srcFile.Length - Path.GetFileName(srcFile).Length) + Path.GetFileNameWithoutExtension(srcFile) + "_files";
                if (Directory.Exists(srcDirectory))
                {
                    string dstDirectory = dstFile.Remove(dstFile.Length - Path.GetFileName(dstFile).Length) + Path.GetFileNameWithoutExtension(dstFile) + "_files";
                    if (srcDirectory.ToLower() != dstDirectory.ToLower())
                    {
                        DirectoryHelper.EnsureDiskPath(srcDirectory, URLHelper.WebApplicationPhysicalPath);
                        DirectoryHelper.CopyDirectory(srcDirectory, dstDirectory);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            lblError.Text    = ex.Message;
            lblError.Visible = true;
            return;
        }

        // Add new web part to database
        WebPartInfoProvider.SetWebPartInfo(nwpi);

        try
        {
            // Get and duplicate all webpart layouts associated to webpart
            DataSet ds = WebPartLayoutInfoProvider.GetWebPartLayouts(webPartId);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    WebPartLayoutInfo wpli = new WebPartLayoutInfo(dr);
                    wpli.WebPartLayoutID                    = 0;              // Create new record
                    wpli.WebPartLayoutWebPartID             = nwpi.WebPartID; // Associate layout to new webpart
                    wpli.WebPartLayoutGUID                  = Guid.NewGuid();
                    wpli.WebPartLayoutCheckedOutByUserID    = 0;
                    wpli.WebPartLayoutCheckedOutFilename    = "";
                    wpli.WebPartLayoutCheckedOutMachineName = "";

                    // Replace classname and inherits attribut
                    wpli.WebPartLayoutCode = ReplaceASCX(wpli.WebPartLayoutCode, DirectoryHelper.CombinePath(path, filename), inher);
                    WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli);
                }
            }

            // Duplicate associated thumbnail
            MetaFileInfoProvider.CopyMetaFiles(webPartId, nwpi.WebPartID, PortalObjectType.WEBPART, MetaFileInfoProvider.OBJECT_CATEGORY_THUMBNAIL, null);
        }
        catch (Exception ex)
        {
            lblError.Text    = ex.Message;
            lblError.Visible = true;
            return;
        }

        // Close clone window
        // Refresh web part tree and select/edit new widget
        string script      = String.Empty;
        string refreshLink = URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Tree.aspx?webpartid=" + nwpi.WebPartID + "&reload=true");

        if (QueryHelper.Contains("reloadAll"))
        {
            script += "wopener.parent.parent.frames['webparttree'].location.href ='" + refreshLink + "';";
        }
        else
        {
            script = "wopener.location = '" + refreshLink + "';";
        }
        script += "window.close();";

        ltlScript.Text = ScriptHelper.GetScript(script);
    }
Пример #8
0
    /// <summary>
    /// Creates new or updates category name.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string displayName = txtCategoryDisplayName.Text;
        string codeName    = txtCategoryName.Text;
        string imagePath   = txtCategoryImagePath.Text;

        string result = new Validator().NotEmpty(displayName, GetString("General.RequiresDisplayName")).NotEmpty(codeName, GetString("General.RequiresCodeName")).Result;

        // If it's root category don't validate codename
        if (parentCategoryId != 0)
        {
            // Validate the codename
            if (!ValidationHelper.IsCodeName(codeName))
            {
                result = GetString("General.ErrorCodeNameInIdentificatorFormat");
            }
        }

        // Check codename uniqness
        if ((categoryId == 0) && (WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName(codeName) != null))
        {
            result = GetString("General.CodeNameExists");
        }

        if (result == "")
        {
            WebPartCategoryInfo ci;

            lblInfo.Visible = true;
            if (categoryId > 0)
            {
                ci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(categoryId);
                ci.CategoryDisplayName = displayName;
                ci.CategoryName        = codeName;
                ci.CategoryImagePath   = imagePath;

                try
                {
                    WebPartCategoryInfoProvider.SetWebPartCategoryInfo(ci);
                    string script = "parent.parent.frames['webparttree'].location.href = '" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Tree.aspx?categoryid=" + categoryId) + "';";
                    script         += "parent.frames['categoryHeader'].location.href = '" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/Category_Header.aspx?categoryid=" + categoryId + "&saved=1") + "';";
                    ltlScript.Text += ScriptHelper.GetScript(script);
                }
                catch (Exception ex)
                {
                    lblInfo.Visible  = false;
                    lblError.Visible = true;
                    lblError.Text    = ex.Message.Replace("%%name%%", displayName);
                }
            }
            else
            {
                ci = new WebPartCategoryInfo();
                ci.CategoryDisplayName = displayName;
                ci.CategoryName        = codeName;
                ci.CategoryParentID    = parentCategoryId;
                ci.CategoryImagePath   = imagePath;

                try
                {
                    WebPartCategoryInfoProvider.SetWebPartCategoryInfo(ci);
                    string script = "parent.frames['webparttree'].location.href = '" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Tree.aspx?categoryid=" + ci.CategoryID) + "';";
                    script         += "this.location.href = '" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/Category_Frameset.aspx?categoryid=" + ci.CategoryID) + "';";
                    ltlScript.Text += ScriptHelper.GetScript(script);
                }
                catch (Exception ex)
                {
                    lblInfo.Visible  = false;
                    lblError.Visible = true;
                    lblError.Text    = ex.Message.Replace("%%name%%", displayName);
                }
            }

            lblInfo.Text        = GetString("General.ChangesSaved");
            pageTitleTabs[1, 0] = HTMLHelper.HTMLEncode(ci.CategoryDisplayName);
        }
        else
        {
            lblInfo.Visible  = false;
            lblError.Visible = true;
            lblError.Text    = HTMLHelper.HTMLEncode(result);
        }
    }
Пример #9
0
    /// <summary>
    /// Reloads the web part list.
    /// </summary>
    /// <param name="forceLoad">if set to <c>true</c>, reload the control even if the control has been already loaded</param>
    protected void LoadWebParts(bool forceLoad)
    {
        if (!dataLoaded || forceLoad)
        {
            /* The order is category driven => first level category display name is used for all nodes incl. sub-nodes */
            string categoryOrder = @"
(SELECT CMS_WebPartCategory.CategoryDisplayName FROM CMS_WebPartCategory 
WHERE CMS_WebPartCategory.CategoryPath = (CASE WHEN (CHARINDEX('/', ObjectPath, 0) > 0) AND (CHARINDEX('/', ObjectPath, CHARINDEX('/', ObjectPath, 0) + 1) = 0) 
THEN ObjectPath 
ELSE SUBSTRING(ObjectPath, 0, LEN(ObjectPath) - (LEN(ObjectPath) - CHARINDEX('/', ObjectPath, CHARINDEX('/', ObjectPath, 0) + 1)))
END))
";
            // Set query repeater
            repItems.SelectedColumns = " ObjectID, DisplayName, ObjectType, ParentID, ThumbnailGUID, IconClass, ObjectLevel, WebPartDescription, WebPartSkipInsertProperties";
            repItems.OrderBy         = categoryOrder + ", ObjectType  DESC, DisplayName";

            // Setup the where condition
            if (SelectedCategory == CATEGORY_RECENTLY_USED)
            {
                // Recently used category
                RenderRecentlyUsedWebParts(true);
            }
            else
            {
                // Specific web part category
                int selectedCategoryId = ValidationHelper.GetInteger(SelectedCategory, 0);
                if (selectedCategoryId > 0)
                {
                    WebPartCategoryInfo categoryInfo = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(selectedCategoryId);
                    if (categoryInfo != null)
                    {
                        string firstLevelCategoryPath = String.Empty;

                        // Select also all subcategories (using "/%")
                        string categoryPath = categoryInfo.CategoryPath;
                        if (!categoryPath.EndsWith("/"))
                        {
                            categoryPath += "/";
                        }

                        // Do not limit items if not root category is selected
                        if (!categoryInfo.CategoryPath.EqualsCSafe("/"))
                        {
                            limitItems = false;
                        }

                        // Get all web parts for the selected category and its subcategories
                        if (categoryPath.EqualsCSafe("/"))
                        {
                            repItems.WhereCondition = SqlHelper.AddWhereCondition(repItems.WhereCondition, "(ObjectType=N'webpart' OR ObjectLevel=1) AND (ParentID = " + selectedCategoryId + " OR ParentID IN (SELECT CategoryID FROM CMS_WebPartCategory WHERE CategoryPath LIKE N'" + categoryPath.Replace("'", "''") + "%'))");

                            // Set caching for query repeater
                            repItems.ForceCacheMinutes = true;
                            repItems.CacheMinutes      = 24 * 60;
                            repItems.CacheDependencies = "cms.webpart|all\ncms.webpartcategory|all";

                            // Show Recently used category
                            RenderRecentlyUsedWebParts(false);
                        }
                        else
                        {
                            // Prepare where condition -- the part that restricts web parts
                            string where = "(ObjectType=N'webpart' AND (ParentID = " + selectedCategoryId + " OR ParentID IN (SELECT CategoryID FROM CMS_WebPartCategory WHERE CategoryPath LIKE N'" + categoryPath.Replace("'", "''") + "%')))";

                            // Get first level category path
                            firstLevelCategoryPath = categoryPath.Substring(0, categoryPath.IndexOf('/', 2));

                            // Distinguish special categories
                            if (categoryPath.StartsWithCSafe(CATEGORY_WIREFRAMES, true) || categoryPath.StartsWithCSafe(CATEGORY_UIWEBPARTS, true))
                            {
                                if (!categoryPath.EqualsCSafe(firstLevelCategoryPath + "/", true))
                                {
                                    // Currently selected category is one of subcategories
                                    string specialCategoryPath = firstLevelCategoryPath;
                                    firstLevelCategoryPath = categoryPath.Substring(CATEGORY_WIREFRAMES.Length + 1).TrimEnd('/');
                                    where += " OR (ObjectType = N'webpartcategory' AND ObjectLevel = 1 AND ObjectPath = N'" + specialCategoryPath + "/" + firstLevelCategoryPath + "')";
                                }
                                else
                                {
                                    // Currently selected category is root category
                                    where += " OR (ObjectType = N'webpartcategory' AND ObjectLevel = 1 AND ObjectPath LIKE N'" + firstLevelCategoryPath + "%')";
                                }
                            }
                            else
                            {
                                // All web part category
                                where += " OR (ObjectType = N'webpartcategory' AND ObjectLevel = 1 AND ObjectPath = N'" + firstLevelCategoryPath + "')";
                            }

                            repItems.WhereCondition = SqlHelper.AddWhereCondition(repItems.WhereCondition, where);

                            // Set caching for query repeater
                            repItems.CacheMinutes      = 0;
                            repItems.ForceCacheMinutes = true;
                        }
                    }
                }

                // Do not display "Widget only" web parts in the toolbar
                repItems.WhereCondition = SqlHelper.AddWhereCondition(repItems.WhereCondition, " ((WebPartType IS NULL) OR (WebPartType <> " + (int)WebPartTypeEnum.WidgetOnly + "))");

                // Limit items if required
                if (limitItems)
                {
                    repItems.SelectTopN = DEFAULT_WEBPART_COUNT;
                }

                repItems.ReloadData(false);
                repItems.DataBind();
            }

            dataLoaded = true;
        }
    }
Пример #10
0
 /// <inheritdoc />
 public IWebPartCategory GetWebPartCategory(int id) =>
 (WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(id) as WebPartCategoryInfo)?.ActLike <IWebPartCategory>();
Пример #11
0
 /// <inheritdoc />
 public void Delete(IWebPartCategory webPartCategory) =>
 WebPartCategoryInfoProvider.DeleteCategoryInfo(webPartCategory.CategoryID);
Пример #12
0
    protected void Page_Load(object sender, EventArgs e)
    {
        lbWebPartCategory.Text             = GetString("Development-WebPart_Edit.WebPartCategory");
        lblWebPartType.Text                = GetString("Development-WebPart_Edit.WebPartType");
        lblUploadFile.Text                 = GetString("Development-WebPart_Edit.lblUpload");
        btnOk.Text                         = GetString("general.ok");
        rfvWebPartDisplayName.ErrorMessage = GetString("Development-WebPart_Edit.ErrorDisplayName");
        rfvWebPartName.ErrorMessage        = GetString("Development-WebPart_Edit.ErrorWebPartName");

        this.lblLoadGeneration.Text = GetString("LoadGeneration.Title");
        this.plcDevelopment.Visible = SettingsKeyProvider.DevelopmentMode;

        // Get the webpart ID
        webPartId = QueryHelper.GetInteger("webpartID", 0);
        WebPartInfo wi = null;

        // fill in the form, edit webpart
        if (!RequestHelper.IsPostBack())
        {
            // Fill webpart type drop down list
            DataHelper.FillListControlWithEnum(typeof(WebPartTypeEnum), drpWebPartType, "Development-WebPart_Edit.Type", null);

            // edit web part
            if (webPartId > 0)
            {
                wi = WebPartInfoProvider.GetWebPartInfo(webPartId);
                if (wi != null)
                {
                    txtWebPartDescription.Text   = wi.WebPartDescription;
                    txtWebPartDisplayName.Text   = wi.WebPartDisplayName;
                    FileSystemSelector.Value     = wi.WebPartFileName;
                    txtWebPartName.Text          = wi.WebPartName;
                    drpWebPartType.SelectedValue = wi.WebPartType.ToString();

                    drpGeneration.Value = wi.WebPartLoadGeneration;
                    drpModule.Value     = wi.WebPartResourceID;

                    if (wi.WebPartParentID != 0)
                    {
                        WebPartInfo parentInfo = WebPartInfoProvider.GetWebPartInfo(wi.WebPartParentID);

                        if (parentInfo != null)
                        {
                            txtInheritedName.Text = parentInfo.WebPartDisplayName;
                        }

                        plcFileSystemSelector.Visible     = false;
                        plcInheritedName.Visible          = true;
                        lblWebPartFileName.ResourceString = "DevelopmentWebPartGeneral.InheritedWebPart";
                    }


                    WebPartCategoryInfo ci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(wi.WebPartCategoryID);
                    if (ci != null)
                    {
                        categorySelector.Value = ci.CategoryID.ToString();
                    }

                    // Init file uploader
                    lblUploadFile.Visible     = true;
                    attachmentFile.Visible    = true;
                    attachmentFile.ObjectID   = webPartId;
                    attachmentFile.ObjectType = PortalObjectType.WEBPART;
                    attachmentFile.Category   = MetaFileInfoProvider.OBJECT_CATEGORY_THUMBNAIL;
                }
            }
            else
            {
                int parentCategoryId = QueryHelper.GetInteger("parentId", 0);
                categorySelector.Value = parentCategoryId.ToString();

                lblUploadFile.Visible  = false;
                attachmentFile.Visible = false;
            }
        }

        // Initialize the master page elements
        this.Title = "Web parts - Edit";

        FileSystemDialogConfiguration config = new FileSystemDialogConfiguration();

        config.DefaultPath                    = "CMSWebParts";
        config.AllowedExtensions              = "ascx";
        config.ShowFolders                    = false;
        FileSystemSelector.DialogConfig       = config;
        FileSystemSelector.AllowEmptyValue    = false;
        FileSystemSelector.SelectedPathPrefix = "~/CMSWebParts/";
    }