(function(){"use strict";u8.Crm.Widgets.LyrisCrmFieldPicker=function(e,i){this.Widget(e,$.extend({},u8.Crm.Widgets.LyrisCrmFieldPicker.defaults,i));var t=this;u8.using({schema:["FI","KP","CP","PE"]},function(){t._create()})};u8.Crm.Widgets.LyrisCrmFieldPicker.defaults={};u8.Crm.Widgets.LyrisCrmFieldPicker.makeClass({name:"LyrisCrmFieldPicker",deriveFrom:u8.Base.Widgets.Widget,events:["Create","CandidateCrmFieldsChange","InfoAreaChange","Save"]});$.extend(u8.Crm.Widgets.LyrisCrmFieldPicker.prototype,{dispose:function(){if(this._isDisposed){return}this.Widget_dispose()},setCandidateCrmFields:function(e){this.candidateCrmFields=e;this.raise("CandidateCrmFieldsChange")},getCandidateCrmFields:function(){return this.candidateCrmFields},setInfoArea:function(e){if(!this._dataModel){return}this._dataModel.setInfoArea(e)},getInfoArea:function(){return this._dataModel.getInfoArea()},saveCandidateCrmFields:function(e){u8.services.lyris.saveCrmFieldsToBeUsedAsDemographics(this.candidateCrmFields,this.activityUid,function(i){e()})},clearSelectedCrmFields:function(){var e=this.candidateCrmFields;$.each(e,function(e,i){i.selected=false});this.setCandidateCrmFields(e)},_createViewModel:function(){this._viewModel={infoAreaSelectorOptions:{infoAreaIds:["FI","PE","KP","CP"],showLockedInfoAreas:false,showVirtualInfoAreas:false,idPostfix:true,bindings:"@infoArea|property(infoAreaId)==>@value;@infoArea<==@value"},fieldSelectorOptions:{model:this.candidateCrmFields,autoLayout:true,showModifiedColumn:true,autoSelect:false,filter:function(e){return e.category!=u8.Crm.Schema.FieldCategory.VirtualCore&&e.category!=u8.Crm.Schema.FieldCategory.WebCustomField},isFieldModified:function(e){return false},bindings:"@infoArea|property(infoAreaId)==>@infoAreaId;@candidateCrmFields==>@candidateCrmFields"},status:status}},_createModel:function(){var e=this;this._dataModel=u8.create("DataModel",{onInfoAreaChange:function(i){var t=i.getInfoArea();e.raise("InfoAreaChange",{infoArea:t})}})},_setDefaultInfoArea:function(){var e=this.candidateCrmFields;var i=null;$.each(e,function(e,t){if(t.selected){i=t.infoAreaId;return false}});if(i===null){i="FI"}this.setInfoArea(i)},_setFieldListBoxHeight:function(){var e=window.parent.$("body").height();var i=.3*e;this.$(this.element).find("#fieldListBoxContainer").css("height",i+"px")},_initialize:function(){var e=this;this._createViewModel();this._createModel();this._setDefaultInfoArea();this.$(this.element).utml({url:"~/crm/LyrisCrmFieldPicker.utml.htm",itemOptions:{parent:this,context:this},data:this._viewModel},function(){e._setFieldListBoxHeight();e.raise("Create")})},_create:function(){var e=this;if(this.candidateCrmFields){this._initialize()}else{u8.services.lyris.getCrmFieldsCandidateForDemographicsInLyris(this.activityUid,function(i){e.candidateCrmFields=i;e._initialize()})}}})})();