Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/gallery.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorOlivier Paroz <github@oparoz.com>2015-05-20 20:28:02 +0300
committerOlivier Paroz <github@oparoz.com>2015-06-22 07:21:21 +0300
commit2f83db3d5fb1c20fbbda93ef68661597bd0ee837 (patch)
treea5f52862ad0a875b79a0fcd8ad94e8fede838c1e /js
parent5f53377c3e9f098e086ee18a699aa1d20294ef71 (diff)
Adds the form which allows a user to add the shared files to his ownCloud
Solution for #144
Diffstat (limited to 'js')
-rw-r--r--js/gallery.js64
-rw-r--r--js/galleryview.js2
2 files changed, 66 insertions, 0 deletions
diff --git a/js/gallery.js b/js/gallery.js
index cfb11063..fb4079ed 100644
--- a/js/gallery.js
+++ b/js/gallery.js
@@ -241,6 +241,70 @@ Gallery.showInfo = function (event) {
};
/**
+ * Lets the user add the shared files to his ownCloud
+ *
+ * @param event
+ */
+Gallery.showSaveForm = function (event) {
+ $(this).hide();
+ $('.save-form').css('display', 'inline');
+ $('#remote_address').focus();
+};
+
+/**
+ * Sends the shared files to the viewer's ownCloud
+ *
+ * @param event
+ */
+Gallery.saveForm = function (event) {
+ event.preventDefault();
+
+ var saveElement = $('#save');
+ var remote = $(this).find('input[type="text"]').val();
+ var owner = saveElement.data('owner');
+ var name = saveElement.data('name');
+ var isProtected = saveElement.data('protected');
+ Gallery.saveToOwnCloud(remote, Gallery.token, owner, name, isProtected);
+};
+
+/**
+ * Saves the folder to a remote ownCloud installation
+ *
+ * Our location is the remote for the other server
+ *
+ * @param {string} remote
+ * @param {string}token
+ * @param {string}owner
+ * @param {string}name
+ * @param {bool} isProtected
+ */
+Gallery.saveToOwnCloud = function (remote, token, owner, name, isProtected) {
+ var location = window.location.protocol + '//' + window.location.host + OC.webroot;
+ var isProtectedInt = (isProtected) ? 1 : 0;
+ var url = remote + '/index.php/apps/files#' + 'remote=' + encodeURIComponent(location)
+ + "&token=" + encodeURIComponent(token) + "&owner=" + encodeURIComponent(owner) + "&name=" +
+ encodeURIComponent(name) + "&protected=" + isProtectedInt;
+
+ 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 (7 or higher) found at {remote}',
+ {remote: remote}),
+ t('files_sharing', 'Invalid ownCloud url'));
+ } else {
+ OC.redirect(protocol + '://' + url);
+ }
+ });
+ }
+};
+
+/**
* Hide the search button while we wait for core to fix the templates
*/
Gallery.hideSearch = function () {
diff --git a/js/galleryview.js b/js/galleryview.js
index 14ce832b..ca6f9d42 100644
--- a/js/galleryview.js
+++ b/js/galleryview.js
@@ -42,6 +42,8 @@
$('#album-info-button').click(Gallery.showInfo);
$('#sort-name-button').click(Gallery.sorter);
$('#sort-date-button').click(Gallery.sorter);
+ $('#save #save-button').click(Gallery.showSaveForm);
+ $('.save-form').submit(Gallery.saveForm);
}
this.viewAlbum(albumPath);
}