Google Drive (first look)

This commit is contained in:
RainLoop Team 2014-07-28 19:55:22 +04:00
parent ba1f0403f7
commit 4d2df09946
16 changed files with 492 additions and 263 deletions

View file

@ -10,8 +10,10 @@ function AdminSocial()
this.googleEnable = oData.googleEnable; this.googleEnable = oData.googleEnable;
this.googleClientID = oData.googleClientID; this.googleClientID = oData.googleClientID;
this.googleClientSecret = oData.googleClientSecret; this.googleClientSecret = oData.googleClientSecret;
this.googleApiKey = oData.googleApiKey;
this.googleTrigger1 = ko.observable(Enums.SaveSettingsStep.Idle); this.googleTrigger1 = ko.observable(Enums.SaveSettingsStep.Idle);
this.googleTrigger2 = ko.observable(Enums.SaveSettingsStep.Idle); this.googleTrigger2 = ko.observable(Enums.SaveSettingsStep.Idle);
this.googleTrigger3 = ko.observable(Enums.SaveSettingsStep.Idle);
this.facebookSupported = oData.facebookSupported; this.facebookSupported = oData.facebookSupported;
this.facebookEnable = oData.facebookEnable; this.facebookEnable = oData.facebookEnable;
@ -45,7 +47,8 @@ AdminSocial.prototype.onBuild = function ()
f4 = Utils.settingsSaveHelperSimpleFunction(self.twitterTrigger2, self), f4 = Utils.settingsSaveHelperSimpleFunction(self.twitterTrigger2, self),
f5 = Utils.settingsSaveHelperSimpleFunction(self.googleTrigger1, self), f5 = Utils.settingsSaveHelperSimpleFunction(self.googleTrigger1, self),
f6 = Utils.settingsSaveHelperSimpleFunction(self.googleTrigger2, 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) { 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) { self.dropboxEnable.subscribe(function (bValue) {
RL.remote().saveAdminConfig(Utils.emptyFunction, { RL.remote().saveAdminConfig(Utils.emptyFunction, {
'DropboxEnable': bValue ? '1' : '0' 'DropboxEnable': bValue ? '1' : '0'
@ -118,7 +127,7 @@ AdminSocial.prototype.onBuild = function ()
}); });
self.dropboxApiKey.subscribe(function (sValue) { self.dropboxApiKey.subscribe(function (sValue) {
RL.remote().saveAdminConfig(f7, { RL.remote().saveAdminConfig(f8, {
'DropboxApiKey': Utils.trim(sValue) 'DropboxApiKey': Utils.trim(sValue)
}); });
}); });

View file

@ -1118,6 +1118,7 @@ Utils.initDataConstructorBySettings = function (oData)
oData.googleEnable = ko.observable(false); oData.googleEnable = ko.observable(false);
oData.googleClientID = ko.observable(''); oData.googleClientID = ko.observable('');
oData.googleClientSecret = ko.observable(''); oData.googleClientSecret = ko.observable('');
oData.googleApiKey = ko.observable('');
oData.dropboxEnable = ko.observable(false); oData.dropboxEnable = ko.observable(false);
oData.dropboxApiKey = ko.observable(''); oData.dropboxApiKey = ko.observable('');

View file

@ -125,6 +125,7 @@ AbstractData.prototype.populateDataOnStart = function()
this.googleEnable(!!RL.settingsGet('AllowGoogleSocial')); this.googleEnable(!!RL.settingsGet('AllowGoogleSocial'));
this.googleClientID(RL.settingsGet('GoogleClientID')); this.googleClientID(RL.settingsGet('GoogleClientID'));
this.googleClientSecret(RL.settingsGet('GoogleClientSecret')); this.googleClientSecret(RL.settingsGet('GoogleClientSecret'));
this.googleApiKey(RL.settingsGet('GoogleApiKey'));
this.dropboxEnable(!!RL.settingsGet('AllowDropboxSocial')); this.dropboxEnable(!!RL.settingsGet('AllowDropboxSocial'));
this.dropboxApiKey(RL.settingsGet('DropboxApiKey')); this.dropboxApiKey(RL.settingsGet('DropboxApiKey'));

View file

@ -321,7 +321,7 @@ function PopupsComposeViewModel()
this.triggerForResize(); this.triggerForResize();
}, this); }, this);
this.dropboxEnabled = ko.observable(RL.settingsGet('DropboxApiKey') ? true : false); this.dropboxEnabled = ko.observable(!!RL.settingsGet('DropboxApiKey'));
this.dropboxCommand = Utils.createCommand(this, function () { this.dropboxCommand = Utils.createCommand(this, function () {
@ -347,18 +347,19 @@ function PopupsComposeViewModel()
return this.dropboxEnabled(); 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.driveCommand = Utils.createCommand(this, function () {
// this.driveOpenPopup(); this.driveOpenPopup();
return true; return true;
}, function () { }, function () {
return this.driveEnabled(); return this.driveEnabled();
}); });
// this.driveCallback = _.bind(this.driveCallback, this); this.driveCallback = _.bind(this.driveCallback, this);
this.bDisabeCloseOnEsc = true; this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = Enums.KeyState.Compose; this.sDefaultKeyScope = Enums.KeyState.Compose;
@ -980,41 +981,89 @@ PopupsComposeViewModel.prototype.onBuild = function ()
document.body.appendChild(oScript); document.body.appendChild(oScript);
} }
// TODO (Google Drive) if (this.driveEnabled())
// if (false) {
// { $.getScript('https://apis.google.com/js/api.js', function () {
// $.getScript('http://www.google.com/jsapi', function () { if (window.gapi)
// if (window.google) {
// { self.driveVisible(true);
// window.google.load('picker', '1', { }
// 'callback': Utils.emptyFunction });
// }); }
// }
// });
// }
}; };
//PopupsComposeViewModel.prototype.driveCallback = function (oData) PopupsComposeViewModel.prototype.driveCallback = function (oData)
//{ {
// if (oData && window.google && oData['action'] === window.google.picker.Action.PICKED) 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.driveOpenPopup = function () }
//{ };
// if (window.google)
// { PopupsComposeViewModel.prototype.driveCreatePiker = function (oOauthToken)
// var {
// oPicker = new window.google.picker.PickerBuilder() if (window.gapi && oOauthToken && oOauthToken.access_token)
// .enableFeature(window.google.picker.Feature.NAV_HIDDEN) {
// .addView(new window.google.picker.View(window.google.picker.ViewId.DOCS)) var self = this;
// .setCallback(this.driveCallback).build()
// ; window.gapi.load('picker', {'callback': function () {
//
// oPicker.setVisible(true); 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 * @param {string} sId
@ -1339,6 +1388,16 @@ PopupsComposeViewModel.prototype.addDropboxAttachment = function (oDropboxFile)
return true; return true;
}; };
/**
* @param {Object} oDriveFile
* @return {boolean}
*/
PopupsComposeViewModel.prototype.addDriveAttachment = function (oDriveFile)
{
window.console.log(oDriveFile);
return false;
};
/** /**
* @param {MessageModel} oMessage * @param {MessageModel} oMessage
* @param {string} sType * @param {string} sType

View file

@ -626,6 +626,74 @@ class Utils
return \trim($sValue); 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 * @param string $sEmail
* *

View file

@ -361,7 +361,7 @@ class Message
} }
/** /**
* @param $iDateTime $iDateTime * @param int $iDateTime
* *
* @return \MailSo\Mime\Message * @return \MailSo\Mime\Message
*/ */

View file

@ -1129,10 +1129,14 @@ class Actions
} }
$aResult['AllowGoogleSocial'] = (bool) $oConfig->Get('social', 'google_enable', false); $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'] && ( if ($aResult['AllowGoogleSocial'] && (
'' === \trim($oConfig->Get('social', 'google_client_id', '')) || '' === \trim($oConfig->Get('social', 'google_client_secret', '')))) '' === \trim($oConfig->Get('social', 'google_client_id', '')) || '' === \trim($oConfig->Get('social', 'google_client_secret', ''))))
{ {
$aResult['AllowGoogleSocial'] = false; $aResult['AllowGoogleSocial'] = false;
$aResult['GoogleClientID'] = '';
$aResult['GoogleApiKey'] = '';
} }
$aResult['AllowFacebookSocial'] = (bool) $oConfig->Get('social', 'fb_enable', false); $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['AllowGoogleSocial'] = (bool) $oConfig->Get('social', 'google_enable', false);
$aResult['GoogleClientID'] = (string) $oConfig->Get('social', 'google_client_id', ''); $aResult['GoogleClientID'] = (string) $oConfig->Get('social', 'google_client_id', '');
$aResult['GoogleClientSecret'] = (string) $oConfig->Get('social', 'google_client_secret', ''); $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['AllowFacebookSocial'] = (bool) $oConfig->Get('social', 'fb_enable', false);
$aResult['FacebookAppID'] = (string) $oConfig->Get('social', 'fb_app_id', ''); $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, 'GoogleEnable', 'social', 'google_enable', 'bool');
$this->setConfigFromParams($oConfig, 'GoogleClientID', 'social', 'google_client_id', 'string'); $this->setConfigFromParams($oConfig, 'GoogleClientID', 'social', 'google_client_id', 'string');
$this->setConfigFromParams($oConfig, 'GoogleClientSecret', 'social', 'google_client_secret', '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, 'FacebookEnable', 'social', 'fb_enable', 'bool');
$this->setConfigFromParams($oConfig, 'FacebookAppID', 'social', 'fb_app_id', 'string'); $this->setConfigFromParams($oConfig, 'FacebookAppID', 'social', 'fb_app_id', 'string');
@ -6389,7 +6395,7 @@ class Actions
$self = $this; $self = $this;
return $this->MailClient()->MessageMimeStream( return $this->MailClient()->MessageMimeStream(
function($rResource, $sContentType, $sFileName, $sMimeIndex = '') use ($self, $sRawKey, $sContentTypeIn, $sFileNameIn, $bDownload) { function($rResource, $sContentType, $sFileName, $sMimeIndex = '') use ($self, $sRawKey, $sContentTypeIn, $sFileNameIn, $bDownload) {
if (is_resource($rResource)) if (\is_resource($rResource))
{ {
$sContentTypeOut = $sContentTypeIn; $sContentTypeOut = $sContentTypeIn;
if (empty($sContentTypeOut)) if (empty($sContentTypeOut))
@ -6409,10 +6415,12 @@ class Actions
$sFileNameOut = $self->MainClearFileName($sFileNameOut, $sContentTypeOut, $sMimeIndex); $sFileNameOut = $self->MainClearFileName($sFileNameOut, $sContentTypeOut, $sMimeIndex);
header('Content-Type: '.$sContentTypeOut); \header('Content-Type: '.$sContentTypeOut);
header('Content-Disposition: '.($bDownload ? 'attachment' : 'inline').'; filename="'.$sFileNameOut.'"; charset=utf-8', true); \header('Content-Disposition: '.($bDownload ? 'attachment' : 'inline').'; '.
header('Accept-Ranges: none', true); \trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileNameOut)), true);
header('Content-Transfer-Encoding: binary');
\header('Accept-Ranges: none', true);
\header('Content-Transfer-Encoding: binary');
$self->cacheByKey($sRawKey); $self->cacheByKey($sRawKey);

View file

@ -182,6 +182,7 @@ Examples:
'google_enable' => array(false, 'Google'), 'google_enable' => array(false, 'Google'),
'google_client_id' => array(''), 'google_client_id' => array(''),
'google_client_secret' => array(''), 'google_client_secret' => array(''),
'google_api_key' => array(''),
'fb_enable' => array(false, 'Facebook'), 'fb_enable' => array(false, 'Facebook'),
'fb_app_id' => array(''), 'fb_app_id' => array(''),

View file

@ -37,6 +37,16 @@
<div data-bind="saveTrigger: googleTrigger2"></div> <div data-bind="saveTrigger: googleTrigger2"></div>
</div> </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"> <div class="legend">
Facebook Facebook
<span style="color: #ccc; font-size: 14px;" data-bind="visible: !facebookSupported()">(requires PHP 5.4 or greater)</span> <span style="color: #ccc; font-size: 14px;" data-bind="visible: !facebookSupported()">(requires PHP 5.4 or greater)</span>

View file

@ -140,7 +140,7 @@
<a class="btn" data-tooltip-placement="top" data-bind="visible: dropboxEnabled, command: dropboxCommand, tooltip: 'COMPOSE/DROPBOX'"> <a class="btn" data-tooltip-placement="top" data-bind="visible: dropboxEnabled, command: dropboxCommand, tooltip: 'COMPOSE/DROPBOX'">
<i class="icon-dropbox"></i> <i class="icon-dropbox"></i>
</a> </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> <i class="icon-google-drive"></i>
</a> </a>
</div> </div>

View file

@ -1915,6 +1915,7 @@ Utils.initDataConstructorBySettings = function (oData)
oData.googleEnable = ko.observable(false); oData.googleEnable = ko.observable(false);
oData.googleClientID = ko.observable(''); oData.googleClientID = ko.observable('');
oData.googleClientSecret = ko.observable(''); oData.googleClientSecret = ko.observable('');
oData.googleApiKey = ko.observable('');
oData.dropboxEnable = ko.observable(false); oData.dropboxEnable = ko.observable(false);
oData.dropboxApiKey = ko.observable(''); oData.dropboxApiKey = ko.observable('');
@ -7000,8 +7001,10 @@ function AdminSocial()
this.googleEnable = oData.googleEnable; this.googleEnable = oData.googleEnable;
this.googleClientID = oData.googleClientID; this.googleClientID = oData.googleClientID;
this.googleClientSecret = oData.googleClientSecret; this.googleClientSecret = oData.googleClientSecret;
this.googleApiKey = oData.googleApiKey;
this.googleTrigger1 = ko.observable(Enums.SaveSettingsStep.Idle); this.googleTrigger1 = ko.observable(Enums.SaveSettingsStep.Idle);
this.googleTrigger2 = ko.observable(Enums.SaveSettingsStep.Idle); this.googleTrigger2 = ko.observable(Enums.SaveSettingsStep.Idle);
this.googleTrigger3 = ko.observable(Enums.SaveSettingsStep.Idle);
this.facebookSupported = oData.facebookSupported; this.facebookSupported = oData.facebookSupported;
this.facebookEnable = oData.facebookEnable; this.facebookEnable = oData.facebookEnable;
@ -7035,7 +7038,8 @@ AdminSocial.prototype.onBuild = function ()
f4 = Utils.settingsSaveHelperSimpleFunction(self.twitterTrigger2, self), f4 = Utils.settingsSaveHelperSimpleFunction(self.twitterTrigger2, self),
f5 = Utils.settingsSaveHelperSimpleFunction(self.googleTrigger1, self), f5 = Utils.settingsSaveHelperSimpleFunction(self.googleTrigger1, self),
f6 = Utils.settingsSaveHelperSimpleFunction(self.googleTrigger2, 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) { 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) { self.dropboxEnable.subscribe(function (bValue) {
RL.remote().saveAdminConfig(Utils.emptyFunction, { RL.remote().saveAdminConfig(Utils.emptyFunction, {
'DropboxEnable': bValue ? '1' : '0' 'DropboxEnable': bValue ? '1' : '0'
@ -7108,7 +7118,7 @@ AdminSocial.prototype.onBuild = function ()
}); });
self.dropboxApiKey.subscribe(function (sValue) { self.dropboxApiKey.subscribe(function (sValue) {
RL.remote().saveAdminConfig(f7, { RL.remote().saveAdminConfig(f8, {
'DropboxApiKey': Utils.trim(sValue) 'DropboxApiKey': Utils.trim(sValue)
}); });
}); });
@ -7576,6 +7586,7 @@ AbstractData.prototype.populateDataOnStart = function()
this.googleEnable(!!RL.settingsGet('AllowGoogleSocial')); this.googleEnable(!!RL.settingsGet('AllowGoogleSocial'));
this.googleClientID(RL.settingsGet('GoogleClientID')); this.googleClientID(RL.settingsGet('GoogleClientID'));
this.googleClientSecret(RL.settingsGet('GoogleClientSecret')); this.googleClientSecret(RL.settingsGet('GoogleClientSecret'));
this.googleApiKey(RL.settingsGet('GoogleApiKey'));
this.dropboxEnable(!!RL.settingsGet('AllowDropboxSocial')); this.dropboxEnable(!!RL.settingsGet('AllowDropboxSocial'));
this.dropboxApiKey(RL.settingsGet('DropboxApiKey')); this.dropboxApiKey(RL.settingsGet('DropboxApiKey'));

File diff suppressed because one or more lines are too long

View file

@ -1918,6 +1918,7 @@ Utils.initDataConstructorBySettings = function (oData)
oData.googleEnable = ko.observable(false); oData.googleEnable = ko.observable(false);
oData.googleClientID = ko.observable(''); oData.googleClientID = ko.observable('');
oData.googleClientSecret = ko.observable(''); oData.googleClientSecret = ko.observable('');
oData.googleApiKey = ko.observable('');
oData.dropboxEnable = ko.observable(false); oData.dropboxEnable = ko.observable(false);
oData.dropboxApiKey = ko.observable(''); oData.dropboxApiKey = ko.observable('');
@ -9304,7 +9305,7 @@ function PopupsComposeViewModel()
this.triggerForResize(); this.triggerForResize();
}, this); }, this);
this.dropboxEnabled = ko.observable(RL.settingsGet('DropboxApiKey') ? true : false); this.dropboxEnabled = ko.observable(!!RL.settingsGet('DropboxApiKey'));
this.dropboxCommand = Utils.createCommand(this, function () { this.dropboxCommand = Utils.createCommand(this, function () {
@ -9330,18 +9331,19 @@ function PopupsComposeViewModel()
return this.dropboxEnabled(); 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.driveCommand = Utils.createCommand(this, function () {
// this.driveOpenPopup(); this.driveOpenPopup();
return true; return true;
}, function () { }, function () {
return this.driveEnabled(); return this.driveEnabled();
}); });
// this.driveCallback = _.bind(this.driveCallback, this); this.driveCallback = _.bind(this.driveCallback, this);
this.bDisabeCloseOnEsc = true; this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = Enums.KeyState.Compose; this.sDefaultKeyScope = Enums.KeyState.Compose;
@ -9963,41 +9965,89 @@ PopupsComposeViewModel.prototype.onBuild = function ()
document.body.appendChild(oScript); document.body.appendChild(oScript);
} }
// TODO (Google Drive) if (this.driveEnabled())
// if (false) {
// { $.getScript('https://apis.google.com/js/api.js', function () {
// $.getScript('http://www.google.com/jsapi', function () { if (window.gapi)
// if (window.google) {
// { self.driveVisible(true);
// window.google.load('picker', '1', { }
// 'callback': Utils.emptyFunction });
// }); }
// }
// });
// }
}; };
//PopupsComposeViewModel.prototype.driveCallback = function (oData) PopupsComposeViewModel.prototype.driveCallback = function (oData)
//{ {
// if (oData && window.google && oData['action'] === window.google.picker.Action.PICKED) 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.driveOpenPopup = function () }
//{ };
// if (window.google)
// { PopupsComposeViewModel.prototype.driveCreatePiker = function (oOauthToken)
// var {
// oPicker = new window.google.picker.PickerBuilder() if (window.gapi && oOauthToken && oOauthToken.access_token)
// .enableFeature(window.google.picker.Feature.NAV_HIDDEN) {
// .addView(new window.google.picker.View(window.google.picker.ViewId.DOCS)) var self = this;
// .setCallback(this.driveCallback).build()
// ; window.gapi.load('picker', {'callback': function () {
//
// oPicker.setVisible(true); 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 * @param {string} sId
@ -10322,6 +10372,16 @@ PopupsComposeViewModel.prototype.addDropboxAttachment = function (oDropboxFile)
return true; return true;
}; };
/**
* @param {Object} oDriveFile
* @return {boolean}
*/
PopupsComposeViewModel.prototype.addDriveAttachment = function (oDriveFile)
{
window.console.log(oDriveFile);
return false;
};
/** /**
* @param {MessageModel} oMessage * @param {MessageModel} oMessage
* @param {string} sType * @param {string} sType
@ -16221,6 +16281,7 @@ AbstractData.prototype.populateDataOnStart = function()
this.googleEnable(!!RL.settingsGet('AllowGoogleSocial')); this.googleEnable(!!RL.settingsGet('AllowGoogleSocial'));
this.googleClientID(RL.settingsGet('GoogleClientID')); this.googleClientID(RL.settingsGet('GoogleClientID'));
this.googleClientSecret(RL.settingsGet('GoogleClientSecret')); this.googleClientSecret(RL.settingsGet('GoogleClientSecret'));
this.googleApiKey(RL.settingsGet('GoogleApiKey'));
this.dropboxEnable(!!RL.settingsGet('AllowDropboxSocial')); this.dropboxEnable(!!RL.settingsGet('AllowDropboxSocial'));
this.dropboxApiKey(RL.settingsGet('DropboxApiKey')); this.dropboxApiKey(RL.settingsGet('DropboxApiKey'));

File diff suppressed because one or more lines are too long