(function(){"use strict";u8.Crm.Widgets.QuestionnaireAnswerAnalysis=function(i,e){this.Widget(i,$.extend({},u8.Crm.Widgets.QuestionnaireAnswerAnalysis.defaults,e));this._isCreated=false;this._create()};u8.Crm.Widgets.QuestionnaireAnswerAnalysis.makeClass({name:"QuestionnaireAnswerAnalysis",deriveFrom:u8.Base.Widgets.Widget});u8.Crm.Widgets.QuestionnaireAnswerAnalysis.defaults={analysisName:"Questionnaire_SurveyAnswers",fieldGroupName:"U2.Analysis"};$.extend(u8.Crm.Widgets.QuestionnaireAnswerAnalysis.prototype,{update:function(){this._create()},_create:function(){var i=this.question&&this.question.uid;if(!i){this._showEmptyView()}else if(this.question.answerIsEditable){this._showListView(i)}else{this._showChartView(i)}},_showEmptyView:function(){if(this._listView){this.$(this._listView.element).hide()}if(this._chartView){this.$(this._chartView.element).hide()}},_createAnswerList:function(i){if(!this._listView){var e=this.$("<div>").appendTo(this.element);this._listView=new u8.Crm.Widgets.ListView(e,{parent:this,model:{link:i,fieldGroupName:this.fieldGroupName,fieldControlType:"List"},canEdit:false,autoLoad:true,grid:{showMiniDetails:false,showMenu:false,showQuickViewAction:false,useDefaultActionOnDblClick:false}})}},_showListView:function(i){if(this._chartView){this.$(this._chartView.element).hide()}if(!this._listView){this._createAnswerList(i)}else{if(!u8.equalsRecordUid(i,this._listView.model.link)){this._listView.model.link=i;this._listView.model.update()}}if(this._listView){this.$(this._listView.element).show()}},_createChartView:function(i){if(!this._chartModel){this._chartModel=u8.services.analyses.createExecutionModel({name:this.analysisName,link:i});this._chartModel.load()}else{this._chartModel.link=i;this._chartModel.data=null}if(!this._chartView){var e=this.$("<div>").appendTo(this.element);this._chartView=new u8.Crm.Widgets.AnalysisResultChart(e,$.extend(this.chart||{},{parent:this,model:this._chartModel,showDrillMenus:false}))}},_showChartView:function(i){if(this._listView){this.$(this._listView.element).hide()}if(!this._chartModel||!u8.equalsRecordUid(i,this._chartModel.link)){this._createChartView(i);this._chartModel.execute()}if(this._chartView){this.$(this._chartView.element).show()}}})})();