diff options
author | Michael Gapczynski <GapczynskiM@gmail.com> | 2012-06-13 13:54:32 -0400 |
---|---|---|
committer | Michael Gapczynski <GapczynskiM@gmail.com> | 2012-06-13 13:54:50 -0400 |
commit | bd01e9346941fa85b4bb96a42cecdbc50e51c368 (patch) | |
tree | c72a41ad073894ddb4f4811e197d9cd7725bc777 /apps/files_external/js/google.js | |
parent | 613a122437a5fff0eb8c502719f8203ea0a61e81 (diff) | |
download | nextcloud-server-bd01e9346941fa85b4bb96a42cecdbc50e51c368.tar.gz nextcloud-server-bd01e9346941fa85b4bb96a42cecdbc50e51c368.zip |
Add support for mounting Google Drive in external storage UI
Diffstat (limited to 'apps/files_external/js/google.js')
-rw-r--r-- | apps/files_external/js/google.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/apps/files_external/js/google.js b/apps/files_external/js/google.js new file mode 100644 index 00000000000..0d65cfda011 --- /dev/null +++ b/apps/files_external/js/google.js @@ -0,0 +1,48 @@ +$(document).ready(function() { + + $('#externalStorage tbody tr').each(function() { + if ($(this).find('.backend').data('class') == 'OC_Filestorage_Google') { + var token = $(this).find('[data-parameter="token"]'); + var token_secret = $(this).find('[data-parameter="token_secret"]'); + if ($(token).val() == '' && $(token).val() == '') { + $(this).find('.configuration').append('<a class="button google">Grant access</a>'); + } else { + var params = {}; + window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) { + params[key] = value; + }); + if (params['oauth_token'].length > 1 && decodeURIComponent(params['oauth_token']) == $(token).val() && params['oauth_verifier'].length > 1) { + var tr = $(this); + $.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); + OC.MountConfig.saveStorage(tr); + } else { + OC.dialogs.alert(result.data.message, 'Error configuring Google Drive storage'); + } + }); + } + } + return false; + } + }); + + $('.google').live('click', function(event) { + event.preventDefault(); + var tr = $(this).parent().parent(); + var token = $(this).parent().find('[data-parameter="token"]'); + var token_secret = $(this).parent().find('[data-parameter="token_secret"]'); + $.post(OC.filePath('files_external', 'ajax', 'google.php'), { step: 1, callback: window.location.href }, function(result) { + if (result && result.status == 'success') { + $(token).val(result.data.request_token); + $(token_secret).val(result.data.request_token_secret); + OC.MountConfig.saveStorage(tr); + window.location = result.data.url; + } else { + OC.dialogs.alert(result.data.message, 'Error configuring Google Drive storage'); + } + }); + }); + +}); |