Skip to content

Commit

Permalink
Merge pull request #10968 from owncloud/admin-groupsselect2
Browse files Browse the repository at this point in the history
Use select2 for the groups excluded from sharing in admin page
  • Loading branch information
LukasReschke committed Sep 19, 2014
2 parents fb033cc + 71776e3 commit fed8100
Show file tree
Hide file tree
Showing 68 changed files with 153 additions and 113 deletions.
4 changes: 2 additions & 2 deletions apps/files_external/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
OCP\Util::addScript('files_external', 'settings');
OCP\Util::addStyle('files_external', 'settings');

OCP\Util::addScript('files_external', '../3rdparty/select2/select2');
OCP\Util::addStyle('files_external', '../3rdparty/select2/select2');
OCP\Util::addScript('core', 'select2/select2');
OCP\Util::addStyle('core', 'select2/select2');

$backends = OC_Mount_Config::getBackends();
$personal_backends = array();
Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
12 changes: 12 additions & 0 deletions core/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ input[type="time"] {
-moz-box-sizing: border-box; box-sizing: border-box;
}

.select2-choices {
border: 1px solid #ddd;
border-radius: 3px;
color: #333;
background-image: none;
}
.select2-dropdown-open .select2-choices {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
border: 1px solid #3875d7;
}

/* correctly align images inside of buttons */
input img, button img, .button img {
vertical-align: text-bottom;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 6 additions & 16 deletions settings/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@

OC_Util::checkAdminUser();

OC_Util::addStyle( "settings", "settings" );
OCP\Util::addStyle('settings', 'settings');
OCP\Util::addScript('settings', 'settings');
OC_Util::addScript( "settings", "admin" );
OC_Util::addScript( "settings", "log" );
OC_Util::addScript( 'core', 'multiselect' );
OCP\Util::addScript('core', 'select2/select2');
OCP\Util::addStyle('core', 'select2/select2');
OC_App::setActiveNavigationEntry( "admin" );

$tmpl = new OC_Template( 'settings', 'admin', 'user');
Expand Down Expand Up @@ -54,22 +57,9 @@
$tmpl->assign('shareEnforceExpireDate', OC_Appconfig::getValue('core', 'shareapi_enforce_expire_date', 'no'));
$excludeGroups = OC_Appconfig::getValue('core', 'shareapi_exclude_groups', 'no') === 'yes' ? true : false;
$tmpl->assign('shareExcludeGroups', $excludeGroups);
$allGroups = OC_Group::getGroups();
$excludedGroupsList = OC_Appconfig::getValue('core', 'shareapi_exclude_groups_list', '');
$excludedGroups = $excludedGroupsList !== '' ? explode(',', $excludedGroupsList) : array();
$groups = array();
foreach ($allGroups as $group) {
if (in_array($group, $excludedGroups)) {
$groups[$group] = array('gid' => $group,
'excluded' => true);
} else {
$groups[$group] = array('gid' => $group,
'excluded' => false);
}
}
ksort($groups);
$tmpl->assign('groups', $groups);

$excludedGroupsList = explode(',', $excludedGroupsList); // FIXME: this should be JSON!
$tmpl->assign('shareExcludedGroupsList', implode('|', $excludedGroupsList));

// Check if connected using HTTPS
$tmpl->assign('isConnectedViaHTTPS', OC_Request::serverProtocol() === 'https');
Expand Down
18 changes: 0 additions & 18 deletions settings/ajax/excludegroups.php

This file was deleted.

8 changes: 4 additions & 4 deletions settings/apps.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
OC_Util::checkAdminUser();

// Load the files we need
OC_Util::addStyle( "settings", "settings" );
OC_Util::addScript("core", "multiselect");
OCP\Util::addStyle('settings', 'settings' );
OCP\Util::addScript('settings', 'settings');
OCP\Util::addScript('core', 'select2/select2');
OCP\Util::addStyle('core', 'select2/select2');
OC_App::setActiveNavigationEntry( "core_apps" );

$combinedApps = OC_App::listAllApps();
$groups = \OC_Group::getGroups();

$tmpl = new OC_Template( "settings", "apps", "user" );

$tmpl->assign('apps', $combinedApps);
$tmpl->assign('groups', $groups);

$appid = (isset($_GET['appid'])?strip_tags($_GET['appid']):'');

Expand Down
54 changes: 12 additions & 42 deletions settings/js/admin.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,3 @@
var SharingGroupList = {
applyMultipleSelect: function(element) {
var checked = [];
if ($(element).hasClass('groupsselect')) {
if (element.data('userGroups')) {
checked = element.data('userGroups');
}
var checkHandeler = function(group) {
$.post(OC.filePath('settings', 'ajax', 'excludegroups.php'),
{changedGroup: group, selectedGroups: JSON.stringify(checked)},
function() {});
};


var addGroup = function(select, group) {
$(this).each(function(index, element) {
if ($(element).find('option[value="' + group + '"]').length === 0 &&
select.data('msid') !== $(element).data('msid')) {
$(element).append('<option value="' + escapeHTML(group) + '">' +
escapeHTML(group) + '</option>');
}
});
};

var label = null;
element.multiSelect({
createCallback: addGroup,
createText: label,
selectedFirst: true,
checked: checked,
oncheck: checkHandeler,
onuncheck: checkHandeler,
minWidth: 100
});

}
}
};

$(document).ready(function(){
var params = OC.Util.History.parseUrlQuery();

Expand All @@ -57,8 +18,17 @@ $(document).ready(function(){
}


$('select#excludedGroups[multiple]').each(function (index, element) {
SharingGroupList.applyMultipleSelect($(element));
$('#excludedGroups').each(function (index, element) {
OC.Settings.setupGroupsSelect($(element));
$(element).change(function(ev) {
var groups = ev.val || [];
if (groups.length > 0) {
groups = ev.val.join(','); // FIXME: make this JSON
} else {
groups = '';
}
OC.AppConfig.setValue('core', $(this).attr('name'), groups);
});
});


Expand All @@ -81,7 +51,7 @@ $(document).ready(function(){
$('#shareAPI p:not(#enable)').toggleClass('hidden', !this.checked);
});

$('#shareAPI input').change(function() {
$('#shareAPI input:not(#excludedGroups)').change(function() {
if ($(this).attr('type') === 'checkbox') {
if (this.checked) {
var value = 'yes';
Expand Down
35 changes: 17 additions & 18 deletions settings/js/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

OC.Settings = OC.Settings || {};
OC.Settings.Apps = OC.Settings.Apps || {
setupGroupsSelect: function() {
OC.Settings.setupGroupsSelect($('#group_select'), {
placeholder: t('core', 'All')
});
},
loadApp:function(app) {
var page = $('#app-content');
page.find('p.license').show();
Expand Down Expand Up @@ -112,23 +117,16 @@ OC.Settings.Apps = OC.Settings.Apps || {
page.find(".warning").hide();
}

page.find("div.multiselect").parent().remove();
if(OC.Settings.Apps.isType(app, 'filesystem') || OC.Settings.Apps.isType(app, 'prelogin') ||
OC.Settings.Apps.isType(app, 'authentication') || OC.Settings.Apps.isType(app, 'logging')) {
page.find("#groups_enable").hide();
page.find("label[for='groups_enable']").hide();
page.find("#groups_enable").attr('checked', null);
} else {
$('#group_select > option').each(function (i, el) {
if (app.groups.length === 0 || app.groups.indexOf(el.value) >= 0) {
$(el).attr('selected', 'selected');
} else {
$(el).attr('selected', null);
}
});
if (app.active) {
if (app.groups.length) {
$('#group_select').multiSelect();
OC.Settings.Apps.setupGroupsSelect();
$('#group_select').select2('val', app.groups || []);
page.find("#groups_enable").attr('checked','checked');
} else {
page.find("#groups_enable").attr('checked', null);
Expand Down Expand Up @@ -380,9 +378,10 @@ $(document).ready(function(){
}
});

$('#group_select').change(function() {
$('#group_select').change(function(ev) {
var element = $('#app-content input.enable');
var groups = $(this).val();
// getting an array of values from select2
var groups = ev.val || [];
var appid = element.data('appid');
if (appid) {
OC.Settings.Apps.enableApp(appid, false, element, groups);
Expand All @@ -404,14 +403,14 @@ $(document).ready(function(){
}

$("#groups_enable").change(function() {
var $select = $('#group_select');
$select.val('');
if (this.checked) {
$("div.multiselect").parent().remove();
$('#group_select').multiSelect();
} else {
$('#group_select').hide().val(null);
$("div.multiselect").parent().remove();
OC.Settings.Apps.setupGroupsSelect();
}

$('#group_select').change();
else {
$select.select2('destroy');
}
$select.change();
});
});
98 changes: 98 additions & 0 deletions settings/js/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Copyright (c) 2014, Vincent Petry <[email protected]>
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file.
*/
OC.Settings = OC.Settings || {};
OC.Settings = _.extend(OC.Settings, {

_cachedGroups: null,

/**
* Setup selection box for group selection.
*
* Values need to be separated by a pipe "|" character.
* (mostly because a comma is more likely to be used
* for groups)
*
* @param $elements jQuery element (hidden input) to setup select2 on
* @param [extraOptions] extra options hash to pass to select2
*/
setupGroupsSelect: function($elements, extraOptions) {
var self = this;
if ($elements.length > 0) {
// note: settings are saved through a "change" event registered
// on all input fields
$elements.select2(_.extend({
placeholder: t('core', 'Groups'),
allowClear: true,
multiple: true,
separator: '|',
query: _.debounce(function(query) {
var queryData = {};
if (self._cachedGroups && query.term === '') {
query.callback({results: self._cachedGroups});
return;
}
if (query.term !== '') {
queryData = {
pattern: query.term,
filterGroups: 1
};
}
$.ajax({
url: OC.generateUrl('/settings/ajax/grouplist'),
data: queryData,
dataType: 'json',
success: function(data) {
if (data.status === "success") {
var results = [];

// add groups
$.each(data.data.adminGroups, function(i, group) {
results.push({id:group.id, displayname:group.name});
});
$.each(data.data.groups, function(i, group) {
results.push({id:group.id, displayname:group.name});
});

if (query.term === '') {
// cache full list
self._cachedGroups = results;
}
query.callback({results: results});
} else {
//FIXME add error handling
}
}
});
}, 100, true),
id: function(element) {
return element.id;
},
initSelection: function(element, callback) {
var selection =
_.map(($(element).val() || []).split('|').sort(),
function(groupName) {
return {
id: groupName,
displayname: groupName
};
});
callback(selection);
},
formatResult: function (element) {
return escapeHTML(element.displayname);
},
formatSelection: function (element) {
return escapeHTML(element.displayname);
},
escapeMarkup: function(m) {
// prevent double markup escape
return m;
}
}, extraOptions || {}));
}
}
});

9 changes: 1 addition & 8 deletions settings/templates/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,7 @@
<label for="shareapiExcludeGroups"><?php p($l->t('Exclude groups from sharing'));?></label><br/>
</p>
<p id="selectExcludedGroups" class="indent <?php if (!$_['shareExcludeGroups'] || $_['shareAPIEnabled'] === 'no') p('hidden'); ?>">
<select
class="groupsselect"
id="excludedGroups" data-placeholder="groups"
title="<?php p($l->t('Groups'))?>" multiple="multiple">
<?php foreach($_["groups"] as $group): ?>
<option value="<?php p($group['gid'])?>" <?php if($group['excluded']) { p('selected="selected"'); }?>><?php p($group['gid']);?></option>
<?php endforeach;?>
</select>
<input name="shareapi_exclude_groups_list" type="hidden" id="excludedGroups" value="<?php p($_['shareExcludedGroupsList']) ?>" style="width: 400px"/>
<br />
<em><?php p($l->t('These groups will still be able to receive shares, but not to initiate them.')); ?></em>
</p>
Expand Down
6 changes: 1 addition & 5 deletions settings/templates/apps.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ class="version"></span><small class="externalapp" style="visibility:hidden;"></s
<input class="hidden" type="checkbox" id="groups_enable"/>
<label class="hidden" for="groups_enable"><?php p($l->t('Enable only for specific groups')); ?></label>
<br />
<select class="hidden" id="group_select" multiple="multiple" title="<?php p($l->t('All')); ?>">
<?php foreach($_['groups'] as $group):?>
<option value="<?php p($group);?>"><?php p($group); ?></option>
<?php endforeach;?>
</select>
<input type="hidden" id="group_select" title="<?php p($l->t('All')); ?>" style="width: 200px">

<div class="warning hidden"></div>
</div>
Expand Down

0 comments on commit fed8100

Please sign in to comment.