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

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

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

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

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

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// After form definition update event handler.
    /// </summary>
    protected void fieldEditor_OnAfterDefinitionUpdate(object sender, EventArgs e)
    {
        // Perform OnBeforeSave if defined
        if (OnBeforeSave != null)
        {
            OnBeforeSave();
        }

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

        if ((widgetInfo != null) && (webpartInfo != null))
        {
            // Compare original and alternative form definitions - store differences only
            widgetInfo.WidgetProperties = FormHelper.GetFormDefinitionDifference(webpartInfo.WebPartProperties, fieldEditor.FormDefinition, true);
            // Update alternative form info in database
            WidgetInfoProvider.SetWidgetInfo(widgetInfo);
        }
        else
        {
            ShowError(GetString("general.invalidid"));
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Creates widget. Called when the "Create widget" button is pressed.
    /// </summary>
    private bool CreateWidget()
    {
        // Get parent webpart and category for widget
        WebPartInfo        webpart  = WebPartInfoProvider.GetWebPartInfo("AbuseReport");
        WidgetCategoryInfo category = WidgetCategoryInfoProvider.GetWidgetCategoryInfo("MyNewCategory");

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

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

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

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

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

            return(true);
        }

        return(false);
    }
    public void RaisePostBackEvent(string eventArgument)
    {
        if (!CheckPermissions("cms.widget", PERMISSION_MODIFY))
        {
            return;
        }

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

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

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

                // Save changes to the widget
                WidgetInfoProvider.SetWidgetInfo(WidgetInfo);
            }
        }
    }
    /// <summary>
    /// 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.º 6
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);
        }
    }
Exemplo n.º 7
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.º 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);

            lblInfo.Visible = true;
            lblInfo.Text    = GetString("General.ChangesSaved");
        }
    }
    /// <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);
    }
    /// <summary>
    /// Creates new widget with setting from parent webpart.
    /// </summary>
    /// <param name="parentWebpartId">ID of parent webpart</param>
    /// <param name="categoryId">ID of parent widget category</param>
    /// <returns>Created widget info</returns>
    private WidgetInfo NewWidget(int parentWebpartId, int categoryId)
    {
        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(parentWebpartId);

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

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

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

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

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

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

                MetaFileInfoProvider.SetMetaFileInfo(mfi);
            }

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

        return(null);
    }
Exemplo n.º 11
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.º 12
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);
    }
Exemplo n.º 13
0
    public void RaisePostBackEvent(string eventArgument)
    {
        if (!CheckPermissions("cms.widget", PERMISSION_MODIFY))
        {
            return;
        }

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

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

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

                // Save changes to the widget
                WidgetInfoProvider.SetWidgetInfo(WidgetInfo);
            }
        }
        else if ((args.Length == 1))
        {
            switch (args[0].ToLowerCSafe())
            {
            // Used in group zones
            case "group":
                if (WidgetInfo != null)
                {
                    WidgetInfo.WidgetForGroup = chkUsedInGroupZones.Checked;
                }
                break;

            // Used in user zones
            case "user":
                if (WidgetInfo != null)
                {
                    WidgetInfo.WidgetForUser = chkUsedInUserZones.Checked;
                }
                break;

            // Used in editor zones
            case "editor":
                if (WidgetInfo != null)
                {
                    WidgetInfo.WidgetForEditor = chkUsedInEditorZones.Checked;
                }
                break;

            //Used as inline widget
            case "inline":
                if (WidgetInfo != null)
                {
                    WidgetInfo.WidgetForInline = chkUsedAsInlineWidget.Checked;
                }
                break;

            // Used in dashboard zones
            case "dashboard":
                if (WidgetInfo != null)
                {
                    WidgetInfo.WidgetForDashboard = chkUsedInDashboard.Checked;
                }
                break;


            default:
                break;
            }

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

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

            this.WidgetInfo = new WidgetInfo();
            this.WidgetInfo.WidgetWebPartID  = this.WidgetWebpartId;
            this.WidgetInfo.WidgetCategoryID = this.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 (String.Compare(this.WidgetInfo.WidgetName, txtCodeName.Text, true) != 0)
            {
                WidgetInfo widget = WidgetInfoProvider.GetWidgetInfo(txtCodeName.Text);
                if (widget != null)
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("general.codenameexists");
                    return;
                }
            }

            this.WidgetInfo.WidgetName        = txtCodeName.Text;
            this.WidgetInfo.WidgetDisplayName = txtDisplayName.Text;
            this.WidgetInfo.WidgetDescription = txtDescription.Text;

            this.WidgetInfo.WidgetCategoryID = ValidationHelper.GetInteger(categorySelector.Value, WidgetInfo.WidgetCategoryID);

            WidgetInfoProvider.SetWidgetInfo(this.WidgetInfo);

            lblInfo.Text    = GetString("general.changessaved");
            lblInfo.Visible = true;

            // Raise save for frame reload
            RaiseOnSaved();
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = errorMessage;
        }
    }
Exemplo n.º 15
0
    /// <summary>
    /// Button OK click handler.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Trim text values
        txtWidgetName.Text        = TextHelper.LimitLength(txtWidgetName.Text.Trim(), 100, "");
        txtWidgetDisplayName.Text = TextHelper.LimitLength(txtWidgetDisplayName.Text.Trim(), 100, "");

        // Validate the text box fields
        string errorMessage = new Validator()
                              .NotEmpty(txtWidgetName.Text, rfvWidgetName.ErrorMessage)
                              .NotEmpty(txtWidgetDisplayName.Text, rfvWidgetDisplayName.ErrorMessage)
                              .IsCodeName(txtWidgetName.Text, GetString("general.InvalidCodeName"))
                              .Result;

        // Check if widget with same name exists
        if (WidgetInfoProvider.GetWidgetInfo(txtWidgetName.Text) != null)
        {
            errorMessage = GetString("general.codenameexists");
        }

        if (errorMessage == "")
        {
            // Clone widget info
            WidgetInfo nwi = new WidgetInfo(wi, false);

            // Modify info data
            nwi.WidgetID          = 0;
            nwi.WidgetGUID        = Guid.NewGuid();
            nwi.WidgetName        = txtWidgetName.Text;
            nwi.WidgetDisplayName = txtWidgetDisplayName.Text;
            nwi.WidgetCategoryID  = ValidationHelper.GetInteger(categorySelector.Value, 0);

            // Add new web part to database
            WidgetInfoProvider.SetWidgetInfo(nwi);

            // Clone widget security
            DataSet ds = WidgetRoleInfoProvider.GetWidgetRoles("WidgetID = " + wi.WidgetID, null, 0, null);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    WidgetRoleInfo nwri = new WidgetRoleInfo(dr);
                    nwri.WidgetID = nwi.WidgetID;
                    WidgetRoleInfoProvider.SetWidgetRoleInfo(nwri);
                }
            }

            // Update widget category counts
            WidgetCategoryInfoProvider.UpdateCategoryWidgetChildCount(0, nwi.WidgetCategoryID);

            // Duplicate associated thumbnail
            MetaFileInfoProvider.CopyMetaFiles(wi.WidgetID, nwi.WidgetID, PortalObjectType.WIDGET, MetaFileInfoProvider.OBJECT_CATEGORY_THUMBNAIL, null);

            string script      = String.Empty;
            string refreshLink = URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/WidgetTree.aspx?widgetid=" + nwi.WidgetID + "&reload=true");
            if (QueryHelper.GetBoolean("reloadAll", true))
            {
                // Refresh web part tree and select/edit new widget
                script = "wopener.location = '" + refreshLink + "';";
            }
            else
            {
                script += "wopener.parent.parent.frames['widgettree'].location.href ='" + refreshLink + "';";
            }
            script += "window.close();";

            ltlScript.Text = ScriptHelper.GetScript(script);
        }
        else
        {
            lblError.Text    = errorMessage;
            lblError.Visible = true;
        }
    }