2012-08-14 01:09:37 +04:00
|
|
|
OC.MountConfig={
|
2012-06-12 19:36:25 +04:00
|
|
|
saveStorage:function(tr) {
|
2012-06-08 19:42:00 +04:00
|
|
|
var mountPoint = $(tr).find('.mountPoint input').val();
|
|
|
|
if (mountPoint == '') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
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 (addMountPoint) {
|
2012-06-29 01:54:53 +04:00
|
|
|
if ($('#externalStorage').data('admin') === true) {
|
2012-06-08 19:42:00 +04:00
|
|
|
var isPersonal = false;
|
|
|
|
var multiselect = $(tr).find('.chzn-select').val();
|
|
|
|
var oldGroups = $(tr).find('.applicable').data('applicable-groups');
|
|
|
|
var oldUsers = $(tr).find('.applicable').data('applicable-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);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var mountType = 'user';
|
|
|
|
var applicable = value;
|
|
|
|
if ($.inArray(applicable, oldUsers) != -1) {
|
|
|
|
oldUsers.splice($.inArray(applicable, oldUsers), 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$.post(OC.filePath('files_external', 'ajax', 'addMountPoint.php'), { mountPoint: mountPoint, class: backendClass, classOptions: classOptions, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
|
|
|
|
});
|
|
|
|
var mountType = 'group';
|
|
|
|
$.each(oldGroups, function(index, applicable) {
|
|
|
|
$.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
|
|
|
|
});
|
|
|
|
var mountType = 'user';
|
|
|
|
$.each(oldUsers, function(index, applicable) {
|
|
|
|
$.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
var isPersonal = true;
|
|
|
|
var mountType = 'user';
|
|
|
|
var applicable = OC.currentUser;
|
|
|
|
$.post(OC.filePath('files_external', 'ajax', 'addMountPoint.php'), { mountPoint: mountPoint, class: backendClass, classOptions: classOptions, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
|
|
|
|
}
|
2012-08-14 01:09:37 +04:00
|
|
|
return true;
|
2012-06-08 19:42:00 +04:00
|
|
|
}
|
2012-06-12 19:36:25 +04:00
|
|
|
}
|
2012-09-06 00:17:33 +04:00
|
|
|
};
|
2012-06-12 19:36:25 +04:00
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
$('.chzn-select').chosen();
|
2012-08-29 10:42:49 +04:00
|
|
|
|
2012-06-12 19:36:25 +04:00
|
|
|
$('#selectBackend').live('change', function() {
|
|
|
|
var tr = $(this).parent().parent();
|
2012-06-29 19:09:17 +04:00
|
|
|
$('#externalStorage tbody').append($(tr).clone());
|
|
|
|
$('#externalStorage tbody tr').last().find('.mountPoint input').val('');
|
2012-06-12 19:36:25 +04:00
|
|
|
var selected = $(this).find('option:selected').text();
|
|
|
|
var backendClass = $(this).val();
|
|
|
|
$(this).parent().text(selected);
|
2012-08-14 01:09:37 +04:00
|
|
|
if ($(tr).find('.mountPoint input').val() == '') {
|
|
|
|
$(tr).find('.mountPoint input').val(suggestMountPoint(selected.replace(/\s+/g, '')));
|
|
|
|
}
|
|
|
|
$(tr).addClass(backendClass);
|
2012-06-12 19:36:25 +04: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+'" />');
|
|
|
|
}
|
|
|
|
});
|
2012-08-14 01:09:37 +04:00
|
|
|
if (parameters['custom'] && $('#externalStorage tbody tr.'+backendClass).length == 1) {
|
2012-06-12 19:36:25 +04:00
|
|
|
OC.addScript('files_external', parameters['custom']);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('.chz-select').chosen();
|
|
|
|
$(tr).find('td').last().attr('class', 'remove');
|
2012-06-29 19:04:35 +04:00
|
|
|
$(tr).find('td').last().removeAttr('style');
|
2012-06-12 19:36:25 +04:00
|
|
|
$(tr).removeAttr('id');
|
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
|
2012-08-14 01:09:37 +04:00
|
|
|
function suggestMountPoint(defaultMountPoint) {
|
|
|
|
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 10:42:49 +04:00
|
|
|
}
|
2012-08-14 01:09:37 +04:00
|
|
|
|
2012-06-12 19:36:25 +04:00
|
|
|
$('#externalStorage td').live('change', function() {
|
|
|
|
OC.MountConfig.saveStorage($(this).parent());
|
2012-05-24 19:06:03 +04:00
|
|
|
});
|
|
|
|
|
2012-06-08 19:42:00 +04:00
|
|
|
$('td.remove>img').live('click', function() {
|
|
|
|
var tr = $(this).parent().parent();
|
|
|
|
var mountPoint = $(tr).find('.mountPoint input').val();
|
2012-11-30 19:27:11 +04:00
|
|
|
if ( ! mountPoint) {
|
2012-07-04 19:16:02 +04:00
|
|
|
var row=this.parentNode.parentNode;
|
|
|
|
$.post(OC.filePath('files_external', 'ajax', 'removeRootCertificate.php'), { cert: row.id });
|
|
|
|
$(tr).remove();
|
|
|
|
return true;
|
2012-06-08 19:42:00 +04:00
|
|
|
}
|
2012-06-29 01:54:53 +04:00
|
|
|
if ($('#externalStorage').data('admin') === true) {
|
2012-06-08 19:42:00 +04:00
|
|
|
var isPersonal = false;
|
|
|
|
var multiselect = $(tr).find('.chzn-select').val();
|
|
|
|
$.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();
|
2012-05-24 19:06:03 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#allowUserMounting').bind('change', function() {
|
2012-06-08 19:42:00 +04: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 19:06:03 +04:00
|
|
|
});
|
|
|
|
|
2012-09-06 00:17:33 +04:00
|
|
|
});
|