Stackedit/public/res/extensions/buttonPublish.js

86 lines
2.3 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-10-06 14:34:40 +00:00
"crel",
2013-06-22 23:48:57 +00:00
"classes/Extension",
2013-10-06 14:34:40 +00:00
], function($, _, crel, Extension) {
2013-05-29 19:55:23 +00:00
2013-06-22 23:48:57 +00:00
var buttonPublish = new Extension("buttonPublish", 'Button "Publish"');
2013-08-04 17:42:22 +00:00
// buttonPublish.settingsBlock = '<p>Adds a "Publish document" button in the
// navigation bar.</p>';
2013-05-29 19:55:23 +00:00
2013-11-07 23:10:38 +00:00
var $button;
var currentFileDesc;
2013-05-29 19:55:23 +00:00
var publishRunning = false;
var hasPublications = false;
var isOffline = false;
// Enable/disable the button
function updateButtonState() {
2013-10-08 00:34:15 +00:00
if($button === undefined) {
2013-05-29 19:55:23 +00:00
return;
}
if(publishRunning === true || hasPublications === false || isOffline === true) {
2013-10-08 00:34:15 +00:00
$button.addClass("disabled");
2013-05-29 19:55:23 +00:00
}
else {
2013-10-08 00:34:15 +00:00
$button.removeClass("disabled");
2013-05-29 19:55:23 +00:00
}
}
2013-11-07 23:10:38 +00:00
var publisher;
2013-05-29 19:55:23 +00:00
buttonPublish.onPublisherCreated = function(publisherParameter) {
publisher = publisherParameter;
};
buttonPublish.onCreateButton = function() {
2014-03-12 00:53:15 +00:00
var button = crel('a', {
2013-10-06 14:34:40 +00:00
class: 'btn btn-success button-publish',
2013-11-20 18:47:49 +00:00
title: 'Update document publication'
2013-10-06 14:34:40 +00:00
}, crel('i', {
2014-03-17 02:01:46 +00:00
class: 'icon-upload'
2013-10-06 14:34:40 +00:00
}));
2013-10-08 00:34:15 +00:00
$button = $(button).click(function() {
2013-10-06 14:34:40 +00:00
if(!$button.hasClass("disabled")) {
2013-05-29 19:55:23 +00:00
publisher.publish();
}
});
2013-10-06 14:34:40 +00:00
return button;
2013-05-29 19:55:23 +00:00
};
buttonPublish.onPublishRunning = function(isRunning) {
publishRunning = isRunning;
updateButtonState();
};
buttonPublish.onOfflineChanged = function(isOfflineParameter) {
isOffline = isOfflineParameter;
updateButtonState();
};
// Check that current file has publications
var checkPublication = function() {
if(_.size(currentFileDesc.publishLocations) === 0) {
hasPublications = false;
}
else {
hasPublications = true;
}
updateButtonState();
};
buttonPublish.onFileSelected = function(fileDesc) {
currentFileDesc = fileDesc;
checkPublication();
};
2014-04-20 01:13:43 +00:00
buttonPublish.onReady = function() {
$(".action-update-publication").click(publisher.publish);
};
2013-05-29 19:55:23 +00:00
buttonPublish.onPublishRemoved = checkPublication;
buttonPublish.onNewPublishSuccess = checkPublication;
return buttonPublish;
2014-04-20 01:13:43 +00:00
});