Commit 4e42183e authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Ensure logged in users have access to site/institution views copied for new users/groups

parent 33e01f72
......@@ -42,9 +42,11 @@ function pieform_element_viewacl(Pieform $form, $element) {
$presets = array();
if (get_config('allowpublicviews') == '1') {
$presets = array('public', 'loggedin', 'friends', 'token');
$loggedinindex = 1;
}
else {
$presets = array('loggedin', 'friends');
$loggedinindex = 0;
}
if ($value) {
foreach ($value as $key => &$item) {
......@@ -76,6 +78,7 @@ function pieform_element_viewacl(Pieform $form, $element) {
}
$smarty->assign('potentialpresets', json_encode($potentialpresets));
$smarty->assign('loggedinindex', $loggedinindex);
$smarty->assign('accesslist', json_encode($value));
$smarty->assign('viewid', $form->get_property('viewid'));
$smarty->assign('formname', $form->get_property('name'));
......
......@@ -86,7 +86,7 @@ function renderAccessListItem(item) {
TBODY(null,
TR(null,
TH(null, name, (item.role ? ' - ' + item.roledisplay : '')),
TD({'class': 'right'}, removeButton)
TD({'class': 'right removebutton'}, removeButton)
),
TR(null,
TD({'colspan': 2},
......@@ -193,6 +193,31 @@ var potentialPresets = {{$potentialpresets}};
forEach(potentialPresets, function(preset) {
renderPotentialPresetItem(preset);
});
var loggedinindex = {{$loggedinindex}};
function ensure_loggedin_access() {
var oldaccess = getFirstElementByTagAndClassName(null, 'loggedin-container', 'accesslistitems');
if (oldaccess) {
forEach(getElementsByTagAndClassName(null, 'loggedin-container', 'accesslistitems'), function (elem) {
if (oldaccess != elem) {
removeElement(elem);
}
});
}
else {
renderAccessListItem(potentialPresets[loggedinindex]);
}
var newaccess = getFirstElementByTagAndClassName(null, 'loggedin-container', 'accesslistitems');
addElementClass(getFirstElementByTagAndClassName(null, 'removebutton', newaccess), 'hidden');
forEach(getElementsByTagAndClassName(null, 'pieform-calendar-toggle', newaccess), function (elem) { addElementClass(elem, 'hidden'); });
forEach(getElementsByTagAndClassName('input', null, newaccess), function (elem) { elem.value = null; elem.disabled = true; });
}
function relax_loggedin_access() {
forEach(getElementsByTagAndClassName(null, 'loggedin-container', $('accesslistitems')), function (elem) {
removeElementClass(getElementsByTagAndClassName(null, 'removebutton', elem)[0], 'hidden');
forEach(getElementsByTagAndClassName(null, 'pieform-calendar-toggle', elem), function (elem1) { removeElementClass(elem1, 'hidden'); });
forEach(getElementsByTagAndClassName('input', null, elem), function (elem1) { elem1.disabled = false; });
});
}
// Left hand side
var searchTable = new TableRenderer(
......
......@@ -111,6 +111,7 @@ if ($institution) {
'value' => '<div class="description">' . get_string('copyfornewgroupsdescription', 'view') . '</div>',
);
$copyoptions = array('copynewuser', 'copyfornewgroups', 'copyfornewgroupsdescription');
$needsaccess = array('copynewuser');
$createfor = $view->get_autocreate_grouptypes();
foreach (group_get_grouptypes() as $grouptype) {
safe_require('grouptype', $grouptype);
......@@ -124,6 +125,7 @@ if ($institution) {
'defaultvalue' => $view->get('template') && in_array($grouptype, $createfor),
);
$copyoptions[] = 'copyfornewgroups_'.$grouptype;
$needsaccess[] = 'copyfornewgroups_'.$grouptype;
}
}
else {
......@@ -134,26 +136,43 @@ if ($institution) {
'defaultvalue' => $view->get('template') && $view->get('copynewuser'),
);
$copyoptions = array('copynewuser');
$needsaccess = array('copynewuser');
}
if (isset($form['elements']['copynewuser'])) {
$copyoptionstr = json_encode($copyoptions);
$js .= <<<EOF
$copyoptionstr = json_encode($copyoptions);
$needsaccessstr = json_encode($needsaccess);
$js .= <<<EOF
function update_copy_options() {
forEach({$copyoptionstr}, function (id) {
if ($('editaccess_template').checked) {
if ($('editaccess_template').checked) {
forEach({$copyoptionstr}, function (id) {
removeElementClass($('editaccess_'+id+'_container'), 'hidden');
}
else {
});
}
else {
forEach({$copyoptionstr}, function (id) {
addElementClass($('editaccess_'+id+'_container'), 'hidden');
}
});
});
forEach({$needsaccessstr}, function (id) {
$('editaccess_'+id).checked = false;
});
update_loggedin_access();
}
}
function update_loggedin_access() {
if (some({$needsaccessstr}, function (id) { return $('editaccess_'+id).checked; })) {
ensure_loggedin_access();
}
else {
relax_loggedin_access();
}
}
addLoadEvent(function() {
update_copy_options();
connect('editaccess_template', 'onchange', update_copy_options);
forEach({$needsaccessstr}, function (id) {
connect('editaccess_'+id, 'onchange', update_loggedin_access);
});
});
EOF;
}
}
$form['elements']['accesslist'] = array(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment