123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- OC.MountConfig={
- saveStorage:function(tr) {
- var mountPoint = $(tr).find('.mountPoint input').val();
- if (mountPoint == '') {
- return false;
- }
- var statusSpan = $(tr).find('.status span');
- var backendClass = $(tr).find('.backend').data('class');
- var configuration = $(tr).find('.configuration input');
- var addMountPoint = true;
- if (configuration.length < 1) {
- return false;
- }
- var classOptions = {};
- $.each(configuration, function(index, input) {
- if ($(input).val() == '' && !$(input).hasClass('optional')) {
- addMountPoint = false;
- return false;
- }
- if ($(input).is(':checkbox')) {
- if ($(input).is(':checked')) {
- classOptions[$(input).data('parameter')] = true;
- } else {
- classOptions[$(input).data('parameter')] = false;
- }
- } else {
- classOptions[$(input).data('parameter')] = $(input).val();
- }
- });
- if ($('#externalStorage').data('admin') === true) {
- var multiselect = $(tr).find('.chzn-select').val();
- if (multiselect == null) {
- return false;
- }
- }
- if (addMountPoint) {
- var status = false;
- if ($('#externalStorage').data('admin') === true) {
- var isPersonal = false;
- var oldGroups = $(tr).find('.applicable').data('applicable-groups');
- var oldUsers = $(tr).find('.applicable').data('applicable-users');
- var groups = [];
- var users = [];
- $.each(multiselect, function(index, value) {
- var pos = value.indexOf('(group)');
- if (pos != -1) {
- var mountType = 'group';
- var applicable = value.substr(0, pos);
- if ($.inArray(applicable, oldGroups) != -1) {
- oldGroups.splice($.inArray(applicable, oldGroups), 1);
- }
- groups.push(applicable);
- } else {
- var mountType = 'user';
- var applicable = value;
- if ($.inArray(applicable, oldUsers) != -1) {
- oldUsers.splice($.inArray(applicable, oldUsers), 1);
- }
- users.push(applicable);
- }
- $.ajax({type: 'POST',
- url: OC.filePath('files_external', 'ajax', 'addMountPoint.php'),
- data: {
- mountPoint: mountPoint,
- 'class': backendClass,
- classOptions: classOptions,
- mountType: mountType,
- applicable: applicable,
- isPersonal: isPersonal
- },
- async: false,
- success: function(result) {
- statusSpan.removeClass();
- if (result && result.status == 'success' && result.data.message) {
- status = true;
- statusSpan.addClass('success');
- } else {
- statusSpan.addClass('error');
- }
- }
- });
- });
- $(tr).find('.applicable').data('applicable-groups', groups);
- $(tr).find('.applicable').data('applicable-users', users);
- var mountType = 'group';
- $.each(oldGroups, function(index, applicable) {
- $.ajax({type: 'POST',
- url: OC.filePath('files_external', 'ajax', 'removeMountPoint.php'),
- data: {
- mountPoint: mountPoint,
- class: backendClass,
- classOptions: classOptions,
- mountType: mountType,
- applicable: applicable,
- isPersonal: isPersonal
- },
- async: false
- });
- });
- var mountType = 'user';
- $.each(oldUsers, function(index, applicable) {
- $.ajax({type: 'POST',
- url: OC.filePath('files_external', 'ajax', 'removeMountPoint.php'),
- data: {
- mountPoint: mountPoint,
- class: backendClass,
- classOptions: classOptions,
- mountType: mountType,
- applicable: applicable,
- isPersonal: isPersonal
- },
- async: false
- });
- });
- } else {
- var isPersonal = true;
- var mountType = 'user';
- var applicable = OC.currentUser;
- $.ajax({type: 'POST',
- url: OC.filePath('files_external', 'ajax', 'addMountPoint.php'),
- data: {
- mountPoint: mountPoint,
- 'class': backendClass,
- classOptions: classOptions,
- mountType: mountType,
- applicable: applicable,
- isPersonal: isPersonal
- },
- async: false,
- success: function(result) {
- statusSpan.removeClass();
- if (result && result.status == 'success' && result.data.message) {
- status = true;
- statusSpan.addClass('success');
- } else {
- statusSpan.addClass('error');
- }
- }
- });
- }
- return status;
- }
- }
- };
- $(document).ready(function() {
- $('.chzn-select').chosen();
- $('#externalStorage').on('change', '#selectBackend', function() {
- var tr = $(this).parent().parent();
- $('#externalStorage tbody').append($(tr).clone());
- $('#externalStorage tbody tr').last().find('.mountPoint input').val('');
- var selected = $(this).find('option:selected').text();
- var backendClass = $(this).val();
- $(this).parent().text(selected);
- if ($(tr).find('.mountPoint input').val() == '') {
- $(tr).find('.mountPoint input').val(suggestMountPoint(selected));
- }
- $(tr).addClass(backendClass);
- $(tr).find('.status').append('<span class="waiting"></span>');
- $(tr).find('.backend').data('class', backendClass);
- var configurations = $(this).data('configurations');
- var td = $(tr).find('td.configuration');
- $.each(configurations, function(backend, parameters) {
- if (backend == backendClass) {
- $.each(parameters['configuration'], function(parameter, placeholder) {
- if (placeholder.indexOf('*') != -1) {
- td.append('<input type="password" data-parameter="'+parameter+'" placeholder="'+placeholder.substring(1)+'" />');
- } else if (placeholder.indexOf('!') != -1) {
- td.append('<label><input type="checkbox" data-parameter="'+parameter+'" />'+placeholder.substring(1)+'</label>');
- } else if (placeholder.indexOf('&') != -1) {
- td.append('<input type="text" class="optional" data-parameter="'+parameter+'" placeholder="'+placeholder.substring(1)+'" />');
- } else if (placeholder.indexOf('#') != -1) {
- td.append('<input type="hidden" data-parameter="'+parameter+'" />');
- } else {
- td.append('<input type="text" data-parameter="'+parameter+'" placeholder="'+placeholder+'" />');
- }
- });
- if (parameters['custom'] && $('#externalStorage tbody tr.'+backendClass.replace(/\\/g, '\\\\')).length == 1) {
- OC.addScript('files_external', parameters['custom']);
- }
- return false;
- }
- });
- // Reset chosen
- var chosen = $(tr).find('.applicable select');
- chosen.parent().find('div').remove();
- chosen.removeAttr('id').removeClass('chzn-done').css({display:'inline-block'});
- chosen.chosen();
- $(tr).find('td').last().attr('class', 'remove');
- $(tr).find('td').last().removeAttr('style');
- $(tr).removeAttr('id');
- $(this).remove();
- });
- function suggestMountPoint(defaultMountPoint) {
- var pos = defaultMountPoint.indexOf('/');
- if (pos !== -1) {
- defaultMountPoint = defaultMountPoint.substring(0, pos);
- }
- defaultMountPoint = defaultMountPoint.replace(/\s+/g, '');
- var i = 1;
- var append = '';
- var match = true;
- while (match && i < 20) {
- match = false;
- $('#externalStorage tbody td.mountPoint input').each(function(index, mountPoint) {
- if ($(mountPoint).val() == defaultMountPoint+append) {
- match = true;
- return false;
- }
- });
- if (match) {
- append = i;
- i++;
- } else {
- break;
- }
- }
- return defaultMountPoint+append;
- }
- $('#externalStorage').on('paste', 'td', function() {
- var tr = $(this).parent();
- setTimeout(function() {
- OC.MountConfig.saveStorage(tr);
- }, 20);
- });
- var timer;
- $('#externalStorage').on('keyup', 'td input', function() {
- clearTimeout(timer);
- var tr = $(this).parent().parent();
- if ($(this).val) {
- timer = setTimeout(function() {
- OC.MountConfig.saveStorage(tr);
- }, 2000);
- }
- });
- $('#externalStorage').on('change', 'td input:checkbox', function() {
- OC.MountConfig.saveStorage($(this).parent().parent().parent());
- });
- $('#externalStorage').on('change', '.applicable .chzn-select', function() {
- OC.MountConfig.saveStorage($(this).parent().parent());
- });
- $('#externalStorage').on('click', 'td.remove>img', function() {
- var tr = $(this).parent().parent();
- var mountPoint = $(tr).find('.mountPoint input').val();
- if ( ! mountPoint) {
- var row=this.parentNode.parentNode;
- $.post(OC.filePath('files_external', 'ajax', 'removeRootCertificate.php'), { cert: row.id });
- $(tr).remove();
- return true;
- }
- if ($('#externalStorage').data('admin') === true) {
- var isPersonal = false;
- var multiselect = $(tr).find('.chzn-select').val();
- if (multiselect != null) {
- $.each(multiselect, function(index, value) {
- var pos = value.indexOf('(group)');
- if (pos != -1) {
- var mountType = 'group';
- var applicable = value.substr(0, pos);
- } else {
- var mountType = 'user';
- var applicable = value;
- }
- $.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
- });
- }
- } else {
- var mountType = 'user';
- var applicable = OC.currentUser;
- var isPersonal = true;
- $.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
- }
- $(tr).remove();
- });
- $('#allowUserMounting').bind('change', function() {
- if (this.checked) {
- OC.AppConfig.setValue('files_external', 'allow_user_mounting', 'yes');
- } else {
- OC.AppConfig.setValue('files_external', 'allow_user_mounting', 'no');
- }
- });
- });
|