Commit e3510c9e authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1620411: Fixing up the checking for start/stop dates



When the row has disabled fields

Also fixing select options when we have a locked option

We used to remove the option but this causes a problem showing the
option as selected one. Need to keep all options and then disable the
locked one from being picked twice.

behatnotneeded

Change-Id: I4db0d6810099c751f46b504edf1a0cffde6e6b83
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 363a224c
......@@ -50,7 +50,9 @@ function pieform_element_viewacl(Pieform $form, $element) {
if ($form->get_property('userview')) {
$allowedpresets[] = 'friends';
}
$accesslist = array();
$lockedpreset = null;
if ($value) {
foreach ($value as $item) {
if (is_array($item)) {
......@@ -84,7 +86,7 @@ function pieform_element_viewacl(Pieform $form, $element) {
$accesslist[] = $item;
}
if (!empty($item['locked'])) {
$allowedpresets = array_values(array_diff($allowedpresets, array($item['type'])));
$lockedpreset = $item['type'];
}
}
}
......@@ -130,6 +132,7 @@ function pieform_element_viewacl(Pieform $form, $element) {
'start' => null,
'end' => null,
'name' => get_string(($preset == 'loggedin' ? 'registeredusers' : $preset), 'view'),
'locked' => ($preset === $lockedpreset),
'preset' => true
);
}
......@@ -199,6 +202,7 @@ function pieform_element_viewacl(Pieform $form, $element) {
$datepickeroptionstr .= $key . ': ' . json_encode($option) . ',';
}
}
$smarty->assign('datepickeroptions', $datepickeroptionstr);
$smarty->assign('viewtype', $element['viewtype']);
$smarty->assign('potentialpresets', json_encode($allowedpresets));
......
......@@ -56,7 +56,7 @@
<optgroup label="{%={{jstr tag=general section=view}}%}" id="potentialpresetitemssharewith">
{% for (var i=0; i<o.shareoptions.general.length; i++) { %}
<option value="{%=o.shareoptions.general[i].id%}"{% if (o.presets.type == o.shareoptions.general[i].id) { %} selected{% } %}>{%=o.shareoptions.general[i].name%}</option>
<option value="{%=o.shareoptions.general[i].id%}"{% if (o.presets.type == o.shareoptions.general[i].id) { %} selected{% } %} {% if (o.shareoptions.general[i].locked) { %} disabled{% } %}>{%=o.shareoptions.general[i].name%}</option>
{% } %}
</optgroup>
......@@ -387,7 +387,8 @@ jQuery(function($) {
results.general[i] = {
'id': item.id,
'name': item.name,
'selected': item.preset
'selected': item.preset,
'locked': item.locked
};
}
......
......@@ -412,17 +412,17 @@ function editaccess_validate(Pieform $form, $values) {
break;
}
if ($item['type'] == 'loggedin' && !$item['startdate'] && !$item['stopdate']) {
if ($item['type'] == 'loggedin' && empty($item['startdate']) && empty($item['stopdate'])) {
$loggedinaccess = true;
}
$now = time();
if ($item['stopdate'] && $now > $item['stopdate']) {
if (!empty($item['stopdate']) && $now > $item['stopdate']) {
$SESSION->add_error_msg(get_string('newstopdatecannotbeinpast', 'view', $accesstypestrings[$item['type']]));
$form->set_error('accesslist', '');
break;
}
if ($item['startdate'] && $item['stopdate'] && $item['startdate'] > $item['stopdate']) {
if (!empty($item['startdate']) && !empty($item['stopdate']) && $item['startdate'] > $item['stopdate']) {
$SESSION->add_error_msg(get_string('newstartdatemustbebeforestopdate', 'view', $accesstypestrings[$item['type']]));
$form->set_error('accesslist', '');
break;
......
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