AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"modfilter.min.js","sources":["../src/modfilter.js"],"sourcesContent":["/**\n * Handles filtering of items on download center page\n *\n * @module local_downloadcenter/modfilter\n * @author Simeon Naydenov (moniNaydenov@gmail.com)\n * @copyright 2022 Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org}\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * @module local_downloadcenter/modfilter\n */\ndefine(['jquery', 'core/str', 'core/url'], function($, Str, url) {\n\n const ModFilter = function(modnames) {\n\n const instance = this;\n this.modnames = modnames;\n this.strings = {};\n this.formid = null;\n this.currentlyshown = false;\n this.modlist = null;\n\n Str.get_strings([\n {key: 'all', component: 'moodle'},\n {key: 'none', component: 'moodle'},\n {key: 'select', component: 'moodle'},\n {key: 'showtypes', co
mponent: 'backup'},\n {key: 'hidetypes', component: 'backup'}\n ]).done(function(strs) {\n // Init strings.. new moodle super cool way...\n instance.strings['all'] = strs[0];\n instance.strings['none'] = strs[1];\n instance.strings['select'] = strs[2];\n instance.strings['showtypes'] = strs[3];\n instance.strings['hidetypes'] = strs[4];\n\n const firstsection = $('div[role=\"main\"] > form .card.block').first();\n instance.formid = firstsection.closest('form').prop('id');\n\n // Add global select all/none options.\n const showTypeOptionsLink = '<span class=\"font-weight-bold ml-3 text-nowrap\">' +\n '(<a id=\"downloadcenter-bytype\" href=\"#\">' + instance.strings['showtypes'] + '</a>)' + '</span>';\n let html = instance.html_generator('included', instance.strings['select']);\n let links = $(document.createElement('div'));\n links.addC
lass('grouped_settings section_level block card');\n links.html(html);\n links.find('.downloadcenter_selector .col-md-9').append(showTypeOptionsLink);\n\n links.insertBefore(firstsection);\n\n // For each module type on the course, add hidden select all/none options.\n instance.modlist = $(document.createElement('div'));\n instance.modlist.prop('id', 'mod_select_links');\n instance.modlist.prop('class', 'm-l-2');\n instance.modlist.appendTo(links);\n instance.modlist.hide();\n\n for (let mod in instance.modnames) {\n // Only include actual values from the list..\n if (!instance.modnames.hasOwnProperty(mod)) {\n continue;\n }\n\n const img = '<img src=\"' + url.imageUrl('icon', 'mod_' + mod) + '\" class=\"activityicon\" />';\n html = instance.html_generator('mod_' + mod, img + instance.modnames[mod]);\n
const modlinks = $(document.createElement('div'));\n modlinks.addClass('grouped_settings section_level');\n modlinks.html(html);\n modlinks.appendTo(instance.modlist);\n instance.initlinks(modlinks, mod);\n }\n\n // Attach events to links!\n $('#downloadcenter-all-included').click(function(e) { instance.helper(e, true, 'item_'); });\n $('#downloadcenter-none-included').click(function(e) { instance.helper(e, false, 'item_'); });\n $('#downloadcenter-bytype').click(function(e) { e.preventDefault(); instance.toggletypes(); });\n // Attach event to checkboxes!\n $('input.form-check-input').click(function() { instance.checkboxhandler($(this)); instance.updateFormState(); });\n });\n\n };\n\n ModFilter.prototype.checkboxhandler = function($checkbox) {\n const prefix = 'item_topic';\n const shortprefix = 'item_';\n const name = $checkbo
x.prop('name');\n const checked = $checkbox.prop('checked');\n if (name.substring(0, shortprefix.length) === shortprefix) {\n const $parent = $checkbox.parentsUntil('form', '.card');\n if (name.substring(0, prefix.length) === prefix) {\n $parent.find('input.form-check-input').prop('checked', checked);\n } else {\n if (checked) {\n $parent.find('input.form-check-input[name^=\"item_topic\"]').prop('checked', true);\n }\n }\n }\n };\n\n ModFilter.prototype.updateFormState = function() {\n // At this point, we really need to persuade the form we are part of to\n // update all of its disabledIf rules. However, as far as I can see,\n // given the way that lib/form/form.js is written, that is impossible.\n if (this.formid && M.form && M.form.updateFormState) {\n M.form.updateFormState(this.formid);\n }\n };\n\n // Toggles the displ
ay of the hidden module select all/none links.\n ModFilter.prototype.toggletypes = function() {\n // Change text of type toggle link.\n const link = $('#downloadcenter-bytype');\n if (this.currentlyshown) {\n link.text(this.strings['showtypes']);\n } else {\n link.text(this.strings['hidetypes']);\n }\n this.modlist.animate({height: 'toggle' }, 500, 'swing');\n\n this.currentlyshown = !this.currentlyshown;\n\n };\n\n ModFilter.prototype.initlinks = function(links, mod) {\n const instance = this;\n $('#downloadcenter-all-mod_' + mod).click(function(e) { instance.helper(e, true, 'item_', mod); });\n $('#downloadcenter-none-mod_' + mod).click(function(e) { instance.helper(e, false, 'item_', mod); });\n\n };\n\n ModFilter.prototype.helper = function(e, check, type, mod) {\n e.preventDefault();\n let prefix = '';\n if (typeof mod !== 'undefined') {\n prefix = 'item_' + mod + '_
';\n }\n\n const len = type.length;\n\n $('input[type=\"checkbox\"]').each(function(i, checkbox) {\n checkbox = $(checkbox);\n const name = checkbox.prop('name');\n\n // If a prefix has been set, ignore checkboxes which don't have that prefix.\n if (prefix && name.substring(0, prefix.length) !== prefix) {\n return;\n }\n if (name.substring(0, len) === type) {\n checkbox.prop('checked', check);\n }\n if (check) {\n checkbox.closest('.card.block').find('.form-group:first-child input').prop('checked', check);\n }\n });\n\n this.updateFormState();\n };\n\n ModFilter.prototype.html_generator = function(idtype, heading) {\n let links = '<a id=\"downloadcenter-all-' + idtype + '\" href=\"#\">' + this.strings['all'] + '</a> / ';\n links += '<a id=\"downloadcenter-none-' + idtype + '\" href=\"#\">' + this.strings['none']
+ '</a>';\n return this.row_generator(heading, links);\n };\n\n ModFilter.prototype.row_generator = function(heading, content) {\n let ret = '<div class=\"form-group row fitem downloadcenter_selector\">';\n ret += '<div class=\"col-md-3\"></div>';\n ret += '<div class=\"col-md-9\">';\n ret += '<label><span class=\"itemtitle\">' + heading + '</span></label>';\n ret += '<span class=\"text-nowrap\">' + content + '</span>';\n ret += '</div>';\n ret += '</div>';\n return ret;\n };\n\n return {\n init: function(modnames) {\n return new ModFilter(modnames);\n }\n };\n});\n"],"names":["define","$","Str","url","ModFilter","modnames","instance","this","strings","formid","currentlyshown","modlist","get_strings","key","component","done","strs","firstsection","first","closest","prop","showTypeOptionsLink","html","html_generator","links","document","createElement","addClass","find","append","insertBefore","appendTo","hid
e","mod","hasOwnProperty","img","imageUrl","modlinks","initlinks","click","e","helper","preventDefault","toggletypes","checkboxhandler","updateFormState","prototype","$checkbox","name","checked","substring","shortprefix","$parent","parentsUntil","prefix","M","form","link","text","animate","height","check","type","len","length","each","i","checkbox","idtype","heading","row_generator","content","ret","init"],"mappings":";;;;;;;;AAYAA,OAAO,iCAAA,CAAC,SAAU,WAAY,aAAa,SAASC,EAAGC,IAAKC,KAExD,MAAMC,UAAY,SAASC,UAEvB,MAAMC,SAAWC,KACjBA,KAAKF,SAAWA,SAChBE,KAAKC,QAAU,GACfD,KAAKE,OAAS,KACdF,KAAKG,gBAAiB,EACtBH,KAAKI,QAAU,KAEfT,IAAIU,YAAY,CACZ,CAACC,IAAK,MAAOC,UAAW,UACxB,CAACD,IAAK,OAAQC,UAAW,UACzB,CAACD,IAAK,SAAUC,UAAW,UAC3B,CAACD,IAAK,YAAaC,UAAW,UAC9B,CAACD,IAAK,YAAaC,UAAW,YAC/BC,MAAK,SAASC,MAEbV,SAASE,QAAa,IAAIQ,KAAK,GAC/BV,SAASE,QAAc,KAAIQ,KAAK,GAChCV,SAASE,QAAgB,OAAIQ,KAAK,GAClCV,SAASE,QAAmB,UAAIQ,KAAK,GACrCV,SAASE,QAAmB,UAAIQ,KAAK,GAErC,MAAMC,aAAehB,EAAE,uCAAuCiB,QAC9DZ,SAASG,OAASQ,aAAaE,QAAQ,QAAQC,KAAK,MAGpD,MAAMC
,oBAAsB,2FACqBf,SAASE,QAAmB,UADjD,eAE5B,IAAIc,KAAOhB,SAASiB,eAAe,WAAYjB,SAASE,QAAgB,QACpEgB,MAAQvB,EAAEwB,SAASC,cAAc,QACrCF,MAAMG,SAAS,6CACfH,MAAMF,KAAKA,MACXE,MAAMI,KAAK,sCAAsCC,OAAOR,qBAExDG,MAAMM,aAAab,cAGnBX,SAASK,QAAUV,EAAEwB,SAASC,cAAc,QAC5CpB,SAASK,QAAQS,KAAK,KAAM,oBAC5Bd,SAASK,QAAQS,KAAK,QAAS,SAC/Bd,SAASK,QAAQoB,SAASP,OAC1BlB,SAASK,QAAQqB,OAEjB,IAAK,IAAIC,OAAO3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