From 8e686968ac480fd8eed23a03d55a15b8247334bc Mon Sep 17 00:00:00 2001 From: Benoit Schweblin Date: Sat, 6 Apr 2013 02:07:45 +0100 Subject: [PATCH] Added Google picker --- js/file-manager.js | 2 +- js/gdrive.js | 67 +++++++++++++++++++--------------------------- 2 files changed, 29 insertions(+), 40 deletions(-) diff --git a/js/file-manager.js b/js/file-manager.js index 8d914f04..3e4b99c0 100644 --- a/js/file-manager.js +++ b/js/file-manager.js @@ -304,7 +304,7 @@ define(["jquery", "core", "gdrive", "synchronizer", "async-runner"], function($, var fileIndex = fileManager.getFileIndexFromSync(fileSyncIndex); if(fileIndex !== undefined) { var title = localStorage[fileIndex + ".title"]; - core.showError('"' + title + '" has already been imported'); + core.showError('"' + title + '" was already imported'); continue; } importIds.push(fileId); diff --git a/js/gdrive.js b/js/gdrive.js index 3b04388c..f044dcd4 100644 --- a/js/gdrive.js +++ b/js/gdrive.js @@ -408,49 +408,38 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) { return; } - var ids = []; - var picker = undefined; + 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.setAppId(GOOGLE_DRIVE_APP_ID); var token = gapi.auth.getToken(); - 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.setAppId(GOOGLE_DRIVE_APP_ID); - if(token) { - pickerBuilder.setOAuthToken(token.access_token); - } - 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").addClass("modal-backdrop")); - picker.setVisible(true); - }; - asyncTask.onSuccess = function() { - $(".modal-backdrop, .picker").remove(); - callback(ids); - }; - asyncTask.onError = function() { - if(picker !== undefined) { - picker.setVisible(false); - } + } + $(".modal-backdrop, .picker").remove(); + callback(ids); + } + }); + var picker = pickerBuilder.build(); + $("body").append($("
").addClass("modal-backdrop").click(function() { + picker.setVisible(false); $(".modal-backdrop, .picker").remove(); callback(); - }; - asyncTaskRunner.addTask(asyncTask); + })); + picker.setVisible(true); }); };