b41323545f89f6fb92e3847d54539a4eea26c273
[moodle.git] / mod / forum / amd / build / local / grades / local / grader / user_picker.min.js
1 define ("mod_forum/local/grades/local/grader/user_picker",["exports","core/templates","./user_picker/selectors"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;b=d(b);c=d(c);function d(a){return a&&a.__esModule?a:{default:a}}function e(a){for(var b=1;b<arguments.length;b++){var c=null!=arguments[b]?arguments[b]:{},d=Object.keys(c);if("function"==typeof Object.getOwnPropertySymbols){d=d.concat(Object.getOwnPropertySymbols(c).filter(function(a){return Object.getOwnPropertyDescriptor(c,a).enumerable}))}d.forEach(function(b){f(a,b,c[b])})}return a}function f(a,b,c){if(b in a){Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0})}else{a[b]=c}return a}function g(a,b){return k(a)||j(a,b)||h()}function h(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function j(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g=a[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){c.push(h.value);if(b&&c.length===b)break}}catch(a){e=!0;f=a}finally{try{if(!d&&null!=g["return"])g["return"]()}finally{if(e)throw f}}return c}function k(a){if(Array.isArray(a))return a}function l(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){c(a);return}if(h.done){b(i)}else{Promise.resolve(i).then(d,e)}}function m(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){l(h,d,e,f,g,"next",a)}function g(a){l(h,d,e,f,g,"throw",a)}f(void 0)})}}function n(a,b){if(!(a instanceof b)){throw new TypeError("Cannot call a class as a function")}}function o(a,b){for(var c=0,d;c<b.length;c++){d=b[c];d.enumerable=d.enumerable||!1;d.configurable=!0;if("value"in d)d.writable=!0;Object.defineProperty(a,d.key,d)}}function p(a,b,c){if(b)o(a.prototype,b);if(c)o(a,c);return a}var q=function(){function a(b,c,d){n(this,a);this.userList=b;this.showUserCallback=c;this.preChangeUserCallback=d;this.currentUserIndex=0;this.render=this.render.bind(this);this.setUserId=this.setUserId.bind(this)}p(a,[{key:"setUserId",value:function setUserId(a){var b=this.userList.findIndex(function(b){return b.id===parseInt(a)});if(-1===b){throw Error("User with id ".concat(a," not found"))}this.currentUserIndex=b}},{key:"render",value:function(){var a=m(regeneratorRuntime.mark(function a(){var c,d,e;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:this.root=document.createElement("div");a.next=3;return this.renderNavigator();case 3:c=a.sent;d=c.html;e=c.js;b.default.replaceNodeContents(this.root,d,e);a.next=9;return this.showUser(this.currentUser);case 9:this.registerEventListeners();case 10:case"end":return a.stop();}}},a,this)}));return function render(){return a.apply(this,arguments)}}()},{key:"renderNavigator",value:function renderNavigator(){return b.default.renderForPromise("".concat("mod_forum/local/grades/local/grader","/user_picker"),{})}},{key:"renderUserChange",value:function renderUserChange(a){return b.default.renderForPromise("".concat("mod_forum/local/grades/local/grader","/user_picker/user"),a)}},{key:"showUser",value:function(){var a=m(regeneratorRuntime.mark(function a(d){var e,f,h,i,j,k;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:a.next=2;return Promise.all([this.renderUserChange(d),this.showUserCallback(d)]);case 2:e=a.sent;f=g(e,1);h=f[0];i=h.html;j=h.js;k=this.root.querySelector(c.default.regions.userRegion);b.default.replaceNodeContents(k,i,j);case 9:case"end":return a.stop();}}},a,this)}));return function showUser(){return a.apply(this,arguments)}}()},{key:"registerEventListeners",value:function registerEventListeners(){var a=this;this.root.addEventListener("click",function(){var b=m(regeneratorRuntime.mark(function b(d){var e;return regeneratorRuntime.wrap(function(b){while(1){switch(b.prev=b.next){case 0:e=d.target.closest(c.default.actions.changeUser);if(!e){b.next=7;break}b.next=4;return a.preChangeUserCallback(a.currentUser);case 4:a.updateIndex(parseInt(e.dataset.direction));b.next=7;return a.showUser(a.currentUser);case 7:case"end":return b.stop();}}},b)}));return function(){return b.apply(this,arguments)}}())}},{key:"updateIndex",value:function updateIndex(a){this.currentUserIndex+=a;if(0>this.currentUserIndex){this.currentUserIndex=this.userList.length-1}else if(this.currentUserIndex>this.userList.length-1){this.currentUserIndex=0}return this.currentUserIndex}},{key:"currentUser",get:function get(){return e({},this.userList[this.currentUserIndex],{total:this.userList.length,displayIndex:this.currentUserIndex+1})}},{key:"rootNode",get:function get(){return this.root}}]);return a}(),r=function(){var a=m(regeneratorRuntime.mark(function a(b,c,d){var e,f,g,h,i=arguments;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:e=3<i.length&&i[3]!==void 0?i[3]:{},f=e.initialUserId,g=void 0===f?null:f;h=new q(b,c,d);if(g){h.setUserId(g)}a.next=5;return h.render();case 5:return a.abrupt("return",h);case 6:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}();a.default=r;return a.default});
2 //# sourceMappingURL=user_picker.min.js.map