Commit 3a5404ef authored by Astor Bizard's avatar Astor Bizard
Browse files

Added by-section activities addition.

parent ffc60900
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
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
......@@ -56,7 +56,7 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
function filterActivitiesChoice(filterfunction) {
var noActivityToAdd = true;
$('.activity-to-add').each(function() {
if (filterfunction($(this).data('cmid'), $(this).data('cmtype'), $(this).find('label').text())) {
if (filterfunction($(this).data('cmid'), $(this).data('cmtype'), $(this).find('label').text(), $(this))) {
noActivityToAdd = false;
$(this).show();
} else {
......@@ -251,8 +251,15 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
// Uncheck all checkboxes.
$('.activity-to-add').each(function() {
$(this).find('input[type="checkbox"]').each(function() {
$(this).prop('checked', false);
$(this).find('input[type="checkbox"]').prop('checked', false);
});
// 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');
});
});
......@@ -287,10 +294,11 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
var type = filters.$selectedvalue.data('cmtype');
var name = filters.$search.val();
var currentActivities = $activities.val().split(' ');
filterActivitiesChoice(function(cmid, cmtype, cmname) {
filterActivitiesChoice(function(cmid, cmtype, cmname, $activity) {
return (!type || cmtype == type)
&& !currentActivities.includes(cmid + "")
&& (name === '' || cmname.toLowerCase().includes(name.toLowerCase()));
&& (name === '' || cmname.toLowerCase().includes(name.toLowerCase()))
&& !$activity.is('.in-collapsed-section');
});
};
......@@ -317,6 +325,45 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
$('.search-icon').click(function() {
filters.$search.focus();
});
// Loops over activities of given section. Calls process($activity) on each activity.
var processSectionActivities = function($section, process) {
var $activityinsection = $section.next();
while ($activityinsection.length > 0 && ! $activityinsection.is('.section')) {
process($activityinsection);
$activityinsection = $activityinsection.next();
}
};
// Select / Deselect all visible activities of a section.
$('.activities-to-add-list .section .btn-link').click(function(e) {
e.stopImmediatePropagation();
var action = $(this).data('action');
processSectionActivities($(this).parents('.section'), function($activity) {
if ($activity.is(':visible')) {
$activity.find('input[type="checkbox"]').prop('checked', (action == 'select'));
}
});
});
// Expand / Collapse a section.
$('.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');
});
filterActivitiesSearch();
}
});
}
return {
......
......@@ -121,6 +121,10 @@
text-overflow: ellipsis;
}
.path-mod-randomactivity .activities-to-add-list .section {
cursor: default;
}
.path-mod-randomactivity .activity-selector-wrapper {
margin-bottom: .8em;
}
......
......@@ -51,11 +51,20 @@
</div>
<div class="activities-to-add-list">
{{# allactivities}}
{{^ issection}}
<div class="activity-to-add" data-cmid="{{cmid}}" data-cmtype="{{modname}}">
<input type="checkbox" id="cm{{cmid}}"/>
<label for="cm{{cmid}}">{{{activity}}}</label>
{{{hiddentable}}}
</div>
{{/ 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>)
</div>
{{/ issection}}
{{/ allactivities}}
</div>
<span id="no-activity-to-add-message">{{# str}} noactivitytoadd, mod_randomactivity {{/ str}}</span>
......
......@@ -169,6 +169,7 @@ if ($editmode) {
$allactivities = array(); // List of all activities that can be added (and that are added, those will be hidden).
// Loop over all activities of the course.
$sectionnum = -1;
foreach (get_fast_modinfo($course, -1)->get_cms() as $cminfo) {
$fullname = (string)$cminfo->modfullname;
// Only the activities that can be added, ie. no randomactivity nor activities with no view page.
......@@ -180,6 +181,14 @@ if ($editmode) {
$modtypes[$fullname]->fullname = $fullname;
$modtypes[$fullname]->name = $cminfo->modname;
}
// Section.
if ($cminfo->sectionnum > $sectionnum) {
$section = new stdClass();
$section->issection = true;
$sectionnum = $cminfo->sectionnum;
$section->sectionname = get_section_name($course->id, $cminfo->sectionnum);
$allactivities[] = $section;
}
// Activity.
$activity = new stdClass();
$activity->cmid = $cminfo->id;
......
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