I have recently implemented a rename favorites feature for Tridion and in the process I am intercepting the AddUri
command and posing a prompt for the user to provide a new name for the favorite.
While testing the feature we have found the AddUri command is sometimes not called for the "Send to My Favorites" click, at least our prompt wasn't showing up in some cases.
For example: I added a page to favorites, my prompt showed up and I gave it a new name. Then I deleted it from the favorites. Then I added the page again to the favorites. This time my prompt for a new name did not show up.
Is there a different command or cache that I need to look at? For now I am refreshing the whole page after every delete of a favorite....
Here is command extension code for AddURI interception:
<cfg:group name="NewNameFavorites.CommandSet" merge="always" merger="Tridion.Web.UI.Core.Configuration.Resources.CommandGroupProcessor">
<cfg:fileset>
<cfg:file type="script">/NewNameFavorites/NewNameFavorites.js</cfg:file>
<cfg:file type="reference">NewNameFavorites.Interface</cfg:file>
</cfg:fileset>
<cfg:dependencies>
<cfg:dependency>Tridion.Web.UI.Editors.CME</cfg:dependency>
<cfg:dependency>Tridion.Web.UI.Editors.CME.commands</cfg:dependency>
</cfg:dependencies>
</cfg:group>
<ext:commandextensions>
<ext:commands>
<ext:command name="AddUri" extendingcommand="NewNameFavorites"/>
</ext:commands>
<ext:dependencies>
<cfg:dependency>NewNameFavorites.CommandSet</cfg:dependency>
</ext:dependencies>
</ext:commandextensions>
<cfg:commandset id="NewNameFavorites.Interface">
<cfg:command name="NewNameFavorites" implementation="Commands.NewNameFavorites" />
</cfg:commandset>
Here is the JS code:
Type.registerNamespace("Commands");
Commands.NewNameFavorites= function NewNameFavorites() {
Type.enableInterface(this, "Commands.NewNameFavorites");
this.addInterface("Tridion.Cme.Command", ["NewNameFavorites"]);
};
Commands.NewNameFavorites.prototype._isAvailable = function NewNameFavorites$_isAvailable(selection, pipeline) {
console.debug("Favorites Is Available called");
if (pipeline)
pipeline.stop = false;
return $cme.getCommand("AddUri")._isAvailable(selection, pipeline);
};
FavoritesReload = function (event) {
$models.$cme.getShortcuts().getList().unload();
};
Commands.NewNameFavorites.prototype._isEnabled = function NewNameFavorites$_isEnabled(selection, pipeline) {
console.debug("Favorites Is Enabled called");
if (pipeline)
pipeline.stop = false;
try {
var view = $display.getView();
var list = view.getListObject("cme:shortcuts");
list.removeEventListener("itemadd", FavoritesReload);
list.removeEventListener("itemupdate", FavoritesReload);
list.addEventListener("itemadd", FavoritesReload);
list.addEventListener("itemupdate", FavoritesReload);
}
catch (err) {
console.debug("Favorites Reload Error occured: " + err);
}
return $cme.getCommand("AddUri")._isEnabled(selection, pipeline);
};
Commands.NewNameFavorites.prototype._execute = function NewNameFavorites$_execute(selection, pipeline) {
console.debug("Favorites Execute called");
if (pipeline)
pipeline.stop = false;
$cme.getCommand("AddUri")._execute(selection, pipeline);
var arrItems = [];
//selectedItem = selection.getItems()[0];
var itemsProcessed = 0;
var items = Array.clone(selection.getItems());
var itemsLen = items.length;
var addFavoritesCustomTitle = function (event) {
var username = Tridion.ContentManager.UserSettings.getInstance().getUserName();//Tridion.UI.UserSettings.getJsonUserSettings(true).User["@ID"];
username = username.replace('\\', '\\\\');
var customTitles = JSON.stringify(arrItems);
var serviceURL = "/ManageAppData.svc/AddFavoritesCustomTitles";
var favoriteData = '{"username" : "' + username + '","customTitles" : ' + customTitles + '}'; //
$j.ajax({
type: "POST",
data: favoriteData,
dataType: "json",
contentType: 'application/json; charset=utf-8',
url: serviceURL,
cache: false,
success: function () {
$models.$cme.getShortcuts().getList().unload();
},
error: function () {
alert('Error Renaming Favoties!');
}
});
};
var itemLoad = function (event) {
var item = this;
var itemId, itemTitle;
$evt.removeEventHandler(item, "load", itemLoad);
itemId = item.getId();
itemTitle = item.getTitle();
var newTitle = prompt("Enter Title for the Favorite", itemTitle);
newTitle = newTitle.replace(/[^A-Za-z0-9-_\s]/g, '');
newTitle = newTitle.trim();
if (!newTitle) newTitle = itemTitle;
if (newTitle != itemTitle) {
if (item && Type.isFunction(item.getTCMItemId)) {
if (refId = item.getTCMItemId()) {
itemId = refId;
}
}
newTitle = newTitle.replace(/[^A-Za-z0-9-_\s]/g, '');
arrItems.push({ "itemId": itemId, "newTitle": newTitle });
}
itemsProcessed++;
if (itemsLen == itemsProcessed) addFavoritesCustomTitle();
};
for (var i = 0; i < itemsLen; i++) {
var item = $models.getItem(items[i]);
$evt.addEventHandler(item, "load", itemLoad);
item.load();
}
};
interception
? Are you doinginterception
throught command extension?