organize js a bit better
This commit is contained in:
parent
f2ebac5c76
commit
2219087df6
|
@ -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) {
|
var getParameterByName = function (query, name) {
|
||||||
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
||||||
var regex = new RegExp("[\\#&]" + name + "=([^&#]*)"),
|
var regex = new RegExp("[\\#&]" + name + "=([^&#]*)"),
|
||||||
|
@ -31,15 +40,15 @@ $(document).ready(function () {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (!passwordProtected) {
|
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 {
|
} 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
|
OCA.Sharing.showAddExternalDialog = function (hash) {
|
||||||
var hash = location.hash;
|
|
||||||
location.hash = '';
|
|
||||||
var remote = getParameterByName(hash, 'remote');
|
var remote = getParameterByName(hash, 'remote');
|
||||||
var owner = getParameterByName(hash, 'owner');
|
var owner = getParameterByName(hash, 'owner');
|
||||||
var name = getParameterByName(hash, 'name');
|
var name = getParameterByName(hash, 'name');
|
||||||
|
@ -49,5 +58,14 @@ $(document).ready(function () {
|
||||||
if (remote && token && owner && name) {
|
if (remote && token && owner && name) {
|
||||||
showAddExternalDialog(remote, token, owner, name, passwordProtected);
|
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -148,6 +148,24 @@ OCA.Sharing.PublicApp = {
|
||||||
$(this).select();
|
$(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
|
// legacy
|
||||||
window.FileList = this.fileList;
|
window.FileList = this.fileList;
|
||||||
},
|
},
|
||||||
|
@ -163,6 +181,29 @@ OCA.Sharing.PublicApp = {
|
||||||
|
|
||||||
_onUrlChanged: function (params) {
|
_onUrlChanged: function (params) {
|
||||||
this.fileList.changeDirectory(params.path || params.dir, false, true);
|
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();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue