2

How can I detect if the user clicked Save or Save and Close?

$evt.addEventHandler(item, "save", this.getDelegate(this.onItemSave));

onItemSave = function (ev) {//code}

Inside onItemSave function, ev.type = "save" and ev.name = "save" in both cases.

1
  • 1
    did you try for ev.type="save" && ev.type="checkin" for save and close? Commented Mar 30, 2016 at 16:53

1 Answer 1

3

What I did in an extension where I had different behaviors depending on whether you clicked Save, SaveClose or SaveNew was to:

  1. Register my commands as extensions of the existing commands:
<ext:commands>
    <ext:command name="Save" extendingcommand="ReleaseValidationOnSave"/>
    <ext:command name="SaveClose" extendingcommand="ReleaseValidationOnSaveClose"/>
    <ext:command name="SaveNew" extendingcommand="ReleaseValidationOnSaveNew"/>
</ext:commands>
  1. Then on each of those methods that would be called I would set a variable identifying which was the original command
CompanyName.Extensions.ReleaseValidationOnSaveClose.prototype._execute = function ReleaseValidationOnSaveClose$_execute(selection, pipeline) {
    if (!this.properties.InitialCommand) {
        this.properties.InitialCommand = "SaveClose";
    }
    return $cme.getCommand("ReleaseValidationOnSave")._execute(selection, pipeline, this.properties.InitialCommand);
};
  1. Finally, on my "ReleaseValidationOnSave" code I would check the value of this.properties.InitialCommand and let the UI resume that command's execution:
// This function is triggered by the event "finish"
// It invokes the original command intended by the editor
CompanyName.Extensions.ReleaseValidationOnSave.prototype._onResumeExecution = function ReleaseValidationOnSave$_onResumeExecution() {
    $evt.removeAllEventHandlers(this, "finish");
    var p = this.properties;
    $cme.getCommand(p.InitialCommand)._execute(p.selection, p.pipeline);
};

Basically this allowed me to "inject" my command before the UI's own, and also let me invoke the original command once my code was done running.

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.