Added Google Drive support

This commit is contained in:
RainLoop Team 2014-07-30 12:48:59 +04:00
parent 7107104e1a
commit 7348b9b8a4
12 changed files with 177 additions and 147 deletions

View file

@ -9,9 +9,11 @@ function AdminSocial()
this.googleEnable = oData.googleEnable;
this.googleClientID = oData.googleClientID;
this.googleApiKey = oData.googleApiKey;
this.googleClientSecret = oData.googleClientSecret;
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,6 +47,7 @@ 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)
;
@ -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'

View file

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

View file

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

View file

@ -347,7 +347,9 @@ function PopupsComposeViewModel()
return this.dropboxEnabled();
});
this.driveEnabled = ko.observable(false && Globals.bXMLHttpRequestSupported && !!RL.settingsGet('GoogleClientID'));
this.driveEnabled = ko.observable(Globals.bXMLHttpRequestSupported &&
!!RL.settingsGet('GoogleClientID') && !!RL.settingsGet('GoogleApiKey'));
this.driveVisible = ko.observable(false);
this.driveCommand = Utils.createCommand(this, function () {
@ -994,7 +996,8 @@ PopupsComposeViewModel.prototype.onBuild = function ()
PopupsComposeViewModel.prototype.driveCallback = function (sAccessToken, oData)
{
if (oData && window.google && oData[window.google.picker.Response.ACTION] === window.google.picker.Action.PICKED &&
if (oData && window.XMLHttpRequest && 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]['id'])
{
@ -1008,19 +1011,49 @@ PopupsComposeViewModel.prototype.driveCallback = function (sAccessToken, oData)
oRequest.addEventListener('load', function() {
if (oRequest && oRequest.responseText)
{
var oItem = JSON.parse(oRequest.responseText);
var oItem = JSON.parse(oRequest.responseText), fExport = function (oItem, sMimeType, sExt) {
if (oItem && oItem['exportLinks'])
{
if (oItem['exportLinks'][sMimeType])
{
oItem['downloadUrl'] = oItem['exportLinks'][sMimeType];
oItem['title'] = oItem['title'] + '.' + sExt;
oItem['mimeType'] = sMimeType;
}
else if (oItem['exportLinks']['application/pdf'])
{
oItem['downloadUrl'] = oItem['exportLinks']['application/pdf'];
oItem['title'] = oItem['title'] + '.pdf';
oItem['mimeType'] = 'application/pdf';
}
}
};
if (oItem && !oItem['downloadUrl'] && oItem['mimeType'] && oItem['exportLinks'])
{
switch (oItem['mimeType'].toString().toLowerCase())
{
case 'application/vnd.google-apps.document':
fExport(oItem, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'docx');
break;
case 'application/vnd.google-apps.spreadsheet':
fExport(oItem, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'xlsx');
break;
case 'application/vnd.google-apps.drawing':
fExport(oItem, 'image/png', 'png');
break;
case 'application/vnd.google-apps.presentation':
fExport(oItem, 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'pptx');
break;
default:
fExport(oItem, 'application/pdf', 'pdf');
break;
}
}
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);
self.addDriveAttachment(oItem, sAccessToken);
}
}
});
@ -1434,11 +1467,11 @@ PopupsComposeViewModel.prototype.addDriveAttachment = function (oDriveFile, sAcc
},
iAttachmentSizeLimit = Utils.pInt(RL.settingsGet('AttachmentLimit')),
oAttachment = null,
mSize = Utils.pInt(oDriveFile['fileSize'])
mSize = oDriveFile['fileSize'] ? Utils.pInt(oDriveFile['fileSize']) : 0
;
oAttachment = new ComposeAttachmentModel(
oDriveFile['downloadUrl'], oDriveFile['originalFilename'], mSize
oDriveFile['downloadUrl'], oDriveFile['title'], mSize
);
oAttachment.fromMessage = false;
@ -1464,7 +1497,8 @@ PopupsComposeViewModel.prototype.addDriveAttachment = function (oDriveFile, sAcc
if (oData.Result[oAttachment.id])
{
bResult = true;
oAttachment.tempName(oData.Result[oAttachment.id]);
oAttachment.tempName(oData.Result[oAttachment.id][0]);
oAttachment.size(Utils.pInt(oData.Result[oAttachment.id][1]));
}
}