File: /var/www/html/ceade.tocsa.com.py/blocks/accessreview/amd/build/module.min.js
function _typeof(obj){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj},_typeof(obj)}define("block_accessreview/module",["exports","core/ajax","core/templates","core/notification"],(function(_exports,_ajax,Templates,_notification){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _slicedToArray(arr,i){return function(arr){if(Array.isArray(arr))return arr}(arr)||function(arr,i){var _i=null==arr?null:"undefined"!=typeof Symbol&&arr[Symbol.iterator]||arr["@@iterator"];if(null==_i)return;var _s,_e,_arr=[],_n=!0,_d=!1;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!i||_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{_n||null==_i.return||_i.return()}finally{if(_d)throw _e}}return _arr}(arr,i)||function(o,minLen){if(!o)return;if("string"==typeof o)return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);"Object"===n&&o.constructor&&(n=o.constructor.name);if("Map"===n||"Set"===n)return Array.from(o);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen)}(arr,i)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function _arrayLikeToArray(arr,len){(null==len||len>arr.length)&&(len=arr.length);for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,Templates=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!==_typeof(obj)&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(Templates);var toggleState=!0,renderTemplate=function(element,errorCount,checkCount,displayFormat,minViews,viewDelta){var weight=parseInt((errorCount-minViews)/viewDelta*2),context={resultPassed:!errorCount,classList:"",passRate:{errorCount:errorCount,checkCount:checkCount,failureRate:Math.round(errorCount/checkCount*100)}};if(!element)return Promise.resolve();var elementClassList=["block_accessreview"];context.resultPassed?elementClassList.push("block_accessreview_success"):weight?elementClassList.push("block_accessreview_danger"):elementClassList.push("block_accessreview_warning");var _element$classList,showIcons="showicons"==displayFormat||"showboth"==displayFormat,showBackground="showbackground"==displayFormat||"showboth"==displayFormat;return showBackground&&!showIcons?((_element$classList=element.classList).add.apply(_element$classList,elementClassList.concat(["alert"])),Promise.resolve()):(showIcons&&!showBackground&&(context.classList=elementClassList.join(" ")),Templates.renderForPromise("block_accessreview/status",context).then((function(_ref){var _element$classList2,html=_ref.html,js=_ref.js;(Templates.appendNodeContents(element,html,js),showBackground)&&(_element$classList2=element.classList).add.apply(_element$classList2,elementClassList.concat(["alert"]))})).catch())},showAccessMap=function(courseId,displayFormat){var updatePreference=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return Promise.all(fetchReviewData(courseId,updatePreference)).then((function(_ref2){var _document$querySelect,_document$querySelect2,_ref3=_slicedToArray(_ref2,2),sectionData=_ref3[0],moduleData=_ref3[1],_getErrorTotals=getErrorTotals(sectionData,moduleData),minViews=_getErrorTotals.minViews,viewDelta=_getErrorTotals.viewDelta;return sectionData.forEach((function(section){var element=document.querySelector("#section-".concat(section.section," .summary"));element&&renderTemplate(element,section.numerrors,section.numchecks,displayFormat,minViews,viewDelta)})),moduleData.forEach((function(module){var element=document.getElementById("module-".concat(module.cmid));element&&renderTemplate(element,module.numerrors,module.numchecks,displayFormat,minViews,viewDelta)})),(_document$querySelect=document.querySelector(".icon-accessmap").classList).remove.apply(_document$querySelect,["fa-eye-slash"]),(_document$querySelect2=document.querySelector(".icon-accessmap").classList).add.apply(_document$querySelect2,["fa-eye"]),{sectionData:sectionData,moduleData:moduleData}})).catch(_notification.exception)},toggleAccessMap=function(courseId,displayFormat){(toggleState=!toggleState)?showAccessMap(courseId,displayFormat,!0):function(){var _document$querySelect3,_document$querySelect4,updatePreference=arguments.length>0&&void 0!==arguments[0]&&arguments[0];document.querySelectorAll(".block_accessreview_view").forEach((function(node){return node.remove()}));var classList=["block_accessreview","block_accessreview_success","block_accessreview_warning","block_accessreview_danger","block_accessreview_view","alert"];document.querySelectorAll(".block_accessreview").forEach((function(node){var _node$classList;return(_node$classList=node.classList).remove.apply(_node$classList,classList)})),updatePreference&&setToggleStatePreference(!1),(_document$querySelect3=document.querySelector(".icon-accessmap").classList).remove.apply(_document$querySelect3,["fa-eye"]),(_document$querySelect4=document.querySelector(".icon-accessmap").classList).add.apply(_document$querySelect4,["fa-eye-slash"])}(!0)},getErrorTotals=function(sectionData,moduleData){var totals={totalErrors:0,totalUsers:0,minViews:0,maxViews:0,viewDelta:0};return[].concat(sectionData,moduleData).forEach((function(item){totals.totalErrors+=item.numerrors,item.numerrors<totals.minViews&&(totals.minViews=item.numerrors),item.numerrors>totals.maxViews&&(totals.maxViews=item.numerrors),totals.totalUsers+=item.numchecks})),totals.viewDelta=totals.maxViews-totals.minViews+1,totals},getTogglePreferenceParams=function(toggleState){return{methodname:"core_user_update_user_preferences",args:{preferences:[{type:"block_accessreviewtogglestate",value:toggleState}]}}},setToggleStatePreference=function(toggleState){return(0,_ajax.call)([getTogglePreferenceParams(toggleState)])},fetchReviewData=function(courseid){var updatePreference=arguments.length>1&&void 0!==arguments[1]&&arguments[1],calls=[{methodname:"block_accessreview_get_section_data",args:{courseid:courseid}},{methodname:"block_accessreview_get_module_data",args:{courseid:courseid}}];return updatePreference&&calls.push(getTogglePreferenceParams(!0)),(0,_ajax.call)(calls)};_exports.init=function(toggled,displayFormat,courseId){(toggleState=1==toggled)&&showAccessMap(courseId,displayFormat),function(courseId,displayFormat){document.addEventListener("click",(function(e){e.target.closest("#toggle-accessmap")&&(e.preventDefault(),toggleAccessMap(courseId,displayFormat))}))}(courseId,displayFormat)}}));
//# sourceMappingURL=module.min.js.map