aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/js
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/js')
-rw-r--r--apps/files_external/js/settings.js96
1 files changed, 72 insertions, 24 deletions
diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js
index 5228b958b67..d3e9fd44c0d 100644
--- a/apps/files_external/js/settings.js
+++ b/apps/files_external/js/settings.js
@@ -24,6 +24,28 @@ function getSelection($row) {
return values;
}
+function getSelectedApplicable($row) {
+ var users = [];
+ var groups = [];
+ var multiselect = getSelection($row);
+ $.each(multiselect, function(index, value) {
+ // FIXME: don't rely on string parts to detect groups...
+ var pos = (value.indexOf)?value.indexOf('(group)'): -1;
+ if (pos !== -1) {
+ groups.push(value.substr(0, pos));
+ } else {
+ users.push(value);
+ }
+ });
+
+ // FIXME: this should be done in the multiselect change event instead
+ $row.find('.applicable')
+ .data('applicable-groups', groups)
+ .data('applicable-users', users);
+
+ return { users, groups };
+}
+
function highlightBorder($element, highlight) {
$element.toggleClass('warning-input', highlight);
return highlight;
@@ -56,7 +78,7 @@ function highlightInput($input) {
* @param {Array<Object>} array of jQuery elements
* @param {number} userListLimit page size for result list
*/
-function addSelect2 ($elements, userListLimit) {
+function initApplicableUsersMultiselect($elements, userListLimit) {
var escapeHTML = function (text) {
return text.toString()
.split('&').join('&amp;')
@@ -68,8 +90,8 @@ function addSelect2 ($elements, userListLimit) {
if (!$elements.length) {
return;
}
- $elements.select2({
- placeholder: t('files_external', 'All users. Type to select user or group.'),
+ return $elements.select2({
+ placeholder: t('files_external', 'Type to select user or group.'),
allowClear: true,
multiple: true,
toggleSelect: true,
@@ -167,6 +189,8 @@ function addSelect2 ($elements, userListLimit) {
$div.avatar($div.data('name'),32);
}
});
+ }).on('change', function(event) {
+ highlightBorder($(event.target).closest('.applicableUsersContainer').find('.select2-choices'), !event.val.length);
});
}
@@ -721,6 +745,8 @@ MountConfigListView.prototype = _.extend({
this.$el.on('change', '.selectBackend', _.bind(this._onSelectBackend, this));
this.$el.on('change', '.selectAuthMechanism', _.bind(this._onSelectAuthMechanism, this));
+
+ this.$el.on('change', '.applicableToAllUsers', _.bind(this._onChangeApplicableToAllUsers, this));
},
_onChange: function(event) {
@@ -746,6 +772,7 @@ MountConfigListView.prototype = _.extend({
var onCompletion = jQuery.Deferred();
$tr = this.newStorage(storageConfig, onCompletion);
+ $tr.find('.applicableToAllUsers').prop('checked', false).trigger('change');
onCompletion.resolve();
$tr.find('td.configuration').children().not('[type=hidden]').first().focus();
@@ -764,6 +791,19 @@ MountConfigListView.prototype = _.extend({
this.saveStorageConfig($tr);
},
+ _onChangeApplicableToAllUsers: function(event) {
+ var $target = $(event.target);
+ var $tr = $target.closest('tr');
+ var checked = $target.is(':checked');
+
+ $tr.find('.applicableUsersContainer').toggleClass('hidden', checked);
+ if (!checked) {
+ $tr.find('.applicableUsers').select2('val', '', true);
+ }
+
+ this.saveStorageConfig($tr);
+ },
+
/**
* Configure the storage config with a new authentication mechanism
*
@@ -818,7 +858,7 @@ MountConfigListView.prototype = _.extend({
$tr.removeAttr('id');
$tr.find('select#selectBackend');
if (!deferAppend) {
- addSelect2($tr.find('.applicableUsers'), this._userListLimit);
+ initApplicableUsersMultiselect($tr.find('.applicableUsers'), this._userListLimit);
}
if (storageConfig.id) {
@@ -890,7 +930,14 @@ MountConfigListView.prototype = _.extend({
})
);
}
- $tr.find('.applicableUsers').val(applicable).trigger('change');
+ if (applicable.length) {
+ $tr.find('.applicableUsers').val(applicable).trigger('change')
+ $tr.find('.applicableUsersContainer').removeClass('hidden');
+ } else {
+ // applicable to all
+ $tr.find('.applicableUsersContainer').addClass('hidden');
+ }
+ $tr.find('.applicableToAllUsers').prop('checked', !applicable.length);
var priorityEl = $('<input type="hidden" class="priority" value="' + backend.priority + '" />');
$tr.append(priorityEl);
@@ -967,7 +1014,7 @@ MountConfigListView.prototype = _.extend({
}
$rows = $rows.add($tr);
});
- addSelect2(self.$el.find('.applicableUsers'), this._userListLimit);
+ initApplicableUsersMultiselect(self.$el.find('.applicableUsers'), this._userListLimit);
self.$el.find('tr#addMountPoint').before($rows);
var mainForm = $('#files_external');
if (result.length === 0 && mainForm.attr('data-can-create') === 'false') {
@@ -1007,7 +1054,7 @@ MountConfigListView.prototype = _.extend({
}
$rows = $rows.add($tr);
});
- addSelect2($rows.find('.applicableUsers'), this._userListLimit);
+ initApplicableUsersMultiselect($rows.find('.applicableUsers'), this._userListLimit);
self.$el.find('tr#addMountPoint').before($rows);
onCompletion.resolve();
onLoaded2.resolve();
@@ -1126,24 +1173,25 @@ MountConfigListView.prototype = _.extend({
// gather selected users and groups
if (!this._isPersonal) {
- var groups = [];
- var users = [];
- var multiselect = getSelection($tr);
- $.each(multiselect, function(index, value) {
- var pos = (value.indexOf)?value.indexOf('(group)'): -1;
- if (pos !== -1) {
- groups.push(value.substr(0, pos));
- } else {
- users.push(value);
- }
- });
- // FIXME: this should be done in the multiselect change event instead
- $tr.find('.applicable')
- .data('applicable-groups', groups)
- .data('applicable-users', users);
+ var multiselect = getSelectedApplicable($tr);
+ var users = multiselect.users || [];
+ var groups = multiselect.groups || [];
+ var isApplicableToAllUsers = $tr.find('.applicableToAllUsers').is(':checked');
+
+ if (isApplicableToAllUsers) {
+ storage.applicableUsers = [];
+ storage.applicableGroups = [];
+ } else {
+ storage.applicableUsers = users;
+ storage.applicableGroups = groups;
- storage.applicableUsers = users;
- storage.applicableGroups = groups;
+ if (!storage.applicableUsers.length && !storage.applicableGroups.length) {
+ if (!storage.errors) {
+ storage.errors = {};
+ }
+ storage.errors['requiredApplicable'] = true;
+ }
+ }
storage.priority = parseInt($tr.find('input.priority').val() || '100', 10);
}