Current Path : C:/xampp/htdocs/moodle/admin/tool/lp/amd/build/ |
Current File : C:/xampp/htdocs/moodle/admin/tool/lp/amd/build/competencypicker.min.js |
define ("tool_lp/competencypicker",["jquery","core/notification","core/ajax","core/templates","tool_lp/dialogue","core/str","tool_lp/tree","core/pending"],function(a,b,c,d,e,f,g,h){var i=function(b,c,d,e){var f=this;f._eventNode=a("<div></div>");f._frameworks=[];f._reset();f._pageContextId=b;f._pageContextIncludes=d||"children";f._multiSelect="undefined"==typeof e||!0===e;if(c){f._frameworkId=c;f._singleFramework=!0}};i.prototype._competencies=null;i.prototype._disallowedCompetencyIDs=null;i.prototype._eventNode=null;i.prototype._frameworks=null;i.prototype._frameworkId=null;i.prototype._pageContextId=null;i.prototype._pageContextIncludes=null;i.prototype._popup=null;i.prototype._searchText="";i.prototype._selectedCompetencies=null;i.prototype._singleFramework=!1;i.prototype._multiSelect=!0;i.prototype._onlyVisible=!0;i.prototype._afterRender=function(){var c=this,d=new g(c._find("[data-enhance=linktree]"),c._multiSelect);c._find("[data-enhance=linktree]").show();d.on("selectionchanged",function(b,d){var e=d.selected;b.preventDefault();var f=[];a.each(e,function(b,d){var e=a(d).data("id"),g=!0;if("undefined"==typeof e){g=!1}else{a.each(c._disallowedCompetencyIDs,function(a,b){if(b==e){g=!1}})}if(g){f.push(e)}});c._selectedCompetencies=f;if(!c._selectedCompetencies.length){c._find("[data-region=\"competencylinktree\"] [data-action=\"add\"]").attr("disabled","disabled")}else{c._find("[data-region=\"competencylinktree\"] [data-action=\"add\"]").removeAttr("disabled")}});if(!c._singleFramework){c._find("[data-action=\"chooseframework\"]").change(function(d){c._frameworkId=a(d.target).val();c._loadCompetencies().then(c._refresh.bind(c)).catch(b.exception)})}c._find("[data-region=\"filtercompetencies\"] button").click(function(b){b.preventDefault();a(b.target).attr("disabled","disabled");c._searchText=c._find("[data-region=\"filtercompetencies\"] input").val()||"";return c._refresh().always(function(){a(b.target).removeAttr("disabled")})});c._find("[data-region=\"competencylinktree\"] [data-action=\"cancel\"]").click(function(a){a.preventDefault();c.close()});c._find("[data-region=\"competencylinktree\"] [data-action=\"add\"]").click(function(a){a.preventDefault();var b=new h;if(!c._selectedCompetencies.length){return}if(c._multiSelect){c._trigger("save",{competencyIds:c._selectedCompetencies})}else{c._trigger("save",{competencyId:c._selectedCompetencies[0]})}c.close();b.resolve()});var e=c._selectedCompetencies.slice(0);a.each(e,function(a,b){var e=c._find("[data-id="+b+"]");if(e.length){d.toggleItem(e);d.updateFocus(e)}})};i.prototype.close=function(){var a=this;a._popup.close();a._reset()};i.prototype.display=function(){var c=this;return a.when(f.get_string("competencypicker","tool_lp"),c._render()).then(function(a,b){c._popup=new e(a,b[0],c._afterRender.bind(c))}).catch(b.exception)};i.prototype._fetchCompetencies=function(a,d){var e=this;return c.call([{methodname:"core_competency_search_competencies",args:{searchtext:d,competencyframeworkid:a}}])[0].done(function(a){function b(a,c){for(var d=0;d<c.length;d++){if(c[d].parentid==a.id){a.haschildren=!0;c[d].children=[];c[d].haschildren=!1;a.children[a.children.length]=c[d];b(c[d],c)}}}var c,d,f=[];for(c=0;c<a.length;c++){d=a[c];if("0"==d.parentid){d.children=[];d.haschildren=0;f[f.length]=d;b(d,a)}}e._competencies=f}).fail(b.exception)};i.prototype._find=function(b){return a(this._popup.getContent()).find(b)};i.prototype._getFramework=function(b){var c;a.each(this._frameworks,function(a,d){if(d.id==b){c=d}});return c};i.prototype._loadCompetencies=function(){return this._fetchCompetencies(this._frameworkId,this._searchText)};i.prototype._loadFrameworks=function(){var d,e=this;if(0<e._frameworks.length){return a.when()}if(e._singleFramework){d=c.call([{methodname:"core_competency_read_competency_framework",args:{id:this._frameworkId}}])[0].then(function(a){return[a]})}else{d=c.call([{methodname:"core_competency_list_competency_frameworks",args:{sort:"shortname",context:{contextid:e._pageContextId},includes:e._pageContextIncludes,onlyvisible:e._onlyVisible}}])[0]}return d.done(function(a){e._frameworks=a}).fail(b.exception)};i.prototype.on=function(a,b){this._eventNode.on(a,b)};i.prototype._preRender=function(){var b=this;return b._loadFrameworks().then(function(){if(!b._frameworkId&&0<b._frameworks.length){b._frameworkId=b._frameworks[0].id}if(!b._frameworkId){b._frameworks=[];return a.when()}return b._loadCompetencies()})};i.prototype._refresh=function(){var a=this;return a._render().then(function(b){a._find("[data-region=\"competencylinktree\"]").replaceWith(b);a._afterRender()})};i.prototype._render=function(){var b=this;return b._preRender().then(function(){if(!b._singleFramework){a.each(b._frameworks,function(a,c){if(c.id==b._frameworkId){c.selected=!0}else{c.selected=!1}})}var c={competencies:b._competencies,framework:b._getFramework(b._frameworkId),frameworks:b._frameworks,search:b._searchText,singleFramework:b._singleFramework};return d.render("tool_lp/competency_picker",c)})};i.prototype._reset=function(){this._competencies=[];this._disallowedCompetencyIDs=[];this._popup=null;this._searchText="";this._selectedCompetencies=[]};i.prototype.setDisallowedCompetencyIDs=function(a){this._disallowedCompetencyIDs=a};i.prototype._trigger=function(a,b){this._eventNode.trigger(a,[b])};return i}); //# sourceMappingURL=competencypicker.min.js.map