Added Google picker
This commit is contained in:
parent
b6a3aba73f
commit
42e327c789
@ -1 +1 @@
|
||||
CACHE MANIFEST
# v29
CACHE:
index.html
css/bootstrap.css
css/jgrowl.css
css/main.css
js/async-runner.js
js/bootstrap.js
js/config.js
js/custo.github.js
js/gdrive.js
js/jgrowl.js
js/jquery.js
js/jquery-ui.js
js/layout.js
js/main.js
js/Markdown.Converter.js
js/Markdown.Editor.js
js/Markdown.Sanitizer.js
js/require.js
js/synchronizer.js
img/ajax-loader.gif
img/dropbox.png
img/gdrive.png
img/glyphicons-halflings.png
img/glyphicons-halflings-white.png
img/stackedit-16.png
img/stackedit-32.ico
NETWORK:
*
|
||||
CACHE MANIFEST
# v30
CACHE:
index.html
css/bootstrap.css
css/jgrowl.css
css/main.css
js/async-runner.js
js/bootstrap.js
js/config.js
js/custo.github.js
js/gdrive.js
js/jgrowl.js
js/jquery.js
js/jquery-ui.js
js/layout.js
js/main.js
js/Markdown.Converter.js
js/Markdown.Editor.js
js/Markdown.Sanitizer.js
js/require.js
js/synchronizer.js
img/ajax-loader.gif
img/dropbox.png
img/gdrive.png
img/glyphicons-halflings.png
img/glyphicons-halflings-white.png
img/stackedit-16.png
img/stackedit-32.ico
NETWORK:
*
|
||||
|
@ -284,3 +284,8 @@ hr {
|
||||
border-right: 5px solid #525252;
|
||||
border-left: 0;
|
||||
}
|
||||
|
||||
/* Google picker */
|
||||
.picker-dialog {
|
||||
z-index: 1050 !important;
|
||||
}
|
||||
|
24
index.html
24
index.html
@ -49,8 +49,7 @@
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="#" class="action-upload-gdrive">Export to
|
||||
Google Drive</a></li>
|
||||
<li><a href="#" data-toggle="modal"
|
||||
data-target="#modal-download-gdrive">Import from Google
|
||||
<li><a href="#" class="action-download-gdrive">Import from Google
|
||||
Drive</a></li>
|
||||
</ul></li>
|
||||
<li class="dropdown-submenu"><a href="#"><i
|
||||
@ -142,27 +141,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="modal-download-gdrive" class="modal hide">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"
|
||||
aria-hidden="true">×</button>
|
||||
<h3>Import</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>Please provide a Google Drive file ID:</p>
|
||||
<div class="input-prepend">
|
||||
<span class="add-on"><i class="icon-gdrive"></i></span><input
|
||||
id="download-gdrive-fileid" type="text" class="span5" placeholder="Google Drive file ID"></input>
|
||||
</div>
|
||||
<p class="muted"><b>NOTE:</b> This will create a local copy of your Google Drive document
|
||||
and keep it synchronized.</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn" data-dismiss="modal">Cancel</a> <a href="#"
|
||||
class="btn btn-primary action-download-gdrive" data-dismiss="modal">OK</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="modal-manage-sync" class="modal hide">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"
|
||||
|
@ -96,7 +96,7 @@ define(["jquery", "bootstrap", "jgrowl", "layout", "Markdown.Editor"], function(
|
||||
offlineTime = core.currentTime;
|
||||
// Try to download anything to test the connection
|
||||
$.ajax({
|
||||
url : "https://apis.google.com/js/client.js",
|
||||
url : "//www.google.com/jsapi",
|
||||
timeout : AJAX_TIMEOUT, dataType : "script"
|
||||
}).done(function() {
|
||||
core.setOnline();
|
||||
|
@ -76,11 +76,8 @@ define(["jquery", "core", "gdrive", "synchronizer", "async-runner"], function($,
|
||||
window.open(uriContent, 'file');
|
||||
});
|
||||
$(".action-upload-gdrive").click(uploadGdrive);
|
||||
$(".action-download-gdrive").click(function(event) {
|
||||
var fileId = core.getInputValue($("#download-gdrive-fileid"), event);
|
||||
if(checkGdriveFileId(fileId) === true) {
|
||||
gdrive.importFiles([fileId]);
|
||||
}
|
||||
$(".action-download-gdrive").click(function() {
|
||||
gdrive.picker(importGdrive);
|
||||
});
|
||||
$(".action-manual-gdrive").click(function(event) {
|
||||
var fileId = core.getInputValue($("#manual-gdrive-fileid"), event);
|
||||
@ -112,10 +109,10 @@ define(["jquery", "core", "gdrive", "synchronizer", "async-runner"], function($,
|
||||
if(fileIndex !== undefined) {
|
||||
localStorage["file.current"] = fileIndex;
|
||||
}
|
||||
refreshManageSync();
|
||||
|
||||
// Update the file titles
|
||||
this.updateFileTitles();
|
||||
refreshManageSync();
|
||||
|
||||
// Recreate the editor
|
||||
var fileIndex = localStorage["file.current"];
|
||||
@ -296,23 +293,35 @@ define(["jquery", "core", "gdrive", "synchronizer", "async-runner"], function($,
|
||||
});
|
||||
}
|
||||
|
||||
function checkGdriveFileId(fileId) {
|
||||
function importGdrive(ids) {
|
||||
if(ids === undefined) {
|
||||
return;
|
||||
}
|
||||
var importIds = [];
|
||||
for(var i=0; i<ids.length; i++) {
|
||||
var fileId = ids[i];
|
||||
var fileSyncIndex = SYNC_PROVIDER_GDRIVE + fileId;
|
||||
var fileIndex = fileManager.getFileIndexFromSync(fileSyncIndex);
|
||||
if(fileIndex !== undefined) {
|
||||
var title = localStorage[fileIndex + ".title"];
|
||||
core.showError('"' + title + '" has already been imported');
|
||||
continue;
|
||||
}
|
||||
importIds.push(fileId);
|
||||
}
|
||||
gdrive.importFiles(importIds);
|
||||
}
|
||||
|
||||
function manualGdrive(fileId) {
|
||||
if(!fileId) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
// Check that file is not synchronized with an other one
|
||||
var fileSyncIndex = SYNC_PROVIDER_GDRIVE + fileId;
|
||||
var fileIndex = fileManager.getFileIndexFromSync(fileSyncIndex);
|
||||
if(fileIndex !== undefined) {
|
||||
var title = localStorage[fileIndex + ".title"];
|
||||
core.showError('Google Drive file is already synchronized with "' + title + '"');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function manualGdrive(fileId) {
|
||||
if(checkGdriveFileId(fileId) === false) {
|
||||
core.showError('File ID is already synchronized with "' + title + '"');
|
||||
return;
|
||||
}
|
||||
var fileIndex = localStorage["file.current"];
|
||||
@ -321,9 +330,7 @@ define(["jquery", "core", "gdrive", "synchronizer", "async-runner"], function($,
|
||||
if(result === undefined || result.length === 0) {
|
||||
return;
|
||||
}
|
||||
var file = result[0];
|
||||
var fileSyncIndex = SYNC_PROVIDER_GDRIVE + file.id;
|
||||
localStorage[fileSyncIndex + ".etag"] = file.etag;
|
||||
localStorage[fileSyncIndex + ".etag"] = result[0].etag;
|
||||
localStorage[fileIndex + ".sync"] += fileSyncIndex + ";";
|
||||
refreshManageSync();
|
||||
fileManager.updateFileTitles();
|
||||
|
97
js/gdrive.js
97
js/gdrive.js
@ -13,6 +13,12 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
|
||||
callback = callback || core.doNothing;
|
||||
var asyncTask = {};
|
||||
asyncTask.run = function() {
|
||||
if(core.isOffline === true) {
|
||||
connected = false;
|
||||
core.showMessage("Operation not available in offline mode.");
|
||||
asyncTask.error();
|
||||
return;
|
||||
}
|
||||
if (connected === true) {
|
||||
asyncTask.success();
|
||||
return;
|
||||
@ -68,11 +74,11 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
|
||||
gapi.auth.authorize({ 'client_id' : GOOGLE_CLIENT_ID,
|
||||
'scope' : GOOGLE_SCOPES, 'immediate' : immediate }, function(
|
||||
authResult) {
|
||||
if (!authResult || authResult.error) {
|
||||
asyncTask.error();
|
||||
return;
|
||||
}
|
||||
gapi.client.load('drive', 'v2', function() {
|
||||
if (!authResult || authResult.error) {
|
||||
asyncTask.error();
|
||||
return;
|
||||
}
|
||||
authenticated = true;
|
||||
asyncTask.success();
|
||||
});
|
||||
@ -357,6 +363,89 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
|
||||
asyncTask.error();
|
||||
}
|
||||
|
||||
var pickerLoaded = false;
|
||||
function loadPicker(callback) {
|
||||
var asyncTask = {};
|
||||
asyncTask.run = function() {
|
||||
if(core.isOffline === true) {
|
||||
pickerLoaded = false;
|
||||
core.showMessage("Operation not available in offline mode.");
|
||||
asyncTask.error();
|
||||
return;
|
||||
}
|
||||
if (pickerLoaded === true) {
|
||||
asyncTask.success();
|
||||
return;
|
||||
}
|
||||
$.ajax({
|
||||
url : "//www.google.com/jsapi",
|
||||
dataType : "script", timeout : AJAX_TIMEOUT
|
||||
}).done(function() {
|
||||
asyncTask.success();
|
||||
}).fail(function() {
|
||||
asyncTask.error();
|
||||
});
|
||||
};
|
||||
asyncTask.onSuccess = function() {
|
||||
google.load('picker', '1', {callback: callback});
|
||||
pickerLoaded = true;
|
||||
};
|
||||
asyncTask.onError = function() {
|
||||
core.setOffline();
|
||||
callback();
|
||||
};
|
||||
asyncTaskRunner.addTask(asyncTask);
|
||||
}
|
||||
|
||||
gdrive.picker = function(callback) {
|
||||
callback = callback || core.doNothing;
|
||||
loadPicker(function() {
|
||||
if (pickerLoaded === false) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
var ids = [];
|
||||
var picker = undefined;
|
||||
var asyncTask = {};
|
||||
asyncTask.run = function() {
|
||||
var view = new google.picker.View(google.picker.ViewId.DOCS);
|
||||
view.setMimeTypes("text/x-markdown,text/plain");
|
||||
var pickerBuilder = new google.picker.PickerBuilder();
|
||||
pickerBuilder.enableFeature(google.picker.Feature.NAV_HIDDEN);
|
||||
pickerBuilder.enableFeature(google.picker.Feature.MULTISELECT_ENABLED);
|
||||
pickerBuilder.addView(view);
|
||||
pickerBuilder.addView(new google.picker.DocsUploadView());
|
||||
pickerBuilder.setCallback(function(data) {
|
||||
if (data.action == google.picker.Action.PICKED ||
|
||||
data.action == google.picker.Action.CANCEL) {
|
||||
if(data.action == google.picker.Action.PICKED) {
|
||||
for(var i=0; i<data.docs.length; i++) {
|
||||
ids.push(data.docs[i].id);
|
||||
}
|
||||
}
|
||||
asyncTask.success();
|
||||
}
|
||||
});
|
||||
picker = pickerBuilder.build();
|
||||
$("body").append($("<div>").addClass("modal-backdrop"));
|
||||
picker.setVisible(true);
|
||||
};
|
||||
asyncTask.onSuccess = function() {
|
||||
$(".modal-backdrop").remove();
|
||||
callback(ids);
|
||||
};
|
||||
asyncTask.onError = function() {
|
||||
if(picker !== undefined) {
|
||||
picker.setVisible(false);
|
||||
}
|
||||
$(".modal-backdrop").remove();
|
||||
callback();
|
||||
};
|
||||
asyncTaskRunner.addTask(asyncTask);
|
||||
});
|
||||
};
|
||||
|
||||
gdrive.createFile = function(title, content, callback) {
|
||||
upload(undefined, undefined, title, content, callback);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user