From 19c6c027863cf19d4bd01814d70c4b09d1aa292c Mon Sep 17 00:00:00 2001 From: benweet Date: Wed, 3 Apr 2013 19:35:25 +0100 Subject: [PATCH] Import document from Google Drive --- js/file-manager.js | 6 +----- js/gdrive.js | 48 +++++++++++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/js/file-manager.js b/js/file-manager.js index f2b5054d..38f44904 100644 --- a/js/file-manager.js +++ b/js/file-manager.js @@ -295,11 +295,7 @@ define(["jquery", "core", "gdrive", "synchronizer", "async-runner"], function($, if(fileId.length === 0) { return; } - gdrive.downloadMetadata([fileId], function(result) { - if(result === undefined || result.length === 0) { - return; - } - }); + gdrive.importFiles([fileId]); } function refreshManageSync() { diff --git a/js/gdrive.js b/js/gdrive.js index 5539cc69..d52a4129 100644 --- a/js/gdrive.js +++ b/js/gdrive.js @@ -254,8 +254,8 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) { message: jqXHR.statusText }; // Handle error - if(error.code === 403) { - error = "File is not available"; + if(error.code === 403 || error.code === 404) { + error = "File is not available."; } handleError(error, asyncTask, callback); }); @@ -365,6 +365,27 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) { gdrive.updateFile = function(id, title, content, callback) { upload(id, undefined, title, content, callback); }; + + gdrive.importFiles = function(ids) { + gdrive.downloadMetadata(ids, function(result) { + if(result === undefined) { + return; + } + gdrive.downloadContent(result, function(result) { + if(result === undefined) { + return; + } + for(var i=0; i