[Pkg-owncloud-commits] [owncloud] 179/223: organize js a bit better

David Prévot taffit at moszumanska.debian.org
Sun Jun 22 01:54:23 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 2219087df6b3226e257547e5a02e120486ab4579
Author: Robin Appelman <icewind at owncloud.com>
Date:   Tue Jun 17 13:28:27 2014 +0200

    organize js a bit better
---
 apps/files_sharing/js/external.js | 38 ++++++++++++++-----
 apps/files_sharing/js/public.js   | 78 ++++++++++++++++++++-------------------
 2 files changed, 69 insertions(+), 47 deletions(-)

diff --git a/apps/files_sharing/js/external.js b/apps/files_sharing/js/external.js
index bc02ecf..5c476b2 100644
--- a/apps/files_sharing/js/external.js
+++ b/apps/files_sharing/js/external.js
@@ -1,4 +1,13 @@
-$(document).ready(function () {
+/*
+ * Copyright (c) 2014 Robin Appelman <icewind at 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);
 	}
 });
diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js
index 359087c..8063190 100644
--- a/apps/files_sharing/js/public.js
+++ b/apps/files_sharing/js/public.js
@@ -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();
-	});
 });
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list