define([
"jquery",
"underscore"
], function($, _) {
var managePublication = {
extensionId: "managePublication",
extensionName: "Manage publication",
settingsBloc: '
Populates the "Manage publication" dialog box.
'
};
var fileMgr = undefined;
managePublication.onFileMgrCreated = function(fileMgrParameter) {
fileMgr = fileMgrParameter;
};
var fileDesc = undefined;
var lineTemplate = [
'',
' ',
' ',
' ',
' ',
'
'
].join("");
var removeButtonTemplate = '';
var refreshDialog = function(fileDescParameter) {
if(fileDescParameter !== undefined && fileDescParameter !== fileDesc) {
return;
}
var publishAttributesList = _.values(fileDesc.publishLocations);
$(".msg-no-publish, .msg-publish-list").addClass("hide");
var publishList = $("#manage-publish-list").empty();
if(publishAttributesList.length > 0) {
$(".msg-publish-list").removeClass("hide");
}
else {
$(".msg-no-publish").removeClass("hide");
}
_.each(publishAttributesList, function(publishAttributes) {
formattedAttributes = _.omit(publishAttributes, "provider", "publishIndex", "sharingLink");
if(formattedAttributes.password) {
formattedAttributes.password = "********";
}
var publishDesc = JSON.stringify(formattedAttributes).replace(/{|}|"/g, "").replace(/,/g, ", ");
var lineElement = $(_.template(lineTemplate, {
provider: publishAttributes.provider,
publishDesc: publishDesc
}));
lineElement.append($(removeButtonTemplate).click(function() {
fileMgr.removePublish(publishAttributes);
}));
publishList.append(lineElement);
});
};
managePublication.onFileSelected = function(fileDescParameter) {
fileDesc = fileDescParameter;
refreshDialog(fileDescParameter);
};
managePublication.onNewPublishSuccess = refreshDialog;
managePublication.onPublishRemoved = refreshDialog;
return managePublication;
});