first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
/**
* Unified filter page JS module for the course participants page.
*
* @module tool_policy/acceptances_filter
* @copyright 2017 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define("tool_policy/acceptances_filter",["jquery","core/form-autocomplete","core/str","core/notification"],(function($,Autocomplete,Str,Notification){var SELECTORS_UNIFIED_FILTERS="#unified-filters";return{init:function(){!function(){M.util.js_pending("acceptances_filter_datasource"),Str.get_strings([{key:"filterplaceholder",component:"tool_policy"},{key:"nofiltersapplied",component:"tool_policy"}]).done((function(langstrings){var placeholder=langstrings[0],noSelectionString=langstrings[1];Autocomplete.enhance(SELECTORS_UNIFIED_FILTERS,!0,"tool_policy/acceptances_filter_datasource",placeholder,!1,!0,noSelectionString,!0).then((function(){M.util.js_complete("acceptances_filter_datasource")})).fail(Notification.exception)})).fail(Notification.exception);var last=$(SELECTORS_UNIFIED_FILTERS).val();$(SELECTORS_UNIFIED_FILTERS).on("change",(function(){var current=$(this).val(),listoffilters=[],textfilters=[],updatedselectedfilters=!1;if($.each(current,(function(index,catoption){var catandoption=catoption.split(":",2);if(2!==catandoption.length)return textfilters.push(catoption),!0;var category=catandoption[0],option=catandoption[1];return void 0!==listoffilters[category]&&(updatedselectedfilters=!0),listoffilters[category]=option,!0})),updatedselectedfilters){var updatefilters=[];for(var category in listoffilters)updatefilters.push(category+":"+listoffilters[category]);updatefilters=updatefilters.concat(textfilters),$(this).val(updatefilters)}last.join(",")!=current.join(",")&&this.form.submit()}))}()},getForm:function(){return $(SELECTORS_UNIFIED_FILTERS).closest("form")}}}));
//# sourceMappingURL=acceptances_filter.min.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
/**
* Datasource for the tool_policy/acceptances_filter.
*
* This module is compatible with core/form-autocomplete.
*
* @copyright 2017 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define("tool_policy/acceptances_filter_datasource",["jquery","core/ajax","core/notification"],(function($,Ajax,Notification){return{list:function(selector,query){var filteredOptions=[],el=$(selector),originalOptions=$(selector).data("originaloptionsjson"),selectedFilters=el.val();$.each(originalOptions,(function(index,option){return""!==query.trim()&&-1===option.label.toLocaleLowerCase().indexOf(query.toLocaleLowerCase())||$.inArray(option.value,selectedFilters)>-1||filteredOptions.push(option),!0}));var deferred=new $.Deferred;return deferred.resolve(filteredOptions),deferred.promise()},processResults:function(selector,results){var options=[];return $.each(results,(function(index,data){options.push({value:data.value,label:data.label})})),options},transport:function(selector,query,callback){this.list(selector,query).then(callback).catch(Notification.exception)}}}));
//# sourceMappingURL=acceptances_filter_datasource.min.js.map
@@ -0,0 +1 @@
{"version":3,"file":"acceptances_filter_datasource.min.js","sources":["../src/acceptances_filter_datasource.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Datasource for the tool_policy/acceptances_filter.\n *\n * This module is compatible with core/form-autocomplete.\n *\n * @copyright 2017 Jun Pataleta\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notification) {\n\n return /** @alias module:tool_policy/acceptances_filter_datasource */ {\n /**\n * List filter options.\n *\n * @param {String} selector The select element selector.\n * @param {String} query The query string.\n * @return {Promise}\n */\n list: function(selector, query) {\n var filteredOptions = [];\n\n var el = $(selector);\n var originalOptions = $(selector).data('originaloptionsjson');\n var selectedFilters = el.val();\n $.each(originalOptions, function(index, option) {\n // Skip option if it does not contain the query string.\n if (query.trim() !== '' && option.label.toLocaleLowerCase().indexOf(query.toLocaleLowerCase()) === -1) {\n return true;\n }\n // Skip filters that have already been selected.\n if ($.inArray(option.value, selectedFilters) > -1) {\n return true;\n }\n\n filteredOptions.push(option);\n return true;\n });\n\n var deferred = new $.Deferred();\n deferred.resolve(filteredOptions);\n\n return deferred.promise();\n },\n\n /**\n * Process the results for auto complete elements.\n *\n * @param {String} selector The selector of the auto complete element.\n * @param {Array} results An array or results.\n * @return {Array} New array of results.\n */\n processResults: function(selector, results) {\n var options = [];\n $.each(results, function(index, data) {\n options.push({\n value: data.value,\n label: data.label\n });\n });\n return options;\n },\n\n /**\n * Source of data for Ajax element.\n *\n * @param {String} selector The selector of the auto complete element.\n * @param {String} query The query string.\n * @param {Function} callback A callback function receiving an array of results.\n */\n /* eslint-disable promise/no-callback-in-promise */\n transport: function(selector, query, callback) {\n this.list(selector, query).then(callback).catch(Notification.exception);\n }\n };\n\n});\n"],"names":["define","$","Ajax","Notification","list","selector","query","filteredOptions","el","originalOptions","data","selectedFilters","val","each","index","option","trim","label","toLocaleLowerCase","indexOf","inArray","value","push","deferred","Deferred","resolve","promise","processResults","results","options","transport","callback","then","catch","exception"],"mappings":";;;;;;;;AAwBAA,mDAAO,CAAC,SAAU,YAAa,sBAAsB,SAASC,EAAGC,KAAMC,oBAEG,CAQlEC,KAAM,SAASC,SAAUC,WACjBC,gBAAkB,GAElBC,GAAKP,EAAEI,UACPI,gBAAkBR,EAAEI,UAAUK,KAAK,uBACnCC,gBAAkBH,GAAGI,MACzBX,EAAEY,KAAKJ,iBAAiB,SAASK,MAAOC,cAEf,KAAjBT,MAAMU,SAA0F,IAAzED,OAAOE,MAAMC,oBAAoBC,QAAQb,MAAMY,sBAItEjB,EAAEmB,QAAQL,OAAOM,MAAOV,kBAAoB,GAIhDJ,gBAAgBe,KAAKP,SAPV,SAWXQ,SAAW,IAAItB,EAAEuB,gBACrBD,SAASE,QAAQlB,iBAEVgB,SAASG,WAUpBC,eAAgB,SAAStB,SAAUuB,aAC3BC,QAAU,UACd5B,EAAEY,KAAKe,SAAS,SAASd,MAAOJ,MAC5BmB,QAAQP,KAAK,CACTD,MAAOX,KAAKW,MACZJ,MAAOP,KAAKO,WAGbY,SAWXC,UAAW,SAASzB,SAAUC,MAAOyB,eAC5B3B,KAAKC,SAAUC,OAAO0B,KAAKD,UAAUE,MAAM9B,aAAa+B"}
+10
View File
@@ -0,0 +1,10 @@
/**
* Add policy consent modal to the page
*
* @module tool_policy/acceptmodal
* @copyright 2018 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define("tool_policy/acceptmodal",["jquery","core/str","core/modal_save_cancel","core/modal_events","core/notification","core/fragment","core/ajax","core_form/changechecker"],(function($,Str,ModalSaveCancel,ModalEvents,Notification,Fragment,Ajax,FormChangeChecker){var AcceptOnBehalf=function(contextid){this.contextid=contextid,this.init()};return AcceptOnBehalf.prototype.modal=null,AcceptOnBehalf.prototype.contextid=-1,AcceptOnBehalf.prototype.currentTrigger=null,AcceptOnBehalf.prototype.triggers={SINGLE:"a[data-action=acceptmodal]",BULK:"input[data-action=acceptmodal]"},AcceptOnBehalf.prototype.init=function(){$(this.triggers.SINGLE).on("click",function(e){e.preventDefault(),this.currentTrigger=$(e.currentTarget);var href=$(e.currentTarget).attr("href"),formData=href.slice(href.indexOf("?")+1);this.showFormModal(formData)}.bind(this)),$(this.triggers.BULK).on("click",function(e){e.preventDefault(),this.currentTrigger=$(e.currentTarget);var form=$(e.currentTarget).closest("form");if(form.find('input[type=checkbox][name="userids[]"]:checked').length){var formData=form.serialize();this.showFormModal(formData)}else Str.get_strings([{key:"notice"},{key:"selectusersforconsent",component:"tool_policy"},{key:"ok"}]).then((function(strings){Notification.alert(strings[0],strings[1],strings[2])})).fail(Notification.exception)}.bind(this))},AcceptOnBehalf.prototype.showFormModal=function(formData){for(var action,params=formData.split("&"),i=0;i<params.length;i++){var pair=params[i].split("=");"action"==pair[0]&&(action=pair[1])}Str.get_strings([{key:"statusformtitleaccept",component:"tool_policy"},{key:"iagreetothepolicy",component:"tool_policy"},{key:"statusformtitlerevoke",component:"tool_policy"},{key:"irevokethepolicy",component:"tool_policy"},{key:"statusformtitledecline",component:"tool_policy"},{key:"declinethepolicy",component:"tool_policy"}]).then(function(strings){var title,saveText;return"accept"==action?(title=strings[0],saveText=strings[1]):"revoke"==action?(title=strings[2],saveText=strings[3]):"decline"==action&&(title=strings[4],saveText=strings[5]),ModalSaveCancel.create({title:title,body:""}).then(function(modal){this.modal=modal,this.setupFormModal(formData,saveText)}.bind(this))}.bind(this)).catch(Notification.exception)},AcceptOnBehalf.prototype.setupFormModal=function(formData,saveText){var modal=this.modal;modal.setLarge(),modal.setSaveButtonText(saveText),modal.getRoot().on(ModalEvents.hidden,this.destroy.bind(this)),modal.setBody(this.getBody(formData)),modal.getRoot().on(ModalEvents.save,this.submitForm.bind(this)),modal.getRoot().on("submit","form",this.submitFormAjax.bind(this)),modal.show()},AcceptOnBehalf.prototype.getBody=function(formData){void 0===formData&&(formData={});var params={jsonformdata:JSON.stringify(formData)};return Fragment.loadFragment("tool_policy","accept_on_behalf",this.contextid,params)},AcceptOnBehalf.prototype.submitFormAjax=function(e){e.preventDefault();var formData=this.modal.getRoot().find("form").serialize();Ajax.call([{methodname:"tool_policy_submit_accept_on_behalf",args:{jsonformdata:JSON.stringify(formData)}}])[0].done(function(data){data.validationerrors?this.modal.setBody(this.getBody(formData)):this.close()}.bind(this)).fail(Notification.exception)},AcceptOnBehalf.prototype.submitForm=function(e){e.preventDefault(),this.modal.getRoot().find("form").submit()},AcceptOnBehalf.prototype.close=function(){this.destroy(),document.location.reload()},AcceptOnBehalf.prototype.destroy=function(){FormChangeChecker.resetAllFormDirtyStates(),this.modal.destroy(),this.currentTrigger.focus()},{getInstance:function(contextid){return new AcceptOnBehalf(contextid)}}}));
//# sourceMappingURL=acceptmodal.min.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
define("tool_policy/jquery-eu-cookie-law-popup",["jquery"],(function($){window.console||(window.console={}),window.console.log||(window.console.log=function(){}),$.fn.euCookieLawPopup=function(){var _self=this;_self.params={cookiePolicyUrl:"/?cookie-policy",popupPosition:"top",colorStyle:"default",compactStyle:!1,popupTitle:"This website is using cookies",popupText:"We use cookies to ensure that we give you the best experience on our website. If you continue without changing your settings, we'll assume that you are happy to receive all cookies on this website.",buttonContinueTitle:"Continue",buttonLearnmoreTitle:"Learn&nbsp;more",buttonLearnmoreOpenInNewWindow:!0,agreementExpiresInDays:30,autoAcceptCookiePolicy:!1,htmlMarkup:null},_self.vars={INITIALISED:!1,HTML_MARKUP:null,COOKIE_NAME:"EU_COOKIE_LAW_CONSENT"};var setUserAcceptsCookies=function(consent){var d=new Date,expiresInDays=24*_self.params.agreementExpiresInDays*60*60*1e3;d.setTime(d.getTime()+expiresInDays);var expires="expires="+d.toGMTString();document.cookie=_self.vars.COOKIE_NAME+"="+consent+"; "+expires+";path=/",$(document).trigger("user_cookie_consent_changed",{consent:consent})},hideContainer=function(){$(".eupopup-container").animate({opacity:0,height:0},200,(function(){$(".eupopup-container").hide(0)}))};return{init:function(settings){!function(object,markup,settings){if(object){var className=$(object).attr("class")?$(object).attr("class"):"";className.indexOf("eupopup-top")>-1?_self.params.popupPosition="top":className.indexOf("eupopup-fixedtop")>-1?_self.params.popupPosition="fixedtop":className.indexOf("eupopup-bottomright")>-1?_self.params.popupPosition="bottomright":className.indexOf("eupopup-bottomleft")>-1?_self.params.popupPosition="bottomleft":className.indexOf("eupopup-bottom")>-1?_self.params.popupPosition="bottom":className.indexOf("eupopup-block")>-1&&(_self.params.popupPosition="block"),className.indexOf("eupopup-color-default")>-1?_self.params.colorStyle="default":className.indexOf("eupopup-color-inverse")>-1&&(_self.params.colorStyle="inverse"),className.indexOf("eupopup-style-compact")>-1&&(_self.params.compactStyle=!0)}markup&&(_self.params.htmlMarkup=markup),settings&&(void 0!==settings.cookiePolicyUrl&&(_self.params.cookiePolicyUrl=settings.cookiePolicyUrl),void 0!==settings.popupPosition&&(_self.params.popupPosition=settings.popupPosition),void 0!==settings.colorStyle&&(_self.params.colorStyle=settings.colorStyle),void 0!==settings.popupTitle&&(_self.params.popupTitle=settings.popupTitle),void 0!==settings.popupText&&(_self.params.popupText=settings.popupText),void 0!==settings.buttonContinueTitle&&(_self.params.buttonContinueTitle=settings.buttonContinueTitle),void 0!==settings.buttonLearnmoreTitle&&(_self.params.buttonLearnmoreTitle=settings.buttonLearnmoreTitle),void 0!==settings.buttonLearnmoreOpenInNewWindow&&(_self.params.buttonLearnmoreOpenInNewWindow=settings.buttonLearnmoreOpenInNewWindow),void 0!==settings.agreementExpiresInDays&&(_self.params.agreementExpiresInDays=settings.agreementExpiresInDays),void 0!==settings.autoAcceptCookiePolicy&&(_self.params.autoAcceptCookiePolicy=settings.autoAcceptCookiePolicy),void 0!==settings.htmlMarkup&&(_self.params.htmlMarkup=settings.htmlMarkup))}($(".eupopup").first(),$(".eupopup-markup").html(),settings),function(){for(var userAcceptedCookies=!1,cookies=document.cookie.split(";"),i=0;i<cookies.length;i++){var c=cookies[i].trim();-1!==c.indexOf(_self.vars.COOKIE_NAME)&&(userAcceptedCookies=c.substring(_self.vars.COOKIE_NAME.length+1,c.length))}return userAcceptedCookies}()?$(document).trigger("user_cookie_already_accepted",{consent:!0}):_self.vars.INITIALISED||(_self.vars.INITIALISED=!0,_self.vars.HTML_MARKUP=_self.params.htmlMarkup?_self.params.htmlMarkup:'<div class="eupopup-container eupopup-container-'+_self.params.popupPosition+(_self.params.compactStyle?" eupopup-style-compact":"")+" eupopup-color-"+_self.params.colorStyle+'"><div class="eupopup-head">'+_self.params.popupTitle+'</div><div class="eupopup-body">'+_self.params.popupText+'</div><div class="eupopup-buttons"><a href="#" class="eupopup-button eupopup-button_1">'+_self.params.buttonContinueTitle+'</a><a href="'+_self.params.cookiePolicyUrl+'"'+(_self.params.buttonLearnmoreOpenInNewWindow?" target=_blank ":"")+' class="eupopup-button eupopup-button_2">'+_self.params.buttonLearnmoreTitle+'</a><div class="clearfix"></div></div><a href="#" class="eupopup-closebutton">x</a></div>',$(".eupopup-block").length>0?$(".eupopup-block").append(_self.vars.HTML_MARKUP):$("BODY").append(_self.vars.HTML_MARKUP),$(".eupopup-button_1").click((function(){return setUserAcceptsCookies(!0),hideContainer(),!1})),$(".eupopup-closebutton").click((function(){return setUserAcceptsCookies(!0),hideContainer(),!1})),$(".eupopup-container").show(),_self.params.autoAcceptCookiePolicy&&setUserAcceptsCookies(!0))}}}}));
//# sourceMappingURL=jquery-eu-cookie-law-popup.min.js.map
File diff suppressed because one or more lines are too long
+10
View File
@@ -0,0 +1,10 @@
/**
* Adds support for confirmation via JS modal for some management actions at the Manage policies page.
*
* @module tool_policy/managedocsactions
* @copyright 2018 David Mudrák <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define("tool_policy/managedocsactions",["jquery","core/log","core/config","core/str","core/modal_save_cancel","core/modal_events"],(function($,Log,Config,Str,ModalSaveCancel,ModalEvents){var ACTION_LINKS="[data-action]",ACTION_MAKE_CURRENT='[data-action="makecurrent"]',ACTION_INACTIVATE='[data-action="inactivate"]',ACTION_DELETE='[data-action="delete"]';function ManageDocsActions(base){this.base=base,this.initEvents()}return ManageDocsActions.prototype.initEvents=function(){this.base.on("click",ACTION_LINKS,(function(e){e.stopPropagation();var promise,strings,link=$(e.currentTarget);if(link.is(ACTION_MAKE_CURRENT))promise=Str.get_strings([{key:"activating",component:"tool_policy"},{key:"activateconfirm",component:"tool_policy",param:{name:link.closest("[data-policy-name]").attr("data-policy-name"),revision:link.closest("[data-policy-revision]").attr("data-policy-revision")}},{key:"activateconfirmyes",component:"tool_policy"}]);else if(link.is(ACTION_INACTIVATE))promise=Str.get_strings([{key:"inactivating",component:"tool_policy"},{key:"inactivatingconfirm",component:"tool_policy",param:{name:link.closest("[data-policy-name]").attr("data-policy-name"),revision:link.closest("[data-policy-revision]").attr("data-policy-revision")}},{key:"inactivatingconfirmyes",component:"tool_policy"}]);else{if(!link.is(ACTION_DELETE))return void Log.error("unknown action type detected","tool_policy/managedocsactions");promise=Str.get_strings([{key:"deleting",component:"tool_policy"},{key:"deleteconfirm",component:"tool_policy",param:{name:link.closest("[data-policy-name]").attr("data-policy-name"),revision:link.closest("[data-policy-revision]").attr("data-policy-revision")}},{key:"delete",component:"core"}])}e.preventDefault(),promise.then((function(strs){return strings=strs,ModalSaveCancel.create({title:strings[0],body:strings[1]})})).then((function(modal){return modal.setSaveButtonText(strings[2]),modal.getRoot().on(ModalEvents.save,(function(){window.location.href=link.attr("href")+"&sesskey="+Config.sesskey+"&confirm=1"})),modal.getRoot().on(ModalEvents.hidden,(function(){modal.destroy()})),modal.show(),!0})).catch((function(e){return Log.error(e),!1}))}))},{init:function(baseid){var base=$(document.getElementById(baseid));if(base.length)return new ManageDocsActions(base);throw new Error("managedocsactions: Invalid base element identifier")}}}));
//# sourceMappingURL=managedocsactions.min.js.map
File diff suppressed because one or more lines are too long
+10
View File
@@ -0,0 +1,10 @@
/**
* Policy actions.
*
* @module tool_policy/policyactions
* @copyright 2018 Sara Arjona (sara@moodle.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define("tool_policy/policyactions",["jquery","core/ajax","core/notification","core/modal"],(function($,Ajax,Notification,Modal){var PolicyActions=function(root){this.registerEvents(root)};return PolicyActions.prototype.registerEvents=function(root){root.on("click",(function(e){e.preventDefault();var request={methodname:"tool_policy_get_policy_version",args:{versionid:$(this).data("versionid"),behalfid:$(this).data("behalfid")}},modalTitle=$.Deferred(),modalBody=$.Deferred(),modal=Modal.create({title:modalTitle,body:modalBody,large:!0,removeOnClose:!0,show:!0}).catch(Notification.exception),promises=Ajax.call([request]);$.when(promises[0]).then((function(data){if(data.result.policy)return modalTitle.resolve(data.result.policy.name),modalBody.resolve(data.result.policy.content),data;throw new Error(data.warnings[0].message)})).catch((function(message){return modal.then((function(modal){return modal.hide(),modal})).catch(Notification.exception),Notification.addNotification({message:message,type:"error"})}))}))},{init:function(root){return root=$(root),new PolicyActions(root)}}}));
//# sourceMappingURL=policyactions.min.js.map
@@ -0,0 +1 @@
{"version":3,"file":"policyactions.min.js","sources":["../src/policyactions.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Policy actions.\n *\n * @module tool_policy/policyactions\n * @copyright 2018 Sara Arjona (sara@moodle.com)\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/ajax',\n 'core/notification',\n 'core/modal',\n], function($, Ajax, Notification, Modal) {\n\n /**\n * PolicyActions class.\n *\n * @param {jQuery} root\n */\n var PolicyActions = function(root) {\n this.registerEvents(root);\n };\n\n /**\n * Register event listeners.\n *\n * @param {jQuery} root\n */\n PolicyActions.prototype.registerEvents = function(root) {\n root.on(\"click\", function(e) {\n e.preventDefault();\n\n var versionid = $(this).data('versionid');\n var behalfid = $(this).data('behalfid');\n\n var params = {\n 'versionid': versionid,\n 'behalfid': behalfid\n };\n\n var request = {\n methodname: 'tool_policy_get_policy_version',\n args: params\n };\n\n var modalTitle = $.Deferred();\n var modalBody = $.Deferred();\n\n var modal = Modal.create({\n title: modalTitle,\n body: modalBody,\n large: true,\n removeOnClose: true,\n show: true,\n })\n .catch(Notification.exception);\n\n // Make the request now that the modal is configured.\n var promises = Ajax.call([request]);\n $.when(promises[0]).then(function(data) {\n if (data.result.policy) {\n modalTitle.resolve(data.result.policy.name);\n modalBody.resolve(data.result.policy.content);\n\n return data;\n } else {\n throw new Error(data.warnings[0].message);\n }\n }).catch(function(message) {\n modal.then(function(modal) {\n modal.hide();\n\n return modal;\n })\n .catch(Notification.exception);\n\n return Notification.addNotification({\n message: message,\n type: 'error'\n });\n });\n });\n\n };\n\n return /** @alias module:tool_policy/policyactions */ {\n // Public variables and functions.\n\n /**\n * Initialise the actions helper.\n *\n * @method init\n * @param {object} root\n * @return {PolicyActions}\n */\n 'init': function(root) {\n root = $(root);\n return new PolicyActions(root);\n }\n };\n});\n"],"names":["define","$","Ajax","Notification","Modal","PolicyActions","root","registerEvents","prototype","on","e","preventDefault","request","methodname","args","this","data","modalTitle","Deferred","modalBody","modal","create","title","body","large","removeOnClose","show","catch","exception","promises","call","when","then","result","policy","resolve","name","content","Error","warnings","message","hide","addNotification","type"],"mappings":";;;;;;;AAsBAA,mCAAO,CACH,SACA,YACA,oBACA,eACD,SAASC,EAAGC,KAAMC,aAAcC,WAO3BC,cAAgB,SAASC,WACpBC,eAAeD,cAQxBD,cAAcG,UAAUD,eAAiB,SAASD,MAC9CA,KAAKG,GAAG,SAAS,SAASC,GACtBA,EAAEC,qBAUEC,QAAU,CACVC,WAAY,iCACZC,KAPS,WAHGb,EAAEc,MAAMC,KAAK,sBACdf,EAAEc,MAAMC,KAAK,cAYxBC,WAAahB,EAAEiB,WACfC,UAAYlB,EAAEiB,WAEdE,MAAQhB,MAAMiB,OAAO,CACrBC,MAAOL,WACPM,KAAMJ,UACNK,OAAO,EACPC,eAAe,EACfC,MAAM,IAETC,MAAMxB,aAAayB,WAGhBC,SAAW3B,KAAK4B,KAAK,CAAClB,UAC1BX,EAAE8B,KAAKF,SAAS,IAAIG,MAAK,SAAShB,SAC1BA,KAAKiB,OAAOC,cACZjB,WAAWkB,QAAQnB,KAAKiB,OAAOC,OAAOE,MACtCjB,UAAUgB,QAAQnB,KAAKiB,OAAOC,OAAOG,SAE9BrB,WAED,IAAIsB,MAAMtB,KAAKuB,SAAS,GAAGC,YAEtCb,OAAM,SAASa,gBACdpB,MAAMY,MAAK,SAASZ,cAChBA,MAAMqB,OAECrB,SAEVO,MAAMxB,aAAayB,WAEbzB,aAAauC,gBAAgB,CAChCF,QAASA,QACTG,KAAM,iBAOgC,MAU1C,SAASrC,aACbA,KAAOL,EAAEK,MACF,IAAID,cAAcC"}
@@ -0,0 +1,143 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unified filter page JS module for the course participants page.
*
* @module tool_policy/acceptances_filter
* @copyright 2017 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'core/form-autocomplete', 'core/str', 'core/notification'],
function($, Autocomplete, Str, Notification) {
/**
* Selectors.
*
* @access private
* @type {{UNIFIED_FILTERS: string}}
*/
var SELECTORS = {
UNIFIED_FILTERS: '#unified-filters'
};
/**
* Init function.
*
* @method init
* @private
*/
var init = function() {
var stringkeys = [{
key: 'filterplaceholder',
component: 'tool_policy'
}, {
key: 'nofiltersapplied',
component: 'tool_policy'
}];
M.util.js_pending('acceptances_filter_datasource');
Str.get_strings(stringkeys).done(function(langstrings) {
var placeholder = langstrings[0];
var noSelectionString = langstrings[1];
Autocomplete.enhance(SELECTORS.UNIFIED_FILTERS, true, 'tool_policy/acceptances_filter_datasource', placeholder,
false, true, noSelectionString, true)
.then(function() {
M.util.js_complete('acceptances_filter_datasource');
return;
})
.fail(Notification.exception);
}).fail(Notification.exception);
var last = $(SELECTORS.UNIFIED_FILTERS).val();
$(SELECTORS.UNIFIED_FILTERS).on('change', function() {
var current = $(this).val();
var listoffilters = [];
var textfilters = [];
var updatedselectedfilters = false;
$.each(current, function(index, catoption) {
var catandoption = catoption.split(':', 2);
if (catandoption.length !== 2) {
textfilters.push(catoption);
return true; // Text search filter.
}
var category = catandoption[0];
var option = catandoption[1];
// The last option (eg. 'Teacher') out of a category (eg. 'Role') in this loop is the one that was last
// selected, so we want to use that if there are multiple options from the same category. Eg. The user
// may have chosen to filter by the 'Student' role, then wanted to filter by the 'Teacher' role - the
// last option in the category to be selected (in this case 'Teacher') will come last, so will overwrite
// 'Student' (after this if). We want to let the JS know that the filters have been updated.
if (typeof listoffilters[category] !== 'undefined') {
updatedselectedfilters = true;
}
listoffilters[category] = option;
return true;
});
// Check if we have something to remove from the list of filters.
if (updatedselectedfilters) {
// Go through and put the list into something we can use to update the list of filters.
var updatefilters = [];
for (var category in listoffilters) {
updatefilters.push(category + ":" + listoffilters[category]);
}
updatefilters = updatefilters.concat(textfilters);
$(this).val(updatefilters);
}
// Prevent form from submitting unnecessarily, eg. on blur when no filter is selected.
if (last.join(',') != current.join(',')) {
this.form.submit();
}
});
};
/**
* Return the unified user filter form.
*
* @method getForm
* @return {DOMElement}
*/
var getForm = function() {
return $(SELECTORS.UNIFIED_FILTERS).closest('form');
};
return /** @alias module:core/form-autocomplete */ {
/**
* Initialise the unified user filter.
*
* @method init
*/
init: function() {
init();
},
/**
* Return the unified user filter form.
*
* @method getForm
* @return {DOMElement}
*/
getForm: function() {
return getForm();
}
};
});
@@ -0,0 +1,92 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Datasource for the tool_policy/acceptances_filter.
*
* This module is compatible with core/form-autocomplete.
*
* @copyright 2017 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notification) {
return /** @alias module:tool_policy/acceptances_filter_datasource */ {
/**
* List filter options.
*
* @param {String} selector The select element selector.
* @param {String} query The query string.
* @return {Promise}
*/
list: function(selector, query) {
var filteredOptions = [];
var el = $(selector);
var originalOptions = $(selector).data('originaloptionsjson');
var selectedFilters = el.val();
$.each(originalOptions, function(index, option) {
// Skip option if it does not contain the query string.
if (query.trim() !== '' && option.label.toLocaleLowerCase().indexOf(query.toLocaleLowerCase()) === -1) {
return true;
}
// Skip filters that have already been selected.
if ($.inArray(option.value, selectedFilters) > -1) {
return true;
}
filteredOptions.push(option);
return true;
});
var deferred = new $.Deferred();
deferred.resolve(filteredOptions);
return deferred.promise();
},
/**
* Process the results for auto complete elements.
*
* @param {String} selector The selector of the auto complete element.
* @param {Array} results An array or results.
* @return {Array} New array of results.
*/
processResults: function(selector, results) {
var options = [];
$.each(results, function(index, data) {
options.push({
value: data.value,
label: data.label
});
});
return options;
},
/**
* Source of data for Ajax element.
*
* @param {String} selector The selector of the auto complete element.
* @param {String} query The query string.
* @param {Function} callback A callback function receiving an array of results.
*/
/* eslint-disable promise/no-callback-in-promise */
transport: function(selector, query, callback) {
this.list(selector, query).then(callback).catch(Notification.exception);
}
};
});
+280
View File
@@ -0,0 +1,280 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Add policy consent modal to the page
*
* @module tool_policy/acceptmodal
* @copyright 2018 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define([
'jquery',
'core/str',
'core/modal_save_cancel',
'core/modal_events',
'core/notification',
'core/fragment',
'core/ajax',
'core_form/changechecker',
], function(
$,
Str,
ModalSaveCancel,
ModalEvents,
Notification,
Fragment,
Ajax,
FormChangeChecker
) {
"use strict";
/**
* Constructor
*
* @param {int} contextid
*
* Each call to init gets it's own instance of this class.
*/
var AcceptOnBehalf = function(contextid) {
this.contextid = contextid;
this.init();
};
/**
* @var {Modal} modal
* @private
*/
AcceptOnBehalf.prototype.modal = null;
/**
* @var {int} contextid
* @private
*/
AcceptOnBehalf.prototype.contextid = -1;
/**
* @var {object} currentTrigger The triggered HTML jQuery object
* @private
*/
AcceptOnBehalf.prototype.currentTrigger = null;
/**
* @var {object} triggers The trigger selectors
* @private
*/
AcceptOnBehalf.prototype.triggers = {
SINGLE: 'a[data-action=acceptmodal]',
BULK: 'input[data-action=acceptmodal]'
};
/**
* Initialise the class.
*
* @private
*/
AcceptOnBehalf.prototype.init = function() {
// Initialise for links accepting policies for individual users.
$(this.triggers.SINGLE).on('click', function(e) {
e.preventDefault();
this.currentTrigger = $(e.currentTarget);
var href = $(e.currentTarget).attr('href'),
formData = href.slice(href.indexOf('?') + 1);
this.showFormModal(formData);
}.bind(this));
// Initialise for multiple users acceptance form.
$(this.triggers.BULK).on('click', function(e) {
e.preventDefault();
this.currentTrigger = $(e.currentTarget);
var form = $(e.currentTarget).closest('form');
if (form.find('input[type=checkbox][name="userids[]"]:checked').length) {
var formData = form.serialize();
this.showFormModal(formData);
} else {
Str.get_strings([
{key: 'notice'},
{key: 'selectusersforconsent', component: 'tool_policy'},
{key: 'ok'}
]).then(function(strings) {
Notification.alert(strings[0], strings[1], strings[2]);
return;
}).fail(Notification.exception);
}
}.bind(this));
};
/**
* Show modal with a form
*
* @param {String} formData
*/
AcceptOnBehalf.prototype.showFormModal = function(formData) {
var action;
var params = formData.split('&');
for (var i = 0; i < params.length; i++) {
var pair = params[i].split('=');
if (pair[0] == 'action') {
action = pair[1];
}
}
// Fetch the title string.
Str.get_strings([
{key: 'statusformtitleaccept', component: 'tool_policy'},
{key: 'iagreetothepolicy', component: 'tool_policy'},
{key: 'statusformtitlerevoke', component: 'tool_policy'},
{key: 'irevokethepolicy', component: 'tool_policy'},
{key: 'statusformtitledecline', component: 'tool_policy'},
{key: 'declinethepolicy', component: 'tool_policy'}
]).then(function(strings) {
var title;
var saveText;
if (action == 'accept') {
title = strings[0];
saveText = strings[1];
} else if (action == 'revoke') {
title = strings[2];
saveText = strings[3];
} else if (action == 'decline') {
title = strings[4];
saveText = strings[5];
}
// Create the modal.
return ModalSaveCancel.create({
title: title,
body: ''
}).then(function(modal) {
this.modal = modal;
this.setupFormModal(formData, saveText);
}.bind(this));
}.bind(this))
.catch(Notification.exception);
};
/**
* Setup form inside a modal
*
* @param {String} formData
* @param {String} saveText
*/
AcceptOnBehalf.prototype.setupFormModal = function(formData, saveText) {
var modal = this.modal;
modal.setLarge();
modal.setSaveButtonText(saveText);
// We want to reset the form every time it is opened.
modal.getRoot().on(ModalEvents.hidden, this.destroy.bind(this));
modal.setBody(this.getBody(formData));
// We catch the modal save event, and use it to submit the form inside the modal.
// Triggering a form submission will give JS validation scripts a chance to check for errors.
modal.getRoot().on(ModalEvents.save, this.submitForm.bind(this));
// We also catch the form submit event and use it to submit the form with ajax.
modal.getRoot().on('submit', 'form', this.submitFormAjax.bind(this));
modal.show();
};
/**
* Load the body of the modal (contains the form)
*
* @method getBody
* @private
* @param {String} formData
* @return {Promise}
*/
AcceptOnBehalf.prototype.getBody = function(formData) {
if (typeof formData === "undefined") {
formData = {};
}
// Get the content of the modal.
var params = {jsonformdata: JSON.stringify(formData)};
return Fragment.loadFragment('tool_policy', 'accept_on_behalf', this.contextid, params);
};
/**
* Submit the form inside the modal via AJAX request
*
* @method submitFormAjax
* @private
* @param {Event} e Form submission event.
*/
AcceptOnBehalf.prototype.submitFormAjax = function(e) {
// We don't want to do a real form submission.
e.preventDefault();
// Convert all the form elements values to a serialised string.
var formData = this.modal.getRoot().find('form').serialize();
var requests = Ajax.call([{
methodname: 'tool_policy_submit_accept_on_behalf',
args: {jsonformdata: JSON.stringify(formData)}
}]);
requests[0].done(function(data) {
if (data.validationerrors) {
this.modal.setBody(this.getBody(formData));
} else {
this.close();
}
}.bind(this)).fail(Notification.exception);
};
/**
* This triggers a form submission, so that any mform elements can do final tricks before the form submission is processed.
*
* @method submitForm
* @param {Event} e Form submission event.
* @private
*/
AcceptOnBehalf.prototype.submitForm = function(e) {
e.preventDefault();
this.modal.getRoot().find('form').submit();
};
/**
* Close the modal
*/
AcceptOnBehalf.prototype.close = function() {
this.destroy();
document.location.reload();
};
/**
* Destroy the modal
*/
AcceptOnBehalf.prototype.destroy = function() {
FormChangeChecker.resetAllFormDirtyStates();
this.modal.destroy();
this.currentTrigger.focus();
};
return /** @alias module:tool_policy/acceptmodal */ {
// Public variables and functions.
/**
* Attach event listeners to initialise this module.
*
* @method init
* @param {int} contextid The contextid for the course.
* @return {AcceptOnBehalf}
*/
getInstance: function(contextid) {
return new AcceptOnBehalf(contextid);
}
};
});
+252
View File
@@ -0,0 +1,252 @@
/**
*
* JQUERY EU COOKIE LAW POPUPS
* version 1.1.1
*
* Code on Github:
* https://github.com/wimagguc/jquery-eu-cookie-law-popup
*
* To see a live demo, go to:
* http://www.wimagguc.com/2018/05/gdpr-compliance-with-the-jquery-eu-cookie-law-plugin/
*
* by Richard Dancsi
* http://www.wimagguc.com/
*
*/
define(['jquery'], function($) {
// for ie9 doesn't support debug console >>>
if (!window.console) window.console = {};
if (!window.console.log) window.console.log = function () { };
// ^^^
$.fn.euCookieLawPopup = (function() {
var _self = this;
///////////////////////////////////////////////////////////////////////////////////////////////
// PARAMETERS (MODIFY THIS PART) //////////////////////////////////////////////////////////////
_self.params = {
cookiePolicyUrl : '/?cookie-policy',
popupPosition : 'top',
colorStyle : 'default',
compactStyle : false,
popupTitle : 'This website is using cookies',
popupText : 'We use cookies to ensure that we give you the best experience on our website. If you continue without changing your settings, we\'ll assume that you are happy to receive all cookies on this website.',
buttonContinueTitle : 'Continue',
buttonLearnmoreTitle : 'Learn&nbsp;more',
buttonLearnmoreOpenInNewWindow : true,
agreementExpiresInDays : 30,
autoAcceptCookiePolicy : false,
htmlMarkup : null
};
///////////////////////////////////////////////////////////////////////////////////////////////
// VARIABLES USED BY THE FUNCTION (DON'T MODIFY THIS PART) ////////////////////////////////////
_self.vars = {
INITIALISED : false,
HTML_MARKUP : null,
COOKIE_NAME : 'EU_COOKIE_LAW_CONSENT'
};
///////////////////////////////////////////////////////////////////////////////////////////////
// PRIVATE FUNCTIONS FOR MANIPULATING DATA ////////////////////////////////////////////////////
// Overwrite default parameters if any of those is present
var parseParameters = function(object, markup, settings) {
if (object) {
var className = $(object).attr('class') ? $(object).attr('class') : '';
if (className.indexOf('eupopup-top') > -1) {
_self.params.popupPosition = 'top';
}
else if (className.indexOf('eupopup-fixedtop') > -1) {
_self.params.popupPosition = 'fixedtop';
}
else if (className.indexOf('eupopup-bottomright') > -1) {
_self.params.popupPosition = 'bottomright';
}
else if (className.indexOf('eupopup-bottomleft') > -1) {
_self.params.popupPosition = 'bottomleft';
}
else if (className.indexOf('eupopup-bottom') > -1) {
_self.params.popupPosition = 'bottom';
}
else if (className.indexOf('eupopup-block') > -1) {
_self.params.popupPosition = 'block';
}
if (className.indexOf('eupopup-color-default') > -1) {
_self.params.colorStyle = 'default';
}
else if (className.indexOf('eupopup-color-inverse') > -1) {
_self.params.colorStyle = 'inverse';
}
if (className.indexOf('eupopup-style-compact') > -1) {
_self.params.compactStyle = true;
}
}
if (markup) {
_self.params.htmlMarkup = markup;
}
if (settings) {
if (typeof settings.cookiePolicyUrl !== 'undefined') {
_self.params.cookiePolicyUrl = settings.cookiePolicyUrl;
}
if (typeof settings.popupPosition !== 'undefined') {
_self.params.popupPosition = settings.popupPosition;
}
if (typeof settings.colorStyle !== 'undefined') {
_self.params.colorStyle = settings.colorStyle;
}
if (typeof settings.popupTitle !== 'undefined') {
_self.params.popupTitle = settings.popupTitle;
}
if (typeof settings.popupText !== 'undefined') {
_self.params.popupText = settings.popupText;
}
if (typeof settings.buttonContinueTitle !== 'undefined') {
_self.params.buttonContinueTitle = settings.buttonContinueTitle;
}
if (typeof settings.buttonLearnmoreTitle !== 'undefined') {
_self.params.buttonLearnmoreTitle = settings.buttonLearnmoreTitle;
}
if (typeof settings.buttonLearnmoreOpenInNewWindow !== 'undefined') {
_self.params.buttonLearnmoreOpenInNewWindow = settings.buttonLearnmoreOpenInNewWindow;
}
if (typeof settings.agreementExpiresInDays !== 'undefined') {
_self.params.agreementExpiresInDays = settings.agreementExpiresInDays;
}
if (typeof settings.autoAcceptCookiePolicy !== 'undefined') {
_self.params.autoAcceptCookiePolicy = settings.autoAcceptCookiePolicy;
}
if (typeof settings.htmlMarkup !== 'undefined') {
_self.params.htmlMarkup = settings.htmlMarkup;
}
}
};
var createHtmlMarkup = function() {
if (_self.params.htmlMarkup) {
return _self.params.htmlMarkup;
}
var html =
'<div class="eupopup-container' +
' eupopup-container-' + _self.params.popupPosition +
(_self.params.compactStyle ? ' eupopup-style-compact' : '') +
' eupopup-color-' + _self.params.colorStyle + '">' +
'<div class="eupopup-head">' + _self.params.popupTitle + '</div>' +
'<div class="eupopup-body">' + _self.params.popupText + '</div>' +
'<div class="eupopup-buttons">' +
'<a href="#" class="eupopup-button eupopup-button_1">' + _self.params.buttonContinueTitle + '</a>' +
'<a href="' + _self.params.cookiePolicyUrl + '"' +
(_self.params.buttonLearnmoreOpenInNewWindow ? ' target=_blank ' : '') +
' class="eupopup-button eupopup-button_2">' + _self.params.buttonLearnmoreTitle + '</a>' +
'<div class="clearfix"></div>' +
'</div>' +
'<a href="#" class="eupopup-closebutton">x</a>' +
'</div>';
return html;
};
// Storing the consent in a cookie
var setUserAcceptsCookies = function(consent) {
var d = new Date();
var expiresInDays = _self.params.agreementExpiresInDays * 24 * 60 * 60 * 1000;
d.setTime( d.getTime() + expiresInDays );
var expires = "expires=" + d.toGMTString();
document.cookie = _self.vars.COOKIE_NAME + '=' + consent + "; " + expires + ";path=/";
$(document).trigger("user_cookie_consent_changed", {'consent' : consent});
};
// Let's see if we have a consent cookie already
var userAlreadyAcceptedCookies = function() {
var userAcceptedCookies = false;
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var c = cookies[i].trim();
if (c.indexOf(_self.vars.COOKIE_NAME) !== -1) {
userAcceptedCookies = c.substring(_self.vars.COOKIE_NAME.length + 1, c.length);
}
}
return userAcceptedCookies;
};
var hideContainer = function() {
// $('.eupopup-container').slideUp(200);
$('.eupopup-container').animate({
opacity: 0,
height: 0
}, 200, function() {
$('.eupopup-container').hide(0);
});
};
///////////////////////////////////////////////////////////////////////////////////////////////
// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////
var publicfunc = {
// INITIALIZE EU COOKIE LAW POPUP /////////////////////////////////////////////////////////
init : function(settings) {
parseParameters(
$(".eupopup").first(),
$(".eupopup-markup").html(),
settings);
// No need to display this if user already accepted the policy
if (userAlreadyAcceptedCookies()) {
$(document).trigger("user_cookie_already_accepted", {'consent': true});
return;
}
// We should initialise only once
if (_self.vars.INITIALISED) {
return;
}
_self.vars.INITIALISED = true;
// Markup and event listeners >>>
_self.vars.HTML_MARKUP = createHtmlMarkup();
if ($('.eupopup-block').length > 0) {
$('.eupopup-block').append(_self.vars.HTML_MARKUP);
} else {
$('BODY').append(_self.vars.HTML_MARKUP);
}
$('.eupopup-button_1').click(function() {
setUserAcceptsCookies(true);
hideContainer();
return false;
});
$('.eupopup-closebutton').click(function() {
setUserAcceptsCookies(true);
hideContainer();
return false;
});
// ^^^ Markup and event listeners
// Ready to start!
$('.eupopup-container').show();
// In case it's alright to just display the message once
if (_self.params.autoAcceptCookiePolicy) {
setUserAcceptsCookies(true);
}
}
};
return publicfunc;
});
});
@@ -0,0 +1,152 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Adds support for confirmation via JS modal for some management actions at the Manage policies page.
*
* @module tool_policy/managedocsactions
* @copyright 2018 David Mudrák <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define([
'jquery',
'core/log',
'core/config',
'core/str',
'core/modal_save_cancel',
'core/modal_events'
], function($, Log, Config, Str, ModalSaveCancel, ModalEvents) {
"use strict";
/**
* List of action selectors.
*
* @property {string} LINKS - Selector for all action links
* @property {string} MAKE_CURRENT
*/
var ACTION = {
LINKS: '[data-action]',
MAKE_CURRENT: '[data-action="makecurrent"]',
INACTIVATE: '[data-action="inactivate"]',
DELETE: '[data-action="delete"]'
};
/**
* @constructor
* @param {Element} base - Management area wrapping element
*/
function ManageDocsActions(base) {
this.base = base;
this.initEvents();
}
/**
* Register event listeners.
*/
ManageDocsActions.prototype.initEvents = function() {
var self = this;
self.base.on('click', ACTION.LINKS, function(e) {
e.stopPropagation();
var link = $(e.currentTarget);
var promise;
var strings;
if (link.is(ACTION.MAKE_CURRENT)) {
promise = Str.get_strings([
{key: 'activating', component: 'tool_policy'},
{key: 'activateconfirm', component: 'tool_policy', param: {
name: link.closest('[data-policy-name]').attr('data-policy-name'),
revision: link.closest('[data-policy-revision]').attr('data-policy-revision')
}},
{key: 'activateconfirmyes', component: 'tool_policy'}
]);
} else if (link.is(ACTION.INACTIVATE)) {
promise = Str.get_strings([
{key: 'inactivating', component: 'tool_policy'},
{key: 'inactivatingconfirm', component: 'tool_policy', param: {
name: link.closest('[data-policy-name]').attr('data-policy-name'),
revision: link.closest('[data-policy-revision]').attr('data-policy-revision')
}},
{key: 'inactivatingconfirmyes', component: 'tool_policy'}
]);
} else if (link.is(ACTION.DELETE)) {
promise = Str.get_strings([
{key: 'deleting', component: 'tool_policy'},
{key: 'deleteconfirm', component: 'tool_policy', param: {
name: link.closest('[data-policy-name]').attr('data-policy-name'),
revision: link.closest('[data-policy-revision]').attr('data-policy-revision')
}},
{key: 'delete', component: 'core'}
]);
} else {
Log.error('unknown action type detected', 'tool_policy/managedocsactions');
return;
}
e.preventDefault();
promise.then(function(strs) {
strings = strs;
return ModalSaveCancel.create({
title: strings[0],
body: strings[1],
});
}).then(function(modal) {
modal.setSaveButtonText(strings[2]);
modal.getRoot().on(ModalEvents.save, function() {
window.location.href = link.attr('href') + '&sesskey=' + Config.sesskey + '&confirm=1';
});
modal.getRoot().on(ModalEvents.hidden, function() {
modal.destroy();
});
modal.show();
return true;
}).catch(function(e) {
Log.error(e);
return false;
});
});
};
return {
/**
* Factory method returning instance of the ManageDocsActions
*
* @param {String} baseid - ID of the management area wrapping element
* @return {ManageDocsActions}
*/
init: function(baseid) {
var base = $(document.getElementById(baseid));
if (base.length) {
return new ManageDocsActions(base);
} else {
throw new Error("managedocsactions: Invalid base element identifier");
}
}
};
});
+116
View File
@@ -0,0 +1,116 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Policy actions.
*
* @module tool_policy/policyactions
* @copyright 2018 Sara Arjona (sara@moodle.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define([
'jquery',
'core/ajax',
'core/notification',
'core/modal',
], function($, Ajax, Notification, Modal) {
/**
* PolicyActions class.
*
* @param {jQuery} root
*/
var PolicyActions = function(root) {
this.registerEvents(root);
};
/**
* Register event listeners.
*
* @param {jQuery} root
*/
PolicyActions.prototype.registerEvents = function(root) {
root.on("click", function(e) {
e.preventDefault();
var versionid = $(this).data('versionid');
var behalfid = $(this).data('behalfid');
var params = {
'versionid': versionid,
'behalfid': behalfid
};
var request = {
methodname: 'tool_policy_get_policy_version',
args: params
};
var modalTitle = $.Deferred();
var modalBody = $.Deferred();
var modal = Modal.create({
title: modalTitle,
body: modalBody,
large: true,
removeOnClose: true,
show: true,
})
.catch(Notification.exception);
// Make the request now that the modal is configured.
var promises = Ajax.call([request]);
$.when(promises[0]).then(function(data) {
if (data.result.policy) {
modalTitle.resolve(data.result.policy.name);
modalBody.resolve(data.result.policy.content);
return data;
} else {
throw new Error(data.warnings[0].message);
}
}).catch(function(message) {
modal.then(function(modal) {
modal.hide();
return modal;
})
.catch(Notification.exception);
return Notification.addNotification({
message: message,
type: 'error'
});
});
});
};
return /** @alias module:tool_policy/policyactions */ {
// Public variables and functions.
/**
* Initialise the actions helper.
*
* @method init
* @param {object} root
* @return {PolicyActions}
*/
'init': function(root) {
root = $(root);
return new PolicyActions(root);
}
};
});