Example #1
0
    /// <summary>
    /// Adds the table comparisson for matching objects.
    /// </summary>
    /// <param name="hashtable">Left side table</param>
    /// <param name="hashtableCompare">Right side table</param>
    /// <param name="titleFormat">Title format string</param>
    /// <param name="attachments">If true, the HTML code is kept (attachment comparison)</param>
    /// <param name="renderOnlyFirstTitle">If true, only first title is rendered</param>
    protected void AddTableComparison(Hashtable hashtable, Hashtable hashtableCompare, string titleFormat, bool attachments, bool renderOnlyFirstTitle)
    {
        TableCell      valueCell     = new TableCell();
        TableCell      valueCompare  = new TableCell();
        TableCell      labelCell     = new TableCell();
        TextComparison comparefirst  = null;
        TextComparison comparesecond = null;

        bool firstTitle = true;

        // Go through left column regions
        if (hashtable != null)
        {
            foreach (DictionaryEntry entry in hashtable)
            {
                object value = entry.Value;
                if (value != null)
                {
                    // Initialize comparators
                    comparefirst = new TextComparison();
                    comparefirst.SynchronizedScrolling = false;

                    comparesecond = new TextComparison();
                    comparesecond.SynchronizedScrolling = false;
                    comparesecond.RenderingMode         = TextComparisonTypeEnum.DestinationText;

                    if (attachments)
                    {
                        comparefirst.IgnoreHTMLTags        = true;
                        comparefirst.ConsiderHTMLTagsEqual = true;

                        comparesecond.IgnoreHTMLTags = true;
                    }

                    comparefirst.PairedControl = comparesecond;

                    // Initialize cells
                    valueCell    = new TableCell();
                    valueCompare = new TableCell();
                    labelCell    = new TableCell();

                    string key      = ValidationHelper.GetString(entry.Key, null);
                    string strValue = ValidationHelper.GetString(value, null);
                    if (firstTitle || !renderOnlyFirstTitle)
                    {
                        labelCell.Text = String.Format(titleFormat, MultiKeyHashtable.GetFirstKey(key));
                        firstTitle     = false;
                    }

                    if (attachments)
                    {
                        comparefirst.SourceText = strValue;
                    }
                    else
                    {
                        comparefirst.SourceText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(strValue, false));
                    }

                    if ((hashtableCompare != null) && hashtableCompare.Contains(key))
                    {
                        // Compare to the existing other version
                        string compareKey = ValidationHelper.GetString(hashtableCompare[key], null);
                        if (attachments)
                        {
                            comparefirst.DestinationText = compareKey;
                        }
                        else
                        {
                            comparefirst.DestinationText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(compareKey, false));
                        }
                        hashtableCompare.Remove(key);
                    }
                    else
                    {
                        // Compare to an empty string
                        comparefirst.DestinationText = "";
                    }

                    // Do not balance content if too short
                    if (attachments)
                    {
                        comparefirst.BalanceContent = false;
                    }
                    else if (Math.Max(comparefirst.SourceText.Length, comparefirst.DestinationText.Length) < 100)
                    {
                        comparefirst.BalanceContent = false;
                    }

                    // Create cell comparison
                    valueCell.Controls.Add(comparefirst);
                    valueCompare.Controls.Add(comparesecond);

                    AddRow(labelCell, valueCell, valueCompare, false, null, even);
                    even = !even;
                }
            }
        }

        // Go through right column regions which left
        if (hashtableCompare != null)
        {
            foreach (DictionaryEntry entry in hashtableCompare)
            {
                object value = entry.Value;
                if (value != null)
                {
                    // Initialize comparators
                    comparefirst = new TextComparison();
                    comparefirst.SynchronizedScrolling = false;

                    comparesecond = new TextComparison();
                    comparesecond.SynchronizedScrolling = false;
                    comparesecond.RenderingMode         = TextComparisonTypeEnum.DestinationText;

                    comparefirst.PairedControl = comparesecond;

                    if (attachments)
                    {
                        comparefirst.IgnoreHTMLTags        = true;
                        comparefirst.ConsiderHTMLTagsEqual = true;

                        comparesecond.IgnoreHTMLTags = true;
                    }

                    // Initialize cells
                    valueCell    = new TableCell();
                    valueCompare = new TableCell();
                    labelCell    = new TableCell();

                    if (firstTitle || !renderOnlyFirstTitle)
                    {
                        labelCell.Text = String.Format(titleFormat, MultiKeyHashtable.GetFirstKey(ValidationHelper.GetString(entry.Key, null)));
                        firstTitle     = false;
                    }

                    comparefirst.SourceText = "";
                    string strValue = ValidationHelper.GetString(value, null);
                    if (attachments)
                    {
                        comparefirst.DestinationText = strValue;
                    }
                    else
                    {
                        comparefirst.DestinationText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(strValue, false));
                    }

                    if (attachments)
                    {
                        comparefirst.BalanceContent = false;
                    }
                    else if (Math.Max(comparefirst.SourceText.Length, comparefirst.DestinationText.Length) < 100)
                    {
                        comparefirst.BalanceContent = false;
                    }

                    // Create cell comparison
                    valueCell.Controls.Add(comparefirst);
                    valueCompare.Controls.Add(comparesecond);

                    AddRow(labelCell, valueCell, valueCompare, false, null, even);
                    even = !even;
                }
            }
        }
    }
Example #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        currentUser = CMSContext.CurrentUser;
        CurrentMaster.FrameResizer.Visible = false;

        // Get query parameters
        selectedNodeType         = QueryHelper.GetString("selectednodetype", "webpart");
        selectedNodeName         = QueryHelper.GetString("selectednodename", string.Empty);
        hdnCurrentNodeType.Value = selectedNodeType;
        hdnCurrentNodeName.Value = selectedNodeName;
        nodeId = QueryHelper.GetInteger("nodeid", 0);
        // Get node
        node = DocumentHelper.GetDocument(nodeId, currentUser.PreferredCultureCode, TreeProvider);
        // Set edited document
        EditedDocument = node;

        // Images
        if (hdnCurrentNodeType.Value == "region")
        {
            imgNewItem.ImageUrl         = GetImageUrl("CMSModules/CMS_Content/EditableContent/addeditableitemsmall.png");
            imgNewItem.DisabledImageUrl = GetImageUrl("CMSModules/CMS_Content/EditableContent/addeditableitemsmalldisabled.png");
        }
        else
        {
            imgNewItem.ImageUrl         = GetImageUrl("CMSModules/CMS_Content/EditableContent/editablewebpart.png");
            imgNewItem.DisabledImageUrl = GetImageUrl("CMSModules/CMS_Content/EditableContent/editablewebpartdisabled.png");
        }
        imgDeleteItem.ImageUrl         = GetImageUrl("Objects/CMS_WebPart/delete.png");
        imgDeleteItem.DisabledImageUrl = GetImageUrl("Objects/CMS_WebPart/deletedisabled.png");

        string selectNodeName = QueryHelper.GetString("selectednodename", null);

        if (!string.IsNullOrEmpty(selectedNodeName))
        {
            bool enabled = UsesWorkflow ? (DocumentIsCheckOuted && IsAuthorizedToModify) : IsAuthorizedToModify;
            pnlDeleteItem.Enabled = enabled;
            if (enabled)
            {
                lnkDeleteItem.CssClass = "NewItemLink";
                lnkDeleteItem.Attributes.Add("onclick", "return DeleteItem();");
            }
        }
        else
        {
            pnlDeleteItem.Enabled = false;
        }

        if (IsAuthorizedToModify)
        {
            lnkNewItem.CssClass = "NewItemLink";
            lnkNewItem.Attributes.Add("onclick", "return CreateNew();");
            pnlNewItem.Enabled = true;
        }
        else
        {
            lnkNewItem.CssClass = "NewItemLinkDisabled";
            pnlNewItem.Enabled  = false;
        }

        // Resource strings
        lnkDeleteItem.Text = GetString("Development-WebPart_Tree.DeleteItem");
        lnkNewItem.Text    = GetString("Development-WebPart_Tree.NewWebPart");

        string imageUrl = "Design/Controls/Tree/";

        // Initialize page
        if (CultureHelper.IsUICultureRTL())
        {
            imageUrl = GetImageUrl("RTL/" + imageUrl, false, false);
        }
        else
        {
            imageUrl = GetImageUrl(imageUrl, false, false);
        }
        webpartsTree.LineImagesFolder = imageUrl;
        regionsTree.LineImagesFolder  = imageUrl;

        if (node != null)
        {
            string webpartRootAttributes = "class=\"ContentTreeItem\"";
            string regionRootAttributes  = "class=\"ContentTreeItem\"";

            if (string.IsNullOrEmpty(selectedNodeName))
            {
                switch (selectedNodeType)
                {
                case "webpart":
                    webpartRootAttributes = "class=\"ContentTreeSelectedItem\" id=\"treeSelectedNode\"";
                    regionRootAttributes  = "class=\"ContentTreeItem\" ";
                    break;

                case "region":
                    webpartRootAttributes = "class=\"ContentTreeItem\" ";
                    regionRootAttributes  = "class=\"ContentTreeSelectedItem\" id=\"treeSelectedNode\"";
                    break;

                default:
                    webpartRootAttributes = "class=\"ContentTreeSelectedItem\" id=\"treeSelectedNode\"";
                    regionRootAttributes  = "class=\"ContentTreeItem\" ";
                    break;
                }
            }
            else
            {
                webpartRootAttributes = "class=\"ContentTreeSelectedItem\" id=\"treeSelectedNode\"";
                regionRootAttributes  = "class=\"ContentTreeItem\" ";
            }

            // Create tree menus
            TreeElemNode rootWebpartNode = new TreeElemNode();
            rootWebpartNode.Text        = "<span " + webpartRootAttributes + " onclick=\"SelectNode('','webpart', this);\"><span class=\"Name\">" + GetString("EditableWebparts.Root") + "</span></span>";
            rootWebpartNode.ImageUrl    = GetImageUrl("CMSModules/CMS_Content/EditableContent/editablewebparts.png");
            rootWebpartNode.Expanded    = true;
            rootWebpartNode.NavigateUrl = "#";

            TreeElemNode rootRegionNode = new TreeElemNode();
            rootRegionNode.Text        = "<span " + regionRootAttributes + " onclick=\"SelectNode('','region', this);\"><span class=\"Name\">" + GetString("EditableRegions.Root") + "</span></span>";
            rootRegionNode.ImageUrl    = GetImageUrl("CMSModules/CMS_Content/EditableContent/editableregions.png");
            rootRegionNode.Expanded    = true;
            rootRegionNode.NavigateUrl = "#";

            // Editable web parts
            webpartsTree.Nodes.Add(rootWebpartNode);
            if (node.DocumentContent.EditableWebParts.Count > 0)
            {
                foreach (DictionaryEntry webPart in node.DocumentContent.EditableWebParts)
                {
                    string key  = webPart.Key.ToString();
                    string name = MultiKeyHashtable.GetFirstKey(key);
                    AddNode(rootWebpartNode, name, "webpart");
                }
            }

            // Editable regions
            regionsTree.Nodes.Add(rootRegionNode);
            if (node.DocumentContent.EditableRegions.Count > 0)
            {
                foreach (DictionaryEntry region in node.DocumentContent.EditableRegions)
                {
                    string key  = region.Key.ToString();
                    string name = MultiKeyHashtable.GetFirstKey(key);
                    AddNode(rootRegionNode, name, "region");
                }
            }
        }

        // Delete item if requested from querystring
        string nodeType = QueryHelper.GetString("nodetype", null);
        string nodeName = QueryHelper.GetString("nodename", null);

        if (!RequestHelper.IsPostBack() && !String.IsNullOrEmpty(nodeType) && QueryHelper.GetBoolean("deleteItem", false))
        {
            DeleteItem(nodeType, nodeName);
        }
    }
Example #3
0
    /// <summary>
    /// Adds the field to the form.
    /// </summary>
    /// <param name="node">Document node</param>
    /// <param name="compareNode">Document compare node</param>
    /// <param name="columnName">Column name</param>
    private void AddField(TreeNode node, TreeNode compareNode, string columnName)
    {
        FormFieldInfo ffi = null;

        if (fi != null)
        {
            ffi = fi.GetFormField(columnName);
        }

        TableCell valueCell = new TableCell();

        valueCell.EnableViewState = false;
        TableCell valueCompare = new TableCell();

        valueCompare.EnableViewState = false;
        TableCell labelCell = new TableCell();

        labelCell.EnableViewState = false;
        TextComparison comparefirst  = null;
        TextComparison comparesecond = null;
        bool           switchSides   = true;
        bool           loadValue     = true;
        bool           empty         = true;
        bool           allowLabel    = true;

        // Get the caption
        if ((columnName == UNSORTED) || (ffi != null))
        {
            AttachmentInfo aiCompare = null;

            // Compare attachments
            if ((columnName == UNSORTED) || (ffi.DataType == FormFieldDataTypeEnum.DocumentAttachments))
            {
                allowLabel = false;

                string title = null;
                if (columnName == UNSORTED)
                {
                    title = GetString("attach.unsorted") + ":";
                }
                else
                {
                    title = (String.IsNullOrEmpty(ffi.Caption) ? ffi.Name : ffi.Caption) + ":";
                }

                // Prepare DataSource for original node
                loadValue = false;

                dsAttachments = new AttachmentsDataSource();
                dsAttachments.DocumentVersionHistoryID = versionHistoryId;
                if (columnName != UNSORTED)
                {
                    dsAttachments.AttachmentGroupGUID = ffi.Guid;
                }
                dsAttachments.Path        = node.NodeAliasPath;
                dsAttachments.CultureCode = CMSContext.PreferredCultureCode;
                SiteInfo si = SiteInfoProvider.GetSiteInfo(node.NodeSiteID);
                dsAttachments.SiteName        = si.SiteName;
                dsAttachments.OrderBy         = "AttachmentOrder, AttachmentName, AttachmentHistoryID";
                dsAttachments.SelectedColumns = "AttachmentHistoryID, AttachmentGUID, AttachmentImageWidth, AttachmentImageHeight, AttachmentExtension, AttachmentName, AttachmentSize, AttachmentOrder, AttachmentTitle, AttachmentDescription";
                dsAttachments.IsLiveSite      = false;
                dsAttachments.DataSource      = null;
                dsAttachments.DataBind();

                // Get the attachments table
                attachments = GetAttachmentsTable((DataSet)dsAttachments.DataSource, versionHistoryId, node.DocumentID);

                // Prepare datasource for compared node
                if (compareNode != null)
                {
                    dsAttachmentsCompare = new AttachmentsDataSource();
                    dsAttachmentsCompare.DocumentVersionHistoryID = versionCompare;
                    if (columnName != UNSORTED)
                    {
                        dsAttachmentsCompare.AttachmentGroupGUID = ffi.Guid;
                    }
                    dsAttachmentsCompare.Path            = compareNode.NodeAliasPath;
                    dsAttachmentsCompare.CultureCode     = CMSContext.PreferredCultureCode;
                    dsAttachmentsCompare.SiteName        = si.SiteName;
                    dsAttachmentsCompare.OrderBy         = "AttachmentOrder, AttachmentName, AttachmentHistoryID";
                    dsAttachmentsCompare.SelectedColumns = "AttachmentHistoryID, AttachmentGUID, AttachmentImageWidth, AttachmentImageHeight, AttachmentExtension, AttachmentName, AttachmentSize, AttachmentOrder, AttachmentTitle, AttachmentDescription";
                    dsAttachmentsCompare.IsLiveSite      = false;
                    dsAttachmentsCompare.DataSource      = null;
                    dsAttachmentsCompare.DataBind();

                    // Get the table to compare
                    attachmentsCompare = GetAttachmentsTable((DataSet)dsAttachmentsCompare.DataSource, versionCompare, node.DocumentID);

                    // Switch the sides if older version is on the right
                    if (versionHistoryId > versionCompare)
                    {
                        Hashtable dummy = attachmentsCompare;
                        attachmentsCompare = attachments;
                        attachments        = dummy;
                    }

                    // Add comparison
                    AddTableComparison(attachments, attachmentsCompare, "<strong>" + title + "</strong>", true, true);
                }
                else
                {
                    // Normal display
                    if (attachments.Count != 0)
                    {
                        bool   first     = true;
                        string itemValue = null;

                        foreach (DictionaryEntry item in attachments)
                        {
                            itemValue = ValidationHelper.GetString(item.Value, null);
                            if (!String.IsNullOrEmpty(itemValue))
                            {
                                valueCell = new TableCell();
                                labelCell = new TableCell();

                                if (first)
                                {
                                    labelCell.Text = "<strong>" + String.Format(title, item.Key) + "</strong>";
                                    first          = false;
                                }
                                valueCell.Text = itemValue;

                                AddRow(labelCell, valueCell, null, even);
                                even = !even;
                            }
                        }
                    }
                }
            }
            // Compare single file attachment
            else if (ffi.DataType == FormFieldDataTypeEnum.File)
            {
                // Get the attachment
                AttachmentInfo ai = DocumentHelper.GetAttachment(ValidationHelper.GetGuid(node.GetValue(columnName), Guid.Empty), versionHistoryId, TreeProvider, false);

                if (compareNode != null)
                {
                    aiCompare = DocumentHelper.GetAttachment(ValidationHelper.GetGuid(compareNode.GetValue(columnName), Guid.Empty), versionCompare, TreeProvider, false);
                }

                loadValue = false;
                empty     = true;

                // Prepare text comparison controls
                if ((ai != null) || (aiCompare != null))
                {
                    string textorig = null;
                    if (ai != null)
                    {
                        textorig = CreateAttachment(ai.Generalized.DataClass, versionHistoryId);
                    }
                    string textcompare = null;
                    if (aiCompare != null)
                    {
                        textcompare = CreateAttachment(aiCompare.Generalized.DataClass, versionCompare);
                    }

                    comparefirst = new TextComparison();
                    comparefirst.SynchronizedScrolling = false;
                    comparefirst.IgnoreHTMLTags        = true;
                    comparefirst.ConsiderHTMLTagsEqual = true;
                    comparefirst.BalanceContent        = false;

                    comparesecond = new TextComparison();
                    comparesecond.SynchronizedScrolling = false;
                    comparesecond.IgnoreHTMLTags        = true;

                    // Source text must be older version
                    if (versionHistoryId < versionCompare)
                    {
                        comparefirst.SourceText      = textorig;
                        comparefirst.DestinationText = textcompare;
                    }
                    else
                    {
                        comparefirst.SourceText      = textcompare;
                        comparefirst.DestinationText = textorig;
                    }

                    comparefirst.PairedControl  = comparesecond;
                    comparesecond.RenderingMode = TextComparisonTypeEnum.DestinationText;

                    valueCell.Controls.Add(comparefirst);
                    valueCompare.Controls.Add(comparesecond);
                    switchSides = false;

                    // Add both cells
                    if (compareNode != null)
                    {
                        AddRow(labelCell, valueCell, valueCompare, switchSides, null, even);
                    }
                    // Add one cell only
                    else
                    {
                        valueCell.Controls.Clear();
                        Literal ltl = new Literal();
                        ltl.Text = textorig;
                        valueCell.Controls.Add(ltl);
                        AddRow(labelCell, valueCell, null, even);
                    }
                    even = !even;
                }
            }
        }

        if (allowLabel && (labelCell.Text == ""))
        {
            labelCell.Text = "<strong>" + columnName + ":</strong>";
        }

        if (loadValue)
        {
            string textcompare = null;

            switch (columnName.ToLower())
            {
            // Document content - display content of editable regions and editable web parts
            case "documentcontent":
                EditableItems ei = new EditableItems();
                ei.LoadContentXml(ValidationHelper.GetString(node.GetValue(columnName), ""));

                // Add text comparison control
                if (compareNode != null)
                {
                    EditableItems eiCompare = new EditableItems();
                    eiCompare.LoadContentXml(ValidationHelper.GetString(compareNode.GetValue(columnName), ""));

                    // Create editable regions comparison
                    Hashtable hashtable;
                    Hashtable hashtableCompare;

                    // Source text must be older version
                    if (versionHistoryId < versionCompare)
                    {
                        hashtable        = ei.EditableRegions;
                        hashtableCompare = eiCompare.EditableRegions;
                    }
                    else
                    {
                        hashtable        = eiCompare.EditableRegions;
                        hashtableCompare = ei.EditableRegions;
                    }

                    // Add comparison
                    AddTableComparison(hashtable, hashtableCompare, "<strong>" + columnName + " ({0}):</strong>", false, false);

                    // Create editable webparts comparison
                    // Source text must be older version
                    if (versionHistoryId < versionCompare)
                    {
                        hashtable        = ei.EditableWebParts;
                        hashtableCompare = eiCompare.EditableWebParts;
                    }
                    else
                    {
                        hashtable        = eiCompare.EditableWebParts;
                        hashtableCompare = ei.EditableWebParts;
                    }

                    // Add comparison
                    AddTableComparison(hashtable, hashtableCompare, "<strong>" + columnName + " ({0}):</strong>", false, false);
                }
                // No compare node
                else
                {
                    // Editable regions
                    Hashtable hashtable = ei.EditableRegions;
                    if (hashtable.Count != 0)
                    {
                        string regionValue = null;
                        string regionKey   = null;

                        foreach (DictionaryEntry region in hashtable)
                        {
                            regionValue = ValidationHelper.GetString(region.Value, null);
                            if (!String.IsNullOrEmpty(regionValue))
                            {
                                regionKey = ValidationHelper.GetString(region.Key, null);

                                valueCell = new TableCell();
                                labelCell = new TableCell();

                                labelCell.Text = "<strong>" + columnName + " (" + MultiKeyHashtable.GetFirstKey(regionKey) + "):</strong>";
                                valueCell.Text = HttpUtility.HtmlDecode(HTMLHelper.StripTags(regionValue, false));

                                AddRow(labelCell, valueCell, null, even);
                                even = !even;
                            }
                        }
                    }

                    // Editable web parts
                    hashtable = ei.EditableWebParts;
                    if (hashtable.Count != 0)
                    {
                        string partValue = null;
                        string partKey   = null;

                        foreach (DictionaryEntry part in hashtable)
                        {
                            partValue = ValidationHelper.GetString(part.Value, null);
                            if (!String.IsNullOrEmpty(partValue))
                            {
                                partKey   = ValidationHelper.GetString(part.Key, null);
                                valueCell = new TableCell();
                                labelCell = new TableCell();

                                labelCell.Text = "<strong>" + columnName + " (" + MultiKeyHashtable.GetFirstKey(partKey) + "):</strong>";
                                valueCell.Text = HttpUtility.HtmlDecode(HTMLHelper.StripTags(partValue, false));

                                AddRow(labelCell, valueCell, null, even);
                                even = !even;
                            }
                        }
                    }
                }

                break;

            // Others, display the string value
            default:
                // Shift date time values to user time zone
                object origobject = node.GetValue(columnName);
                string textorig   = null;
                if (origobject is DateTime)
                {
                    TimeZoneInfo usedTimeZone = null;
                    textorig = TimeZoneHelper.GetCurrentTimeZoneDateTimeString(ValidationHelper.GetDateTime(origobject, DateTimeHelper.ZERO_TIME), CurrentUser, CMSContext.CurrentSite, out usedTimeZone);
                }
                else
                {
                    textorig = ValidationHelper.GetString(origobject, "");
                }

                // Add text comparison control
                if (compareNode != null)
                {
                    // Shift date time values to user time zone
                    object compareobject = compareNode.GetValue(columnName);
                    if (compareobject is DateTime)
                    {
                        TimeZoneInfo usedTimeZone = null;
                        textcompare = TimeZoneHelper.GetCurrentTimeZoneDateTimeString(ValidationHelper.GetDateTime(compareobject, DateTimeHelper.ZERO_TIME), CurrentUser, CMSContext.CurrentSite, out usedTimeZone);
                    }
                    else
                    {
                        textcompare = ValidationHelper.GetString(compareobject, "");
                    }

                    comparefirst = new TextComparison();
                    comparefirst.SynchronizedScrolling = false;

                    comparesecond = new TextComparison();
                    comparesecond.SynchronizedScrolling = false;
                    comparesecond.RenderingMode         = TextComparisonTypeEnum.DestinationText;

                    // Source text must be older version
                    if (versionHistoryId < versionCompare)
                    {
                        comparefirst.SourceText      = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textorig, false));
                        comparefirst.DestinationText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textcompare, false));
                    }
                    else
                    {
                        comparefirst.SourceText      = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textcompare, false));
                        comparefirst.DestinationText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textorig, false));
                    }

                    comparefirst.PairedControl = comparesecond;

                    if (Math.Max(comparefirst.SourceText.Length, comparefirst.DestinationText.Length) < 100)
                    {
                        comparefirst.BalanceContent = false;
                    }

                    valueCell.Controls.Add(comparefirst);
                    valueCompare.Controls.Add(comparesecond);
                    switchSides = false;
                }
                else
                {
                    valueCell.Text = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textorig, false));
                }

                empty = (String.IsNullOrEmpty(textorig)) && (String.IsNullOrEmpty(textcompare));
                break;
            }
        }

        if (!empty)
        {
            if (compareNode != null)
            {
                AddRow(labelCell, valueCell, valueCompare, switchSides, null, even);
                even = !even;
            }
            else
            {
                AddRow(labelCell, valueCell, null, even);
                even = !even;
            }
        }
    }
Example #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!RequestHelper.IsPostBack())
        {
            // Fill dropdown list
            InitEditorOptions();

            // Inform user about saving
            if (QueryHelper.GetBoolean("imagesaved", false))
            {
                lblInfo.Text    = GetString("general.changessaved");
                lblInfo.Visible = true;
                drpEditControl.SelectedIndex = 1;
            }
        }

        // Initialize HTML editor
        InitHTMLEditor();

        // Find postback invoker
        string invokerName = Page.Request.Params.Get("__EVENTTARGET");

        invokeControl = !string.IsNullOrEmpty(invokerName) ? Page.FindControl(invokerName) : null;

        // Set whether new item is to be created
        createNew = QueryHelper.GetBoolean("createNew", false);

        if (invokerName != null)
        {
            if (createNew && (invokeControl == drpEditControl))
            {
                createNew = true;
            }
            else
            {
                if (invokeControl == drpEditControl)
                {
                    createNew       = false;
                    lblInfo.Text    = string.Empty;
                    lblInfo.Visible = false;
                }
            }
        }


        // Get query parameters
        keyName = QueryHelper.GetString("nodename", string.Empty);
        nodeId  = QueryHelper.GetInteger("nodeid", 0);

        // Set editable content type enum
        switch (QueryHelper.GetString("nodetype", "webpart"))
        {
        case "webpart":
            keyType = EditableContentType.webpart;
            break;

        case "region":
            keyType = EditableContentType.region;
            break;
        }

        // Get node
        node = DocumentHelper.GetDocument(nodeId, CMSContext.PreferredCultureCode, TreeProvider);
        // Set edited document
        EditedDocument = node;

        // Initialize javascripts
        ltlScript.Text += ScriptHelper.GetScript("mainUrl = '" + ResolveUrl("~/CMSModules/Content/CMSDesk/Properties/Advanced/EditableContent/main.aspx") + "?nodeid=" + nodeId + "';");

        lblError.Visible = false;


        // Show editing controls
        if ((createNew || keyName != string.Empty))
        {
            pnlMenu.Visible            = true;
            menuElem.AllowSave         = IsAuthorizedToModify();
            pnlEditableContent.Visible = true;
        }

        // Get content
        if ((node != null) && (keyName != string.Empty) || createNew)
        {
            if (!RequestHelper.IsPostBack() && !createNew)
            {
                txtName.Text = MultiKeyHashtable.GetFirstKey(keyName);
            }

            if (!createNew)
            {
                content = GetContent();

                // Disable HTML editor if content is typeof image
                if (content != null)
                {
                    if (content.StartsWith("<image>"))
                    {
                        ListItem li =
                            drpEditControl.Items.FindByValue(Convert.ToInt32(EditingForms.HTMLEditor).ToString());
                        if (li != null)
                        {
                            drpEditControl.Items.Remove(li);
                        }
                    }
                }
            }
        }

        // Hide all content controls
        txtAreaContent.Visible = txtContent.Visible = htmlContent.Visible = imageContent.Visible = false;

        // Set up editing forms
        switch (((EditingForms)Convert.ToInt32(drpEditControl.SelectedValue)))
        {
        case EditingForms.TextArea:
            txtAreaContent.Visible = true;
            break;

        case EditingForms.HTMLEditor:
            htmlContent.Visible = true;
            break;

        case EditingForms.EditableImage:
            imageContent.Visible    = true;
            imageContent.ImageTitle = HTMLHelper.HTMLEncode(MultiKeyHashtable.GetFirstKey(keyName));
            break;

        case EditingForms.TextBox:
            txtContent.Visible = true;
            break;
        }
        lblContent.Visible = txtContent.Visible;
    }