Added Google picker

This commit is contained in:
Benoit Schweblin 2013-04-06 01:57:52 +01:00
parent f7d9903c96
commit 59ce59862d
2 changed files with 38 additions and 30 deletions

View File

@ -1,5 +1,6 @@
var GOOGLE_SCOPES = [ 'https://www.googleapis.com/auth/drive.install', var GOOGLE_SCOPES = [ 'https://www.googleapis.com/auth/drive.install',
'https://www.googleapis.com/auth/drive' ]; 'https://www.googleapis.com/auth/drive' ];
var GOOGLE_DRIVE_APP_ID = "241271498917";
var DEFAULT_FILE_TITLE = "Title"; var DEFAULT_FILE_TITLE = "Title";
var GDRIVE_DEFAULT_FILE_TITLE = "New Markdown document"; var GDRIVE_DEFAULT_FILE_TITLE = "New Markdown document";
var CHECK_ONLINE_PERIOD = 60000; var CHECK_ONLINE_PERIOD = 60000;

View File

@ -365,14 +365,15 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
var pickerLoaded = false; var pickerLoaded = false;
function loadPicker(callback) { function loadPicker(callback) {
var asyncTask = {}; authenticate(function() {
asyncTask.run = function() { if (connected === false) {
if(core.isOffline === true) {
pickerLoaded = false; pickerLoaded = false;
core.showMessage("Operation not available in offline mode."); callback();
asyncTask.error();
return; return;
} }
var asyncTask = {};
asyncTask.run = function() {
if (pickerLoaded === true) { if (pickerLoaded === true) {
asyncTask.success(); asyncTask.success();
return; return;
@ -396,6 +397,7 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
callback(); callback();
}; };
asyncTaskRunner.addTask(asyncTask); asyncTaskRunner.addTask(asyncTask);
});
} }
gdrive.picker = function(callback) { gdrive.picker = function(callback) {
@ -408,6 +410,7 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
var ids = []; var ids = [];
var picker = undefined; var picker = undefined;
var token = gapi.auth.getToken();
var asyncTask = {}; var asyncTask = {};
asyncTask.run = function() { asyncTask.run = function() {
var view = new google.picker.View(google.picker.ViewId.DOCS); var view = new google.picker.View(google.picker.ViewId.DOCS);
@ -415,6 +418,10 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
var pickerBuilder = new google.picker.PickerBuilder(); var pickerBuilder = new google.picker.PickerBuilder();
pickerBuilder.enableFeature(google.picker.Feature.NAV_HIDDEN); pickerBuilder.enableFeature(google.picker.Feature.NAV_HIDDEN);
pickerBuilder.enableFeature(google.picker.Feature.MULTISELECT_ENABLED); pickerBuilder.enableFeature(google.picker.Feature.MULTISELECT_ENABLED);
pickerBuilder.setAppId(GOOGLE_DRIVE_APP_ID);
if(token) {
pickerBuilder.setOAuthToken(token.access_token);
}
pickerBuilder.addView(view); pickerBuilder.addView(view);
pickerBuilder.addView(new google.picker.DocsUploadView()); pickerBuilder.addView(new google.picker.DocsUploadView());
pickerBuilder.setCallback(function(data) { pickerBuilder.setCallback(function(data) {
@ -433,14 +440,14 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
picker.setVisible(true); picker.setVisible(true);
}; };
asyncTask.onSuccess = function() { asyncTask.onSuccess = function() {
$(".modal-backdrop").remove(); $(".modal-backdrop, .picker").remove();
callback(ids); callback(ids);
}; };
asyncTask.onError = function() { asyncTask.onError = function() {
if(picker !== undefined) { if(picker !== undefined) {
picker.setVisible(false); picker.setVisible(false);
} }
$(".modal-backdrop").remove(); $(".modal-backdrop, .picker").remove();
callback(); callback();
}; };
asyncTaskRunner.addTask(asyncTask); asyncTaskRunner.addTask(asyncTask);