Added folder ID in the Google Drive export dialog. Implemented export/publish preferences by storing last input values. Fixes #5

This commit is contained in:
benweet 2013-05-22 22:54:14 +01:00
parent 45972cd945
commit 4664ecd1b0
11 changed files with 102 additions and 25 deletions

View File

@ -203,7 +203,6 @@ hr {
#file-selector { #file-selector {
max-height: 500px; max-height: 500px;
overflow-y: auto; overflow-y: auto;
overflow-x: hidden;
} }
#file-selector .stick { #file-selector .stick {

View File

@ -100,8 +100,7 @@
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="#" class="action-sync-import-gdrive">Import <li><a href="#" class="action-sync-import-gdrive">Import
from Google Drive</a></li> from Google Drive</a></li>
<li><a href="#" data-toggle="modal" <li><a href="#" class="action-sync-export-dialog-gdrive">Export
data-target="#modal-upload-gdrive" class="action-reset-input">Export
to Google Drive</a></li> to Google Drive</a></li>
</ul></li> </ul></li>
<li class="dropdown-submenu"><a href="#"><i <li class="dropdown-submenu"><a href="#"><i
@ -109,8 +108,7 @@
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a class="action-sync-import-dropbox" href="#">Import <li><a class="action-sync-import-dropbox" href="#">Import
from Dropbox</a></li> from Dropbox</a></li>
<li><a href="#" data-toggle="modal" <li><a href="#" class="action-sync-export-dialog-dropbox">Export
data-target="#modal-upload-dropbox" class="action-reset-input">Export
to Dropbox</a></li> to Dropbox</a></li>
</ul></li> </ul></li>
<li><a href="#" data-toggle="modal" <li><a href="#" data-toggle="modal"
@ -215,11 +213,24 @@
<h3>Export to Google Drive</h3> <h3>Export to Google Drive</h3>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<p>This will upload the current document into your Google Drive <blockquote class="muted">This will upload the current
root folder and keep it synchronized.</p> document to your Google Drive account and keep it synchronized.</blockquote>
<p>Here, you can specify a <b>folder ID</b> (optional):
</p>
<div class="input-prepend">
<span class="add-on"><i class="icon-gdrive"></i></span><input
id="input-sync-export-gdrive-parentid" type="text" class="span5"
placeholder="FolderID"></input>
</div>
<br /> <br />
<blockquote class="muted"> <blockquote class="muted">
<b>NOTE:</b> You can move or rename the file afterwards within <b>NOTE:</b>
Google Drive. <ul>
<li>If no folder ID is supplied, the file will be created in
your root folder.</li>
<li>You can move or rename the file afterwards within Google
Drive.</li>
</ul>
</blockquote> </blockquote>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
@ -236,9 +247,9 @@
<h3>Export to Dropbox</h3> <h3>Export to Dropbox</h3>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<p>This will upload the current document to your Dropbox account <blockquote class="muted">This will upload the current
and keep it synchronized.</p> document to your Dropbox account and keep it synchronized.</blockquote>
<p>Please specify a file path for "<span class="file-title"></span>": <p>Please specify a <b>file path</b> for "<span class="file-title"></span>":
</p> </p>
<div class="input-prepend"> <div class="input-prepend">
<span class="add-on"><i class="icon-dropbox"></i></span><input <span class="add-on"><i class="icon-dropbox"></i></span><input
@ -460,7 +471,7 @@
<div class="controls"> <div class="controls">
<input type="text" id="input-publish-gdrive-fileid" <input type="text" id="input-publish-gdrive-fileid"
placeholder="FileID"> <span class="help-block">If placeholder="FileID"> <span class="help-block">If
no file ID is supplied, the file will be created in your Google no file ID is supplied, a new file will be created in your Google
Drive root folder. You can move the file afterwards within Google Drive root folder. You can move the file afterwards within Google
Drive.</span> Drive.</span>
</div> </div>
@ -506,10 +517,10 @@
is published on the following location(s): is published on the following location(s):
</p> </p>
<div id="manage-publish-list"></div> <div id="manage-publish-list"></div>
<blockquote class="msg-no-publish hide muted">
"<span class="file-title"></span>" is not published yet.
</blockquote>
<blockquote class="muted"> <blockquote class="muted">
<div class="msg-no-publish hide">
"<span class="file-title"></span>" is not published yet. <br /> <br />
</div>
<b>NOTE:</b> You can add locations using "Publish on" sub-menu. <b>NOTE:</b> You can add locations using "Publish on" sub-menu.
</blockquote> </blockquote>
</div> </div>

View File

@ -5,7 +5,8 @@ define(["jquery", "core", "google-helper"], function($, core, googleHelper) {
var bloggerProvider = { var bloggerProvider = {
providerId: PROVIDER_BLOGGER, providerId: PROVIDER_BLOGGER,
providerName: "Blogger", providerName: "Blogger",
defaultPublishFormat: "html" defaultPublishFormat: "html",
publishPreferencesInputIds: ["blogger-url"]
}; };
bloggerProvider.publish = function(publishAttributes, title, content, callback) { bloggerProvider.publish = function(publishAttributes, title, content, callback) {

View File

@ -265,6 +265,10 @@ define(["jquery", "core", "synchronizer", "publisher", "sharing", "text!../WELCO
$(".action-create-file").click(function() { $(".action-create-file").click(function() {
var fileIndex = fileManager.createFile(); var fileIndex = fileManager.createFile();
fileManager.selectFile(fileIndex); fileManager.selectFile(fileIndex);
var wmdInput = $("#wmd-input").focus().get(0);
if(wmdInput.setSelectionRange) {
wmdInput.setSelectionRange(0, 0);
}
$("#file-title").click(); $("#file-title").click();
}); });
$(".action-remove-file").click(function() { $(".action-remove-file").click(function() {
@ -276,7 +280,10 @@ define(["jquery", "core", "synchronizer", "publisher", "sharing", "text!../WELCO
return; return;
} }
$(this).hide(); $(this).hide();
$("#file-title-input").show().focus().get(0).select(); var fileTitleInput = $("#file-title-input").show();
_.defer(function() {
fileTitleInput.focus().get(0).select();
});
}); });
function applyTitle(input) { function applyTitle(input) {
var title = $.trim(input.val()); var title = $.trim(input.val());
@ -291,6 +298,7 @@ define(["jquery", "core", "synchronizer", "publisher", "sharing", "text!../WELCO
input.hide().val(localStorage[fileIndexTitle]); input.hide().val(localStorage[fileIndexTitle]);
$("#file-title").show(); $("#file-title").show();
core.layoutRefresh(); core.layoutRefresh();
$("#wmd-input").focus();
} }
$("#file-title-input").blur(function() { $("#file-title-input").blur(function() {
applyTitle($(this)); applyTitle($(this));

View File

@ -6,6 +6,7 @@ define(["jquery", "core", "google-helper", "underscore"], function($, core, goog
providerId: PROVIDER_GDRIVE, providerId: PROVIDER_GDRIVE,
providerName: "Google Drive", providerName: "Google Drive",
defaultPublishFormat: "template", defaultPublishFormat: "template",
exportPreferencesInputIds: ["gdrive-parentid"],
useSync: false useSync: false
}; };
@ -70,7 +71,8 @@ define(["jquery", "core", "google-helper", "underscore"], function($, core, goog
}; };
gdriveProvider.exportFile = function(event, title, content, callback) { gdriveProvider.exportFile = function(event, title, content, callback) {
googleHelper.upload(undefined, undefined, title, content, undefined, function(error, result) { var parentId = core.getInputValue($("#input-sync-export-gdrive-parentid"));
googleHelper.upload(undefined, parentId, title, content, undefined, function(error, result) {
if (error) { if (error) {
callback(error); callback(error);
return; return;

View File

@ -4,7 +4,8 @@ define(["jquery", "core", "github-helper"], function($, core, githubHelper) {
var githubProvider = { var githubProvider = {
providerId: PROVIDER_GITHUB, providerId: PROVIDER_GITHUB,
providerName: "GitHub" providerName: "GitHub",
publishPreferencesInputIds: ["github-reponame", "github-branch"]
}; };
githubProvider.publish = function(publishAttributes, title, content, callback) { githubProvider.publish = function(publishAttributes, title, content, callback) {

View File

@ -151,6 +151,16 @@ define(["jquery", "core", "sharing", "blogger-provider", "dropbox-provider", "gi
core.resetModalInputs(); core.resetModalInputs();
$("input:radio[name=radio-publish-format][value=" + defaultPublishFormat + "]").prop("checked", true); $("input:radio[name=radio-publish-format][value=" + defaultPublishFormat + "]").prop("checked", true);
// Load preferences
var serializedPreferences = localStorage[provider.providerId + ".publishPreferences"];
if(serializedPreferences) {
var publishPreferences = JSON.parse(serializedPreferences);
_.each(provider.publishPreferencesInputIds, function(inputId) {
$("#input-publish-" + inputId).val(publishPreferences[inputId]);
});
$("input:radio[name=radio-publish-format][value=" + publishPreferences.format + "]").prop("checked", true);
}
// Open dialog box // Open dialog box
$("#modal-publish").modal(); $("#modal-publish").modal();
} }
@ -162,6 +172,8 @@ define(["jquery", "core", "sharing", "blogger-provider", "dropbox-provider", "gi
if(publishAttributes === undefined) { if(publishAttributes === undefined) {
return; return;
} }
// Perform provider's publishing
var fileIndex = core.fileManager.getCurrentFileIndex(); var fileIndex = core.fileManager.getCurrentFileIndex();
var title = localStorage[fileIndex + ".title"]; var title = localStorage[fileIndex + ".title"];
var content = getPublishContent(publishAttributes); var content = getPublishContent(publishAttributes);
@ -177,6 +189,14 @@ define(["jquery", "core", "sharing", "blogger-provider", "dropbox-provider", "gi
}); });
} }
}); });
// Store input values as preferences for next time we open the publish dialog
var publishPreferences = {};
_.each(provider.publishPreferencesInputIds, function(inputId) {
publishPreferences[inputId] = $("#input-publish-" + inputId).val();
});
publishPreferences.format = publishAttributes.format;
localStorage[provider.providerId + ".publishPreferences"] = JSON.stringify(publishPreferences);
} }
// Used to populate the "Manage publication" dialog // Used to populate the "Manage publication" dialog

View File

@ -4,7 +4,8 @@ define([ "jquery", "core", "ssh-helper" ], function($, core, sshHelper) {
var sshProvider = { var sshProvider = {
providerId : PROVIDER_SSH, providerId : PROVIDER_SSH,
providerName : "SSH server" providerName : "SSH server",
publishPreferencesInputIds: ["ssh-host", "ssh-port", "ssh-username", "ssh-password"]
}; };
sshProvider.publish = function(publishAttributes, title, content, callback) { sshProvider.publish = function(publishAttributes, title, content, callback) {

View File

@ -237,6 +237,25 @@ define(["jquery", "core", "dropbox-provider", "gdrive-provider", "underscore"],
return attributesList; return attributesList;
}; };
// Initialize the export dialog
function initExportDialog(provider) {
// Reset fields
core.resetModalInputs();
// Load preferences
var serializedPreferences = localStorage[provider.providerId + ".exportPreferences"];
if(serializedPreferences) {
var exportPreferences = JSON.parse(serializedPreferences);
_.each(provider.exportPreferencesInputIds, function(inputId) {
$("#input-sync-export-" + inputId).val(exportPreferences[inputId]);
});
}
// Open dialog box
$("#modal-upload-" + provider.providerId).modal();
}
core.onReady(function() { core.onReady(function() {
// Init each provider // Init each provider
_.each(providerMap, function(provider) { _.each(providerMap, function(provider) {
@ -244,8 +263,13 @@ define(["jquery", "core", "dropbox-provider", "gdrive-provider", "underscore"],
$(".action-sync-import-" + provider.providerId).click(function(event) { $(".action-sync-import-" + provider.providerId).click(function(event) {
provider.importFiles(event); provider.importFiles(event);
}); });
// Provider's export button // Provider's export action
$(".action-sync-export-dialog-" + provider.providerId).click(function() {
initExportDialog(provider);
});
$(".action-sync-export-" + provider.providerId).click(function(event) { $(".action-sync-export-" + provider.providerId).click(function(event) {
// Perform the provider's export
var fileIndex = core.fileManager.getCurrentFileIndex(); var fileIndex = core.fileManager.getCurrentFileIndex();
var title = localStorage[fileIndex + ".title"]; var title = localStorage[fileIndex + ".title"];
var content = localStorage[fileIndex + ".content"]; var content = localStorage[fileIndex + ".content"];
@ -253,14 +277,22 @@ define(["jquery", "core", "dropbox-provider", "gdrive-provider", "underscore"],
if(error) { if(error) {
return; return;
} }
// Link syncIndex with fileIndex
localStorage[fileIndex + ".sync"] += syncIndex + ";"; localStorage[fileIndex + ".sync"] += syncIndex + ";";
synchronizer.refreshManageSync(); synchronizer.refreshManageSync();
core.fileManager.updateFileTitles(); core.fileManager.updateFileTitles();
core.showMessage('"' + title core.showMessage('"' + title
+ '" will now be synchronized on ' + provider.providerName + '.'); + '" will now be synchronized on ' + provider.providerName + '.');
}); });
// Store input values as preferences for next time we open the export dialog
var exportPreferences = {};
_.each(provider.exportPreferencesInputIds, function(inputId) {
exportPreferences[inputId] = $("#input-sync-export-" + inputId).val();
});
localStorage[provider.providerId + ".exportPreferences"] = JSON.stringify(exportPreferences);
}); });
// Provider's manual sync button // Provider's manual export button
$(".action-sync-manual-" + provider.providerId).click(function(event) { $(".action-sync-manual-" + provider.providerId).click(function(event) {
var fileIndex = core.fileManager.getCurrentFileIndex(); var fileIndex = core.fileManager.getCurrentFileIndex();
var title = localStorage[fileIndex + ".title"]; var title = localStorage[fileIndex + ".title"];

View File

@ -4,7 +4,8 @@ define(["jquery", "core", "tumblr-helper"], function($, core, tumblrHelper) {
var tumblrProvider = { var tumblrProvider = {
providerId: PROVIDER_TUMBLR, providerId: PROVIDER_TUMBLR,
providerName: "Tumblr" providerName: "Tumblr",
publishPreferencesInputIds: ["tumblr-hostname"]
}; };
tumblrProvider.publish = function(publishAttributes, title, content, callback) { tumblrProvider.publish = function(publishAttributes, title, content, callback) {

View File

@ -5,7 +5,8 @@ define(["jquery", "core", "wordpress-helper"], function($, core, wordpressHelper
var wordpressProvider = { var wordpressProvider = {
providerId: PROVIDER_WORDPRESS, providerId: PROVIDER_WORDPRESS,
providerName: "WordPress", providerName: "WordPress",
defaultPublishFormat: "html" defaultPublishFormat: "html",
publishPreferencesInputIds: ["wordpress-site"]
}; };
wordpressProvider.publish = function(publishAttributes, title, content, callback) { wordpressProvider.publish = function(publishAttributes, title, content, callback) {