$(function(){$('[data-toggle\x3d"tooltip"]').tooltip()});
AUI().add("ntnu-programmeinfo-infotype-select",function(A){A.Plugin.InfotypeSelect=A.Base.create("InfotypeSelectPlugin",A.Plugin.Base,[],{initializer:function(config){this.form=this.get("host");this.url=this.get("url");this.code=this.form.one('input[name\x3d"programmeCode"]');this.language=this.form.one('select[name\x3d"language"]');this.year=this.form.one('input[name\x3d"year"]');this.buildSelect();this.refresh()},buildSelect:function(){var infotypeField=this.form.one('input[name\x3d"type"]');if(infotypeField){this.infotypeSelect=
A.Node.create("\x3cselect\x3e\x3c/select\x3e");this.infotypeSelect.attr("id",infotypeField.attr("id"));this.infotypeSelect.attr("name",infotypeField.attr("name"));this.infotypeSelect.attr("class",infotypeField.attr("class"));infotypeField.replace(this.infotypeSelect);var self=this;this.code.on("change",function(e){A.bind(self,self.refresh())});this.language.on("change",function(e){A.bind(self,self.refresh())});this.year.on("change",function(e){A.bind(self,self.refresh())})}},refresh:function(){if(!this.infotypeSelect)return;
var code=this.code.get("value");var language=this.language.get("value");var year=this.year.get("value");var url=this.url+"\x26programmeCode\x3d"+code+"\x26language\x3d"+language+"\x26year\x3d"+year;var self=this;A.io.request(url,{dataType:"json",on:{success:function(){var data=this.get("responseData");self.infotypeSelect.empty();A.Array.forEach(data.infotypes,function(infotype){var option=A.Node.create('\x3coption value\x3d"'+infotype.code+'"\x3e'+infotype.code+" - "+infotype.name+"\x3c/option\x3e");
if(infotype.code===data.settings.type)option.attr("selected","selected");self.infotypeSelect.append(option)})},failure:function(){A.log("failed on request!","error","ntnu-programmeinfo-infotype-select:refresh")}}})}},{NS:"infotypeSelect",NAME:"InfotypeSelectPlugin",ATTRS:{url:{value:""}}})},"1.0",{requires:["base-build","plugin","node","aui-io-request"]});
