(function(){"use strict";u8.Crm.Widgets.ParticipantsExtrasWidget=function(i,e){this.Widget(i,e);this._view=null;this._participantFieldId=null;this._listenToChanges=true;this._isCreated=false};$.extend(u8.Crm.Widgets.ParticipantsExtrasWidget.prototype,{create:function(){u8.using({schema:["MA"]},this._onLoaded.bind(this))},getModel:function(){return this._view.getModel()},isModified:function(){return false},update:function(){this._bindBusinessObjectEvents();if(!this._view){return}var i=this.getModel();var e=this.expandView.model.getUid();if(!u8.equalsRecordUid(e,i.uid)){this._view.setModel(new u8.Crm.Widgets.ParticipantListModel({uid:e}))}else{i.update()}},dispose:function(){if(this._isDisposed){return}var i=this.expandView.model;if(i){var e=i.getItem("Root").businessObject;if(e){e.unbind("FieldValueChange",this.id)}}this.Widget_dispose()},isEmpty:function(){return this._view.isEmpty()},_onLoaded:function(){this._participantFieldId=u8.services.schema.toFieldIds("MA","ParticipantID")[0];this._bindBusinessObjectEvents();var i=new u8.Crm.Widgets.ParticipantListModel({uid:this.expandView.model.getUid()});var e=$p(this.element).participants;if(e&&e.uids){i.addRecords(e.uids)}this._view=u8.widget("ParticipantList",this.element,{parent:this,onChange:this._onParticipantListChange.bind(this),onCreate:u8.tools.created.curry(this,{}),model:i,header:{headerGroupName:this.expandView.model.properties.headerGroupName||"MA"}})},_bindBusinessObjectEvents:function(){var i=this.expandView.model;var e=i.getItem("Root").businessObject;if(e){e.unbind("FieldValueChange",this.id);e.bind("FieldValueChange",this._onFieldValueChange.bind(this),this.id)}},_updateIsModified:function(){var i=this.isModified();if(this._lastIsModified!==i){this._lastIsModified=i;this.raise("IsModifiedChange")}},_onParticipantListChange:function(){if(!this._listenToChanges){return}var i=this.expandView.model.getItem("Root").businessObject;if(!i){return}var e=i.get(this._participantFieldId);if(!e){return}var t=this.getModel();var s=u8.services.reps.parseParticipants(e);for(var n=0;n<s.length;n++){var a=t.find(s[n].repId);if(!a||a.action==="Delete"){s.splice(n,1);n--}else if(a.type!=s[n].participation){s[n].participation=a.type}}e=u8.services.reps.formatParticipants(s);try{this._listenToChanges=false;i.set(this._participantFieldId,e)}finally{this._listenToChanges=true}},_onFieldValueChange:function(i,e){if(!this._listenToChanges){return}if(this._participantFieldId!=e.fieldId){return}try{this._listenToChanges=false;this.getModel().update({participants:e.value})}finally{this._listenToChanges=true}}});u8.Crm.Widgets.ParticipantsExtrasWidget.makeClass({name:"ParticipantsExtrasWidget",deriveFrom:u8.Base.Widgets.Widget,events:["Create","IsModifiedChange"]})})();