Added AutoSync feature for Google Drive

This commit is contained in:
benweet 2014-02-09 17:50:40 +00:00
parent 891260dd4e
commit 5a8e0910f2
6 changed files with 166 additions and 14 deletions

View File

@ -126,17 +126,17 @@ Markdown Extra
Item | Value
--------- | -----
Computer | \$1600
Phone | \$12
Pipe | \$1
Computer | 1600 USD
Phone | 12 USD
Pipe | 1 USD
You can specify column alignment with one or two colons:
| Item | Value | Qty |
| :-------- | ------:| :--: |
| Computer | \$1600 | 5 |
| Phone | \$12 | 12 |
| Pipe | \$1 | 234 |
| Item | Value | Qty |
| :-------- | --------:| :--: |
| Computer | 1600 USD | 5 |
| Phone | 12 USD | 12 |
| Pipe | 1 USD | 234 |
### Definition Lists

View File

@ -117,6 +117,7 @@
Google Drive</a></li>
<li><a href="#" class="action-sync-export-dialog-gdrive">Export
to Google Drive</a></li>
<li><a href="#" class="action-autosync-dialog-gdrive">AutoSync...</a></li>
</ul>
</div>
<a href="#" data-toggle="collapse"
@ -129,6 +130,7 @@
Google Drive</a></li>
<li><a href="#" class="action-sync-export-dialog-gdrivesec">Export
to Google Drive</a></li>
<li><a href="#" class="action-autosync-dialog-gdrivesec">AutoSync...</a></li>
</ul>
</div>
<a href="#" data-toggle="collapse"
@ -141,6 +143,7 @@
Google Drive</a></li>
<li><a href="#" class="action-sync-export-dialog-gdriveter">Export
to Google Drive</li>
<li><a href="#" class="action-autosync-dialog-gdriveter">AutoSync...</a></li>
</ul>
</div>
<a href="#" data-toggle="collapse"
@ -490,6 +493,14 @@
</div>
<div class="modal modal-autosync-gdrive">
</div>
<div class="modal modal-autosync-gdrivesec">
</div>
<div class="modal modal-autosync-gdriveter">
</div>
<div class="modal modal-upload-dropbox">
<div class="modal-dialog">
<div class="modal-content">

View File

@ -0,0 +1,57 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">&times;</button>
<h3 class="modal-title">AutoSync to <%= providerName %></h3>
</div>
<div class="modal-body">
<p>
<b>AutoSync</b> feature automatically exports every new document to your <i
class="icon-provider-<%= providerId %>"></i>
<code>Google Drive</code>
account and keep it synchronized.
</p>
<div class="form-horizontal">
<br/>
<div class="form-group">
<div class="col-lg-3 control-label"></div>
<div class="col-lg-8">
<label> <input id="input-autosync-<%= providerId %>-enabled"
type="checkbox"> Enable AutoSync for <%= providerName %>
</label>
</div>
</div>
<br/>
<div class="form-group">
<label class="col-lg-3 control-label"
for="input-autosync-<%= providerId %>-parentid">Folder ID
(optional)</label>
<div class="col-lg-8">
<div class="input-group">
<input type="text" id="input-autosync-<%= providerId %>-parentid"
placeholder="FolderID" class="form-control">
<div class="input-group-btn">
<a class="btn btn-link action-autosync-<%= providerId %>-choose-folder"
title="Choose folder" data-dismiss="modal"><i
class="icon-folder-open"></i></a>
</div>
</div>
<span class="help-block"> If no folder ID is supplied,
files will be created in your root folder. </span>
</div>
</div>
</div>
<blockquote>
<b>NOTE:</b> Removing a local document will not delete the linked file on Google
Drive.
</blockquote>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-default" data-dismiss="modal">Cancel</a>
<a href="#" data-dismiss="modal"
class="btn btn-primary action-autosync-<%= providerId %>">OK</a>
</div>
</div>
</div>

View File

@ -10,7 +10,7 @@
<p>
This will save "<span class="file-title"></span>" to your <i
class="icon-provider-<%= providerId %>"></i>
<code><%= providerName %></code>
<code>Google Drive</code>
account and keep it synchronized.
</p>
<div class="collapse form-horizontal sync-export-<%= providerId %>-options-collapse">
@ -23,7 +23,7 @@
<input type="text" id="input-sync-export-<%= providerId %>-parentid"
placeholder="FolderID" class="form-control">
<div class="input-group-btn">
<a class="btn btn-link export-<%= providerId %>-choose-folder"
<a class="btn btn-link action-export-<%= providerId %>-choose-folder"
title="Choose folder" data-dismiss="modal"><i
class="icon-folder-open"></i></a>
</div>

View File

@ -11,8 +11,9 @@ define([
"eventMgr",
"fileMgr",
"helpers/googleHelper",
"text!html/dialogExportGdrive.html"
], function($, _, constants, utils, storage, logger, Provider, settings, eventMgr, fileMgr, googleHelper, dialogExportGdriveHTML) {
"text!html/dialogExportGdrive.html",
"text!html/dialogAutoSyncGdrive.html",
], function($, _, constants, utils, storage, logger, Provider, settings, eventMgr, fileMgr, googleHelper, dialogExportGdriveHTML, dialogAutoSyncGdriveHTML) {
return function(providerId, providerName, accountIndex) {
var accountId = 'google.gdrive' + accountIndex;
@ -474,6 +475,34 @@ define([
}
};
// Initialize the AutoSync dialog fields
gdriveProvider.setAutosyncDialogConfig = function() {
var config = gdriveProvider.autosyncConfig;
utils.setInputChecked('#input-autosync-' + providerId + '-enabled', config.enabled);
utils.setInputValue('#input-autosync-' + providerId + '-parentid', config.parentId);
};
// Retrieve the AutoSync dialog fields
gdriveProvider.getAutosyncDialogConfig = function() {
var config = {};
config.enabled = utils.getInputChecked('#input-autosync-' + providerId + '-enabled');
config.parentId = utils.getInputTextValue('#input-autosync-' + providerId + '-parentid');
return config;
};
// Perform AutoSync
gdriveProvider.autosyncFile = function(title, content, config, callback) {
var parentId = config.parentId;
googleHelper.upload(undefined, parentId, title, content, undefined, undefined, accountId, function(error, result) {
if(error) {
callback(error);
return;
}
var syncAttributes = createSyncAttributes(result.id, result.etag, content, title);
callback(undefined, syncAttributes);
});
};
// Disable publish on optional multi-account
gdriveProvider.isPublishEnabled = settings.gdriveMultiAccount > accountIndex;
@ -488,8 +517,15 @@ define([
providerName: providerName
}));
// Create autosync dialog
var modalAutosyncElt = document.querySelector('.modal-autosync-' + providerId);
modalAutosyncElt && (modalAutosyncElt.innerHTML = _.template(dialogAutoSyncGdriveHTML, {
providerId: providerId,
providerName: providerName
}));
// Choose folder button in export modal
$('.export-' + providerId + '-choose-folder').click(function() {
$('.action-export-' + providerId + '-choose-folder').click(function() {
googleHelper.picker(function(error, docs) {
if(error || docs.length === 0) {
return;
@ -501,6 +537,19 @@ define([
}, 'folder', accountId);
});
// Choose folder button in autosync modal
$('.action-autosync-' + providerId + '-choose-folder').click(function() {
googleHelper.picker(function(error, docs) {
if(error || docs.length === 0) {
return;
}
// Open export dialog
$(".modal-autosync-" + providerId).modal();
// Set parent ID
utils.setInputValue('#input-autosync-' + providerId + '-parentid', docs[0].id);
}, 'folder', accountId);
});
// On export, disable file ID input if realtime is checked
var $realtimeCheckboxElt = $('#input-sync-export-' + providerId + '-realtime');
var $fileIdInputElt = $('#input-sync-export-' + providerId + '-fileid');

View File

@ -48,6 +48,11 @@ define([
});
});
// AutoSync configuration
_.each(providerMap, function(provider) {
provider.autosyncConfig = utils.retrieveIgnoreError(provider.providerId + ".autosyncConfig") || {};
});
// Returns true if at least one file has synchronized location
synchronizer.hasSync = function(provider) {
return _.some(fileSystem, function(fileDesc) {
@ -292,10 +297,24 @@ define([
});
}
// Open dialog box
// Open dialog
$(".modal-upload-" + provider.providerId).modal();
}
eventMgr.addListener("onFileCreated", function(fileDesc) {
if(_.size(fileDesc.syncLocations) === 0) {
_.each(providerMap, function(provider) {
provider.autosyncConfig.enabled && provider.autosyncFile(fileDesc.title, fileDesc.content, provider.autosyncConfig, function(error, syncAttributes) {
if(error) {
return;
}
fileDesc.addSyncLocation(syncAttributes);
eventMgr.onSyncExportSuccess(fileDesc, syncAttributes);
});
});
}
});
eventMgr.addListener("onReady", function() {
// Init each provider
_.each(providerMap, function(provider) {
@ -307,6 +326,15 @@ define([
$(".action-sync-export-dialog-" + provider.providerId).click(function() {
initExportDialog(provider);
});
// Provider's autosync action
$(".action-autosync-dialog-" + provider.providerId).click(function() {
// Reset fields
utils.resetModalInputs();
// Load config
provider.setAutosyncDialogConfig(provider);
// Open dialog
$(".modal-autosync-" + provider.providerId).modal();
});
$(".action-sync-export-" + provider.providerId).click(function(event) {
var isRealtime = utils.getInputChecked("#input-sync-export-" + provider.providerId + "-realtime");
var fileDesc = fileMgr.currentFile;
@ -360,6 +388,13 @@ define([
});
storage[provider.providerId + ".exportPreferences"] = JSON.stringify(exportPreferences);
});
$(".action-autosync-" + provider.providerId).click(function(event) {
var config = provider.getAutosyncDialogConfig(event);
if(config !== undefined) {
storage[provider.providerId + ".autosyncConfig"] = JSON.stringify(config);
provider.autosyncConfig = config;
}
});
});
});