(function(){"use strict";u8.Crm.Widgets.AddItemToWatchlistPopup=function(e,t){this.Widget(e,t)};u8.Crm.Widgets.AddItemToWatchlistPopup.makeClass({name:"AddItemToWatchlistPopup",deriveFrom:u8.Base.Widgets.Widget,events:["Close"]});u8.Crm.Widgets.AddItemToWatchlistPopup.defaults={notifyOnOption:null,uid:null};$.extend(u8.Crm.Widgets.AddItemToWatchlistPopup.prototype,{open:function(e){this.uid=e;u8.using({texts:["AddItemToWatchlist_text"],templates:[{name:"addItemToWatchlist_template",url:"~/crm/AddItemToWatchlistPopup.utml.htm"}]},this._create.bind(this))},_create:function(){var e=this,t=$.extend({parent:this,position:"center",alignTo:"window",allowResize:true,allowMaximize:true,autoShow:false,modal:true,disposeOnClose:true,sizing:"fit",title:$t("TXT_AddItemToWatchlist_text_1"),onCreate:function(t){e._popup=t;e._createView(e._popup.getContent())}},this.popup);this._popup=new u8.Base.Widgets.Popup("<div/>",t);this._popup.open()},_createView:function(e){var t=$("#fieldsPanel");var i=this,n={id:this.id,uid:this.uid,notifyOnOptions:[{key:"EveryChange",text:$t("TXT_AddItemToWatchlist_text_3")},{key:"ChangeOnSpecificField",text:$t("TXT_AddItemToWatchlist_text_4")}],notifyOnOptionValue:this.notifyOnOption,notificationAreaTypesValue:8,notificationAreaTypes:[{name:$t("TXT_AddItemToWatchlist_text_6"),code:1},{name:$t("TXT_AddItemToWatchlist_text_7"),code:2},{name:$t("TXT_AddItemToWatchlist_text_8"),code:4},{name:$t("TXT_AddItemToWatchlist_text_9"),code:8}],notifyOnOptionValueChange:function(e){var t=i._popup.children.get(i.id+"_fields");if(e.getValue()!="ChangeOnSpecificField"){t.element.parentElement.style.display="none"}else{t.element.parentElement.style.display="block";i._popup.autoSizeAndPosition()}},onSaveButtonClick:function(e){var t=i._popup.children.get(i.id+"_notifyOnOption").getValue();var n=i._popup.children.get(i.id+"_fields").getValue();var o=i._popup.children.get(i.id+"_notificationAreaTypes").getValue();var a=0;if(o!=null&&o.length>0){for(var s=0;s<o.length;s++){a|=o[s]}}var d=false;var l=i._popup.children.get(i.id+"_notificationAreaTypesErrorMessage");var p=i._popup.children.get(i.id+"_notifyOnOptionErrorMessage");var u=i._popup.children.get(i.id+"_fieldsErrorMessage");l.setVisible(false);p.setVisible(false);u.setVisible(false);if(a==0){l.setVisible(true);d=true}if(t==null){p.setVisible(true);d=true}if(t=="ChangeOnSpecificField"&&(n==null||n.length==0)){u.setVisible(true);d=true}if(d){return}u8.request("WatchListChannel.AddItemToWatchList",{request:{itemToWatchIdentifier:i.uid.uid.recordId,watchItemType:i.uid.uid.infoAreaId,notifyOn:t,creator:u8.session.identity.repId,creatorUsername:u8.session.identity.userName,creatorFullName:u8.session.identity.repName,notificationAreaType:a},selectedFields:n},function(e,t){if(t.error){}else{i._popup.close();var n="{0} {TXT_AddItemToWatchlist_text_5}";n.format({0:u8.services.schema.idToLabel(i.uid.uid.infoAreaId)},function(e){u8.services.notification.info(e)})}})}};e.addClass("u8-additemtowatchlistpopup").utml({name:"addItemToWatchlist_template",data:n,itemOptions:{parent:this._popup}},function(){i._popup.autoSizeAndPosition().show()})}})})();