(function(){"use strict";function e(e,t){this.MobileWidget(e,t);this._$value=this.$element.find("input[type='hidden']");this._$template=this.$element.find(".template");this._$list=this.$element.find(".u8-participants")}e.prototype={"Parent.create":function(){var e=this.parent;var t=this.element.getAttribute("data-dependson");var i=e.getField(t);if(i){var n=this;i.on("change",function(e,t){var i=t.getValue();n._updateMandatoryRepId(i)})}},setValue:function(e){$(this.element).val(e||"")},remove:function(e){var i=$(e.srcElement).closest("li");var n=t(i[0]);if(n){this._remove(n.repId)}},edit:function(e){var i=$(e.srcElement).closest("li");var n=t(i[0]);if(!n){return}var r={repId:n.repId,acceptance:n.acceptance,requirement:n.requirement,fieldGroupName:this.fieldGroupName,canRequire:e.type=="requirement",canAccept:e.type=="acceptance"};if(!r.canRequire&&!r.canRemove&&!r.canAccept){return}var a=new u8.Base.Uri("~/meetings/editparticipant");a.params=r;u8.application.execute("popup",{url:a.toString_(),data:{},method:"GET",srcElement:e.srcElement})},updateParticipant:function(e,i){var n=e.operation||"add";delete e.operation;if(n=="remove"){this._remove(e.repId);return}var r=$(i.srcElement).closest("li");if(!r.length){return}var a=t(r[0]);this._updateListElement($.extend({requirement:a.requirement,acceptance:a.acceptance},e),r)},_updateListElement:function(e,t){u8.rest({url:"~/meetings/participant",data:$.extend({},e,{fieldGroupName:this.fieldGroupName,parentUid:this.parentUid,mandatoryRepId:this.mandatoryRepId})}).done(this._done.bind(this,t))},"Expand.save":function(e){e.children.push({type:"Participants",fieldGroupName:this.fieldGroupName,items:this._createModel()})},"Selector.canSelect":function(e){return e.type=="rep"},"Selector.select":function(e,t){if(e.type=="rep"){this._add(e)}},_add:function(e){if(!e){return}var t=this._keyTo$(e.repId);if(t.length){return}u8.rest({url:"~/meetings/participant",data:{repId:e.repId,parentUid:this.parentUid,fieldGroupName:this.fieldGroupName,mandatoryRepId:this.mandatoryRepId}}).done(this._done.bind(this,null))},_done:function(e,t){if(e){e.replaceWith($(t))}else{var i=this._$list.children("[data-key]:last");if(i.length){i.after($(t))}else{$(t).prependTo(this._$list)}}},_remove:function(e){var t=this._keyTo$(e);if(t.length){t.remove()}},_createModel:function(){return this._$list.children("[data-model]").toArray().map(t)},_updateMandatoryRepId:function(e){if(this.mandatoryRepId==e){return}var i=this._$list.children("[data-model]");var n=null,r=null,a=null;for(var d=0;d<i.length;d++){var s=i[d],p=t(s);if(p.repId==e){a=p;r=s}else if(p.repId==this.mandatoryRepId){n=s}}this.mandatoryRepId=e;if(n){$(n).remove()}if(r){this._updateListElement(a,$(r))}else{this._add({repId:e})}},_keyTo$:function(e){return this._$list.children("[data-key='"+e+"']")}};e.makeClass({name:"ParticipantsField",deriveFrom:u8.Mobile.Widgets.MobileWidget});function t(e){var t=e&&e.getAttribute("data-model");return t&&JSON.parse(t)}})();