mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 12:39:20 +03:00
Google Drive (first look)
This commit is contained in:
parent
ba1f0403f7
commit
4d2df09946
16 changed files with 492 additions and 263 deletions
|
|
@ -10,8 +10,10 @@ function AdminSocial()
|
|||
this.googleEnable = oData.googleEnable;
|
||||
this.googleClientID = oData.googleClientID;
|
||||
this.googleClientSecret = oData.googleClientSecret;
|
||||
this.googleApiKey = oData.googleApiKey;
|
||||
this.googleTrigger1 = ko.observable(Enums.SaveSettingsStep.Idle);
|
||||
this.googleTrigger2 = ko.observable(Enums.SaveSettingsStep.Idle);
|
||||
this.googleTrigger3 = ko.observable(Enums.SaveSettingsStep.Idle);
|
||||
|
||||
this.facebookSupported = oData.facebookSupported;
|
||||
this.facebookEnable = oData.facebookEnable;
|
||||
|
|
@ -45,7 +47,8 @@ AdminSocial.prototype.onBuild = function ()
|
|||
f4 = Utils.settingsSaveHelperSimpleFunction(self.twitterTrigger2, self),
|
||||
f5 = Utils.settingsSaveHelperSimpleFunction(self.googleTrigger1, self),
|
||||
f6 = Utils.settingsSaveHelperSimpleFunction(self.googleTrigger2, self),
|
||||
f7 = Utils.settingsSaveHelperSimpleFunction(self.dropboxTrigger1, self)
|
||||
f7 = Utils.settingsSaveHelperSimpleFunction(self.googleTrigger3, self),
|
||||
f8 = Utils.settingsSaveHelperSimpleFunction(self.dropboxTrigger1, self)
|
||||
;
|
||||
|
||||
self.facebookEnable.subscribe(function (bValue) {
|
||||
|
|
@ -111,6 +114,12 @@ AdminSocial.prototype.onBuild = function ()
|
|||
});
|
||||
});
|
||||
|
||||
self.googleApiKey.subscribe(function (sValue) {
|
||||
RL.remote().saveAdminConfig(f7, {
|
||||
'GoogleApiKey': Utils.trim(sValue)
|
||||
});
|
||||
});
|
||||
|
||||
self.dropboxEnable.subscribe(function (bValue) {
|
||||
RL.remote().saveAdminConfig(Utils.emptyFunction, {
|
||||
'DropboxEnable': bValue ? '1' : '0'
|
||||
|
|
@ -118,7 +127,7 @@ AdminSocial.prototype.onBuild = function ()
|
|||
});
|
||||
|
||||
self.dropboxApiKey.subscribe(function (sValue) {
|
||||
RL.remote().saveAdminConfig(f7, {
|
||||
RL.remote().saveAdminConfig(f8, {
|
||||
'DropboxApiKey': Utils.trim(sValue)
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1118,6 +1118,7 @@ Utils.initDataConstructorBySettings = function (oData)
|
|||
oData.googleEnable = ko.observable(false);
|
||||
oData.googleClientID = ko.observable('');
|
||||
oData.googleClientSecret = ko.observable('');
|
||||
oData.googleApiKey = ko.observable('');
|
||||
|
||||
oData.dropboxEnable = ko.observable(false);
|
||||
oData.dropboxApiKey = ko.observable('');
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@ AbstractData.prototype.populateDataOnStart = function()
|
|||
this.googleEnable(!!RL.settingsGet('AllowGoogleSocial'));
|
||||
this.googleClientID(RL.settingsGet('GoogleClientID'));
|
||||
this.googleClientSecret(RL.settingsGet('GoogleClientSecret'));
|
||||
this.googleApiKey(RL.settingsGet('GoogleApiKey'));
|
||||
|
||||
this.dropboxEnable(!!RL.settingsGet('AllowDropboxSocial'));
|
||||
this.dropboxApiKey(RL.settingsGet('DropboxApiKey'));
|
||||
|
|
|
|||
|
|
@ -321,7 +321,7 @@ function PopupsComposeViewModel()
|
|||
this.triggerForResize();
|
||||
}, this);
|
||||
|
||||
this.dropboxEnabled = ko.observable(RL.settingsGet('DropboxApiKey') ? true : false);
|
||||
this.dropboxEnabled = ko.observable(!!RL.settingsGet('DropboxApiKey'));
|
||||
|
||||
this.dropboxCommand = Utils.createCommand(this, function () {
|
||||
|
||||
|
|
@ -347,18 +347,19 @@ function PopupsComposeViewModel()
|
|||
return this.dropboxEnabled();
|
||||
});
|
||||
|
||||
this.driveEnabled = ko.observable(false);
|
||||
this.driveEnabled = ko.observable(!!RL.settingsGet('GoogleApiKey') && !!RL.settingsGet('GoogleClientID'));
|
||||
this.driveVisible = ko.observable(false);
|
||||
|
||||
this.driveCommand = Utils.createCommand(this, function () {
|
||||
|
||||
// this.driveOpenPopup();
|
||||
this.driveOpenPopup();
|
||||
return true;
|
||||
|
||||
}, function () {
|
||||
return this.driveEnabled();
|
||||
});
|
||||
|
||||
// this.driveCallback = _.bind(this.driveCallback, this);
|
||||
this.driveCallback = _.bind(this.driveCallback, this);
|
||||
|
||||
this.bDisabeCloseOnEsc = true;
|
||||
this.sDefaultKeyScope = Enums.KeyState.Compose;
|
||||
|
|
@ -980,41 +981,89 @@ PopupsComposeViewModel.prototype.onBuild = function ()
|
|||
document.body.appendChild(oScript);
|
||||
}
|
||||
|
||||
// TODO (Google Drive)
|
||||
// if (false)
|
||||
// {
|
||||
// $.getScript('http://www.google.com/jsapi', function () {
|
||||
// if (window.google)
|
||||
// {
|
||||
// window.google.load('picker', '1', {
|
||||
// 'callback': Utils.emptyFunction
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
if (this.driveEnabled())
|
||||
{
|
||||
$.getScript('https://apis.google.com/js/api.js', function () {
|
||||
if (window.gapi)
|
||||
{
|
||||
self.driveVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//PopupsComposeViewModel.prototype.driveCallback = function (oData)
|
||||
//{
|
||||
// if (oData && window.google && oData['action'] === window.google.picker.Action.PICKED)
|
||||
// {
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//PopupsComposeViewModel.prototype.driveOpenPopup = function ()
|
||||
//{
|
||||
// if (window.google)
|
||||
// {
|
||||
// var
|
||||
// oPicker = new window.google.picker.PickerBuilder()
|
||||
// .enableFeature(window.google.picker.Feature.NAV_HIDDEN)
|
||||
// .addView(new window.google.picker.View(window.google.picker.ViewId.DOCS))
|
||||
// .setCallback(this.driveCallback).build()
|
||||
// ;
|
||||
//
|
||||
// oPicker.setVisible(true);
|
||||
// }
|
||||
//};
|
||||
PopupsComposeViewModel.prototype.driveCallback = function (oData)
|
||||
{
|
||||
if (oData && window.google && oData[window.google.picker.Response.ACTION] === window.google.picker.Action.PICKED &&
|
||||
oData[window.google.picker.Response.DOCUMENTS] && oData[window.google.picker.Response.DOCUMENTS][0] &&
|
||||
oData[window.google.picker.Response.DOCUMENTS][0]['url'])
|
||||
{
|
||||
this.addDriveAttachment(oData[window.google.picker.Response.DOCUMENTS][0]);
|
||||
}
|
||||
};
|
||||
|
||||
PopupsComposeViewModel.prototype.driveCreatePiker = function (oOauthToken)
|
||||
{
|
||||
if (window.gapi && oOauthToken && oOauthToken.access_token)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
window.gapi.load('picker', {'callback': function () {
|
||||
|
||||
if (window.google && window.google.picker)
|
||||
{
|
||||
var drivePicker = new window.google.picker.PickerBuilder()
|
||||
.addView(
|
||||
new window.google.picker.DocsView()
|
||||
.setIncludeFolders(true)
|
||||
)
|
||||
.setAppId(RL.settingsGet('GoogleClientID'))
|
||||
.setDeveloperKey(RL.settingsGet('GoogleApiKey'))
|
||||
.setOAuthToken(oOauthToken.access_token)
|
||||
.setCallback(_.bind(self.driveCallback, self))
|
||||
.enableFeature(window.google.picker.Feature.NAV_HIDDEN)
|
||||
.build()
|
||||
;
|
||||
|
||||
drivePicker.setVisible(true);
|
||||
}
|
||||
}});
|
||||
}
|
||||
};
|
||||
|
||||
PopupsComposeViewModel.prototype.driveOpenPopup = function ()
|
||||
{
|
||||
if (window.gapi)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
window.gapi.load('auth', {'callback': function () {
|
||||
|
||||
var oAuthToken = window.gapi.auth.getToken();
|
||||
if (!oAuthToken)
|
||||
{
|
||||
window.gapi.auth.authorize({
|
||||
'client_id': RL.settingsGet('GoogleClientID'),
|
||||
'scope': 'https://www.googleapis.com/auth/drive.readonly',
|
||||
'immediate': false
|
||||
}, function (oAuthResult) {
|
||||
if (oAuthResult && !oAuthResult.error)
|
||||
{
|
||||
var oAuthToken = window.gapi.auth.getToken();
|
||||
if (oAuthToken)
|
||||
{
|
||||
self.driveCreatePiker(oAuthToken);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
self.driveCreatePiker(oAuthToken);
|
||||
}
|
||||
}});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sId
|
||||
|
|
@ -1339,6 +1388,16 @@ PopupsComposeViewModel.prototype.addDropboxAttachment = function (oDropboxFile)
|
|||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} oDriveFile
|
||||
* @return {boolean}
|
||||
*/
|
||||
PopupsComposeViewModel.prototype.addDriveAttachment = function (oDriveFile)
|
||||
{
|
||||
window.console.log(oDriveFile);
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {MessageModel} oMessage
|
||||
* @param {string} sType
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue