(function(){var o="<div class='u8-surveyconduct-portfolio-grid'>"+"<span class='u8-surveyconduct-portfolio-showLegend' >"+'{{CheckBox({ value: true, label: "TXT_Question_Text_57", onValueChange: showLegendValueChange })}}'+"</span>"+"<h2>{{text TXT_Question_Text_55}}</h2>"+"<div>"+'{{PortfolioChart({ bindings: "#sectorDistribution==>sectorDistribution;#value==>@value" })}}'+"</div>"+"</div>"+"<div class='u8-surveyconduct-portfolio-result'>"+"<h2>{{text TXT_Question_Text_56}}</h2>"+'{{TextInput({readonly: true, multiLine: true, style: "frameless", bindings: "#resultText==>@value"})}}'+"</div>"+"<div class='u8-surveyconduct-portfolio-legend'>"+"<div>"+"<table>"+"{{each legendRows}}"+"<tr>"+"{{each columns}}"+"<td>"+"<div style='background-color: ${color};'></div>"+"</td>"+"<td>${text}</td>"+"{{/each}}"+"{{if emptyColumn && emptyColumn > 0}}"+"<td colspan='${emptyColumn}'>&nbsp;</td>"+"{{/if}}"+"</tr>"+"{{/each}}"+"</table>"+"</div>"+"</div>";u8.Crm.Widgets.PortfolioSurveyConduct=function(o,e){if(!u8.tools.isClass(e.model)){e.model=new u8.Crm.Widgets.PortfolioSurveyConductModel(e.model||{})}e.isPortfolioSurvey=true;this.SurveyConduct(o,$.extend({},u8.Crm.Widgets.PortfolioSurveyConduct.defaults,e))};u8.Crm.Widgets.PortfolioSurveyConduct.defaults={showExpand:false,showHeader:false,showFinalize:false};u8.Crm.Widgets.PortfolioSurveyConduct.makeClass({name:"PortfolioSurveyConduct",deriveFrom:u8.Crm.Widgets.SurveyConduct});u8.Crm.Widgets.PortfolioSurveyConduct.override({_createView:function(e){e();var t=this.$("<div />").attr({id:this.id+"_portfolio"}).addClass("u8-surveyconduct-portfolio");this.$("#"+this.id+"_content").prepend(t);this._portfolioChartModel=new u8.Base.Model({properties:{sectorDistribution:this.model.portfolioChartInfo,value:this.model.portfolioResult,resultText:this.model.portfolioResult&&this.model.portfolioResult.text}});this._$portfolio=this.$("<div class='u8-surveyconduct-portfolio-chart' />").appendTo(t).utml({template:o,itemOptions:{parent:this,context:this._portfolioChartModel},data:{legendRows:this._createLegendRows(),showLegendValueChange:function(){this.$("div.u8-surveyconduct-portfolio-legend").toggle()}.bind(this)}})},_evaluateAnswer:function(o,e){var t=this.$(this.element).find(".u8-surveyconduct-survey");t.keepSize();var i=this;this._sendAnswersToServerAndMove({},function(o){if(o.error){return}i.model.calculatePortfolio(function(){i._portfolioChartModel.set("value",i.model.portfolioResult);i._portfolioChartModel.set("resultText",i.model.portfolioResult&&i.model.portfolioResult.text);t.keepSize(false)})})}});$.extend(u8.Crm.Widgets.PortfolioSurveyConduct.prototype,{_createLegendRows:function(){var o=[];var e=4;var t={columns:[],emptyColumn:0};var i=[];for(var r=0;r<this.model.portfolioChartInfo.percentagesRows.length;r++){for(var s=0;s<this.model.portfolioChartInfo.percentagesColumns.length;s++){var n=this._findSectorDefinition(r+1,s+1);if(!n||i.contains(n.classification)){continue}t.columns.push({color:n.color,text:n.name});i.push(n.classification);if(t.columns.length==e){o.push(t);t={columns:[],emptyColumn:0}}}}if(t.columns.length>0){if(t.columns.length<e){t.emptyColumn=2*(e-t.columns.length)}o.push(t)}return o},_findSectorDefinition:function(o,e){return this.model.portfolioChartInfo.sectors.find(function(t){return t.cells.some(function(t){return t.rowNo===o&&t.columnNo===e})})},_preCreateHeader:function(o){if(!o){return}if(!o.parameters){o.parameters={}}o.parameters.linkedUid=this.model.response.accountUid}})})();