Beispiel #1
0
    /// <summary>
    /// Creates widget. Called when the "Create widget" button is pressed.
    /// </summary>
    private bool CreateWidget()
    {
        // Get parent webpart and category for widget
        WebPartInfo        webpart  = WebPartInfoProvider.GetWebPartInfo("AbuseReport");
        WidgetCategoryInfo category = WidgetCategoryInfoProvider.GetWidgetCategoryInfo("MyNewCategory");

        // Widget cannot be created from inherited webpart
        if ((webpart != null) && (webpart.WebPartParentID == 0) && (category != null))
        {
            // Create new widget object
            WidgetInfo newWidget = new WidgetInfo();

            // Set the properties from parent webpart
            newWidget.WidgetName        = "MyNewWidget";
            newWidget.WidgetDisplayName = "My new widget";
            newWidget.WidgetDescription = webpart.WebPartDescription;

            newWidget.WidgetProperties = FormHelper.GetFormFieldsWithDefaultValue(webpart.WebPartProperties, "visible", "false");

            newWidget.WidgetWebPartID  = webpart.WebPartID;
            newWidget.WidgetCategoryID = category.WidgetCategoryID;

            // Save new widget
            WidgetInfoProvider.SetWidgetInfo(newWidget);

            return(true);
        }

        return(false);
    }
Beispiel #2
0
    /// <summary>
    /// Gets and bulk updates widget categories. Called when the "Get and bulk update categories" button is pressed.
    /// Expects the CreateWidgetCategory method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateWidgetCategories()
    {
        // Prepare the parameters
        string where = "WidgetCategoryName LIKE N'MyNewCategory%'";
        string orderBy = "";
        int    topN    = 0;
        string columns = "";

        // Get the data
        DataSet categories = WidgetCategoryInfoProvider.GetWidgetCategories()
                             .Where(where)
                             .OrderBy(orderBy)
                             .TopN(topN)
                             .Columns(columns);

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

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

                // Save the changes
                WidgetCategoryInfoProvider.SetWidgetCategoryInfo(modifyCategory);
            }

            return(true);
        }

        return(false);
    }
    /// <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);
            WidgetCategoryInfo categoryInfo = WidgetCategoryInfoProvider.GetWidgetCategoryInfo(categoryId);
            if (categoryInfo != null)
            {
                currentWidgetCategory = HTMLHelper.HTMLEncode(categoryInfo.WidgetCategoryDisplayName);
            }
            else
            {
                // Set root category
                WidgetCategoryInfo rootCategory = WidgetCategoryInfoProvider.GetWidgetCategoryInfo("/");
                if (rootCategory != null)
                {
                    currentWidgetCategory = rootCategory.WidgetCategoryDisplayName;
                }
            }
        }

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

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

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

        // Register script for refresh tree after delete/destroy
        string script = @"function RefreshAdditionalContent() {
                            if (parent.parent.frames['widgettree'])
                            {
                                parent.parent.frames['widgettree'].location.href = '" + URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/WidgetTree.aspx?categoryid=" + categoryId) + @"';
                            }
                        }";

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

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

        // Configure the UniGrid
        WidgetCategoryInfo categoryInfo = WidgetCategoryInfoProvider.GetWidgetCategoryInfo(categoryId);

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

        InitializeMasterPage();
    }
Beispiel #5
0
    /// <summary>
    /// Deletes widget category. Called when the "Delete category" button is pressed.
    /// Expects the CreateWidgetCategory method to be run first.
    /// </summary>
    private bool DeleteWidgetCategory()
    {
        // Get the widget category
        WidgetCategoryInfo deleteCategory = WidgetCategoryInfoProvider.GetWidgetCategoryInfo("MyNewCategory");

        // Delete the widget category
        WidgetCategoryInfoProvider.DeleteWidgetCategoryInfo(deleteCategory);

        return(deleteCategory != null);
    }
Beispiel #6
0
    /// <summary>
    /// Creates widget category. Called when the "Create category" button is pressed.
    /// </summary>
    private bool CreateWidgetCategory()
    {
        // Create new widget category object
        WidgetCategoryInfo newCategory = new WidgetCategoryInfo();

        // Set the properties
        newCategory.WidgetCategoryDisplayName = "My new category";
        newCategory.WidgetCategoryName        = "MyNewCategory";

        // Save the widget category
        WidgetCategoryInfoProvider.SetWidgetCategoryInfo(newCategory);

        return(true);
    }
Beispiel #7
0
    /// <summary>
    /// Selects root category in tree, clears search condition and resets pager to first page.
    /// </summary>
    public void ResetToDefault()
    {
        // Select root by default            
        WidgetCategoryInfo wci = WidgetCategoryInfoProvider.GetWidgetCategoryInfo("/");
        if (wci != null)
        {
            flatElem.SelectedCategory = wci;

            // Select and expand root node                
            treeElem.SelectedItem = wci.WidgetCategoryID.ToString();
            treeElem.SelectPath = "/";
        }

        // Clear search condition and resets pager to first page
        flatElem.UniFlatSelector.ResetToDefault();
    }
    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check "read" permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Widget", "Read"))
        {
            RedirectToAccessDenied("CMS.Widget", "Read");
        }

        widgetId = QueryHelper.GetInteger("widgetId", 0);
        widget   = WidgetInfoProvider.GetWidgetInfo(widgetId);

        if (widget != null)
        {
            string             currentWidget = widget.WidgetDisplayName;
            WidgetCategoryInfo categoryInfo  = WidgetCategoryInfoProvider.GetWidgetCategoryInfo(widget.WidgetCategoryID);

            // Initialize Master Page
            string[,] pageTitleTabs = new string[3, 4];

            pageTitleTabs[0, 0] = GetString("widgets.title");
            pageTitleTabs[0, 1] = URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/Category_Frameset.aspx");
            pageTitleTabs[0, 2] = "_parent";
            pageTitleTabs[0, 3] = "if (parent.parent.frames['widgettree']) { parent.parent.frames['widgettree'].location.href = '" + URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/WidgetTree.aspx") + "'; }";

            if (categoryInfo != null)
            {
                pageTitleTabs[1, 0] = HTMLHelper.HTMLEncode(categoryInfo.WidgetCategoryDisplayName);
                pageTitleTabs[1, 1] = URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/Category_Frameset.aspx?categoryid=" + widget.WidgetCategoryID);
                pageTitleTabs[1, 2] = "_parent";
                pageTitleTabs[1, 3] = "if (parent.parent.frames['widgettree']) { parent.parent.frames['widgettree'].location.href = '" + URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/WidgetTree.aspx?categoryid=" + widget.WidgetCategoryID) + "'; }";

                pageTitleTabs[2, 0] = HTMLHelper.HTMLEncode(currentWidget);
                pageTitleTabs[2, 1] = "";
                pageTitleTabs[2, 2] = "";
            }

            // Set masterpage
            CurrentMaster.Title.TitleImage    = GetImageUrl("Objects/CMS_Widget/object.png");
            CurrentMaster.Title.HelpTopicName = "widget_general";
            CurrentMaster.Title.HelpName      = "helpTopic";
            CurrentMaster.Title.Breadcrumbs   = pageTitleTabs;

            // Tabs
            InitalizeTabs();
        }
    }
Beispiel #9
0
    /// <summary>
    /// Gets and updates widget category. Called when the "Get and update category" button is pressed.
    /// Expects the CreateWidgetCategory method to be run first.
    /// </summary>
    private bool GetAndUpdateWidgetCategory()
    {
        // Get the widget category
        WidgetCategoryInfo updateCategory = WidgetCategoryInfoProvider.GetWidgetCategoryInfo("MyNewCategory");

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

            // Save the changes
            WidgetCategoryInfoProvider.SetWidgetCategoryInfo(updateCategory);

            return(true);
        }

        return(false);
    }
Beispiel #10
0
    /// <summary>
    /// Used for maxnodes in collapsed node.
    /// </summary>
    protected TreeNode treeElem_OnNodeCreated(DataRow itemData, TreeNode defaultNode)
    {
        if (UseMaxNodeLimit && (MaxTreeNodes > 0))
        {
            // 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.ToLowerCSafe() == "widgetcategory")
            {
                return(defaultNode);
            }

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

                WidgetCategoryInfo parentParent = WidgetCategoryInfoProvider.GetWidgetCategoryInfo(parentID);
                if (parentParent != null)
                {
                    parentParentID = parentParent.WidgetCategoryParentID;
                }

                TreeNode node = new TreeNode();
                node.Text = "<span class=\"ContentTreeItem\" onclick=\"SelectNode(" + parentID + " ,'widgetcategory'," + parentParentID + ",true ); return false;\"><span class=\"Name\">" + GetString("general.seelisting") + "</span></span>";
                return(node);
            }
            if (indexMaxTreeNodes > MaxTreeNodes)
            {
                return(null);
            }
        }
        return(defaultNode);
    }
    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        categoryEdit.ItemID = QueryHelper.GetInteger("categoryid", 0);

        int parentCategoryId = QueryHelper.GetInteger("parentid", 0);

        categoryEdit.ParentCategoryID = parentCategoryId;

        // Edit cateogry
        if (categoryEdit.ItemID > 0)
        {
            WidgetCategoryInfo wci = WidgetCategoryInfoProvider.GetWidgetCategoryInfo(categoryEdit.ItemID);
            if (wci != null)
            {
                // Set already loaded object to inner control
                categoryEdit.CategoryInfo = wci;

                // Set masterpage
                CurrentMaster.Title.TitleText   = "";
                CurrentMaster.Title.Breadcrumbs = null;
            }
        }
        // New category
        else
        {
            CurrentMaster.Title.HelpName      = "helpTopic";
            CurrentMaster.Title.HelpTopicName = "widget_category_general";

            isNew = true;

            WidgetCategoryInfo parentCategoryInfo = WidgetCategoryInfoProvider.GetWidgetCategoryInfo(parentCategoryId);

            string parentCategoryName = GetString("development.pagetemplates");
            if (parentCategoryInfo != null)
            {
                parentCategoryName = parentCategoryInfo.WidgetCategoryDisplayName;
            }

            string[,] pageTitleTabs = new string[3, 4];

            pageTitleTabs[0, 0] = GetString("widgets.title");
            pageTitleTabs[0, 1] = URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/Category_Frameset.aspx");
            pageTitleTabs[0, 2] = "";
            pageTitleTabs[0, 3] = "if (parent.frames['widgettree']) { parent.frames['widgettree'].location.href = '" + URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/WidgetTree.aspx") + "'; }";

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

            pageTitleTabs[2, 0] = GetString("widgets.category.titlenew");
            pageTitleTabs[2, 1] = "";
            pageTitleTabs[2, 2] = "";

            // Set masterpage
            CurrentMaster.Title.TitleText   = GetString("widget.category");
            CurrentMaster.Title.TitleImage  = GetImageUrl("Objects/CMS_WidgetCategory/new.png");
            CurrentMaster.Title.Breadcrumbs = pageTitleTabs;
        }

        categoryEdit.OnSaved += new EventHandler(categoryEdit_OnSaved);
    }
    /// <summary>
    /// Gets and bulk updates widget categories. Called when the "Get and bulk update categories" button is pressed.
    /// Expects the CreateWidgetCategory method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateWidgetCategories()
    {
        // Prepare the parameters
        string where = "WidgetCategoryName LIKE N'MyNewCategory%'";
        string orderBy = "";
        int topN = 0;
        string columns = "";

        // Get the data
        DataSet categories = WidgetCategoryInfoProvider.GetWidgetCategories()
            .Where(where)
            .OrderBy(orderBy)
            .TopN(topN)
            .Columns(columns);

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

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

                // Save the changes
                WidgetCategoryInfoProvider.SetWidgetCategoryInfo(modifyCategory);
            }

            return true;
        }

        return false;
    }
Beispiel #13
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (!CheckPermissions("cms.widgetcategory", CMSAdminControl.PERMISSION_MODIFY))
        {
            return;
        }

        // Limit length of inputs
        txtCodeName.Text    = TextHelper.LimitLength(txtCodeName.Text.Trim(), 100, "");
        txtDisplayName.Text = TextHelper.LimitLength(txtDisplayName.Text.Trim(), 100, "");
        txtImagePath.Text   = TextHelper.LimitLength(txtImagePath.Text.Trim(), 400, "");

        // Perform validation
        string errorMessage = new Validator().NotEmpty(txtCodeName.Text, rfvCodeName.ErrorMessage).NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage).Result;

        if (String.IsNullOrEmpty(errorMessage))
        {
            // New category
            if (this.CategoryInfo == null)
            {
                this.CategoryInfo = new WidgetCategoryInfo();
                this.CategoryInfo.WidgetCategoryParentID = this.ParentCategoryID;
            }

            // Indicates whether current object is root
            bool isRoot = (this.CategoryInfo.WidgetCategoryPath == "/");
            if (!isRoot)
            {
                // Check codename
                errorMessage = new Validator().IsCodeName(txtCodeName.Text, GetString("general.invalidcodename")).Result;
                if (!String.IsNullOrEmpty(errorMessage))
                {
                    // Error message - validation
                    lblError.Visible = true;
                    lblError.Text    = errorMessage;
                    return;
                }
            }

            WidgetCategoryInfo current = WidgetCategoryInfoProvider.GetWidgetCategoryInfo(txtCodeName.Text);

            // Check if code name is unique
            if ((current == null) || (this.CategoryInfo.WidgetCategoryID == current.WidgetCategoryID))
            {
                // Set category values
                if (!isRoot)
                {
                    this.CategoryInfo.WidgetCategoryName = txtCodeName.Text;
                }
                this.CategoryInfo.WidgetCategoryDisplayName = txtDisplayName.Text;
                this.CategoryInfo.WidgetCategoryImagePath   = txtImagePath.Text;

                WidgetCategoryInfoProvider.SetWidgetCategoryInfo(this.CategoryInfo);

                // Redirect to edit mode
                RaiseOnSaved();
            }
            else
            {
                // Error message - code name already exists
                lblError.Visible = true;
                lblError.Text    = GetString("general.codenameexists");
            }
        }
        else
        {
            // Error message - validation
            lblError.Visible = true;
            lblError.Text    = errorMessage;
        }
    }
Beispiel #14
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 > 2))
        {
            string             action   = values[0];
            int                id       = 0;
            int                parentId = 0;
            string             script   = String.Empty;
            WidgetCategoryInfo wci      = null;

            switch (action)
            {
            case "newwidget":

                id       = ValidationHelper.GetInteger(values[1], 0);
                parentId = ValidationHelper.GetInteger(values[2], 0);

                // Create new widget of selected type
                WidgetInfo wi = NewWidget(id, parentId);
                if (wi != null)
                {
                    // Select parent node after delete
                    wci = WidgetCategoryInfoProvider.GetWidgetCategoryInfo(parentId);
                    if (wci != null)
                    {
                        script = SelectAtferLoad(wci.WidgetCategoryPath + "/" + wi.WidgetName, wi.WidgetID, "widget", wi.WidgetCategoryID);
                    }
                }

                break;

            // Delete widget or widget category
            case "delete":

                id       = ValidationHelper.GetInteger(values[2], 0);
                parentId = ValidationHelper.GetInteger(values[3], 0);

                switch (values[1])
                {
                case "widget":
                    WidgetInfoProvider.DeleteWidgetInfo(id);
                    break;

                case "widgetcategory":
                    try
                    {
                        WidgetCategoryInfoProvider.DeleteWidgetCategoryInfo(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
                wci = WidgetCategoryInfoProvider.GetWidgetCategoryInfo(parentId);
                if (wci != null)
                {
                    script = SelectAtferLoad(wci.WidgetCategoryPath + "/", parentId, "widgetcategory", wci.WidgetCategoryParentID) + script;
                }
                break;
            }

            widgetTree.ReloadData();

            ltlScript.Text += ScriptHelper.GetScript(script);
        }
    }
Beispiel #15
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Register scripts
        this.RegisterExportScript();
        ScriptHelper.RegisterJQuery(this.Page);

        // Use only global settings for max tree nodes
        widgetTree.UseGlobalSettings = true;

        // Setup menu action images
        imgNewCategory.ImageUrl  = GetImageUrl("Objects/CMS_WidgetCategory/add.png");
        imgNewWidget.ImageUrl    = GetImageUrl("Objects/CMS_Widget/add.png");
        imgDeleteItem.ImageUrl   = GetImageUrl("Objects/CMS_Widget/delete.png");
        imgExportObject.ImageUrl = GetImageUrl("Objects/CMS_Widget/export.png");
        imgCloneWidget.ImageUrl  = GetImageUrl("Objects/CMS_Widget/clone.png");

        // Setup menu action labels
        lnkNewWidget.Text    = GetString("widgets.NewWidget");
        lnkDeleteItem.Text   = GetString("widgets.DeleteItem");
        lnkNewCategory.Text  = GetString("widgets.NewCategory");
        lnkExportObject.Text = GetString("widgets.ExportWidget");
        lnkCloneWidget.Text  = GetString("widgets.CloneWidget");

        // Setup menu action scripts
        lnkNewWidget.Attributes.Add("onclick", "NewItem('widget');");
        lnkNewCategory.Attributes.Add("onclick", "NewItem('widgetcategory');");
        lnkDeleteItem.Attributes.Add("onclick", "DeleteItem();");
        lnkExportObject.Attributes.Add("onclick", "ExportObject();");
        lnkCloneWidget.Attributes.Add("onclick", "CloneWidget();");

        // Tooltips
        lnkNewWidget.ToolTip    = GetString("widgets.NewWidget");
        lnkDeleteItem.ToolTip   = GetString("widgets.DeleteItem");
        lnkNewCategory.ToolTip  = GetString("widgets.NewCategory");
        lnkExportObject.ToolTip = GetString("widgets.ExportWidget");
        lnkCloneWidget.ToolTip  = GetString("widgets.CloneWidget");

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

        // URLs for menu actions
        script += "var categoryURL = '" + URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/Category_Frameset.aspx") + "';\n";
        script += "var categoryNewURL = '" + URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/WidgetCategory_Edit.aspx") + "';\n";
        script += "var widgetURL = '" + URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/Widget_Edit_Frameset.aspx") + "';\n";
        script += "var newWidgetURL = '" + URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/Widget_New.aspx") + "';\n";
        script += "var cloneURL = '" + URLHelper.ResolveUrl("~/CMSModules/Widgets/Dialogs/Widget_Clone.aspx") + "';\n";
        script += "var webpartSelectorURL = '" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPartSelector.aspx") + "';\n";

        // Script for deleting widget or category
        string postbackRef  = ControlsHelper.GetPostBackEventReference(this.Page, "##");
        string deleteScript = "function DeleteItem() { \n" +
                              " if ((selectedItemId > 0) && (selectedItemParent > 0)) { " +
                              "   var message = (selectedItemType == 'widgetcategory') ? '" + GetString("widgets.deletecategoryconfirm") + "' : '" + GetString("widgets.deleteconfirm") + "';" +
                              "   if (confirm(message)) {\n " +
                              postbackRef.Replace("'##'", "'delete;'+selectedItemType+';'+selectedItemId+';'+selectedItemParent") + ";\n" +
                              "   }\n" +
                              " }\n" +
                              "}\n";

        script += deleteScript;

        // Script for new widget
        string newWidgetScript = "function OnSelectWebPart(webpartId) { \n" +
                                 " if ((webpartId > 0) && (selectedItemId > 0) && (selectedItemType == 'widgetcategory')) { \n" +
                                 postbackRef.Replace("'##'", "'newwidget;' + webpartId + ';' + selectedItemId") +
                                 "\n }  }\n";

        script += newWidgetScript;


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

            // Select category
            if (categoryId > 0)
            {
                WidgetCategoryInfo wci = WidgetCategoryInfoProvider.GetWidgetCategoryInfo(categoryId);
                if (wci != null)
                {
                    // If not set explicitly stop reloading of right frame
                    if (!reload)
                    {
                        script += "doNotReloadContent = true;";
                    }
                    script += SelectAtferLoad(wci.WidgetCategoryPath + "/", categoryId, "widgetcategory", wci.WidgetCategoryParentID);
                }
            }
            // Select widget
            else if (widgetId > 0)
            {
                WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetId);
                if (wi != null)
                {
                    WidgetCategoryInfo wci = WidgetCategoryInfoProvider.GetWidgetCategoryInfo(wi.WidgetCategoryID);
                    if (wci != null)
                    {
                        // If not set explicitly stop reloading of right frame
                        if (!reload)
                        {
                            script += "doNotReloadContent = true;";
                        }
                        string path = wci.WidgetCategoryPath + "/" + wi.WidgetName;
                        script += SelectAtferLoad(path, widgetId, "widget", wi.WidgetCategoryID);
                    }
                }
            }
            // Select root by default
            else
            {
                WidgetCategoryInfo wci = WidgetCategoryInfoProvider.GetWidgetCategoryInfo("/");
                if (wci != null)
                {
                    script += SelectAtferLoad("/", wci.WidgetCategoryID, "widgetcategory", 0);
                }
            }
        }

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

        // Special browser class for RTL scrollbars correction
        pnlSubBox.CssClass = BrowserHelper.GetBrowserClass();
    }
    /// <summary>
    /// Creates widget category. Called when the "Create category" button is pressed.
    /// </summary>
    private bool CreateWidgetCategory()
    {
        // Create new widget category object
        WidgetCategoryInfo newCategory = new WidgetCategoryInfo();

        // Set the properties
        newCategory.WidgetCategoryDisplayName = "My new category";
        newCategory.WidgetCategoryName = "MyNewCategory";

        // Save the widget category
        WidgetCategoryInfoProvider.SetWidgetCategoryInfo(newCategory);

        return true;
    }
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (!CheckPermissions("cms.widgetcategory", PERMISSION_MODIFY))
        {
            return;
        }

        // Limit length of inputs
        txtCodeName.Text = TextHelper.LimitLength(txtCodeName.Text.Trim(), 100, "");
        txtDisplayName.Text = TextHelper.LimitLength(txtDisplayName.Text.Trim(), 100, "");
        txtImagePath.Text = TextHelper.LimitLength(txtImagePath.Text.Trim(), 400, "");

        // Perform validation
        string errorMessage = new Validator().NotEmpty(txtCodeName.Text, rfvCodeName.ErrorMessage).NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage).Result;

        if (String.IsNullOrEmpty(errorMessage))
        {
            // New category
            if (CategoryInfo == null)
            {
                CategoryInfo = new WidgetCategoryInfo();
                CategoryInfo.WidgetCategoryParentID = ParentCategoryID;
            }

            // Indicates whether current object is root
            bool isRoot = (CategoryInfo.WidgetCategoryPath == "/");
            if (!isRoot)
            {
                // Check codename
                errorMessage = new Validator().IsCodeName(txtCodeName.Text, GetString("general.invalidcodename")).Result;
                if (!String.IsNullOrEmpty(errorMessage))
                {
                    // Error message - validation
                    ShowError(errorMessage);
                    return;
                }
            }

            WidgetCategoryInfo current = WidgetCategoryInfoProvider.GetWidgetCategoryInfo(txtCodeName.Text);

            // Check if code name is unique
            if ((current == null) || (CategoryInfo.WidgetCategoryID == current.WidgetCategoryID))
            {
                // Set category values
                if (!isRoot)
                {
                    CategoryInfo.WidgetCategoryName = txtCodeName.Text;
                }
                CategoryInfo.WidgetCategoryDisplayName = txtDisplayName.Text;
                CategoryInfo.WidgetCategoryImagePath = txtImagePath.Text;

                WidgetCategoryInfoProvider.SetWidgetCategoryInfo(CategoryInfo);

                // Redirect to edit mode
                RaiseOnSaved();
            }
            else
            {
                // Error message - code name already exists
                ShowError(GetString("general.codenameexists"));
            }
        }
        else
        {
            // Error message - validation
            ShowError(errorMessage);
        }
    }