Added Google picker

This commit is contained in:
Benoit Schweblin 2013-04-06 02:07:45 +01:00
parent 932fc4afc7
commit 8e686968ac
2 changed files with 29 additions and 40 deletions

View File

@ -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);

View File

@ -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<data.docs.length; i++) {
ids.push(data.docs[i].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) {
var ids = [];
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, .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($("<div>").addClass("modal-backdrop").click(function() {
picker.setVisible(false);
$(".modal-backdrop, .picker").remove();
callback();
};
asyncTaskRunner.addTask(asyncTask);
}));
picker.setVisible(true);
});
};