Stackedit/js/extensions/dialogManagePublication.js

62 lines
2.4 KiB
JavaScript
Raw Normal View History

2013-05-27 19:45:33 +00:00
define([
"jquery",
2013-06-10 21:22:32 +00:00
"underscore",
"text!html/dialogManagePublicationLocation.html",
], function($, _, dialogManagePublicationLocationHTML) {
2013-05-29 19:55:23 +00:00
2013-06-10 21:22:32 +00:00
var dialogManagePublication = {
extensionId: "dialogManagePublication",
extensionName: 'Dialog "Manage publication"',
2013-05-29 19:55:23 +00:00
settingsBloc: '<p>Populates the "Manage publication" dialog box.</p>'
};
2013-06-16 10:47:35 +00:00
var extensionMgr = undefined;
dialogManagePublication.onExtensionMgrCreated = function(extensionMgrParameter) {
extensionMgr = extensionMgrParameter;
2013-05-29 19:55:23 +00:00
};
var fileDesc = undefined;
var removeButtonTemplate = '<a class="btn" title="Remove this location"><i class="icon-trash"></i></a>';
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, ", ");
2013-06-10 21:22:32 +00:00
var lineElement = $(_.template(dialogManagePublicationLocationHTML, {
2013-05-29 19:55:23 +00:00
provider: publishAttributes.provider,
publishDesc: publishDesc
}));
lineElement.append($(removeButtonTemplate).click(function() {
2013-06-16 10:47:35 +00:00
fileDesc.removePublishLocation(publishAttributes);
2013-06-16 18:29:54 +00:00
extensionMgr.onPublishRemoved(fileDesc, publishAttributes);
2013-05-29 19:55:23 +00:00
}));
publishList.append(lineElement);
});
};
2013-06-10 21:22:32 +00:00
dialogManagePublication.onFileSelected = function(fileDescParameter) {
2013-05-29 19:55:23 +00:00
fileDesc = fileDescParameter;
refreshDialog(fileDescParameter);
};
2013-06-10 21:22:32 +00:00
dialogManagePublication.onNewPublishSuccess = refreshDialog;
dialogManagePublication.onPublishRemoved = refreshDialog;
2013-05-29 19:55:23 +00:00
2013-06-10 21:22:32 +00:00
return dialogManagePublication;
2013-05-29 19:55:23 +00:00
2013-05-26 22:59:17 +00:00
});