From 6c1ea7a54b01595c1f760ba15b47fb368ca11c6f Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 23 Jun 2016 18:42:11 +0200 Subject: Fix "Other" value handling in quota dropdown in users page Prevents "other" value to be deleted. When appending custom value, put it above the "other" entry. --- settings/js/users/users.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'settings/js') diff --git a/settings/js/users/users.js b/settings/js/users/users.js index e0fccbd9539..a4d88204861 100644 --- a/settings/js/users/users.js +++ b/settings/js/users/users.js @@ -138,10 +138,13 @@ var UserList = { .find('option').attr('selected', null) .first().attr('selected', 'selected'); } else { - if ($quotaSelect.find('option').filterAttr('value', user.quota).length > 0) { - $quotaSelect.find('option').filterAttr('value', user.quota).attr('selected', 'selected'); + var $options = $quotaSelect.find('option'); + var $foundOption = $options.filterAttr('value', user.quota); + if ($foundOption.length > 0) { + $foundOption.attr('selected', 'selected'); } else { - $quotaSelect.append(''); + // append before "Other" entry + $options.last().before(''); } } @@ -576,6 +579,9 @@ var UserList = { var $select = $(ev.target); var uid = UserList.getUID($select); var quota = $select.val(); + if (quota === 'other') { + return; + } UserList._updateQuota(uid, quota, function(returnedQuota){ if (quota !== returnedQuota) { $select.find(':selected').text(returnedQuota); -- cgit v1.2.3 From 819b7c45a94dd86e673a478d13ae100e9bc34ad4 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 24 Jun 2016 09:20:13 +0200 Subject: Prevent negative or non-number values in quota input --- settings/js/users/users.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'settings/js') diff --git a/settings/js/users/users.js b/settings/js/users/users.js index a4d88204861..2524a1da0bb 100644 --- a/settings/js/users/users.js +++ b/settings/js/users/users.js @@ -582,6 +582,12 @@ var UserList = { if (quota === 'other') { return; } + if (isNaN(parseInt(quota, 10)) || parseInt(quota, 10) < 0) { + // the select component has added the bogus value, delete it again + $select.find('option[selected]').remove(); + OC.Notification.showTemporary(t('core', 'Invalid quota value "{val}"', {val: quota})); + return; + } UserList._updateQuota(uid, quota, function(returnedQuota){ if (quota !== returnedQuota) { $select.find(':selected').text(returnedQuota); -- cgit v1.2.3