Stackedit/res/extensions/dialogManagePublication.js

73 lines
2.9 KiB
JavaScript
Raw Permalink Normal View History

2013-05-27 19:45:33 +00:00
define([
"jquery",
2013-06-10 21:22:32 +00:00
"underscore",
2013-06-22 23:48:57 +00:00
"classes/Extension",
2013-06-10 21:22:32 +00:00
"text!html/dialogManagePublicationLocation.html",
2013-06-22 23:48:57 +00:00
], function($, _, Extension, dialogManagePublicationLocationHTML) {
2013-05-29 19:55:23 +00:00
2013-08-21 00:16:10 +00:00
var dialogManagePublication = new Extension("dialogManagePublication", 'Dialog "Manage publication"', false, true);
2013-05-29 19:55:23 +00:00
2013-07-30 08:46:36 +00:00
var eventMgr = undefined;
dialogManagePublication.onEventMgrCreated = function(eventMgrParameter) {
eventMgr = eventMgrParameter;
2013-05-29 19:55:23 +00:00
};
var fileDesc = undefined;
2013-08-14 23:44:51 +00:00
var publishListElt = undefined;
var $msgPublishListElt = undefined;
var $msgNoPublishElt = undefined;
2013-05-29 19:55:23 +00:00
var refreshDialog = function(fileDescParameter) {
if(fileDescParameter !== undefined && fileDescParameter !== fileDesc) {
return;
}
2013-08-14 23:44:51 +00:00
if(_.size(fileDesc.publishLocations) > 0) {
$msgPublishListElt.removeClass("hide");
$msgNoPublishElt.addClass("hide");
2013-05-29 19:55:23 +00:00
}
else {
2013-08-14 23:44:51 +00:00
$msgPublishListElt.addClass("hide");
$msgNoPublishElt.removeClass("hide");
2013-05-29 19:55:23 +00:00
}
2013-08-14 23:44:51 +00:00
var publishListHtml = _.reduce(fileDesc.publishLocations, function(result, publishAttributes) {
var formattedAttributes = _.omit(publishAttributes, "provider", "publishIndex", "sharingLink");
2013-05-29 19:55:23 +00:00
if(formattedAttributes.password) {
formattedAttributes.password = "********";
}
2013-08-14 23:44:51 +00:00
formattedAttributes = JSON.stringify(formattedAttributes).replace(/{|}|"/g, "").replace(/,/g, ", ");
return result + _.template(dialogManagePublicationLocationHTML, {
publishAttributes: publishAttributes,
publishDesc: formattedAttributes
});
}, '');
publishListElt.innerHTML = publishListHtml;
_.each(publishListElt.querySelectorAll('.remove-button'), function(removeButtonElt) {
var $removeButtonElt = $(removeButtonElt);
var publishAttributes = fileDesc.publishLocations[$removeButtonElt.data('publishIndex')];
$removeButtonElt.click(function() {
2013-06-16 10:47:35 +00:00
fileDesc.removePublishLocation(publishAttributes);
2013-07-30 08:46:36 +00:00
eventMgr.onPublishRemoved(fileDesc, publishAttributes);
2013-08-14 23:44:51 +00:00
});
2013-05-29 19:55:23 +00:00
});
};
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-08-14 23:44:51 +00:00
dialogManagePublication.onReady = function() {
var modalElt = document.querySelector(".modal-manage-publish");
publishListElt = modalElt.querySelector(".publish-list");
$msgPublishListElt = $(modalElt.querySelectorAll(".msg-publish-list"));
$msgNoPublishElt = $(modalElt.querySelectorAll(".msg-no-publish"));
};
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
});