2014-06-17 11:28:27 +00:00
|
|
|
/*
|
|
|
|
* 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 () {
|
2014-05-09 15:06:08 +00:00
|
|
|
var addExternalShare = function (remote, token, owner, name, password) {
|
|
|
|
return $.post(OC.generateUrl('apps/files_sharing/external'), {
|
2014-06-17 11:28:27 +00:00
|
|
|
remote: remote,
|
|
|
|
token: token,
|
|
|
|
owner: owner,
|
|
|
|
name: name,
|
2014-05-09 15:06:08 +00:00
|
|
|
password: password
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-06-25 10:24:46 +00:00
|
|
|
/**
|
|
|
|
* Shows "add external share" dialog.
|
|
|
|
*
|
|
|
|
* @param {String} remote remote server URL
|
|
|
|
* @param {String} owner owner name
|
|
|
|
* @param {String} name name of the shared folder
|
|
|
|
* @param {String} token authentication token
|
|
|
|
* @param {bool} passwordProtected true if the share is password protected
|
|
|
|
*/
|
|
|
|
OCA.Sharing.showAddExternalDialog = function (remote, token, owner, name, passwordProtected) {
|
2014-05-09 15:06:08 +00:00
|
|
|
var remoteClean = (remote.substr(0, 8) === 'https://') ? remote.substr(8) : remote.substr(7);
|
|
|
|
var callback = function (add, password) {
|
|
|
|
password = password || '';
|
|
|
|
if (add) {
|
|
|
|
addExternalShare(remote, token, owner, name, password).then(function (result) {
|
2014-06-12 17:49:52 +00:00
|
|
|
if (result.status === 'error') {
|
|
|
|
OC.Notification.show(result.data.message);
|
2014-05-09 15:06:08 +00:00
|
|
|
} else {
|
2014-06-12 17:49:52 +00:00
|
|
|
FileList.reload();
|
2014-05-09 15:06:08 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (!passwordProtected) {
|
2014-07-07 13:57:26 +00:00
|
|
|
OC.dialogs.confirm(
|
|
|
|
t(
|
|
|
|
'files_sharing',
|
|
|
|
'Do you want to add the remote share {name} from {owner}@{remote}?',
|
|
|
|
{name: name, owner: owner, remote: remoteClean}
|
|
|
|
),
|
|
|
|
t('files_sharing','Remote share'),
|
|
|
|
callback,
|
|
|
|
true
|
|
|
|
).then(this._adjustDialog);
|
2014-05-09 15:06:08 +00:00
|
|
|
} else {
|
2014-07-07 13:57:26 +00:00
|
|
|
OC.dialogs.prompt(
|
|
|
|
t(
|
|
|
|
'files_sharing',
|
|
|
|
'Do you want to add the remote share {name} from {owner}@{remote}?',
|
|
|
|
{name: name, owner: owner, remote: remoteClean}
|
|
|
|
),
|
|
|
|
t('files_sharing','Remote share'),
|
|
|
|
callback,
|
|
|
|
true,
|
|
|
|
t('files_sharing','Remote share password'),
|
|
|
|
true
|
|
|
|
).then(this._adjustDialog);
|
2014-05-09 15:06:08 +00:00
|
|
|
}
|
|
|
|
};
|
2014-07-07 13:57:26 +00:00
|
|
|
|
|
|
|
OCA.Sharing._adjustDialog = function() {
|
|
|
|
var $dialog = $('.oc-dialog:visible');
|
|
|
|
var $buttons = $dialog.find('button');
|
|
|
|
// hack the buttons
|
|
|
|
$dialog.find('.ui-icon').remove();
|
|
|
|
$buttons.eq(0).text(t('core', 'Cancel'));
|
|
|
|
$buttons.eq(1).text(t('core', 'Add remote share'));
|
|
|
|
};
|
2014-06-17 11:28:27 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
$(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
|
2014-06-25 10:24:46 +00:00
|
|
|
var params = OC.Util.History.parseUrlQuery();
|
|
|
|
if (params.remote && params.token && params.owner && params.name) {
|
|
|
|
// clear hash, it is unlikely that it contain any extra parameters
|
|
|
|
location.hash = '';
|
2014-07-01 15:34:01 +00:00
|
|
|
params.passwordProtected = parseInt(params.protected, 10) === 1;
|
2014-06-25 10:24:46 +00:00
|
|
|
OCA.Sharing.showAddExternalDialog(
|
|
|
|
params.remote,
|
|
|
|
params.token,
|
|
|
|
params.owner,
|
|
|
|
params.name,
|
|
|
|
params.passwordProtected
|
|
|
|
);
|
|
|
|
}
|
2014-05-09 15:06:08 +00:00
|
|
|
}
|
|
|
|
});
|