Display multiple messages on a custom Share Action
I’m sure you’ve all developed a custom Share Action by taking an example from the share-extra’s Google Code project.
The first time I’ve made my own cool custom Action, I’ve used the Backup Action as an example.
Normally one can re-use all of the code, but in some cases this example isn’t sufficient. In my case I wanted to have a Notify Action which shows a user messaged that a notification has been added or been removed. So I couldn’t have 1 success message. I could use the failure message, but that wouldn’t be a nice implementation in case something really went wrong.
So I’ve changed my Action a bit to show multiple messages.
The default client JS Action looked like this:
Alfresco.doclib.Actions.prototype.onActionNotify = function DL_onActionNotify(file) {
this.modules.actions.genericAction({
success : {
message : this.msg("message.notify.success", file.displayName),
events : [ {
name : "metadataRefresh"
} ]
},
failure : {
message : this.msg("message.notify.failure", file.displayName)
},
webscript : {
name : "notify/site/{site}/{container}",
method : Alfresco.util.Ajax.POST
},
params : {
site : this.options.siteId,
container : this.options.containerId
},
config : {
requestContentType : Alfresco.util.Ajax.JSON,
dataObj : {
nodeRefs : [ file.nodeRef ]
}
}
});
};
So I needed something like:
success1 : {
message : this.msg("message.notify.success1", file.displayName),
events : [ {
name : "metadataRefresh"
} ]
}success2 : {
message : this.msg("message.notify.success2", file.displayName),
events : [ {
name : "metadataRefresh"
} ]
},
failure : {
message : this.msg("message.notify.failure", file.displayName)
},
By default this isn’t possible, so instead using the success and failure handler I needed the real AJAX CallBackHandler.
After having contact with an Alfresco Engineer, who replied on my Forum Post. I’ve come up with the following code:
Alfresco.doclib.Actions.prototype.onActionNotify = function DL_onActionNotify(file) {
this.modules.actions.genericAction({
success : {
events : [ {
name : “metadataRefresh”
} ],
callback: {
fn : function DL_oAN_success(data){
var resultJson = YAHOO.lang.JSON.parse(data.serverResponse.responseText);
var added = resultJson.results[0].added;
if (added)
Alfresco.util.PopupManager.displayMessage({
text: this.msg(“message.notify.added”, file.displayName)
});
else
Alfresco.util.PopupManager.displayMessage({
text: this.msg(“message.notify.removed”, file.displayName)
});
},
scope : this
}
},
So I’ve replaced the message block within the success event with the callback block. Now I’ve got full control of the CallBackHandler.
The message block eventually called the Alfresco.util.PopulManager.displayMessage function. So now you’ve got to do it directly.
So this fixes the client side, now we only have to push the new added property from the Repository webscript.
The default result object looks like this:
var result = {
nodeRef: null,
action: “notifyAction”,
success: true,
}
So I’ve changed it to the following to get it to work:
var result = {
action: “notifyAction”,
success: true,
added: false
}
I don’t need the nodeRef so I’ve deleted it and added my own property.
This opens a whole new world into Share for me. By using the CallBackHandler I can use any Repository property I want and evaluate on the Client Side to build my logic.
