Commit 72dda251 authored by Astor Bizard's avatar Astor Bizard 🐕
Browse files

Fixed relative urls and namespace collisions (Moodle tracker issue CONTRIB-8331).

parent aa063eeb
define(["jquery","jqueryui","mod_randomactivity/orderabletable"],function(a,b,c){function d(b,c){var d=b.find("tbody tr");if(d.length>1)b.find(".empty-row").remove();else if(0==d.length){var e=b.find("thead th").length;b.find("tbody").append('<tr class="empty-row lastrow"><td colspan="'+e+'"></td></tr>')}var f="";b.find("tbody tr:not(.empty-row)").each(function(b){a(this).find("td:first-child").html(b+1),f+=a(this).data("cmid")+" "}).removeClass("lastrow").last().addClass("lastrow"),c.val(f.trim())}function e(b){var c=!0;a(".activity-to-add").each(function(){b(a(this).data("cmid"),a(this).data("cmtype"),a(this).find("label").text())?(c=!1,a(this).show()):a(this).hide()}),c?a("#no-activity-to-add-message").show():a("#no-activity-to-add-message").hide()}return{setup:function(){var b=a("#randomactivity-activities-table"),f=a("#form-randomactivity-activities"),g=f.find("[name=activities]"),h=f.find("[name=seed]");d(b,g),c.makeOrderable(a(".activitytable"),function(){d(b,g),f.change()}),a(".activitytable .removebutton").click(function(){a(this).closest("tr").remove(),d(b,g),f.change()});var i=function(a){a.preventDefault(),a.returnValue=""},j=!1;f.change(function(){a("#apply-assign-button").removeAttr("disabled"),j||(j=!0,window.addEventListener("beforeunload",i))}),a("#cancel-button").click(function(){window.removeEventListener("beforeunload",i)});var k=a("#confirm-reassign").dialog({autoOpen:!1,dialogClass:"popup-dialog",title:M.str.moodle.confirm,modal:!0,buttons:[{text:M.str.moodle.confirm,class:"btn btn-primary",click:function(){window.removeEventListener("beforeunload",i),f.submit()}},{text:M.str.moodle.cancel,class:"btn btn-secondary",click:function(){a(this).dialog("close")}}],open:function(){a(":focus").blur()}});a("#apply-assign-button").attr("disabled","disabled").click(function(){k.dialog("open")}),a("#seed-timestamp").click(function(a){a.preventDefault(),h.val((new Date).getTime()),f.change()}),a("#seed-balance").click(function(b){b.preventDefault();var c=a(".load-icon");c.show(),h.attr("disabled","disabled");var d=f.find("[name=id]").val(),e=g.val(),i=0;""!=e&&(i=e.split(" ").length),a.ajax("/mod/randomactivity/ajax/balanceseed.json.php?id="+d+"&nactivities="+i).done(function(a){a.success&&(h.val(a.response.seed),f.change()),h.removeAttr("disabled"),c.hide()}).fail(function(){h.removeAttr("disabled"),c.hide()})}),a(".refresh-assignees").click(function(){var c=f.find("[name=id]").val(),d=g.val(),e=h.val();a.ajax("/mod/randomactivity/ajax/refresh.json.php?id="+c+"&activities="+d+"&seed="+e).done(function(c){c.success&&b.find("tbody tr td:nth-child(3)").each(function(b){a(this).html(c.response.assignees[b])})})});var l={$selector:a(".activity-type-selector"),$dropdown:a(".activity-type-dropdown"),$selectmenu:a(".activity-type-selector, .activity-type-dropdown"),$selectedvalue:a(".activity-type-selected span"),$search:a("#activity-search")},m=a("#activities-choice").dialog({autoOpen:!1,dialogClass:"popup-dialog",title:M.util.get_string("addactivities","mod_randomactivity"),modal:!0,buttons:[{text:M.str.mod_randomactivity.addselectedactivities,class:"btn btn-primary",click:function(){a(".activity-to-add").each(function(){a(this).find('input[type="checkbox"]').prop("checked")&&a(this).find("tr").clone(!0,!0).appendTo(b).css("display","")}),a(this).dialog("close"),d(b,g),f.change()}},{text:M.str.moodle.cancel,class:"btn btn-secondary",click:function(){a(this).dialog("close")}}],open:function(){a(":focus").blur();var b=g.val().split(" ");e(function(a){return!b.includes(a+"")}),a(".activity-to-add").each(function(){a(this).find('input[type="checkbox"]').each(function(){a(this).prop("checked",!1)})}),l.$selectedvalue.html(a(".activity-type").first().html()).data("cmtype",""),l.$selector.removeClass("expanded").addClass("collapsed"),l.$selectmenu.width(""),l.$search.val("").keyup()}});a("#add-activities").click(function(){m.dialog("open")}),l.$selectmenu.click(function(){if(l.$selector.is(".collapsed")){l.$selector.removeClass("collapsed").addClass("expanded");var a=2*l.$dropdown.width()-l.$dropdown.prop("clientWidth");l.$selectmenu.width(Math.max(a,l.$selector.width()))}else l.$selector.removeClass("expanded").addClass("collapsed"),l.$selectmenu.width("")});var n=function(){var a=l.$selectedvalue.data("cmtype"),b=l.$search.val(),c=g.val().split(" ");e(function(d,e,f){return(!a||e==a)&&!c.includes(d+"")&&(""===b||f.toLowerCase().includes(b.toLowerCase()))})};a(".activity-type").click(function(){l.$selectedvalue.html(a(this).html()).data("cmtype",a(this).data("cmtype")),n()}),l.$search.keyup(function(){""!==a(this).val()?a(this).removeClass("empty"):a(this).addClass("empty"),n()}),a(".search-remove").click(function(){l.$search.val("").keyup()}),a(".search-icon").click(function(){l.$search.focus()})}}});
\ No newline at end of file
define(["jquery","jqueryui","core/url","mod_randomactivity/orderabletable"],function(a,b,c,d){function e(b,c){var d=b.find("tbody tr");if(d.length>1)b.find(".empty-row").remove();else if(0==d.length){var e=b.find("thead th").length;b.find("tbody").append('<tr class="empty-row lastrow"><td colspan="'+e+'"></td></tr>')}var f="";b.find("tbody tr:not(.empty-row)").each(function(b){a(this).find("td:first-child").html(b+1),f+=a(this).data("cmid")+" "}).removeClass("lastrow").last().addClass("lastrow"),c.val(f.trim())}function f(b){var c=!0;a(".activity-to-add").each(function(){b(a(this).data("cmid"),a(this).data("cmtype"),a(this).find("label").text())?(c=!1,a(this).show()):a(this).hide()}),c?a("#no-activity-to-add-message").show():a("#no-activity-to-add-message").hide()}return{setup:function(){var b=a("#randomactivity-activities-table"),g=a("#form-randomactivity-activities"),h=g.find("[name=activities]"),i=g.find("[name=seed]");e(b,h),d.makeOrderable(a(".activitytable"),function(){e(b,h),g.change()}),a(".activitytable .removebutton").click(function(){a(this).closest("tr").remove(),e(b,h),g.change()});var j=function(a){a.preventDefault(),a.returnValue=""},k=!1;g.change(function(){a("#apply-assign-button").removeAttr("disabled"),k||(k=!0,window.addEventListener("beforeunload",j))}),a("#cancel-button").click(function(){window.removeEventListener("beforeunload",j)});var l=a("#confirm-reassign").dialog({autoOpen:!1,dialogClass:"popup-dialog",title:M.str.moodle.confirm,modal:!0,buttons:[{text:M.str.moodle.confirm,class:"btn btn-primary",click:function(){window.removeEventListener("beforeunload",j),g.submit()}},{text:M.str.moodle.cancel,class:"btn btn-secondary",click:function(){a(this).dialog("close")}}],open:function(){a(":focus").blur()}});a("#apply-assign-button").attr("disabled","disabled").click(function(){l.dialog("open")}),a("#seed-timestamp").click(function(a){a.preventDefault(),i.val((new Date).getTime()),g.change()});var m=c.relativeUrl("/mod/randomactivity/ajax");a("#seed-balance").click(function(b){b.preventDefault();var c=a(".load-icon");c.show(),i.attr("disabled","disabled");var d=g.find("[name=id]").val(),e=h.val(),f=0;""!=e&&(f=e.split(" ").length),a.ajax(m+"/balanceseed.json.php?id="+d+"&nactivities="+f).done(function(a){a.success&&(i.val(a.response.seed),g.change()),i.removeAttr("disabled"),c.hide()}).fail(function(){i.removeAttr("disabled"),c.hide()})}),a(".refresh-assignees").click(function(){var c=g.find("[name=id]").val(),d=h.val(),e=i.val();a.ajax(m+"/refresh.json.php?id="+c+"&activities="+d+"&seed="+e).done(function(c){c.success&&b.find("tbody tr td:nth-child(3)").each(function(b){a(this).html(c.response.assignees[b])})})});var n={$selector:a(".activity-type-selector"),$dropdown:a(".activity-type-dropdown"),$selectmenu:a(".activity-type-selector, .activity-type-dropdown"),$selectedvalue:a(".activity-type-selected span"),$search:a("#activity-search")},o=a("#activities-choice").dialog({autoOpen:!1,dialogClass:"popup-dialog",title:M.util.get_string("addactivities","mod_randomactivity"),modal:!0,buttons:[{text:M.str.mod_randomactivity.addselectedactivities,class:"btn btn-primary",click:function(){a(".activity-to-add").each(function(){a(this).find('input[type="checkbox"]').prop("checked")&&a(this).find("tr").clone(!0,!0).appendTo(b).css("display","")}),a(this).dialog("close"),e(b,h),g.change()}},{text:M.str.moodle.cancel,class:"btn btn-secondary",click:function(){a(this).dialog("close")}}],open:function(){a(":focus").blur();var b=h.val().split(" ");f(function(a){return!b.includes(a+"")}),a(".activity-to-add").each(function(){a(this).find('input[type="checkbox"]').each(function(){a(this).prop("checked",!1)})}),n.$selectedvalue.html(a(".activity-type").first().html()).data("cmtype",""),n.$selector.removeClass("expanded").addClass("collapsed"),n.$selectmenu.width(""),n.$search.val("").keyup()}});a("#add-activities").click(function(){o.dialog("open")}),n.$selectmenu.click(function(){if(n.$selector.is(".collapsed")){n.$selector.removeClass("collapsed").addClass("expanded");var a=2*n.$dropdown.width()-n.$dropdown.prop("clientWidth");n.$selectmenu.width(Math.max(a,n.$selector.width()))}else n.$selector.removeClass("expanded").addClass("collapsed"),n.$selectmenu.width("")});var p=function(){var a=n.$selectedvalue.data("cmtype"),b=n.$search.val(),c=h.val().split(" ");f(function(d,e,f){return(!a||e==a)&&!c.includes(d+"")&&(""===b||f.toLowerCase().includes(b.toLowerCase()))})};a(".activity-type").click(function(){n.$selectedvalue.html(a(this).html()).data("cmtype",a(this).data("cmtype")),p()}),n.$search.keyup(function(){""!==a(this).val()?a(this).removeClass("empty"):a(this).addClass("empty"),p()}),a(".search-remove").click(function(){n.$search.val("").keyup()}),a(".search-icon").click(function(){n.$search.focus()})}}});
\ No newline at end of file
......@@ -19,7 +19,7 @@
* @copyright Astor Bizard, 2020
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'jqueryui', 'mod_randomactivity/orderabletable'], function($, jqui, OrderableTable) {
define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'], function($, jqui, url, OrderableTable) {
/**
* Reads the table and updates the hidden form field accordingly.
......@@ -157,6 +157,8 @@ define(['jquery', 'jqueryui', 'mod_randomactivity/orderabletable'], function($,
$form.change();
});
var baseurl = url.relativeUrl("/mod/randomactivity/ajax");
// Button "Seed to balance users".
$('#seed-balance').click(function(event) {
event.preventDefault();
......@@ -171,7 +173,7 @@ define(['jquery', 'jqueryui', 'mod_randomactivity/orderabletable'], function($,
if (activities != '') {
nactivities = activities.split(' ').length;
}
$.ajax('/mod/randomactivity/ajax/balanceseed.json.php?id=' + id + '&nactivities=' + nactivities)
$.ajax(baseurl + '/balanceseed.json.php?id=' + id + '&nactivities=' + nactivities)
.done(function(outcome) {
if (outcome.success) {
$seed.val(outcome.response.seed);
......@@ -191,7 +193,7 @@ define(['jquery', 'jqueryui', 'mod_randomactivity/orderabletable'], function($,
var id = $form.find('[name=id]').val();
var activities = $activities.val();
var seed = $seed.val();
$.ajax('/mod/randomactivity/ajax/refresh.json.php?id=' + id + '&activities=' + activities + '&seed=' + seed)
$.ajax(baseurl + '/refresh.json.php?id=' + id + '&activities=' + activities + '&seed=' + seed)
.done(function(outcome) {
if (outcome.success) {
$table.find('tbody tr td:nth-child(3)').each(function(i) {
......
......@@ -32,8 +32,8 @@ $cm = get_coursemodule_from_id( 'randomactivity', $id );
$context = context_module::instance( $cm->id );
if ( !has_capability('mod/randomactivity:viewgrades', $context) ) {
redirect('/mod/randomactivity/view.php?id=' . $id);
redirect( new moodle_url('/mod/randomactivity/view.php', array( 'id' => $id )) );
} else {
redirect('/mod/randomactivity/gradeslist.php?id=' . $id . '&userid=' . $userid);
redirect( new moodle_url('/mod/randomactivity/gradeslist.php', array( 'id' => $id, 'userid' => $userid )) );
}
die();
\ No newline at end of file
......@@ -213,4 +213,51 @@ function randomactivity_print_status_chip($status, $message = '', $title = '') {
break;
}
return '<span class="badge ' . $statusclass . '" title="' . $title . '">' . $message . '</span>';
}
/**
* Creates a row with an activity data to be put in an html_table.
* @param int $i Index of the row.
* @param cm_info|null $cminfo Course module info.
* @param string $cmassignees Formatted assignees list.
* @param boolean $editmode Whether the table/row can be edited.
* @param int|null $cmid (optional) Needed if $cminfo is null.
* @return html_table_row The built table row.
*/
function randomactivity_create_activity_table_row($i, $cminfo, $cmassignees, $editmode, $cmid = null) {
global $CFG, $DB;
$status = randomactivity_print_status_chip(randomactivity_get_activity_status($cminfo));
if ($cminfo !== null) {
$cmid = $cminfo->id;
$actions = '<a href="' . $CFG->wwwroot . '/course/modedit.php?update=' . $cminfo->id . '">' .
randomactivity_print_icon( 'settings', get_string( 'editsettings' ), array( 'class' => 'action-button' ) ) .
'</a>';
if ($editmode) {
$actions .= randomactivity_print_icon( 'move', get_string( 'move' ), array( 'class' => 'draghandle action-button' ) );
}
$gradeitems = grade_get_grades($cminfo->course, 'mod', $cminfo->modname, $cminfo->instance)->items;
if (count($gradeitems) == 0) {
// No grade.
$grade = get_string( 'nograde' );
} else if ($gradeitems[0]->scaleid != 0) {
// Scale.
$grade = $DB->get_record('scale', array( 'id' => $gradeitems[0]->scaleid ))->name;
} else {
// Point.
$grade = get_string( 'modgradetypepoint', 'grades' );
}
} else {
$grade = '';
$actions = '';
}
if ($editmode) {
$actions .= randomactivity_print_icon( 'remove', get_string( 'remove' ), array( 'class' => 'removebutton action-button' ) );
}
$row = new html_table_row(array($i, randomactivity_activity_icon_and_name($cminfo), $cmassignees, $grade, $status, $actions));
$row->attributes['data-cmid'] = $cmid;
return $row;
}
\ No newline at end of file
......@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die;
global $CFG;
require_once($CFG->dirroot.'/course/moodleform_mod.php');
require_once($CFG->dirroot . '/course/moodleform_mod.php');
/**
* Random activity edition form definition.
......
......@@ -23,7 +23,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2021012800;
$plugin->version = 2021012900;
$plugin->requires = 2018112800;
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '1.1';
......
......@@ -27,53 +27,6 @@ require_once(dirname(__FILE__) . '/lib.php');
require_login();
/**
* Creates a row with an activity data to be put in an html_table.
* @param int $i Index of the row.
* @param cm_info|null $cminfo Course module info.
* @param string $cmassignees Formatted assignees list.
* @param boolean $editmode Whether the table/row can be edited.
* @param int|null $cmid (optional) Needed if $cminfo is null.
* @return html_table_row The built table row.
*/
function create_activity_table_row($i, $cminfo, $cmassignees, $editmode, $cmid = null) {
global $DB;
$status = randomactivity_print_status_chip(randomactivity_get_activity_status($cminfo));
if ($cminfo !== null) {
$cmid = $cminfo->id;
$actions = '<a href="/course/modedit.php?update=' . $cminfo->id . '">' .
randomactivity_print_icon( 'settings', get_string( 'editsettings' ), array( 'class' => 'action-button' ) ) .
'</a>';
if ($editmode) {
$actions .= randomactivity_print_icon( 'move', get_string( 'move' ), array( 'class' => 'draghandle action-button' ) );
}
$gradeitems = grade_get_grades($cminfo->course, 'mod', $cminfo->modname, $cminfo->instance)->items;
if (count($gradeitems) == 0) {
// No grade.
$grade = get_string( 'nograde' );
} else if ($gradeitems[0]->scaleid != 0) {
// Scale.
$grade = $DB->get_record('scale', array( 'id' => $gradeitems[0]->scaleid ))->name;
} else {
// Point.
$grade = get_string( 'modgradetypepoint', 'grades' );
}
} else {
$grade = '';
$actions = '';
}
if ($editmode) {
$actions .= randomactivity_print_icon( 'remove', get_string( 'remove' ), array( 'class' => 'removebutton action-button' ) );
}
$row = new html_table_row(array($i, randomactivity_activity_icon_and_name($cminfo), $cmassignees, $grade, $status, $actions));
$row->attributes['data-cmid'] = $cmid;
return $row;
}
global $PAGE, $OUTPUT, $DB, $USER;
$id = required_param('id', PARAM_INT);
......@@ -121,7 +74,7 @@ if (($newseed = optional_param('seed', false, PARAM_RAW)) !== false && has_capab
$message = get_string('dbupdatefailed', 'error');
$messagetype = \core\output\notification::NOTIFY_ERROR;
}
redirect('/mod/randomactivity/view.php?id=' . $id, $message, $messagetype);
redirect(new moodle_url('/mod/randomactivity/view.php', array( 'id' => $id )), $message, null, $messagetype);
die();
}
......@@ -185,7 +138,7 @@ if ($module->activities == '') {
} catch (moodle_exception $e) {
$cminfo = null;
}
$table->data[] = create_activity_table_row($i, $cminfo, $cmassignees, $editmode, $cmid);
$table->data[] = randomactivity_create_activity_table_row($i, $cminfo, $cmassignees, $editmode, $cmid);
}
}
......@@ -226,7 +179,7 @@ if ($editmode) {
// Add a hidden table containing only one row. This row will be copied to the main table if the activity is added.
$hiddentable = new html_table();
$hiddentable->attributes['class'] = 'hidden-table activitytable';
$hiddentable->data = array( create_activity_table_row(0, $cminfo, get_string('none'), $editmode) );
$hiddentable->data = array( randomactivity_create_activity_table_row(0, $cminfo, get_string('none'), $editmode) );
$activity->hiddentable = html_writer::table( $hiddentable );
$allactivities[] = $activity;
}
......
Supports Markdown
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