Your IP : 192.168.165.1


Current Path : C:/xampp/htdocs/moodle/admin/tool/lp/amd/build/
Upload File :
Current File : C:/xampp/htdocs/moodle/admin/tool/lp/amd/build/competencyruleconfig.min.js

define ("tool_lp/competencyruleconfig",["jquery","core/notification","core/templates","tool_lp/dialogue","tool_lp/competency_outcomes","core/str"],function(a,b,c,d,e,f){var g=function(b,c){this._eventNode=a("<div></div>");this._tree=b;this._rulesModules=c;this._setUp()};g.prototype._competency=null;g.prototype._eventNode=null;g.prototype._outcomesOption=null;g.prototype._popup=null;g.prototype._ready=null;g.prototype._rules=null;g.prototype._rulesModules=null;g.prototype._tree=null;g.prototype._afterChange=function(){if(!this._isValid()){this._find("[data-action=\"save\"]").prop("disabled",!0)}else{this._find("[data-action=\"save\"]").prop("disabled",!1)}};g.prototype._afterRuleConfigChange=function(a,b){if(b!=this._getRule()){return}this._afterChange()};g.prototype._afterRender=function(){var a=this;a._find("[name=\"outcome\"]").on("change",function(){a._switchedOutcome()}).trigger("change");a._find("[name=\"rule\"]").on("change",function(){a._switchedRule()}).trigger("change");a._find("[data-action=\"save\"]").on("click",function(){a._trigger("save",a._getConfig());a.close()});a._find("[data-action=\"cancel\"]").on("click",function(){a.close()})};g.prototype.canBeConfigured=function(){var b=!1;a.each(this._rules,function(a,c){if(c.canConfig()){b=!0}});return b};g.prototype.close=function(){this._popup.close();this._popup=null};g.prototype.display=function(){var c=this;if(!c._competency){return!1}return a.when(f.get_string("competencyrule","tool_lp"),c._render()).then(function(a,b){c._popup=new d(a,b[0],c._afterRender.bind(c))}).fail(b.exception)};g.prototype._find=function(b){return a(this._popup.getContent()).find(b)};g.prototype._getApplicableOutcomesOptions=function(){var b=this,c=[];a.each(b._outcomesOption,function(a,d){c.push({code:d.code,name:d.name,selected:d.code==b._competency.ruleoutcome?!0:!1})});return c};g.prototype._getApplicableRulesOptions=function(){var b=this,c=[];a.each(b._rules,function(a,d){if(!d.canConfig()){return}c.push({name:b._getRuleName(d.getType()),type:d.getType(),selected:d.getType()==b._competency.ruletype?!0:!1})});return c};g.prototype._getConfig=function(){var a=this._getRule();return{ruletype:a?a.getType():null,ruleconfig:a?a.getConfig():null,ruleoutcome:this._getOutcome()}};g.prototype._getOutcome=function(){return this._find("[name=\"outcome\"]").val()};g.prototype._getRule=function(){var b,c=this._find("[name=\"rule\"]").val();a.each(this._rules,function(a,d){if(d.getType()==c){b=d}});return b};g.prototype._getRuleName=function(b){var c=this,d;a.each(c._rulesModules,function(a,c){if(c.type==b){d=c.name}});return d};g.prototype._initOutcomes=function(){var a=this;return e.getAll().then(function(b){a._outcomesOption=b})};g.prototype._initRules=function(){var b=this,c=[];a.each(b._rules,function(d,e){var f=e.init().then(function(){e.setTargetCompetency(b._competency);e.on("change",b._afterRuleConfigChange.bind(b))},function(){b._rules.splice(d,1);return a.when()});c.push(f)});return a.when.apply(a.when,c)};g.prototype._isValid=function(){var a=this._getOutcome(),b=this._getRule();if(a==e.NONE){return!0}else if(!b){return!1}return b.isValid()};g.prototype.on=function(a,b){this._eventNode.on(a,b)};g.prototype._preRender=function(){return this.ready()};g.prototype.ready=function(){return this._ready.promise()};g.prototype._render=function(){var a=this;return this._preRender().then(function(){var b;if(!a.canBeConfigured()){b=!1}else{b={};b.outcomes=a._getApplicableOutcomesOptions();b.rules=a._getApplicableRulesOptions()}var d={competencyshortname:a._competency.shortname,config:b};return c.render("tool_lp/competency_rule_config",d)})};g.prototype.setTargetCompetencyId=function(b){var c=this;c._competency=c._tree.getCompetency(b);a.each(c._rules,function(a,b){b.setTargetCompetency(c._competency)})};g.prototype._setUp=function(){var b=this,c=[],d=[];b._ready=a.Deferred();b._rules=[];a.each(b._rulesModules,function(a,b){d.push(b.amd)});require(d,function(){a.each(arguments,function(a,c){var d=new c(b._tree);b._rules.push(d)});c.push(b._initRules());c.push(b._initOutcomes());a.when.apply(a.when,c).always(function(){b._ready.resolve()})})};g.prototype._switchedOutcome=function(){var a=this,b=a._getOutcome();if(b==e.NONE){a._find("[data-region=\"rule-type\"]").hide().find("[name=\"rule\"]").val(-1);a._find("[data-region=\"rule-config\"]").empty().hide();a._afterChange();return}a._find("[data-region=\"rule-type\"]").show();a._find("[data-region=\"rule-config\"]").show();a._afterChange()};g.prototype._switchedRule=function(){var a=this,b=a._find("[data-region=\"rule-config\"]"),c=a._getRule();if(!c){b.empty().hide();a._afterChange();return}c.injectTemplate(b).then(function(){b.show()}).always(function(){a._afterChange()}).catch(function(){b.empty().hide()})};g.prototype._trigger=function(a,b){this._eventNode.trigger(a,[b])};return g});
//# sourceMappingURL=competencyruleconfig.min.js.map