"use strict";define(["app","handlebars","View","text!/v2/webapps/FirstAccess/AdminSettings/PatientOrientationPopup/Templates/PatientOrientationPopupTemplate.html","../../../../../components/Confirmation/Controllers/ConfirmationController","utils","typeahead"],function(d,g,f,e,b,a){var c=f.extend({id:"patientOrientationPopup",overlay:null,savedReport:null,template:g.compile(e),events:{"click [name=save]":"Save","click [name=cancel]":"Cancel","fileselect .btn-file :file":"fileSelected","change .btn-file :file":"clickBrowse","click button#discardLink":"clickDiscardReport"},clickDiscardReport:function(j){j.preventDefault();var i=$(j.target).closest(".form-group").find("#textFileArea");if(this.savedReport!==undefined&&this.savedReport!==null&&i.val().trim()===this.savedReport.trim()){var h=new b();h.open({parent:this,header:a.localize(this,["adminsetting.discardCrystalReport"]),message:a.localize(this,["adminsetting.discardCrystalReportMessage"])},_.bind(function(k){if(k===true){i.val("");this.$el.find("#discardLink").prop("disabled","disabled");}},this));}else{i.val("");this.$el.find("#discardLink").prop("disabled","disabled");}},Save:function(h){h.preventDefault();this.trigger("view:validate",{overlay:this.overlay},this);if(this.validating===true){this.overlay.close();}},Cancel:function(h){this.overlay.close();},clickBrowse:function(k){var h=$(k.target),j=h.get(0).files?h.get(0).files.length:1,i=h.val().replace(/\\/g,"/").replace(/.*\//,"");h.trigger("fileselect",[j,i,h]);},fileSelected:function(l,k,i,h){var j=$(l.target).closest(".input-group").find(":text");if(j.length){j.val(i);}if(i!==undefined&&i!==null&&i.trim().length>0){this.$el.find("#discardLink").prop("disabled","");}else{this.$el.find("#discardLink").prop("disabled","disabled");}},initialize:function(h){f.prototype.initialize.apply(this,arguments);this.options=h||{};this.overlay=this.options.parent;this.validating=false;},initTypeahead:function(k){var h=_.filter(k.OrientationRecords,function(l){return l.LanguageCode===k.language;});var i=new Bloodhound({limit:10,datumTokenizer:Bloodhound.tokenizers.obj.whitespace("value"),queryTokenizer:Bloodhound.tokenizers.whitespace,local:$.map(_.pluck(h,"QuestionText"),function(l){return{value:l};})});i.initialize();this.$el.find("#questionText").typeahead({hint:true,highlight:true,minLength:1},{name:"value",displayKey:"value",source:i.ttAdapter()});var j=new Bloodhound({limit:10,datumTokenizer:Bloodhound.tokenizers.obj.whitespace("value"),queryTokenizer:Bloodhound.tokenizers.whitespace,local:$.map(_.pluck(h,"MessageText"),function(l){return{value:l};})});j.initialize();this.$el.find("#messageText").typeahead({hint:true,highlight:true,minLength:1},{name:"value",displayKey:"value",source:j.ttAdapter()});},render:function(j){f.prototype.render.apply(this,arguments);this.setParent(j.parent);this.savedReport=j.CrystalReport;var h=a.getSupportedLanguages();var i=_.findWhere(j.OrientationRecords,{Id:j.Id})||{};i.questionTypes=[{type:0,text:a.localize(this,["adminsetting.unanswered"]),selected:(j.mode==="add"?true:i.Type===0?true:false)},{type:1,text:a.localize(this,["adminsetting.YesNo"]),selected:(j.mode==="add"?false:i.Type===1?true:false)}];if(i.Type){i.questionTypes=$.map(i.questionTypes,function(k){k.selected=(k.type===i.Type);return k;});}i.mode=j.mode;i.Languages=$.map(h,function(k){return{langCd:k,name:"adminsetting.languagesView.language."+k,selected:k===j.language};});this.savedReport=i.CrystalReport;this.$el.html(this.template(i));if(i.CrystalReport!==undefined&&i.CrystalReport.trim().length>0){this.$el.find("#discardLink").prop("disabled","");}this.overlay.render().$el.find("#overlay").html(this.$el);j.parent.$el.append(this.overlay.$el);this.$el.find("#textFileArea").on("keydown",function(k){k.preventDefault();return false;});this.initTypeahead(j);this.delegateEvents();return this;}});return c;});