2012-08-13 21:09:37 +00:00
|
|
|
OC.MountConfig={
|
2012-06-12 15:36:25 +00:00
|
|
|
saveStorage:function(tr) {
|
2012-06-08 15:42:00 +00:00
|
|
|
var mountPoint = $(tr).find('.mountPoint input').val();
|
|
|
|
if (mountPoint == '') {
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-24 18:45:52 +00:00
|
|
|
var statusSpan = $(tr).find('.status span');
|
2012-06-08 15:42:00 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
2012-12-24 18:55:37 +00:00
|
|
|
if ($('#externalStorage').data('admin') === true) {
|
|
|
|
var multiselect = $(tr).find('.chzn-select').val();
|
|
|
|
if (multiselect == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-06-08 15:42:00 +00:00
|
|
|
if (addMountPoint) {
|
2012-12-24 18:45:52 +00:00
|
|
|
var status = false;
|
2012-06-28 21:54:53 +00:00
|
|
|
if ($('#externalStorage').data('admin') === true) {
|
2012-06-08 15:42:00 +00:00
|
|
|
var isPersonal = false;
|
|
|
|
var oldGroups = $(tr).find('.applicable').data('applicable-groups');
|
|
|
|
var oldUsers = $(tr).find('.applicable').data('applicable-users');
|
2012-12-28 22:38:24 +00:00
|
|
|
var groups = [];
|
|
|
|
var users = [];
|
2012-06-08 15:42:00 +00:00
|
|
|
$.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);
|
|
|
|
}
|
2012-12-28 22:38:24 +00:00
|
|
|
groups.push(applicable);
|
2012-06-08 15:42:00 +00:00
|
|
|
} else {
|
|
|
|
var mountType = 'user';
|
|
|
|
var applicable = value;
|
|
|
|
if ($.inArray(applicable, oldUsers) != -1) {
|
|
|
|
oldUsers.splice($.inArray(applicable, oldUsers), 1);
|
|
|
|
}
|
2012-12-28 22:38:24 +00:00
|
|
|
users.push(applicable);
|
2012-06-08 15:42:00 +00:00
|
|
|
}
|
2013-01-01 21:19:40 +00:00
|
|
|
$.ajax({type: 'POST',
|
|
|
|
url: OC.filePath('files_external', 'ajax', 'addMountPoint.php'),
|
|
|
|
data: {
|
|
|
|
mountPoint: mountPoint,
|
2013-02-20 00:12:14 +00:00
|
|
|
'class': backendClass,
|
2013-01-01 21:19:40 +00:00
|
|
|
classOptions: classOptions,
|
|
|
|
mountType: mountType,
|
|
|
|
applicable: applicable,
|
|
|
|
isPersonal: isPersonal
|
|
|
|
},
|
2013-02-12 23:23:37 +00:00
|
|
|
async: false,
|
2013-01-01 21:19:40 +00:00
|
|
|
success: function(result) {
|
|
|
|
statusSpan.removeClass();
|
|
|
|
if (result && result.status == 'success' && result.data.message) {
|
|
|
|
status = true;
|
|
|
|
statusSpan.addClass('success');
|
|
|
|
} else {
|
|
|
|
statusSpan.addClass('error');
|
|
|
|
}
|
2012-12-24 18:45:52 +00:00
|
|
|
}
|
|
|
|
});
|
2012-06-08 15:42:00 +00:00
|
|
|
});
|
2012-12-28 22:38:24 +00:00
|
|
|
$(tr).find('.applicable').data('applicable-groups', groups);
|
|
|
|
$(tr).find('.applicable').data('applicable-users', users);
|
2012-06-08 15:42:00 +00:00
|
|
|
var mountType = 'group';
|
|
|
|
$.each(oldGroups, function(index, applicable) {
|
2013-01-01 21:19:40 +00:00
|
|
|
$.ajax({type: 'POST',
|
|
|
|
url: OC.filePath('files_external', 'ajax', 'removeMountPoint.php'),
|
|
|
|
data: {
|
|
|
|
mountPoint: mountPoint,
|
2013-06-12 08:30:54 +00:00
|
|
|
'class': backendClass,
|
2013-01-01 21:19:40 +00:00
|
|
|
classOptions: classOptions,
|
|
|
|
mountType: mountType,
|
|
|
|
applicable: applicable,
|
|
|
|
isPersonal: isPersonal
|
|
|
|
},
|
|
|
|
async: false
|
|
|
|
});
|
2012-06-08 15:42:00 +00:00
|
|
|
});
|
|
|
|
var mountType = 'user';
|
|
|
|
$.each(oldUsers, function(index, applicable) {
|
2013-01-01 21:19:40 +00:00
|
|
|
$.ajax({type: 'POST',
|
|
|
|
url: OC.filePath('files_external', 'ajax', 'removeMountPoint.php'),
|
|
|
|
data: {
|
|
|
|
mountPoint: mountPoint,
|
2013-06-12 08:30:54 +00:00
|
|
|
'class': backendClass,
|
2013-01-01 21:19:40 +00:00
|
|
|
classOptions: classOptions,
|
|
|
|
mountType: mountType,
|
|
|
|
applicable: applicable,
|
|
|
|
isPersonal: isPersonal
|
|
|
|
},
|
|
|
|
async: false
|
|
|
|
});
|
2012-06-08 15:42:00 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
var isPersonal = true;
|
|
|
|
var mountType = 'user';
|
|
|
|
var applicable = OC.currentUser;
|
2013-01-01 21:19:40 +00:00
|
|
|
$.ajax({type: 'POST',
|
|
|
|
url: OC.filePath('files_external', 'ajax', 'addMountPoint.php'),
|
|
|
|
data: {
|
|
|
|
mountPoint: mountPoint,
|
2013-02-20 00:12:14 +00:00
|
|
|
'class': backendClass,
|
2013-01-01 21:19:40 +00:00
|
|
|
classOptions: classOptions,
|
|
|
|
mountType: mountType,
|
|
|
|
applicable: applicable,
|
|
|
|
isPersonal: isPersonal
|
|
|
|
},
|
2013-02-12 23:23:37 +00:00
|
|
|
async: false,
|
2013-01-01 21:19:40 +00:00
|
|
|
success: function(result) {
|
|
|
|
statusSpan.removeClass();
|
|
|
|
if (result && result.status == 'success' && result.data.message) {
|
|
|
|
status = true;
|
|
|
|
statusSpan.addClass('success');
|
|
|
|
} else {
|
|
|
|
statusSpan.addClass('error');
|
|
|
|
}
|
2012-12-24 18:45:52 +00:00
|
|
|
}
|
|
|
|
});
|
2012-06-08 15:42:00 +00:00
|
|
|
}
|
2013-01-01 21:19:40 +00:00
|
|
|
return status;
|
2012-06-08 15:42:00 +00:00
|
|
|
}
|
2012-06-12 15:36:25 +00:00
|
|
|
}
|
2012-09-05 20:17:33 +00:00
|
|
|
};
|
2012-06-12 15:36:25 +00:00
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
$('.chzn-select').chosen();
|
2012-08-29 06:42:49 +00:00
|
|
|
|
2013-02-20 11:06:08 +00:00
|
|
|
$('#externalStorage').on('change', '#selectBackend', function() {
|
2012-06-12 15:36:25 +00:00
|
|
|
var tr = $(this).parent().parent();
|
2012-06-29 15:09:17 +00:00
|
|
|
$('#externalStorage tbody').append($(tr).clone());
|
|
|
|
$('#externalStorage tbody tr').last().find('.mountPoint input').val('');
|
2012-06-12 15:36:25 +00:00
|
|
|
var selected = $(this).find('option:selected').text();
|
|
|
|
var backendClass = $(this).val();
|
|
|
|
$(this).parent().text(selected);
|
2012-08-13 21:09:37 +00:00
|
|
|
if ($(tr).find('.mountPoint input').val() == '') {
|
2012-12-28 20:56:48 +00:00
|
|
|
$(tr).find('.mountPoint input').val(suggestMountPoint(selected));
|
2012-08-13 21:09:37 +00:00
|
|
|
}
|
|
|
|
$(tr).addClass(backendClass);
|
2012-12-24 18:45:52 +00:00
|
|
|
$(tr).find('.status').append('<span class="waiting"></span>');
|
2012-06-12 15:36:25 +00:00
|
|
|
$(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+'" />');
|
|
|
|
}
|
|
|
|
});
|
2013-01-22 04:57:26 +00:00
|
|
|
if (parameters['custom'] && $('#externalStorage tbody tr.'+backendClass.replace(/\\/g, '\\\\')).length == 1) {
|
2012-06-12 15:36:25 +00:00
|
|
|
OC.addScript('files_external', parameters['custom']);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2012-12-28 22:38:24 +00:00
|
|
|
// 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();
|
2012-06-12 15:36:25 +00:00
|
|
|
$(tr).find('td').last().attr('class', 'remove');
|
2012-06-29 15:04:35 +00:00
|
|
|
$(tr).find('td').last().removeAttr('style');
|
2012-06-12 15:36:25 +00:00
|
|
|
$(tr).removeAttr('id');
|
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
|
2012-08-13 21:09:37 +00:00
|
|
|
function suggestMountPoint(defaultMountPoint) {
|
2012-12-28 20:56:48 +00:00
|
|
|
var pos = defaultMountPoint.indexOf('/');
|
|
|
|
if (pos !== -1) {
|
|
|
|
defaultMountPoint = defaultMountPoint.substring(0, pos);
|
|
|
|
}
|
|
|
|
defaultMountPoint = defaultMountPoint.replace(/\s+/g, '');
|
2012-08-13 21:09:37 +00:00
|
|
|
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;
|
2012-08-29 06:42:49 +00:00
|
|
|
}
|
2012-08-13 21:09:37 +00:00
|
|
|
|
2013-02-12 01:27:05 +00:00
|
|
|
$('#externalStorage').on('paste', 'td', function() {
|
2012-12-26 18:35:22 +00:00
|
|
|
var tr = $(this).parent();
|
|
|
|
setTimeout(function() {
|
|
|
|
OC.MountConfig.saveStorage(tr);
|
|
|
|
}, 20);
|
|
|
|
});
|
|
|
|
|
|
|
|
var timer;
|
|
|
|
|
2013-02-12 01:27:05 +00:00
|
|
|
$('#externalStorage').on('keyup', 'td input', function() {
|
2012-12-26 18:35:22 +00:00
|
|
|
clearTimeout(timer);
|
2012-12-28 22:38:24 +00:00
|
|
|
var tr = $(this).parent().parent();
|
2012-12-26 18:35:22 +00:00
|
|
|
if ($(this).val) {
|
|
|
|
timer = setTimeout(function() {
|
|
|
|
OC.MountConfig.saveStorage(tr);
|
|
|
|
}, 2000);
|
|
|
|
}
|
2012-05-24 15:06:03 +00:00
|
|
|
});
|
|
|
|
|
2013-02-12 01:27:05 +00:00
|
|
|
$('#externalStorage').on('change', 'td input:checkbox', function() {
|
2013-01-02 17:13:59 +00:00
|
|
|
OC.MountConfig.saveStorage($(this).parent().parent().parent());
|
|
|
|
});
|
|
|
|
|
2013-02-20 11:06:08 +00:00
|
|
|
$('#externalStorage').on('change', '.applicable .chzn-select', function() {
|
2012-12-28 22:38:24 +00:00
|
|
|
OC.MountConfig.saveStorage($(this).parent().parent());
|
|
|
|
});
|
|
|
|
|
2013-06-12 08:30:54 +00:00
|
|
|
$('#sslCertificate').on('click', 'td.remove>img', function() {
|
|
|
|
var $tr = $(this).parent().parent();
|
|
|
|
var row = this.parentNode.parentNode;
|
|
|
|
$.post(OC.filePath('files_external', 'ajax', 'removeRootCertificate.php'), {cert: row.id});
|
|
|
|
$tr.remove();
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
2013-02-20 11:06:08 +00:00
|
|
|
$('#externalStorage').on('click', 'td.remove>img', function() {
|
2012-06-08 15:42:00 +00:00
|
|
|
var tr = $(this).parent().parent();
|
|
|
|
var mountPoint = $(tr).find('.mountPoint input').val();
|
2013-06-12 08:30:54 +00:00
|
|
|
|
2012-06-28 21:54:53 +00:00
|
|
|
if ($('#externalStorage').data('admin') === true) {
|
2012-06-08 15:42:00 +00:00
|
|
|
var isPersonal = false;
|
|
|
|
var multiselect = $(tr).find('.chzn-select').val();
|
2012-12-28 22:38:24 +00:00
|
|
|
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 });
|
|
|
|
});
|
|
|
|
}
|
2012-06-08 15:42:00 +00:00
|
|
|
} else {
|
|
|
|
var mountType = 'user';
|
|
|
|
var applicable = OC.currentUser;
|
|
|
|
var isPersonal = true;
|
2012-12-28 22:38:24 +00:00
|
|
|
$.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
|
2012-06-08 15:42:00 +00:00
|
|
|
}
|
|
|
|
$(tr).remove();
|
2012-05-24 15:06:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#allowUserMounting').bind('change', function() {
|
2012-06-08 15:42:00 +00:00
|
|
|
if (this.checked) {
|
|
|
|
OC.AppConfig.setValue('files_external', 'allow_user_mounting', 'yes');
|
|
|
|
} else {
|
|
|
|
OC.AppConfig.setValue('files_external', 'allow_user_mounting', 'no');
|
|
|
|
}
|
2012-05-24 15:06:03 +00:00
|
|
|
});
|
|
|
|
|
2012-09-05 20:17:33 +00:00
|
|
|
});
|