Fix problems with chosen multiselect

This commit is contained in:
Michael Gapczynski 2012-12-28 17:38:24 -05:00
parent 595e72ade8
commit 442a045ef6
1 changed files with 31 additions and 15 deletions

View File

@ -39,6 +39,8 @@ OC.MountConfig={
var isPersonal = false; var isPersonal = false;
var oldGroups = $(tr).find('.applicable').data('applicable-groups'); var oldGroups = $(tr).find('.applicable').data('applicable-groups');
var oldUsers = $(tr).find('.applicable').data('applicable-users'); var oldUsers = $(tr).find('.applicable').data('applicable-users');
var groups = [];
var users = [];
$.each(multiselect, function(index, value) { $.each(multiselect, function(index, value) {
var pos = value.indexOf('(group)'); var pos = value.indexOf('(group)');
if (pos != -1) { if (pos != -1) {
@ -47,12 +49,14 @@ OC.MountConfig={
if ($.inArray(applicable, oldGroups) != -1) { if ($.inArray(applicable, oldGroups) != -1) {
oldGroups.splice($.inArray(applicable, oldGroups), 1); oldGroups.splice($.inArray(applicable, oldGroups), 1);
} }
groups.push(applicable);
} else { } else {
var mountType = 'user'; var mountType = 'user';
var applicable = value; var applicable = value;
if ($.inArray(applicable, oldUsers) != -1) { if ($.inArray(applicable, oldUsers) != -1) {
oldUsers.splice($.inArray(applicable, oldUsers), 1); oldUsers.splice($.inArray(applicable, oldUsers), 1);
} }
users.push(applicable);
} }
$.post(OC.filePath('files_external', 'ajax', 'addMountPoint.php'), { mountPoint: mountPoint, class: backendClass, classOptions: classOptions, mountType: mountType, applicable: applicable, isPersonal: isPersonal }, function(result) { $.post(OC.filePath('files_external', 'ajax', 'addMountPoint.php'), { mountPoint: mountPoint, class: backendClass, classOptions: classOptions, mountType: mountType, applicable: applicable, isPersonal: isPersonal }, function(result) {
statusSpan.removeClass(); statusSpan.removeClass();
@ -63,6 +67,8 @@ OC.MountConfig={
} }
}); });
}); });
$(tr).find('.applicable').data('applicable-groups', groups);
$(tr).find('.applicable').data('applicable-users', users);
var mountType = 'group'; var mountType = 'group';
$.each(oldGroups, function(index, applicable) { $.each(oldGroups, function(index, applicable) {
$.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal }); $.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
@ -128,7 +134,11 @@ $(document).ready(function() {
return false; return false;
} }
}); });
$('.chz-select').chosen(); // 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().attr('class', 'remove');
$(tr).find('td').last().removeAttr('style'); $(tr).find('td').last().removeAttr('style');
$(tr).removeAttr('id'); $(tr).removeAttr('id');
@ -171,9 +181,9 @@ $(document).ready(function() {
var timer; var timer;
$('#externalStorage td').live('keyup', function() { $('#externalStorage td input').live('keyup', function() {
clearTimeout(timer); clearTimeout(timer);
var tr = $(this).parent(); var tr = $(this).parent().parent();
if ($(this).val) { if ($(this).val) {
timer = setTimeout(function() { timer = setTimeout(function() {
OC.MountConfig.saveStorage(tr); OC.MountConfig.saveStorage(tr);
@ -181,6 +191,10 @@ $(document).ready(function() {
} }
}); });
$('.applicable .chzn-select').live('change', function() {
OC.MountConfig.saveStorage($(this).parent().parent());
});
$('td.remove>img').live('click', function() { $('td.remove>img').live('click', function() {
var tr = $(this).parent().parent(); var tr = $(this).parent().parent();
var mountPoint = $(tr).find('.mountPoint input').val(); var mountPoint = $(tr).find('.mountPoint input').val();
@ -193,23 +207,25 @@ $(document).ready(function() {
if ($('#externalStorage').data('admin') === true) { if ($('#externalStorage').data('admin') === true) {
var isPersonal = false; var isPersonal = false;
var multiselect = $(tr).find('.chzn-select').val(); var multiselect = $(tr).find('.chzn-select').val();
$.each(multiselect, function(index, value) { if (multiselect != null) {
var pos = value.indexOf('(group)'); $.each(multiselect, function(index, value) {
if (pos != -1) { var pos = value.indexOf('(group)');
var mountType = 'group'; if (pos != -1) {
var applicable = value.substr(0, pos); var mountType = 'group';
} else { var applicable = value.substr(0, pos);
var mountType = 'user'; } else {
var applicable = value; var mountType = 'user';
} var applicable = value;
$.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal }); }
}); $.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
});
}
} else { } else {
var mountType = 'user'; var mountType = 'user';
var applicable = OC.currentUser; var applicable = OC.currentUser;
var isPersonal = true; var isPersonal = true;
$.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
} }
$.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
$(tr).remove(); $(tr).remove();
}); });