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-right: 5px solid #525252;
|
||||||
border-left: 0;
|
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">
|
<ul class="dropdown-menu">
|
||||||
<li><a href="#" class="action-upload-gdrive">Export to
|
<li><a href="#" class="action-upload-gdrive">Export to
|
||||||
Google Drive</a></li>
|
Google Drive</a></li>
|
||||||
<li><a href="#" data-toggle="modal"
|
<li><a href="#" class="action-download-gdrive">Import from Google
|
||||||
data-target="#modal-download-gdrive">Import from Google
|
|
||||||
Drive</a></li>
|
Drive</a></li>
|
||||||
</ul></li>
|
</ul></li>
|
||||||
<li class="dropdown-submenu"><a href="#"><i
|
<li class="dropdown-submenu"><a href="#"><i
|
||||||
@ -142,27 +141,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</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 id="modal-manage-sync" class="modal hide">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<button type="button" class="close" data-dismiss="modal"
|
<button type="button" class="close" data-dismiss="modal"
|
||||||
|
@ -96,7 +96,7 @@ define(["jquery", "bootstrap", "jgrowl", "layout", "Markdown.Editor"], function(
|
|||||||
offlineTime = core.currentTime;
|
offlineTime = core.currentTime;
|
||||||
// Try to download anything to test the connection
|
// Try to download anything to test the connection
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : "https://apis.google.com/js/client.js",
|
url : "//www.google.com/jsapi",
|
||||||
timeout : AJAX_TIMEOUT, dataType : "script"
|
timeout : AJAX_TIMEOUT, dataType : "script"
|
||||||
}).done(function() {
|
}).done(function() {
|
||||||
core.setOnline();
|
core.setOnline();
|
||||||
|
@ -76,11 +76,8 @@ define(["jquery", "core", "gdrive", "synchronizer", "async-runner"], function($,
|
|||||||
window.open(uriContent, 'file');
|
window.open(uriContent, 'file');
|
||||||
});
|
});
|
||||||
$(".action-upload-gdrive").click(uploadGdrive);
|
$(".action-upload-gdrive").click(uploadGdrive);
|
||||||
$(".action-download-gdrive").click(function(event) {
|
$(".action-download-gdrive").click(function() {
|
||||||
var fileId = core.getInputValue($("#download-gdrive-fileid"), event);
|
gdrive.picker(importGdrive);
|
||||||
if(checkGdriveFileId(fileId) === true) {
|
|
||||||
gdrive.importFiles([fileId]);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
$(".action-manual-gdrive").click(function(event) {
|
$(".action-manual-gdrive").click(function(event) {
|
||||||
var fileId = core.getInputValue($("#manual-gdrive-fileid"), event);
|
var fileId = core.getInputValue($("#manual-gdrive-fileid"), event);
|
||||||
@ -112,10 +109,10 @@ define(["jquery", "core", "gdrive", "synchronizer", "async-runner"], function($,
|
|||||||
if(fileIndex !== undefined) {
|
if(fileIndex !== undefined) {
|
||||||
localStorage["file.current"] = fileIndex;
|
localStorage["file.current"] = fileIndex;
|
||||||
}
|
}
|
||||||
refreshManageSync();
|
|
||||||
|
|
||||||
// Update the file titles
|
// Update the file titles
|
||||||
this.updateFileTitles();
|
this.updateFileTitles();
|
||||||
|
refreshManageSync();
|
||||||
|
|
||||||
// Recreate the editor
|
// Recreate the editor
|
||||||
var fileIndex = localStorage["file.current"];
|
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) {
|
if(!fileId) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
// Check that file is not synchronized with an other one
|
// Check that file is not synchronized with an other one
|
||||||
var fileSyncIndex = SYNC_PROVIDER_GDRIVE + fileId;
|
var fileSyncIndex = SYNC_PROVIDER_GDRIVE + fileId;
|
||||||
var fileIndex = fileManager.getFileIndexFromSync(fileSyncIndex);
|
var fileIndex = fileManager.getFileIndexFromSync(fileSyncIndex);
|
||||||
if(fileIndex !== undefined) {
|
if(fileIndex !== undefined) {
|
||||||
var title = localStorage[fileIndex + ".title"];
|
var title = localStorage[fileIndex + ".title"];
|
||||||
core.showError('Google Drive file is already synchronized with "' + title + '"');
|
core.showError('File ID is already synchronized with "' + title + '"');
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function manualGdrive(fileId) {
|
|
||||||
if(checkGdriveFileId(fileId) === false) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var fileIndex = localStorage["file.current"];
|
var fileIndex = localStorage["file.current"];
|
||||||
@ -321,9 +330,7 @@ define(["jquery", "core", "gdrive", "synchronizer", "async-runner"], function($,
|
|||||||
if(result === undefined || result.length === 0) {
|
if(result === undefined || result.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var file = result[0];
|
localStorage[fileSyncIndex + ".etag"] = result[0].etag;
|
||||||
var fileSyncIndex = SYNC_PROVIDER_GDRIVE + file.id;
|
|
||||||
localStorage[fileSyncIndex + ".etag"] = file.etag;
|
|
||||||
localStorage[fileIndex + ".sync"] += fileSyncIndex + ";";
|
localStorage[fileIndex + ".sync"] += fileSyncIndex + ";";
|
||||||
refreshManageSync();
|
refreshManageSync();
|
||||||
fileManager.updateFileTitles();
|
fileManager.updateFileTitles();
|
||||||
|
99
js/gdrive.js
99
js/gdrive.js
@ -13,6 +13,12 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
|
|||||||
callback = callback || core.doNothing;
|
callback = callback || core.doNothing;
|
||||||
var asyncTask = {};
|
var asyncTask = {};
|
||||||
asyncTask.run = function() {
|
asyncTask.run = function() {
|
||||||
|
if(core.isOffline === true) {
|
||||||
|
connected = false;
|
||||||
|
core.showMessage("Operation not available in offline mode.");
|
||||||
|
asyncTask.error();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (connected === true) {
|
if (connected === true) {
|
||||||
asyncTask.success();
|
asyncTask.success();
|
||||||
return;
|
return;
|
||||||
@ -68,11 +74,11 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
|
|||||||
gapi.auth.authorize({ 'client_id' : GOOGLE_CLIENT_ID,
|
gapi.auth.authorize({ 'client_id' : GOOGLE_CLIENT_ID,
|
||||||
'scope' : GOOGLE_SCOPES, 'immediate' : immediate }, function(
|
'scope' : GOOGLE_SCOPES, 'immediate' : immediate }, function(
|
||||||
authResult) {
|
authResult) {
|
||||||
if (!authResult || authResult.error) {
|
|
||||||
asyncTask.error();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
gapi.client.load('drive', 'v2', function() {
|
gapi.client.load('drive', 'v2', function() {
|
||||||
|
if (!authResult || authResult.error) {
|
||||||
|
asyncTask.error();
|
||||||
|
return;
|
||||||
|
}
|
||||||
authenticated = true;
|
authenticated = true;
|
||||||
asyncTask.success();
|
asyncTask.success();
|
||||||
});
|
});
|
||||||
@ -357,6 +363,89 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
|
|||||||
asyncTask.error();
|
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) {
|
gdrive.createFile = function(title, content, callback) {
|
||||||
upload(undefined, undefined, title, content, callback);
|
upload(undefined, undefined, title, content, callback);
|
||||||
};
|
};
|
||||||
@ -420,6 +509,6 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
|
|||||||
gdrive.importFiles(ids);
|
gdrive.importFiles(ids);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return gdrive;
|
return gdrive;
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user