This is a migrated thread and some comments may be shown as answers.

Save Track Changes Content without Dialog

4 Answers 162 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Sean Patterson
Top achievements
Rank 1
Sean Patterson asked on 26 Aug 2010, 01:23 AM
Is it possible to save the Track Changes result without opening the dialog?  Or even just a way to open the dialog in the background and close it out once the content is rendered an I have grabed the fieldset for the Track Change Content? 

My objective is to present the track changes content outside of the Editor to other users, so they can see what has changed.  I currently save both the initial and final versions to my database right now.  And I can force the content to automatically set and switch out with the following script.  I would just prefer not to have the dialog interfere with the UI when my sole purpose for it's use is just get the content rendered in the track change format, not to inform the users that wrote the content.
function EditorCommand(editor, args) {
                                  
switch (args.get_commandName()) {
 case "TrackChangesDialog":
   var loc = "Pub.aspx";
   var methodName = "GetLastRevContent" + location.search;
   var jsondata = new Object();
   jsondata.contentId = _$currentEdit.attr("id");
   var jsoon = $.toJSON(jsondata);
   $.ajax({
           async: false,
           type: "POST",
           url: loc + "/" + methodName,
           data: jsoon,
           contentType: "application/json; charset=utf-8",
           dataType: "json",
           timeout: _sysEditPubVars.timeoutRate,
           success: function (response) {
               var editor = $find('<%= RadEditor1.ClientID %>');
               var fromServer = jQuery.parseJSON(response.d);
               var currentcontent = editor.get_html(true);
               editor.set_html(fromServer.oldContent);
               editor.set_initialContent();
               editor.set_html(currentcontent);
               },
             });
      break;
  default:
      break;
   }
}

4 Answers, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 31 Aug 2010, 01:56 PM
Hi Sean,

RadEditor's TrackChanges dialog is using a helper class DiffEngine to provide its functionality. It is possible to take advantage of that helper class to achieve the required functionality, e.g.:
using Telerik.Web.UI.Editor.Diff;
........
DiffEngine diff =
new DiffEngine();
 
//currentContent and initContent are string variables content to be matched
string result = diff.GetDiffs(currentContent, initContent);//returns the decorated content

also you need to include the following CSS selectors to the page displaying the modified content:
<style runat="server" id="cssFormatting" type="text/css">
    body
    {
        background-color: transparent;
    }
    legend
    {
        font: normal 12px Arial, Verdana, Sans-serif;
    }
    .diff_new
    {
        background-color: #00ff00;
    }
    .diff_deleted
    {
        color: Red;
        text-decoration: line-through;
    }
    table.diff_new
    {
        border: 2px solid green;
    }
    .diff_new td
    {
        padding: 5px, 5px, 5px, 5px;
        background-color: #00ff00;
    }
    table.diff_deleted
    {
        padding: 5px, 5px, 5px, 5px;
        border: 2px solid red;
        filter: alpha(opacity=20);
        -moz-opacity: 0.2;
        opacity: 0.2;
    }
</style>

I hope this helps.

All the best,
Dobromir
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Arasu
Top achievements
Rank 1
answered on 13 Dec 2010, 03:43 PM
Hi,

Could it possible to post the full code for this functionality please. I'm after the requirement as similar to Sean's and i'm new to ASP.net & telerik, thank you.

Regards
Arasu
0
Dobromir
Telerik team
answered on 16 Dec 2010, 01:10 PM
Hi Arasu,

This is a custom solution and providing such is out of our support scope. However, I have prepared a sample website demonstrating the approach from my previous answer. Please find it attached.

Regards,
Dobromir
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Sean Patterson
Top achievements
Rank 1
answered on 17 Dec 2010, 12:22 PM
Arasu,
For my purposes, I eventually settled on sending the current database ID key of the content that I wanted compared to it's last version back to the server via AJAX and using a web service to implement the differance engine against the database text of the current ID verus the text of the current ID's last version (there are versions assigned to each database row).  I then sent that string asn the respose to the request. The comparision also has the option to do other comparsion types through the same webservice.

CLIENTSIDE
function compareXref(xreftype, xrefIdBpub) {
  
                var loc = "Pub Editor.aspx"
                var methodName = "CompareContent"
                var jsondata = new Object();
  
                /* generic call to CompareContent */
                jsondata.OrignalId = xrefIdBpub;     //Orginal ID is the selected item
                jsondata.NewId = -1;                        //set to -1 since we are going to search for the last rev data
                jsondata.CompareType = "Pub to Pub";        //Compare this pub with itself
                jsondata.ResultType = "JSON";               //return data in JSON form
  
                var jsoon = $.toJSON(jsondata);
                $.ajax({
                    type: "POST",
                    url: loc + "/" + methodName,
                    data: jsoon,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        var fromServer = jQuery.parseJSON(response.d);
                        switch (xreftype) {
                            case 0:
                                $this = $("#" + xrefIdBpub)
                                 
                                break;
                            case 1:
  
                                $this = $("[sectId=" + xrefIdBpub + "]").find('.sectionTitle:First')
                                                                 
                                break;
                            case 2:
                                $this = $(".slct:first", "MainContainer")
                                                                  
                                break;
                        }
                        $this.next('.infoDiv').find('.comparedresultsDIV').remove();
                        $this.next('.infoDiv').find('.infoBody').prepend(fromServer.comparision);
                        $this.next('.infoDiv').toggleClass('ui-helper-hidden')
                        $this.next('.infoDiv').slideDown(150)
                    },
                    error: onFail
                });
}


SERVERSIDE

<WebMethod()> _
 Public Shared Function CompareContent(ByVal OrignalId As Integer, ByVal NewId As Integer, ByVal CompareType As String, ByVal ResultType As String) As String
     Dim diff As Telerik.Web.UI.Editor.Diff.DiffEngine = New Telerik.Web.UI.Editor.Diff.DiffEngine()
     Dim messages As String = ""
     Dim output As String = ""
     Using myData As myDatabases.Sample_PubDataContext = New myDatabases.Sample_PubDataContext()
         If CompareType = "Pub to Pub" Then
             Dim thisContent = (From t In myData.Pubs _
                           Where t.Id = OrignalId _
                           Select t).Single
             Dim thisHistory = From h In myData.Pubs _
                               Where h.SupercededById = thisContent.SupercededById _
                               Order By h.Master_Revision_List_Revision.RevisionNumber Descending _
                               Select h
             If thisHistory.Count = 1 Then
                 output = "This context has no history"
             Else
                 Dim initContent = (From p In thisHistory _
                                       Where p.inActiveRev = thisContent.Revision _
                                       Select p.PubContent.Contents).Single()
                 output = diff.GetDiffs(thisContent.PubContent.Contents, initContent)
             End If
         ElseIf CompareType = "Pub to Comment" Then
             ......... OTHER COMPARE TYPES..............
         End If
     End Using
     If ResultType = "HTML" Then
         Return output
     End If
     Dim plcContent As PlaceHolder = New PlaceHolder()
     Dim lcContent As Literal = New Literal()
     lcContent.Text = output
     plcContent.Controls.Add(lcContent)
     Dim resultWidget As MyResultsDivWidget = New MyResultsDivWidget(True, "Comparision of Last Revision with New Revision", plcContent)
     resultWidget.ResultDivClass = "comparedresultsDIV"
     Dim results As String = resultWidget.ReturnHTML()
     If ResultType = "JSON" Then
         Dim w As Jayrock.Json.JsonWriter = New Jayrock.Json.JsonTextWriter()
         w.WriteStartObject()
         w.WriteMember("message")
         w.WriteString(messages)
         w.WriteMember("comparision")
         w.WriteString(results)
         w.WriteEndObject()
         Return w.ToString()
     End If
     Return False
 End Function

Hope this helps.
Tags
Editor
Asked by
Sean Patterson
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Arasu
Top achievements
Rank 1
Sean Patterson
Top achievements
Rank 1
Share this question
or