You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1 lines
8.3 KiB

define(["jquery","core/notification","core/str","core/form-autocomplete","core/ajax","mod_assign/grading_form_change_checker"],function(a,b,c,d,e,f){var g=function(e){this._regionSelector=e,this._region=a(e),this._filters=[],this._users=[],this._filteredUsers=[],this._lastXofYUpdate=0,this._firstLoadUsers=!0,this._loadAllUsers(),this._region.find('[data-action="previous-user"]').on("click",this._handlePreviousUser.bind(this)),this._region.find('[data-action="next-user"]').on("click",this._handleNextUser.bind(this)),this._region.find('[data-action="change-user"]').on("change",this._handleChangeUser.bind(this)),this._region.find('[data-region="user-filters"]').on("click",this._toggleExpandFilters.bind(this)),a(document).on("user-changed",this._refreshSelector.bind(this)),a(document).on("done-saving-show-next",this._handleNextUser.bind(this));var f=this._region.find('[data-region="user-filters"]'),g=a(document.getElementById(f.attr("aria-controls")));g.on("change","select",this._filterChanged.bind(this));var h=a('[data-region="grading-navigation-panel"]').data("first-userid");h&&this._selectUserById(h),c.get_string("changeuser","mod_assign").done(function(a){d.enhance("[data-action=change-user]",!1,"mod_assign/participant_selector",a)}).fail(b.exception),a(document).bind("start-loading-user",function(){this._isLoading=!0}.bind(this)),a(document).bind("finish-loading-user",function(){this._isLoading=!1}.bind(this))};return g.prototype._isLoading=!1,g.prototype._regionSelector=null,g.prototype._filters=null,g.prototype._users=null,g.prototype._region=null,g.prototype._lastFilters="",g.prototype._loadAllUsers=function(){var a=this._region.find("[data-action=change-user]"),c=a.attr("data-assignmentid"),d=a.attr("data-groupid"),f=this._region.find('[data-region="configure-filters"]'),g=f.find('select[name="filter"]').val(),h=f.find('select[name="workflowfilter"]');h&&(g+=","+h.val());var i=f.find('select[name="markerfilter"]');return i&&(g+=","+i.val()),this._lastFilters!=g&&(this._lastFilters=g,e.call([{methodname:"mod_assign_list_participants",args:{assignid:c,groupid:d,filter:"",onlyids:!0,tablesort:!0},done:this._usersLoaded.bind(this),fail:b.exception}]),!0)},g.prototype._usersLoaded=function(b){if(this._firstLoadUsers=!1,this._filteredUsers=this._users=b,this._users.length){var c=this._region.find('[data-region="user-filters"]'),d=a(document.getElementById(c.attr("aria-controls")));d.find('select[name="filter"]').trigger("change")}else this._selectNoUser();this._triggerNextUserEvent()},g.prototype._checkClickOutsideConfigureFilters=function(b){var c=this._region.find('[data-region="configure-filters"]');if(!c.is(b.target)&&0===c.has(b.target).length){var d=this._region.find('[data-region="user-filters"]');c.hide(),c.attr("aria-hidden","true"),d.attr("aria-expanded","false"),a(document).unbind("click.mod_assign_grading_navigation")}},g.prototype._updateFilterPreferences=function(b,c,d){var f=[],g=0;if(0==c.length||this._firstLoadUsers){var h=a.Deferred();return h.resolve(),h}for(g=0;g<c.length;g++){var i=c[g];"none"==i&&(i=""),f.push({userid:b,name:d[g],value:i})}return e.call([{methodname:"core_user_set_user_preferences",args:{preferences:f}}])[0]},g.prototype._filterChanged=function(){var d=this._region.find('[data-region="configure-filters"]'),e=d.find("select");this._filters=[],e.each(function(b,c){this._filters.push(a(c).val())}.bind(this));var f=[];d.find("option:checked").each(function(b,c){f[f.length]=a(c).text()}),f.length?this._region.find('[data-region="user-filters"] span').text(f.join(", ")):c.get_string("nofilters","mod_assign").done(function(a){this._region.find('[data-region="user-filters"] span').text(a)}.bind(this)).fail(b.exception);var g=this._region.find("[data-action=change-user]"),h=g.data("currentuserid"),i=["assign_filter","assign_workflowfilter","assign_markerfilter"];this._updateFilterPreferences(h,this._filters,i).done(function(){if(!this._loadAllUsers()){var b=parseInt(g.attr("data-selected")),c=0;a.each(this._filteredUsers,function(a,d){b==d.id&&(c=a)}),this._filteredUsers.length?this._selectUserById(this._filteredUsers[c].id):this._selectNoUser()}}.bind(this)).fail(b.exception),this._refreshCount()},g.prototype._selectNoUser=function(){this._isLoading||(f.checkFormForChanges('[data-region="grade-panel"] .gradeform')?c.get_strings([{key:"unsavedchanges",component:"mod_assign"},{key:"unsavedchangesquestion",component:"mod_assign"},{key:"saveandcontinue",component:"mod_assign"},{key:"cancel",component:"core"}]).done(function(c){b.confirm(c[0],c[1],c[2],c[3],function(){a(document).trigger("save-changes",-1)})}):a(document).trigger("user-changed",-1))},g.prototype._selectUserById=function(d){var e=this._region.find("[data-action=change-user]"),g=parseInt(d,10);this._isLoading||(f.checkFormForChanges('[data-region="grade-panel"] .gradeform')?c.get_strings([{key:"unsavedchanges",component:"mod_assign"},{key:"unsavedchangesquestion",component:"mod_assign"},{key:"saveandcontinue",component:"mod_assign"},{key:"cancel",component:"core"}]).done(function(c){b.confirm(c[0],c[1],c[2],c[3],function(){a(document).trigger("save-changes",g)})}):(e.attr("data-selected",d),!isNaN(g)&&g>0&&a(document).trigger("user-changed",d)))},g.prototype._toggleExpandFilters=function(b){b.preventDefault();var c=a(b.target).closest('[data-region="user-filters"]'),d="true"==c.attr("aria-expanded"),e=a(document.getElementById(c.attr("aria-controls")));d?(e.hide(),e.attr("aria-hidden","true"),c.attr("aria-expanded","false"),a(document).unbind("click.mod_assign_grading_navigation")):(e.css("display","inline-block"),e.attr("aria-hidden","false"),c.attr("aria-expanded","true"),b.stopPropagation(),a(document).on("click.mod_assign_grading_navigation",this._checkClickOutsideConfigureFilters.bind(this)))},g.prototype._handlePreviousUser=function(a){a.preventDefault();var b=this._region.find("[data-action=change-user]"),c=b.attr("data-selected"),d=0,e=0;for(d=0;d<this._filteredUsers.length;d++)if(this._filteredUsers[d].id==c){e=d;break}var f=this._filteredUsers.length,g=e-1;g<0&&(g=f-1),f&&this._selectUserById(this._filteredUsers[g].id)},g.prototype._handleNextUser=function(b,c){b.preventDefault();var d=this._region.find("[data-action=change-user]"),e=d.attr("data-selected"),f=0,g=0;for(f=0;f<this._filteredUsers.length;f++)if(this._filteredUsers[f].id==e){g=f;break}var h=this._filteredUsers.length,i=(g+1)%h;if(c&&h){var j=this._filteredUsers[i].id,k=parseInt(j,10);d.attr("data-selected",j),!isNaN(k)&&k>0&&a(document).trigger("user-changed",j)}else h&&this._selectUserById(this._filteredUsers[i].id)},g.prototype._setCountString=function(a,d){var e=0;this._lastXofYUpdate++,e=this._lastXofYUpdate;var f={x:a,y:d};c.get_string("xofy","mod_assign",f).done(function(a){e==this._lastXofYUpdate&&this._region.find('[data-region="user-count-summary"]').text(a)}.bind(this)).fail(b.exception)},g.prototype._refreshCount=function(){var a=this._region.find("[data-action=change-user]"),b=a.attr("data-selected"),c=0,d=0;if(isNaN(b)||b<=0)this._region.find('[data-region="user-count"]').hide();else{for(this._region.find('[data-region="user-count"]').show(),c=0;c<this._filteredUsers.length;c++)if(this._filteredUsers[c].id==b){d=c;break}var e=this._filteredUsers.length;if(e&&(d+=1),this._setCountString(d,e),d>0){var f=new URL(window.location);if(parseInt(f.searchParams.get("blindid"))>0){var g=this._filteredUsers[d-1].recordid;f.searchParams.set("blindid",g)}else f.searchParams.set("userid",b);window.history.replaceState({},"",f)}}},g.prototype._refreshSelector=function(a,b){var c=this._region.find("[data-action=change-user]");b=parseInt(b,10),!isNaN(b)&&b>0&&c.attr("data-selected",b),this._refreshCount()},g.prototype._triggerNextUserEvent=function(){this._filteredUsers.length>1?a(document).trigger("next-user",{nextUserId:null,nextUser:!0}):a(document).trigger("next-user",{nextUser:!1})},g.prototype._handleChangeUser=function(){var d=this._region.find("[data-action=change-user]"),e=parseInt(d.val(),10);this._isLoading||(f.checkFormForChanges('[data-region="grade-panel"] .gradeform')?c.get_strings([{key:"unsavedchanges",component:"mod_assign"},{key:"unsavedchangesquestion",component:"mod_assign"},{key:"saveandcontinue",component:"mod_assign"},{key:"cancel",component:"core"}]).done(function(c){b.confirm(c[0],c[1],c[2],c[3],function(){a(document).trigger("save-changes",e)})}):!isNaN(e)&&e>0&&(d.attr("data-selected",e),a(document).trigger("user-changed",e)))},g});