Commit 6f17f5b2 authored by Astor Bizard's avatar Astor Bizard 🐕
Browse files

Moodle coding guidelines.

parent 3a5404ef
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(),a(this))?(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"]').prop("checked",!1)}),a(".activities-to-add-list .section").each(function(){a(this).addClass("expanded"),a(this).find("i.fa").removeClass("fa-caret-right").addClass("fa-caret-down"),q(a(this),function(a){a.removeClass("in-collapsed-section")})}),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,g){return(!a||e==a)&&!c.includes(d+"")&&(""===b||f.toLowerCase().includes(b.toLowerCase()))&&!g.is(".in-collapsed-section")})};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()});var q=function(a,b){for(var c=a.next();c.length>0&&!c.is(".section");)b(c),c=c.next()};a(".activities-to-add-list .section .btn-link").click(function(b){b.stopImmediatePropagation();var c=a(this).data("action");q(a(this).parents(".section"),function(a){a.is(":visible")&&a.find('input[type="checkbox"]').prop("checked","select"==c)})}),a(".activities-to-add-list .section").click(function(){a(this).is(".expanded")?(a(this).removeClass("expanded"),a(this).find("i.fa").removeClass("fa-caret-down").addClass("fa-caret-right"),q(a(this),function(a){a.hide(),a.addClass("in-collapsed-section")})):(a(this).addClass("expanded"),a(this).find("i.fa").removeClass("fa-caret-right").addClass("fa-caret-down"),q(a(this),function(a){a.removeClass("in-collapsed-section")}),p())})}}});
\ 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(),a(this))?(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.util.get_string("confirm","moodle"),modal:!0,buttons:[{text:M.util.get_string("confirm","moodle"),class:"btn btn-primary",click:function(){window.removeEventListener("beforeunload",j),g.submit()}},{text:M.util.get_string("cancel","moodle"),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.util.get_string("addselectedactivities","mod_randomactivity"),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.util.get_string("cancel","moodle"),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"]').prop("checked",!1)}),a(".activities-to-add-list .section").each(function(){a(this).addClass("expanded"),q(a(this),function(a){a.removeClass("in-collapsed-section")})}),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,g){return(!a||e==a)&&!c.includes(d+"")&&(""===b||f.toLowerCase().includes(b.toLowerCase()))&&!g.is(".in-collapsed-section")})};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()});var q=function(a,b){for(var c=a.next();c.length>0&&!c.is(".section");)b(c),c=c.next()};a(".activities-to-add-list .section .toggle-all").click(function(b){b.stopImmediatePropagation();var c=a(this).data("action");q(a(this).parents(".section"),function(a){a.is(":visible")&&a.find('input[type="checkbox"]').prop("checked","select"==c)})}),a(".activities-to-add-list .section").click(function(){a(this).is(".expanded")?(a(this).removeClass("expanded"),q(a(this),function(a){a.hide(),a.addClass("in-collapsed-section")})):(a(this).addClass("expanded"),q(a(this),function(a){a.removeClass("in-collapsed-section")}),p())})}}});
\ No newline at end of file
define(["jquery"],function(a){return{makeOrderable:function(b,c){var d,e,f,g,h,i,j=null;b.find(".draghandle").mousedown(function(b){b.preventDefault(),d=b.pageY,i=a(this).closest("table"),(j=a(this).closest("tr")).addClass("dragged"),e=j.attr("style")||"",f=j.index(),g=f,h=0}),a(window).mousemove(function(a){if(null!==j){var b,c;if(a.preventDefault(),g>0){var e=i.find("tbody tr:nth-child("+g+")");b=(2*e.offset().top+e.height()+j.height())/2}else b=Number.MIN_SAFE_INTEGER;if(g<i.find("tbody tr").length-1){var f=i.find("tbody tr:nth-child("+(g+2)+")");c=(2*f.offset().top+f.height()-j.height())/2}else c=Number.MAX_SAFE_INTEGER;a.pageY<b?(j.insertBefore(e),h+=e.height(),g--):a.pageY>c&&(j.insertAfter(f),h-=f.height(),g++);var k=a.pageY-d+h;j.css("position","relative"),j.css("top",k)}}).mouseup(function(){null!==j&&(j.attr("style",e),j.removeClass("dragged"),j=null,g!=f&&c())})}}});
\ No newline at end of file
define(["jquery"],function(a){return{makeOrderable:function(b,c){var d,e,f,g,h,i,j=null;b.find(".draghandle").mousedown(function(b){b.preventDefault(),d=b.pageY,i=a(this).closest("table"),(j=a(this).closest("tr")).addClass("dragged"),e=j.attr("style")||"",f=j.index(),g=f,h=0}),a(window).mousemove(function(a){if(null!==j){var b,c;a.preventDefault();var e=!1;if(g>0){var f=i.find("tbody tr:nth-child("+g+")");b=(2*f.offset().top+f.height()+j.height())/2,a.pageY<b&&(j.insertBefore(f),h+=f.height(),g--,e=!0)}if(g<i.find("tbody tr").length-1&&!e){var k=i.find("tbody tr:nth-child("+(g+2)+")");c=(2*k.offset().top+k.height()-j.height())/2,a.pageY>c&&(j.insertAfter(k),h-=k.height(),g++)}var l=a.pageY-d+h;j.css("position","relative"),j.css("top",l)}}).mouseup(function(){null!==j&&(j.attr("style",e),j.removeClass("dragged"),j=null,g!=f&&c())})}}});
\ No newline at end of file
......@@ -24,6 +24,8 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
/**
* Reads the table and updates the hidden form field accordingly.
* Also updates the table attributes and numbering if necessary.
* @param {jQuery} $table The table to read and update.
* @param {jQuery} $activities Hidden form field containing activities ids.
*/
function updateActivities($table, $activities) {
// In case the table is emptied, create a dummy empty row (and remove it if the table is filled).
......@@ -50,8 +52,9 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
/**
* Filters the activities in the "Add activities" window according to the filter function.
* @param filterfunction A function (cmid, cmtype, label) -> boolean
* returning whether the entry should be kept or not in the activities choice.
* @param {Function(Number, String, String, jQuery) : Boolean} filterfunction
* A function (cmid, cmtype, label, $activity) returning whether the entry should be kept or not
* in the activities choice.
*/
function filterActivitiesChoice(filterfunction) {
var noActivityToAdd = true;
......@@ -119,11 +122,11 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
var $confirmReassignDialog = $('#confirm-reassign').dialog({
autoOpen: false,
dialogClass: 'popup-dialog',
title: M.str.moodle.confirm,
title: M.util.get_string('confirm', 'moodle'),
modal: true,
buttons:
[{
text: M.str.moodle.confirm,
text: M.util.get_string('confirm', 'moodle'),
'class': 'btn btn-primary',
click: function() {
// The unloading of the page will not lose modifications, don't prompt the user anymore.
......@@ -132,7 +135,7 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
}
},
{
text: M.str.moodle.cancel,
text: M.util.get_string('cancel', 'moodle'),
'class': 'btn btn-secondary',
click: function() {
$(this).dialog('close');
......@@ -145,7 +148,7 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
// Button "Apply changes and re-assign".
$('#apply-assign-button')
.attr('disabled','disabled')
.attr('disabled', 'disabled')
.click(function() {
$confirmReassignDialog.dialog('open');
});
......@@ -220,7 +223,7 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
modal: true,
buttons:
[{
text: M.str.mod_randomactivity.addselectedactivities,
text: M.util.get_string('addselectedactivities', 'mod_randomactivity'),
'class': 'btn btn-primary',
click: function() {
$('.activity-to-add').each(function() {
......@@ -234,7 +237,7 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
}
},
{
text: M.str.moodle.cancel,
text: M.util.get_string('cancel', 'moodle'),
'class': 'btn btn-secondary',
click: function() {
$(this).dialog('close');
......@@ -257,7 +260,6 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
// Expand all sections.
$('.activities-to-add-list .section').each(function() {
$(this).addClass('expanded');
$(this).find('i.fa').removeClass('fa-caret-right').addClass('fa-caret-down');
processSectionActivities($(this), function($activity) {
$activity.removeClass('in-collapsed-section');
});
......@@ -282,7 +284,7 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
filters.$selector.removeClass('collapsed').addClass('expanded');
// Compute width including scrollbar.
var dropdownwidth = filters.$dropdown.width() * 2 - filters.$dropdown.prop('clientWidth');
filters.$selectmenu.width( Math.max(dropdownwidth, filters.$selector.width()) );
filters.$selectmenu.width(Math.max(dropdownwidth, filters.$selector.width()));
} else {
filters.$selector.removeClass('expanded').addClass('collapsed');
filters.$selectmenu.width('');
......@@ -336,7 +338,7 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
};
// Select / Deselect all visible activities of a section.
$('.activities-to-add-list .section .btn-link').click(function(e) {
$('.activities-to-add-list .section .toggle-all').click(function(e) {
e.stopImmediatePropagation();
var action = $(this).data('action');
processSectionActivities($(this).parents('.section'), function($activity) {
......@@ -350,14 +352,12 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
$('.activities-to-add-list .section').click(function() {
if ($(this).is('.expanded')) {
$(this).removeClass('expanded');
$(this).find('i.fa').removeClass('fa-caret-down').addClass('fa-caret-right');
processSectionActivities($(this), function($activity) {
$activity.hide();
$activity.addClass('in-collapsed-section');
});
} else {
$(this).addClass('expanded');
$(this).find('i.fa').removeClass('fa-caret-right').addClass('fa-caret-down');
processSectionActivities($(this), function($activity) {
$activity.removeClass('in-collapsed-section');
});
......
......@@ -26,8 +26,8 @@ define(['jquery'], function($) {
* Rows need to have at least one element with class 'draghandle' to be used as a handle.
* The table in which the drag-and-drop occurs is computed dynamically, so cloning rows from a table
* into another one will make them orderable in the latter.
* @param $tables JQuery set of tables to make orderable.
* @param onChange A function to call every time row order is modified.
* @param {jQuery} $tables Set of tables to make orderable.
* @param {Function} onChange A function to call every time row order is modified.
*/
function makeOrderable($tables, onChange) {
var initialY;
......@@ -55,27 +55,25 @@ define(['jquery'], function($) {
event.preventDefault();
var toplimit, bottomlimit;
var justmoved = false;
if (currentIndex > 0) {
var $toprow = $table.find('tbody tr:nth-child(' + currentIndex + ')');
toplimit = ($toprow.offset().top * 2 + $toprow.height() + $rowBeingDragged.height()) / 2;
} else {
toplimit = Number.MIN_SAFE_INTEGER;
if (event.pageY < toplimit) {
$rowBeingDragged.insertBefore($toprow);
rowsHeightOffset += $toprow.height();
currentIndex--;
justmoved = true;
}
}
if (currentIndex < $table.find('tbody tr').length - 1) {
var $bottomrow = $table.find('tbody tr:nth-child(' + ( currentIndex + 2 ) + ')');
if (currentIndex < $table.find('tbody tr').length - 1 && !justmoved) {
var $bottomrow = $table.find('tbody tr:nth-child(' + (currentIndex + 2) + ')');
bottomlimit = ($bottomrow.offset().top * 2 + $bottomrow.height() - $rowBeingDragged.height()) / 2;
} else {
bottomlimit = Number.MAX_SAFE_INTEGER;
}
if (event.pageY < toplimit) {
$rowBeingDragged.insertBefore($toprow);
rowsHeightOffset += $toprow.height();
currentIndex --;
} else if (event.pageY > bottomlimit) {
$rowBeingDragged.insertAfter($bottomrow);
rowsHeightOffset -= $bottomrow.height();
currentIndex ++;
if (event.pageY > bottomlimit) {
$rowBeingDragged.insertAfter($bottomrow);
rowsHeightOffset -= $bottomrow.height();
currentIndex++;
}
}
var cssOffset = event.pageY - initialY + rowsHeightOffset;
......
......@@ -19,26 +19,26 @@
* @copyright Astor Bizard, 2020
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery'], function($){
define(['jquery'], function($) {
/**
* Makes an html table sortable by creating clickable column headers and arrows.
* @param tableid The id of the table to make sortable.
* @param nosortcols (optional) An array of column indexes to exclude.
* @param {String} tableid The id of the table to make sortable.
* @param {Number[]} nosortcols (optional) An array of column indexes to exclude.
* Negative indexes can be specified to exclude columns counting from the last.
* @param defaultsortcol (optional) The index of the column to sort by default.
* @param {Number} defaultsortcol (optional) The index of the column to sort by default.
* This index is computed after excluding columns. Negative indexes are allowed.
* @param nexcludedlines (optional) The number of lines to ignore at the end of the table.
* @param {Number} nexcludedlines (optional) The number of lines to ignore at the end of the table.
*/
function makeSortable(tableid, nosortcols=[], defaultsortcol, nexcludedlines=0){
function makeSortable(tableid, nosortcols = [], defaultsortcol, nexcludedlines = 0) {
var sortdirection;
if(defaultsortcol === null) {
if (defaultsortcol === null) {
defaultsortcol = undefined;
}
var table = $('#' + tableid + ' tbody');
var $ths = $('#' + tableid + ' thead th');
var nths = $ths.length;
$ths.each(function(){
$ths.each(function() {
// Create sorting arrows except for excluded columns.
var i = $ths.index(this);
if (nosortcols.indexOf(i) == -1 && nosortcols.indexOf(i - nths) == -1) {
......@@ -46,24 +46,22 @@ define(['jquery'], function($){
}
});
// Setup sort arrows / headers.
$('#' + tableid + ' thead .sortarrow').each(function(){
$('#' + tableid + ' thead .sortarrow').each(function() {
var $arrow = $(this);
var $th = $arrow.closest('th');
var icol = $ths.index($th);
$th.css('cursor','pointer').css('user-select','none').click(function(){
if(!$arrow.hasClass('sortarrow-active')){
$th.css('cursor', 'pointer').css('user-select', 'none').click(function() {
if (!$arrow.hasClass('sortarrow-active')) {
// Change of sorting column: remove old sorting column arrow and setup the new one.
$('i.sortarrow-active').removeClass('sortarrow-active fa-caret-down fa-caret-up');
$arrow.addClass('sortarrow-active fa-caret-down');
sortdirection = 1;
}
else {
} else {
// Change sorting direction and arrow display.
sortdirection = -sortdirection;
if (sortdirection == 1) {
$arrow.removeClass('fa-caret-up').addClass('fa-caret-down');
}
else {
} else {
$arrow.removeClass('fa-caret-down').addClass('fa-caret-up');
}
}
......@@ -71,9 +69,9 @@ define(['jquery'], function($){
var num = 1;
var rows = Array.from(table.children('tr'));
var endrows = rows.splice(-nexcludedlines, nexcludedlines);
rows.sort(function(a, b){
rows.sort(function(a, b) {
// Sort according to 'value' attributes or inner text.
var getCellValue = function(tr){
var getCellValue = function(tr) {
return $(tr).find('.cell.c' + icol + ' [value]').attr('value') || $(tr).find('.cell.c' + icol).text();
};
var v1 = getCellValue(a);
......@@ -81,11 +79,11 @@ define(['jquery'], function($){
return sortdirection *
(v1 !== '' && v2 !== '' && !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.toString().localeCompare(v2));
})
.forEach(function(tr){
.forEach(function(tr) {
// Renumber first column.
var $firstcol = $(tr).children('td').first();
$firstcol.find(':not(:empty)').addBack(':not(:empty)').each(function(){
if(/^[0-9]+$/.test($(this).html())){
$firstcol.find(':not(:empty)').addBack(':not(:empty)').each(function() {
if (/^[0-9]+$/.test($(this).html())) {
$(this).html(num);
}
});
......@@ -94,18 +92,18 @@ define(['jquery'], function($){
table.append(tr);
});
// Re-insert excluded rows at the end.
endrows.forEach(function(tr){
endrows.forEach(function(tr) {
table.append(tr);
});
});
// Do not sort upon click on header link.
$th.find('a').click(function(e){
$th.find('a').click(function(e) {
e.stopPropagation();
});
}).eq(defaultsortcol).click();
}
return {
makeSortable : makeSortable
makeSortable: makeSortable
};
});
\ No newline at end of file
......@@ -49,7 +49,7 @@ class backup_randomactivity_activity_task extends backup_activity_task {
* {@inheritdoc}
* @param string $content some HTML text that eventually contains URLs to the activity instance scripts
*/
static public function encode_content_links($content) {
public static function encode_content_links($content) {
$search = "/(\/mod\/randomactivity\/index.php\?id\=)([0-9]+)/";
$content = preg_replace ( $search, '$@RANDOMACTIVITYINDEX*$2@$', $content );
......
......@@ -47,14 +47,14 @@ class restore_randomactivity_activity_task extends restore_activity_task {
/**
* {@inheritdoc}
*/
static public function define_decode_contents() {
public static function define_decode_contents() {
return array();
}
/**
* {@inheritdoc}
*/
static public function define_decode_rules() {
public static function define_decode_rules() {
return array(
new restore_decode_rule ( 'RANDOMACTIVITYVIEW', '/mod/randomactivity/view.php?id=$1', 'course_module' ),
new restore_decode_rule ( 'RANDOMACTIVITYGRADES', '/mod/randomactivity/gradeslist.php?id=$1', 'course_module' ),
......@@ -65,7 +65,7 @@ class restore_randomactivity_activity_task extends restore_activity_task {
/**
* {@inheritdoc}
*/
static public function define_restore_log_rules() {
public static function define_restore_log_rules() {
return array();
}
}
\ No newline at end of file
......@@ -353,6 +353,7 @@ function randomactivity_get_fontawesome_icon_map() {
'mod_randomactivity:reassign' => 'fa-random',
'mod_randomactivity:edit' => 'fa-edit',
'mod_randomactivity:dropdown' => 'fa-caret-down',
'mod_randomactivity:dropdowncollapsed' => 'fa-caret-right',
'mod_randomactivity:search' => 'fa-search',
'mod_randomactivity:list' => 'fa-list-ul',
'mod_randomactivity:grades' => 'fa-check-square'
......
......@@ -125,6 +125,18 @@
cursor: default;
}
.path-mod-randomactivity .activities-to-add-list .section .dropdown-icon i.icon {
margin-right: 0;
}
.path-mod-randomactivity .activities-to-add-list .section.expanded .dropdown-icon.collapsed {
display: none;
}
.path-mod-randomactivity .activities-to-add-list .section:not(.expanded) .dropdown-icon.expanded {
display: none;
}
.path-mod-randomactivity .activity-selector-wrapper {
margin-bottom: .8em;
}
......@@ -209,11 +221,11 @@
}
.path-mod-randomactivity #activity-search.empty ~ .search-remove {
display:none;
display: none;
}
.path-mod-randomactivity #activity-search:not(.empty) ~ .search-icon {
display:none;
display: none;
}
.path-mod-randomactivity .activities-to-add-list,
......
......@@ -17,19 +17,34 @@
{{!
@template mod_randomactivity/activitiesform
Classes required for JS:
* load-icon
Data attributes required for JS:
* none
Context variables required for this template:
* id Course module ID.
* activities Space-separated list of course module IDs of current activities pool.
* seed Current seed.
* seedhelpbutton HTML fragment containing help button for seed.
* editmode Whether editing is turned on for the activities form.
Example context (json):
{
"id": "2",
"activities": "6 8 19",
"seed": "0",
"seedhelpbutton": "<a class="btn btn-link p-0"><i class="icon fa fa-question-circle text-info fa-fw"></i></a>",
"editmode": true
}
}}
<form id="form-randomactivity-activities" class="form-inline">
<input name="id" type="hidden" value="{{id}}">
<input name="activities" type="hidden" value="{{activities}}">
<div id="form-seed">
{{# str}} seed, mod_randomactivity {{/ str}}{{{seedhelpbutton}}}
<input name="seed" class="form-control" type="text" size="15" value={{seed}} autocomplete="off" {{^ editmode}}disabled="disabled"{{/ editmode}}>
<input name="seed" class="form-control" type="text" size="15" value="{{seed}}" autocomplete="off" {{^ editmode}}disabled="disabled"{{/ editmode}}>
{{# editmode}}
<div id="seed-controls">
<a id="seed-timestamp" href="#">{{# str}} seedtotimestamp, mod_randomactivity {{/ str}}</a>
......
......@@ -17,16 +17,64 @@
{{!
@template mod_randomactivity/addactivities
Classes required for JS:
* activity
* activityicon
* activities-to-add-list
* activity-to-add
* activity-type
* activity-type-dropdown
* activity-type-selected
* activity-type-selector
* collapsed
* expanded
* search-icon
* search-remove
* section
* toggle-all
Data attributes required for JS:
* data-action
* data-cmid
* data-cmtype
Context variables required for this template:
* moduletypes Activity modules types list.
* name Activity module type short name.
* icon Activity module type icon.
* fullname Activity module type full name.
* allactivities All compatible current course activity modules.
* allactivities All compatible current course activity modules, or section headers.
If this entry describes a section:
* issection true.
* sectionname Section name.
If this entry describes an activity module:
* cmid Course module ID.
* modname Activity module type short name.
* activity Activity displayable name. Can include icon.
* hiddentable HTML table containing the row for this activity, to be added to the main activities pool table.
Example context (json):
{
"moduletypes": [
{
"icon": "http:\/\/localhost\/theme\/image.php\/boost\/assign\/1617710167\/icon",
"fullname": "Assignment",
"name": "assign"
}
],
"allactivities": [
{
"issection": true,
"sectionname": "Topic 1"
},
{
"cmid": "7",
"modname": "assign",
"activity": "<span class="activity"><img class="activityicon" src="http:\/\/localhost\/theme\/image.php\/boost\/quiz\/1617710167\/icon"/>Exercise 1</span>",
"hiddentable": ""
}
]
}
}}
<div id="activities-choice">
<div>{{# str}} filters, mod_randomactivity {{/ str}}</div>
......@@ -60,9 +108,11 @@
{{/ issection}}
{{# issection}}
<div class="section expanded">
<i class="icon fa fa-fw fa-caret-down"></i>{{{ sectionname }}}
(<span class="btn-link" data-action="select">{{# str}} selectall {{/ str }}</span>)
(<span class="btn-link" data-action="deselect">{{# str}} deselectall {{/ str }}</span>)
<span class="dropdown-icon expanded">{{# pix}} dropdown, mod_randomactivity {{/ pix}}</span>
<span class="dropdown-icon collapsed">{{# pix}} dropdowncollapsed, mod_randomactivity {{/ pix}}</span>
{{{sectionname}}}
(<span class="btn-link toggle-all" data-action="select">{{# str}} selectall {{/ str}}</span>)
(<span class="btn-link toggle-all" data-action="deselect">{{# str}} deselectall {{/ str}}</span>)
</div>
{{/ issection}}
{{/ allactivities}}
......
......@@ -17,10 +17,23 @@
{{!
@template mod_randomactivity/navigationbuttons
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* id Course module ID.
* editmode Whether editing is turned on for the activities form.
* allowedit Whether editing can be turned on for the activities form.
Example context (json):
{
"id": "2",
"editmode": true,
"allowedit": true
}
}}
{{# editmode}}
<button id="add-activities" class="btn btn-secondary">
......
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