Exemplo n.º 1
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (!CheckPermissions("cms.widgets", PERMISSION_MODIFY))
        {
            return;
        }

        // Create new widget info if new widget
        if (WidgetInfo == null)
        {
            // Parent webpart must be set
            if ((WidgetWebpartId == 0) || (WidgetCategoryId == 0))
            {
                return;
            }

            WidgetInfo = new WidgetInfo();
            WidgetInfo.WidgetWebPartID  = WidgetWebpartId;
            WidgetInfo.WidgetCategoryID = WidgetCategoryId;
        }

        txtCodeName.Text    = TextHelper.LimitLength(txtCodeName.Text.Trim(), 100, "");
        txtDisplayName.Text = TextHelper.LimitLength(txtDisplayName.Text.Trim(), 100, "");

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

        if (errorMessage == "")
        {
            // If name changed, check if new name is unique
            if (CMSString.Compare(WidgetInfo.WidgetName, txtCodeName.Text, true) != 0)
            {
                WidgetInfo widget = WidgetInfoProvider.GetWidgetInfo(txtCodeName.Text);
                if (widget != null)
                {
                    ShowError(GetString("general.codenameexists"));
                    return;
                }
            }

            WidgetInfo.WidgetName                 = txtCodeName.Text;
            WidgetInfo.WidgetDisplayName          = txtDisplayName.Text;
            WidgetInfo.WidgetDescription          = txtDescription.Text;
            WidgetInfo.WidgetLayoutID             = ValidationHelper.GetInteger(ucLayouts.Value, 0);
            WidgetInfo.WidgetCategoryID           = ValidationHelper.GetInteger(categorySelector.Value, WidgetInfo.WidgetCategoryID);
            WidgetInfo.WidgetSkipInsertProperties = chkSkipInsertProperties.Checked;

            WidgetInfoProvider.SetWidgetInfo(WidgetInfo);

            ShowChangesSaved();

            // Raise save for frame reload
            RaiseOnSaved();
        }
        else
        {
            ShowError(errorMessage);
        }
    }
    /// <summary>
    /// Handles OnFieldCreated action and updates form definition of all widgets based on current webpart.
    /// Newly created field is set to be disabled in widget definition for security reasons.
    /// </summary>
    /// <param name="newField">Newly created field</param>
    protected void UpdateWidgetsDefinition(object sender, FormFieldInfo newField)
    {
        if ((webPartInfo != null) && (newField != null))
        {
            // Get widgets based on this webpart
            DataSet ds = WidgetInfoProvider.GetWidgets()
                         .WhereEquals("WidgetWebPartID", WebPartID)
                         .Columns("WidgetID");

            // Continue only if there are some widgets
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int        widgetId = ValidationHelper.GetInteger(dr["WidgetID"], 0);
                    WidgetInfo widget   = WidgetInfoProvider.GetWidgetInfo(widgetId);
                    if (widget != null)
                    {
                        // Prepare disabled field definition
                        string disabledField = String.Format("<form><field column=\"{0}\" visible=\"false\" /></form>", newField.Name);

                        // Incorporate disabled field into original definition of widget
                        widget.WidgetProperties = FormHelper.CombineFormDefinitions(widget.WidgetProperties, disabledField);

                        // Update widget
                        WidgetInfoProvider.SetWidgetInfo(widget);
                    }
                }
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        widgetInfo             = WidgetInfoProvider.GetWidgetInfo(WidgetID);
        UIContext.EditedObject = widgetInfo;

        if (widgetInfo != null)
        {
            webpartInfo           = WebPartInfoProvider.GetWebPartInfo(widgetInfo.WidgetWebPartID);
            fieldEditor.DisplayIn = FormInfo.DISPLAY_CONTEXT_DASHBOARD;

            if (webpartInfo != null)
            {
                // Set original form definition from webpart
                fieldEditor.OriginalFormDefinition = webpartInfo.WebPartProperties;

                // Merge class and alternative form definitions
                string formDef = FormHelper.MergeFormDefinitions(webpartInfo.WebPartProperties, widgetInfo.WidgetProperties);

                // Use alternative form mode for field editor
                fieldEditor.Mode           = FieldEditorModeEnum.Widget;
                fieldEditor.FormDefinition = formDef;

                // Use same control for widgets as for webparts
                fieldEditor.DisplayedControls = FieldEditorControlsEnum.Controls;

                // Handle definition update (move up, move down, delete, OK button)
                fieldEditor.OnAfterDefinitionUpdate += fieldEditor_OnAfterDefinitionUpdate;
            }
        }
        else
        {
            fieldEditor.Visible = false;
            ShowError(GetString("general.invalidid"));
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        widgetId = QueryHelper.GetInteger("widgetid", 0);

        Title = "Widget part documentation";

        // Resource string
        btnOk.Text = GetString("General.Ok");

        WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetId);

        // set Documentation header - "View documentation" + "Generate Documentation"
        if (wi != null)
        {
            HeaderAction action = new HeaderAction();
            action.Text        = GetString("webparteditdocumentation.view");
            action.RedirectUrl = "~/CMSModules/Widgets/Dialogs/WidgetDocumentation.aspx?widgetid=" + wi.WidgetID;
            action.Target      = "_blank";
            CurrentMaster.HeaderActions.AddAction(action);
        }

        // HTML editor settings
        htmlText.AutoDetectLanguage = false;
        htmlText.DefaultLanguage    = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
        htmlText.EditorAreaCSS      = "";
        htmlText.ToolbarSet         = "SimpleEdit";

        // Load data
        if (!RequestHelper.IsPostBack() && (wi != null))
        {
            htmlText.ResolvedValue = wi.WidgetDocumentation;
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void pageTemplatesGrid_OnAction(string actionName, object actionArgument)
    {
        int widgetId = Convert.ToInt32(actionArgument);

        switch (actionName)
        {
        case "delete":
            // Check 'Modify' permission
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.widget", "Modify"))
            {
                RedirectToAccessDenied("cms.widget", "Modify");
            }

            // delete PageTemplateInfo object from database
            WidgetInfoProvider.DeleteWidgetInfo(widgetId);

            // Refresh tree
            ltlScript.Text = ScriptHelper.GetScript("RefreshAdditionalContent();");
            break;

        case "clone":
            string scriptDialog = "modalDialog('" + URLHelper.ResolveUrl("~/CMSModules/Widgets/Dialogs/Widget_Clone.aspx") + "?widgetid=" + widgetId + "&reloadAll=0','WidgetClone', 500, 250);";
            ltlScript.Text = ScriptHelper.GetScript(scriptDialog);
            break;
        }
    }
Exemplo n.º 6
0
    /// <summary>
    /// Update web part properties default values
    /// </summary>
    private static void UpdateWidgetProperties()
    {
        try
        {
            List <string> wpGuid = new List <string>()
            {
                "D6EC4B53-781E-4240-98F4-F4D64873A482",
                "09F5FF6C-F2A1-4322-AEA6-6B0D61CD1375",
                "1CEF5345-672E-4571-A0BD-BC7BD217B1A0",
                "90994364-454F-4457-98FE-6EB78D2B452C"
            };

            // Get inherited webparts with properties stored in old way
            string where = "WidgetDefaultValues LIKE N'%field name=\"%' AND WidgetGUID NOT IN ('" + wpGuid.Join("','") + "')";
            InfoDataSet <WidgetInfo> data = WidgetInfoProvider.GetWidgets().Where(where).TypedResult;
            if (!DataHelper.DataSourceIsEmpty(data))
            {
                foreach (WidgetInfo info in data)
                {
                    info.WidgetDefaultValues = ModifyProperties(info.WidgetDefaultValues);

                    // Update widget
                    info.Update();
                }
            }
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException("Upgrade - Widget properties", "Upgrade", ex);
        }
    }
    public void RaisePostBackEvent(string eventArgument)
    {
        if (!CheckPermissions("cms.widget", PERMISSION_MODIFY))
        {
            return;
        }

        string[] args = eventArgument.Split(';');

        if (args.Length == 2)
        {
            // Get info on currently selected item
            int permission = Convert.ToInt32(args[0]);
            int access     = Convert.ToInt32(args[1]);

            if (WidgetInfo != null)
            {
                // Update widget permission access information
                switch (permission)
                {
                case 0:
                    WidgetInfo.AllowedFor = ((SecurityAccessEnum)access);
                    break;
                }

                // Save changes to the widget
                WidgetInfoProvider.SetWidgetInfo(WidgetInfo);
            }
        }
    }
    /// <summary>
    /// After form definition update event handler.
    /// </summary>
    protected void fieldEditor_OnAfterDefinitionUpdate(object sender, EventArgs e)
    {
        // Perform OnBeforeSave if defined
        if (OnBeforeSave != null)
        {
            OnBeforeSave();
        }

        // Stop processing if set from outside
        if (StopProcessing)
        {
            return;
        }

        if ((widgetInfo != null) && (webpartInfo != null))
        {
            // Compare original and alternative form definitions - store differences only
            widgetInfo.WidgetProperties = FormHelper.GetFormDefinitionDifference(webpartInfo.WebPartProperties, fieldEditor.FormDefinition, true);
            // Update alternative form info in database
            WidgetInfoProvider.SetWidgetInfo(widgetInfo);
        }
        else
        {
            ShowError(GetString("general.invalidid"));
        }
    }
Exemplo n.º 9
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void webpartGrid_OnAction(string actionName, object actionArgument)
    {
        int webpartId = Convert.ToInt32(actionArgument);

        switch (actionName)
        {
        case "delete":
            // Check 'Modify' permission
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.webpart", "Modify"))
            {
                RedirectToAccessDenied("cms.webpart", "Modify");
            }

            // Check if webpart has widgets
            DataSet dsWidgets = WidgetInfoProvider.GetWidgets("WidgetWebPartID = " + webpartId, null, 0, "WidgetWebPartID");
            if (!DataHelper.DataSourceIsEmpty(dsWidgets))
            {
                string delPostback = ControlsHelper.GetPostBackEventReference(Page, webpartId.ToString());
                delPostback    = "if (confirm('" + GetString("webparts.deletewithwidgets") + "')) {\n " + delPostback + ";}\n";
                ltlScript.Text = ScriptHelper.GetScript(delPostback);
            }
            else
            {
                // Delete PageTemplateInfo object from database
                WebPartInfoProvider.DeleteWebPartInfo(webpartId);

                // Refresh tree
                ltlScript.Text = ScriptHelper.GetScript("RefreshAdditionalContent();");
            }
            break;
        }
    }
Exemplo n.º 10
0
    /// <summary>
    /// Gets and bulk updates widgets. Called when the "Get and bulk update widgets" button is pressed.
    /// Expects the CreateWidget method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateWidgets()
    {
        // Prepare the parameters
        string where = "WidgetName LIKE N'MyNewWidget%'";
        string orderBy = "";
        int    topN    = 0;
        string columns = "";

        // Get the data
        DataSet widgets = WidgetInfoProvider.GetWidgets(where, orderBy, topN, columns);

        if (!DataHelper.DataSourceIsEmpty(widgets))
        {
            // Loop through the individual items
            foreach (DataRow widgetDr in widgets.Tables[0].Rows)
            {
                // Create object from DataRow
                WidgetInfo modifyWidget = new WidgetInfo(widgetDr);

                // Update the properties
                modifyWidget.WidgetDisplayName = modifyWidget.WidgetDisplayName.ToUpper();

                // Save the changes
                WidgetInfoProvider.SetWidgetInfo(modifyWidget);
            }

            return(true);
        }

        return(false);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        widgetInfo = WidgetInfoProvider.GetWidgetInfo(this.WidgetID);
        if (widgetInfo != null)
        {
            webpartInfo           = WebPartInfoProvider.GetWebPartInfo(widgetInfo.WidgetWebPartID);
            fieldEditor.DisplayIn = FormInfo.DISPLAY_CONTEXT_DASHBOARD;

            if (webpartInfo != null)
            {
                // Merge class and alternative form definitions
                string formDef = FormHelper.MergeFormDefinitions(webpartInfo.WebPartProperties, widgetInfo.WidgetProperties);

                // Use alternative form mode for field editor
                fieldEditor.Mode              = FieldEditorModeEnum.General;
                fieldEditor.FormDefinition    = formDef;
                fieldEditor.IsAlternativeForm = true;

                // Use same control for widgets as for webparts
                fieldEditor.DisplayedControls = FieldEditorControlsEnum.Controls;

                // Handle definition update (move up, move down, delete, OK button)
                fieldEditor.OnAfterDefinitionUpdate += fieldEditor_OnAfterDefinitionUpdate;
            }
        }
        else
        {
            fieldEditor.Visible = false;
            ShowErrorMessage();
        }
    }
Exemplo n.º 12
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);
    }
Exemplo n.º 13
0
    /// <summary>
    /// Page load.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        InitializeComponents();

        // Get the widget ID
        widgetId = QueryHelper.GetInteger("widgetID", 0);

        // Select widget category on dropdown list
        wi = WidgetInfoProvider.GetWidgetInfo(widgetId);

        if (wi != null)
        {
            if (!RequestHelper.IsPostBack())
            {
                int    counter      = 1;
                string codenameBase = TextHelper.LimitLength(wi.WidgetName, 98, "");

                Regex regexCodename    = RegexHelper.GetRegex("^(.*?)_(\\d+)$");
                Regex regexDisplayName = RegexHelper.GetRegex("^(.*?)\\((\\d+)\\)$");

                Match match = regexCodename.Match(wi.WidgetName);
                if (match.Success && (match.Groups.Count == 3))
                {
                    // Incremental codename
                    codenameBase = match.Groups[1].Value;
                    counter      = ValidationHelper.GetInteger(match.Groups[2].Value, 1);
                }

                // Find unique widget name
                while (WidgetInfoProvider.GetWidgetInfo(codenameBase + "_" + counter) != null)
                {
                    counter++;
                }

                // New names
                string newWidgetName        = codenameBase + "_" + counter;
                string newWidgetDisplayName = wi.WidgetDisplayName;

                match = regexDisplayName.Match(wi.WidgetDisplayName);
                if (match.Success && (match.Groups.Count == 3))
                {
                    // Incremental display name
                    newWidgetDisplayName = match.Groups[1].Value + "(" + counter + ")";
                }
                else
                {
                    // Full display name
                    newWidgetDisplayName = wi.WidgetDisplayName + "(" + counter + ")";
                }

                txtWidgetDisplayName.Text = newWidgetDisplayName;
                txtWidgetName.Text        = newWidgetName;
                categorySelector.Value    = wi.WidgetCategoryID;
            }
        }
    }
Exemplo n.º 14
0
    /// <summary>
    /// Deletes widget. Called when the "Delete widget" button is pressed.
    /// Expects the CreateWidget method to be run first.
    /// </summary>
    private bool DeleteWidget()
    {
        // Get the widget
        WidgetInfo deleteWidget = WidgetInfoProvider.GetWidgetInfo("MyNewWidget");

        // Delete the widget
        WidgetInfoProvider.DeleteWidgetInfo(deleteWidget);

        return(deleteWidget != null);
    }
    void fieldEditor_AfterItemDeleted(object sender, FieldEditorEventArgs e)
    {
        if (e == null)
        {
            return;
        }

        // Remove deleted field or category from inherited web parts
        InfoDataSet <WebPartInfo> webParts = WebPartInfoProvider.GetWebParts()
                                             .WhereEquals("WebPartParentID", WebPartID).TypedResult;

        if (!DataHelper.DataSourceIsEmpty(webParts))
        {
            foreach (WebPartInfo info in webParts)
            {
                switch (e.ItemType)
                {
                case FieldEditorSelectedItemEnum.Field:
                    info.WebPartProperties = FormHelper.RemoveFieldFromAlternativeDefinition(info.WebPartProperties, e.ItemName, e.ItemOrder);
                    break;

                case FieldEditorSelectedItemEnum.Category:
                    info.WebPartProperties = FormHelper.RemoveCategoryFromAlternativeDefinition(info.WebPartProperties, e.ItemName, e.ItemOrder);
                    break;
                }

                // Update web part
                info.Update();
            }
        }

        // Remove deleted field or category from widgets based on this web part
        InfoDataSet <WidgetInfo> widgets = WidgetInfoProvider.GetWidgets()
                                           .WhereEquals("WidgetWebPartID", WebPartID).TypedResult;

        if (!DataHelper.DataSourceIsEmpty(widgets))
        {
            foreach (WidgetInfo info in widgets)
            {
                switch (e.ItemType)
                {
                case FieldEditorSelectedItemEnum.Field:
                    info.WidgetProperties = FormHelper.RemoveFieldFromAlternativeDefinition(info.WidgetProperties, e.ItemName, e.ItemOrder);
                    break;

                case FieldEditorSelectedItemEnum.Category:
                    info.WidgetProperties = FormHelper.RemoveCategoryFromAlternativeDefinition(info.WidgetProperties, e.ItemName, e.ItemOrder);
                    break;
                }

                // Update widget
                info.Update();
            }
        }
    }
Exemplo n.º 16
0
    /// <summary>
    /// OK click handler, save changes.
    /// </summary>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetId);

        if (wi != null)
        {
            wi.WidgetDocumentation = htmlText.ResolvedValue;
            WidgetInfoProvider.SetWidgetInfo(wi);

            ShowChangesSaved();
        }
    }
Exemplo n.º 17
0
    /// <summary>
    /// OK click handler, save changes.
    /// </summary>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetId);

        if (wi != null)
        {
            wi.WidgetDocumentation = htmlText.ResolvedValue;
            WidgetInfoProvider.SetWidgetInfo(wi);

            lblInfo.Visible = true;
            lblInfo.Text    = GetString("General.ChangesSaved");
        }
    }
Exemplo n.º 18
0
    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        widgetId = QueryHelper.GetInteger("widgetid", 0);

        this.Title = "Widget part documentation";

        // Resource string
        btnOk.Text        = GetString("General.Ok");
        string[,] actions = new string[2, 12];

        WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetId);

        // set Documentation header - "View documentation" + "Generate Documentation"
        if (wi != null)
        {
            // Generate doucmentation action
            actions[0, 0]  = "HyperLink";
            actions[0, 1]  = GetString("webparteditdocumentation.view");
            actions[0, 3]  = "~/CMSModules/Widgets/Dialogs/WidgetDocumentation.aspx?widgetid=" + wi.WidgetName;
            actions[0, 5]  = GetImageUrl("CMSModules/CMS_WebParts/viewdocumentation.png");
            actions[0, 11] = "_blank";

            if (SettingsKeyProvider.DevelopmentMode)
            {
                // Generate doucmentation action
                actions[1, 0]  = "HyperLink";
                actions[1, 1]  = GetString("webparteditdocumentation.generate");
                actions[1, 3]  = "~/CMSPages/Dialogs/Documentation.aspx?widget=" + wi.WidgetName;
                actions[1, 5]  = GetImageUrl("CMSModules/CMS_WebParts/generatedocumentation.png");
                actions[1, 11] = "_blank";
            }
        }

        this.CurrentMaster.HeaderActions.Actions = actions;

        // HTML editor settings
        htmlText.AutoDetectLanguage = false;
        htmlText.DefaultLanguage    = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
        htmlText.EditorAreaCSS      = "";
        htmlText.ToolbarSet         = "SimpleEdit";

        // Load data
        if (!RequestHelper.IsPostBack())
        {
            if (wi != null)
            {
                htmlText.ResolvedValue = wi.WidgetDocumentation;
            }
        }
    }
    /// <summary>
    /// Finds unique widget name. Uses base prefix string with incrementing counter.
    /// </summary>
    /// <param name="basePrefix">New code name will start with this string</param>
    /// <param name="maxLength">Maximum length of unique name</param>
    /// <returns>Unique widget code name.</returns>
    private string FindUniqueWidgetName(string basePrefix, int maxLength)
    {
        int    i       = 0;
        string newName = null;

        // Loop to get unique widget name
        do
        {
            i++;
            string postfix = "_" + i;
            newName = TextHelper.LimitLength(basePrefix, maxLength - postfix.Length, "") + postfix;
        } while (WidgetInfoProvider.GetWidgetInfo(newName) != null);

        return(newName);
    }
Exemplo n.º 20
0
    /// <summary>
    /// Rturns TRUE if selector is used in group widget.
    /// </summary>
    private bool IsGroupPollWidget()
    {
        int        widgetId   = QueryHelper.GetInteger("widgetid", 0);
        string     widgetName = QueryHelper.GetString("widgetname", null);
        WidgetInfo widget     = null;

        if (widgetId > 0)
        {
            widget = WidgetInfoProvider.GetWidgetInfo(widgetId);
        }
        else if (widgetName != null)
        {
            widget = WidgetInfoProvider.GetWidgetInfo(widgetName);
        }

        return((widget != null) && (widget.WidgetName.IndexOf("grouppoll", StringComparison.InvariantCultureIgnoreCase) != -1));
    }
    /// <summary>
    /// Event loaded after ok button clicked.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="e">Event args</param>
    void ucDefaultValueEditor_XMLCreated(object sender, EventArgs e)
    {
        int        widgetID = QueryHelper.GetInteger("widgetID", 0);
        WidgetInfo wi       = WidgetInfoProvider.GetWidgetInfo(widgetID);

        if (wi != null)
        {
            wi.WidgetDefaultValues = ucDefaultValueEditor.DefaultValueXMLDefinition;
            WidgetInfoProvider.SetWidgetInfo(wi);
        }

        // Redirect to apply settings
        string url = URLHelper.RemoveParameterFromUrl(URLRewriter.CurrentURL, "saved");

        url = URLHelper.AddParameterToUrl(url, "saved", "1");
        URLHelper.Redirect(url);
    }
Exemplo n.º 22
0
    /// <summary>
    /// Rturns TRUE if selector is used in group widget.
    /// </summary>
    private bool IsGroupPollWidget()
    {
        int        widgetId   = QueryHelper.GetInteger("widgetid", 0);
        string     widgetName = QueryHelper.GetString("widgetname", null);
        WidgetInfo widget     = null;

        if (widgetId > 0)
        {
            widget = WidgetInfoProvider.GetWidgetInfo(widgetId);
        }
        else if (widgetName != null)
        {
            widget = WidgetInfoProvider.GetWidgetInfo(widgetName);
        }

        return((widget != null) && (widget.WidgetName.IndexOfCSafe("grouppoll", true) != -1));
    }
    /// <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();
        }
    }
    /// <summary>
    /// Creates new widget with setting from parent webpart.
    /// </summary>
    /// <param name="parentWebpartId">ID of parent webpart</param>
    /// <param name="categoryId">ID of parent widget category</param>
    /// <returns>Created widget info</returns>
    private WidgetInfo NewWidget(int parentWebpartId, int categoryId)
    {
        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(parentWebpartId);

        // Widget cannot be created from inherited webpart
        if ((wpi != null) && (wpi.WebPartParentID == 0))
        {
            // Set widget according to parent webpart
            WidgetInfo wi = new WidgetInfo();
            wi.WidgetName                 = FindUniqueWidgetName(wpi.WebPartName, 100);
            wi.WidgetDisplayName          = wpi.WebPartDisplayName;
            wi.WidgetDescription          = wpi.WebPartDescription;
            wi.WidgetDocumentation        = wpi.WebPartDocumentation;
            wi.WidgetSkipInsertProperties = wpi.WebPartSkipInsertProperties;
            wi.WidgetIconClass            = wpi.WebPartIconClass;

            wi.WidgetProperties = FormHelper.GetFormFieldsWithDefaultValue(wpi.WebPartProperties, "visible", "false");

            wi.WidgetWebPartID  = parentWebpartId;
            wi.WidgetCategoryID = categoryId;

            // Save new widget to DB
            WidgetInfoProvider.SetWidgetInfo(wi);

            // Get thumbnail image from webpart
            DataSet ds = MetaFileInfoProvider.GetMetaFiles(wpi.WebPartID, WebPartInfo.OBJECT_TYPE, null, null, null, null, 1);

            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                MetaFileInfo mfi = new MetaFileInfo(ds.Tables[0].Rows[0]);
                mfi.Generalized.EnsureBinaryData();
                mfi.MetaFileID         = 0;
                mfi.MetaFileGUID       = Guid.NewGuid();
                mfi.MetaFileObjectID   = wi.WidgetID;
                mfi.MetaFileObjectType = WidgetInfo.OBJECT_TYPE;

                MetaFileInfoProvider.SetMetaFileInfo(mfi);
            }

            // Return ID of newly created widget
            return(wi);
        }

        return(null);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        int widgetID = QueryHelper.GetInteger("widgetID", 0);

        // Default values XML load
        XmlDocument xmlBefore = new XmlDocument();
        XmlDocument xmlAfter  = new XmlDocument();

        ucDefaultValueEditor.XMLCreated += new EventHandler(ucDefaultValueEditor_XMLCreated);

        // If saved is found in query string
        if (!RequestHelper.IsPostBack() && (QueryHelper.GetInteger("saved", 0) == 1))
        {
            ShowChangesSaved();
        }

        // Load the form definition
        string before = PortalFormHelper.LoadProperties("Widget", "Before.xml");
        string after  = PortalFormHelper.LoadProperties("Widget", "After.xml");

        string formDef = FormHelper.CombineFormDefinitions(before, after);

        // Get the widget info
        WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetID);

        if (wi != null)
        {
            // Load default values for current web part
            XmlDocument xmlDefault = LoadDefaultValuesXML(wi, formDef);

            // Set field editor
            if (wi.WidgetDefaultValues == String.Empty)
            {
                ucDefaultValueEditor.DefaultValueXMLDefinition = "<form></form>";
            }
            else
            {
                // WebPartDefaultValues contains changed fields versus default XML settings (stored in files)
                ucDefaultValueEditor.DefaultValueXMLDefinition = wi.WidgetDefaultValues;
            }

            ucDefaultValueEditor.LoadHiddenFields    = true;
            ucDefaultValueEditor.SourceXMLDefinition = xmlDefault.DocumentElement.OuterXml;
        }
    }
Exemplo n.º 26
0
    /// <summary>
    /// Sets Security level for widget. Called when the "Remove widget to role" button is pressed.
    /// Expects the CreateWidget method to be run first.
    /// </summary>
    private bool SetSecurityLevel()
    {
        // Get widget object
        WidgetInfo widget = WidgetInfoProvider.GetWidgetInfo("MyNewWidget");

        // If widget exists
        if (widget != null)
        {
            // Set security access
            widget.AllowedFor = SecurityAccessEnum.AuthenticatedUsers;

            WidgetInfoProvider.SetWidgetInfo(widget);

            return(true);
        }

        return(false);
    }
Exemplo n.º 27
0
    /// <summary>
    /// Remove widget from role. Called when the "Remove widget to role" button is pressed.
    /// Expects the CreateWidget method to be run first.
    /// </summary>
    private bool RemoveWidgetFromRole()
    {
        // Get role, widget and permission object
        RoleInfo           role       = RoleInfoProvider.GetRoleInfo("CMSDeskAdmin", SiteContext.CurrentSiteID);
        WidgetInfo         widget     = WidgetInfoProvider.GetWidgetInfo("MyNewWidget");
        PermissionNameInfo permission = PermissionNameInfoProvider.GetPermissionNameInfo("AllowedFor", "Widgets", null);

        // If all exist
        if ((role != null) && (widget != null) && (permission != null))
        {
            // Add widget to role
            WidgetRoleInfoProvider.RemoveRoleFromWidget(role.RoleID, widget.WidgetID, permission.PermissionId);

            return(true);
        }

        return(false);
    }
Exemplo n.º 28
0
    /// <summary>
    /// Gets and updates widget. Called when the "Get and update widget" button is pressed.
    /// Expects the CreateWidget method to be run first.
    /// </summary>
    private bool GetAndUpdateWidget()
    {
        // Get the widget
        WidgetInfo updateWidget = WidgetInfoProvider.GetWidgetInfo("MyNewWidget");

        if (updateWidget != null)
        {
            // Update the properties
            updateWidget.WidgetDisplayName = updateWidget.WidgetDisplayName.ToLower();

            // Save the changes
            WidgetInfoProvider.SetWidgetInfo(updateWidget);

            return(true);
        }

        return(false);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        int widgetID = QueryHelper.GetInteger("widgetID", 0);

        // Default values XML load
        XmlDocument xmlBefore = new XmlDocument();
        XmlDocument xmlAfter  = new XmlDocument();

        ucDefaultValueEditor.XMLCreated += new EventHandler(ucDefaultValueEditor_XMLCreated);

        // If saved is found in query string
        if ((!RequestHelper.IsPostBack()) && (QueryHelper.GetInteger("saved", 0) == 1))
        {
            lblInfo.Visible = true;
            lblInfo.Text    = GetString("General.ChangesSaved");
        }

        // Load default values XML files
        xmlBefore.Load(Server.MapPath("~/CMSModules/PortalEngine/UI/WebParts/Properties/WebPart_PropertiesBefore.xml"));
        xmlAfter.Load(Server.MapPath("~/CMSModules/PortalEngine/UI/WebParts/Properties/WebPart_PropertiesAfter.xml"));
        string formDef = FormHelper.CombineFormDefinitions(xmlBefore.DocumentElement.OuterXml, xmlAfter.DocumentElement.OuterXml);

        WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetID);

        if (wi != null)
        {
            // Load default values for current web part
            XmlDocument xmlDefault = LoadDefaultValuesXML(wi, formDef);

            // Set field editor
            if (wi.WidgetDefaultValues == String.Empty)
            {
                ucDefaultValueEditor.DefaultValueXMLDefinition = "<form></form>";
            }
            else
            {
                // WebPartDefaultValues contains changed fields versus default XML settings (stored in files)
                ucDefaultValueEditor.DefaultValueXMLDefinition = wi.WidgetDefaultValues;
            }

            ucDefaultValueEditor.SourceXMLDefinition = xmlDefault.DocumentElement.OuterXml;
        }
    }
Exemplo n.º 30
0
    /// <summary>
    /// Generates HTML text to be used in description area.
    /// </summary>
    ///<param name="selectedValue">Selected item for which generate description</param>
    private string ShowInDescriptionArea(string selectedValue)
    {
        string description = String.Empty;

        if (!String.IsNullOrEmpty(selectedValue))
        {
            int        widgetId = ValidationHelper.GetInteger(selectedValue, 0);
            WidgetInfo wi       = WidgetInfoProvider.GetWidgetInfo(widgetId);
            if (wi != null)
            {
                description = wi.WidgetDescription;
            }
        }

        if (!String.IsNullOrEmpty(description))
        {
            return("<div class=\"Description\">" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(description)) + "</div>");
        }

        return(String.Empty);
    }