4

I want to always have all the Targets unchecked on the Publish popup (Publish.aspx) disregarding the selected Targets from previous publish actions.

How can I achieved this? GUI Extension? Any example?

I'm not being able to find it.

UPDATE

PublishDialogSettings.js (TargetTypeList_frame_details is the name of the iFrame where the name of the targets are along with its checkboxes)

$evt.addEventHandler($display, "start", onDisplayStarted);

function onDisplayStarted() {
    $evt.removeEventHandler($display, "start", onDisplayStarted);
    $("#TargetTypeList_frame_details").contents().find("input:checkbox").prop('checked', false);
}

PublishDialogSettings.config

<?xml version="1.0"?>
<Configuration xmlns="http://www.sdltridion.com/2009/GUI/Configuration/Merge"
    xmlns:cfg="http://www.sdltridion.com/2009/GUI/Configuration"
    xmlns:ext="http://www.sdltridion.com/2009/GUI/extensions"
    xmlns:cmenu="http://www.sdltridion.com/2009/GUI/extensions/ContextMenu">
  <resources cache="true">
    <cfg:filters />
    <cfg:extensiongroups>
      <cfg:extensiongroup name="PublishDialogSettings">
        <cfg:extension target="Tridion.Web.UI.Editors.CME.Views.Popups.Publish">
          <cfg:insertafter>MyCompany.Resources.PublishDialogSettings</cfg:insertafter>
        </cfg:extension>
      </cfg:extensiongroup>
    </cfg:extensiongroups>
    <cfg:groups>
      <cfg:group name="MyCompany.Resources.PublishDialogSettings">
        <cfg:fileset>
          <cfg:file type="script">/Scripts/jquery-3.3.1.min.js</cfg:file>
          <cfg:file type="script">/Scripts/PublishDialogSettings.js</cfg:file>
        </cfg:fileset>
      </cfg:group>
    </cfg:groups>
  </resources>
  <definitionfiles/>
  <extensions>
    <ext:editorextensions>
      <ext:editorextension target="CME">
        <ext:editurls />
        <ext:listdefinitions />
        <ext:taskbars />
        <ext:commands />
        <ext:commandextensions />
        <ext:contextmenus />
        <ext:lists />
        <ext:tabpages />
        <ext:toolbars />
        <ext:ribbontoolbars/>
      </ext:editorextension>
    </ext:editorextensions>
    <ext:dataextenders />
  </extensions>
  <commands />
  <contextmenus/>
  <localization/>
  <settings>
    <defaultpage/>
    <navigatorurl/>
    <editurls/>
    <listdefinitions/>
    <itemicons/>
    <theme>
      <path />
    </theme>
    <resourceextensions>
      <resourceextension>PublishDialogSettings</resourceextension>
    </resourceextensions>
    <customconfiguration/>
  </settings>
</Configuration>

added in system.config

<editor name="PublishDialogSettings">
    <installpath>E:\Tridion\web\WebUI\Editors\PublishDialogSettings\</installpath>
    <configuration>Configuration\PublishDialogSettings.config</configuration>
    <vdir/>
</editor>

UPDATE 2

I can now see the javascript file being used but the problem is that the iframe is not loaded yet when I try to use it (the TargetTypeList is inside an iframe).

I tried with this

$("#TargetTypeList_frame_details").load(function() {
    var targetCheckboxes = document.getElementById('TargetTypeList_frame_details').contentWindow.document.body.querySelectorAll('input[type="checkbox"]');
    for (var i = 0, len = targetCheckboxes.length; i < len; i++) {
        targetCheckboxes[i].checked = false;
    }
});

But I get: Uncaught TypeError: Cannot read property 'load' of undefined

Any ideas?

1
  • Glad that you were able to "invoke" your js, that is (more than) half of the struggle :). Unfortunately I'm not so good with js/Anguilla, but I would think that there is an event fired when the Publication Targets are loaded. If indeed yes, then you should execute your code in the handler.
    – Atila Sos
    Commented Mar 9, 2018 at 18:19

3 Answers 3

2

You can use this GUI UI Extention, It's working fine on Web8.5

SetPublishDefaultToUnCheckAllTargets.config

<?xml version="1.0"?>
<Configuration xmlns="http://www.sdltridion.com/2009/GUI/Configuration/Merge"
               xmlns:cfg="http://www.sdltridion.com/2009/GUI/Configuration"
               xmlns:ext="http://www.sdltridion.com/2009/GUI/extensions"
               xmlns:cmenu="http://www.sdltridion.com/2009/GUI/extensions/ContextMenu">

    <resources cache="true">
        <cfg:filters />
        <cfg:extensiongroups>
            <cfg:extensiongroup name="SetPublishDefaultToUnCheckAllTargets">
                <cfg:extension target="Tridion.Web.UI.Controls.RibbonToolbar">
                    <cfg:insertafter>SetPublishDefaultToUnCheckAllTargets</cfg:insertafter>
                </cfg:extension>
            </cfg:extensiongroup>
        </cfg:extensiongroups>
        <cfg:groups>
            <cfg:group name="SetPublishDefaultToUnCheckAllTargets">
                <cfg:fileset>
                    <cfg:file type="script">/js/PublishDialogSettings.js</cfg:file>
                </cfg:fileset>
            </cfg:group>
        </cfg:groups>
    </resources>
    <definitionfiles />
    <extensions>
        <ext:editorextensions/>
        <ext:dataextenders/>
    </extensions>
    <commands />
    <contextmenus />
    <localization />
    <settings>
        <defaultpage />
        <navigatorurl />
        <editurls/>
        <listdefinitions/>
        <itemicons/>
        <theme>
            <path/>
            <resourcegroup />
        </theme>
        <resourceextensions>
            <resourceextension>SetPublishDefaultToUnCheckAllTargets</resourceextension>
        </resourceextensions>
        <customconfiguration/>
    </settings>
</Configuration>

PublishDialogSettings.js

$evt.addEventHandler($display, "start", onPublishPopupOpenToSetPublishDefaultToUnCheckAllTargets);
    function onPublishPopupOpenToSetPublishDefaultToUnCheckAllTargets () {
        $evt.removeEventHandler($display, "start", onPublishPopupOpenToSetPublishDefaultToUnCheckAllTargets);

        if ($display.getView().getId() == "PublishPopup") {
            var ps = Tridion.UI.UserSettings.getPublishSettings();
            if (typeof ps !== 'undefined') 
            {
                for (var property in ps) {
                    if (property.startsWith("item_") && ps.hasOwnProperty(property)) {              
                        ps[property] = "unchecked";                                     
                    }
                }

                Tridion.UI.UserSettings.setPublishSettings(ps);
            }
        }   
    }

I hope it helps.

6
  • It works!!! Thx!!! Now, despite it works...isn't the use of property.startsWith("item_") a little bit hacky? I mean, if next version changes item_ with item- it will stop working... right?
    – polonskyg
    Commented Mar 14, 2018 at 12:54
  • Good to know its works for you, I'm not sure about the next version changes. Let's see I have my GUI Extention source here if required I can modify to support next version. github.com/avmgan/SetPublishDefaultToUnCheckAllTargets, if this solution useful for you upvote.
    – Velmurugan
    Commented Mar 14, 2018 at 16:57
  • Upvoted! Thx!!!
    – polonskyg
    Commented Mar 16, 2018 at 17:45
  • Hey, after upgrading to Web 8.5 Tridion.UI.UserSettings.getPublishSettings() is returning an empty json object. Any idea why?
    – polonskyg
    Commented May 7, 2018 at 21:23
  • check your Chrome Console is there any error, I'm not sure what is differs in your environment, try debugging in chrome inspect element PublishDialogSettings.js file add the "debugger" after this line $evt.removeEventHandler, you can able to see property values.
    – Velmurugan
    Commented May 8, 2018 at 7:14
5

Yes, you can achieve this with a UI extension. I haven't done this specific scenario, but this is similar to something that I have done, and that is to check the "Abort Publishing/Unpublishing on All Servers in Case of Error" option by default.

The trick is to create a UI extension without any additional Commands (the scenario which most of the examples out there represent) and have it applied to the appropriate "area".

The example below is for 2013sp1.

The extension config:

<?xml version="1.0"?>
<Configuration xmlns="http://www.sdltridion.com/2009/GUI/Configuration/Merge" 
    xmlns:cfg="http://www.sdltridion.com/2009/GUI/Configuration" 
    xmlns:ext="http://www.sdltridion.com/2009/GUI/extensions"  
    xmlns:cmenu="http://www.sdltridion.com/2009/GUI/extensions/ContextMenu">
    <resources cache="true">
        <cfg:extensiongroups>
            <cfg:extensiongroup name="PublishDialogSettings">
                <cfg:extension target="Tridion.Web.UI.Editors.CME.Views.Popups.Publish">         
                    <cfg:insertafter>MyCompany.PublishDialogSettings</cfg:insertafter>
                </cfg:extension>
            </cfg:extensiongroup>
        </cfg:extensiongroups>
        <cfg:groups>
            <cfg:group name="MyCompany.PublishDialogSettings">
                <cfg:fileset>
                    <cfg:file type="script">/Scripts/jquery.js</cfg:file>
                    <cfg:file type="script">/Scripts/PublishDialogSettings.js</cfg:file>
                </cfg:fileset>
            </cfg:group>
        </cfg:groups>
    </resources>
    <definitionfiles/>
    <extensions>
        <ext:editorextensions>
            <ext:editorextension target="CME">
                <ext:editurls />
                <ext:listdefinitions />
                <ext:taskbars />
                <ext:commands />
                <ext:commandextensions />
                <ext:contextmenus />
                <ext:lists />
                <ext:tabpages />
                <ext:toolbars />
                <ext:ribbontoolbars/>
            </ext:editorextension>
        </ext:editorextensions>
        <ext:dataextenders />
    </extensions>
    <commands />
    <contextmenus/>
    <localization/>
    <settings>
        <defaultpage/>
        <navigatorurl/>
        <editurls/>
        <listdefinitions/>
        <itemicons/>
        <theme>
            <path />
        </theme>
        <resourceextensions>
            <resourceextension>PublishDialogSettings</resourceextension>
        </resourceextensions>
        <customconfiguration/>
    </settings>
</Configuration>

The "Command" (PublishDialogSettings.js):

$evt.addEventHandler($display, "start", onDisplayStarted);

function onDisplayStarted() {
    $evt.removeEventHandler($display, "start", onDisplayStarted);

    $j("#abortOnError").prop("checked", true);
}

......

9
  • Thx! I'll try it, Is there any place in the docs where I can see any explanation of this? I didn't find anything...and I don't want to keep reverse engineering, inspecting elements or posting questions here for every little thing I have to do... :)
    – polonskyg
    Commented Mar 8, 2018 at 13:01
  • Unfortunately, I"m getting this error (shown in Chrome Console) Uncaught SyntaxError: Unexpected token < at eval (<anonymous>) at Function.globalEval (SDL.Client.Core.js:1) at JsFileHandler._render (SDL.Client.Core.js:3) at JsFileHandler.o.render (SDL.Client.Core.js:3) at Function.o.renderWhenLoaded (SDL.Client.Core.js:3) at eval (SDL.Client.Core.js:3) at Object.eval (SDL.Client.Core.js:3) at c (SDL.Client.Core.js:2) at Object.fireWith (SDL.Client.Core.js:2) at Object.fire (SDL.Client.Core.js:2) Any idea?
    – polonskyg
    Commented Mar 8, 2018 at 15:06
  • I don't find that character anyways
    – polonskyg
    Commented Mar 8, 2018 at 15:07
  • I have copied and pasted your code without changing a letter.. and added the editor in system.config
    – polonskyg
    Commented Mar 8, 2018 at 15:08
  • Which version of Tridion are you running?
    – Atila Sos
    Commented Mar 8, 2018 at 15:31
1

Looking at the publishing dialog, here's some snippets that may be useful to you:

c.TargetTypeList = $controls.getControl($("#TargetTypeList"), "Tridion.Controls.List");

^ This stores the target type list in your controls object

p.checkBoxView = c.TargetTypeList.getCurrentView();

^ This gets the view and stores in the properties

var selection = p.checkBoxView.getSelection();
return selection.getItems();

^ this gets the selected items from the list, here i'd inspect checkBoxView to see if there's a clear all method, or you can write a little loop to go through each item in there and clear them.

Please let me know if that helps.

P.S I'm assuming you're familiar with the conventions SDL uses for the c and p - you don't have to use these you could just store them in your own variables etc.

1
  • I'm using this: var targetTypeList = $controls.getControl($("#TargetTypeList"), "Tridion.Controls.List"); console.log ('targetTypeList: ' + targetTypeList); var checkBoxView = targetTypeList.TargetTypeList.getCurrentView(); console.log ('checkBoxView: ' + checkBoxView); var selection = checkBoxView.getSelection(); console.log ('selection.getItems(): ' + selection.getItems()); And the output is: targetTypeList: [object Object] Uncaught TypeError: Cannot read property 'getCurrentView' of undefined
    – polonskyg
    Commented Mar 13, 2018 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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