text: define(["jquery","core/notification","core/ajax","core/templates","tool_lp/dialogue","core/str","tool_lp/tree"],function(a,b,c,d,e,f,g){var h=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||e===!0,c&&(f._frameworkId=c,f._singleFramework=!0)};return h.prototype._competencies=null,h.prototype._disallowedCompetencyIDs=null,h.prototype._eventNode=null,h.prototype._frameworks=null,h.prototype._frameworkId=null,h.prototype._pageContextId=null,h.prototype._pageContextIncludes=null,h.prototype._popup=null,h.prototype._searchText="",h.prototype._selectedCompetencies=null,h.prototype._singleFramework=!1,h.prototype._multiSelect=!0,h.prototype._onlyVisible=!0,h.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;"undefined"==typeof e?g=!1:a.each(c._disallowedCompetencyIDs,function(a,b){b==e&&(g=!1)}),g&&f.push(e)}),c._selectedCompetencies=f,c._selectedCompetencies.length?c._find('[data-region="competencylinktree"] [data-action="add"]').removeAttr("disabled"):c._find('[data-region="competencylinktree"] [data-action="add"]').attr("disabled","disabled")}),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){return b.preventDefault(),a(b.target).attr("disabled","disabled"),c._searchText=c._find('[data-region="filtercompetencies"] input').val()||"",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(),c._selectedCompetencies.length&&(c._multiSelect?c._trigger("save",{competencyIds:c._selectedCompetencies}):c._trigger("save",{competencyId:c._selectedCompetencies[0]}),c.close())});var e=c._selectedCompetencies.slice(0);a.each(e,function(a,b){var e=c._find("[data-id="+b+"]");e.length&&(d.toggleItem(e),d.updateFocus(e))})},h.prototype.close=function(){var a=this;a._popup.close(),a._reset()},h.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)},h.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++)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],"0"==d.parentid&&(d.children=[],d.haschildren=0,f[f.length]=d,b(d,a));e._competencies=f}).fail(b.exception)},h.prototype._find=function(b){return a(this._popup.getContent()).find(b)},h.prototype._getFramework=function(b){var c;return a.each(this._frameworks,function(a,d){if(d.id==b)return void(c=d)}),c},h.prototype._loadCompetencies=function(){return this._fetchCompetencies(this._frameworkId,this._searchText)},h.prototype._loadFrameworks=function(){var d,e=this;return e._frameworks.length>0?a.when():(d=e._singleFramework?c.call([{methodname:"core_competency_read_competency_framework",args:{id:this._frameworkId}}])[0].then(function(a){return[a]}):c.call([{methodname:"core_competency_list_competency_frameworks",args:{sort:"shortname",context:{contextid:e._pageContextId},includes:e._pageContextIncludes,onlyvisible:e._onlyVisible}}])[0],d.done(function(a){e._frameworks=a}).fail(b.exception))},h.prototype.on=function(a,b){this._eventNode.on(a,b)},h.prototype._preRender=function(){var b=this;return b._loadFrameworks().then(function(){return!b._frameworkId&&b._frameworks.length>0&&(b._frameworkId=b._frameworks[0].id),b._frameworkId?b._loadCompetencies():(b._frameworks=[],a.when())})},h.prototype._refresh=function(){var a=this;return a._render().then(function(b){a._find('[data-region="competencylinktree"]').replaceWith(b),a._afterRender()})},h.prototype._render=function(){var b=this;return b._preRender().then(function(){b._singleFramework||a.each(b._frameworks,function(a,c){c.id==b._frameworkId?c.selected=!0: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)})},h.prototype._reset=function(){this._competencies=[],this._disallowedCompetencyIDs=[],this._popup=null,this._searchText="",this._selectedCompetencies=[]},h.prototype.setDisallowedCompetencyIDs=function(a){this._disallowedCompetencyIDs=a},h.prototype._trigger=function(a,b){this._eventNode.trigger(a,[b])},h});