").addClass("input-prepend input-append");
if (publishObject.provider == PUBLISH_PROVIDER_GITHUB) {
line.append($("
").addClass("add-on").prop("title", "GitHub").html(
''));
line.append($("").prop("type", "text").prop(
"disabled", true).addClass("span5").val(
serializedObject));
}
else if (publishObject.provider == PUBLISH_PROVIDER_BLOGGER) {
line.append($("").addClass("add-on").prop("title", "Blogger").html(
''));
line.append($("").prop("type", "text").prop(
"disabled", true).addClass("span5").val(
serializedObject));
}
line.append($("").addClass("btn").html(
'').prop("title",
"Remove this location").click(function() {
fileManager.removePublish(publishIndex);
}));
$("#manage-publish-list").append(line);
})(publishIndex, JSON.parse(serializedObject), serializedObject.replace(/{|}|"/g, ""));
}
}
// Initialize the "New publication" dialog
var newPublishProvider = undefined;
function initNewPublish(provider, defaultPublishFormat) {
defaultPublishFormat = defaultPublishFormat || "markdown";
newPublishProvider = provider;
// Show/hide controls depending on provider
$('div[class*=" modal-publish-"]').hide().filter(".modal-publish-" + provider).show();
// Reset fields
core.resetModalInputs();
$("input:radio[name=radio-publish-format][value=" + defaultPublishFormat + "]").prop("checked", true);
// Open dialog box
$("#modal-publish").modal();
}
// Generate a publishIndex, store a publishObject and associate it to a fileIndex
function createPublishIndex(publishObject, fileIndex) {
var publishIndex = undefined;
do {
publishIndex = "publish." + core.randomString();
} while(localStorage[publishIndex] !== undefined);
localStorage[publishIndex] = JSON.stringify(publishObject);
localStorage[fileIndex + ".publish"] += publishIndex + ";";
}
// Create a new publication on GitHub
function newPublishGithub(event) {
var publishObject = {};
publishObject.repository = core.getInputValue($("#input-publish-github-reponame"), event);
publishObject.branch = core.getInputValue($("#input-publish-github-branch"), event);
publishObject.path = core.getInputValue($("#input-publish-github-path"), event);
publishObject.provider = newPublishProvider;
if(event.isPropagationStopped()) {
return;
}
var fileIndex = fileManager.getCurrentFileIndex();
var title = localStorage[fileIndex + ".title"];
var content = publisher.getPublishContent(publishObject);
var commitMsg = core.settings.commitMsg;
githubHelper.upload(publishObject.repository,
publishObject.branch, publishObject.path, content, commitMsg,
function(error) {
if(error === undefined) {
createPublishIndex(publishObject, fileIndex);
refreshManagePublish();
publisher.notifyCurrentFile();
core.showMessage('"' + title
+ '" will now be published on GitHub.');
}
});
}
// Create a new publication on Blogger
function newPublishBlogger(event) {
var blogUrl = core.getInputValue($("#input-publish-blogger-url"), event);
if(event.isPropagationStopped()) {
return;
}
googleHelper.getBlogByUrl(blogUrl, function(blog) {
console.log(blog);
});
}
fileManager.init = function(coreModule) {
core = coreModule;
fileManager.selectFile();
$(".action-create-file").click(function() {
var fileIndex = fileManager.createFile();
fileManager.selectFile(fileIndex);
$("#file-title").click();
});
$(".action-remove-file").click(function() {
fileManager.deleteFile();
fileManager.selectFile();
});
$("#file-title").click(function() {
$(this).hide();
$("#file-title-input").show().focus();
});
$("#file-title-input").blur(function() {
var title = $.trim($(this).val());
if (title) {
var fileIndexTitle = fileManager.getCurrentFileIndex() + ".title";
if (title != localStorage[fileIndexTitle]) {
localStorage[fileIndexTitle] = title;
fileManager.updateFileTitles();
fileManager.saveFile();
}
}
$(this).hide();
$("#file-title").show();
});
$(".action-download-md").click(
function() {
var content = $("#wmd-input").val();
var uriContent = "data:application/octet-stream;base64,"
+ core.encodeBase64(content);
window.open(uriContent, 'file');
});
$(".action-download-html").click(
function() {
var content = $("#wmd-preview").html();
var uriContent = "data:application/octet-stream;base64,"
+ core.encodeBase64(content);
window.open(uriContent, 'file');
});
// Synchronize actions
$(".action-upload-gdrive-root").click(function() {
uploadGdrive();
});
$(".action-upload-gdrive-select").click(function() {
// This action is not available because picker does not support
// folder selection
googleHelper.picker(function(ids) {
if(ids !== undefined && ids.length !== 0) {
uploadGdrive(undefined, ids[0]);
}
}, true);
});
$(".action-download-gdrive").click(function() {
googleHelper.picker(importGdrive);
});
$(".action-manual-gdrive").click(function(event) {
var fileId = core.getInputValue($("#manual-gdrive-fileid"), event);
manualGdrive(fileId);
});
$(".action-download-dropbox").click(function() {
dropboxHelper.picker(importDropbox);
});
$(".action-upload-dropbox").click(function(event) {
var path = core.getInputValue($("#upload-dropbox-path"), event);
manualDropbox(path);
});
$(".action-manual-dropbox").click(function(event) {
var path = core.getInputValue($("#manual-dropbox-path"), event);
manualDropbox(path);
});
// Publish actions
$(".action-publish-github").click(function() {
initNewPublish(PUBLISH_PROVIDER_GITHUB);
});
$(".action-publish-blogger").click(function() {
initNewPublish(PUBLISH_PROVIDER_BLOGGER, "html");
});
$(".action-process-publish").click(function(e) {
if(newPublishProvider == PUBLISH_PROVIDER_GITHUB) {
newPublishGithub(e);
}
else if(newPublishProvider == PUBLISH_PROVIDER_BLOGGER) {
newPublishBlogger(e);
}
});
};
return fileManager;
});