mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-01 13:39:22 +03:00
Google Drive (second look)
This commit is contained in:
parent
eea55d4e0a
commit
7107104e1a
18 changed files with 507 additions and 233 deletions
|
|
@ -10,10 +10,8 @@ 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;
|
||||
|
|
@ -47,7 +45,6 @@ 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.googleTrigger3, self),
|
||||
f8 = Utils.settingsSaveHelperSimpleFunction(self.dropboxTrigger1, self)
|
||||
;
|
||||
|
||||
|
|
@ -114,12 +111,6 @@ 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'
|
||||
|
|
|
|||
|
|
@ -80,6 +80,11 @@ Globals.bAllowPdfPreview = !Globals.bMobileDevice;
|
|||
*/
|
||||
Globals.bAnimationSupported = !Globals.bMobileDevice && $html.hasClass('csstransitions');
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
Globals.bXMLHttpRequestSupported = !!window.XMLHttpRequest;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1118,7 +1118,6 @@ 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('');
|
||||
|
|
@ -2016,3 +2015,21 @@ Utils.detectDropdownVisibility = _.debounce(function () {
|
|||
return oItem.hasClass('open');
|
||||
}));
|
||||
}, 50);
|
||||
|
||||
Utils.triggerAutocompleteInputChange = function (bDelay) {
|
||||
|
||||
var fFunc = function () {
|
||||
$('.checkAutocomplete').trigger('change');
|
||||
};
|
||||
|
||||
if (bDelay)
|
||||
{
|
||||
_.delay(fFunc, 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
fFunc();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -125,7 +125,6 @@ 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'));
|
||||
|
|
|
|||
|
|
@ -302,6 +302,18 @@ WebMailAjaxRemoteStorage.prototype.composeUploadExternals = function (fCallback,
|
|||
}, 999000);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {?Function} fCallback
|
||||
* @param {Array} aExternals
|
||||
*/
|
||||
WebMailAjaxRemoteStorage.prototype.composeUploadDrive = function (fCallback, sUrl, sAccessToken)
|
||||
{
|
||||
this.defaultRequest(fCallback, 'ComposeUploadDrive', {
|
||||
'AccessToken': sAccessToken,
|
||||
'Url': sUrl
|
||||
}, 999000);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {?Function} fCallback
|
||||
* @param {string} sFolder
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ function AdminLoginViewModel()
|
|||
|
||||
this.submitCommand = Utils.createCommand(this, function () {
|
||||
|
||||
Utils.triggerAutocompleteInputChange();
|
||||
|
||||
this.loginError('' === Utils.trim(this.login()));
|
||||
this.passwordError('' === Utils.trim(this.password()));
|
||||
|
||||
|
|
@ -89,9 +91,7 @@ AdminLoginViewModel.prototype.onHide = function ()
|
|||
|
||||
AdminLoginViewModel.prototype.onBuild = function ()
|
||||
{
|
||||
_.delay(function () {
|
||||
$('.checkAutocomplete').trigger('change');
|
||||
}, 100);
|
||||
Utils.triggerAutocompleteInputChange(true);
|
||||
};
|
||||
|
||||
AdminLoginViewModel.prototype.submitForm = function ()
|
||||
|
|
|
|||
|
|
@ -73,6 +73,8 @@ function LoginViewModel()
|
|||
|
||||
this.submitCommand = Utils.createCommand(this, function () {
|
||||
|
||||
Utils.triggerAutocompleteInputChange();
|
||||
|
||||
this.emailError('' === Utils.trim(this.email()));
|
||||
this.passwordError('' === Utils.trim(this.password()));
|
||||
|
||||
|
|
@ -326,9 +328,7 @@ LoginViewModel.prototype.onBuild = function ()
|
|||
});
|
||||
}, 50);
|
||||
|
||||
_.delay(function () {
|
||||
$('.checkAutocomplete').trigger('change');
|
||||
}, 100);
|
||||
Utils.triggerAutocompleteInputChange(true);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -347,7 +347,7 @@ function PopupsComposeViewModel()
|
|||
return this.dropboxEnabled();
|
||||
});
|
||||
|
||||
this.driveEnabled = ko.observable(!!RL.settingsGet('GoogleApiKey') && !!RL.settingsGet('GoogleClientID'));
|
||||
this.driveEnabled = ko.observable(false && Globals.bXMLHttpRequestSupported && !!RL.settingsGet('GoogleClientID'));
|
||||
this.driveVisible = ko.observable(false);
|
||||
|
||||
this.driveCommand = Utils.createCommand(this, function () {
|
||||
|
|
@ -992,13 +992,40 @@ PopupsComposeViewModel.prototype.onBuild = function ()
|
|||
}
|
||||
};
|
||||
|
||||
PopupsComposeViewModel.prototype.driveCallback = function (oData)
|
||||
PopupsComposeViewModel.prototype.driveCallback = function (sAccessToken, 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'])
|
||||
oData[window.google.picker.Response.DOCUMENTS][0]['id'])
|
||||
{
|
||||
this.addDriveAttachment(oData[window.google.picker.Response.DOCUMENTS][0]);
|
||||
var
|
||||
self = this,
|
||||
oRequest = new window.XMLHttpRequest()
|
||||
;
|
||||
|
||||
oRequest.open('GET', 'https://www.googleapis.com/drive/v2/files/' + oData[window.google.picker.Response.DOCUMENTS][0]['id']);
|
||||
oRequest.setRequestHeader('Authorization', 'Bearer ' + sAccessToken);
|
||||
oRequest.addEventListener('load', function() {
|
||||
if (oRequest && oRequest.responseText)
|
||||
{
|
||||
var oItem = JSON.parse(oRequest.responseText);
|
||||
if (oItem && oItem['downloadUrl'])
|
||||
{
|
||||
window.console.log(oItem['downloadUrl']);
|
||||
var oSubRequest = new window.XMLHttpRequest();
|
||||
oSubRequest.open('GET', oItem['downloadUrl']);
|
||||
oSubRequest.setRequestHeader('Authorization', 'Bearer ' + sAccessToken);
|
||||
oSubRequest.addEventListener('load', function() {
|
||||
window.console.log(oSubRequest);
|
||||
});
|
||||
|
||||
oSubRequest.send();
|
||||
// self.addDriveAttachment(oItem, sAccessToken);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
oRequest.send();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -1018,9 +1045,8 @@ PopupsComposeViewModel.prototype.driveCreatePiker = function (oOauthToken)
|
|||
.setIncludeFolders(true)
|
||||
)
|
||||
.setAppId(RL.settingsGet('GoogleClientID'))
|
||||
.setDeveloperKey(RL.settingsGet('GoogleApiKey'))
|
||||
.setOAuthToken(oOauthToken.access_token)
|
||||
.setCallback(_.bind(self.driveCallback, self))
|
||||
.setCallback(_.bind(self.driveCallback, self, oOauthToken.access_token))
|
||||
.enableFeature(window.google.picker.Feature.NAV_HIDDEN)
|
||||
.build()
|
||||
;
|
||||
|
|
@ -1044,7 +1070,9 @@ PopupsComposeViewModel.prototype.driveOpenPopup = function ()
|
|||
{
|
||||
window.gapi.auth.authorize({
|
||||
'client_id': RL.settingsGet('GoogleClientID'),
|
||||
'scope': 'https://www.googleapis.com/auth/drive.readonly',
|
||||
'scope': [
|
||||
'https://www.googleapis.com/auth/drive.readonly'
|
||||
].join(' '),
|
||||
'immediate': false
|
||||
}, function (oAuthResult) {
|
||||
if (oAuthResult && !oAuthResult.error)
|
||||
|
|
@ -1390,12 +1418,64 @@ PopupsComposeViewModel.prototype.addDropboxAttachment = function (oDropboxFile)
|
|||
|
||||
/**
|
||||
* @param {Object} oDriveFile
|
||||
* @param {string} sAccessToken
|
||||
* @return {boolean}
|
||||
*/
|
||||
PopupsComposeViewModel.prototype.addDriveAttachment = function (oDriveFile)
|
||||
PopupsComposeViewModel.prototype.addDriveAttachment = function (oDriveFile, sAccessToken)
|
||||
{
|
||||
window.console.log(oDriveFile);
|
||||
return false;
|
||||
var
|
||||
self = this,
|
||||
fCancelFunc = function (sId) {
|
||||
return function () {
|
||||
self.attachments.remove(function (oItem) {
|
||||
return oItem && oItem.id === sId;
|
||||
});
|
||||
};
|
||||
},
|
||||
iAttachmentSizeLimit = Utils.pInt(RL.settingsGet('AttachmentLimit')),
|
||||
oAttachment = null,
|
||||
mSize = Utils.pInt(oDriveFile['fileSize'])
|
||||
;
|
||||
|
||||
oAttachment = new ComposeAttachmentModel(
|
||||
oDriveFile['downloadUrl'], oDriveFile['originalFilename'], mSize
|
||||
);
|
||||
|
||||
oAttachment.fromMessage = false;
|
||||
oAttachment.cancel = fCancelFunc(oDriveFile['downloadUrl']);
|
||||
oAttachment.waiting(false).uploading(true);
|
||||
|
||||
this.attachments.push(oAttachment);
|
||||
|
||||
if (0 < mSize && 0 < iAttachmentSizeLimit && iAttachmentSizeLimit < mSize)
|
||||
{
|
||||
oAttachment.uploading(false);
|
||||
oAttachment.error(Utils.i18n('UPLOAD/ERROR_FILE_IS_TOO_BIG'));
|
||||
return false;
|
||||
}
|
||||
|
||||
RL.remote().composeUploadDrive(function (sResult, oData) {
|
||||
|
||||
var bResult = false;
|
||||
oAttachment.uploading(false);
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
if (oData.Result[oAttachment.id])
|
||||
{
|
||||
bResult = true;
|
||||
oAttachment.tempName(oData.Result[oAttachment.id]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!bResult)
|
||||
{
|
||||
oAttachment.error(Utils.getUploadErrorDescByCode(Enums.UploadErrorCode.FileNoUploaded));
|
||||
}
|
||||
|
||||
}, oDriveFile['downloadUrl'], sAccessToken);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue