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 {
max-height: 500px;
overflow-y: auto;
overflow-x: hidden;
}
#file-selector .stick {

View File

@ -100,8 +100,7 @@
<ul class="dropdown-menu">
<li><a href="#" class="action-sync-import-gdrive">Import
from Google Drive</a></li>
<li><a href="#" data-toggle="modal"
data-target="#modal-upload-gdrive" class="action-reset-input">Export
<li><a href="#" class="action-sync-export-dialog-gdrive">Export
to Google Drive</a></li>
</ul></li>
<li class="dropdown-submenu"><a href="#"><i
@ -109,8 +108,7 @@
<ul class="dropdown-menu">
<li><a class="action-sync-import-dropbox" href="#">Import
from Dropbox</a></li>
<li><a href="#" data-toggle="modal"
data-target="#modal-upload-dropbox" class="action-reset-input">Export
<li><a href="#" class="action-sync-export-dialog-dropbox">Export
to Dropbox</a></li>
</ul></li>
<li><a href="#" data-toggle="modal"
@ -215,11 +213,24 @@
<h3>Export to Google Drive</h3>
</div>
<div class="modal-body">
<p>This will upload the current document into your Google Drive
root folder and keep it synchronized.</p>
<blockquote class="muted">This will upload the current
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">
<b>NOTE:</b> You can move or rename the file afterwards within
Google Drive.
<b>NOTE:</b>
<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>
</div>
<div class="modal-footer">
@ -236,9 +247,9 @@
<h3>Export to Dropbox</h3>
</div>
<div class="modal-body">
<p>This will upload the current document to your Dropbox account
and keep it synchronized.</p>
<p>Please specify a file path for "<span class="file-title"></span>":
<blockquote class="muted">This will upload the current
document to your Dropbox account and keep it synchronized.</blockquote>
<p>Please specify a <b>file path</b> for "<span class="file-title"></span>":
</p>
<div class="input-prepend">
<span class="add-on"><i class="icon-dropbox"></i></span><input
@ -460,7 +471,7 @@
<div class="controls">
<input type="text" id="input-publish-gdrive-fileid"
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.</span>
</div>
@ -506,10 +517,10 @@
is published on the following location(s):
</p>
<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">
<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.
</blockquote>
</div>

View File

@ -5,7 +5,8 @@ define(["jquery", "core", "google-helper"], function($, core, googleHelper) {
var bloggerProvider = {
providerId: PROVIDER_BLOGGER,
providerName: "Blogger",
defaultPublishFormat: "html"
defaultPublishFormat: "html",
publishPreferencesInputIds: ["blogger-url"]
};
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() {
var fileIndex = fileManager.createFile();
fileManager.selectFile(fileIndex);
var wmdInput = $("#wmd-input").focus().get(0);
if(wmdInput.setSelectionRange) {
wmdInput.setSelectionRange(0, 0);
}
$("#file-title").click();
});
$(".action-remove-file").click(function() {
@ -276,7 +280,10 @@ define(["jquery", "core", "synchronizer", "publisher", "sharing", "text!../WELCO
return;
}
$(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) {
var title = $.trim(input.val());
@ -291,6 +298,7 @@ define(["jquery", "core", "synchronizer", "publisher", "sharing", "text!../WELCO
input.hide().val(localStorage[fileIndexTitle]);
$("#file-title").show();
core.layoutRefresh();
$("#wmd-input").focus();
}
$("#file-title-input").blur(function() {
applyTitle($(this));

View File

@ -6,6 +6,7 @@ define(["jquery", "core", "google-helper", "underscore"], function($, core, goog
providerId: PROVIDER_GDRIVE,
providerName: "Google Drive",
defaultPublishFormat: "template",
exportPreferencesInputIds: ["gdrive-parentid"],
useSync: false
};
@ -70,7 +71,8 @@ define(["jquery", "core", "google-helper", "underscore"], function($, core, goog
};
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) {
callback(error);
return;

View File

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

View File

@ -151,6 +151,16 @@ define(["jquery", "core", "sharing", "blogger-provider", "dropbox-provider", "gi
core.resetModalInputs();
$("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
$("#modal-publish").modal();
}
@ -162,6 +172,8 @@ define(["jquery", "core", "sharing", "blogger-provider", "dropbox-provider", "gi
if(publishAttributes === undefined) {
return;
}
// Perform provider's publishing
var fileIndex = core.fileManager.getCurrentFileIndex();
var title = localStorage[fileIndex + ".title"];
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

View File

@ -4,7 +4,8 @@ define([ "jquery", "core", "ssh-helper" ], function($, core, sshHelper) {
var sshProvider = {
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) {

View File

@ -237,6 +237,25 @@ define(["jquery", "core", "dropbox-provider", "gdrive-provider", "underscore"],
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() {
// Init each 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) {
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) {
// Perform the provider's export
var fileIndex = core.fileManager.getCurrentFileIndex();
var title = localStorage[fileIndex + ".title"];
var content = localStorage[fileIndex + ".content"];
@ -253,14 +277,22 @@ define(["jquery", "core", "dropbox-provider", "gdrive-provider", "underscore"],
if(error) {
return;
}
// Link syncIndex with fileIndex
localStorage[fileIndex + ".sync"] += syncIndex + ";";
synchronizer.refreshManageSync();
core.fileManager.updateFileTitles();
core.showMessage('"' + title
+ '" 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) {
var fileIndex = core.fileManager.getCurrentFileIndex();
var title = localStorage[fileIndex + ".title"];

View File

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

View File

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