4

I have implemented a custom Rich text editor button. When I click on the custom RTE button it opens a Sheer dialog where the user can select an item from a list and I build a link based on the selected item. At the end it the link value has a value similar to any Sitecore media links like:

<a href="~/media/c91e6ce67216446c8c2af1ae5d2a8120.ashx">PDF_test</a>

That works fine except that the link is not inserted into the RTE within the content but it becomes the content. In other words all the content is cleared and the new link is applied.

My Dialog inherits from Sitecore.Web.UI.Pages.DialogForm. Here is how the OnOK overridden method looks like of my dialog(adapted for the question)

protected override void OnOK(object sender, EventArgs args)
        {

            //previous code cleared from this question

            var dialogValue = AssetService.GetValue();

            SheerResponse.SetDialogValue(dialogValue);

            base.OnOK(sender, args);
        }

Also this is the custom command item set on the RichTextCommands.js:

Telerik.Web.UI.Editor.CommandList["SelectAsset"] = function (commandName, editor, args) {


    scEditor = editor;

    editor.showExternalDialog(
        "/sitecore/shell/default.aspx?xmlcontrol=SelectAsset&currentItemId=" + scItemID + "&assetType=link",
        null, //argument
        1105,
        700,
        scInsertSitecoreLink,
        null,
        "Asset",
        true, //modal
        Telerik.Web.UI.WindowBehaviors.Close, // behaviors
        false, //showStatusBar
        false //showTitleBar
    );
};

Any thoughts on what I'm missing here?

2

To address this issue I had to change the dialog OnOk method. Instead of calling the SetDialogValue I called the following:

    //writes the url and link name(dialogValue .Value). This will build the link on the Rich Text Editor
     SheerResponse.Eval("scClose(" + StringUtil.EscapeJavascriptString(dialogValue.Url) + "," + StringUtil.EscapeJavascriptString(dialogValue.Text) + ")");

What this is doing is passing the url and text the will be used to build the anchor tag. Note also that it's evaluating a javascript function called scClose accepting these 2 parameters(url and text).

Now all I had to do was define a new js file and reference it on my xml dialog. This is what the js file looks like:

function getRadWindow() {
    if (window.radWindow) {
        return window.radWindow;
    }

    if (window.frameElement &amp;&amp; window.frameElement.radWindow) {
        return window.frameElement.radWindow;
    }

    return null;
}

var isRadWindow = true;

var radWindow = getRadWindow();

if (radWindow) {
    if (window.dialogArguments) {
        radWindow.Window = window;
    }
}

function GetDialogArguments() {
    return getRadWindow().ClientParameters;
} 

function scCancel() {
    getRadWindow().close();
}

function scClose(url, text) {
    //builds the link and anchor name
    var returnValue = {
        url: url,
        text: text
    };

    getRadWindow().close(returnValue);

}     

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.