]> source.dussan.org Git - nextcloud-server.git/commitdiff
organize js a bit better
authorRobin Appelman <icewind@owncloud.com>
Tue, 17 Jun 2014 11:28:27 +0000 (13:28 +0200)
committerRobin Appelman <icewind@owncloud.com>
Tue, 17 Jun 2014 11:47:36 +0000 (13:47 +0200)
apps/files_sharing/js/external.js
apps/files_sharing/js/public.js

index bc02ecfaf97e1928f7a9b530ab71e5e7681049da..5c476b2d43d25fa007732e9d81b005ab40d30646 100644 (file)
@@ -1,4 +1,13 @@
-$(document).ready(function () {
+/*
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+(function () {
        var getParameterByName = function (query, name) {
                name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
                var regex = new RegExp("[\\#&]" + name + "=([^&#]*)"),
@@ -8,10 +17,10 @@ $(document).ready(function () {
 
        var addExternalShare = function (remote, token, owner, name, password) {
                return $.post(OC.generateUrl('apps/files_sharing/external'), {
-                       remote  : remote,
-                       token   : token,
-                       owner   : owner,
-                       name    : name,
+                       remote: remote,
+                       token: token,
+                       owner: owner,
+                       name: name,
                        password: password
                });
        };
@@ -31,15 +40,15 @@ $(document).ready(function () {
                        }
                };
                if (!passwordProtected) {
-                       OC.dialogs.confirm('Add ' + name + ' from ' + owner + '@' + remoteClean, 'Add Share', callback, true);
+                       OC.dialogs.confirm(t('files_sharing', 'Add {name} from {owner}@{remote}', {name: name, owner: owner, remote: remoteClean})
+                               , 'Add Share', callback, true);
                } else {
-                       OC.dialogs.prompt('Add ' + name + ' from ' + owner + '@' + remoteClean, 'Add Share', callback, true, 'Password', true);
+                       OC.dialogs.prompt(t('files_sharing', 'Add {name} from {owner}@{remote}', {name: name, owner: owner, remote: remoteClean})
+                               , 'Add Share', callback, true, 'Password', true);
                }
        };
 
-       if (OCA.Files) {// only run in the files app
-               var hash = location.hash;
-               location.hash = '';
+       OCA.Sharing.showAddExternalDialog = function (hash) {
                var remote = getParameterByName(hash, 'remote');
                var owner = getParameterByName(hash, 'owner');
                var name = getParameterByName(hash, 'name');
@@ -49,5 +58,14 @@ $(document).ready(function () {
                if (remote && token && owner && name) {
                        showAddExternalDialog(remote, token, owner, name, passwordProtected);
                }
+       };
+})();
+
+$(document).ready(function () {
+       // FIXME: HACK: do not init when running unit tests, need a better way
+       if (!window.TESTING && OCA.Files) {// only run in the files app
+               var hash = location.hash;
+               location.hash = '';
+               OCA.Sharing.showAddExternalDialog(hash);
        }
 });
index 359087c0f94cb2ed94d4f631ec3eb429fd1db0a6..80631908d24df715e6b145162d3c8c139e7f1fc9 100644 (file)
@@ -148,6 +148,24 @@ OCA.Sharing.PublicApp = {
                        $(this).select();
                });
 
+               $('.save-form').submit(function (event) {
+                       event.preventDefault();
+
+                       var remote = $(this).find('input[type="text"]').val();
+                       var token = $('#sharingToken').val();
+                       var owner = $('#save').data('owner');
+                       var name = $('#save').data('name');
+                       var isProtected = $('#save').data('protected') ? 1 : 0;
+                       OCA.Sharing.PublicApp._saveToOwnCloud(remote, token, owner, name, isProtected);
+               });
+
+               $('#save > button').click(function () {
+                       $(this).hide();
+                       $('.header-right').addClass('active');
+                       $('.save-form').css('display', 'inline');
+                       $('#remote_address').focus();
+               });
+
                // legacy
                window.FileList = this.fileList;
        },
@@ -163,6 +181,29 @@ OCA.Sharing.PublicApp = {
 
        _onUrlChanged: function (params) {
                this.fileList.changeDirectory(params.path || params.dir, false, true);
+       },
+
+       _saveToOwnCloud: function(remote, token, owner, name, isProtected) {
+               var location = window.location.protocol + '//' + window.location.host + OC.webroot;
+
+               var url = remote + '/index.php/apps/files#' + 'remote=' + encodeURIComponent(location) // our location is the remote for the other server
+                       + "&token=" + encodeURIComponent(token) + "&owner=" + encodeURIComponent(owner) + "&name=" + encodeURIComponent(name) + "&protected=" + isProtected;
+
+
+               if (remote.indexOf('://') > 0) {
+                       OC.redirect(url);
+               } else {
+                       // if no protocol is specified, we automatically detect it by testing https and http
+                       // this check needs to happen on the server due to the Content Security Policy directive
+                       $.get(OC.generateUrl('apps/files_sharing/testremote'), {remote: remote}).then(function (protocol) {
+                               if (protocol !== 'http' && protocol !== 'https') {
+                                       OC.dialogs.alert(t('files_sharing', 'No ownCloud installation found at {remote}', {remote: remote}),
+                                               t('files_sharing', 'Invalid ownCloud url'));
+                               } else {
+                                       OC.redirect(protocol + '://' + url);
+                               }
+                       });
+               }
        }
 };
 
@@ -186,42 +227,5 @@ $(document).ready(function () {
                        });
                };
        }
-
-       $('.save-form').submit(function (event) {
-               event.preventDefault();
-
-               var remote = $(this).find('input[type="text"]').val();
-               var token = $('#sharingToken').val();
-               var location = window.location.protocol + '//' + window.location.host + OC.webroot;
-               var owner = $('#save').data('owner');
-               var name = $('#save').data('name');
-               var isProtected = $('#save').data('protected') ? 1 : 0;
-
-               var url = remote + '/index.php/apps/files#' + 'remote=' + encodeURIComponent(location) // our location is the remote for the other server
-                       + "&token=" + encodeURIComponent(token) + "&owner=" + encodeURIComponent(owner) + "&name=" + encodeURIComponent(name) + "&protected=" + isProtected;
-
-
-               if (remote.indexOf('://') > 0) {
-                       window.location = url;
-               } else {
-                       // if no protocol is specified, we automatically detect it by testing https and http
-                       // this check needs to happen on the server due to the Content Security Policy directive
-                       $.get(OC.generateUrl('apps/files_sharing/testremote'), {remote: remote}).then(function (protocol) {
-                               if (protocol !== 'http' && protocol !== 'https') {
-                                       OC.dialogs.alert(t('files_sharing', 'No ownCloud installation found at {remote}', {remote: remote}),
-                                               t('files_sharing', 'Invalid ownCloud url'));
-                               } else {
-                                       window.location = protocol + '://' + url;
-                               }
-                       });
-               }
-       });
-
-       $('#save > button').click(function () {
-               $(this).hide();
-               $('.header-right').addClass('active');
-               $('.save-form').css('display', 'inline');
-               $('#remote_address').focus();
-       });
 });