mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-09-20 23:55:55 +08:00
Google Drive (first look)
This commit is contained in:
parent
ba1f0403f7
commit
4d2df09946
|
@ -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
|
||||
|
|
|
@ -626,6 +626,74 @@ class Utils
|
|||
return \trim($sValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sAttrName
|
||||
* @param string $sValue = 'utf-8'
|
||||
* @param string $sCharset = ''
|
||||
* @param string $sLang = ''
|
||||
* @param int $iLen = 78
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public static function AttributeRfc2231Encode($sAttrName, $sValue, $sCharset = 'utf-8', $sLang = '', $iLen = 1000)
|
||||
{
|
||||
$sValue = \strtoupper($sCharset).'\''.$sLang.'\''.
|
||||
\preg_replace_callback('/[\x00-\x20*\'%()<>@,;:\\\\"\/[\]?=\x80-\xFF]/', function ($match) {
|
||||
return \rawurlencode($match[0]);
|
||||
}, $sValue);
|
||||
|
||||
$iNlen = \strlen($sAttrName);
|
||||
$iVlen = \strlen($sValue);
|
||||
|
||||
if (\strlen($sAttrName) + $iVlen > $iLen - 3)
|
||||
{
|
||||
$sections = array();
|
||||
$section = 0;
|
||||
|
||||
for ($i = 0, $j = 0; $i < $iVlen; $i += $j)
|
||||
{
|
||||
$j = $iLen - $iNlen - \strlen($section) - 4;
|
||||
$sections[$section++] = \substr($sValue, $i, $j);
|
||||
}
|
||||
|
||||
for ($i = 0, $n = $section; $i < $n; $i++)
|
||||
{
|
||||
$sections[$i] = ' '.$sAttrName.'*'.$i.'*='.$sections[$i];
|
||||
}
|
||||
|
||||
return \implode(";\r\n", $sections);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $sAttrName.'*='.$sValue;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param string $sAttrName
|
||||
* @param string $sValue
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function EncodeHeaderUtf8AttributeValue($sAttrName, $sValue)
|
||||
{
|
||||
$sAttrName = \trim($sAttrName);
|
||||
$sValue = \trim($sValue);
|
||||
|
||||
if (0 < \strlen($sValue) && !\MailSo\Base\Utils::IsAscii($sValue))
|
||||
{
|
||||
if (!empty($_SERVER['HTTP_USER_AGENT']) && 0 < \strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
|
||||
{
|
||||
$sValue = $sAttrName.'="'.\preg_replace('/[+\s]+/', '%20', \urlencode($sValue)).'"';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sValue = \MailSo\Base\Utils::AttributeRfc2231Encode($sAttrName, $sValue);
|
||||
}
|
||||
}
|
||||
|
||||
return \trim($sValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
*
|
||||
|
|
|
@ -361,7 +361,7 @@ class Message
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $iDateTime $iDateTime
|
||||
* @param int $iDateTime
|
||||
*
|
||||
* @return \MailSo\Mime\Message
|
||||
*/
|
||||
|
|
|
@ -1129,10 +1129,14 @@ class Actions
|
|||
}
|
||||
|
||||
$aResult['AllowGoogleSocial'] = (bool) $oConfig->Get('social', 'google_enable', false);
|
||||
$aResult['GoogleClientID'] = \trim($oConfig->Get('social', 'google_client_id', ''));
|
||||
$aResult['GoogleApiKey'] = \trim($oConfig->Get('social', 'google_api_key', ''));
|
||||
if ($aResult['AllowGoogleSocial'] && (
|
||||
'' === \trim($oConfig->Get('social', 'google_client_id', '')) || '' === \trim($oConfig->Get('social', 'google_client_secret', ''))))
|
||||
{
|
||||
$aResult['AllowGoogleSocial'] = false;
|
||||
$aResult['GoogleClientID'] = '';
|
||||
$aResult['GoogleApiKey'] = '';
|
||||
}
|
||||
|
||||
$aResult['AllowFacebookSocial'] = (bool) $oConfig->Get('social', 'fb_enable', false);
|
||||
|
@ -1189,6 +1193,7 @@ class Actions
|
|||
$aResult['AllowGoogleSocial'] = (bool) $oConfig->Get('social', 'google_enable', false);
|
||||
$aResult['GoogleClientID'] = (string) $oConfig->Get('social', 'google_client_id', '');
|
||||
$aResult['GoogleClientSecret'] = (string) $oConfig->Get('social', 'google_client_secret', '');
|
||||
$aResult['GoogleApiKey'] = (string) $oConfig->Get('social', 'google_api_key', '');
|
||||
|
||||
$aResult['AllowFacebookSocial'] = (bool) $oConfig->Get('social', 'fb_enable', false);
|
||||
$aResult['FacebookAppID'] = (string) $oConfig->Get('social', 'fb_app_id', '');
|
||||
|
@ -2394,6 +2399,7 @@ class Actions
|
|||
$this->setConfigFromParams($oConfig, 'GoogleEnable', 'social', 'google_enable', 'bool');
|
||||
$this->setConfigFromParams($oConfig, 'GoogleClientID', 'social', 'google_client_id', 'string');
|
||||
$this->setConfigFromParams($oConfig, 'GoogleClientSecret', 'social', 'google_client_secret', 'string');
|
||||
$this->setConfigFromParams($oConfig, 'GoogleApiKey', 'social', 'google_api_key', 'string');
|
||||
|
||||
$this->setConfigFromParams($oConfig, 'FacebookEnable', 'social', 'fb_enable', 'bool');
|
||||
$this->setConfigFromParams($oConfig, 'FacebookAppID', 'social', 'fb_app_id', 'string');
|
||||
|
@ -6389,7 +6395,7 @@ class Actions
|
|||
$self = $this;
|
||||
return $this->MailClient()->MessageMimeStream(
|
||||
function($rResource, $sContentType, $sFileName, $sMimeIndex = '') use ($self, $sRawKey, $sContentTypeIn, $sFileNameIn, $bDownload) {
|
||||
if (is_resource($rResource))
|
||||
if (\is_resource($rResource))
|
||||
{
|
||||
$sContentTypeOut = $sContentTypeIn;
|
||||
if (empty($sContentTypeOut))
|
||||
|
@ -6409,10 +6415,12 @@ class Actions
|
|||
|
||||
$sFileNameOut = $self->MainClearFileName($sFileNameOut, $sContentTypeOut, $sMimeIndex);
|
||||
|
||||
header('Content-Type: '.$sContentTypeOut);
|
||||
header('Content-Disposition: '.($bDownload ? 'attachment' : 'inline').'; filename="'.$sFileNameOut.'"; charset=utf-8', true);
|
||||
header('Accept-Ranges: none', true);
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
\header('Content-Type: '.$sContentTypeOut);
|
||||
\header('Content-Disposition: '.($bDownload ? 'attachment' : 'inline').'; '.
|
||||
\trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileNameOut)), true);
|
||||
|
||||
\header('Accept-Ranges: none', true);
|
||||
\header('Content-Transfer-Encoding: binary');
|
||||
|
||||
$self->cacheByKey($sRawKey);
|
||||
|
||||
|
|
|
@ -182,6 +182,7 @@ Examples:
|
|||
'google_enable' => array(false, 'Google'),
|
||||
'google_client_id' => array(''),
|
||||
'google_client_secret' => array(''),
|
||||
'google_api_key' => array(''),
|
||||
|
||||
'fb_enable' => array(false, 'Facebook'),
|
||||
'fb_app_id' => array(''),
|
||||
|
|
|
@ -37,6 +37,16 @@
|
|||
<div data-bind="saveTrigger: googleTrigger2"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">
|
||||
Client Api Key
|
||||
</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="span5" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
|
||||
data-bind="value: googleApiKey, saveTrigger: googleTrigger3" />
|
||||
<div data-bind="saveTrigger: googleTrigger3"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="legend">
|
||||
Facebook
|
||||
<span style="color: #ccc; font-size: 14px;" data-bind="visible: !facebookSupported()">(requires PHP 5.4 or greater)</span>
|
||||
|
|
|
@ -140,7 +140,7 @@
|
|||
<a class="btn" data-tooltip-placement="top" data-bind="visible: dropboxEnabled, command: dropboxCommand, tooltip: 'COMPOSE/DROPBOX'">
|
||||
<i class="icon-dropbox"></i>
|
||||
</a>
|
||||
<a class="btn" data-tooltip-placement="top" data-bind="visible: driveEnabled, command: driveCommand, tooltip: 'COMPOSE/GOOGLE_DRIVE'">
|
||||
<a class="btn" data-tooltip-placement="top" data-bind="visible: driveEnabled() && driveVisible(), command: driveCommand, tooltip: 'COMPOSE/GOOGLE_DRIVE'">
|
||||
<i class="icon-google-drive"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
@ -1915,6 +1915,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('');
|
||||
|
@ -7000,8 +7001,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;
|
||||
|
@ -7035,7 +7038,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) {
|
||||
|
@ -7101,6 +7105,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'
|
||||
|
@ -7108,7 +7118,7 @@ AdminSocial.prototype.onBuild = function ()
|
|||
});
|
||||
|
||||
self.dropboxApiKey.subscribe(function (sValue) {
|
||||
RL.remote().saveAdminConfig(f7, {
|
||||
RL.remote().saveAdminConfig(f8, {
|
||||
'DropboxApiKey': Utils.trim(sValue)
|
||||
});
|
||||
});
|
||||
|
@ -7576,6 +7586,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'));
|
||||
|
|
8
rainloop/v/0.0.0/static/js/admin.min.js
vendored
8
rainloop/v/0.0.0/static/js/admin.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1918,6 +1918,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('');
|
||||
|
@ -9304,7 +9305,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 () {
|
||||
|
||||
|
@ -9330,18 +9331,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;
|
||||
|
@ -9963,41 +9965,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
|
||||
|
@ -10322,6 +10372,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
|
||||
|
@ -16221,6 +16281,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'));
|
||||
|
|
16
rainloop/v/0.0.0/static/js/app.min.js
vendored
16
rainloop/v/0.0.0/static/js/app.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue