Commit 5605fcc4 authored by Astor Bizard's avatar Astor Bizard 🐕
Browse files

Minor refactor of some javascript.

parent 7dd426d9
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())}return{setup:function(){var b=a("#randomactivity-activities-table"),f=a("#form-randomactivity-activities"),g=f.find("[name=activities]"),h=f.find("[name=seed]");e(b,g),d.makeOrderable(a(".activitytable"),function(){e(b,g),f.change()}),a(".activitytable .removebutton").click(function(){a(this).closest("tr").remove(),e(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.util.get_string("confirm","moodle"),modal:!0,buttons:[{text:M.util.get_string("confirm","moodle"),class:"btn btn-primary",click:function(){window.removeEventListener("beforeunload",i),f.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(){k.dialog("open")}),a("#seed-timestamp").click(function(a){a.preventDefault(),h.val((new Date).getTime()),f.change()});var l=c.relativeUrl("/mod/randomactivity/ajax");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=f.find("[name=group]").val(),i=g.val(),j=0;""!=i&&(j=i.split(" ").length),a.ajax(l+"/balanceseed.json.php?id="+d+"&nactivities="+j+"&group="+e).done(function(a){a.success&&(h.val(a.response.seed),f.change())}).always(function(){h.removeAttr("disabled"),c.hide()})}),a(".refresh-assignees").click(function(){var c=f.find("[name=id]").val(),d=f.find("[name=group]").val(),e=g.val(),i=h.val();a.ajax(l+"/refresh.json.php?id="+c+"&activities="+e+"&seed="+i+"&group="+d).done(function(c){c.success&&b.find("tbody tr td:nth-child(3)").each(function(b){a(this).html(c.response.assignees[b])})})});var m={$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")},n=function(){var b=m.$selectedvalue.data("cmtype"),c=m.$search.val(),d=g.val().split(" "),e=!0;a(".activities-to-add-list .section").each(function(){var f=!0,g=a(this).is(".expanded");a(this).find(".activity-to-add").each(function(){var e=a(this).data("cmid"),h=a(this).data("cmtype"),i=a(this).find("label").text(),j=(!b||h==b)&&!d.includes(e+"")&&(""===c||i.toLowerCase().includes(c.toLowerCase()));j&&g?a(this).show():a(this).hide(),j&&(f=!1)}),f?a(this).hide():(e=!1,a(this).show())}),e?a("#no-activity-to-add-message").show():a("#no-activity-to-add-message").hide()},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,g),f.change()}},{text:M.util.get_string("cancel","moodle"),class:"btn btn-secondary",click:function(){a(this).dialog("close")}}],open:function(){a(":focus").blur(),a('.activity-to-add input[type="checkbox"]').prop("checked",!1),a(".activities-to-add-list .section").addClass("expanded"),a(".activities-to-add-list").scrollTop(0),m.$selectedvalue.html(a(".activity-type").first().html()).data("cmtype",""),m.$selector.removeClass("expanded").addClass("collapsed"),m.$selectmenu.width(""),m.$search.val("").keyup(),n()}});a("#add-activities").click(function(){o.dialog("open")}),m.$selectmenu.click(function(){if(m.$selector.toggleClass("collapsed expanded"),m.$selector.is(".expanded")){var a=2*m.$dropdown.width()-m.$dropdown.prop("clientWidth");m.$selectmenu.width(Math.max(a,m.$selector.width()))}else m.$selectmenu.width("")}),a(".activity-type").click(function(){m.$selectedvalue.html(a(this).html()).data("cmtype",a(this).data("cmtype")),n()}),m.$search.keyup(function(){a(this).toggleClass("empty",""===a(this).val()),n()}),a(".search-remove").click(function(){m.$search.val("").keyup()}),a(".search-icon").click(function(){m.$search.focus()}),a(".activities-to-add-list .section .toggle-all").click(function(b){b.stopImmediatePropagation(),a(this).parents(".section").find('.activity-to-add:visible input[type="checkbox"]').prop("checked","select"==a(this).data("action"))}),a(".activities-to-add-list .section-header").click(function(){a(this).parents(".section").toggleClass("expanded"),n()})}}});
\ 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())}return{setup:function(){var b=a("#randomactivity-activities-table"),f=a("#form-randomactivity-activities"),g=f.find("[name=activities]"),h=f.find("[name=seed]");e(b,g),d.makeOrderable(a(".activitytable"),function(){e(b,g),f.change()}),a(".activitytable .removebutton").click(function(){a(this).closest("tr").remove(),e(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.util.get_string("confirm","moodle"),modal:!0,buttons:[{text:M.util.get_string("confirm","moodle"),class:"btn btn-primary",click:function(){window.removeEventListener("beforeunload",i),f.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(){k.dialog("open")}),a("#seed-timestamp").click(function(a){a.preventDefault(),h.val((new Date).getTime()),f.change()});var l=c.relativeUrl("/mod/randomactivity/ajax");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=f.find("[name=group]").val(),i=g.val(),j=0;""!=i&&(j=i.split(" ").length),a.ajax(l+"/balanceseed.json.php?id="+d+"&nactivities="+j+"&group="+e).done(function(a){a.success&&(h.val(a.response.seed),f.change())}).always(function(){h.removeAttr("disabled"),c.hide()})}),a(".refresh-assignees").click(function(){var c=f.find("[name=id]").val(),d=f.find("[name=group]").val(),e=g.val(),i=h.val();a.ajax(l+"/refresh.json.php?id="+c+"&activities="+e+"&seed="+i+"&group="+d).done(function(c){c.success&&b.find("tbody tr td:nth-child(3)").each(function(b){a(this).html(c.response.assignees[b])})})});var m={$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")},n=function(){var b=m.$selectedvalue.data("cmtype"),c=m.$search.val(),d=g.val().split(" "),e=!0;a(".activities-to-add-list .section").each(function(){var f=!0,g=a(this).is(".expanded");a(this).find(".activity-to-add").each(function(){var e=a(this).data("cmid"),h=a(this).data("cmtype"),i=a(this).find("label").text(),j=(!b||h==b)&&!d.includes(e+"")&&(""===c||i.toLowerCase().includes(c.toLowerCase()));a(this).toggle(j&&g),j&&(f=!1)}),f?a(this).hide():(e=!1,a(this).show())}),a("#no-activity-to-add-message").toggle(e)},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,g),f.change()}},{text:M.util.get_string("cancel","moodle"),class:"btn btn-secondary",click:function(){a(this).dialog("close")}}],open:function(){a(":focus").blur(),a('.activity-to-add input[type="checkbox"]').prop("checked",!1),a(".activities-to-add-list .section").addClass("expanded"),a(".activities-to-add-list").scrollTop(0),m.$selectedvalue.html(a(".activity-type").first().html()).data("cmtype",""),m.$selector.removeClass("expanded").addClass("collapsed"),m.$selectmenu.width(""),m.$search.val("").keyup(),n()}});a("#add-activities").click(function(){o.dialog("open")}),m.$selectmenu.click(function(){if(m.$selector.toggleClass("collapsed expanded"),m.$selector.is(".expanded")){var a=2*m.$dropdown.width()-m.$dropdown.prop("clientWidth");m.$selectmenu.width(Math.max(a,m.$selector.width()))}else m.$selectmenu.width("")}),a(".activity-type").click(function(){m.$selectedvalue.html(a(this).html()).data("cmtype",a(this).data("cmtype")),n()}),m.$search.keyup(function(){a(this).toggleClass("empty",""===a(this).val()),n()}),a(".search-remove").click(function(){m.$search.val("").keyup()}),a(".search-icon").click(function(){m.$search.focus()}),a(".activities-to-add-list .section .toggle-all").click(function(b){b.stopImmediatePropagation(),a(this).parents(".section").find('.activity-to-add:visible input[type="checkbox"]').prop("checked","select"==a(this).data("action"))}),a(".activities-to-add-list .section-header").click(function(){a(this).parents(".section").toggleClass("expanded"),n()})}}});
\ No newline at end of file
define(["jquery"],function(a){return{makeSortable:function(b,c=[],d,e=0){var f;null===d&&(d=void 0);var g=a("#"+b+" tbody"),h=a("#"+b+" thead th"),i=h.length;h.each(function(){var b=h.index(this);-1==c.indexOf(b)&&-1==c.indexOf(b-i)&&a(this).append('<i class="icon fa fa-fw sortarrow"></i>')}),a("#"+b+" thead .sortarrow").each(function(){var b=a(this),c=b.closest("th"),d=h.index(c);c.css("cursor","pointer").css("user-select","none").click(function(){b.hasClass("sortarrow-active")?1==(f=-f)?b.removeClass("fa-caret-up").addClass("fa-caret-down"):b.removeClass("fa-caret-down").addClass("fa-caret-up"):(a("i.sortarrow-active").removeClass("sortarrow-active fa-caret-down fa-caret-up"),b.addClass("sortarrow-active fa-caret-down"),f=1);var c=1,h=Array.from(g.children("tr")),i=h.splice(-e,e);h.sort(function(b,c){var e=function(b){return a(b).find(".cell.c"+d+" [value]").attr("value")||a(b).find(".cell.c"+d).text()},g=e(b),h=e(c);return f*(""===g||""===h||isNaN(g)||isNaN(h)?g.toString().localeCompare(h):g-h)}).forEach(function(b){a(b).children("td").first().find(":not(:empty)").addBack(":not(:empty)").each(function(){/^[0-9]+$/.test(a(this).html())&&a(this).html(c)}),c++,g.append(b)}),i.forEach(function(a){g.append(a)})}),c.find("a").click(function(a){a.stopPropagation()})}).eq(d).click()}}});
\ No newline at end of file
define(["jquery"],function(a){return{makeSortable:function(b,c=[],d,e=0){var f;null===d&&(d=void 0);var g=a("#"+b+" tbody"),h=a("#"+b+" thead th"),i=h.length;h.each(function(){var b=h.index(this);-1==c.indexOf(b)&&-1==c.indexOf(b-i)&&a(this).append('<i class="icon fa fa-fw sortarrow"></i>')}),a("#"+b+" thead .sortarrow").each(function(){var b=a(this),c=b.closest("th"),d=h.index(c);c.css("cursor","pointer").css("user-select","none").click(function(){b.hasClass("sortarrow-active")?(f=-f,b.toggleClass("fa-caret-up",1!=f).toggleClass("fa-caret-down",1==f)):(a("i.sortarrow-active").removeClass("sortarrow-active fa-caret-down fa-caret-up"),b.addClass("sortarrow-active fa-caret-down"),f=1);var c=1,h=Array.from(g.children("tr")),i=h.splice(-e,e);h.sort(function(b,c){var e=function(b){return a(b).find(".cell.c"+d+" [value]").attr("value")||a(b).find(".cell.c"+d).text()},g=e(b),h=e(c);return f*(""===g||""===h||isNaN(g)||isNaN(h)?g.toString().localeCompare(h):g-h)}).forEach(function(b){a(b).children("td").first().find(":not(:empty)").addBack(":not(:empty)").each(function(){/^[0-9]+$/.test(a(this).html())&&a(this).html(c)}),c++,g.append(b)}),i.forEach(function(a){g.append(a)})}),c.find("a").click(function(a){a.stopPropagation()})}).eq(d).click()}}});
\ No newline at end of file
......@@ -214,11 +214,7 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
&& (name === '' || cmname.toLowerCase().includes(name.toLowerCase()));
// Show or hide activity according to filters.
if (isFilteredIn && isExpanded) {
$(this).show();
} else {
$(this).hide();
}
$(this).toggle(isFilteredIn && isExpanded);
if (isFilteredIn) {
noActivityToAddInSection = false;
......@@ -235,11 +231,7 @@ define(['jquery', 'jqueryui', 'core/url', 'mod_randomactivity/orderabletable'],
});
// If all sections are hidden, show a message.
if (noSectionToShow) {
$('#no-activity-to-add-message').show();
} else {
$('#no-activity-to-add-message').hide();
}
$('#no-activity-to-add-message').toggle(noSectionToShow);
};
// Activities addition dialog.
......
......@@ -59,11 +59,7 @@ define(['jquery'], function($) {
} else {
// Change sorting direction and arrow display.
sortdirection = -sortdirection;
if (sortdirection == 1) {
$arrow.removeClass('fa-caret-up').addClass('fa-caret-down');
} else {
$arrow.removeClass('fa-caret-down').addClass('fa-caret-up');
}
$arrow.toggleClass('fa-caret-up', sortdirection != 1).toggleClass('fa-caret-down', sortdirection == 1);
}
// Sort rows.
var num = 1;
......
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