Cleanup and bugfix in category only capabilities (non-system)

This commit is contained in:
PMKuipers 2023-08-17 23:29:32 +02:00
parent 9fde891c94
commit c04827d48c
9 changed files with 26 additions and 104 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -51,8 +51,10 @@ let strings = load_strings({
*/ */
export function init(contextid,categoryid) { export function init(contextid,categoryid) {
// Make sure the id's are numeric and integer // Make sure the id's are numeric and integer
if(undefined === contextid || !Number.isInteger(contextid) || contextid < 1 ){ contextid = 1;} if(undefined === contextid || !Number.isInteger(Number(contextid)) || contextid < 1 ){ contextid = 1;}
if(undefined === categoryid || !Number.isInteger(categoryid)){ categoryid = 0;} else { contextid = Number(contextid);} // ensure a numeric value instead of string
if(undefined === categoryid || !Number.isInteger(Number(categoryid))){ categoryid = 0;}
else { categoryid = Number(categoryid);} // ensure a numeric value instead of string
const in_systemcontext = (contextid <= 1); const in_systemcontext = (contextid <= 1);

View file

@ -44,8 +44,10 @@ let strings = load_strings({
*/ */
export function init(contextid,categoryid) { export function init(contextid,categoryid) {
// Make sure the id's are numeric and integer // Make sure the id's are numeric and integer
if(undefined === contextid || !Number.isInteger(contextid) || contextid < 1 ){ contextid = 1;} if(undefined === contextid || !Number.isInteger(Number(contextid)) || contextid < 1 ){ contextid = 1;}
if(undefined === categoryid || !Number.isInteger(categoryid)){ categoryid = 0;} else { contextid = Number(contextid);} // ensure a numeric value instead of string
if(undefined === categoryid || !Number.isInteger(Number(categoryid))){ categoryid = 0;}
else { categoryid = Number(categoryid);} // ensure a numeric value instead of string
const in_systemcontext = (contextid <= 1); const in_systemcontext = (contextid <= 1);

View file

@ -1,91 +0,0 @@
.vue-hsluv-picker {
min-width: 300px;
display: flex;
flex-direction: column;
}
.vue-hsluv-picker.horizontal {
flex-direction: row;
}
.vue-hsluv-picker.horizontal .display {
margin-top: 10px;
}
.vue-hsluv-picker td.cell-input {
width: 90px;
padding-right: 20px;
}
.vue-hsluv-picker td.cell-input input {
margin: 0;
height: 22px;
background: transparent;
outline: none;
border: 1px solid #333;
border-radius: 0;
text-align: right;
width: 100%;
padding: 0;
}
.vue-hsluv-picker td.cell-input.cell-input-hex input {
font-family: monospace;
border-color: #555;
}
.vue-hsluv-picker table {
margin-top: 20px;
width: 100%;
}
.vue-hsluv-picker table td {
padding: 5px 5px;
vertical-align: top;
border: none;
}
.vue-hsluv-picker table td.picker-label {
color: #eee;
width: 30px;
line-height: 22px;
}
.vue-hsluv-picker table .swatch {
height: 50px;
border-color: #555;
border-style: solid;
border-width: 1px;
}
.vue-hsluv-picker .explanation-text {
margin-bottom: 60px;
margin-top: 100px;
}
.vue-hsluv-picker .range-slider {
height: 22px;
display: block;
position: relative;
border-color: #555;
border-style: solid;
border-width: 1px;
}
.vue-hsluv-picker .range-slider-handle {
display: inline-block;
position: absolute;
width: 6px;
left: -5px;
top: -2px;
height: calc(100% + 4px);
cursor: default;
border: 2px solid #333;
touch-action: pan-y;
-ms-touch-action: pan-y;
background-color: #fff;
}
.vue-hsluv-picker circle.outercircle {
stroke: black;
}

View file

@ -31,8 +31,19 @@ elseif($contextid > 0)
} }
else else
{ {
$categoryid = 0; // If no context is selected, find the first available one
$studyplancontext = $systemcontext; $available_contexts = courseservice::list_accessible_categories_with_usage("edit");
$contextid=1; // fallback to system context
foreach($available_contexts as $ctx){
if($ctx->count > 0){
$contextid = $ctx->ctxid;
break;
}
}
// reload page with selected category
$url = new \moodle_url('/local/treestudyplan/edit-plan.php',["contextid" => $contextid]);
header('Location: '.$url->out(false), true, 302);
exit;
} }
require_capability('local/treestudyplan:editstudyplan',$studyplancontext); require_capability('local/treestudyplan:editstudyplan',$studyplancontext);
@ -52,7 +63,6 @@ if($studyplancontext->id > 1){
// Load javascripts and specific css // Load javascripts and specific css
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue.min.css')); $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue.min.css'));
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css')); $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/vue-hsluv-picker.css'));
$PAGE->requires->js_call_amd('local_treestudyplan/page-edit-plan', 'init', [$studyplancontext->id,$categoryid]); $PAGE->requires->js_call_amd('local_treestudyplan/page-edit-plan', 'init', [$studyplancontext->id,$categoryid]);
@ -122,7 +132,7 @@ print $OUTPUT->header();
<template #title> <template #title>
<span class='s-studyplan-card-title-buttons'> <span class='s-studyplan-card-title-buttons'>
<a href='#' @click.prevent="export_plan(studyplan)" ><i class='fa fa-download'></i></a> <a href='#' @click.prevent="export_plan(studyplan)" ><i class='fa fa-download'></i></a>
<t-studyplan-edit v-model="studyplans[planindex]"></t-studyplan-edit> <t-studyplan-edit v-model="studyplans[planindex]" @moved="movedStudyplan"></t-studyplan-edit>
<t-studyplan-associate v-model="studyplans[planindex]"></t-studyplan-associate> <t-studyplan-associate v-model="studyplans[planindex]"></t-studyplan-associate>
</span> </span>
</template> </template>

View file

@ -62,7 +62,6 @@ if($studyplancontext->id > 1){
// Load javascripts and specific css // Load javascripts and specific css
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue.min.css')); $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue.min.css'));
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css')); $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/vue-hsluv-picker.css'));
$PAGE->requires->js_call_amd('local_treestudyplan/page-view-plan', 'init',[$studyplancontext->id,$categoryid]); $PAGE->requires->js_call_amd('local_treestudyplan/page-view-plan', 'init',[$studyplancontext->id,$categoryid]);
//Local translate function //Local translate function