diff options
author | Michael Gapczynski <mtgap@owncloud.com> | 2013-05-16 20:09:32 -0400 |
---|---|---|
committer | Michael Gapczynski <mtgap@owncloud.com> | 2013-05-16 20:09:32 -0400 |
commit | d8c660c6d524ad1226abeb00e8d4de4039eae1e1 (patch) | |
tree | 8842c05edbb524d43f665a5a21a206fda81b28ea /apps/files_external/js | |
parent | 1ec92b6377ee784c6e067a8d7e7c10ebf89367e4 (diff) | |
download | nextcloud-server-d8c660c6d524ad1226abeb00e8d4de4039eae1e1.tar.gz nextcloud-server-d8c660c6d524ad1226abeb00e8d4de4039eae1e1.zip |
Switch to using Google Drive SDK, closes #2047
Diffstat (limited to 'apps/files_external/js')
-rw-r--r-- | apps/files_external/js/google.js | 163 |
1 files changed, 97 insertions, 66 deletions
diff --git a/apps/files_external/js/google.js b/apps/files_external/js/google.js index 7be1b338e90..7e111a95d98 100644 --- a/apps/files_external/js/google.js +++ b/apps/files_external/js/google.js @@ -1,69 +1,89 @@ $(document).ready(function() { - $('#externalStorage tbody tr.\\\\OC\\\\Files\\\\Storage\\\\Google').each(function(index, tr) { - setupGoogleRow(tr); - }); - - $('#externalStorage').on('change', '#selectBackend', function() { - if ($(this).val() == '\\OC\\Files\\Storage\\Google') { - setupGoogleRow($('#externalStorage tbody>tr:last').prev('tr')); - } - }); - - function setupGoogleRow(tr) { - var configured = $(tr).find('[data-parameter="configured"]'); + $('#externalStorage tbody tr.\\\\OC\\\\Files\\\\Storage\\\\Google').each(function() { + var configured = $(this).find('[data-parameter="configured"]'); if ($(configured).val() == 'true') { - $(tr).find('.configuration').append('<span id="access" style="padding-left:0.5em;">'+t('files_external', 'Access granted')+'</span>'); + $(this).find('.configuration input').attr('disabled', 'disabled'); + $(this).find('.configuration').append($('<span/>').attr('id', 'access') + .text(t('files_external', 'Access granted'))); } else { - var token = $(tr).find('[data-parameter="token"]'); - var token_secret = $(tr).find('[data-parameter="token_secret"]'); - var params = {}; - window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) { - params[key] = value; - }); - if (params['oauth_token'] !== undefined && params['oauth_verifier'] !== undefined && decodeURIComponent(params['oauth_token']) == $(token).val()) { - var statusSpan = $(tr).find('.status span'); - statusSpan.removeClass(); - statusSpan.addClass('waiting'); - $.post(OC.filePath('files_external', 'ajax', 'google.php'), { step: 2, oauth_verifier: params['oauth_verifier'], request_token: $(token).val(), request_token_secret: $(token_secret).val() }, function(result) { - if (result && result.status == 'success') { - $(token).val(result.access_token); - $(token_secret).val(result.access_token_secret); - $(configured).val('true'); - OC.MountConfig.saveStorage(tr); - $(tr).find('.configuration').append('<span id="access" style="padding-left:0.5em;">'+t('files_external', 'Access granted')+'</span>'); - } else { - OC.dialogs.alert(result.data.message, t('files_external', 'Error configuring Google Drive storage')); - onGoogleInputsChange(tr); - } + var client_id = $(this).find('.configuration [data-parameter="client_id"]').val(); + var client_secret = $(this).find('.configuration [data-parameter="client_secret"]') + .val(); + if (client_id != '' && client_secret != '') { + var params = {}; + window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) { + params[key] = value; }); + if (params['code'] !== undefined) { + var tr = $(this); + var token = $(this).find('.configuration [data-parameter="token"]'); + var statusSpan = $(tr).find('.status span'); + statusSpan.removeClass(); + statusSpan.addClass('waiting'); + $.post(OC.filePath('files_external', 'ajax', 'google.php'), + { + step: 2, + client_id: client_id, + client_secret: client_secret, + redirect: location.protocol + '//' + location.host + location.pathname, + code: params['code'], + }, function(result) { + if (result && result.status == 'success') { + $(token).val(result.data.token); + $(configured).val('true'); + OC.MountConfig.saveStorage(tr); + $(tr).find('.configuration input').attr('disabled', 'disabled'); + $(tr).find('.configuration').append($('<span/>') + .attr('id', 'access') + .text(t('files_external', 'Access granted'))); + } else { + OC.dialogs.alert(result.data.message, + t('files_external', 'Error configuring Google Drive storage') + ); + } + } + ); + } } else { - onGoogleInputsChange(tr); + onGoogleInputsChange($(this)); } } - } - - $('#externalStorage').on('paste', 'tbody tr.\\\\OC\\\\Files\\\\Storage\\\\Google td', function() { - var tr = $(this).parent(); - setTimeout(function() { - onGoogleInputsChange(tr); - }, 20); }); - $('#externalStorage').on('keyup', 'tbody tr.\\\\OC\\\\Files\\\\Storage\\\\Google td', function() { - onGoogleInputsChange($(this).parent()); - }); + $('#externalStorage').on('paste', 'tbody tr.\\\\OC\\\\Files\\\\Storage\\\\Google td', + function() { + var tr = $(this).parent(); + setTimeout(function() { + onGoogleInputsChange(tr); + }, 20); + } + ); - $('#externalStorage').on('change', 'tbody tr.\\\\OC\\\\Files\\\\Storage\\\\Google .chzn-select', function() { - onGoogleInputsChange($(this).parent().parent()); - }); + $('#externalStorage').on('keyup', 'tbody tr.\\\\OC\\\\Files\\\\Storage\\\\Google td', + function() { + onGoogleInputsChange($(this).parent()); + } + ); + + $('#externalStorage').on('change', 'tbody tr.\\\\OC\\\\Files\\\\Storage\\\\Google .chzn-select' + , function() { + onGoogleInputsChange($(this).parent().parent()); + } + ); function onGoogleInputsChange(tr) { if ($(tr).find('[data-parameter="configured"]').val() != 'true') { var config = $(tr).find('.configuration'); - if ($(tr).find('.mountPoint input').val() != '' && ($(tr).find('.chzn-select').length == 0 || $(tr).find('.chzn-select').val() != null)) { + if ($(tr).find('.mountPoint input').val() != '' + && $(config).find('[data-parameter="client_id"]').val() != '' + && $(config).find('[data-parameter="client_secret"]').val() != '' + && ($(tr).find('.chzn-select').length == 0 + || $(tr).find('.chzn-select').val() != null)) + { if ($(tr).find('.google').length == 0) { - $(config).append('<a class="button google">'+t('files_external', 'Grant access')+'</a>'); + $(config).append($('<a/>').addClass('button google') + .text(t('files_external', 'Grant access'))); } else { $(tr).find('.google').show(); } @@ -77,22 +97,33 @@ $(document).ready(function() { event.preventDefault(); var tr = $(this).parent().parent(); var configured = $(this).parent().find('[data-parameter="configured"]'); - var token = $(this).parent().find('[data-parameter="token"]'); - var token_secret = $(this).parent().find('[data-parameter="token_secret"]'); + var client_id = $(this).parent().find('[data-parameter="client_id"]').val(); + var client_secret = $(this).parent().find('[data-parameter="client_secret"]').val(); var statusSpan = $(tr).find('.status span'); - $.post(OC.filePath('files_external', 'ajax', 'google.php'), { step: 1, callback: location.protocol + '//' + location.host + location.pathname }, function(result) { - if (result && result.status == 'success') { - $(configured).val('false'); - $(token).val(result.data.request_token); - $(token_secret).val(result.data.request_token_secret); - OC.MountConfig.saveStorage(tr); - statusSpan.removeClass(); - statusSpan.addClass('waiting'); - window.location = result.data.url; - } else { - OC.dialogs.alert(result.data.message, t('files_external', 'Error configuring Google Drive storage')); - } - }); + if (client_id != '' && client_secret != '') { + var token = $(this).parent().find('[data-parameter="token"]'); + $.post(OC.filePath('files_external', 'ajax', 'google.php'), + { + step: 1, + client_id: client_id, + client_secret: client_secret, + redirect: location.protocol + '//' + location.host + location.pathname, + }, function(result) { + if (result && result.status == 'success') { + $(configured).val('false'); + $(token).val('false'); + OC.MountConfig.saveStorage(tr); + statusSpan.removeClass(); + statusSpan.addClass('waiting'); + window.location = result.data.url; + } else { + OC.dialogs.alert(result.data.message, + t('files_external', 'Error configuring Google Drive storage') + ); + } + } + ); + } }); -}); +});
\ No newline at end of file |