/// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        categoryId = QueryHelper.GetInteger("categoryid", 0);

        // Used for delete calls
        int webpartId = QueryHelper.GetInteger("webpartid", 0);

        string script = @"function RefreshAdditionalContent() {
                            if (parent.parent.frames['webparttree'])
                            {
                                parent.parent.frames['webparttree'].location.href = '" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Tree.aspx?categoryid=" + categoryId) + @"';
                            }
                        }";

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "RefreshTree", ScriptHelper.GetScript(script));

        // Configure the UniGrid
        WebPartCategoryInfo categoryInfo = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(categoryId);

        if (categoryInfo != null)
        {
            string categoryPath = categoryInfo.CategoryPath;
            // Add the slash character at the end of the categoryPath
            if (!categoryPath.EndsWith("/"))
            {
                categoryPath += "/";
            }
            webpartGrid.WhereCondition = "ObjectPath LIKE '" + SqlHelperClass.GetSafeQueryString(categoryPath, false) + "%' AND ObjectType = 'webpart'";
        }
        webpartGrid.OnAction    += webpartGrid_OnAction;
        webpartGrid.ZeroRowsText = GetString("general.nodatafound");

        InitializeMasterPage();
    }
Exemple #2
0
    /// <summary>
    /// Gets and bulk updates web part categories. Called when the "Get and bulk update categories" button is pressed.
    /// Expects the CreateWebPartCategory method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateWebPartCategories()
    {
        // Prepare the parameters
        string where = "CategoryDisplayName LIKE N'My new category%'";

        // Get the data
        DataSet categories = WebPartCategoryInfoProvider.GetCategories(where, null);

        if (!DataHelper.DataSourceIsEmpty(categories))
        {
            // Loop through the individual items
            foreach (DataRow categoryDr in categories.Tables[0].Rows)
            {
                // Create object from DataRow
                WebPartCategoryInfo modifyCategory = new WebPartCategoryInfo(categoryDr);

                // Update the properties
                modifyCategory.CategoryDisplayName = modifyCategory.CategoryDisplayName.ToUpper();

                // Save the changes
                WebPartCategoryInfoProvider.SetWebPartCategoryInfo(modifyCategory);
            }

            return(true);
        }

        return(false);
    }
Exemple #3
0
    /// <summary>
    /// Creates web part. Called when the "Create part" button is pressed.
    /// </summary>
    private bool CreateWebPart()
    {
        // Get parent category for web part
        WebPartCategoryInfo category = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("MyNewCategory");

        if (category != null)
        {
            // Create new web part object
            WebPartInfo newWebpart = new WebPartInfo();

            // Set the properties
            newWebpart.WebPartDisplayName = "My new web part";
            newWebpart.WebPartName        = "MyNewWebpart";
            newWebpart.WebPartDescription = "This is my new web part.";
            newWebpart.WebPartFileName    = "whatever";
            newWebpart.WebPartProperties  = "<form></form>";
            newWebpart.WebPartCategoryID  = category.CategoryID;

            // Save the web part
            WebPartInfoProvider.SetWebPartInfo(newWebpart);

            return(true);
        }
        return(false);
    }
Exemple #4
0
    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (QueryHelper.Contains("categoryid"))
        {
            categoryId = QueryHelper.GetInteger("categoryid", 0);
            WebPartCategoryInfo categoryInfo = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(categoryId);
            if (categoryInfo != null)
            {
                currentWebPartCategory = HTMLHelper.HTMLEncode(categoryInfo.CategoryDisplayName);
            }
            else
            {
                // Set root category
                WebPartCategoryInfo rootCategory = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("/");
                if (rootCategory != null)
                {
                    currentWebPartCategory = rootCategory.CategoryDisplayName;
                }
            }
        }

        if (QueryHelper.Contains("saved"))
        {
            this.CurrentMaster.Tabs.SelectedTab = 1;
        }

        if (!RequestHelper.IsPostBack())
        {
            InitalizeMenu();
        }

        this.InitializeMasterPage();
    }
Exemple #5
0
    /// <summary>
    /// Selects root category in tree, clears search condition and resets pager to first page.
    /// </summary>
    public void ResetToDefault()
    {
        string rootCategory = ShowUIWebparts ? "UIWebparts" : "/";

        // Get root webpart category
        WebPartCategoryInfo wci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName(rootCategory);

        if (wci != null)
        {
            flatElem.SelectedCategory = wci;

            string selItem = wci.CategoryID.ToString();

            // Expand root node
            if (ShowUIWebparts)
            {
                treeUI.SelectedItem = selItem;
                treeUI.SelectPath   = "/";

                // Select tree elem also for proper first time flat elem load (see prerender)
                treeElem.SelectedItem = selItem;
            }
            else
            {
                treeElem.SelectedItem = selItem;
                treeElem.SelectPath   = "/";
            }

            flatElem.TreeSelectedItem = selItem;
        }

        // Clear search condition and resets pager to first page
        flatElem.UniFlatSelector.ResetToDefault();
    }
    /// <summary>
    /// Selects root category in tree, clears search condition and resets pager to first page.
    /// </summary>
    public void ResetToDefault()
    {
        string rootCategory = (ShowWireframeOnlyWebparts ? "Wireframes" : "/");

        // Get root webpart category
        WebPartCategoryInfo wci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName(rootCategory);

        if (wci != null)
        {
            flatElem.SelectedCategory = wci;

            string selItem = wci.CategoryID.ToString();

            // Expand root node
            if (ShowWireframeOnlyWebparts)
            {
                treeWireframes.SelectedItem = selItem;
                treeWireframes.SelectPath   = "/";
            }
            else
            {
                treeElem.SelectedItem = selItem;
                treeElem.SelectPath   = "/";
            }

            flatElem.TreeSelectedItem = selItem;
        }

        // Clear search condition and resets pager to first page
        flatElem.UniFlatSelector.ResetToDefault();
    }
Exemple #7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Setup page title text and image
        this.CurrentMaster.Title.TitleText  = GetString("Development-WebPart_Edit.TitleNew");
        this.CurrentMaster.Title.TitleImage = GetImageUrl("Objects/CMS_WebPart/new.png");

        this.CurrentMaster.Title.HelpTopicName = "new_web_part";
        this.CurrentMaster.Title.HelpName      = "helpTopic";

        // Initialize
        btnOk.Text = GetString("general.ok");
        rfvWebPartDisplayName.ErrorMessage = GetString("Development-WebPart_Edit.ErrorDisplayName");
        rfvWebPartName.ErrorMessage        = GetString("Development-WebPart_Edit.ErrorWebPartName");

        webpartSelector.ShowInheritedWebparts = false;

        radNewWebPart.Text  = GetString("developmentwebparteditnewwepart");
        radInherited.Text   = GetString("Development-WebPart_Edit.Inherited");
        lblWebpartList.Text = GetString("DevelopmentWebPartEdit.InheritedWebPart");

        // Set breadcrumbs
        int i = 0;

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

        int parentid = QueryHelper.GetInteger("parentid", 0);
        WebPartCategoryInfo categoryInfo = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(parentid);

        // Check if the parent category is a root category, if not => display both (root + parent)
        if ((categoryInfo != null) && (categoryInfo.CategoryParentID != 0))
        {
            // Add a cetegory tab
            pageTitleTabs[i, 0] = HTMLHelper.HTMLEncode(categoryInfo.CategoryDisplayName);
            pageTitleTabs[i, 1] = URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/Category_Frameset.aspx") + "?categoryid=" + categoryInfo.CategoryID;
            pageTitleTabs[i, 2] = "";
            i++;
        }

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

        this.CurrentMaster.Title.Breadcrumbs = pageTitleTabs;

        FileSystemDialogConfiguration config = new FileSystemDialogConfiguration();

        config.DefaultPath                    = "CMSWebParts";
        config.AllowedExtensions              = "ascx";
        config.ShowFolders                    = false;
        FileSystemSelector.DialogConfig       = config;
        FileSystemSelector.AllowEmptyValue    = false;
        FileSystemSelector.SelectedPathPrefix = "~/CMSWebParts/";
    }
Exemple #8
0
    /// <summary>
    /// Deletes web part category. Called when the "Delete category" button is pressed.
    /// Expects the CreateWebPartCategory method to be run first.
    /// </summary>
    private bool DeleteWebPartCategory()
    {
        // Get the web part category
        WebPartCategoryInfo deleteCategory = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("MyNewCategory");

        // Delete the web part category
        WebPartCategoryInfoProvider.DeleteCategoryInfo(deleteCategory);

        return(deleteCategory != null);
    }
Exemple #9
0
        /// <inheritdoc />
        public IWebPartCategory Create(IWebPartCategory webPartCategory)
        {
            var category = new WebPartCategoryInfo
            {
                CategoryDisplayName = webPartCategory.CategoryDisplayName,
                CategoryName        = webPartCategory.CategoryName,
                CategoryImagePath   = webPartCategory.CategoryImagePath,
                CategoryParentID    = webPartCategory.CategoryParentID,
            };

            WebPartCategoryInfoProvider.SetWebPartCategoryInfo(category);

            return(category.ActLike <IWebPartCategory>());
        }
    /// <summary>
    /// Selects root category in tree, clears search condition and resets pager to first page.
    /// </summary>
    public void ResetToDefault()
    {
        // Get root webpart category
        WebPartCategoryInfo wci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("/");

        if (wci != null)
        {
            flatElem.SelectedCategory = wci;

            // Expand root node
            treeElem.SelectedItem = wci.CategoryID.ToString();
            treeElem.SelectPath   = "/";
        }

        // Clear search condition and resets pager to first page
        flatElem.UniFlatSelector.ResetToDefault();
    }
Exemple #11
0
    /// <summary>
    /// Gets and updates web part category. Called when the "Get and update category" button is pressed.
    /// Expects the CreateWebPartCategory method to be run first.
    /// </summary>
    private bool GetAndUpdateWebPartCategory()
    {
        // Get the web part category
        WebPartCategoryInfo updateCategory = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("MyNewCategory");

        if (updateCategory != null)
        {
            // Update the properties
            updateCategory.CategoryDisplayName = updateCategory.CategoryDisplayName.ToLower();

            // Save the changes
            WebPartCategoryInfoProvider.SetWebPartCategoryInfo(updateCategory);

            return(true);
        }

        return(false);
    }
Exemple #12
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;

            switch (values[0])
            {
            case "webpart":
                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;
            }

            // Select parent node after delete
            WebPartCategoryInfo wci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(parentId);
            if (wci != null)
            {
                script          = SelectAtferLoad(wci.CategoryPath + "/", parentId, "webpartcategory", wci.CategoryParentID) + script;
                ltlScript.Text += ScriptHelper.GetScript(script);
            }

            treeElem.ReloadData();
        }
    }
Exemple #13
0
    /// <summary>
    /// Initialize master page.
    /// </summary>
    private void InitializeMasterPage()
    {
        this.Title = "WebParts - List";

        // Set the master page title
        this.CurrentMaster.Title.TitleImage    = GetImageUrl("Objects/CMS_Webpart/object.png");
        this.CurrentMaster.Title.HelpTopicName = "webpart_general";
        this.CurrentMaster.Title.HelpName      = "helpTopic";

        // Initializes page title
        string[,] breadcrumbs = new string[3, 4];
        breadcrumbs[0, 0]     = GetString("Development-WebPart_Edit.WebParts");
        breadcrumbs[0, 1]     = URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/Category_Frameset.aspx");
        breadcrumbs[0, 2]     = "_parent";
        breadcrumbs[0, 3]     = "if (parent.parent.frames['webparttree']) { parent.parent.frames['webparttree'].location.href = '" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Tree.aspx") + "'; }";


        if (wpi != null)
        {
            if (isInherited)
            {
                this.CurrentMaster.Title.HelpTopicName = "webpart_general_inherited";
            }

            WebPartCategoryInfo categoryInfo = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(wpi.WebPartCategoryID);

            if (categoryInfo != null)
            {
                breadcrumbs[1, 0] = HTMLHelper.HTMLEncode(categoryInfo.CategoryDisplayName);
                breadcrumbs[1, 1] = URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/Category_Frameset.aspx?categoryid=" + wpi.WebPartCategoryID);
                breadcrumbs[1, 2] = "_parent";
                breadcrumbs[1, 3] = "if (parent.parent.frames['webparttree']) { parent.parent.frames['webparttree'].location.href = '" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Tree.aspx?categoryid=" + wpi.WebPartCategoryID) + "'; }";


                breadcrumbs[2, 0] = HTMLHelper.HTMLEncode(wpi.WebPartDisplayName);
                breadcrumbs[2, 1] = "";
                breadcrumbs[2, 2] = "";
            }
        }

        this.CurrentMaster.Title.Breadcrumbs = breadcrumbs;
    }
Exemple #14
0
    /// <summary>
    /// Creates web part category. Called when the "Create category" button is pressed.
    /// </summary>
    private bool CreateWebPartCategory()
    {
        WebPartCategoryInfo root = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("/");

        if (root != null)
        {
            // Create new web part category object
            WebPartCategoryInfo newCategory = new WebPartCategoryInfo();

            // Set the properties
            newCategory.CategoryDisplayName = "My new category";
            newCategory.CategoryName        = "MyNewCategory";
            newCategory.CategoryParentID    = root.CategoryID;

            // Save the web part category
            WebPartCategoryInfoProvider.SetWebPartCategoryInfo(newCategory);

            return(true);
        }

        return(false);
    }
Exemple #15
0
    /// <summary>
    /// Used for maxnodes in collapsed node.
    /// </summary>
    /// <param name="itemData">The data row to check</param>
    /// <param name="defaultNode">The defaul node</param>
    protected TreeNode treeElem_OnNodeCreated(DataRow itemData, TreeNode defaultNode)
    {
        if (UseMaxNodeLimit)
        {
            // Get parentID from data row
            int    parentID   = ValidationHelper.GetInteger(itemData["ParentID"], 0);
            string objectType = ValidationHelper.GetString(itemData["ObjectType"], String.Empty);

            // Don't use maxnodes limitation for categories
            if (objectType.ToLower() == "webpartcategory")
            {
                return(defaultNode);
            }

            // Increment index count in collapsing
            indexMaxTreeNodes++;
            if (indexMaxTreeNodes == MaxTreeNodes)
            {
                // Load parentid
                int parentParentID = 0;

                WebPartCategoryInfo category = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(parentID);
                if (category != null)
                {
                    parentParentID = category.CategoryParentID;
                }

                System.Web.UI.WebControls.TreeNode node = new System.Web.UI.WebControls.TreeNode();
                node.Text = "<span class=\"ContentTreeItem\" onclick=\"SelectNode(" + parentID + " ,'webpartcategory'," + parentParentID + ",true ); return false;\"><span class=\"Name\" style=\"font-style: italic;\">" + GetString("general.seelisting") + "</span></span>";
                return(node);
            }
            if (indexMaxTreeNodes > MaxTreeNodes)
            {
                return(null);
            }
        }
        return(defaultNode);
    }
Exemple #16
0
    /// <summary>
    /// Initializes master page.
    /// </summary>
    protected void InitializeMasterPage()
    {
        this.CurrentMaster.Title.HelpName      = "helpTopic";
        this.CurrentMaster.Title.HelpTopicName = "webpart_list";

        // initializes page title control
        string[,] tabs = new string[2, 4];

        WebPartCategoryInfo rootCategory = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("/");

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

        tabs[1, 0] = HTMLHelper.HTMLEncode(currentWebPartCategory);
        tabs[1, 1] = "";
        tabs[1, 2] = "";

        this.CurrentMaster.Title.Breadcrumbs = tabs;
        this.CurrentMaster.Title.TitleText   = "";
        this.CurrentMaster.Title.TitleImage  = GetImageUrl("Objects/CMS_WebPart/object.png");
    }
    /// <summary>
    /// Traverses over parent categories and returns all as string.
    /// </summary>
    /// <param name="dr">Data row containing the web part data</param>
    private string GetParentCategories(DataRow dr)
    {
        StringBuilder parents = new StringBuilder();

        // Get web part parent ID
        int parentId = ValidationHelper.GetInteger(dr["ParentID"], 0);

        // Traverse over categories
        while (parentId > 0)
        {
            WebPartCategoryInfo wpci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(parentId);
            if ((wpci != null) && !wpci.CategoryPath.EqualsCSafe("/"))
            {
                parents.Insert(0, wpci.CategoryDisplayName + " ");
                parentId = wpci.CategoryParentID;
            }
            else
            {
                break;
            }
        }

        return(parents.ToString());
    }
    /// <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;
        }
    }
    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");

        lblLoadGeneration.Text = GetString("LoadGeneration.Title");
        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);
                EditedObject = wi;
                if (wi != null)
                {
                    txtWebPartDescription.Text      = wi.WebPartDescription;
                    txtWebPartDisplayName.Text      = wi.WebPartDisplayName;
                    FileSystemSelector.Value        = wi.WebPartFileName;
                    txtWebPartName.Text             = wi.WebPartName;
                    drpWebPartType.SelectedValue    = wi.WebPartType.ToString();
                    chkSkipInsertProperties.Checked = wi.WebPartSkipInsertProperties;

                    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
        Title = "Web parts - Edit";

        FileSystemDialogConfiguration config = new FileSystemDialogConfiguration();

        config.StartingPath      = "~/CMSWebParts/";
        config.DefaultPath       = "CMSWebParts";
        config.AllowedExtensions = "ascx";
        config.ShowFolders       = false;

        FileSystemSelector.DialogConfig       = config;
        FileSystemSelector.AllowEmptyValue    = false;
        FileSystemSelector.SelectedPathPrefix = "~/CMSWebParts/";
    }
Exemple #20
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Register scripts
        ScriptHelper.RegisterJQuery(this.Page);
        this.RegisterExportScript();

        treeElem.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/PortalEngine/UI/WebParts/Development/WebPart_Clone.aspx") + "';\n";
        script += "var doNotReloadContent = false;\n";

        // Script for deleting widget or category
        string delPostback  = ControlsHelper.GetPostBackEventReference(this.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();
    }
    /// <summary>
    /// Gets and bulk updates web part categories. Called when the "Get and bulk update categories" button is pressed.
    /// Expects the CreateWebPartCategory method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateWebPartCategories()
    {
        // Prepare the parameters
        string where = "CategoryDisplayName LIKE N'My new category%'";

        // Get the data
        DataSet categories = WebPartCategoryInfoProvider.GetCategories().Where(where);
        if (!DataHelper.DataSourceIsEmpty(categories))
        {
            // Loop through the individual items
            foreach (DataRow categoryDr in categories.Tables[0].Rows)
            {
                // Create object from DataRow
                WebPartCategoryInfo modifyCategory = new WebPartCategoryInfo(categoryDr);

                // Update the properties
                modifyCategory.CategoryDisplayName = modifyCategory.CategoryDisplayName.ToUpper();

                // Save the changes
                WebPartCategoryInfoProvider.SetWebPartCategoryInfo(modifyCategory);
            }

            return true;
        }

        return false;
    }
    /// <summary>
    /// Creates web part category. Called when the "Create category" button is pressed.
    /// </summary>
    private bool CreateWebPartCategory()
    {
        WebPartCategoryInfo root = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("/");

        if (root != null)
        {
            // Create new web part category object
            WebPartCategoryInfo newCategory = new WebPartCategoryInfo();

            // Set the properties
            newCategory.CategoryDisplayName = "My new category";
            newCategory.CategoryName = "MyNewCategory";
            newCategory.CategoryParentID = root.CategoryID;

            // Save the web part category
            WebPartCategoryInfoProvider.SetWebPartCategoryInfo(newCategory);

            return true;
        }

        return false;
    }
Exemple #23
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);
    }
Exemple #24
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();
        }
    }
    /// <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;
        }
    }
    /// <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.ErrorCodeNameInIdentifierFormat");
            }
        }

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

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

            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)
                {
                    ShowError(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)
                {
                    ShowError(ex.Message.Replace("%%name%%", displayName));
                }
            }

            ShowChangesSaved();
            pageTitleTabs[1, 0] = HTMLHelper.HTMLEncode(ci.CategoryDisplayName);
        }
        else
        {
            ShowError(HTMLHelper.HTMLEncode(result));
        }
    }
    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
            CurrentMaster.Title.TitleText   = "";
            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
            CurrentMaster.Title.HelpName      = "helpTopic";
            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
            CurrentMaster.Title.Breadcrumbs = tabs;
            CurrentMaster.Title.TitleText   = HTMLHelper.HTMLEncode(currentWebPartCategoryName);
            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);
        }
    }
    /// <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);
        }
    }
Exemple #29
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)
        {
            // Get only required columns
            repItems.Columns = WEBPART_COLUMNS;

            // Setup the where condition
            if (SelectedCategory == CATEGORY_RECENTLY_USED)
            {
                // Recently used category
                string where = null;

                // Root category path
                string rootPath = categorySelector.RootPath;
                if (!String.IsNullOrEmpty(rootPath))
                {
                    where = "WebPartCategoryID IN (SELECT CategoryID FROM CMS_WebPartCategory WHERE CategoryPath LIKE N'" + rootPath.Replace("'", "''") + "%')";
                }

                repItems.WhereCondition = SqlHelperClass.AddWhereCondition(where, SqlHelperClass.GetWhereCondition("WebPartName", currentUser.UserSettings.UserUsedWebParts.Split(';')));
                repItems.OrderBy        = "WebPartLastSelection DESC";
            }
            else
            {
                // Specific web part category
                int selectedCategoryId = ValidationHelper.GetInteger(SelectedCategory, 0);
                if (selectedCategoryId > 0)
                {
                    WebPartCategoryInfo categoryInfo = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(selectedCategoryId);
                    if (categoryInfo != null)
                    {
                        // 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
                        repItems.WhereCondition = SqlHelperClass.AddWhereCondition(repItems.WhereCondition, "WebPartCategoryID = " + selectedCategoryId + " OR WebPartCategoryID IN (SELECT CategoryID FROM CMS_WebPartCategory WHERE CategoryPath LIKE N'" + categoryPath.Replace("'", "''") + "%')");
                    }
                }
            }

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

            // Limit items if required
            if (limitItems)
            {
                repItems.SelectTopN = DEFAULT_WEBPART_COUNT;
            }
            repItems.ReloadData(true);
            dataLoaded = true;
        }
    }
Exemple #30
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Security test
        if (!MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin))
        {
            RedirectToAccessDenied(GetString("attach.actiondenied"));
        }

        // Add link to external stylesheet
        CSSHelper.RegisterCSSLink(this, "Default", "/CMSDesk.css");

        // Get current resolver
        resolver = MacroContext.CurrentResolver.CreateChild();

        DataSet ds  = null;
        DataSet cds = null;

        // Check init settings
        bool allWidgets    = QueryHelper.GetBoolean("allWidgets", false);
        bool allWebParts   = QueryHelper.GetBoolean("allWebparts", false);
        bool allWireframes = QueryHelper.GetBoolean("allwireframes", 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 && !allWireframes)
        {
            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.GetCategories();
        }
        // Generate all widgets
        else if (allWidgets)
        {
            // Get all widget categories
            cds = WidgetCategoryInfoProvider.GetWidgetCategories();
        }
        else if (allWireframes)
        {
            WebPartCategoryInfo wpci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("Wireframes");
            if (wpci != null)
            {
                cds = WebPartCategoryInfoProvider.GetCategories(wpci.CategoryID);
            }
        }
        // Generate single webpart
        else if (isWebpartInQuery)
        {
            // Split weparts
            string[] webparts = webpartQueryParam.Split(';');
            if (webparts.Length > 0)
            {
                string webpartWhere = SqlHelper.GetWhereCondition("WebpartName", webparts);
                ds = WebPartInfoProvider.GetWebParts().Where(webpartWhere);

                // 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().Where(ctWhere);
                }
            }
        }
        // Generate single widget
        else if (isWidgetInQuery)
        {
            string[] widgets = webpartQueryParam.Split(';');
            if (widgets.Length > 0)
            {
                string widgetsWhere = SqlHelper.GetWhereCondition("WidgetName", widgets);
                ds = WidgetInfoProvider.GetWidgets().Where(widgetsWhere);
            }

            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().Where(ctWhere);
            }
        }

        if (allWidgets || isWidgetInQuery)
        {
            documentationTitle = "Kentico Widgets";
            Page.Header.Title  = "Widgets documentation";
        }

        if (!allWebParts && !allWidgets && !allWireframes && !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 || allWireframes)
                {
                    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().WhereEquals("WidgetCategoryID", categoryID);
                }

                // 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 || allWireframes)
                        {
                            wpi = new WebPartInfo(dr);
                            if (wpi != null)
                            {
                                itemDisplayName   = wpi.WebPartDisplayName;
                                itemDescription   = wpi.WebPartDescription;
                                itemDocumentation = wpi.WebPartDocumentation;
                                itemID            = wpi.WebPartID;
                                itemType          = WebPartInfo.OBJECT_TYPE;

                                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          = WidgetInfo.OBJECT_TYPE;
                                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(ResHelper.LocalizeString(cdr[namePrefix + "CategoryDisplayName"].ToString())) + "&nbsp;>&nbsp;" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(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;
    }