6

I am trying to catch the FinishActivity in the UI/UX when a user selects the option from a Page or Component.

Using the standard method of adding the extended command in the relevant config file I am able to add the interface and catch the isAvailable method using the scripts shown below.

Tridion.Extensions.CheckTitleOnFinishActivitySE = function Commands$CheckTitleOnFinishActivitySE() {
    Tridion.OO.enableInterface(this, "Tridion.Cme.Commands.CheckTitleOnFinishActivitySE");
    this.addInterface("Tridion.Web.UI.Editors.SiteEdit.Commands.FACommand", ["CheckTitleOnFinishActivitySE", $const.AllowedActions.FinishActivity]);
};
Tridion.Extensions.CheckTitleOnFinishActivitySE.prototype._isAvailable = function (selection) {
    var response = Tridion.Web.UI.Editors.SiteEdit.Commands.FinishActivity.prototype._isAvailable(selection);
};

However, when I attempt to reuse the exisitng isEnabled function:

Tridion.Extensions.CheckTitleOnFinishActivitySE.prototype.isEnabled = function (selection) {
    var response = Tridion.Web.UI.Editors.SiteEdit.Commands.FinishActivity.prototype._isEnabled(selection);
};

or even copying the existing code from the siteedit function itself (which I'd obviously rather not do)

Tridion.Extensions.CheckTitleOnFinishActivitySE.prototype.isEnabled = function (selection) {
    return (selection && selection.getProperty && selection.getProperty("isSEPage")) && 
        this.callBase("Tridion.Cme.Command", "_isEnabled", [selection]);
};

I receieve the following error:

Can't execute the command "FinishActivity" on [tcm:8-349-131200]. Reason: not enabled.

I can force the state to enabled by using just return true from the isEnabled function but I'd rather inherit/reuse the existing check to cater for current and future scenarios...

I can confirm the _isAvailable is caught and returns true and that the required function to extend is isEnabled and not _isEnabled (adding the latter alone or in addition to isEnabled has no effect)

Any advice would be splendid!

Thanks in advance.

Update - debug addition

So, I added the following into my extended isEnabled to track the difference between the response on the selection object in my isEnabled 'v' the default isEnabled:

The 'workflow.js' shows the value if the isSEPage property as true - but when checked directly in my function it's false. It reads consistent then that when called from my isEnabled into the original it then returns false also. I don't understand what could happen to the selection or that I'd be dealing with a different selection object/context?

Updated extended isEnabled with debug scripts:

Tridion.Extensions.CheckTitleOnFinishActivitySE.prototype.isEnabled = function (selection) {

    $log.message('myfile.js::FinishActivity.prototype._isEnabled::selection.getProperty("isSEPage") = ' + selection.getProperty("isSEPage"));

    $log.message('myfile.js::FinishActivity.prototype.isEnabled ==> checking calling original...');
    var response = Tridion.Web.UI.Editors.SiteEdit.Commands.FinishActivity.prototype._isEnabled(selection);
    $log.message('myfile.js::FinishActivity.prototype.isEnabled ==> ' + response);


    $log.message('myfile.js::FinishActivity.prototype.isEnabled ==> checking using copied code from original...');
    return (selection && selection.getProperty && selection.getProperty("isSEPage")) &&
        this.callBase("Tridion.Cme.Command", "_isEnabled", [selection]);


};

Output (workflow.js represents the original workflow value for the same evaluation)

workflow.js:FinishActivity.prototype._isEnabled::selection.getProperty("isSEPage") = true myfile.js::FinishActivity.prototype._isEnabled::selection.getProperty("isSEPage") = undefined myfile.js::FinishActivity.prototype.isEnabled ==> checking calling original... workflow.js:FinishActivity.prototype._isEnabled::selection.getProperty("isSEPage") = undefined myfile.js::FinishActivity.prototype.isEnabled ==> undefined myfile.js::FinishActivity.prototype.isEnabled ==> checking using copied code from original... Can't execute the command "CheckTitleOnFinishActivitySE" on [tcm:8-349-131200]. Reason: not enabled.

More debug

I see that in the original CME workflow script there is no isEnabled function at all?

I added the following to the extended isEnabled scipt:

Tridion.Extensions.CheckTitleOnFinishActivitySE.prototype.isEnabled = function (selection) {

    $log.message('myfile.js::FinishActivity.prototype._isEnabled::selection.getProperty("isSEPage") = ' + selection.getProperty("isSEPage"));
    $log.message('Tridion.Web.UI.Editors.SiteEdit.Commands.FinishActivity.prototype._isEnabled(selection) = ' + Tridion.Web.UI.Editors.SiteEdit.Commands.FinishActivity.prototype._isEnabled(selection));

$log.message('this.callBase("Tridion.Cme.Command", "_isEnabled", [selection]) = ' + this.callBase("Tridion.Cme.Command", "_isEnabled", [selection]));

resulting in:

myfile.js::FinishActivity.prototype._isEnabled::selection.getProperty("isSEPage") = undefined Editor_v6.1.0.55920.269_.aspx:7175 workflow.js:FinishActivity.prototype._isEnabled::selection.getProperty("isSEPage") = undefined Editor_v6.1.0.55920.269_.aspx:7175 Tridion.Web.UI.Editors.SiteEdit.Commands.FinishActivity.prototype._isEnabled(selection) = undefined Editor_v6.1.0.55920.269_.aspx:7175 this.callBase("Tridion.Cme.Command", "_isEnabled", [selection]) = false

Although the original (SiteEdit) is still being executed prior to my script and returns

workflow.js::FinishActivity.prototype._isEnabled::selection.getProperty("isSEPage") = true

I'm wondering if the Tridion SiteEdit isEnabled is being checked on selection of the option to FinishActivity and my extension is being executed when the FinishActivity action itself is instantiated. I'm looking further but if anyone sees anything in the iterim that would be great!

Thanks

  • Can you clarify what is your goal? because it's not fully clear what exactly you are trying to achieve. When dealing whith Commands, there are three options: - Create totally new Command implementation (inherit from "Tridion.Core.Command") - Create new Command and inherit it from one of the existing Commands (so it will have all the same functionality, as source Command, and extra functionlity, which you'll add) - Create Command-extension to existing Command. And that's only way how you can influence on behavior of the existing Commands in CME or SiteEdit. – Boris Ponomarenko Dec 18 '12 at 15:45
  • Hi Boris. We want to 'force' a user to enter some metadata (if it's not already entered - via a modal dialog) before the item is saved as a minor version. We can see that the SaveAll command is applied to the Save Draft button and have tried to add a log message when the SaveAll command is triggered - but the log message doesn't register - so when is the SaveAll _executed? Is it safe to apply the checking/forcing of the meta against this (extended) function – Dylan .. Mark Saunders Dec 18 '12 at 20:32
  • - this would avoid having to extend many other commands such as FinishEditing, StartActivity, FinishActivity etc. as we could ensure the same application as the CME version which simply hooks into Save, SaveNew and SaveClose? - if there is a SiteEdit extension then this would be the one we extend as we only intend to add this metadata and then resume the normal pipeline/state of affairs. Thanks for any comment. – Dylan .. Mark Saunders Dec 18 '12 at 20:33
  • UPDATE: the issue seems to be with my expectation of the SaveAll (seemingly?) being triggered on exit of the component when a minor version is created. It seems black magic at work as the command associated with the Save Draft icon doesn't seem to be invoked - yet when I physically enable the same Save Draft button, clicking it does trigger the SaveAll command (and therefore my extended code)... – Dylan .. Mark Saunders Dec 19 '12 at 05:07
  • 1. Explicit action triggered by click on "Save Draft" toolbar button and implicit save action, when user "leaves" the Component - are two different actions. 2. Have you tried search? There are few topics where you can find info on how to extend existing Commands: http://stackoverflow.com/questions/12410599/how-can-a-tridion-command-extension-find-out-the-command-it-extends http://stackoverflow.com/questions/12457823/how-to-extend-checkout-command-in-sdl-tridion-2011-sp1 http://stackoverflow.com/questions/11936363/whats-the-difference-between-isenabled-and-isenabled-in-anguilla – Boris Ponomarenko Dec 19 '12 at 08:54
  • Hi Boris, just to confirm - the issue was that there isn't a direct method triggered on entering the component - in fact, the item is checked out - if no change is detected when exited then undocheckout is triggered and we can't extend off this without going into backend coding. It seems, however, that the validate (checks if changed etc.) *is* triggered so I'm going to try extending of this to catch all interaction on the page. – Dylan .. Mark Saunders Dec 28 '12 at 13:05
  • CME framework is event-based. You always can listen for a specific event on an item from Model Repository. (event like "save", "savefailed", "undocheckout" etc.) – Boris Ponomarenko Jan 11 '13 at 08:26
  • Indeed Boris - we're looking into the use of the 'validate' method as this is called to (currently) check if a change has occurred and whether or not to action the requested event - so we should catch most user intentions in there. – Dylan .. Mark Saunders Jan 11 '13 at 12:32

1 Answers1

1

OK! So the Tridion SiteEdit instance of isEnabled is executed when the user selects the icon to trigger the ShowActivityStartedPopup Command.

My isEnabled is triggered when the FininshActivity option is selected by the user.

Can anyone see a quicker way I could have gotten to this conclusion... or if this conclusion is not correct...

Thanks