/// <summary>
    /// Initializes menu.
    /// </summary>
    protected void InitalizeMenu()
    {
        if (!String.IsNullOrEmpty(widgetId) || !String.IsNullOrEmpty(widgetName))
        {
            WidgetInfo wi = null;

            // Get page info
            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 zone type defined or not inline => do not 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 => do not create documentation link
            default:
                if (inline)
                {
                    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(RequestContext.CurrentURL);
            if (wi != null)
            {
                documentationUrl = URLHelper.UpdateParameterInUrl(documentationUrl, "widgetid", wi.WidgetID.ToString());
            }

            string docScript = "NewWindow('" + documentationUrl + "', 'WebPartPropertiesDocumentation', 800, 800); return false;";
            string tooltip   = GetString("help.tooltip");
            ltr.Text += String.Format
                            ("<div class=\"action-button\"><a onclick=\"{0}\" href=\"#\"><span class=\"sr-only\">{1}</span><i class=\"icon-modal-question cms-icon-80\" title=\"{1}\" aria-hidden=\"true\"></i></a></div>",
                            docScript, tooltip);
        }
    }
    /// <summary>
    /// Initializes menu.
    /// </summary>
    protected void InitalizeMenu()
    {
        string             zoneId      = QueryHelper.GetString("zoneid", "");
        string             culture     = QueryHelper.GetString("culture", CMSContext.PreferredCultureCode);
        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;
                }
                if (!isNewWidget)
                {
                    // 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);

                        // Set the variant mode (MVT/Content personalization)
                        variantMode = widget.VariantMode;
                    }
                }
            }
            // 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)) + ")";
            }

            // Use live or non live dialogs
            string documentationUrl = String.Empty;

            // If no zonetype defined or not inline dont show documentation
            switch (zoneType)
            {
            case WidgetZoneTypeEnum.Dashboard:
            case WidgetZoneTypeEnum.Editor:
            case WidgetZoneTypeEnum.Group:
            case WidgetZoneTypeEnum.User:
                documentationUrl = ResolveUrl("~/CMSModules/Widgets/Dialogs/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>";

            tabsElem.OnTabCreated           += tabElem_OnTabCreated;
            tabsElem.UrlTarget               = "widgetpropertiescontent";
            tabsElem.OpenTabContentAfterLoad = !isInline;
        }
    }
예제 #3
0
    protected override void OnLoad(EventArgs e)
    {
        plImg  = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/plus.png");
        minImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/minus.png");

        if (WebpartID != String.Empty)
        {
            wpi = WebPartInfoProvider.GetWebPartInfo(WebpartID);
        }


        // Ensure correct view mode
        if (String.IsNullOrEmpty(AliasPath))
        {
            // Ensure the dashboard mode for the dialog
            if (!string.IsNullOrEmpty(DashboardName))
            {
                PortalContext.SetRequestViewMode(ViewModeEnum.DashboardWidgets);
                PortalContext.DashboardName     = DashboardName;
                PortalContext.DashboardSiteName = DashboardSiteName;
            }
            // Ensure the design mode for the dialog
            else
            {
                PortalContext.SetRequestViewMode(ViewModeEnum.Design);
            }
        }

        if (WidgetID != String.Empty)
        {
            PageInfo pi = null;
            try
            {
                // Load page info from alias path and page template
                pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateID, CultureCode);
            }
            catch (PageNotFoundException)
            {
                // Do not throw exception if page info not found (e.g. bad alias path)
            }

            if (pi != null)
            {
                PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi);

                if (templateInstance != null)
                {
                    // Get the instance of widget
                    WebPartInstance widgetInstance = templateInstance.GetWebPart(InstanceGUID, WidgetID);

                    // Info for zone type
                    WebPartZoneInstance zone = templateInstance.GetZone(ZoneID);

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

                    if (widgetInstance != null)
                    {
                        // Create widget from webpart instance
                        wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType);
                    }
                }
            }

            // If inline widget display columns as in editor zone
            if (IsInline)
            {
                zoneType = WidgetZoneTypeEnum.Editor;
            }


            // If no zone set (only global admins allowed to continue)
            if (zoneType == WidgetZoneTypeEnum.None)
            {
                if (!CMSContext.CurrentUser.UserSiteManagerAdmin)
                {
                    RedirectToAccessDenied(GetString("attach.actiondenied"));
                }
            }

            // If wi is still null (new item f.e.)
            if (wi == null)
            {
                // Try to get widget info directly by ID
                if (!IsNew)
                {
                    wi = WidgetInfoProvider.GetWidgetInfo(WidgetID);
                }
                else
                {
                    wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetID, 0));
                }
            }
        }

        String itemDescription   = String.Empty;
        String itemType          = String.Empty;
        String itemDisplayName   = String.Empty;
        String itemDocumentation = String.Empty;
        int    itemID            = 0;

        // Check whether webpart was found
        if (wpi != null)
        {
            itemDescription   = wpi.WebPartDescription;
            itemType          = PortalObjectType.WEBPART;
            itemID            = wpi.WebPartID;
            itemDisplayName   = wpi.WebPartDisplayName;
            itemDocumentation = wpi.WebPartDocumentation;
        }
        // Or widget was found
        else if (wi != null)
        {
            itemDescription   = wi.WidgetDescription;
            itemType          = PortalObjectType.WIDGET;
            itemID            = wi.WidgetID;
            itemDisplayName   = wi.WidgetDisplayName;
            itemDocumentation = wi.WidgetDocumentation;
        }

        if ((wpi != null) || (wi != null))
        {
            // Get WebPart (widget) image
            DataSet ds = MetaFileInfoProvider.GetMetaFiles(itemID, itemType);

            // Set image url of exists
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                MetaFileInfo mtfi = new MetaFileInfo(ds.Tables[0].Rows[0]);
                if (mtfi != null)
                {
                    if (mtfi.MetaFileImageWidth > 385)
                    {
                        imgTeaser.Width = 385;
                    }

                    imgTeaser.ImageUrl = ResolveUrl("~/CMSPages/GetMetaFile.aspx?fileguid=" + mtfi.MetaFileGUID.ToString());
                }
            }
            else
            {
                // Set default image
                imgTeaser.ImageUrl = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/imagenotavailable.png");
            }

            // Additional image information
            imgTeaser.ToolTip       = HTMLHelper.HTMLEncode(itemDisplayName);
            imgTeaser.AlternateText = HTMLHelper.HTMLEncode(itemDisplayName);

            // Set description of webpart
            ltlDescription.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(itemDescription));

            // Get description from parent weboart if webpart is inherited
            if ((wpi != null) && (string.IsNullOrEmpty(wpi.WebPartDescription) && (wpi.WebPartParentID > 0)))
            {
                WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID);
                if (pwpi != null)
                {
                    ltlDescription.Text = HTMLHelper.HTMLEncode(pwpi.WebPartDescription);
                }
            }

            FormInfo fi = null;

            // Generate properties
            if (wpi != null)
            {
                // Get form info from parent if webpart is inherited
                if (wpi.WebPartParentID != 0)
                {
                    WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID);
                    if (pwpi != null)
                    {
                        fi = GetWebPartProperties(pwpi);
                    }
                }
                else
                {
                    fi = GetWebPartProperties(wpi);
                }
            }
            else if (wi != null)
            {
                fi = GetWidgetProperties(wi);
            }

            // Generate properties
            if (fi != null)
            {
                GenerateProperties(fi);
            }

            // Generate documentation text
            if (itemDocumentation == null || itemDocumentation.Trim() == "")
            {
                if ((wpi != null) && (wpi.WebPartParentID != 0))
                {
                    WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID);
                    if (pwpi != null && pwpi.WebPartDocumentation.Trim() != "")
                    {
                        ltlContent.Text = HTMLHelper.ResolveUrls(pwpi.WebPartDocumentation, null);
                    }
                    else
                    {
                        ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />";
                    }
                }
                else
                {
                    ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />";
                }
            }
            else
            {
                ltlContent.Text = HTMLHelper.ResolveUrls(itemDocumentation, null);
            }
        }
        ScriptHelper.RegisterJQuery(Page);

        string script = @"
$j(document.body).ready(initializeResize);
           
function initializeResize ()  { 
    resizeareainternal();
    $j(window).resize(function() { resizeareainternal(); });
}

function resizeareainternal () {
    var height = document.body.clientHeight ; 
    var panel = document.getElementById ('" + divScrolable.ClientID + @"');
                
    // Get parent footer to count proper height (with padding included)
    var footer = $j('.PageFooterLine');                      
    panel.style.height = (height - footer.outerHeight() - panel.offsetTop) +'px';                  
}";

        ScriptHelper.RegisterClientScriptBlock(Page, typeof(Page), "mainScript", ScriptHelper.GetScript(script));

        string[,] tabs = new string[4, 4];
        tabs[0, 0]     = GetString("webparts.documentation");
        tabs[1, 0]     = GetString("general.properties");

        tabControlElem.Tabs        = tabs;
        tabControlElem.UsePostback = true;

        // Disable caching
        Response.Cache.SetNoStore();

        base.OnLoad(e);
    }
    /// <summary>
    /// OnInit event (BasicForm initialization).
    /// </summary>
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        string zoneId     = QueryHelper.GetString("zoneid", "");
        string aliasPath  = QueryHelper.GetString("aliaspath", "");
        int    templateId = QueryHelper.GetInteger("templateid", 0);
        string culture    = QueryHelper.GetString("culture", LocalizationContext.PreferredCultureCode);

        mZoneVariantID = QueryHelper.GetInteger("variantid", 0);
        mIsNewVariant  = QueryHelper.GetBoolean("isnewvariant", false);
        variantMode    = VariantModeFunctions.GetVariantModeEnum(QueryHelper.GetString("variantmode", string.Empty));

        // When displaying an existing variant of a web part, get the variant mode for its original web part
        if (ZoneVariantID > 0)
        {
            PageTemplateInfo pti = PageTemplateInfoProvider.GetPageTemplateInfo(templateId);
            if ((pti != null) && ((pti.TemplateInstance != null)))
            {
                // Get the original webpart and retrieve its variant mode
                WebPartZoneInstance zoneInstance = pti.TemplateInstance.GetZone(zoneId);
                if ((zoneInstance != null) && (zoneInstance.VariantMode != VariantModeEnum.None))
                {
                    variantMode = zoneInstance.VariantMode;
                }
            }
        }

        // Try to find the zone 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, templateId, variantName, true);

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

        if (!String.IsNullOrEmpty(zoneId))
        {
            // Get page info
            pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateId, culture);
            if (pi == null)
            {
                ShowInformation(GetString("webpartzone.notfound"));
                pnlFormArea.Visible = false;
                return;
            }

            // Get template
            pti = pi.UsedPageTemplateInfo;
            if (pti != null)
            {
                // Get web part zone
                pti.TemplateInstance.EnsureZone(zoneId);
                webPartZone = pti.TemplateInstance.GetZone(zoneId);

                if ((ZoneVariantID > 0) && (webPartZone != null) && (webPartZone.ZoneInstanceVariants != null))
                {
                    // Check OnlineMarketing permissions
                    if (CheckPermissions("Read"))
                    {
                        webPartZone = webPartZone.ZoneInstanceVariants.Find(v => v.VariantID.Equals(ZoneVariantID));
                    }
                    else
                    {
                        // Not authorized for OnlineMarketing - Manage.
                        RedirectToInformation(String.Format(GetString("general.permissionresource"), "Read", (variantMode == VariantModeEnum.ContentPersonalization) ? "CMS.ContentPersonalization" : "CMS.MVTest"));
                    }
                }
                if (webPartZone == null)
                {
                    ShowInformation(GetString("webpartzone.notfound"));
                    pnlFormArea.Visible = false;
                    return;
                }

                FormInfo fi = BuildFormInfo(webPartZone);

                // Get the DataRow and fill the data row with values
                DataRow dr = fi.GetDataRow();
                foreach (DataColumn column in dr.Table.Columns)
                {
                    try
                    {
                        DataHelper.SetDataRowValue(dr, column.ColumnName, webPartZone.GetValue(column.ColumnName));
                    }
                    catch
                    {
                    }
                }

                // Initialize Form
                formElem.DataRow              = dr;
                formElem.MacroTable           = webPartZone.MacroTable;
                formElem.SubmitButton.Visible = false;
                formElem.SiteName             = SiteContext.CurrentSiteName;
                formElem.FormInformation      = fi;
                formElem.ShowPrivateFields    = true;
                formElem.OnAfterDataLoad     += formElem_OnAfterDataLoad;

                // HTML editor toolbar
                if (fi.UsesHtmlArea())
                {
                    plcToolbarPadding.Visible = true;
                    plcToolbar.Visible        = true;
                    pnlFormArea.Height        = 285;
                }
            }
        }
    }
예제 #5
0
    /// <summary>
    /// Handles form's after data load event.
    /// </summary>
    protected void EditForm_OnAfterDataLoad(object sender, EventArgs e)
    {
        etaCode.Language = LanguageEnum.HTML;

        cssLayoutEditor.Editor.Language      = LanguageEnum.CSS;
        cssLayoutEditor.Editor.ShowBookmarks = true;

        // Do not check changes
        DocumentManager.RegisterSaveChangesScript = false;

        EditForm.OnBeforeSave += EditForm_OnBeforeSave;

        etaCode.Language = LanguageEnum.HTML;

        wpli = UIContext.EditedObject as WebPartLayoutInfo;

        layoutID = QueryHelper.GetInteger("layoutid", 0);

        isSiteManager = ((MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin) && layoutID != 0) || QueryHelper.GetBoolean("sitemanager", false));
        isNew         = (LayoutCodeName == "|new|");
        isDefault     = (LayoutCodeName == "|default|") || (!isSiteManager && string.IsNullOrEmpty(LayoutCodeName));

        if ((wpli == null) || (wpli.WebPartLayoutID <= 0))
        {
            isNew |= isSiteManager;
            editMenuElem.ObjectManager.ObjectType = WebPartLayoutInfo.OBJECT_TYPE;
        }

        ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "PreviewHierarchyPerformAction", ScriptHelper.GetScript("function actionPerformed(action) { if (action == 'saveandclose') { document.getElementById('" + hdnClose.ClientID + "').value = '1'; } " + editMenuElem.ObjectManager.GetJSFunction(ComponentEvents.SAVE, null, null) + "; }"));

        currentUser = MembershipContext.AuthenticatedUser;

        // Get web part instance (if edited in administration)
        if ((webpartId != "") && !isSiteManager)
        {
            // Get page info
            pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateId, culture);
            if (pi == null)
            {
                ShowInformation(GetString("WebPartProperties.WebPartNotFound"), persistent: false);
            }
            else
            {
                // Get page template
                pti = pi.UsedPageTemplateInfo;
                if ((pti != null) && ((pti.TemplateInstance != null)))
                {
                    webPart = pti.TemplateInstance.GetWebPart(instanceGuid, zoneVariantId, variantId) ?? pti.TemplateInstance.GetWebPart(webpartId);
                }
            }
        }

        // If the web part is not found, try web part ID
        if (webPart == null)
        {
            wpi = WebPartInfoProvider.GetWebPartInfo(ValidationHelper.GetInteger(webpartId, 0));
            if (wpi == null)
            {
                ShowError(GetString("WebPartProperties.WebPartNotFound"));
                startWithFullScreen = false;
                return;
            }
        }
        else
        {
            // CMS desk
            wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
            if (string.IsNullOrEmpty(LayoutCodeName))
            {
                // Get the current layout name
                LayoutCodeName = ValidationHelper.GetString(webPart.GetValue("WebPartLayout"), "");
            }
        }

        if (wpi != null)
        {
            // Load the web part information
            webPartInfo = wpi;
            bool loaded = false;

            if (!RequestHelper.IsPostBack())
            {
                if (wpli != null)
                {
                    editMenuElem.MenuPanel.Visible = true;

                    // Read-only code text area
                    etaCode.Editor.ReadOnly = false;
                    loaded = true;
                }

                if (!loaded)
                {
                    string fileName = WebPartInfoProvider.GetFullPhysicalPath(webPartInfo);

                    // Check if filename exist
                    if (!FileHelper.FileExists(fileName))
                    {
                        ShowError(GetString("WebPartProperties.FileNotExist"));
                        pnlContent.Visible = false;
                        editMenuElem.ObjectEditMenu.Visible = false;
                    }
                    else
                    {
                        // Load default web part layout code
                        etaCode.Text = File.ReadAllText(Server.MapPath(fileName));

                        // Load default web part CSS
                        cssLayoutEditor.Text = wpi.WebPartCSS;
                        startWithFullScreen  = false;
                    }
                }
            }
        }

        if (((wpli == null) || (wpli.WebPartLayoutID <= 0)) && isSiteManager)
        {
            editMenuElem.Title.Breadcrumbs.AddBreadcrumb(new BreadcrumbItem
            {
                Text        = GetString("WebParts.Layout"),
                RedirectUrl = String.Format("{0}&parentobjectid={1}&displaytitle={2}", UIContextHelper.GetElementUrl("CMS.Design", "WebPart.Layout"), QueryHelper.GetInteger("webpartid", 0), false)
            });

            editMenuElem.Title.Breadcrumbs.AddBreadcrumb(new BreadcrumbItem
            {
                Text = GetString("webparts_layout_newlayout"),
            });
        }

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ApplyButton", ScriptHelper.GetScript(
                                                   "function SetRefresh(refreshpage) { document.getElementById('" + hidRefresh.ClientID + @"').value = refreshpage; }
             function OnApplyButton(refreshpage) { SetRefresh(refreshpage); actionPerformed('save');refreshPreview(); }  
             function OnOKButton(refreshpage) { SetRefresh(refreshpage); actionPerformed('saveandclose'); } "));

        InitLayoutForm();
    }
    protected override void OnLoad(EventArgs e)
    {
        plImg  = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/plus.png");
        minImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/minus.png");

        if (WebpartID != String.Empty)
        {
            wpi = WebPartInfoProvider.GetWebPartInfo(WebpartID);
        }


        // Ensure correct view mode
        if (String.IsNullOrEmpty(AliasPath))
        {
            // Ensure the dashboard mode for the dialog
            if (!string.IsNullOrEmpty(DashboardName))
            {
                PortalContext.SetRequestViewMode(ViewModeEnum.DashboardWidgets);
                PortalContext.DashboardName     = DashboardName;
                PortalContext.DashboardSiteName = DashboardSiteName;
            }
            // Ensure the design mode for the dialog
            else
            {
                PortalContext.SetRequestViewMode(ViewModeEnum.Design);
            }
        }

        if (WidgetID != 0)
        {
            PageInfo pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateID, CultureCode);

            if (pi != null)
            {
                PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi);

                if (templateInstance != null)
                {
                    // Get the instance of widget
                    WebPartInstance widgetInstance = templateInstance.GetWebPart(InstanceGUID);

                    // Info for zone type
                    WebPartZoneInstance zone = templateInstance.GetZone(ZoneID);

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

                    if (widgetInstance != null)
                    {
                        // Create widget from webpart instance
                        wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType);
                    }
                }
            }

            // If inline widget display columns as in editor zone
            if (IsInline)
            {
                zoneType = WidgetZoneTypeEnum.Editor;
            }


            // If no zone set (only global admins allowed to continue)
            if (zoneType == WidgetZoneTypeEnum.None)
            {
                if (!MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin))
                {
                    RedirectToAccessDenied(GetString("attach.actiondenied"));
                }
            }

            // If wi is still null (new item f.e.)
            if (wi == null)
            {
                // Try to get widget info directly by ID
                wi = WidgetInfoProvider.GetWidgetInfo(WidgetID);
            }
        }

        String itemDescription   = String.Empty;
        String itemType          = String.Empty;
        String itemDisplayName   = String.Empty;
        String itemDocumentation = String.Empty;
        String itemIcon          = String.Empty;
        int    itemID            = 0;

        // Check whether webpart was found
        if (wpi != null)
        {
            itemDescription   = wpi.WebPartDescription;
            itemType          = WebPartInfo.OBJECT_TYPE;
            itemID            = wpi.WebPartID;
            itemDisplayName   = wpi.WebPartDisplayName;
            itemDocumentation = wpi.WebPartDocumentation;

            itemIcon = PortalHelper.GetIconHtml(wpi.WebPartThumbnailGUID, wpi.WebPartIconClass ?? PortalHelper.DefaultWebPartIconClass);
        }
        // Or widget was found
        else if (wi != null)
        {
            itemDescription   = wi.WidgetDescription;
            itemType          = WidgetInfo.OBJECT_TYPE;
            itemID            = wi.WidgetID;
            itemDisplayName   = wi.WidgetDisplayName;
            itemDocumentation = wi.WidgetDocumentation;
            itemIcon          = PortalHelper.GetIconHtml(wi.WidgetThumbnailGUID, wi.WidgetIconClass ?? PortalHelper.DefaultWidgetIconClass);
        }

        if ((wpi != null) || (wi != null))
        {
            // Get WebPart (widget) icon
            ltrImage.Text = itemIcon;

            // Set description of webpart
            ltlDescription.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(itemDescription));

            // Get description from parent weboart if webpart is inherited
            if ((wpi != null) && (string.IsNullOrEmpty(wpi.WebPartDescription) && (wpi.WebPartParentID > 0)))
            {
                WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID);
                if (pwpi != null)
                {
                    ltlDescription.Text = HTMLHelper.HTMLEncode(pwpi.WebPartDescription);
                }
            }

            FormInfo fi = null;

            // Generate properties
            if (wpi != null)
            {
                // Get form info from parent if webpart is inherited
                if (wpi.WebPartParentID != 0)
                {
                    WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID);
                    if (pwpi != null)
                    {
                        fi = GetWebPartProperties(pwpi);
                    }
                }
                else
                {
                    fi = GetWebPartProperties(wpi);
                }
            }
            else if (wi != null)
            {
                fi = GetWidgetProperties(wi);
            }

            // Generate properties
            if (fi != null)
            {
                GenerateProperties(fi);
            }

            // Generate documentation text
            if (itemDocumentation == null || itemDocumentation.Trim() == "")
            {
                if ((wpi != null) && (wpi.WebPartParentID != 0))
                {
                    WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID);
                    if (pwpi != null && pwpi.WebPartDocumentation.Trim() != "")
                    {
                        ltlContent.Text = HTMLHelper.ResolveUrls(pwpi.WebPartDocumentation, null);
                    }
                    else
                    {
                        ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />";
                    }
                }
                else
                {
                    ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />";
                }
            }
            else
            {
                ltlContent.Text = HTMLHelper.ResolveUrls(itemDocumentation, null);
            }
        }
        ScriptHelper.RegisterJQuery(Page);

        string script = @"
$cmsj(document.body).ready(initializeResize);
           
function initializeResize ()  { 
    resizeareainternal();
    $cmsj(window).resize(function() { resizeareainternal(); });
}

function resizeareainternal () {
    var height = document.body.clientHeight ; 
    var panel = document.getElementById ('" + divScrolable.ClientID + @"');
                
    // Get parent footer to count proper height (with padding included)
    var footer = $cmsj('#divFooter');                      
    panel.style.height = (height - footer.outerHeight() - panel.offsetTop) +'px';                  
}";

        ScriptHelper.RegisterClientScriptBlock(Page, typeof(Page), "mainScript", ScriptHelper.GetScript(script));

        // Init tabs
        tabControlElem.UsePostback = true;

        tabControlElem.AddTab(new UITabItem()
        {
            Text = GetString("webparts.documentation"),
        });

        tabControlElem.AddTab(new UITabItem()
        {
            Text = GetString("general.properties"),
        });

        // Disable caching
        Response.Cache.SetNoStore();

        base.OnLoad(e);
    }
    /// <summary>
    /// Loads the web part form.
    /// </summary>
    protected void LoadForm()
    {
        // Load settings
        if (!string.IsNullOrEmpty(Request.Form[hdnIsNewWebPart.UniqueID]))
        {
            IsNewWebPart = ValidationHelper.GetBoolean(Request.Form[hdnIsNewWebPart.UniqueID], false);
        }
        if (!string.IsNullOrEmpty(Request.Form[hdnInstanceGUID.UniqueID]))
        {
            InstanceGUID = ValidationHelper.GetGuid(Request.Form[hdnInstanceGUID.UniqueID], Guid.Empty);
        }

        // Indicates whether the new variant should be chosen when closing this dialog
        selectNewVariant = IsNewVariant;

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

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

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

        if (!String.IsNullOrEmpty(WebPartID))
        {
            // Get the page info
            pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateID, CultureCode);
            if (pi != null)
            {
                // Get template
                pti = pi.UsedPageTemplateInfo;

                // Get template instance
                templateInstance = pti.TemplateInstance;

                if (!IsNewWebPart)
                {
                    // Standard zone
                    webPartInstance = templateInstance.GetWebPart(InstanceGUID, WebPartID);

                    // If the web part not found, try to find it among the MVT/CP variants
                    if (webPartInstance == null)
                    {
                        // MVT/CP variant
                        templateInstance.LoadVariants(false, VariantModeEnum.None);
                        webPartInstance = templateInstance.GetWebPart(InstanceGUID, -1, 0);

                        // Set the VariantMode according to the selected web part/zone variant
                        if ((webPartInstance != null) && (webPartInstance.ParentZone != null))
                        {
                            VariantMode = (webPartInstance.VariantMode != VariantModeEnum.None) ? webPartInstance.VariantMode : webPartInstance.ParentZone.VariantMode;
                        }
                        else
                        {
                            VariantMode = VariantModeEnum.None;
                        }
                    }
                    else
                    {
                        // Ensure that the ZoneVarianID is not set when the web part was found in a regular zone
                        ZoneVariantID = 0;
                    }

                    if ((VariantID > 0) && (webPartInstance != null) && (webPartInstance.PartInstanceVariants != null))
                    {
                        // Check OnlineMarketing permissions.
                        if (CheckPermissions("Read"))
                        {
                            webPartInstance = webPartInstance.FindVariant(VariantID);
                        }
                        else
                        {
                            // Not authorized for OnlineMarketing - Manage.
                            RedirectToInformation(String.Format(GetString("general.permissionresource"), "Read", (VariantMode == VariantModeEnum.ContentPersonalization) ? "CMS.ContentPersonalization" : "CMS.MVTest"));
                        }
                    }

                    if (webPartInstance == null)
                    {
                        UIContext.EditedObject = null;
                        return;
                    }
                }

                mainWebPartInstance = webPartInstance;

                // Keep xml version
                if (webPartInstance != null)
                {
                    xmlVersion = webPartInstance.XMLVersion;

                    // If data source ID set, edit the data source
                    if (NestedWebPartID > 0)
                    {
                        webPartInstance = webPartInstance.NestedWebParts[NestedWebPartKey] ?? new WebPartInstance()
                        {
                            InstanceGUID = Guid.NewGuid()
                        };
                    }
                }

                // Get the form info
                FormInfo fi = GetWebPartFormInfo();

                // Get the form definition
                if (fi != null)
                {
                    fi.ContextResolver.Settings.RelatedObject = templateInstance;
                    form.AllowMacroEditing = ((WebPartTypeEnum)wpi.WebPartType != WebPartTypeEnum.Wireframe);

                    // Get data row with required columns
                    DataRow dr = fi.GetDataRow(true);

                    if (IsNewWebPart || (xmlVersion > 0))
                    {
                        fi.LoadDefaultValues(dr);
                    }

                    // Load values from existing web part
                    LoadDataRowFromWebPart(dr, webPartInstance, fi);

                    // Set a unique WebPartControlID for the new variant
                    if (IsNewVariant || IsNewWebPart)
                    {
                        // Set control ID
                        dr["WebPartControlID"] = WebPartZoneInstance.GetUniqueWebPartId(wpi.WebPartName, templateInstance);
                    }

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

                    AddExportLink();
                }
                else
                {
                    UIContext.EditedObject = null;
                }
            }
        }
    }
    /// <summary>
    /// Page load.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (StopProcessing)
        {
            return;
        }

        treeElem.OnItemSelected += treeElem_OnItemSelected;

        if (!RequestHelper.IsPostBack())
        {
            // Select root by default
            ResetToDefault();
        }

        // Different behavior of flat selector for different group zones
        if (IsInline)
        {
            // Inline widget
            flatElem.SelectInlineWidgets = true;
            treeElem.SelectInlineWidgets = true;
        }
        else if (IsDashboard)
        {
            // Dashboard zone
            flatElem.SelectDashboardWidgets = true;
            treeElem.SelectDashboardWidgets = true;
        }
        else if (!String.IsNullOrEmpty(ZoneId))
        {
            // Get pageinfo
            PageInfo pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateId, CultureCode);

            PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi);
            if (templateInstance != null)
            {
                WidgetZoneTypeEnum zoneType = ZoneType;

                // Get settings of the zone if present in the template
                WebPartZoneInstance zone = templateInstance.GetZone(ZoneId);
                if ((zoneType == WidgetZoneTypeEnum.None) && (zone != null))
                {
                    zoneType = zone.WidgetZoneType;
                }

                // Set flags to flat element by type of widget zone
                if (zoneType == WidgetZoneTypeEnum.Group)
                {
                    flatElem.SelectGroupWidgets = true;
                    treeElem.SelectGroupWidgets = true;
                    flatElem.GroupID            = pi.NodeGroupID;
                }
                else if (zoneType == WidgetZoneTypeEnum.User)
                {
                    flatElem.SelectUserWidgets = true;
                    treeElem.SelectUserWidgets = true;
                }
                else if (zoneType == WidgetZoneTypeEnum.Editor)
                {
                    flatElem.SelectEditorWidgets = true;
                    treeElem.SelectEditorWidgets = true;
                }
            }
        }
    }
예제 #9
0
    /// <summary>
    /// Init event handler.
    /// </summary>
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        // 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 = 0;
                if (VariantMode == VariantModeEnum.MVT)
                {
                    variantIdFromDB = ModuleCommands.OnlineMarketingGetMVTVariantId(PageTemplateId, variantName);
                }
                else if (VariantMode == VariantModeEnum.ContentPersonalization)
                {
                    variantIdFromDB = ModuleCommands.OnlineMarketingGetContentPersonalizationVariantId(PageTemplateId, variantName);
                }

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

        EnsureDashboard();

        if (!String.IsNullOrEmpty(WidgetId) && !IsInline)
        {
            // Get pageinfo
            try
            {
                pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateId);
            }
            catch (PageNotFoundException)
            {
                // Do not throw exception if page info not found (e.g. bad alias path)
            }

            if (pi == null)
            {
                lblInfo.Text        = GetString("Widgets.Properties.aliasnotfound");
                lblInfo.Visible     = true;
                pnlFormArea.Visible = false;
                return;
            }

            // Get template
            pti = pi.PageTemplateInfo;

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

            if (!IsNewWidget)
            {
                // Get the instance of widget
                widgetInstance = templateInstance.GetWebPart(InstanceGUID, WidgetId);
                if (widgetInstance == null)
                {
                    lblInfo.Text        = GetString("Widgets.Properties.WidgetNotFound");
                    lblInfo.Visible     = true;
                    pnlFormArea.Visible = false;
                    return;
                }

                if ((VariantID > 0) && (widgetInstance != null) && (widgetInstance.PartInstanceVariants != null))
                {
                    // Check OnlineMarketing permissions.
                    if (CheckPermissions("Read"))
                    {
                        widgetInstance = pi.DocumentTemplateInstance.GetWebPart(InstanceGUID, WidgetId);
                        widgetInstance = widgetInstance.PartInstanceVariants.Find(v => v.VariantID.Equals(VariantID));
                        // Set the widget variant mode
                        if (widgetInstance != null)
                        {
                            VariantMode = widgetInstance.VariantMode;
                        }
                    }
                    else
                    {
                        // Not authorised 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)
                wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType);
            }
            // Widget instance hasn't created yet
            else
            {
                wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetId, 0));
            }

            CMSPage.EditedObject = wi;
            zoneType             = ZoneType;

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

            // Check security
            CurrentUserInfo currentUser = CMSContext.CurrentUser;

            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 (!wi.WidgetForGroup || (!currentUser.IsGroupAdministrator(pi.NodeGroupId) && ((CMSContext.ViewMode != ViewModeEnum.Design) || ((CMSContext.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 (!wi.WidgetForEditor)
                {
                    if (OnNotAllowed != null)
                    {
                        OnNotAllowed(this, null);
                    }
                }
                break;

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

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

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

            // Get form schemas
            wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID);
            FormInfo zoneTypeDefinition = PortalHelper.GetPositionFormInfo(zoneType);
            string   widgetProperties   = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties);
            FormInfo fi = FormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), widgetProperties, zoneTypeDefinition, true);

            if (fi != null)
            {
                // Check if there are some editable properties
                FormFieldInfo[] ffi = fi.GetFields(true, false);
                if ((ffi == null) || (ffi.Length == 0))
                {
                    lblInfo.Visible = true;
                    lblInfo.Text    = GetString("widgets.emptyproperties");
                }

                // Get datarows with required columns
                DataRow dr = CombineWithDefaultValues(fi, wi);

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

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

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

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

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

                // Set the context name
                formCustom.ControlContext.ContextName = CMS.SiteProvider.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;

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

                //parse defininiton
                parameters = CMSDialogHelper.GetHashTableFromString(definition);

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

                wi = WidgetInfoProvider.GetWidgetInfo(mName);
            }
            if (wi == null)
            {
                ShowError("widget.failedtoload");
                return;
            }

            //If widget cant be used asi inline
            if (!wi.WidgetForInline)
            {
                ShowError("widget.cantbeusedasinline");
                return;
            }


            //Test permission for user
            CurrentUserInfo currentUser = CMSContext.CurrentUser;
            if (!WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, currentUser.IsAuthenticated()))
            {
                mIsValidWidget = false;
                OnNotAllowed(this, null);
            }

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

            WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID);
            string      widgetProperties   = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties);
            FormInfo    zoneTypeDefinition = PortalHelper.GetPositionFormInfo(zoneType);
            FormInfo    fi = FormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), widgetProperties, zoneTypeDefinition, true);

            if (fi != null)
            {
                // Check if there are some editable properties
                mFields = fi.GetFields(true, true);
                if ((mFields == null) || (mFields.Length == 0))
                {
                    lblInfo.Visible = true;
                    lblInfo.Text    = GetString("widgets.emptyproperties");
                }

                // Get datarows with required columns
                DataRow dr = CombineWithDefaultValues(fi, wi);

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

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

                // Init HTML toolbar if exists
                InitHTMLToobar(fi);
                // Init the form
                InitForm(formCustom, dr, fi);

                // Set the context name
                formCustom.ControlContext.ContextName = CMS.SiteProvider.ControlContext.WIDGET_PROPERTIES;
            }
        }
    }
예제 #10
0
    public void BindData()
    {
        if (WebpartId != "")
        {
            // Get page info
            pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateId);
            if (pi == null)
            {
                this.Visible = false;
                return;
            }

            // Get page template info
            pti = pi.PageTemplateInfo;
            if (pti != null)
            {
                // Get web part instance
                webPart = pti.GetWebPart(InstanceGUID, WebpartId);
                if (webPart == null)
                {
                    return;
                }

                // Get the web part info
                WebPartInfo wpi = WebPartInfoProvider.GetBaseWebPart(webPart.WebPartType);
                if (wpi == null)
                {
                    return;
                }

                // Get webpart properties (XML)
                string   wpProperties = wpi.WebPartProperties;
                FormInfo fi           = FormHelper.GetWebPartFormInfo(wpi.WebPartName + FormHelper.CORE, wpi.WebPartProperties, null, null, false);

                // Get datarow with required columns
                DataRow dr = fi.GetDataRow();

                // Bind drop down list
                if (!RequestHelper.IsPostBack())
                {
                    DataTable dropTable = new DataTable();
                    dropTable.Columns.Add("name");

                    foreach (DataColumn column in dr.Table.Columns)
                    {
                        dropTable.Rows.Add(column.ColumnName);
                    }

                    dropTable.DefaultView.Sort = "name";
                    drpProperty.DataTextField  = "name";
                    drpProperty.DataValueField = "name";
                    drpProperty.DataSource     = dropTable.DefaultView;
                    drpProperty.DataBind();
                }

                // Bind grid view
                DataTable table = new DataTable();
                table.Columns.Add("LocalProperty");
                table.Columns.Add("SourceProperty");
                bindings = webPart.Bindings;

                foreach (DataColumn column in dr.Table.Columns)
                {
                    string propertyName = column.ColumnName.ToLower();
                    if (bindings.ContainsKey(propertyName))
                    {
                        WebPartBindingInfo bi = (WebPartBindingInfo)bindings[propertyName];
                        table.Rows.Add(column.ColumnName, bi.SourceWebPart + "." + bi.SourceProperty);
                    }
                }

                gvBinding.DataSource = table;
                gvBinding.DataBind();
            }
        }
    }