With Méthode Swing it’s possible to add custom manipulation to the content of a channel copy after his creation.
Registration of a custom manipulation
To register a custom manipulation, use the following namespace
eidosmedia.webclient.extensions.channelCopy
and its function
register( options )
Method |
|
Parameter |
Required |
Returns |
|
The following is a very simple registration for a custom manipulation.
(function() {
eidosmedia.webclient.extensions.channelCopy.register(function( data, callback ) {
// Save the current content of the channel copy
var xmlElaborated = data.xmlContent;
try {
/**
* Save the current content of the channel copy. This variable will be used to make some changes to the current content
*/
var xmlContent = data.xmlContent;
/**
* Save information about the current channel copy. For example the channel name
*/
var copyInfo = data;
/**
* Perform some simple manipulation. In our case add only a new attribute
*/
var xml = $.parseXML(xmlContent);
var $xml = $(xml);
var $doc = $xml.find('doc');
$doc.attr('newattr', 'newvalue');
/**
* Serialize the new xml content
*/
var serializer = new XMLSerializer();
var preValue = xmlElaborated.slice(0, xmlElaborated.indexOf('<doc'));
var result = serializer.serializeToString($doc[0]);
/**
* Save the new xml content
*/
xmlElaborated = preValue + result;
/**
* notify a callback if specified
*/
if (callback) {
callback(xmlElaborated);
}
} catch (ex) {
console.log("Channel copy custom manipulation exception caught", ex);
if (callback) {
callback(xmlElaborated);
}
}
});
})();
|
The function must be have two parameters. The first one contains info about xml content and the channel object info. The second one it’s a callback that must be invoked after the custom manipulation. Wrap all the custom manipulation with a try…catch block otherwise the normal process of the channel copy creation will be not performed. After the custom manipulation the system will perform a validation check of the new content. If the check goes wrong the channel copy will be created with the original content and the user will be notified |