From 2ccbcf01698f0c46cf6deaaa12a3a38aa630b096 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Fri, 17 Oct 2014 19:34:16 +0800 Subject: [PATCH] MDL-47738 gradereport_history: User selector handles broke with 0 user It was impossible to reopen the dialogue when the last search result did not return any user. --- .../moodle-gradereport_history-userselector-debug.js | 4 ++++ .../moodle-gradereport_history-userselector-min.js | 2 +- .../moodle-gradereport_history-userselector.js | 4 ++++ grade/report/history/yui/src/userselector/js/userselector.js | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/grade/report/history/yui/build/moodle-gradereport_history-userselector/moodle-gradereport_history-userselector-debug.js b/grade/report/history/yui/build/moodle-gradereport_history-userselector/moodle-gradereport_history-userselector-debug.js index a305c9a3906..a53eb2a1e1d 100644 --- a/grade/report/history/yui/build/moodle-gradereport_history-userselector/moodle-gradereport_history-userselector-debug.js +++ b/grade/report/history/yui/build/moodle-gradereport_history-userselector/moodle-gradereport_history-userselector-debug.js @@ -643,6 +643,10 @@ Y.namespace('M.gradereport_history').UserSelector = Y.extend(USERSELECTOR, M.cor if (this._userTabFocus) { this._userTabFocus.setAttribute('tabindex', '-1'); } + if (!user) { + // We were not passed a user, there is apparently none in the dialogue. Nothing to do here \\\o/. + return; + } this._userTabFocus = user.one(SELECTORS.USERSELECT); this._userTabFocus.setAttribute('tabindex', '0'); diff --git a/grade/report/history/yui/build/moodle-gradereport_history-userselector/moodle-gradereport_history-userselector-min.js b/grade/report/history/yui/build/moodle-gradereport_history-userselector/moodle-gradereport_history-userselector-min.js index 6efa1571cdf..8d69f0de564 100644 --- a/grade/report/history/yui/build/moodle-gradereport_history-userselector/moodle-gradereport_history-userselector-min.js +++ b/grade/report/history/yui/build/moodle-gradereport_history-userselector/moodle-gradereport_history-userselector-min.js @@ -1,2 +1,2 @@ YUI.add("moodle-gradereport_history-userselector",function(e,t){var n="gradereport_history",r={AJAXURL:"ajaxurl",BASE:"base",CHECKBOX_NAME_PREFIX:"usp-u",COURSEID:"courseid",DIALOGUE_PREFIX:"moodle-dialogue",NAME:"gradereport_history_usp",PAGE:"page",PARAMS:"params",PERPAGE:"perPage",SEARCH:"search",SEARCHBTN:"searchbtn",SELECTEDUSERS:"selectedUsers",URL:"url",USERCOUNT:"userCount"},i={ACCESSHIDE:"accesshide",AJAXCONTENT:"usp-ajax-content",CHECKBOX:"usp-checkbox",CLOSE:"close",CLOSEBTN:"usp-finish",CONTENT:"usp-content",DETAILS:"details",EXTRAFIELDS:"extrafields",FIRSTADDED:"usp-first-added",FULLNAME:"fullname",HEADER:"usp-header",HIDDEN:"hidden",LIGHTBOX:"usp-loading-lightbox",LOADINGICON:"loading-icon",MORERESULTS:"usp-more-results",OPTIONS:"options",PICTURE:"usp-picture",RESULTSCOUNT:"usp-results-count",SEARCH:"usp-search",SEARCHBTN:"usp-search-btn",SEARCHFIELD:"usp-search-field",SEARCHRESULTS:"usp-search-results",SELECTED:"selected",USER:"usp-user",USERS:"usp-users",WRAP:"usp-wrap"},s={AJAXCONTENT:"."+i.AJAXCONTENT,FINISHBTN:"."+i.CLOSEBTN+" input",FIRSTADDED:"."+i.FIRSTADDED,FULLNAME:"."+i.FULLNAME+" label",LIGHTBOX:"."+i.LIGHTBOX,MORERESULTS:"."+i.MORERESULTS,OPTIONS:"."+i.OPTIONS,PICTURE:"."+i.USER+" .userpicture",RESULTSCOUNT:"."+i.RESULTSCOUNT,RESULTSUSERS:"."+i.SEARCHRESULTS+" ."+i.USERS,SEARCHBTN:"."+i.SEARCHBTN,SEARCHFIELD:"."+i.SEARCHFIELD,SELECTEDNAMES:".felement .selectednames",TRIGGER:".gradereport_history_plugin input.selectortrigger",USER:"."+i.USER,USERFULLNAMES:'input[name="userfullnames"]',USERIDS:'input[name="userids"]',USERSELECT:"."+i.CHECKBOX+" input[type=checkbox]"},o=function(){o.superclass.constructor.apply(this,arguments)};e.namespace("M.gradereport_history").UserSelector=e.extend(o,M.core.dialogue,{_firstDisplay:!0,_usersBufferList:null,_userTabFocus:null,_userTemplate:null,initializer:function(){var t=this.get("boundingBox"),o,u,a;a=e.Handlebars.compile('
{{get_string
'),o=e.Node.create(a({COMPONENT:n,CSS:i,loadingIcon:M.util.image_url("i/loading","moodle")})),this.getStdModNode(e.WidgetStdMod.HEADER).prepend(e.Node.create("

"+this.get("title")+"

")),this.setStdModContent(e.WidgetStdMod.BODY,o,e.WidgetStdMod.REPLACE),this.get("boundingBox").one(".moodle-dialogue-wrap").addClass("moodle-dialogue-content"),e.one(s.TRIGGER).on("click",this.show,this),t.one(s.FINISHBTN).on("click",this.finishSelectingUsers,this),t.delegate("key",this.userKeyboardNavigation,"down:38,40",s.AJAXCONTENT,this),e.delegate("click",this.selectUser,s.AJAXCONTENT,s.USERSELECT,this),e.delegate("click",this.selectUser,s.AJAXCONTENT,s.PICTURE,this),u=this.get(r.PARAMS),u.id=this.get(r.COURSEID),this.set(r.PARAMS,u),t.one(s.SEARCHBTN).on("click",this.search,this,!1)},show:function(t){var n;return this._usersBufferList=e.clone(this.get(r.SELECTEDUSERS)),this._firstDisplay?(this._firstDisplay=!1,this.search(t,!1)):(n=this.get("boundingBox"),n.all(s.USER).each(function(e){this.markUserNode(e,!1)},this),e.Object.each(this._usersBufferList,function(e,t){var r=n.one(s.USER+'[data-userid="'+t+'"]');r&&this.markUserNode(r,!0)},this),this.setUserTabFocus(n.one(s.USER))),e.namespace("M.gradereport_history.UserSelector").superclass.show.call(this)},search:function(t,n){t&&t.preventDefault();var i;n?this.set(r.PAGE,this.get(r.PAGE)+1):(this.set(r.USERCOUNT,0),this.set(r.PAGE,0)),i=this.get(r.PARAMS),i.sesskey=M.cfg.sesskey,i.action="searchusers",i.search=this.get("boundingBox").one(s.SEARCHFIELD).get("value"),i.page=this.get(r.PAGE),i.perpage=this.get(r.PERPAGE),e.io(M.cfg.wwwroot+this.get(r.AJAXURL),{method:"POST",data:build_querystring(i),on:{start:this.preSearch,complete:this.processSearchResults,end:this.postSearch},context:this,arguments:{append:n}})},preSearch:function(e,t){var n=this.get("boundingBox");n.one(s.LIGHTBOX).removeClass(i.HIDDEN),t.append||n.one(s.RESULTSCOUNT).setHTML(M.util.get_string("loading","admin"))},postSearch:function(e,t){var n=this.get("boundingBox"),r=n.one(s.FIRSTADDED),o;n.one(s.LIGHTBOX).addClass(i.HIDDEN),t.append&&r?(this.setUserTabFocus(r),r.one(s.USERSELECT).focus()):(o=n.one(s.USER),o&&this.setUserTabFocus(o))},processSearchResults:function(t,o,u){var a=!1,f=!1,l=this.get("boundingBox"),c,h,p,d,v,m=!0,g,y,b,w;try{a=e.JSON.parse(o.responseText);if(!a.success||a.error)f=!0}catch(E){f=!0}if(f){this.setContent(""),l.one(s.RESULTSCOUNT).setHTML(M.util.get_string("errajaxsearch",n));return}u.append?c=l.one(s.RESULTSUSERS):c=e.Node.create('
'),this._userTemplate||(this._userTemplate=e.Handlebars.compile('
{{{picture}}}
{{extrafields}}
')),h=this._userTemplate,p=this.get(r.USERCOUNT),d="";for(v in a.response.users)p++,user=a.response -.users[v],e.Object.hasKey(this._usersBufferList,user.userid)?d=!0:d=!1,g=e.Node.create(h({checkboxId:e.guid(),COMPONENT:n,count:p,CSS:i,extrafields:user.extrafields,extraFieldsId:e.guid(),fullname:user.fullname,picture:user.picture,userId:user.userid,USP:r})),this.markUserNode(g,d),u.append&&m&&(c.all(s.FIRSTADDED).removeClass(i.FIRSTADDED),g.addClass(i.FIRSTADDED),m=!1),c.append(g);this.set(r.USERCOUNT,p),w=parseInt(a.response.totalusers,10),u.append?w<=(this.get(r.PAGE)+1)*this.get(r.PERPAGE)&&l.one(s.MORERESULTS).remove():(w===0?(l.one(s.RESULTSCOUNT).setHTML(M.util.get_string("noresults","moodle")),y=""):(w===1?l.one(s.RESULTSCOUNT).setHTML(M.util.get_string("foundoneuser",n)):l.one(s.RESULTSCOUNT).setHTML(M.util.get_string("foundnusers",n,w)),y=e.Node.create('
').append(c),a.response.totalusers>(this.get(r.PAGE)+1)*this.get(r.PERPAGE)&&(b=e.Node.create('
'+''+M.util.get_string("loadmoreusers",n)+"
"),b.one("a").on("click",this.search,this,!0),b.one("a").on("key",this.search,"space",this,!0),y.append(b))),this.setContent(y))},finishSelectingUsers:function(e){e.preventDefault(),this.applySelection(),this.hide()},applySelection:function(){var t=e.Object.keys(this._usersBufferList);this.set(r.SELECTEDUSERS,e.clone(this._usersBufferList)).setNameDisplay(),e.one(s.USERIDS).set("value",t.join())},selectUser:function(e){var t=e.currentTarget.ancestor(s.USER),n=t.one(s.USERSELECT),r=t.one(s.FULLNAME).get("innerHTML"),i=n.get("checked"),o=t.getData("userid");e.currentTarget!==n&&(i=!i),i?this._usersBufferList[o]=r:(delete this._usersBufferList[o],delete this._usersBufferList[parseInt(o,10)]),this.markUserNode(t,i)},markUserNode:function(e,t){return t?e.addClass(i.SELECTED).set("aria-selected",!0).one(s.USERSELECT).set("checked",!0):e.removeClass(i.SELECTED).set("aria-selected",!1).one(s.USERSELECT).set("checked",!1),this},setContent:function(e){return this.get("boundingBox").one(s.AJAXCONTENT).setHTML(e),this},setNameDisplay:function(){var t=e.Object.values(this.get(r.SELECTEDUSERS));e.one(s.SELECTEDNAMES).set("innerHTML",t.join(", ")),e.one(s.USERFULLNAMES).set("value",t.join())},userKeyboardNavigation:function(e){var t=this.get("boundingBox"),n=t.all(s.USER),r=1,i,o=e.target.ancestor(s.USER,!0);e.keyCode===38&&(r=-1),i=this.findFocusableUser(n,o,r),i&&(e.preventDefault(),i.one(s.USERSELECT).focus(),this.setUserTabFocus(i))},findFocusableUser:function(e,t,n){var r=e.indexOf(t);return e.size()<1?null:r<0?e.item(0):(r+=n,r<0?r=e.size()-1:r>=e.size()&&(r=0),e.item(r))},setUserTabFocus:function(e){this._userTabFocus&&this._userTabFocus.setAttribute("tabindex","-1"),this._userTabFocus=e.one(s.USERSELECT),this._userTabFocus.setAttribute("tabindex","0"),this.get("boundingBox").one(s.RESULTSUSERS).setAttribute("aria-activedescendant",this._userTabFocus.generateID())}},{NAME:r.NAME,CSS_PREFIX:r.CSS_PREFIX,ATTRS:{title:{validator:e.Lang.isString,valueFn:function(){return M.util.get_string("selectusers",n)}},url:{validator:e.Lang.isString,value:null},ajaxurl:{validator:e.Lang.isString,value:null},selectedUsers:{validator:e.Lang.isObject,value:null,getter:function(e){return e===null?{}:e}},courseid:{value:null},params:{validator:e.Lang.isArray,value:[]},page:{validator:e.Lang.isNumber,value:0},userCount:{value:0,validator:e.Lang.isNumber},perPage:{value:25,Validator:e.Lang.isNumber}}}),e.Base.modifyAttrs(e.namespace("M.gradereport_history.UserSelector"),{extraClasses:{value:["gradereport_history_usp"]},focusOnPreviousTargetAfterHide:{value:!0},width:{value:"500px"},visible:{value:!1},modal:{value:!0},draggable:{value:!0}}),e.namespace("M.gradereport_history.UserSelector").init=function(e){return new o(e)}},"@VERSION@",{requires:["escape","event-delegate","event-key","handlebars","io-base","json-parse","moodle-core-notification-dialogue"]}); +.users[v],e.Object.hasKey(this._usersBufferList,user.userid)?d=!0:d=!1,g=e.Node.create(h({checkboxId:e.guid(),COMPONENT:n,count:p,CSS:i,extrafields:user.extrafields,extraFieldsId:e.guid(),fullname:user.fullname,picture:user.picture,userId:user.userid,USP:r})),this.markUserNode(g,d),u.append&&m&&(c.all(s.FIRSTADDED).removeClass(i.FIRSTADDED),g.addClass(i.FIRSTADDED),m=!1),c.append(g);this.set(r.USERCOUNT,p),w=parseInt(a.response.totalusers,10),u.append?w<=(this.get(r.PAGE)+1)*this.get(r.PERPAGE)&&l.one(s.MORERESULTS).remove():(w===0?(l.one(s.RESULTSCOUNT).setHTML(M.util.get_string("noresults","moodle")),y=""):(w===1?l.one(s.RESULTSCOUNT).setHTML(M.util.get_string("foundoneuser",n)):l.one(s.RESULTSCOUNT).setHTML(M.util.get_string("foundnusers",n,w)),y=e.Node.create('
').append(c),a.response.totalusers>(this.get(r.PAGE)+1)*this.get(r.PERPAGE)&&(b=e.Node.create('
'+''+M.util.get_string("loadmoreusers",n)+"
"),b.one("a").on("click",this.search,this,!0),b.one("a").on("key",this.search,"space",this,!0),y.append(b))),this.setContent(y))},finishSelectingUsers:function(e){e.preventDefault(),this.applySelection(),this.hide()},applySelection:function(){var t=e.Object.keys(this._usersBufferList);this.set(r.SELECTEDUSERS,e.clone(this._usersBufferList)).setNameDisplay(),e.one(s.USERIDS).set("value",t.join())},selectUser:function(e){var t=e.currentTarget.ancestor(s.USER),n=t.one(s.USERSELECT),r=t.one(s.FULLNAME).get("innerHTML"),i=n.get("checked"),o=t.getData("userid");e.currentTarget!==n&&(i=!i),i?this._usersBufferList[o]=r:(delete this._usersBufferList[o],delete this._usersBufferList[parseInt(o,10)]),this.markUserNode(t,i)},markUserNode:function(e,t){return t?e.addClass(i.SELECTED).set("aria-selected",!0).one(s.USERSELECT).set("checked",!0):e.removeClass(i.SELECTED).set("aria-selected",!1).one(s.USERSELECT).set("checked",!1),this},setContent:function(e){return this.get("boundingBox").one(s.AJAXCONTENT).setHTML(e),this},setNameDisplay:function(){var t=e.Object.values(this.get(r.SELECTEDUSERS));e.one(s.SELECTEDNAMES).set("innerHTML",t.join(", ")),e.one(s.USERFULLNAMES).set("value",t.join())},userKeyboardNavigation:function(e){var t=this.get("boundingBox"),n=t.all(s.USER),r=1,i,o=e.target.ancestor(s.USER,!0);e.keyCode===38&&(r=-1),i=this.findFocusableUser(n,o,r),i&&(e.preventDefault(),i.one(s.USERSELECT).focus(),this.setUserTabFocus(i))},findFocusableUser:function(e,t,n){var r=e.indexOf(t);return e.size()<1?null:r<0?e.item(0):(r+=n,r<0?r=e.size()-1:r>=e.size()&&(r=0),e.item(r))},setUserTabFocus:function(e){this._userTabFocus&&this._userTabFocus.setAttribute("tabindex","-1");if(!e)return;this._userTabFocus=e.one(s.USERSELECT),this._userTabFocus.setAttribute("tabindex","0"),this.get("boundingBox").one(s.RESULTSUSERS).setAttribute("aria-activedescendant",this._userTabFocus.generateID())}},{NAME:r.NAME,CSS_PREFIX:r.CSS_PREFIX,ATTRS:{title:{validator:e.Lang.isString,valueFn:function(){return M.util.get_string("selectusers",n)}},url:{validator:e.Lang.isString,value:null},ajaxurl:{validator:e.Lang.isString,value:null},selectedUsers:{validator:e.Lang.isObject,value:null,getter:function(e){return e===null?{}:e}},courseid:{value:null},params:{validator:e.Lang.isArray,value:[]},page:{validator:e.Lang.isNumber,value:0},userCount:{value:0,validator:e.Lang.isNumber},perPage:{value:25,Validator:e.Lang.isNumber}}}),e.Base.modifyAttrs(e.namespace("M.gradereport_history.UserSelector"),{extraClasses:{value:["gradereport_history_usp"]},focusOnPreviousTargetAfterHide:{value:!0},width:{value:"500px"},visible:{value:!1},modal:{value:!0},draggable:{value:!0}}),e.namespace("M.gradereport_history.UserSelector").init=function(e){return new o(e)}},"@VERSION@",{requires:["escape","event-delegate","event-key","handlebars","io-base","json-parse","moodle-core-notification-dialogue"]}); diff --git a/grade/report/history/yui/build/moodle-gradereport_history-userselector/moodle-gradereport_history-userselector.js b/grade/report/history/yui/build/moodle-gradereport_history-userselector/moodle-gradereport_history-userselector.js index 320994655bc..390997d1ae3 100644 --- a/grade/report/history/yui/build/moodle-gradereport_history-userselector/moodle-gradereport_history-userselector.js +++ b/grade/report/history/yui/build/moodle-gradereport_history-userselector/moodle-gradereport_history-userselector.js @@ -641,6 +641,10 @@ Y.namespace('M.gradereport_history').UserSelector = Y.extend(USERSELECTOR, M.cor if (this._userTabFocus) { this._userTabFocus.setAttribute('tabindex', '-1'); } + if (!user) { + // We were not passed a user, there is apparently none in the dialogue. Nothing to do here \\\o/. + return; + } this._userTabFocus = user.one(SELECTORS.USERSELECT); this._userTabFocus.setAttribute('tabindex', '0'); diff --git a/grade/report/history/yui/src/userselector/js/userselector.js b/grade/report/history/yui/src/userselector/js/userselector.js index 38f662e89df..0622cb9bf90 100644 --- a/grade/report/history/yui/src/userselector/js/userselector.js +++ b/grade/report/history/yui/src/userselector/js/userselector.js @@ -641,6 +641,10 @@ Y.namespace('M.gradereport_history').UserSelector = Y.extend(USERSELECTOR, M.cor if (this._userTabFocus) { this._userTabFocus.setAttribute('tabindex', '-1'); } + if (!user) { + // We were not passed a user, there is apparently none in the dialogue. Nothing to do here \\\o/. + return; + } this._userTabFocus = user.one(SELECTORS.USERSELECT); this._userTabFocus.setAttribute('tabindex', '0');