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);
                    }
                }
            }
        }
    }
Exemplo n.º 3
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;
        }
    }
    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();
        }
    }
    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.º 6
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.º 7
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);
    }
Exemplo n.º 8
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.º 9
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.º 10
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.º 12
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>
    /// 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>
    /// 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.º 15
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));
    }
    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.º 17
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.º 18
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.º 19
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.º 21
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);
    }
Exemplo n.º 22
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 name        = String.Empty;
        string description = String.Empty;

        if (!String.IsNullOrEmpty(selectedValue))
        {
            int        widgetId = ValidationHelper.GetInteger(selectedValue, 0);
            WidgetInfo wi       = WidgetInfoProvider.GetWidgetInfo(widgetId);
            if (wi != null)
            {
                name        = wi.WidgetDisplayName;
                description = wi.WidgetDescription;
            }
        }
        // No selection show selected category
        else if (SelectedCategory != null)
        {
            name = SelectedCategory.WidgetCategoryDisplayName;
        }
        // Recently used
        else
        {
            name = GetString("widgets.recentlyused");
        }


        string text = "<div class=\"ItemName\">" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(name)) + "</div>";

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

        return(text);
    }
Exemplo n.º 23
0
    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        string widgetId     = QueryHelper.GetString("widgetid", String.Empty);
        string aliasPath    = QueryHelper.GetString("aliasPath", String.Empty);
        int    templateId   = QueryHelper.GetInteger("templateid", 0);
        string zoneId       = QueryHelper.GetString("zoneid", String.Empty);
        Guid   instanceGUID = QueryHelper.GetGuid("instanceguid", Guid.Empty);

        bool   isNewWidget = QueryHelper.GetBoolean("isnew", false);
        bool   inline      = QueryHelper.GetBoolean("inline", false);
        int    variantId   = QueryHelper.GetInteger("variantid", 0);
        string culture     = QueryHelper.GetString("culture", CMSContext.PreferredCultureCode);

        // Set page title
        Page.Title = GetString(isNewWidget ? "widgets.propertiespage.titlenew" : "widgets.propertiespage.title");

        // Resize the header (enlarge) to make a space for the tabs header when displaying a widget variant
        if (variantId > 0)
        {
            rowsFrameset.Attributes.Add("rows", "67, *");
        }

        // Ensure correct view mode
        if (String.IsNullOrEmpty(aliasPath))
        {
            // Ensure the dashboard mode for the dialog
            if (QueryHelper.Contains("dashboard"))
            {
                PortalContext.SetRequestViewMode(ViewModeEnum.DashboardWidgets);
                PortalContext.DashboardName     = QueryHelper.GetString("dashboard", String.Empty);
                PortalContext.DashboardSiteName = QueryHelper.GetString("sitename", String.Empty);
            }
            // Ensure the design mode for the dialog
            else
            {
                PortalContext.SetRequestViewMode(ViewModeEnum.Design);
            }
        }

        if (widgetId != "")
        {
            // Get pageinfo
            PageInfo pi = null;
            try
            {
                pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateId, culture);
            }
            catch (PageNotFoundException)
            {
                // Do not throw exception if page info not found (e.g. bad alias path)
            }

            if (pi == null)
            {
                return;
            }

            // Get template instance
            PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi);

            // Get widget from instance
            WidgetInfo wi = null;
            if (!isNewWidget)
            {
                // Get the instance of widget
                WebPartInstance widgetInstance = templateInstance.GetWebPart(instanceGUID, widgetId);
                if (widgetInstance == null)
                {
                    return;
                }

                // Get widget info by widget name(widget type)
                wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType);
            }
            // Widget instance hasn't created yet
            else
            {
                wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(widgetId, 0));
            }

            if (wi != null)
            {
                WebPartZoneInstance zone = templateInstance.GetZone(zoneId);
                if (zone != null)
                {
                    CurrentUserInfo currentUser = CMSContext.CurrentUser;

                    switch (zone.WidgetZoneType)
                    {
                    // Group zone => Only group widgets and group admin
                    case WidgetZoneTypeEnum.Group:
                        // Should always be, only group widget are allowed in group zone
                        if (!wi.WidgetForGroup || (!currentUser.IsGroupAdministrator(pi.NodeGroupID) && ((CMSContext.ViewMode != ViewModeEnum.Design) || ((CMSContext.ViewMode == ViewModeEnum.Design) && (!currentUser.IsAuthorizedPerResource("CMS.Design", "Design"))))))
                        {
                            RedirectToAccessDenied(GetString("widgets.security.notallowed"));
                        }
                        break;

                    // Widget must be allowed for editor zones
                    case WidgetZoneTypeEnum.Editor:
                        if (!wi.WidgetForEditor)
                        {
                            RedirectToAccessDenied(GetString("widgets.security.notallowed"));
                        }
                        break;

                    // Widget must be allowed for user zones
                    case WidgetZoneTypeEnum.User:
                        if (!wi.WidgetForUser)
                        {
                            RedirectToAccessDenied(GetString("widgets.security.notallowed"));
                        }
                        break;
                    }

                    if ((zone.WidgetZoneType != WidgetZoneTypeEnum.Group) && !WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, currentUser.IsAuthenticated()))
                    {
                        RedirectToAccessDenied(GetString("widgets.security.notallowed"));
                    }
                }

                // If all ok, set up frames
                frameHeader.Attributes.Add("src", "widgetproperties_header.aspx" + URLHelper.Url.Query);
                frameContent.Attributes.Add("src", "widgetproperties_properties_frameset.aspx" + URLHelper.Url.Query);
            }
        }

        frameHeader.Attributes.Add("src", "widgetproperties_header.aspx" + URLHelper.Url.Query);
        if (inline && !isNewWidget)
        {
            frameContent.Attributes.Add("src", ResolveUrl("~/CMSPages/Blank.htm"));
        }
        else
        {
            frameContent.Attributes.Add("src", "widgetproperties_properties_frameset.aspx" + URLHelper.Url.Query);
        }
    }
Exemplo n.º 24
0
    /// <summary>
    /// Adds the inline widget without the properties dialog.
    /// </summary>
    /// <param name="widgetId">The widget id</param>
    private string AddInlineWidgetWithoutDialog(int widgetId)
    {
        string script = string.Empty;

        if (widgetId > 0)
        {
            // New widget - load widget info by id
            WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetId);

            if ((wi != null) && wi.WidgetForInline)
            {
                // Test permission for user
                var currentUser = MembershipContext.AuthenticatedUser;
                if (!WidgetRoleInfoProvider.IsWidgetAllowed(widgetId, currentUser.UserID, AuthenticationHelper.IsAuthenticated()))
                {
                    return(string.Empty);
                }

                // If user is editor, more properties are shown
                WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.User;
                if (currentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Editor, SiteContext.CurrentSiteName))
                {
                    zoneType = WidgetZoneTypeEnum.Editor;
                }

                WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID);

                // Merge the parent web part properties definition with the widget properties definition
                string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties);

                // Create the FormInfo for the current widget properties definition
                FormInfo fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, zoneType, widgetProperties, true);
                DataRow  dr = null;

                if (fi != null)
                {
                    // Get data rows with required columns
                    dr = PortalHelper.CombineWithDefaultValues(fi, wi);

                    // Load default values for new widget
                    fi.LoadDefaultValues(dr, FormResolveTypeEnum.Visible);

                    // Override default value and set title as widget display name
                    DataHelper.SetDataRowValue(dr, "WidgetTitle", wi.WidgetDisplayName);
                }

                // Save inline widget script
                script = PortalHelper.GetAddInlineWidgetScript(wi, dr, fi.GetFields(true, true));

                script += " CloseDialog(false);";

                if (!string.IsNullOrEmpty(script))
                {
                    // Add to recently used widgets collection
                    MembershipContext.AuthenticatedUser.UserSettings.UpdateRecentlyUsedWidget(wi.WidgetName);
                }
            }
        }

        return(script);
    }
    /// <summary>
    /// Initializes menu.
    /// </summary>
    protected void InitalizeMenu()
    {
        string             zoneId       = QueryHelper.GetString("zoneid", string.Empty);
        string             culture      = QueryHelper.GetString("culture", CMSContext.PreferredCultureCode);
        Guid               instanceGuid = QueryHelper.GetGuid("instanceguid", Guid.Empty);
        bool               isNewWidget  = QueryHelper.GetBoolean("isnew", false);
        WidgetZoneTypeEnum zoneType     = WidgetZoneTypeEnum.None;

        if (!String.IsNullOrEmpty(widgetId) || !String.IsNullOrEmpty(widgetName))
        {
            WidgetInfo wi = null;

            // get pageinfo
            PageInfo pi = null;
            try
            {
                pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateId, culture);
            }
            catch (PageNotFoundException)
            {
                // Do not throw exception if page info not found (e.g. bad alias path)
            }

            if (pi == null)
            {
                Visible = false;
                return;
            }

            // Get template instance
            PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi);
            if (templateInstance != null)
            {
                // Get zone type
                WebPartZoneInstance zoneInstance = templateInstance.GetZone(zoneId);

                if (zoneInstance != null)
                {
                    zoneType = zoneInstance.WidgetZoneType;
                }

                // Get web part
                WebPartInstance widget = templateInstance.GetWebPart(instanceGuid, widgetId);

                if ((widget != null) && widget.IsWidget)
                {
                    // WebPartType = codename, get widget by codename
                    wi = WidgetInfoProvider.GetWidgetInfo(widget.WebPartType);
                }
            }

            // New widget
            if (isNewWidget)
            {
                int id = ValidationHelper.GetInteger(widgetId, 0);
                if (id > 0)
                {
                    wi = WidgetInfoProvider.GetWidgetInfo(id);
                }
                else if (!String.IsNullOrEmpty(widgetName))
                {
                    wi = WidgetInfoProvider.GetWidgetInfo(widgetName);
                }
            }

            // Get widget info from name if not found yet
            if ((wi == null) && (!String.IsNullOrEmpty(widgetName)))
            {
                wi = WidgetInfoProvider.GetWidgetInfo(widgetName);
            }

            if (wi != null)
            {
                PageTitle.TitleText = GetString("Widgets.Properties.Title") + " (" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(wi.WidgetDisplayName)) + ")";
            }

            // If no zonetype defined or not inline dont show documentation
            string documentationUrl = String.Empty;
            switch (zoneType)
            {
            case WidgetZoneTypeEnum.Dashboard:
            case WidgetZoneTypeEnum.Editor:
            case WidgetZoneTypeEnum.Group:
            case WidgetZoneTypeEnum.User:
                documentationUrl = ResolveUrl("~/CMSModules/Widgets/LiveDialogs/WidgetDocumentation.aspx");
                break;

            // If no zone set dont create documentation link
            default:
                if (isInline)
                {
                    documentationUrl = ResolveUrl("~/CMSModules/Widgets/Dialogs/WidgetDocumentation.aspx");
                }
                else
                {
                    return;
                }
                break;
            }

            // Generate documentation link
            Literal ltr = new Literal();
            PageTitle.RightPlaceHolder.Controls.Add(ltr);

            // Ensure correct parameters in documentation url
            documentationUrl += URLHelper.GetQuery(URLHelper.CurrentURL);
            if (!String.IsNullOrEmpty(widgetName))
            {
                documentationUrl = URLHelper.UpdateParameterInUrl(documentationUrl, "widgetname", widgetName);
            }
            if (!String.IsNullOrEmpty(widgetId))
            {
                documentationUrl = URLHelper.UpdateParameterInUrl(documentationUrl, "widgetid", widgetId);
            }
            string docScript = "NewWindow('" + documentationUrl + "', 'WebPartPropertiesDocumentation', 800, 800); return false;";

            ltr.Text += "<a onclick=\"" + docScript + "\" href=\"#\"><img src=\"" + ResolveUrl(GetImageUrl("General/HelpLargeDark.png")) + "\" style=\"border-width: 0px;\"></a>";
        }
    }
Exemplo n.º 26
0
    /// <summary>
    /// Loads the widget form.
    /// </summary>
    private void LoadForm()
    {
        // Setup basic form on live site
        formCustom.AllowMacroEditing = false;
        formCustom.IsLiveSite        = IsLiveSite;

        // Load settings
        if (!String.IsNullOrEmpty(Request.Form[hdnIsNewWebPart.UniqueID]))
        {
            IsNewWidget = ValidationHelper.GetBoolean(Request.Form[hdnIsNewWebPart.UniqueID], false);
        }
        if (!String.IsNullOrEmpty(Request.Form[hdnInstanceGUID.UniqueID]))
        {
            InstanceGUID = ValidationHelper.GetGuid(Request.Form[hdnInstanceGUID.UniqueID], Guid.Empty);
        }

        // Try to find the widget variant in the database and set its VariantID
        if (IsNewVariant)
        {
            Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable;
            if (properties != null)
            {
                // Get the variant code name from the WindowHelper
                string variantName = ValidationHelper.GetString(properties["codename"], string.Empty);

                // Check if the variant exists in the database
                int variantIdFromDB = VariantHelper.GetVariantID(VariantMode, PageTemplateId, variantName, false);

                // Set the variant id from the database
                if (variantIdFromDB > 0)
                {
                    VariantID    = variantIdFromDB;
                    IsNewVariant = false;
                }
            }
        }

        EnsureDashboard();

        if (!String.IsNullOrEmpty(WidgetId) && !IsInline)
        {
            if (CurrentPageInfo == null)
            {
                ShowError(GetString("Widgets.Properties.aliasnotfound"));
                pnlFormArea.Visible = false;
                return;
            }

            // Get template instance
            mTemplateInstance = CMSPortalManager.GetTemplateInstanceForEditing(CurrentPageInfo);

            if (!IsNewWidget)
            {
                // Get the instance of widget
                mWidgetInstance = mTemplateInstance.GetWebPart(InstanceGUID, WidgetId);
                if (mWidgetInstance == null)
                {
                    ShowError(GetString("Widgets.Properties.WidgetNotFound"));
                    pnlFormArea.Visible = false;
                    return;
                }

                if ((VariantID > 0) && (mWidgetInstance != null) && (mWidgetInstance.PartInstanceVariants != null))
                {
                    // Check OnlineMarketing permissions.
                    if (CheckPermissions("Read"))
                    {
                        mWidgetInstance = CurrentPageInfo.DocumentTemplateInstance.GetWebPart(InstanceGUID, WidgetId);
                        mWidgetInstance = mWidgetInstance.PartInstanceVariants.Find(v => v.VariantID.Equals(VariantID));
                        // Set the widget variant mode
                        if (mWidgetInstance != null)
                        {
                            VariantMode = mWidgetInstance.VariantMode;
                        }
                    }
                    else
                    {
                        // Not authorized for OnlineMarketing - Manage.
                        RedirectToInformation(String.Format(GetString("general.permissionresource"), "Read", (VariantMode == VariantModeEnum.ContentPersonalization) ? "CMS.ContentPersonalization" : "CMS.MVTest"));
                    }
                }

                // Get widget info by widget name(widget type)
                mWidgetInfo = WidgetInfoProvider.GetWidgetInfo(mWidgetInstance.WebPartType);
            }
            // Widget instance hasn't created yet
            else
            {
                mWidgetInfo = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetId, 0));
            }

            // Keep xml version
            if (mWidgetInstance != null)
            {
                mXmlVersion = mWidgetInstance.XMLVersion;
            }

            UIContext.EditedObject = mWidgetInfo;

            // Get the zone to which it inserts
            WebPartZoneInstance zone = mTemplateInstance.GetZone(ZoneId);
            if ((ZoneType == WidgetZoneTypeEnum.None) && (zone != null))
            {
                ZoneType = zone.WidgetZoneType;
            }

            // Check security
            var currentUser = MembershipContext.AuthenticatedUser;

            switch (ZoneType)
            {
            // Group zone => Only group widgets and group admin
            case WidgetZoneTypeEnum.Group:
                // Should always be, only group widget are allowed in group zone
                if (!mWidgetInfo.WidgetForGroup || (!currentUser.IsGroupAdministrator(CurrentPageInfo.NodeGroupID) && ((PortalContext.ViewMode != ViewModeEnum.Design) || ((PortalContext.ViewMode == ViewModeEnum.Design) && (!currentUser.IsAuthorizedPerResource("CMS.Design", "Design"))))))
                {
                    if (OnNotAllowed != null)
                    {
                        OnNotAllowed(this, null);
                    }
                }
                break;

            // Widget must be allowed for editor zones
            case WidgetZoneTypeEnum.Editor:
                if (!mWidgetInfo.WidgetForEditor)
                {
                    if (OnNotAllowed != null)
                    {
                        OnNotAllowed(this, null);
                    }
                }
                break;

            // Widget must be allowed for user zones
            case WidgetZoneTypeEnum.User:
                if (!mWidgetInfo.WidgetForUser)
                {
                    if (OnNotAllowed != null)
                    {
                        OnNotAllowed(this, null);
                    }
                }
                break;

            // Widget must be allowed for dashboard zones
            case WidgetZoneTypeEnum.Dashboard:
                if (!mWidgetInfo.WidgetForDashboard)
                {
                    if (OnNotAllowed != null)
                    {
                        OnNotAllowed(this, null);
                    }
                }
                break;
            }

            // Check security
            if ((ZoneType != WidgetZoneTypeEnum.Group) && !WidgetRoleInfoProvider.IsWidgetAllowed(mWidgetInfo, currentUser.UserID, AuthenticationHelper.IsAuthenticated()))
            {
                if (OnNotAllowed != null)
                {
                    OnNotAllowed(this, null);
                }
            }

            // Get form schemas
            mWebPartInfo = WebPartInfoProvider.GetWebPartInfo(mWidgetInfo.WidgetWebPartID);
            string   widgetProperties = FormHelper.MergeFormDefinitions(mWebPartInfo.WebPartProperties, mWidgetInfo.WidgetProperties);
            FormInfo fi = PortalFormHelper.GetWidgetFormInfo(mWidgetInfo.WidgetName, ZoneType, widgetProperties, true, mWidgetInfo.WidgetDefaultValues);

            if (fi != null)
            {
                fi.ContextResolver.Settings.RelatedObject = mTemplateInstance;

                // Check if there are some editable properties
                var ffi = fi.GetFields(true, false);
                if ((ffi == null) || (ffi.Count == 0))
                {
                    ShowInformation(GetString("widgets.emptyproperties"));
                }

                DataRow dr = fi.GetDataRow();

                // Load overridden values for new widget
                if (IsNewWidget || (mXmlVersion > 0))
                {
                    fi.LoadDefaultValues(dr, FormResolveTypeEnum.WidgetVisible);
                }

                if (IsNewWidget)
                {
                    // Override default value and set title as widget display name
                    DataHelper.SetDataRowValue(dr, "WidgetTitle", ResHelper.LocalizeString(mWidgetInfo.WidgetDisplayName));
                }

                // Load values from existing widget
                LoadDataRowFromWidget(dr, fi);

                // Init HTML toolbar if exists
                InitHTMLToobar(fi);

                // Init the form
                InitForm(formCustom, dr, fi);

                // Set the context name
                formCustom.ControlContext.ContextName = CMS.Base.Web.UI.ControlContext.WIDGET_PROPERTIES;
            }
        }

        if (IsInline)
        {
            // Load text definition from session
            string definition = ValidationHelper.GetString(SessionHelper.GetValue("WidgetDefinition"), String.Empty);
            if (String.IsNullOrEmpty(definition))
            {
                definition = Request.Form[hdnWidgetDefinition.UniqueID];
            }
            else
            {
                hdnWidgetDefinition.Value = definition;
            }

            Hashtable parameters = null;
            string    widgetName = String.Empty;



            if (IsNewWidget)
            {
                // New widget - load widget info by id
                if (!String.IsNullOrEmpty(WidgetId))
                {
                    mWidgetInfo = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetId, 0));
                }
                else
                {
                    // Try to get widget from codename
                    widgetName  = QueryHelper.GetString("WidgetName", String.Empty);
                    mWidgetInfo = WidgetInfoProvider.GetWidgetInfo(widgetName);
                }
            }
            else
            {
                if (definition == null)
                {
                    DisplayError("widget.failedtoload");
                    return;
                }

                // Parse definition
                parameters = CMSDialogHelper.GetHashTableFromString(definition);

                // Trim control name
                if (parameters["name"] != null)
                {
                    widgetName = parameters["name"].ToString();
                }

                mWidgetInfo = WidgetInfoProvider.GetWidgetInfo(widgetName);
            }
            if (mWidgetInfo == null)
            {
                DisplayError("widget.failedtoload");
                return;
            }

            // If widget cant be used as inline
            if (!mWidgetInfo.WidgetForInline)
            {
                DisplayError("widget.cantbeusedasinline");
                return;
            }


            // Test permission for user
            var currentUser = MembershipContext.AuthenticatedUser;
            if (!WidgetRoleInfoProvider.IsWidgetAllowed(mWidgetInfo, currentUser.UserID, AuthenticationHelper.IsAuthenticated()))
            {
                mIsValidWidget = false;
                OnNotAllowed(this, null);
            }

            // If user is editor, more properties are shown
            WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.User;
            if (currentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Editor, SiteContext.CurrentSiteName))
            {
                zoneType = WidgetZoneTypeEnum.Editor;
            }

            WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(mWidgetInfo.WidgetWebPartID);
            string      widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, mWidgetInfo.WidgetProperties);
            FormInfo    fi = PortalFormHelper.GetWidgetFormInfo(mWidgetInfo.WidgetName, zoneType, widgetProperties, true, mWidgetInfo.WidgetDefaultValues);
            if (fi != null)
            {
                // Check if there are some editable properties
                mFields = fi.GetFields(true, true);
                if ((mFields == null) || !mFields.Any())
                {
                    ShowInformation(GetString("widgets.emptyproperties"));
                }

                // Get datarows with required columns
                DataRow dr = PortalHelper.CombineWithDefaultValues(fi, mWidgetInfo);

                if (IsNewWidget)
                {
                    // Load default values for new widget
                    fi.LoadDefaultValues(dr, FormResolveTypeEnum.WidgetVisible);
                }
                else
                {
                    foreach (string key in parameters.Keys)
                    {
                        object value = parameters[key];
                        // Test if given property exists
                        if (dr.Table.Columns.Contains(key) && (value != null))
                        {
                            try
                            {
                                dr[key] = DataHelper.ConvertValue(value, dr.Table.Columns[key].DataType);
                            }
                            catch
                            {
                            }
                        }
                    }
                }

                // Override default value and set title as widget display name
                DataHelper.SetDataRowValue(dr, "WidgetTitle", mWidgetInfo.WidgetDisplayName);

                // Init HTML toolbar if exists
                InitHTMLToobar(fi);

                // Init the form
                InitForm(formCustom, dr, fi);

                // Set the context name
                formCustom.ControlContext.ContextName = CMS.Base.Web.UI.ControlContext.WIDGET_PROPERTIES;
            }
        }
    }
Exemplo n.º 27
0
    protected void Page_Load(object sender, EventArgs e)
    {
        StringSafeDictionary <object> decodedProperties = new StringSafeDictionary <object>();

        foreach (DictionaryEntry param in Properties)
        {
            // Decode special CK editor char
            String str = String.Empty;
            if (param.Value != null)
            {
                str = param.Value.ToString().Replace("%25", "%");
            }

            decodedProperties[(string)param.Key] = HttpUtility.UrlDecode(str);
        }
        Properties = decodedProperties;

        string widgetName = ValidationHelper.GetString(Properties["name"], String.Empty);

        // Widget name must be specified
        if (String.IsNullOrEmpty(widgetName))
        {
            AddErrorWebPart("widgets.invalidname", null);
            return;
        }

        WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetName);

        if (wi == null)
        {
            AddErrorWebPart("widget.failedtoload", null);
            return;
        }

        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID);

        if (wpi == null)
        {
            return;
        }

        //no widgets can be used as inline
        if (!wi.WidgetForInline)
        {
            AddErrorWebPart("widgets.cantbeusedasinline", null);
            return;
        }

        try
        {
            FormInfo fi = null;
            DataRow  dr = null;

            using (var cs = new CachedSection <FormInfo>(ref fi, 1440, (PortalContext.ViewMode == ViewModeEnum.LiveSite), null, "inlinewidgetcontrol", wi.WidgetID, wpi.WebPartID))
            {
                if (cs.LoadData)
                {
                    // Merge widget and it's parent webpart properties
                    string props = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties);

                    // Prepare form
                    const WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.Editor;
                    fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, zoneType, props, true, wi.WidgetDefaultValues);

                    // Apply changed values
                    dr = fi.GetDataRow();
                    fi.LoadDefaultValues(dr);

                    if (cs.Cached)
                    {
                        cs.CacheDependency = CacheHelper.GetCacheDependency("cms.webpart|byid|" + wpi.WebPartID + "\n" + "cms.widget|byid|" + wi.WidgetID);
                    }

                    cs.Data = fi;
                }
            }

            // Get datarow
            if (dr == null)
            {
                dr = fi.GetDataRow();
                fi.LoadDefaultValues(dr);
            }

            // Incorporate inline parameters to datarow
            string publicFields = ";containertitle;container;";
            if (wi.WidgetPublicFileds != null)
            {
                publicFields += ";" + wi.WidgetPublicFileds.ToLowerCSafe() + ";";
            }

            // Load the widget control
            string url = null;

            // Set widget layout
            WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wi.WidgetLayoutID);

            if (wpli != null)
            {
                // Load specific layout through virtual path
                url = wpli.Generalized.GetVirtualFileRelativePath(WebPartLayoutInfo.EXTERNAL_COLUMN_CODE, wpli.WebPartLayoutVersionGUID);
            }
            else
            {
                // Load regularly
                url = WebPartInfoProvider.GetWebPartUrl(wpi, false);
            }

            CMSAbstractWebPart control = (CMSAbstractWebPart)Page.LoadUserControl(url);
            control.PartInstance = new WebPartInstance();

            // Use current page placeholder
            control.PagePlaceholder = PortalHelper.FindParentPlaceholder(this);

            // Set all form values to webpart
            foreach (DataColumn column in dr.Table.Columns)
            {
                object value      = dr[column];
                string columnName = column.ColumnName.ToLowerCSafe();

                //Resolve set values by user
                if (Properties.Contains(columnName))
                {
                    FormFieldInfo ffi = fi.GetFormField(columnName);
                    if ((ffi != null) && ffi.Visible && ((ffi.DisplayIn == null) || !ffi.DisplayIn.Contains(FormInfo.DISPLAY_CONTEXT_DASHBOARD)))
                    {
                        value = Properties[columnName];
                    }
                }

                // Resolve macros in defined in default values
                if (!String.IsNullOrEmpty(value as string))
                {
                    // Do not resolve macros for public fields
                    if (publicFields.IndexOfCSafe(";" + columnName + ";") < 0)
                    {
                        // Check whether current column
                        bool avoidInjection = control.SQLProperties.Contains(";" + columnName + ";");

                        // Resolve macros
                        MacroSettings settings = new MacroSettings()
                        {
                            AvoidInjection = avoidInjection,
                        };
                        value = control.ContextResolver.ResolveMacros(value.ToString(), settings);
                    }
                }

                control.PartInstance.SetValue(column.ColumnName, value);
            }

            control.PartInstance.IsWidget = true;

            // Load webpart content
            control.OnContentLoaded();

            // Add webpart to controls collection
            Controls.Add(control);

            // Handle DisableViewstate setting
            control.EnableViewState = !control.DisableViewState;
        }

        catch (Exception ex)
        {
            AddErrorWebPart("widget.failedtoload", ex);
        }
    }
Exemplo n.º 28
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Hashtable decodedProperties = new Hashtable();

        foreach (DictionaryEntry param in mProperties)
        {
            // Decode special CK editor char
            String str = String.Empty;
            if (param.Value != null)
            {
                str = param.Value.ToString().Replace("%25", "%");
            }

            decodedProperties[param.Key] = HttpUtility.UrlDecode(str);
        }
        mProperties = decodedProperties;

        string widgetName = ValidationHelper.GetString(mProperties["name"], String.Empty);

        // Widget name must be specified
        if (String.IsNullOrEmpty(widgetName))
        {
            AddErrorWebPart("widgets.invalidname", null);
            return;
        }

        WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetName);

        if (wi == null)
        {
            AddErrorWebPart("widget.failedtoload", null);
            return;
        }

        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID);

        if (wpi == null)
        {
            return;
        }

        //no widgets can be used as inline
        if (!wi.WidgetForInline)
        {
            AddErrorWebPart("widgets.cantbeusedasinline", null);
            return;
        }

        try
        {
            // Merge widget and it's parent webpart properties
            string properties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties);

            // Prepare form
            WidgetZoneTypeEnum zoneType           = WidgetZoneTypeEnum.Editor;
            FormInfo           zoneTypeDefinition = PortalHelper.GetPositionFormInfo(zoneType);
            FormInfo           fi = FormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), properties, zoneTypeDefinition, true);

            // Apply changed values
            DataRow dr = fi.GetDataRow();
            fi.LoadDefaultValues(dr);

            // Incorporate inline parameters to datarow
            string publicFields = ";containertitle;container;";
            if (wi.WidgetPublicFileds != null)
            {
                publicFields += ";" + wi.WidgetPublicFileds.ToLower() + ";";
            }

            // Load the webpart(widget) control
            string url = WebPartInfoProvider.GetWebPartUrl(wpi, false);

            CMSAbstractWebPart control = (CMSAbstractWebPart)Page.LoadControl(url);
            control.PartInstance = new WebPartInstance();

            // Set all form values to webpart
            foreach (DataColumn column in dr.Table.Columns)
            {
                object value      = dr[column];
                string columnName = column.ColumnName.ToLower();

                //Resolve set values by user
                if (mProperties.Contains(columnName))
                {
                    FormFieldInfo ffi = fi.GetFormField(columnName);
                    if ((ffi != null) && ffi.Visible && (!ffi.DisplayIn.Contains(FormInfo.DISPLAY_CONTEXT_DASHBOARD)))
                    {
                        value = mProperties[columnName];
                    }
                }

                // Resolve macros in defined in default values
                if (!String.IsNullOrEmpty(value as string))
                {
                    // Do not resolve macros for public fields
                    if (publicFields.IndexOf(";" + columnName + ";") < 0)
                    {
                        // Check whether current column
                        bool avoidInjection = control.SQLProperties.Contains(";" + columnName + ";");

                        // Resolve macros
                        value = control.ContextResolver.ResolveMacros(value.ToString(), avoidInjection);
                    }
                }

                control.PartInstance.SetValue(column.ColumnName, value);
            }

            // Load webpart content
            control.OnContentLoaded();

            // Add webpart to controls collection
            this.Controls.Add(control);
        }

        catch (Exception ex)
        {
            AddErrorWebPart("widget.failedtoload", ex);
        }
    }
Exemplo n.º 29
0
    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        // Public user is not allowed for widgets
        if (!AuthenticationHelper.IsAuthenticated())
        {
            RedirectToAccessDenied(GetString("widgets.security.notallowed"));
        }

        var viewMode = ViewModeCode.FromString(QueryHelper.GetString("viewmode", String.Empty));
        var hash     = QueryHelper.GetString("hash", String.Empty);

        LiveSiteWidgetsParameters dialogparameters = new LiveSiteWidgetsParameters(aliasPath, viewMode)
        {
            ZoneId         = zoneId,
            ZoneType       = zoneType,
            InstanceGuid   = instanceGuid,
            TemplateId     = templateId,
            IsInlineWidget = inline
        };

        if (!dialogparameters.ValidateHash(hash))
        {
            return;
        }

        // Set page title
        Page.Title = GetString(isNewWidget ? "widgets.propertiespage.titlenew" : "widgets.propertiespage.title");

        if ((widgetId != string.Empty) && (aliasPath != string.Empty))
        {
            // Get page info
            var      siteName = SiteContext.CurrentSiteName;
            PageInfo pi       = PageInfoProvider.GetPageInfo(siteName, aliasPath, LocalizationContext.PreferredCultureCode, null, SiteInfoProvider.CombineWithDefaultCulture(siteName));

            if (pi == null)
            {
                return;
            }

            // Get template instance
            PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi);

            // Get widget from instance
            WidgetInfo wi = null;
            if (!isNewWidget)
            {
                // Get the instance of widget
                WebPartInstance widgetInstance = templateInstance.GetWebPart(instanceGuid, widgetId);
                if (widgetInstance == null)
                {
                    return;
                }

                // Get widget info by widget name(widget type)
                wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType);
            }
            // Widget instance hasn't created yet
            else
            {
                wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(widgetId, 0));
            }


            if (wi != null)
            {
                WebPartZoneInstance zone = templateInstance.GetZone(zoneId);
                if (zone != null)
                {
                    var currentUser = MembershipContext.AuthenticatedUser;

                    bool checkSecurity = true;

                    // Check security
                    // It is group zone type but widget is not allowed in group
                    if (zone.WidgetZoneType == WidgetZoneTypeEnum.Group)
                    {
                        // Should always be, only group widget are allowed in group zone
                        if (wi.WidgetForGroup)
                        {
                            if (!currentUser.IsGroupAdministrator(pi.NodeGroupID))
                            {
                                RedirectToAccessDenied(GetString("widgets.security.notallowed"));
                            }

                            // All ok, don't check classic security
                            checkSecurity = false;
                        }
                    }

                    if (checkSecurity && !WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, AuthenticationHelper.IsAuthenticated()))
                    {
                        RedirectToAccessDenied(GetString("widgets.security.notallowed"));
                    }
                }
            }
        }
        // If all ok, set up frames
        rowsFrameset.Attributes.Add("rows", string.Format("{0}, *", TitleOnlyHeight));

        frameHeader.Attributes.Add("src", "widgetproperties_header.aspx" + RequestContext.CurrentQueryString);
        if (inline && !isNewWidget)
        {
            frameContent.Attributes.Add("src", ResolveUrl("~/CMSPages/Blank.htm"));
        }
        else
        {
            frameContent.Attributes.Add("src", "widgetproperties_properties_frameset.aspx" + RequestContext.CurrentQueryString);
        }
    }
Exemplo n.º 30
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();
    }