4

I have a speak dialog that creates a group of items based on some user input. I want to be able to open a new content editor frame if the user is currently in the shell. I have access to the id or path of the item that I want to select in the content editor.

This comes very close to what I want: How to open the content editor from SPEAK?. I don't want to refresh the page in case the content editor is working on something in that same window though.

Basically the flow I want is if the user is in the desktop view of the shell open a new content editor window in the shell with the item selected. If the user is in content editor or anything other than shell I'm going to just close the dialog.

  • From where the user will open the content editor? Is it from the speak dialog? Can you provide screenshots – Hishaam Namooya Jul 15 '17 at 8:14
  • @HishaamNamooya it will open after a speak dialog closes. The speak dialog can be opened in the shell or content editor. – Teeknow Jul 17 '17 at 13:00
3

You can make use of the below command in the Javascript file to open the Content Editor.

window.top.scForm.postRequest('','','','RunShortcut("{E28353A0-FB68-455B-9B2E-99AD280EF64E}")');
  • Thanks! I ended up using this to open a new content editor window and then opened the item in that. – Teeknow Jul 18 '17 at 20:21
2

Here's what I ended up doing. I'm sure there's a way to do it in one step though (somehow emulate a shortcut pointing to an item?). If that ever gets posted I'll accept that answer. This does it in multiple steps with a lot of assumptions. It opens a content editor window using the default content editor window id which should be fine. The sketchier parts are where it gets the last window in the scManager.windows array (which SEEMS to be in order). Then blindly setting the url can be improved upon by just looking for the fo parameter and replacing or adding that.

In the success function of an ajax call (data is an id):

success: function (data) {
    var topScForm,
        topScManager,
        contentEditorWindow;

    topScForm = window.top.scForm;
    topScManager = window.top.scManager;

    if (typeof topScForm != 'undefined' && topScForm != null) {
        //open the default content editor shortcut
        topScForm.postRequest('', '', '', 'RunShortcut("{E28353A0-FB68-455B-9B2E-99AD280EF64E}")');

        if (topScManager.windows.length) {
            //get the window we just opened
            contentEditorWindow = topScManager.getWindow(topScManager.windows[topScManager.windows.length - 1]);

            //set the url to open our new item
            contentEditorWindow.src = '/sitecore/shell/Applications/Content-Editor?ic=Apps%2F48x48%2FPencil.png&he=Content%20Editor&cl=0&fo=' + encodeURIComponent(data);
        }

        //close our dialog
        window.top.dialogClose();
    }
}
  • In Sitecore 9.0.2 running window.top.scForm.postRequest('', '', '', 'RunShortcut(<ID>)'); does not open the content editor and instead an error dialog appears Method "RunShortcut" not found in Sitecore.Shell.Applications.ContentManager.ContentEditorForm. (method: Sitecore.Web.UI.Sheer.ClientPage.Dispatch(String command)). – Andreas Warberg Nov 6 at 9:56
0

EDIT: I think this first solution is better for opening a new tab (taken from here: https://mikerobbins.co.uk/2015/07/14/sitecore-content-editor-tabs-in-speak/

Basically - you should be able to open a new tab using the following Javascript (assuming the blog is still relevant):

parent.scForm.postRequest(\'\', \'\', \'\', \'contenteditor:launchtab(url={ITEMIDHERE}, la={LANGUAGENAMEHERE}, datasource=sitecore)\')

A simpler solution: If you don't want the possibility that the user is going to lose work if they're already doing something in the content editor - I think the safest thing to do would be to open a new tab in the browser pointing to the selected item.

You can do this with a specifically formatted URL (as mentioned in the referenced question). If you add target="_blank" to the link being pressed by the user - then this will open a new tab.

  • With the second approach are you suggesting to make a command that does that? – Teeknow Jul 18 '17 at 13:38
  • 1
    Let me update the answer - I've found a solution which I think is better :) – Owen Niblock Jul 18 '17 at 14:20
  • 1
    Unfortunately parent.scForm is undefined for me. I used window.top.scForm.postRequest('', '', '', 'contenteditor:launchtab(url=' + data + ', la=en, datasource=sitecore)'); but that seemed to fail silently as nothing happened and no errors showed up in the console. I should specify that I am in the desktop view of the shell with a speak application open. The runtime value of the string that gets concatenated with data was "contenteditor:launchtab(url={05DD41A0-820F-4960-87B6-E2E5A2114604}, la=en, datasource=sitecore)" which was pulled from Chrome's watch window. – Teeknow Jul 18 '17 at 14:42
  • You might have to experiment a bit to get it running at the right level I guess. You could try "scForm", and "parent.parent.scForm" - if those don't work it could be that this JS is no longer the way to go :( Let me know if it doesn't and I'll have a dig about this evening. – Owen Niblock Jul 18 '17 at 15:05
0

The contenteditor:launchtab command did not work for me in Sitecore 9.

I was able to do it with item:load instead:

window.top.scForm.postRequest('', '', '', 'item:load(id={0DE95AE4-41AB-4D01-9EB0-67441B7C2450})');
window.top.dialogClose();

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.